Skip to content

Commit

Permalink
Sector: Added getter methods for all Sector property values
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 15, 2013
1 parent aa0081a commit 4cca36a
Show file tree
Hide file tree
Showing 37 changed files with 507 additions and 349 deletions.
3 changes: 3 additions & 0 deletions doomsday/api/dd_share.h
Expand Up @@ -576,6 +576,9 @@ enum {
NUM_REVERB_DATA
};

/// Environmental audio characteristics. @ingroup map
typedef float AudioEnvironmentFactors[NUM_REVERB_DATA];

/// SideDef section indices. @ingroup map
typedef enum sidedefsection_e {
SS_MIDDLE,
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/include/map/bsp/hedgeintercept.h
Expand Up @@ -63,8 +63,8 @@ struct HEdgeIntercept
<< inst.vertex->_buildData.index
<< inst.vertex->origin()[VX]
<< inst.vertex->origin()[VY]
<< (inst.before? inst.before->buildData.index : -1)
<< (inst.after? inst.after->buildData.index : -1)
<< (inst.before? inst.before->origIndex() : -1)
<< (inst.after? inst.after->origIndex() : -1)
<< (inst.selfRef? "SELFREF" : "");
})
};
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/map/bsp/superblockmap.h
Expand Up @@ -247,7 +247,7 @@ class SuperBlock
HEdge* hedge = *it;
LOG_DEBUG("Build: %s %p sector: %d [%1.1f, %1.1f] -> [%1.1f, %1.1f]")
<< (hedge->lineDef? "NORM" : "MINI")
<< hedge << hedge->sector->buildData.index
<< hedge << hedge->sector->origIndex()
<< hedge->v[0]->origin()[VX] << hedge->v[0]->origin()[VY]
<< hedge->v[1]->origin()[VX] << hedge->v[1]->origin()[VY];
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/map/r_world.h
Expand Up @@ -60,7 +60,7 @@ extern boolean firstFrameAfterLoad;
/**
* Sector light color may be affected by the sky light color.
*/
const float* R_GetSectorLightColor(const Sector *sector);
const_pvec3f_t &R_GetSectorLightColor(Sector const *sector);

float R_DistAttenuateLightLevel(float distToViewer, float lightLevel);

Expand Down
154 changes: 120 additions & 34 deletions doomsday/client/include/map/sector.h
Expand Up @@ -23,6 +23,7 @@

#include <QList>
#include <de/aabox.h>
#include <de/vector1.h>
#include <de/Error>
#include "map/plane.h"
#include "p_mapdata.h"
Expand All @@ -32,16 +33,17 @@
class BspLeaf;
class LineDef;

// Sector frame flags
#define SIF_VISIBLE 0x1 // Sector is visible on this frame.
#define SIF_FRAME_CLEAR 0x1 // Flags to clear before each frame.
#define SIF_LIGHT_CHANGED 0x2
/**
* @defgroup sectorFrameFlags Sector frame flags
* @ingroup map
*/
///@{
#define SIF_VISIBLE 0x1 ///< Sector is visible on this frame.
#define SIF_LIGHT_CHANGED 0x2

typedef struct msector_s {
/// Sector index. Always valid after loading & pruning.
int index;
int refCount;
} msector_t;
// Flags to clear before each frame.
#define SIF_FRAME_CLEAR SIF_VISIBLE
///@}

/**
* Map sector.
Expand All @@ -64,28 +66,48 @@ class Sector : public de::MapElement
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:
int frameFlags;
/// @ref sectorFrameFlags
int _frameFlags;

/// if == validCount, already checked.
int validCount;
int _validCount;

/// Bounding box for the sector.
AABoxd aaBox;
AABoxd _aaBox;

/// Rough approximation of sector area.
coord_t roughArea;
coord_t _roughArea;

float lightLevel;
/// Ambient light level in the sector.
float _lightLevel;

float oldLightLevel;
/// Old ambient light level in the sector. For smoothing.
float _oldLightLevel;

float rgb[3];
/// Ambient light color in the sector.
vec3f_t _lightColor;

float oldRGB[3];
/// Old ambient light color in the sector. For smoothing.
vec3f_t _oldLightColor;

/// List of mobjs "in" the sector (not owned).
struct mobj_s *mobjList;
/// Head of the linked list of mobjs "in" the sector (not owned).
struct mobj_s *_mobjList;

/// List of lines which reference the sector (not owned).
Lines _lines;
Expand All @@ -97,28 +119,73 @@ class Sector : public de::MapElement
/// characteristics of the sector (not owned).
BspLeafs _reverbBspLeafs;

ddmobj_base_t base;
/// Primary sound emitter. Others are linked to this, forming a chain.
ddmobj_base_t _soundEmitter;

/// List of sector planes (owned).
Planes _planes;

/// Number of gridblocks attributed to the sector.
uint blockCount;

/// Number of attributed blocks to mark changed.
uint changedBlockCount;
/// LightGrid data values.
LightGridData _lightGridData;

/// Light grid block indices.
ushort *blocks;
/// Final environmental audio characteristics.
AudioEnvironmentFactors _reverb;

float reverb[NUM_REVERB_DATA];

msector_t buildData;
/// Original index in the archived map.
int _origIndex;

public:
Sector();
~Sector();

/**
* Returns the ambient light level in the sector.
*/
float lightLevel() const;

/**
* Returns the ambient light color in the sector.
*/
const_pvec3f_t &lightColor() const;

/**
* 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.
*/
Expand Down Expand Up @@ -214,27 +281,46 @@ class Sector : public de::MapElement
*/
inline uint reverbBspLeafCount() const { return uint(reverbBspLeafs().count()); }

/**
* Returns the axis-aligned bounding box which encompases all vertex
* origin points for lines which reference the sector, in map coordinate
* space units. Note that if no lines reference the sector the bounding
* box will be invalid (has negative dimensions).
*
* @deprecated Algorithms which are dependent on this are likely making
* invalid assumptions about the geometry of the map.
*/
AABoxd const &aaBox() const;

/**
* Update the sector's map space axis-aligned bounding box to encompass
* the points defined by it's LineDefs' vertexes.
*
* @pre LineDef list must have been initialized.
* @pre Line list must have been initialized.
*/
void updateAABox();

/**
* Returns a rough approximation of the area of the sector in the map
* coordinate space (units squared).
*
* @deprecated Algorithms which are dependent on this are likely making
* invalid assumptions about the geometry of the map.
*/
coord_t roughArea() const;

/**
* Update the sector's rough area approximation.
*
* @pre Axis-aligned bounding box must have been initialized.
*/
void updateArea();
void updateRoughArea();

/**
* Update the 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).
*/
void updateBaseOrigin();
void updateSoundEmitterOrigin();

/**
* Get a property value, selected by DMU_* name.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/map/sidedef.h
Expand Up @@ -162,7 +162,7 @@ class SideDef : public de::MapElement
* defined by the associated LineDef's vertices and the plane heights of the
* Sector on this side. If no LineDef is presently associated this is a no-op.
*/
void updateBaseOrigins();
void updateSoundEmitterOrigins();

/**
* Update the side's map space surface tangents according to the points
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/map/surface.h
Expand Up @@ -97,7 +97,7 @@ class Surface : public de::MapElement
*
* If no owner is presently associated this is a no-op.
*/
void updateBaseOrigin();
void updateSoundEmitterOrigin();

/// @return @c true= is drawable (i.e., a drawable Material is bound).
bool isDrawable() const;
Expand Down

0 comments on commit 4cca36a

Please sign in to comment.