Skip to content

Commit

Permalink
Sector|World|Client: Sector now manages axis-aligned bounding box upd…
Browse files Browse the repository at this point in the history
…ates internally
  • Loading branch information
danij-deng committed Aug 17, 2013
1 parent 5dd7b19 commit ff062d4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
10 changes: 0 additions & 10 deletions doomsday/client/include/world/sector.h
Expand Up @@ -245,16 +245,6 @@ class Sector : public de::MapElement
*/
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 the primary sound emitter for the sector. Other emitters in the
* sector are linked to this, forming a chain which can be traversed using
Expand Down
1 change: 0 additions & 1 deletion doomsday/client/src/world/map.cpp
Expand Up @@ -3568,7 +3568,6 @@ bool Map::endEditing()
{
sector->buildBspLeafs();
sector->buildSides();
sector->updateAABox();

/*
* Chain sound emitters (ddmobj_base_t) owned by all Surfaces in the
Expand Down
60 changes: 37 additions & 23 deletions doomsday/client/src/world/sector.cpp
Expand Up @@ -49,6 +49,7 @@ DENG2_OBSERVES(Plane, HeightChange)
{
/// Bounding box for the sector.
AABoxd aaBox;
bool needAABoxUpdate; ///< @c true= marked for update.

/// Primary sound emitter. Others are linked to this, forming a chain.
ddmobj_base_t soundEmitter;
Expand Down Expand Up @@ -92,6 +93,7 @@ DENG2_OBSERVES(Plane, HeightChange)

Instance(Public *i, float lightLevel, Vector3f const &lightColor)
: Base(i),
needAABoxUpdate(false), // Sectors with no BSP leafs have no geometry.
lightLevel(lightLevel),
lightColor(lightColor),
validCount(0)
Expand Down Expand Up @@ -142,6 +144,34 @@ DENG2_OBSERVES(Plane, HeightChange)
notifyLightColorChanged(oldLightColor, changedComponents);
}

/**
* Update the axis-aligned bounding box in the map coordinate space to
* encompass the geometry of all BSP leafs attributed to the sector.
*/
void updateAABox()
{
needAABoxUpdate = false;

aaBox.clear();
bool isFirst = false;
foreach(BspLeaf *leaf, bspLeafs)
{
if(leaf->isDegenerate()) continue;

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

if(!isFirst)
{
V2d_UniteBox(aaBox.arvec2, leafAABox.arvec2);
}
else
{
V2d_CopyBox(aaBox.arvec2, leafAABox.arvec2);
isFirst = false;
}
}
}

#ifdef __CLIENT__
void updateRoughArea()
{
Expand Down Expand Up @@ -512,38 +542,22 @@ void Sector::buildBspLeafs()
}
}

// We'll need to recalculate the axis-aligned bounding box.
d->needAABoxUpdate = true;
#ifdef __CLIENT__
// We'll need to update the rough area calculation.
// ...and the rough area approximation.
d->needRoughAreaUpdate = true;
#endif
}

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

void Sector::updateAABox()
{
d->aaBox.clear();

bool isFirst = false;
foreach(BspLeaf *leaf, d->bspLeafs)
// Perform any scheduled update now.
if(d->needAABoxUpdate)
{
if(leaf->isDegenerate()) continue;

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

if(!isFirst)
{
V2d_UniteBox(d->aaBox.arvec2, leafAABox.arvec2);
}
else
{
V2d_CopyBox(d->aaBox.arvec2, leafAABox.arvec2);
isFirst = false;
}
d->updateAABox();
}
return d->aaBox;
}

void Sector::linkSoundEmitter(ddmobj_base_t &newEmitter)
Expand Down

0 comments on commit ff062d4

Please sign in to comment.