Skip to content

Commit

Permalink
Refactor|Sector: Made private more Sector instance data
Browse files Browse the repository at this point in the history
Axis-aligned bounding box/rough area/sound emitter chain
  • Loading branch information
danij-deng committed Apr 8, 2013
1 parent 34def4d commit 3cab8e8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
9 changes: 0 additions & 9 deletions doomsday/client/include/map/sector.h
Expand Up @@ -98,12 +98,6 @@ class Sector : public de::MapElement
/// if == validCount, already checked.
int _validCount;

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

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

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

Expand All @@ -123,9 +117,6 @@ class Sector : public de::MapElement
/// characteristics of the sector (not owned).
BspLeafs _reverbBspLeafs;

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

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

Expand Down
51 changes: 31 additions & 20 deletions doomsday/client/src/map/sector.cpp
Expand Up @@ -36,14 +36,27 @@ using namespace de;

DENG2_PIMPL(Sector)
{
/// Bounding box for the sector.
AABoxd aaBox;

/// Rough approximation of sector area (map units squared).
coord_t roughArea;

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

/// List of lines which reference the sector (not owned).
Lines lines;

/// List of BSP leafs which reference the sector (not owned).
BspLeafs bspLeafs;

Instance(Public *i) : Base(i)
{}
Instance(Public *i)
: Base(i),
roughArea(0)
{
std::memset(&soundEmitter, 0, sizeof(soundEmitter));
}

~Instance()
{
Expand Down Expand Up @@ -92,9 +105,7 @@ Sector::Sector(float lightLevel, Vector3f const &lightColor)
{
_frameFlags = 0;
_validCount = 0;
_roughArea = 0;
_mobjList = 0;
std::memset(&_soundEmitter, 0, sizeof(_soundEmitter));
std::memset(&_lightGridData, 0, sizeof(_lightGridData));
std::memset(_reverb, 0, sizeof(_reverb));
_origIndex = 0;
Expand Down Expand Up @@ -159,7 +170,7 @@ struct mobj_s *Sector::firstMobj() const

ddmobj_base_t &Sector::soundEmitter()
{
return _soundEmitter;
return d->soundEmitter;
}

ddmobj_base_t const &Sector::soundEmitter() const
Expand Down Expand Up @@ -280,55 +291,55 @@ Sector::BspLeafs const &Sector::reverbBspLeafs() const

AABoxd const &Sector::aaBox() const
{
return _aaBox;
return d->aaBox;
}

coord_t Sector::roughArea() const
{
return _roughArea;
return d->roughArea;
}

void Sector::updateAABox()
{
V2d_Set(_aaBox.min, DDMAXFLOAT, DDMAXFLOAT);
V2d_Set(_aaBox.max, DDMINFLOAT, DDMINFLOAT);
V2d_Set(d->aaBox.min, DDMAXFLOAT, DDMAXFLOAT);
V2d_Set(d->aaBox.max, DDMINFLOAT, DDMINFLOAT);

if(!d->lines.count()) return;

QListIterator<LineDef *> lineIt(d->lines);

LineDef *line = lineIt.next();
V2d_CopyBox(_aaBox.arvec2, line->aaBox().arvec2);
V2d_CopyBox(d->aaBox.arvec2, line->aaBox().arvec2);

while(lineIt.hasNext())
{
line = lineIt.next();
V2d_UniteBox(_aaBox.arvec2, line->aaBox().arvec2);
V2d_UniteBox(d->aaBox.arvec2, line->aaBox().arvec2);
}
}

void Sector::updateRoughArea()
{
// Only a very rough estimate is required.
_roughArea = ((_aaBox.maxX - _aaBox.minX) / 128) *
((_aaBox.maxY - _aaBox.minY) / 128);
d->roughArea = ((d->aaBox.maxX - d->aaBox.minX) / 128) *
((d->aaBox.maxY - d->aaBox.minY) / 128);
}

void Sector::linkSoundEmitter(ddmobj_base_t &newEmitter)
{
// The sector's base is always head of the chain, so link the other after it.
newEmitter.thinker.prev = &_soundEmitter.thinker;
newEmitter.thinker.next = _soundEmitter.thinker.next;
newEmitter.thinker.prev = &d->soundEmitter.thinker;
newEmitter.thinker.next = d->soundEmitter.thinker.next;
if(newEmitter.thinker.next)
newEmitter.thinker.next->prev = &newEmitter.thinker;
_soundEmitter.thinker.next = &newEmitter.thinker;
d->soundEmitter.thinker.next = &newEmitter.thinker;
}

void Sector::updateSoundEmitterOrigin()
{
_soundEmitter.origin[VX] = (_aaBox.minX + _aaBox.maxX) / 2;
_soundEmitter.origin[VY] = (_aaBox.minY + _aaBox.maxY) / 2;
_soundEmitter.origin[VZ] = (floor().height() + ceiling().height()) / 2;
d->soundEmitter.origin[VX] = (d->aaBox.minX + d->aaBox.maxX) / 2;
d->soundEmitter.origin[VY] = (d->aaBox.minY + d->aaBox.maxY) / 2;
d->soundEmitter.origin[VZ] = (floor().height() + ceiling().height()) / 2;
}

int Sector::property(setargs_t &args) const
Expand All @@ -353,7 +364,7 @@ int Sector::property(setargs_t &args) const
DMU_GetValue(DMT_SECTOR_RGB, &_lightColor.z, &args, 0);
break;
case DMU_BASE: {
ddmobj_base_t const *soundEmitterAdr = &_soundEmitter;
ddmobj_base_t const *soundEmitterAdr = &d->soundEmitter;
DMU_GetValue(DMT_SECTOR_BASE, &soundEmitterAdr, &args, 0);
break; }
case DMU_LINEDEF_COUNT: {
Expand Down

0 comments on commit 3cab8e8

Please sign in to comment.