| 1 | // tObject.cpp  |
| 2 | //  |
| 3 | // The base class for all tScene objects. All objects have an ID, a name, and attributes.  |
| 4 | //  |
| 5 | // Copyright (c) 2006, 2017 Tristan Grimmer.  |
| 6 | // Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby  |
| 7 | // granted, provided that the above copyright notice and this permission notice appear in all copies.  |
| 8 | //  |
| 9 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL  |
| 10 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,  |
| 11 | // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN  |
| 12 | // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR  |
| 13 | // PERFORMANCE OF THIS SOFTWARE.  |
| 14 |   |
| 15 | #include "Scene/tObject.h"  |
| 16 | namespace tScene  |
| 17 | {  |
| 18 |   |
| 19 |   |
| 20 | void tObject::Save(tChunkWriter& chunk) const  |
| 21 | {  |
| 22 | chunk.Begin(tChunkID::Scene_Object);  |
| 23 | {  |
| 24 | chunk.Begin(tChunkID::Core_ID);  |
| 25 | chunk.Write(ID);  |
| 26 | chunk.End();  |
| 27 |   |
| 28 | chunk.Begin(tChunkID::Core_Name);  |
| 29 | chunk.Write(Name);  |
| 30 | chunk.End();  |
| 31 |   |
| 32 | Attributes.Save(chunk);  |
| 33 | }  |
| 34 | chunk.End();  |
| 35 | }  |
| 36 |   |
| 37 |   |
| 38 | void tObject::Load(const tChunk& objChunk)  |
| 39 | {  |
| 40 | Clear();  |
| 41 | tAssert(objChunk.ID() == tChunkID::Scene_Object);  |
| 42 |   |
| 43 | for (tChunk chunk = objChunk.First(); chunk.Valid(); chunk = chunk.Next())  |
| 44 | {  |
| 45 | switch (chunk.ID())  |
| 46 | {  |
| 47 | case tChunkID::Core_ID:  |
| 48 | chunk.GetItem(ID);  |
| 49 | break;  |
| 50 |   |
| 51 | case tChunkID::Core_Name:  |
| 52 | chunk.GetItem(Name);  |
| 53 | break;  |
| 54 |   |
| 55 | case tChunkID::Scene_AttributeList:  |
| 56 | Attributes.Load(chunk);  |
| 57 | break;  |
| 58 | }  |
| 59 | }  |
| 60 | }  |
| 61 |   |
| 62 |   |
| 63 | }  |
| 64 | |