| 1 | // tSelection.cpp  |
| 2 | //  |
| 3 | // This file implements scene selection sets. A selection is simply a collection of scene instances referenced by ID.  |
| 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/tSelection.h"  |
| 16 | namespace tScene  |
| 17 | {  |
| 18 |   |
| 19 |   |
| 20 | void tSelection::Save(tChunkWriter& chunk) const  |
| 21 | {  |
| 22 | chunk.Begin(tChunkID::Scene_Selection);  |
| 23 | {  |
| 24 | tObject::Save(chunk);  |
| 25 |   |
| 26 | chunk.Begin(tChunkID::Scene_SelectionInstanceIDs);  |
| 27 | {  |
| 28 | for (tItList<uint32>::Iter instIDIter = InstanceIDs.First(); instIDIter; ++instIDIter)  |
| 29 | {  |
| 30 | uint32* instID = instIDIter.GetObject();  |
| 31 | chunk.Write(*instID);  |
| 32 | }  |
| 33 | }  |
| 34 | chunk.End();  |
| 35 | }  |
| 36 | chunk.End();  |
| 37 | }  |
| 38 |   |
| 39 |   |
| 40 | void tSelection::Load(const tChunk& selSetChunk)  |
| 41 | {  |
| 42 | tAssert(selSetChunk.ID() == tChunkID::Scene_Selection);  |
| 43 | Clear();  |
| 44 |   |
| 45 | for (tChunk chunk = selSetChunk.First(); chunk.Valid(); chunk = chunk.Next())  |
| 46 | {  |
| 47 | switch (chunk.ID())  |
| 48 | {  |
| 49 | case tChunkID::Scene::Scene_Object:  |
| 50 | tObject::Load(chunk);  |
| 51 | break;  |
| 52 |   |
| 53 | case tChunkID::Scene_SelectionInstanceIDs:  |
| 54 | {  |
| 55 | int numInstances = chunk.GetDataSize() / sizeof(uint32);  |
| 56 | for (int i = 0; i < numInstances; i++)  |
| 57 | {  |
| 58 | uint32 instID;  |
| 59 | chunk.GetItem(instID);  |
| 60 | InstanceIDs.Append(new uint32(instID));  |
| 61 | }  |
| 62 | break;  |
| 63 | }  |
| 64 | }  |
| 65 | }  |
| 66 | }  |
| 67 |   |
| 68 |   |
| 69 | }  |
| 70 | |