ScummVM API documentation
World3D.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_WORLD3D_H
29 #define HPL_WORLD3D_H
30 
31 #include "hpl1/engine/graphics/GraphicsTypes.h"
32 #include "hpl1/engine/math/MathTypes.h"
33 #include "hpl1/engine/system/SystemTypes.h"
34 
35 #include "hpl1/engine/scene/Entity3D.h"
36 #include "hpl1/engine/scene/SoundSource.h"
37 
38 #include "hpl1/engine/game/GameTypes.h"
39 
40 #include "hpl1/engine/game/SaveGame.h"
41 
42 class TiXmlElement;
43 
44 namespace hpl {
45 
46 class cGraphics;
47 class cResources;
48 class cSound;
49 class cPhysics;
50 class cScene;
51 class cSystem;
52 class cAI;
53 
54 class iCamera;
55 class cCamera3D;
56 class cNode3D;
57 class cLight3DSpot;
58 class cLight3DPoint;
59 class iLight3D;
60 class cImageEntity;
61 class cParticleManager;
62 class cParticleSystem3D;
63 class iScript;
64 class cPortalContainer;
65 class iRenderableContainer;
66 class cMeshEntity;
67 class cMesh;
68 class cBillboard;
69 class cBeam;
70 class iPhysicsWorld;
71 class cColliderEntity;
72 class iPhysicsBody;
73 class cSoundEntity;
74 class cAINodeContainer;
75 class cAStarHandler;
76 class cAINodeGeneratorParams;
77 
78 typedef Common::List<iLight3D *> tLight3DList;
79 typedef Common::List<iLight3D *>::iterator tLight3DListIt;
80 
81 typedef Common::List<cMeshEntity *> tMeshEntityList;
82 typedef Common::List<cMeshEntity *>::iterator tMeshEntityListIt;
83 
84 typedef Common::List<cBillboard *> tBillboardList;
85 typedef Common::List<cBillboard *>::iterator tBillboardListIt;
86 
87 typedef Common::List<cBeam *> tBeamList;
88 typedef Common::List<cBeam *>::iterator tBeamListIt;
89 
90 typedef Common::List<cParticleSystem3D *> tParticleSystem3DList;
91 typedef tParticleSystem3DList::iterator tParticleSystem3DListIt;
92 
93 typedef Common::List<cColliderEntity *> tColliderEntityList;
94 typedef Common::List<cColliderEntity *>::iterator tColliderEntityListIt;
95 
96 typedef Common::List<cSoundEntity *> tSoundEntityList;
97 typedef Common::List<cSoundEntity *>::iterator tSoundEntityListIt;
98 
99 typedef Common::List<cAINodeContainer *> tAINodeContainerList;
100 typedef Common::List<cAINodeContainer *>::iterator tAINodeContainerListIt;
101 
102 typedef Common::List<cAStarHandler *> tAStarHandlerList;
103 typedef Common::List<cAStarHandler *>::iterator tAStarHandlerIt;
104 
105 //-------------------------------------------------------------------
106 
107 typedef cSTLIterator<cMeshEntity *, tMeshEntityList, tMeshEntityListIt> cMeshEntityIterator;
108 typedef cSTLIterator<cBillboard *, tBillboardList, tBillboardListIt> cBillboardIterator;
109 typedef cSTLIterator<iLight3D *, tLight3DList, tLight3DListIt> cLight3DListIterator;
110 typedef cSTLIterator<cParticleSystem3D *, tParticleSystem3DList, tParticleSystem3DListIt> cParticleSystem3DIterator;
111 typedef cSTLIterator<cSoundEntity *, tSoundEntityList, tSoundEntityListIt> cSoundEntityIterator;
112 typedef cSTLIterator<cBeam *, tBeamList, tBeamListIt> cBeamIterator;
113 
114 //-------------------------------------------------------------------
115 
116 class cTempAiNode {
117 public:
118  cTempAiNode(const cVector3f &avPos, const tString &asName) : mvPos(avPos), msName(asName) {}
119  cVector3f mvPos;
120  tString msName;
121 };
122 
125 
127 public:
128  tString msName;
129  tTempAiNodeList mlstNodes;
130 };
131 
133 typedef Common::StableMap<tString, cTempNodeContainer *>::iterator tTempNodeContainerMapIt;
134 
135 //-------------------------------------------------------------------
136 
137 class cAreaEntity : public iSerializable {
138  kSerializableClassInit(cAreaEntity) public : tString msName;
139  tString msType;
140  cMatrixf m_mtxTransform;
141  cVector3f mvSize;
142 };
143 
145 typedef tAreaEntityMap::iterator tAreaEntityMapIt;
146 
147 //-------------------------------------------------------------------
148 
150  kSerializableClassInit(cStartPosEntity) public : cStartPosEntity() {}
151  cStartPosEntity(const tString &asName) : msName(asName) {}
152 
153  cMatrixf &GetWorldMatrix() { return m_mtxTransform; }
154  cMatrixf &GetLocalMatrix() { return m_mtxTransform; }
155  void SetMatrix(const cMatrixf &a_mtxTrans) { m_mtxTransform = a_mtxTrans; }
156 
157  tString &GetName() { return msName; }
158 
159  cMatrixf m_mtxTransform;
160  tString msName;
161 };
162 
165 
166 //------------------------------------------
167 
168 kSaveData_BaseClass(cWorld3D) {
169  kSaveData_ClassInit(cWorld3D) public : cContainerList<cStartPosEntity> mlstStartpos;
170  cContainerList<cAreaEntity> mlstAreaEntities;
171  cContainerList<cScriptVar> mlstScriptVars;
172 
173  virtual iSaveObject *CreateSaveObject(cSaveObjectHandler * apSaveObjectHandler, cGame * apGame);
174  virtual int GetSaveCreatePrio();
175 };
176 
177 //-------------------------------------------------------------------
178 
179 class cWorld3D {
180 public:
181  cWorld3D(tString asName, cGraphics *apGraphics, cResources *apResources, cSound *apSound,
182  cPhysics *apPhysics, cScene *apScene, cSystem *apSystem, cAI *apAI);
183  ~cWorld3D();
184 
185  tString GetName() { return msName; }
186 
187  bool CreateFromFile(tString asFile);
188 
189  void SetFileName(const tString &asFile) { msFileName = asFile; }
190  const tString &GetFileName() { return msFileName; }
191 
192  void Update(float afTimeStep);
193 
194  void PreUpdate(float afTotalTime, float afTimeStep);
195 
196  cVector3f GetWorldSize() { return mvWorldSize; }
197 
198  iScript *GetScript() { return mpScript; }
199  void SetScript(iScript *apScript) { mpScript = apScript; }
200 
201  iRenderableContainer *GetRenderContainer();
202  cPortalContainer *GetPortalContainer();
203 
204  cPhysics *GetPhysics() { return mpPhysics; }
205  cResources *GetResources() { return mpResources; }
206  cSound *GetSound() { return mpSound; }
207  cSystem *GetSystem() { return mpSystem; }
208 
209  iEntity3D *CreateEntity(const tString &asName, const cMatrixf &a_mtxTransform,
210  const tString &asFile, bool abLoadReferences);
214  void SetUpData();
215 
216  void AddSaveData(cSaveDataHandler *apHandler);
217 
219 
220  void SetPhysicsWorld(iPhysicsWorld *apWorld, bool abAutoDelete = true);
221  iPhysicsWorld *GetPhysicsWorld();
222 
224 
225  cAreaEntity *CreateAreaEntity(const tString &asName);
226  cAreaEntity *GetAreaEntity(const tString &asName);
227  tAreaEntityMap *GetAreaEntityMap() { return &m_mapAreaEntities; }
228 
230 
231  cMeshEntity *CreateMeshEntity(const tString &asName, cMesh *apMesh, bool abAddToContainer = true);
232  void DestroyMeshEntity(cMeshEntity *apMesh);
233  cMeshEntity *GetMeshEntity(const tString &asName);
234 
235  cMeshEntityIterator GetMeshEntityIterator();
236 
237  void DrawMeshBoundingBoxes(const cColor &aColor, bool abStatic);
238 
240 
241  cLight3DPoint *CreateLightPoint(const tString &asName = "", bool abAddToContainer = true);
242  cLight3DSpot *CreateLightSpot(const tString &asName = "", const tString &asGobo = "",
243  bool abAddToContainer = true);
244  void DestroyLight(iLight3D *apLight);
245  iLight3D *GetLight(const tString &asName);
246 
247  tLight3DList *GetLightList() { return &mlstLights; }
248 
249  cLight3DListIterator GetLightIterator() { return cLight3DListIterator(&mlstLights); }
250 
252 
253  cBillboard *CreateBillboard(const tString &asName, const cVector2f &avSize,
254  const tString &asMaterial = "",
255  bool abAddToContainer = true, cMatrixf *apTransform = NULL);
256  void DestroyBillboard(cBillboard *apObject);
257  cBillboard *GetBillboard(const tString &asName);
258  cBillboardIterator GetBillboardIterator();
259 
261 
262  cBeam *CreateBeam(const tString &asName);
263  void DestroyBeam(cBeam *apObject);
264  cBeam *GetBeam(const tString &asName);
265  cBeamIterator GetBeamIterator();
266 
268 
269  cParticleSystem3D *CreateParticleSystem(const tString &asName, const tString &asType,
270  const cVector3f &avSize, const cMatrixf &a_mtxTransform);
271  void DestroyParticleSystem(cParticleSystem3D *apPS);
272  cParticleSystem3D *GetParticleSystem(const tString &asName);
273  bool ParticleSystemExists(cParticleSystem3D *apPS);
274 
275  cParticleSystem3DIterator GetParticleSystemIterator() { return cParticleSystem3DIterator(&mlstParticleSystems); }
276 
278 
279  cColliderEntity *CreateColliderEntity(const tString &asName, iPhysicsBody *apBody);
280  void DestroyColliderEntity(cColliderEntity *apCollider);
281  cColliderEntity *GetColliderEntity(const tString &asName);
282 
284 
285  cSoundEntity *CreateSoundEntity(const tString &asName, const tString &asSoundEntity,
286  bool abRemoveWhenOver);
287  void DestroySoundEntity(cSoundEntity *apEntity);
288  cSoundEntity *GetSoundEntity(const tString &asName);
289  void DestroyAllSoundEntities();
290  bool SoundEntityExists(cSoundEntity *apEntity);
291 
292  cSoundEntityIterator GetSoundEntityIterator() { return cSoundEntityIterator(&mlstSoundEntities); }
293 
295 
296  cStartPosEntity *CreateStartPos(const tString &asName);
297  cStartPosEntity *GetStartPosEntity(const tString &asName);
298  cStartPosEntity *GetFirstStartPosEntity();
299 
301 
302  void GenerateAINodes(cAINodeGeneratorParams *apParams);
303 
304  cAINodeContainer *CreateAINodeContainer(const tString &asName,
305  const tString &asNodeName,
306  const cVector3f &avSize,
307  bool abNodeIsAtCenter,
308  int alMinEdges, int alMaxEdges, float afMaxEdgeDistance,
309  float afMaxHeight);
310 
311  cAStarHandler *CreateAStarHandler(cAINodeContainer *apContainer);
312 
313  void AddAINode(const tString &asName, const tString &asType, const cVector3f &avPosition);
314  tTempAiNodeList *GetAINodeList(const tString &asType);
315 
317  // Remove this for the time being, not need it seems.
318  // cNode3D* GetRootNode(){ return mpRootNode; }
319 
320 private:
321  iSaveData *CreateSaveData();
322 
323  // Update
324  void UpdateEntities(float afTimeStep);
325  void UpdateBodies(float afTimeStep);
326  void UpdateParticles(float afTimeStep);
327  void UpdateLights(float afTimeStep);
328  void UpdateSoundEntities(float afTimeStep);
329 
330  tString msName;
331  tString msFileName;
332  cGraphics *mpGraphics;
333  cSound *mpSound;
334  cResources *mpResources;
335  cPhysics *mpPhysics;
336  cScene *mpScene;
337  cSystem *mpSystem;
338  cAI *mpAI;
339 
340  iPhysicsWorld *mpPhysicsWorld;
341  bool mbAutoDeletePhysicsWorld;
342 
343  cVector3f mvWorldSize;
344 
345  cPortalContainer *mpPortalContainer;
346 
347  iScript *mpScript;
348 
349  tLight3DList mlstLights;
350  tMeshEntityList mlstMeshEntities;
351  tBillboardList mlstBillboards;
352  tBeamList mlstBeams;
353  tParticleSystem3DList mlstParticleSystems;
354  tColliderEntityList mlstColliders;
355  tSoundEntityList mlstSoundEntities;
356  tStartPosEntityList mlstStartPosEntities;
357  tAreaEntityMap m_mapAreaEntities;
358 
359  tAINodeContainerList mlstAINodeContainers;
360  tAStarHandlerList mlstAStarHandlers;
361  tTempNodeContainerMap m_mapTempNodes;
362 
363  cNode3D *mpRootNode;
364 
365  tString msMapName;
366  cColor mAmbientColor;
367 };
368 
369 } // namespace hpl
370 
371 #endif // HPL_WOLRD3D_H
Definition: AI.h:36
Definition: Script.h:223
Definition: Game.h:91
Definition: str.h:59
Definition: World3D.h:116
Definition: Light3DPoint.h:46
Definition: AI.h:40
Definition: Light3D.h:117
Definition: Light3DSpot.h:54
Definition: AStar.h:84
Definition: PhysicsWorld.h:115
Definition: Mesh.h:215
typename TreeT::BasicIterator iterator
Definition: stablemap.h:48
Definition: ColliderEntity.h:40
Definition: SerializeClass.h:230
Definition: SaveGame.h:130
Definition: Sound.h:40
Definition: SaveGame.h:214
Definition: BillBoard.h:78
Definition: Node3D.h:52
Definition: PhysicsBody.h:117
Definition: World3D.h:179
Definition: SaveGame.h:111
Definition: Physics.h:67
Definition: AINodeContainer.h:158
Definition: Container.h:219
ListInternal::Iterator< t_T > iterator
Definition: list.h:52
Definition: World3D.h:126
Definition: ParticleSystem3D.h:90
Definition: Resources.h:160
Definition: Color.h:37
Definition: World3D.h:149
Definition: System.h:36
Definition: Entity3D.h:81
Definition: tinyxml.h:864
Definition: list_intern.h:51
Definition: PortalContainer.h:229
Definition: Scene.h:61
Definition: MeshEntity.h:96
Definition: SoundEntity.h:86
Definition: SaveGame.h:183
Definition: Graphics.h:46
Definition: World3D.h:137
Definition: Beam.h:80
Definition: RenderableContainer.h:41
Definition: AINodeGenerator.h:53