File: PortalContainer.h

package info (click to toggle)
scummvm 2.9.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 450,268 kB
  • sloc: cpp: 4,297,604; asm: 28,322; python: 12,901; sh: 11,219; java: 8,477; xml: 7,843; perl: 2,633; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (311 lines) | stat: -rw-r--r-- 8,021 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/*
 * Copyright (C) 2006-2010 - Frictional Games
 *
 * This file is part of HPL1 Engine.
 */

#ifndef HPL_PORTAL_CONTAINER_H
#define HPL_PORTAL_CONTAINER_H

#include "common/list.h"
#include "hpl1/engine/graphics/Renderable.h"
#include "hpl1/engine/math/BoundingVolume.h"
#include "hpl1/engine/scene/RenderableContainer.h"
#include "common/stablemap.h"
#include "hpl1/std/set.h"

namespace hpl {

class iLight3D;
class cSectorVisibilityContainer;

typedef Common::List<iRenderable *> tRenderableList;
typedef Common::List<iRenderable *>::iterator tRenderableListIt;

typedef Hpl1::Std::set<iRenderable *> tRenderableSet;
typedef Hpl1::Std::set<iRenderable *>::iterator tRenderableSetIt;

typedef Hpl1::Std::set<iEntity3D *> tEntity3DSet;
typedef Hpl1::Std::set<iEntity3D *>::iterator tEntity3DSetIt;

//----------------------------------------------------

class cPortalContainer;
class cSector;

//----------------------------------------------------

typedef Common::StableMap<tString, cSector *> tSectorMap;
typedef Common::StableMap<tString, cSector *>::iterator tSectorMapIt;

//----------------------------------------------------

class cPortalContainerEntityIterator {
public:
	cPortalContainerEntityIterator(cPortalContainer *apContainer,
								   cBoundingVolume *apBV);

	bool HasNext();

	iEntity3D *Next();

private:
	cPortalContainer *mpContainer;
	cBoundingVolume *mpBV;

	tSectorMap *mpSectorMap;
	tEntity3DSet *mpEntity3DSet;

	tEntity3DSetIt mEntityIt;
	tSectorMapIt mSectorIt;

	tEntity3DSet mIteratedSet;

	int mlIteratorCount;

	bool mbGlobal;
};

//----------------------------------------------------

class cPortalContainerCallback : public iEntityCallback {
public:
	cPortalContainerCallback(cPortalContainer *apContainer);

	void OnTransformUpdate(iEntity3D *apEntity);

private:
	cPortalContainer *mpContainer;
};

//----------------------------------------------------

class cPortalContainerEntityCallback : public iEntityCallback {
public:
	cPortalContainerEntityCallback(cPortalContainer *apContainer);

	void OnTransformUpdate(iEntity3D *apEntity);

private:
	cPortalContainer *mpContainer;
};

//----------------------------------------------------

class cSector;
class cPortal;

typedef Common::StableMap<int, cPortal *> tPortalMap;
typedef Common::StableMap<int, cPortal *>::iterator tPortalMapIt;

typedef Common::List<cPortal *> tPortalList;
typedef Common::List<cPortal *>::iterator tPortalListIt;

class cPortal {
	friend class cSector;

public:
	cPortal(int alId, cPortalContainer *apContainer);
	~cPortal();

	void SetTargetSector(tString asSectorId);
	cSector *GetTargetSector();

	cSector *GetSector();

	void AddPortalId(int alId);
	void SetNormal(const cVector3f &avNormal);
	void AddPoint(const cVector3f &avPoint);
	void SetTransform(const cMatrixf &a_mtxTrans);

	void Compile();

	bool IsVisible(cFrustum *apFrustum);

	tPortalList *GetPortalList();

	// Debug stuffs
	cBoundingVolume *GetBV() { return &mBV; }
	cVector3f GetNormal() { return mvNormal; }
	int GetId() { return mlId; }
	cPlanef &GetPlane() { return mPlane; }

	bool GetActive() { return mbActive; }
	void SetActive(bool abX) { mbActive = abX; }

private:
	cPortalContainer *mpContainer;

	int mlId;
	tString msSectorId;

	tString msTargetSectorId;
	cSector *mpTargetSector;
	cSector *mpSector;

	tIntVec mvPortalIds;
	tPortalList mlstPortals;
	bool mbPortalsNeedUpdate;

	bool mbActive;

