Skip to content

Commit

Permalink
World|Sector: Properly resolve cyclic sector cluster linking
Browse files Browse the repository at this point in the history
If two sector clusters determine they should both link to the other
then by virtue of the clustering this inherently means that one of
the two contains the other. To resolve this situation we'll simply
compare the bounding boxes to determine which.
  • Loading branch information
danij-deng committed Aug 26, 2013
1 parent 95d3227 commit c76bb55
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions doomsday/client/src/world/sector.cpp
Expand Up @@ -18,6 +18,7 @@
* 02110-1301 USA</small>
*/

#include <QRect>
#include <QSet>
#include <QtAlgorithms>

Expand All @@ -43,6 +44,11 @@

using namespace de;

static QRectF qrectFromAABox(AABoxd const &aaBox)
{
return QRectF(QPointF(aaBox.minX, aaBox.maxY), QPointF(aaBox.maxX, aaBox.minY));
}

void Sector::Cluster::remapVisPlanes()
{
// By default both planes are mapped to the parent sector.
Expand All @@ -61,7 +67,7 @@ void Sector::Cluster::remapVisPlanes()
{
if(hedge->mapElement()->as<LineSideSegment>().line().isSelfReferencing())
{
if(!exteriorCluster && hedge->twin().hasFace())
if(hedge->twin().hasFace())
{
BspLeaf &otherLeaf = hedge->twin().face().mapElement()->as<BspLeaf>();
if(otherLeaf.hasCluster())
Expand Down Expand Up @@ -89,11 +95,25 @@ void Sector::Cluster::remapVisPlanes()
{
// Ensure we don't produce a cyclic dependency...
Sector *finalSector = &exteriorCluster->visPlane(Floor).sector();
if(finalSector != &sector())
if(finalSector == &sector())
{
_mappedVisFloor = exteriorCluster;
_mappedVisCeiling = exteriorCluster;
// Must share a boundary edge.
QRectF boundingRect = qrectFromAABox(aaBox());
if(boundingRect.contains(qrectFromAABox(exteriorCluster->aaBox())))
{
// The contained cluster will link to this.
return;
}
else
{
// Reverse the linkage (this cluster is containted).
exteriorCluster->_mappedVisFloor =
exteriorCluster->_mappedVisCeiling = exteriorCluster;
}
}

_mappedVisFloor = exteriorCluster;
_mappedVisCeiling = exteriorCluster;
}
}

Expand Down

0 comments on commit c76bb55

Please sign in to comment.