Skip to content

Commit

Permalink
World|Sector: Deferred calculation of sector cluster bounding boxes
Browse files Browse the repository at this point in the history
It is now clear that a sector cluster can determine autonomously from
its BSP leaf data set when one or more planes need to be linked to
some other sector for "deep water hack" effects. Also, recording just
the boundary geometry of the cluster is unnecessary would not provide
any performance benefit.
  • Loading branch information
danij-deng committed Aug 20, 2013
1 parent d222dd9 commit 94068a9
Showing 1 changed file with 24 additions and 32 deletions.
56 changes: 24 additions & 32 deletions doomsday/client/src/world/sector.cpp
Expand Up @@ -61,15 +61,32 @@ Plane &Sector::Cluster::visPlane(int planeIndex) const

AABoxd const &Sector::Cluster::aaBox() const
{
// If a bounding box is assigned - use it.
if(!_aaBox.isNull())
// If the cluster is comprised of a single BSP leaf we can use the bounding
// box of the leaf's geometry directly.
if(_bspLeafs.count() == 1)
{
return *_aaBox;
return _bspLeafs.first()->poly().aaBox();
}
// Otherwise it means the cluster is comprised of a single BSP leaf, so we
// can use the bounding box of the leaf's geometry directly.
DENG_ASSERT(_bspLeafs.count() == 1); // sanity check
return _bspLeafs.first()->poly().aaBox();

// Time to determine bounds?
if(_aaBox.isNull())
{
// Unite the geometry bounding boxes of all BSP leafs in the cluster.
foreach(BspLeaf *leaf, _bspLeafs)
{
AABoxd const &leafAABox = leaf->poly().aaBox();
if(!_aaBox.isNull())
{
V2d_UniteBox((*_aaBox).arvec2, leafAABox.arvec2);
}
else
{
const_cast<Sector::Cluster *>(this)->_aaBox.reset(new AABoxd(leafAABox));
}
}
}

return *_aaBox;
}

Sector::Cluster::BspLeafs const &Sector::Cluster::bspLeafs() const
Expand Down Expand Up @@ -646,32 +663,7 @@ void Sector::buildClusters()
}
if(!didMerge) break;
}

// Clustering complete.

// Determine the bounds of each cluster.
/// @todo Defer until necessary.
foreach(Cluster *cluster, d->clusters)
{
// If the cluster is comprised of a single BSP leaf we can use the
// bounding box of it's geometry directly.
if(cluster->_bspLeafs.count() == 1)
continue;

// Unite the geometry bounding boxes of BSP leafs in the cluster.
foreach(BspLeaf *leaf, cluster->_bspLeafs)
{
AABoxd const &leafAABox = leaf->poly().aaBox();
if(!cluster->_aaBox.isNull())
{
V2d_UniteBox((*cluster->_aaBox).arvec2, leafAABox.arvec2);
}
else
{
cluster->_aaBox.reset(new AABoxd(leafAABox));
}
}
}
}

AABoxd const &Sector::aaBox() const
Expand Down

0 comments on commit 94068a9

Please sign in to comment.