Torque3D Documentation / _generateds / scenePersist.cpp

scenePersist.cpp

Engine/source/lighting/common/scenePersist.cpp

More...

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "platform/platform.h"
 25#include "lighting/common/scenePersist.h"
 26
 27#include "lighting/lightingInterfaces.h"
 28#include "scene/sceneManager.h"
 29#include "lighting/lightManager.h"
 30
 31
 32U32 PersistInfo::smFileVersion   = 0x11;
 33
 34PersistInfo::~PersistInfo()
 35{
 36   for(U32 i = 0; i < mChunks.size(); i++)
 37      delete mChunks[i];
 38}
 39
 40//------------------------------------------------------------------------------
 41bool PersistInfo::read(Stream & stream)
 42{
 43   U32 version;
 44   if(!stream.read(&version) || version != smFileVersion)
 45      return(false);
 46
 47   U32 numChunks;
 48   if(!stream.read(&numChunks))
 49      return(false);
 50
 51   if(numChunks == 0)
 52      return(false);
 53
 54   // read in all the chunks
 55   for(U32 i = 0; i < numChunks; i++)
 56   {
 57      U32 chunkType;
 58      if(!stream.read(&chunkType))
 59         return(false);
 60
 61      // MissionChunk must be first chunk
 62      if(i == 0 && chunkType != PersistChunk::MissionChunkType)
 63         return(false);
 64      if(i != 0 && chunkType == PersistChunk::MissionChunkType)
 65         return(false);
 66
 67      // Create the right chunk for the system 
 68      bool bChunkFound = false; 
 69      SceneLightingInterfaces sli = LIGHTMGR->getSceneLightingInterface()->mAvailableSystemInterfaces;
 70      for(SceneLightingInterface** itr = sli.begin(); itr != sli.end() && !bChunkFound; itr++)
 71      {
 72         PersistInfo::PersistChunk* pc = (*itr)->createPersistChunk(chunkType);
 73         if (pc != NULL)
 74         {
 75            mChunks.push_back(pc);
 76            bChunkFound = true;            
 77         }
 78      }
 79         
 80      if (!bChunkFound)
 81      {
 82         // create the chunk
 83         switch(chunkType)
 84         {
 85         case PersistChunk::MissionChunkType:
 86            mChunks.push_back(new PersistInfo::MissionChunk);
 87            break;
 88
 89         default:
 90            return(false);
 91            break;
 92         }
 93      }
 94
 95      // load the chunk info
 96      if(!mChunks[i]->read(stream))
 97         return(false);
 98   }
 99
100   return(true);
101}
102
103bool PersistInfo::write(Stream & stream)
104{
105   if(!stream.write(smFileVersion))
106      return(false);
107
108   if(!stream.write((U32)mChunks.size()))
109      return(false);
110
111   for(U32 i = 0; i < mChunks.size(); i++)
112   {
113      if(!stream.write(mChunks[i]->mChunkType))
114         return(false);
115      if(!mChunks[i]->write(stream))
116         return(false);
117   }
118
119   return(true);
120}
121
122//------------------------------------------------------------------------------
123// Class SceneLighting::PersistInfo::PersistChunk
124//------------------------------------------------------------------------------
125bool PersistInfo::PersistChunk::read(Stream & stream)
126{
127   if(!stream.read(&mChunkCRC))
128      return(false);
129   return(true);
130}
131
132bool PersistInfo::PersistChunk::write(Stream & stream)
133{
134   if(!stream.write(mChunkCRC))
135      return(false);
136   return(true);
137}
138
139//------------------------------------------------------------------------------
140// Class SceneLighting::PersistInfo::MissionChunk
141//------------------------------------------------------------------------------
142PersistInfo::MissionChunk::MissionChunk()
143{
144   mChunkType = PersistChunk::MissionChunkType;
145}
146