diff --git a/doomsday/client/src/world/sector.cpp b/doomsday/client/src/world/sector.cpp index 666956170d..0f4e851ae5 100644 --- a/doomsday/client/src/world/sector.cpp +++ b/doomsday/client/src/world/sector.cpp @@ -18,6 +18,7 @@ * 02110-1301 USA */ +#include #include #include @@ -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. @@ -61,7 +67,7 @@ void Sector::Cluster::remapVisPlanes() { if(hedge->mapElement()->as().line().isSelfReferencing()) { - if(!exteriorCluster && hedge->twin().hasFace()) + if(hedge->twin().hasFace()) { BspLeaf &otherLeaf = hedge->twin().face().mapElement()->as(); if(otherLeaf.hasCluster()) @@ -89,11 +95,25 @@ void Sector::Cluster::remapVisPlanes() { // Ensure we don't produce a cyclic dependency... Sector *finalSector = &exteriorCluster->visPlane(Floor).sector(); - if(finalSector != §or()) + if(finalSector == §or()) { - _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; } }