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
42class TiXmlElement;
43
44namespace hpl {
45
46class cGraphics;
47class cResources;
48class cSound;
49class cPhysics;
50class cScene;
51class cSystem;
52class cAI;
53
54class iCamera;
55class cCamera3D;
56class cNode3D;
57class cLight3DSpot;
58class cLight3DPoint;
59class iLight3D;
60class cImageEntity;
61class cParticleManager;
62class cParticleSystem3D;
63class iScript;
64class cPortalContainer;
65class iRenderableContainer;
66class cMeshEntity;
67class cMesh;
68class cBillboard;
69class cBeam;
70class iPhysicsWorld;
71class cColliderEntity;
72class iPhysicsBody;
73class cSoundEntity;
74class cAINodeContainer;
75class cAStarHandler;
76class cAINodeGeneratorParams;
77
78typedef Common::List<iLight3D *> tLight3DList;
79typedef Common::List<iLight3D *>::iterator tLight3DListIt;
80
81typedef Common::List<cMeshEntity *> tMeshEntityList;
82typedef Common::List<cMeshEntity *>::iterator tMeshEntityListIt;
83
84typedef Common::List<cBillboard *> tBillboardList;
85typedef Common::List<cBillboard *>::iterator tBillboardListIt;
86
87typedef Common::List<cBeam *> tBeamList;
88typedef Common::List<cBeam *>::iterator tBeamListIt;
89
90typedef Common::List<cParticleSystem3D *> tParticleSystem3DList;
91typedef tParticleSystem3DList::iterator tParticleSystem3DListIt;
92
93typedef Common::List<cColliderEntity *> tColliderEntityList;
94typedef Common::List<cColliderEntity *>::iterator tColliderEntityListIt;
95
96typedef Common::List<cSoundEntity *> tSoundEntityList;
97typedef Common::List<cSoundEntity *>::iterator tSoundEntityListIt;
98
99typedef Common::List<cAINodeContainer *> tAINodeContainerList;
100typedef Common::List<cAINodeContainer *>::iterator tAINodeContainerListIt;
101
102typedef Common::List<cAStarHandler *> tAStarHandlerList;
103typedef Common::List<cAStarHandler *>::iterator tAStarHandlerIt;
104
105//-------------------------------------------------------------------
106
107typedef cSTLIterator<cMeshEntity *, tMeshEntityList, tMeshEntityListIt> cMeshEntityIterator;
108typedef cSTLIterator<cBillboard *, tBillboardList, tBillboardListIt> cBillboardIterator;
109typedef cSTLIterator<iLight3D *, tLight3DList, tLight3DListIt> cLight3DListIterator;
110typedef cSTLIterator<cParticleSystem3D *, tParticleSystem3DList, tParticleSystem3DListIt> cParticleSystem3DIterator;
111typedef cSTLIterator<cSoundEntity *, tSoundEntityList, tSoundEntityListIt> cSoundEntityIterator;
112typedef cSTLIterator<cBeam *, tBeamList, tBeamListIt> cBeamIterator;
113
114//-------------------------------------------------------------------
115
117public:
118 cTempAiNode(const cVector3f &avPos, const tString &asName) : mvPos(avPos), msName(asName) {}
119 cVector3f mvPos;
120 tString msName;
121};
122
125
127public:
128 tString msName;
129 tTempAiNodeList mlstNodes;
130};
131
134
135//-------------------------------------------------------------------
136
138 kSerializableClassInit(cAreaEntity) public : tString msName;
139 tString msType;
140 cMatrixf m_mtxTransform;
141 cVector3f mvSize;
142};
143
145typedef 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
168kSaveData_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
179class cWorld3D {
180public:
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
320private:
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
ListInternal::Iterator< cParticleSystem3D * > iterator
Definition: list.h:52
typename TreeT::BasicIterator iterator
Definition: stablemap.h:48
Definition: str.h:59
Definition: tinyxml.h:864
Definition: AI.h:40
Definition: World3D.h:137
Definition: Color.h:37
Definition: Container.h:219
Definition: Game.h:91
Definition: Graphics.h:46
Definition: Light3DPoint.h:46
Definition: Light3DSpot.h:54
Definition: MeshEntity.h:96
Definition: Mesh.h:215
Definition: Physics.h:67
Definition: PortalContainer.h:229
Definition: Resources.h:160
Definition: SystemTypes.h:411
Definition: SaveGame.h:214
Definition: SaveGame.h:183
Definition: Scene.h:61
Definition: Sound.h:40
Definition: World3D.h:149
Definition: System.h:36
Definition: World3D.h:116
Definition: World3D.h:126
Definition: World3D.h:179
void SetUpData()
Definition: Entity3D.h:81
Definition: Light3D.h:117
Definition: PhysicsWorld.h:115
Definition: RenderableContainer.h:41
Definition: SaveGame.h:130
Definition: Script.h:223
Definition: SerializeClass.h:230
Definition: list_intern.h:54