/
sector.h
579 lines (487 loc) · 17.9 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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
/** @file sector.h World 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 DENG_WORLD_SECTOR_H
#define DENG_WORLD_SECTOR_H
#include <QList>
#include <de/aabox.h>
#include <de/Error>
#include <de/Observers>
#include <de/Vector>
#include "dd_share.h" // AudioEnvironmentFactors
#include "MapElement"
#include "Line"
#include "Plane"
#ifdef __CLIENT__
# include "render/lightgrid.h"
#endif
class BspLeaf;
class Surface;
struct mobj_s;
/**
* World map sector.
*
* @ingroup world
*/
class Sector : public de::MapElement
{
DENG2_NO_COPY (Sector)
DENG2_NO_ASSIGN(Sector)
public:
/// Required/referenced plane is missing. @ingroup errors
DENG2_ERROR(MissingPlaneError);
/*
* Notified whenever a light level change occurs.
*/
DENG2_DEFINE_AUDIENCE(LightLevelChange,
void sectorLightLevelChanged(Sector §or, float oldLightLevel))
/*
* Notified whenever a light color change occurs.
*/
DENG2_DEFINE_AUDIENCE(LightColorChange,
void sectorLightColorChanged(Sector §or, de::Vector3f const &oldLightColor,
int changedComponents /*bit-field (0x1=Red, 0x2=Green, 0x4=Blue)*/))
/**
* Adjacent BSP leafs in the sector (i.e., those which share one or more
* common edge) are grouped into a "cluster". Clusters are never empty and
* will always contain at least one BSP leaf.
*
* Call Sector::buildClusters to rebuild the cluster set for the sector.
*/
class Cluster
{
public:
/*
* Notified when the cluster is about to be deleted.
*/
DENG2_DEFINE_AUDIENCE(Deletion, void sectorClusterBeingDeleted(Cluster const &cluster))
typedef QList<BspLeaf *> BspLeafs;
public:
/**
* Construct a new sector cluster comprised of the specified set of BSP
* leafs. It is assumed that all BSP leafs in the list are attributed to
* the same sector and there is always at least one.
*
* @param bspLeafs Set of BSP leafs comprising the resulting cluster.
*/
Cluster(BspLeafs const &bspLeafs);
/**
* Returns the parent sector of the cluster.
*/
Sector §or() const;
/**
* Returns the identified @em physical plane of the parent sector. Note
* that this is not the same as the "visual" plane which may well be
* defined by another sector.
*
* @param planeIndex Index of the plane to return.
*/
Plane &plane(int planeIndex) const;
/**
* Returns the sector plane which defines the @em physical floor of the
* cluster.
* @see hasSector(), plane()
*/
inline Plane &floor() const { return plane(Sector::Floor); }
/**
* Returns the sector plane which defines the @em physical ceiling of the
* cluster.
* @see hasSector(), plane()
*/
inline Plane &ceiling() const { return plane(Sector::Ceiling); }
/**
* Returns the identified @em visual sector plane for the cluster (which
* may or may not be the same as the physical plane).
*
* @param planeIndex Index of the plane to return.
*/
Plane &visPlane(int planeIndex) const;
/**
* Returns the sector plane which defines the @em visual floor of the
* cluster.
* @see hasSector(), floor()
*/
inline Plane &visFloor() const { return visPlane(Sector::Floor); }
/**
* Returns the sector plane which defines the @em visual ceiling of the
* cluster.
* @see hasSector(), ceiling()
*/
inline Plane &visCeiling() const { return visPlane(Sector::Ceiling); }
/**
* Provides access to the list of all BSP leafs in the cluster, for
* efficient traversal.
*/
BspLeafs const &bspLeafs() const;
/**
* Returns the total number of BSP leafs in the cluster.
*/
inline int bspLeafCount() const { return bspLeafs().count(); }
/**
* Returns the axis-aligned bounding box of the cluster.
*/
AABoxd const &aaBox() const;
/**
* Returns the point defined by the center of the axis-aligned bounding
* box in the map coordinate space.
*/
inline de::Vector2d center() const {
return (de::Vector2d(aaBox().min) + de::Vector2d(aaBox().max)) / 2;
}
#ifdef __CLIENT__
/**
* Returns a rough approximation of the total combined area of the geometry
* for all BSP leafs which define the cluster (map units squared).
*/
coord_t roughArea() const;
/**
* Request re-calculation of environmental audio (reverb) characteristics
* for the cluster (update is deferred until next accessed).
*
* To be called whenever any of the properties governing reverb properties
* have changed (i.e., wall/plane material changes).
*/
void markReverbDirty(bool yes = true);
/**
* Returns the final environmental audio characteristics (reverb) of the
* cluster. Note that if a reverb update is scheduled it will be done at
* this time (@ref markReverbDirty()).
*/
AudioEnvironmentFactors const &reverb() const;
#endif // __CLIENT__
private:
DENG2_PRIVATE(d)
};
#ifdef __CLIENT__
/**
* LightGrid data values for "smoothed sector lighting".
*
* @todo Encapsulate in LightGrid itself?
*/
struct LightGridData
{
/// Number of blocks attributed to the sector.
uint blockCount;
/// Number of attributed blocks to mark changed.
uint changedBlockCount;
/// Block indices.
de::LightGrid::Index *blocks;
};
#endif
/*
* Linked-element lists:
*/
typedef QList<Cluster *> Clusters;
typedef QList<Plane *> Planes;
typedef QList<LineSide *> Sides;
// Plane identifiers:
enum { Floor, Ceiling };
public:
/**
* Construct a new sector.
*
* @param lightLevel Ambient light level.
* @param lightColor Ambient light color.
*/
Sector(float lightLevel = 1,
de::Vector3f const &lightColor = de::Vector3f(1, 1, 1));
/**
* 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(Floor); }
/// @copydoc floor()
inline Plane const &floor() const { return plane(Floor); }
/**
* Returns the ceiling plane of the sector.
*/
inline Plane &ceiling() { return plane(Ceiling); }
/// @copydoc ceiling()
inline Plane const &ceiling() const { return plane(Ceiling); }
Plane *addPlane(de::Vector3f const &normal, coord_t height);
/**
* 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 int planeCount() const { return planes().count(); }
/**
* Returns @c true iff at least one of the surfaces of a plane in/owned
* by the sector presently has a sky-masked material bound.
*
* @see Surface::hasSkyMaskedMaterial()
*/
bool hasSkyMaskedPlane() const;
/**
* 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 line sides which reference the sector,
* for efficient traversal.
*/
Sides const &sides() const;
/**
* Returns the total number of line sides which reference the sector.
*/
inline int sideCount() const { return sides().count(); }
/**
* (Re)Build the side list for the sector.
*
* @note In the special case of self-referencing line, only the front side
* reference is added to this list.
*
* @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 @em line index, ascending.
*/
void buildSides();
/**
* Provides access to the list of BSP leaf clusters for the sector, for
* efficient traversal.
*/
Clusters const &clusters() const;
/**
* Returns the total number of BSP leaf clusters for the sector.
*/
inline int clusterCount() const { return clusters().count(); }
/**
* Convenient method of determning whether the sector is a parent of one or
* BSP leaf (i.e., at least one cluster is defined).
*/
inline bool hasBspLeafs() const { return clusterCount() != 0; }
/**
* (Re)Build BSP leaf clusters for the sector.
*/
void buildClusters();
/**
* 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.
*/
SoundEmitter &soundEmitter();
/// @copydoc soundEmitter()
SoundEmitter const &soundEmitter() const;
/**
* (Re)Build the sound emitter chains for the sector. These chains are used
* for efficiently traversing all sound emitters in the sector (e.g., when
* stopping all sounds emitted in the sector). To be called during map load
* once planes and sides have been initialized.
*
* @see addPlane(), buildSides()
*/
void chainSoundEmitters();
/**
* 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()
*/
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); }
/**
* Returns the first mobj in the linked list of mobjs "in" the sector.
*/
struct mobj_s *firstMobj() const;
/**
* Unlink the mobj from the list of mobjs "in" the sector.
*
* @param mobj Mobj to be unlinked.
*/
void unlink(struct mobj_s *mobj);
/**
* Link the mobj to the head of the list of mobjs "in" the sector.
*
* @param mobj Mobj to be linked.
*/
void link(struct mobj_s *mobj);
/**
* 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;
/// @todo Refactor away.
void setValidCount(int newValidCount);
#ifdef __CLIENT__
/**
* 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).
*
* @todo Refactor away (still used by light decoration and particle systems).
*/
AABoxd const &aaBox() const;
/**
* Returns a rough approximation of the total combined area of the geometry
* for all BSP leafs attributed to the sector (map units squared).
*
* @todo Refactor away (still used by the particle system).
*/
coord_t roughArea() const;
/**
* Returns the LightGrid data values (for smoothed ambient lighting) for
* the sector.
*/
LightGridData &lightGridData();
/**
* Perform missing material fixes again for all line sides in the sector.
*/
void fixMissingMaterialsForSides();
#endif // __CLIENT__
protected:
int property(DmuArgs &args) const;
int setProperty(DmuArgs const &args);
private:
DENG2_PRIVATE(d)
};
typedef Sector::Cluster SectorCluster;
#endif // DENG_WORLD_SECTOR_H