ScummVM API documentation
SaveGame.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * Copyright (C) 2006-2010 - Frictional Games
24  *
25  * This file is part of HPL1 Engine.
26  */
27 
28 #ifndef HPL_SAVE_GAME_H
29 #define HPL_SAVE_GAME_H
30 
31 #include "hpl1/engine/system/SerializeClass.h"
32 #include "hpl1/engine/system/SystemTypes.h"
33 #include "common/stablemap.h"
34 #include "common/multimap.h"
35 
36 class TiXmlElement;
37 
38 #define kSaveData_LoadFromBegin(aClass) \
39  super::LoadFromSaveData(apSaveData); \
40  cSaveData_##aClass *pData = static_cast<cSaveData_##aClass *>(apSaveData); \
41  assert(pData != nullptr);
42 
43 #define kSaveData_SaveToBegin(aClass) \
44  super::SaveToSaveData(apSaveData); \
45  cSaveData_##aClass *pData = static_cast<cSaveData_##aClass *>(apSaveData); \
46  assert(pData != nullptr);
47 
48 #define kSaveData_SetupBegin(aClass) \
49  super::SaveDataSetup(apSaveObjectHandler, apGame); \
50  cSaveData_##aClass *pData = static_cast<cSaveData_##aClass *>(mpSaveData); \
51  assert(pData != nullptr);
52 
53 #define kSaveData_BaseClass(aClass) class cSaveData_##aClass : public iSaveData
54 #define kSaveData_ChildClass(aParent, aChild) class cSaveData_##aChild : public cSaveData_##aParent
55 
56 #define kSaveData_ClassInit(aClass) kSerializableClassInit(cSaveData_##aClass)
57 
59 // Helpers to copy data.
60 #define kSaveData_SaveTo(aVar) pData->aVar = aVar;
61 #define kSaveData_LoadFrom(aVar) aVar = pData->aVar;
62 
63 #define kSaveData_SaveObject(aObject, aId) \
64  if (aObject) \
65  pData->aId = aObject->GetSaveObjectId(); \
66  else \
67  pData->aId = -1;
68 
69 // Only used in setup:
70 #define kSaveData_LoadObject(aObject, aId, aClass) \
71  if (pData->aId == -1) \
72  aObject = NULL; \
73  else { \
74  aObject = static_cast<aClass>(apSaveObjectHandler->Get(pData->aId)); \
75  }
76 
78 // Helpers to copy containers with SaveDataId
79 #define kSaveData_SaveIdList(aSrcList, aSrcIt, aDestList) \
80  pData->aDestList.Clear(); \
81  for (aSrcIt it = aSrcList.begin(); it != aSrcList.end(); ++it) { \
82  pData->aDestList.Add((*it)->GetSaveObjectId()); \
83  }
84 
85 // Only used in setup:
86 #define kSaveData_LoadIdList(aSrcList, aDestList, aClass) \
87  { \
88  cContainerListIterator<int> it = pData->aDestList.GetIterator(); \
89  aSrcList.clear(); \
90  while (it.HasNext()) { \
91  int lId = it.Next(); \
92  iSaveObject *pObject = apSaveObjectHandler->Get(lId); \
93  if (pObject == NULL) { \
94  continue; \
95  } \
96  aSrcList.push_back(static_cast<aClass>(pObject)); \
97  } \
98  }
99 
100 namespace hpl {
101 
102 //--------------------------------------------------------
103 
104 class cSaveObjectHandler;
105 class iSaveObject;
106 class cGame;
107 
111 class iSaveData : public iSerializable {
112  kSerializableClassInit(iSaveData) public : int mlSaveDataId;
113 
117  virtual iSaveObject *CreateSaveObject(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame) = 0;
118 
122  virtual int GetSaveCreatePrio() = 0;
123 };
124 
125 //--------------------------------------------------------
126 
130 class iSaveObject {
131  friend class cSaveObjectHandler;
132 
133 public:
134  iSaveObject();
135  virtual ~iSaveObject();
136 
140  int GetSaveObjectId() { return mlSaveObjectId; }
141 
145  virtual void SaveToSaveData(iSaveData *apSaveData);
149  virtual void LoadFromSaveData(iSaveData *apSaveData);
150 
154  virtual iSaveData *CreateSaveData() = 0;
155 
159  virtual void SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame);
160 
161  void SetIsSaved(bool abX) { mbIsSaved = abX; }
162  bool IsSaved() { return mbIsSaved; }
163 
164 protected:
165  iSaveData *mpSaveData;
166 
167 private:
168  int mlSaveObjectId;
169  bool mbIsSaved;
170  static int _mlGlobalIdCount;
171 };
172 
173 //---------------------------------------------------------
174 
176 typedef tSaveObjectMap::iterator tSaveObjectMapIt;
177 
179 
184 public:
187 
188 public:
189  void Add(iSaveObject *pObject);
190 
191  iSaveObject *Get(int alId);
192 
193  cSaveObjectIterator GetIterator();
194 
195  void SetUpAll(cGame *apGame);
196 
197  void Clear();
198  size_t Size();
199 
200 private:
201  tSaveObjectMap m_mapSaveObjects;
202 };
203 
204 //---------------------------------------------------------
205 
207 typedef tSaveDataMap::iterator tSaveDataMapIt;
208 
210 
214 class cSaveDataHandler : public iContainer {
215 public:
217  ~cSaveDataHandler();
218 
219  void Add(iSaveData *pData);
220 
221  cSaveDataIterator GetIterator();
222 
223  void Clear();
224  size_t Size();
225 
226 private:
227  void AddVoidPtr(void **apPtr);
228  void AddVoidClass(void *apClass);
229 
230  iContainerIterator *CreateIteratorPtr();
231 
232  tSaveDataMap m_mapSaveData;
233 };
234 
235 //---------------------------------------------------------
236 
237 } // namespace hpl
238 
239 #endif // HPL_SAVE_GAME_H
Definition: AI.h:36
Definition: Game.h:91
int GetSaveObjectId()
Definition: SaveGame.h:140
Definition: Container.h:40
Definition: SystemTypes.h:467
Definition: Container.h:54
Definition: SerializeClass.h:230
Definition: SaveGame.h:130
Definition: SaveGame.h:214
Definition: SaveGame.h:111
Definition: tinyxml.h:864
Definition: SaveGame.h:183