Skip to content

Commit

Permalink
Sector|World|Client: Sector now manages rough area approximation upda…
Browse files Browse the repository at this point in the history
…tes internally
  • Loading branch information
danij-deng committed Aug 17, 2013
1 parent 71ee34d commit 5dd7b19
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
11 changes: 0 additions & 11 deletions doomsday/client/include/world/sector.h
Expand Up @@ -456,20 +456,9 @@ class Sector : public de::MapElement
/**
* 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();

/**
* Returns @c true iff the sector is marked as visible for the current frame.
* @see markVisible()
Expand Down
4 changes: 0 additions & 4 deletions doomsday/client/src/world/map.cpp
Expand Up @@ -3570,10 +3570,6 @@ bool Map::endEditing()
sector->buildSides();
sector->updateAABox();

#ifdef __CLIENT__
sector->updateRoughArea();
#endif

/*
* Chain sound emitters (ddmobj_base_t) owned by all Surfaces in the
* sector-> These chains are used for efficiently traversing all of the
Expand Down
51 changes: 32 additions & 19 deletions doomsday/client/src/world/sector.cpp
Expand Up @@ -50,9 +50,6 @@ DENG2_OBSERVES(Plane, HeightChange)
/// 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;

Expand All @@ -75,6 +72,10 @@ DENG2_OBSERVES(Plane, HeightChange)
int validCount;

#ifdef __CLIENT__
/// Rough approximation of sector area (map units squared).
coord_t roughArea;
bool needRoughAreaUpdate; /// @c true= marked for update.

/// LightGrid data values.
LightGridData lightGridData;

Expand All @@ -91,12 +92,13 @@ DENG2_OBSERVES(Plane, HeightChange)

Instance(Public *i, float lightLevel, Vector3f const &lightColor)
: Base(i),
roughArea(0),
lightLevel(lightLevel),
lightColor(lightColor),
validCount(0)
#ifdef __CLIENT__
,needReverbUpdate(true),
,roughArea(0),
needRoughAreaUpdate(false), // Sectors with no BSP leafs have zero area.
needReverbUpdate(true),
visible(false)
#endif
{
Expand Down Expand Up @@ -141,6 +143,22 @@ DENG2_OBSERVES(Plane, HeightChange)
}

#ifdef __CLIENT__
void updateRoughArea()
{
needRoughAreaUpdate = false;

roughArea = 0;
foreach(BspLeaf *leaf, bspLeafs)
{
if(leaf->isDegenerate()) continue;

AABoxd const &leafAABox = leaf->poly().aaBox();

roughArea += (leafAABox.maxX - leafAABox.minX) *
(leafAABox.maxY - leafAABox.minY);
}
}

void addReverbBspLeaf(BspLeaf *bspLeaf)
{
// Degenerate leafs never contribute.
Expand Down Expand Up @@ -493,6 +511,11 @@ void Sector::buildBspLeafs()
d->bspLeafs.append(bspLeaf);
}
}

#ifdef __CLIENT__
// We'll need to update the rough area calculation.
d->needRoughAreaUpdate = true;
#endif
}

AABoxd const &Sector::aaBox() const
Expand Down Expand Up @@ -602,22 +625,12 @@ AudioEnvironmentFactors const &Sector::reverb() const

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

void Sector::updateRoughArea()
{
d->roughArea = 0;

foreach(BspLeaf *leaf, d->bspLeafs)
// Perform any scheduled update now.
if(d->needRoughAreaUpdate)
{
if(leaf->isDegenerate()) continue;

AABoxd const &leafAABox = leaf->poly().aaBox();

d->roughArea += (leafAABox.maxX - leafAABox.minX) *
(leafAABox.maxY - leafAABox.minY);
d->updateRoughArea();
}
return d->roughArea;
}

bool Sector::isVisible() const
Expand Down

0 comments on commit 5dd7b19

Please sign in to comment.