	cVector3f mvNormal;
	cPlanef mPlane;
	cBoundingVolume mBV;
	tVector3fList mlstPoints;
};

//----------------------------------------------------

class cSector : public iRenderContainerData {
	friend class cPortalContainer;
	friend class cPortalContainerEntityIterator;

public:
	cSector(tString asId, cPortalContainer *apContainer);
	~cSector();

	bool TryToAdd(iRenderable *apObject, bool abStatic);
	bool TryToAddEntity(iEntity3D *apEntity);

	void AddPortal(cPortal *apPortal);

	void GetVisible(cFrustum *apFrustum, cRenderList *apRenderList, cPortal *apStartPortal);

	void RemoveDynamic(iRenderable *apObject);
	void RemoveEntity(iEntity3D *apEntity);

	cPortal *GetPortal(int alId);

	void SetAmbientColor(const cColor &aAmbient) { mAmbient = aAmbient; }
	const cColor &GetAmbientColor() { return mAmbient; }

	// Debug stuffs
	cBoundingVolume *GetBV() { return &mBV; }
	tPortalList *GetPortalList() { return &mlstPortals; }
	tString &GetId() { return msId; }

private:
	cPortalContainer *mpContainer;

	tString msId;
	cBoundingVolume mBV;

	int mlVisitCount;

	tRenderableSet m_setStaticObjects;
	tRenderableSet m_setDynamicObjects;

	tEntity3DSet m_setEntities;

	tPortalList mlstPortals;

	cColor mAmbient;
};

//----------------------------------------------------

class cPortalContainer : public iRenderableContainer {
	friend class cPortalContainerCallback;
	friend class cPortalContainerEntityCallback;
	friend class cPortalContainerEntityIterator;

public:
	cPortalContainer();
	virtual ~cPortalContainer();

	bool AddEntity(iEntity3D *pEntity);
	bool RemoveEntity(iEntity3D *pEntity);

	bool Add(iRenderable *apRenderable, bool abStatic);
	bool Remove(iRenderable *apRenderable);

	void AddLightShadowCasters(iLight3D *apLight, cFrustum *apFrustum, cRenderList *apRenderList);

	void AddToRenderList(iRenderable *apObject, cFrustum *apFrustum, cRenderList *apRenderList);

	void GetVisible(cFrustum *apFrustum, cRenderList *apRenderList);

	void Compile();

	// Portal Specific Stuff
	/**
	 * Adds a new sector to the container. All sectors must be created before anything else.
	 */
	void AddSector(tString asSectorId);

	/**
	 * Adds a new renderable to a specific sector.This also recalculates the sector's bounding volume.
	 * Object must be (and is considered) static!
	 */
	bool AddToSector(iRenderable *apRenderable, tString asSector);

	/*
	 * Adds a portal to a sector.
	 */
	bool AddPortal(cPortal *apPortal, tString asSector);

	cSector *GetSector(tString asId);

	int GetSectorVisitCount() const { return mlSectorVisitCount; }

	cPortalContainerEntityIterator GetEntityIterator(cBoundingVolume *apBV);

	// Visibility tools
	cSectorVisibilityContainer *CreateVisibiltyFromBV(cBoundingVolume *apBV);
	cSectorVisibilityContainer *CreateVisibiltyFromFrustum(cFrustum *apFrustum);

	// Debug stuff
	tSectorMap *GetSectorMap() { return &m_mapSectors; }
	tStringList *GetVisibleSectorsList() { return &mlstVisibleSectors; }

	tRenderableSet *GetGlobalDynamicObjectSet() { return &m_setGlobalDynamicObjects; }
	tRenderableList *GetGlobalStaticObjectList() { return &mlstGlobalStaticObjects; }

private:
	void ComputeSectorVisibilty(cSectorVisibilityContainer *apContainer);

	tSectorMap m_mapSectors;

	int mlSectorVisitCount;

	cPortalContainerCallback *mpEntityCallback;
	cPortalContainerEntityCallback *mpNormalEntityCallback;

	// List with dynamic objects that are not in any sector.
	tRenderableSet m_setGlobalDynamicObjects;
	// List with static objects that are not in any sector.
	tRenderableList mlstGlobalStaticObjects;

	// Global dynamic entities
	tEntity3DSet m_setGlobalEntities;

	tStringList mlstVisibleSectors;

	int mlEntityIterateCount;
};

} // namespace hpl

#endif // HPL_PORTAL_CONTAINER_H