Skip to content

Commit

Permalink
World|Sector: Fixed sector BSP leaf clustering algorithm
Browse files Browse the repository at this point in the history
The previous version didn't quite work. There must be a faster way
to do this...
  • Loading branch information
danij-deng committed Aug 23, 2013
1 parent 263f026 commit 4532443
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -169,8 +169,8 @@ DGLuint dlBBox;
*/

byte devMobjVLights; ///< @c 1= Draw mobj vertex lighting vector.
int devMobjBBox; ///< @c 1 = Draw mobj bounding boxes.
int devPolyobjBBox; ///< @c 1 = Draw polyobj bounding boxes.
int devMobjBBox; ///< @c 1= Draw mobj bounding boxes.
int devPolyobjBBox; ///< @c 1= Draw polyobj bounding boxes.

byte devVertexIndices; ///< @c 1= Draw world vertex indices.
byte devVertexBars; ///< @c 1= Draw world vertex position bars.
Expand Down
21 changes: 13 additions & 8 deletions doomsday/client/src/world/sector.cpp
Expand Up @@ -711,23 +711,28 @@ void Sector::buildClusters()
if(d->clusters.isEmpty()) return;

// Merge clusters whose BSP leafs share a common edge.
forever
while(d->clusters.count() > 1)
{
bool didMerge = false;
for(int i = 0; i < d->clusters.count() - 1; ++i)
for(int i = 0; i < d->clusters.count(); ++i)
for(int k = 0; k < d->clusters.count(); ++k)
{
if(findSharedEdge(*d->clusters[i], *d->clusters[i+1]))
if(i == k)
continue;

if(findSharedEdge(*d->clusters[i], *d->clusters[k]))
{
// Merge n+1 into n.
foreach(BspLeaf *bspLeaf, d->clusters[i+1]->_bspLeafs)
// Merge k into i.
foreach(BspLeaf *bspLeaf, d->clusters[k]->_bspLeafs)
{
bspLeaf->setCluster(d->clusters[i]);
}
d->clusters[i]->_bspLeafs.append(d->clusters[i+1]->_bspLeafs);
d->clusters.removeAt(i+1);
d->clusters[i]->_bspLeafs.append(d->clusters[k]->_bspLeafs);
d->clusters.removeAt(k);

// Compare the next pair.
i -= 1;
if(i >= k) i -= 1;
k -= 1;

// We'll need to repeat in any case.
didMerge = true;
Expand Down

0 comments on commit 4532443

Please sign in to comment.