ScummVM API documentation
PortalContainer.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_PORTAL_CONTAINER_H
29#define HPL_PORTAL_CONTAINER_H
30
31#include "common/list.h"
32#include "hpl1/engine/graphics/Renderable.h"
33#include "hpl1/engine/math/BoundingVolume.h"
34#include "hpl1/engine/scene/RenderableContainer.h"
35#include "common/stablemap.h"
36#include "hpl1/std/set.h"
37
38namespace hpl {
39
40class iLight3D;
41class cSectorVisibilityContainer;
42
43typedef Common::List<iRenderable *> tRenderableList;
44typedef Common::List<iRenderable *>::iterator tRenderableListIt;
45
46typedef Hpl1::Std::set<iRenderable *> tRenderableSet;
47typedef Hpl1::Std::set<iRenderable *>::iterator tRenderableSetIt;
48
49typedef Hpl1::Std::set<iEntity3D *> tEntity3DSet;
50typedef Hpl1::Std::set<iEntity3D *>::iterator tEntity3DSetIt;
51
52//----------------------------------------------------
53
54class cPortalContainer;
55class cSector;
56
57//----------------------------------------------------
58
61
62//----------------------------------------------------
63
65public:
67 cBoundingVolume *apBV);
68
69 bool HasNext();
70
71 iEntity3D *Next();
72
73private:
74 cPortalContainer *mpContainer;
75 cBoundingVolume *mpBV;
76
77 tSectorMap *mpSectorMap;
78 tEntity3DSet *mpEntity3DSet;
79
80 tEntity3DSetIt mEntityIt;
81 tSectorMapIt mSectorIt;
82
83 tEntity3DSet mIteratedSet;
84
85 int mlIteratorCount;
86
87 bool mbGlobal;
88};
89
90//----------------------------------------------------
91
93public:
95
96 void OnTransformUpdate(iEntity3D *apEntity);
97
98private:
99 cPortalContainer *mpContainer;
100};
101
102//----------------------------------------------------
103
105public:
107
108 void OnTransformUpdate(iEntity3D *apEntity);
109
110private:
111 cPortalContainer *mpContainer;
112};
113
114//----------------------------------------------------
115
116class cSector;
117class cPortal;
118
121
124
125class cPortal {
126 friend class cSector;
127
128public:
129 cPortal(int alId, cPortalContainer *apContainer);
130 ~cPortal();
131
132 void SetTargetSector(tString asSectorId);
133 cSector *GetTargetSector();
134
135 cSector *GetSector();
136
137 void AddPortalId(int alId);
138 void SetNormal(const cVector3f &avNormal);
139 void AddPoint(const cVector3f &avPoint);
140 void SetTransform(const cMatrixf &a_mtxTrans);
141
142 void Compile();
143
144 bool IsVisible(cFrustum *apFrustum);
145
146 tPortalList *GetPortalList();
147
148 // Debug stuffs
149 cBoundingVolume *GetBV() { return &mBV; }
150 cVector3f GetNormal() { return mvNormal; }
151 int GetId() { return mlId; }
152 cPlanef &GetPlane() { return mPlane; }
153
154 bool GetActive() { return mbActive; }
155 void SetActive(bool abX) { mbActive = abX; }
156
157private:
158 cPortalContainer *mpContainer;
159
160 int mlId;
161 tString msSectorId;
162
163 tString msTargetSectorId;
164 cSector *mpTargetSector;
165 cSector *mpSector;
166
167 tIntVec mvPortalIds;
168 tPortalList mlstPortals;
169 bool mbPortalsNeedUpdate;
170
171 bool mbActive;
172
173 cVector3f mvNormal;
174 cPlanef mPlane;
175 cBoundingVolume mBV;
176 tVector3fList mlstPoints;
177};
178
179//----------------------------------------------------
180
182 friend class cPortalContainer;
184
185public:
186 cSector(tString asId, cPortalContainer *apContainer);
187 ~cSector();
188
189 bool TryToAdd(iRenderable *apObject, bool abStatic);
190 bool TryToAddEntity(iEntity3D *apEntity);
191
192 void AddPortal(cPortal *apPortal);
193
194 void GetVisible(cFrustum *apFrustum, cRenderList *apRenderList, cPortal *apStartPortal);
195
196 void RemoveDynamic(iRenderable *apObject);
197 void RemoveEntity(iEntity3D *apEntity);
198
199 cPortal *GetPortal(int alId);
200
201 void SetAmbientColor(const cColor &aAmbient) { mAmbient = aAmbient; }
202 const cColor &GetAmbientColor() { return mAmbient; }
203
204 // Debug stuffs
205 cBoundingVolume *GetBV() { return &mBV; }
206 tPortalList *GetPortalList() { return &mlstPortals; }
207 tString &GetId() { return msId; }
208
209private:
210 cPortalContainer *mpContainer;
211
212 tString msId;
213 cBoundingVolume mBV;
214
215 int mlVisitCount;
216
217 tRenderableSet m_setStaticObjects;
218 tRenderableSet m_setDynamicObjects;
219
220 tEntity3DSet m_setEntities;
221
222 tPortalList mlstPortals;
223
224 cColor mAmbient;
225};
226
227//----------------------------------------------------
228
230 friend class cPortalContainerCallback;
233
234public:
236 virtual ~cPortalContainer();
237
238 bool AddEntity(iEntity3D *pEntity);
239 bool RemoveEntity(iEntity3D *pEntity);
240
241 bool Add(iRenderable *apRenderable, bool abStatic);
242 bool Remove(iRenderable *apRenderable);
243
244 void AddLightShadowCasters(iLight3D *apLight, cFrustum *apFrustum, cRenderList *apRenderList);
245
246 void AddToRenderList(iRenderable *apObject, cFrustum *apFrustum, cRenderList *apRenderList);
247
248 void GetVisible(cFrustum *apFrustum, cRenderList *apRenderList);
249
250 void Compile();
251
252 // Portal Specific Stuff
256 void AddSector(tString asSectorId);
257
262 bool AddToSector(iRenderable *apRenderable, tString asSector);
263
264 /*
265 * Adds a portal to a sector.
266 */
267 bool AddPortal(cPortal *apPortal, tString asSector);
268
269 cSector *GetSector(tString asId);
270
271 int GetSectorVisitCount() const { return mlSectorVisitCount; }
272
273 cPortalContainerEntityIterator GetEntityIterator(cBoundingVolume *apBV);
274
275 // Visibility tools
276 cSectorVisibilityContainer *CreateVisibiltyFromBV(cBoundingVolume *apBV);
277 cSectorVisibilityContainer *CreateVisibiltyFromFrustum(cFrustum *apFrustum);
278
279 // Debug stuff
280 tSectorMap *GetSectorMap() { return &m_mapSectors; }
281 tStringList *GetVisibleSectorsList() { return &mlstVisibleSectors; }
282
283 tRenderableSet *GetGlobalDynamicObjectSet() { return &m_setGlobalDynamicObjects; }
284 tRenderableList *GetGlobalStaticObjectList() { return &mlstGlobalStaticObjects; }
285
286private:
287 void ComputeSectorVisibilty(cSectorVisibilityContainer *apContainer);
288
289 tSectorMap m_mapSectors;
290
291 int mlSectorVisitCount;
292
293 cPortalContainerCallback *mpEntityCallback;
294 cPortalContainerEntityCallback *mpNormalEntityCallback;
295
296 // List with dynamic objects that are not in any sector.
297 tRenderableSet m_setGlobalDynamicObjects;
298 // List with static objects that are not in any sector.
299 tRenderableList mlstGlobalStaticObjects;
300
301 // Global dynamic entities
302 tEntity3DSet m_setGlobalEntities;
303
304 tStringList mlstVisibleSectors;
305
306 int mlEntityIterateCount;
307};
308
309} // namespace hpl
310
311#endif // HPL_PORTAL_CONTAINER_H
typename TreeT::BasicIterator iterator
Definition: stablemap.h:48
Definition: str.h:59
Definition: BoundingVolume.h:71
Definition: Color.h:37
Definition: Frustum.h:57
Definition: PortalContainer.h:92
Definition: PortalContainer.h:104
Definition: PortalContainer.h:64
Definition: PortalContainer.h:229
bool AddToSector(iRenderable *apRenderable, tString asSector)
void GetVisible(cFrustum *apFrustum, cRenderList *apRenderList)
void AddSector(tString asSectorId)
bool Add(iRenderable *apRenderable, bool abStatic)
bool Remove(iRenderable *apRenderable)
Definition: PortalContainer.h:125
Definition: RenderList.h:145
Definition: PortalContainer.h:181
Definition: SectorVisibility.h:136
Definition: Entity3D.h:81
Definition: Entity3D.h:44
Definition: Light3D.h:117
Definition: Entity3D.h:57
Definition: RenderableContainer.h:41
Definition: Renderable.h:70
Definition: list_intern.h:54