-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
sector.h
487 lines (404 loc) · 15.1 KB
/
sector.h
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/** @file sector.h Map Sector.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>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 2 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, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifndef LIBDENG_MAP_SECTOR
#define LIBDENG_MAP_SECTOR
#include <QList>
#include <de/aabox.h>
#include <de/Error>
#include <de/Observers>
#include "map/plane.h"
#include "p_mapdata.h"
#include "p_dmu.h"
#include "MapElement"
class BspLeaf;
class LineDef;
/**
* @defgroup sectorFrameFlags Sector frame flags
* @ingroup map
*/
///@{
#define SIF_VISIBLE 0x1 ///< Sector is visible on this frame.
#define SIF_LIGHT_CHANGED 0x2
// Flags to clear before each frame.
#define SIF_FRAME_CLEAR SIF_VISIBLE
///@}
/**
* Map sector.
*
* @ingroup map
*/
class Sector : public de::MapElement
{
public:
/// Required/referenced plane is missing. @ingroup errors
DENG2_ERROR(MissingPlaneError);
/// The referenced property does not exist. @ingroup errors
DENG2_ERROR(UnknownPropertyError);
/// The referenced property is not writeable. @ingroup errors
DENG2_ERROR(WritePropertyError);
DENG2_DEFINE_AUDIENCE(LightLevelChange,
void lightLevelChanged(Sector §or, float oldLightLevel))
DENG2_DEFINE_AUDIENCE(LightColorChange,
void lightColorChanged(Sector §or, de::Vector3f const &oldLightColor,
int changedComponents /*bit-field (0x1=Red, 0x2=Green, 0x4=Blue)*/))
static float const DEFAULT_LIGHT_LEVEL; ///< 1.f
static de::Vector3f const DEFAULT_LIGHT_COLOR; ///< red=1.f green=1.f, blue=1.f
typedef QList<LineDef *> Lines;
typedef QList<Plane *> Planes;
typedef QList<BspLeaf *> BspLeafs;
/**
* LightGrid data values for "smoothed sector lighting".
*/
struct LightGridData
{
/// Number of blocks attributed to the sector.
uint blockCount;
/// Number of attributed blocks to mark changed.
uint changedBlockCount;
/// Block indices.
ushort *blocks;
};
public: /// @todo Make private:
/// @ref sectorFrameFlags
int _frameFlags;
/// if == validCount, already checked.
int _validCount;
/// Ambient light level in the sector.
float _lightLevel;
/// Old ambient light level in the sector. For smoothing.
float _oldLightLevel;
/// Ambient light color in the sector.
de::Vector3f _lightColor;
/// Old ambient light color in the sector. For smoothing.
de::Vector3f _oldLightColor;
/// Head of the linked list of mobjs "in" the sector (not owned).
struct mobj_s *_mobjList;
/// List of BSP leafs which contribute to the environmental audio
/// characteristics of the sector (not owned).
BspLeafs _reverbBspLeafs;
/// List of sector planes (owned).
Planes _planes;
/// LightGrid data values.
LightGridData _lightGridData;
/// Final environmental audio characteristics.
AudioEnvironmentFactors _reverb;
/// Original index in the archived map.
int _origIndex;
public:
Sector(float lightLevel = DEFAULT_LIGHT_LEVEL,
de::Vector3f const &lightColor = DEFAULT_LIGHT_COLOR);
/**
* Returns the first mobj in the linked list of mobjs "in" the sector.
*/
struct mobj_s *firstMobj() const;
/**
* Returns the primary sound emitter for the sector. Other emitters in the
* sector are linked to this, forming a chain which can be traversed using
* the 'next' pointer of the emitter's thinker_t.
*/
ddmobj_base_t &soundEmitter();
/// @copydoc soundEmitter()
ddmobj_base_t const &soundEmitter() const;
/**
* Returns the final environmental audio characteristics of the sector.
*/
AudioEnvironmentFactors const &audioEnvironmentFactors() const;
/**
* Returns the original index of the sector.
*/
uint origIndex() const;
/**
* Returns the @ref sectorFrameFlags for the sector.
*/
int frameFlags() const;
/**
* Returns the @em validCount of the sector. Used by some legacy iteration
* algorithms for marking sectors as processed/visited.
*
* @todo Refactor away.
*/
int validCount() const;
/**
* Returns the sector plane with the specified @a planeIndex.
*/
Plane &plane(int planeIndex);
/// @copydoc plane()
Plane const &plane(int planeIndex) const;
/**
* Returns the floor plane of the sector.
*/
inline Plane &floor() { return plane(Plane::Floor); }
/// @copydoc floor()
inline Plane const &floor() const { return plane(Plane::Floor); }
/**
* Returns the ceiling plane of the sector.
*/
inline Plane &ceiling() { return plane(Plane::Ceiling); }
/// @copydoc ceiling()
inline Plane const &ceiling() const { return plane(Plane::Ceiling); }
/**
* Convenient accessor method for returning the surface of the specified
* plane of the sector.
*/
inline Surface &planeSurface(int planeIndex) { return plane(planeIndex).surface(); }
/// @copydoc planeSurface()
inline Surface const &planeSurface(int planeIndex) const { return plane(planeIndex).surface(); }
/**
* Convenient accessor method for returning the surface of the floor plane
* of the sector.
*/
inline Surface &floorSurface() { return floor().surface(); }
/// @copydoc floorSurface()
inline Surface const &floorSurface() const { return floor().surface(); }
/**
* Convenient accessor method for returning the surface of the ceiling plane
* of the sector.
*/
inline Surface &ceilingSurface() { return ceiling().surface(); }
/// @copydoc ceilingSurface()
inline Surface const &ceilingSurface() const { return ceiling().surface(); }
/**
* Provides access to the list of lines which reference the sector,
* for efficient traversal.
*/
Lines const &lines() const;
/**
* Returns the total number of lines which reference the sector.
*/
inline uint lineCount() const { return uint(lines().count()); }
/**
* (Re)Build the line list for the sector.
*
* @attention The behavior of some algorithms used in the DOOM game logic
* is dependant upon the order of this list. For example, EV_DoFloor and
* EV_BuildStairs. That same order is used here, for compatibility.
*
* Order: Original line index, ascending.
*
* @param map Map to collate lines from. @todo Refactor away.
*/
void buildLines(GameMap const &map);
/**
* Provides access to the list of planes in/owned by the sector, for efficient
* traversal.
*/
Planes const &planes() const;
/**
* Returns the total number of planes in/owned by the sector.
*/
inline uint planeCount() const { return uint(planes().count()); }
/**
* Provides access to the list of BSP leafs which reference the sector, for
* efficient traversal.
*/
BspLeafs const &bspLeafs() const;
/**
* Returns the total number of BSP leafs which reference the sector.
*/
inline uint bspLeafCount() const { return uint(bspLeafs().count()); }
/**
* (Re)Build the BSP leaf list for the sector.
*
* @param map Map to collate BSP leafs from. @todo Refactor away.
*/
void buildBspLeafs(GameMap const &map);
/**
* Provides access to the list of BSP leafs which contribute to the environmental
* audio characteristics of the sector, for efficient traversal.
*/
BspLeafs const &reverbBspLeafs() const;
/**
* Returns the total number of BSP leafs which contribute to the environmental
* audio characteristics of the sector.
*/
inline uint reverbBspLeafCount() const { return uint(reverbBspLeafs().count()); }
/**
* Returns the axis-aligned bounding box which encompases the geometry of
* all BSP leafs attributed to the sector (map units squared). Note that if
* no BSP leafs reference the sector the bounding box will be invalid (has
* negative dimensions).
*/
AABoxd const &aaBox() const;
/**
* Update the sector's map space axis-aligned bounding box to encompass
* the geometry of all BSP leafs attributed to the sector.
*
* @pre BSP leaf list must have be initialized.
*
* @see buildBspLeafs()
*/
void updateAABox();
/**
* Returns a rough approximation of the total combined area of the geometry
* for all BSP leafs attributed to the sector (map units squared).
*
* @see updateRoughArea()
*/
coord_t roughArea() const;
/**
* Update the sector's rough area approximation.
*
* @pre BSP leaf list must have be initialized.
*
* @see buildBspLeafs(), roughArea()
*/
void updateRoughArea();
/**
* @param newEmitter Mobj base to link to the sector. Caller must ensure
* that the object is not linked multiple times into
* the chain.
*/
void linkSoundEmitter(ddmobj_base_t &newEmitter);
/**
* Update the sound emitter origin of the sector according to the point
* defined by the center of the sector's axis-aligned bounding box (which
* must be initialized before calling) and the mid point on the map up
* axis between floor and ceiling planes.
*/
void updateSoundEmitterOrigin();
/**
* Returns the ambient light level in the sector. The LightLevelChange
* audience is notified whenever the light level changes.
*
* @see setLightLevel()
*/
float lightLevel() const;
/**
* Change the ambient light level in the sector. The LightLevelChange
* audience is notified whenever the light level changes.
*
* @param newLightLevel New ambient light level.
*
* @see lightLevel()
*/
void setLightLevel(float newLightLevel);
/**
* Returns the ambient light color in the sector. The LightColorChange
* audience is notified whenever the light color changes.
*
* @see setLightColor(), lightColorComponent(), lightRed(), lightGreen(), lightBlue()
*/
de::Vector3f const &lightColor() const;
/**
* Returns the strength of the specified @a component of the ambient light
* color in the sector. The LightColorChange audience is notified whenever
* the light color changes.
*
* @param component RGB index of the color component (0=Red, 1=Green, 2=Blue).
*
* @see lightColor(), lightRed(), lightGreen(), lightBlue()
*/
inline float lightColorComponent(int component) const { return lightColor()[component]; }
/**
* Returns the strength of the @em red component of the ambient light
* color in the sector. The LightColorChange audience is notified whenever
* the light color changes.
*
* @see lightColorComponent(), lightGreen(), lightBlue()
*/
inline float lightRed() const { return lightColorComponent(0); }
/**
* Returns the strength of the @em green component of the ambient light
* color in the sector. The LightColorChange audience is notified whenever
* the light color changes.
*
* @see lightColorComponent(), lightRed(), lightBlue()
*/
inline float lightGreen() const { return lightColorComponent(1); }
/**
* Returns the strength of the @em blue component of the ambient light
* color in the sector. The LightColorChange audience is notified whenever
* the light color changes.
*
* @see lightColorComponent(), lightRed(), lightGreen()
*/
inline float lightBlue() const { return lightColorComponent(2); }
/**
* Change the ambient light color in the sector. The LightColorChange
* audience is notified whenever the light color changes.
*
* @param newLightColor New ambient light color.
*
* @see lightColor(), setLightColorComponent(), setLightRed(), setLightGreen(), setLightBlue()
*/
void setLightColor(de::Vector3f const &newLightColor);
/// @copydoc setLightColor()
inline void setLightColor(float red, float green, float blue) {
setLightColor(de::Vector3f(red, green, blue));
}
/**
* Change the strength of the specified @a component of the ambient light
* color in the sector. The LightColorChange audience is notified whenever
* the light color changes.
*
* @param component RGB index of the color component (0=Red, 1=Green, 2=Blue).
* @param newStrength New strength factor for the color component.
*
* @see setLightColor(), setLightRed(), setLightGreen(), setLightBlue()
*/
inline void setLightColorComponent(int component, float newStrength);
/**
* Change the strength of the red component of the ambient light color in
* the sector. The LightColorChange audience is notified whenever the light
* color changes.
*
* @param newStrength New red strength for the ambient light color.
*
* @see setLightColorComponent(), setLightGreen(), setLightBlue()
*/
inline void setLightRed(float newStrength) { setLightColorComponent(0, newStrength); }
/**
* Change the strength of the green component of the ambient light color in
* the sector. The LightColorChange audience is notified whenever the light
* color changes.
*
* @param newStrength New green strength for the ambient light color.
*
* @see setLightColorComponent(), setLightRed(), setLightBlue()
*/
inline void setLightGreen(float newStrength) { setLightColorComponent(1, newStrength); }
/**
* Change the strength of the blue component of the ambient light color in
* the sector. The LightColorChange audience is notified whenever the light
* color changes.
*
* @param newStrength New blue strength for the ambient light color.
*
* @see setLightColorComponent(), setLightRed(), setLightGreen()
*/
inline void setLightBlue(float newStrength) { setLightColorComponent(2, newStrength); }
/**
* Get a property value, selected by DMU_* name.
*
* @param args Property arguments.
* @return Always @c 0 (can be used as an iterator).
*/
int property(setargs_t &args) const;
/**
* Update a property value, selected by DMU_* name.
*
* @param args Property arguments.
* @return Always @c 0 (can be used as an iterator).
*/
int setProperty(setargs_t const &args);
private:
DENG2_PRIVATE(d)
};
#endif // LIBDENG_MAP_SECTOR