diff --git a/doomsday/engine/portable/include/map/bsp/hplane.h b/doomsday/engine/portable/include/map/bsp/hplane.h index 8b537a381b..9c303d2d46 100644 --- a/doomsday/engine/portable/include/map/bsp/hplane.h +++ b/doomsday/engine/portable/include/map/bsp/hplane.h @@ -94,9 +94,9 @@ class HPlane { public: typedef std::list Intercepts; - HPlane() : partition(), intercepts(0){} + HPlane() : partition(), intercepts_(0){} HPlane(coord_t const origin[2], coord_t const direction[2]) : - partition(origin, direction), intercepts(0) {} + partition(origin, direction), intercepts_(0) {} ~HPlane() { clear(); } @@ -130,29 +130,20 @@ class HPlane { * * @param userData Ownership passes to HPlane. */ - HPlaneIntercept* newIntercept(coord_t distance, void* userData=NULL); + HPlaneIntercept& newIntercept(coord_t distance, void* userData=NULL); Intercepts::const_iterator deleteIntercept(Intercepts::iterator at); + Intercepts::const_iterator deleteIntercept(Intercepts::const_iterator at); - inline bool empty() const { return intercepts.empty(); } - - inline Intercepts::iterator begin() { return intercepts.begin(); } - - inline Intercepts::const_iterator begin() const { return intercepts.begin(); } - - inline Intercepts::iterator end() { return intercepts.end(); } - - inline Intercepts::const_iterator end() const { return intercepts.end(); } - - inline Intercepts::size_type size() const { return intercepts.size(); } + const Intercepts& intercepts() const; static void DebugPrint(const HPlane& inst); private: HPlanePartition partition; - /// The intercept list. Kept sorted by along_dist, in ascending order. - Intercepts intercepts; + /// The intercept list. Kept sorted by distance, in ascending order. + Intercepts intercepts_; }; } // namespace bsp diff --git a/doomsday/engine/portable/include/map/bsp/superblockmap.h b/doomsday/engine/portable/include/map/bsp/superblockmap.h index 0636a3ae90..1df870b566 100644 --- a/doomsday/engine/portable/include/map/bsp/superblockmap.h +++ b/doomsday/engine/portable/include/map/bsp/superblockmap.h @@ -232,21 +232,19 @@ class SuperBlock */ HEdge* pop(); - HEdges::const_iterator hedgesBegin() const; - HEdges::const_iterator hedgesEnd() const; + const HEdges& hedges() const; DENG_DEBUG_ONLY( static void DebugPrint(SuperBlock const& inst) { - for(SuperBlock::HEdges::const_iterator it = inst.hedgesBegin(); - it != inst.hedgesEnd(); ++it) + DENG2_FOR_EACH(it, inst.hedges(), SuperBlock::HEdges::const_iterator) { HEdge* hedge = *it; LOG_DEBUG("Build: %s %p sector: %d [%1.1f, %1.1f] -> [%1.1f, %1.1f]") - << (hedge->lineDef? "NORM" : "MINI") - << hedge << hedge->sector->buildData.index - << hedge->v[0]->origin[VX] << hedge->v[0]->origin[VY] - << hedge->v[1]->origin[VX] << hedge->v[1]->origin[VY]; + << (hedge->lineDef? "NORM" : "MINI") + << hedge << hedge->sector->buildData.index + << hedge->v[0]->origin[VX] << hedge->v[0]->origin[VY] + << hedge->v[1]->origin[VX] << hedge->v[1]->origin[VY]; } }) diff --git a/doomsday/engine/portable/src/map/bsp/hplane.cpp b/doomsday/engine/portable/src/map/bsp/hplane.cpp index 1410f811a3..7fefbe6456 100644 --- a/doomsday/engine/portable/src/map/bsp/hplane.cpp +++ b/doomsday/engine/portable/src/map/bsp/hplane.cpp @@ -35,7 +35,7 @@ using namespace de::bsp; void HPlane::clear() { - intercepts.clear(); + intercepts_.clear(); } HPlane* HPlane::setOrigin(coord_t const newOrigin[2]) @@ -99,33 +99,40 @@ HPlane* HPlane::setDY(coord_t newDY) return this; } -HPlaneIntercept* HPlane::newIntercept(coord_t distance, void* userData) +HPlaneIntercept& HPlane::newIntercept(coord_t distance, void* userData) { Intercepts::reverse_iterator after; - HPlaneIntercept* inter; - for(after = intercepts.rbegin(); - after != intercepts.rend() && distance < (*after).distance(); after++) + for(after = intercepts_.rbegin(); + after != intercepts_.rend() && distance < (*after).distance(); after++) {} - inter = &*intercepts.insert(after.base(), HPlaneIntercept(distance, userData)); - return inter; + return *intercepts_.insert(after.base(), HPlaneIntercept(distance, userData)); } HPlane::Intercepts::const_iterator HPlane::deleteIntercept(Intercepts::iterator at) { - //if(at < intercepts.begin() || at >= intercepts.end()) return at; - return intercepts.erase(at); + return intercepts_.erase(at); +} + +HPlane::Intercepts::const_iterator HPlane::deleteIntercept(Intercepts::const_iterator at) +{ + return intercepts_.erase(at); +} + +const HPlane::Intercepts& HPlane::intercepts() const +{ + return intercepts_; } #if _DEBUG void HPlane::DebugPrint(const HPlane& inst) { - uint n = 0; - for(HPlane::Intercepts::const_iterator it = inst.begin(); it != inst.end(); it++, n++) + uint index = 0; + DENG2_FOR_EACH(it, inst.intercepts(), HPlane::Intercepts::const_iterator) { const HPlaneIntercept* inter = &*it; - Con_Printf(" %u: >%1.2f ", n, inter->distance()); + Con_Printf(" %u: >%1.2f ", index++, inter->distance()); HEdgeIntercept::DebugPrint(*static_cast(inter->userData())); } } diff --git a/doomsday/engine/portable/src/map/bsp/partitioner.cpp b/doomsday/engine/portable/src/map/bsp/partitioner.cpp index 2b9e33b9e4..8361609830 100644 --- a/doomsday/engine/portable/src/map/bsp/partitioner.cpp +++ b/doomsday/engine/portable/src/map/bsp/partitioner.cpp @@ -452,7 +452,7 @@ struct Partitioner::Instance LineDef* line = hedge->lineDef; HEdgeIntercept* intercept = newHEdgeIntercept(vertex, line && lineDefInfo(*line).flags.testFlag(LineDefInfo::SELFREF)); - return partition->newIntercept(vertexDistanceFromPartition(vertex), intercept); + return &partition->newIntercept(vertexDistanceFromPartition(vertex), intercept); } /** @@ -495,17 +495,19 @@ struct Partitioner::Instance void mergeIntersections() { - HPlane::Intercepts::iterator node = partition->begin(); - while(node != partition->end()) + HPlane::Intercepts::const_iterator node = partition->intercepts().begin(); + while(node != partition->intercepts().end()) { - HPlane::Intercepts::iterator np = node; np++; - if(np == partition->end()) break; + HPlane::Intercepts::const_iterator np = node; np++; + if(np == partition->intercepts().end()) break; coord_t len = *np - *node; if(len < -0.1) { throw de::Error("Partitioner::MergeIntersections", - QString("Invalid intercept order - %1 > %2").arg(node->distance(), 0, 'f', 3).arg(np->distance(), 0, 'f', 3)); + QString("Invalid intercept order - %1 > %2") + .arg(node->distance(), 0, 'f', 3) + .arg( np->distance(), 0, 'f', 3)); } else if(len > 0.2) { @@ -532,11 +534,11 @@ struct Partitioner::Instance void buildHEdgesAtIntersectionGaps(SuperBlock& rightList, SuperBlock& leftList) { - HPlane::Intercepts::const_iterator node = partition->begin(); - while(node != partition->end()) + HPlane::Intercepts::const_iterator node = partition->intercepts().begin(); + while(node != partition->intercepts().end()) { HPlane::Intercepts::const_iterator np = node; np++; - if(np == partition->end()) break; + if(np == partition->intercepts().end()) break; HEdgeIntercept* cur = reinterpret_cast((*node).userData()); HEdgeIntercept* next = reinterpret_cast((*np).userData()); @@ -1019,8 +1021,7 @@ struct Partitioner::Instance } // Check partition against all half-edges. - for(SuperBlock::HEdges::const_iterator it = block.hedgesBegin(); - it != block.hedgesEnd(); ++it) + DENG2_FOR_EACH(it, block.hedges(), SuperBlock::HEdges::const_iterator) { // Do we already have a better choice? if(best && !(cost < bestCost)) return false; // Stop iteration. @@ -1112,8 +1113,7 @@ struct Partitioner::Instance DENG_ASSERT(best); // Test each half-edge as a potential partition. - for(SuperBlock::HEdges::const_iterator it = partList.hedgesBegin(); - it != partList.hedgesEnd(); ++it) + DENG2_FOR_EACH(it, partList.hedges(), SuperBlock::HEdges::const_iterator) { HEdge* hedge = *it; @@ -1444,7 +1444,7 @@ struct Partitioner::Instance void clearPartitionIntercepts() { - for(HPlane::Intercepts::iterator it = partition->begin(); it != partition->end(); ++it) + DENG2_FOR_EACH(it, partition->intercepts(), HPlane::Intercepts::const_iterator) { HEdgeIntercept* intercept = static_cast((*it).userData()); deleteHEdgeIntercept(*intercept); @@ -1753,7 +1753,8 @@ struct Partitioner::Instance mergeIntersections(); LOG_TRACE("Building HEdges along partition [%1.1f, %1.1f] > [%1.1f, %1.1f]") - << partitionInfo.start[VX] << partitionInfo.start[VY] << partitionInfo.direction[VX] << partitionInfo.direction[VY]; + << partitionInfo.start[VX] << partitionInfo.start[VY] + << partitionInfo.direction[VX] << partitionInfo.direction[VY]; // Find connections in the intersections. buildHEdgesAtIntersectionGaps(rightList, leftList); @@ -1771,10 +1772,11 @@ struct Partitioner::Instance { if(!vertex) return NULL; // Hmm... - for(HPlane::Intercepts::const_iterator it = partition->begin(); it != partition->end(); ++it) + DENG2_FOR_EACH(it, partition->intercepts(), HPlane::Intercepts::const_iterator) { const HPlaneIntercept* inter = &*it; - if(reinterpret_cast(inter->userData())->vertex == vertex) return inter; + HEdgeIntercept* hedgeInter = reinterpret_cast(inter->userData()); + if(hedgeInter->vertex == vertex) return inter; } return NULL; diff --git a/doomsday/engine/portable/src/map/bsp/superblockmap.cpp b/doomsday/engine/portable/src/map/bsp/superblockmap.cpp index 1f8ff41401..b5823b6971 100644 --- a/doomsday/engine/portable/src/map/bsp/superblockmap.cpp +++ b/doomsday/engine/portable/src/map/bsp/superblockmap.cpp @@ -44,8 +44,8 @@ struct SuperBlock::Instance int realNum; int miniNum; - Instance(SuperBlockmap& blockmap) : - bmap(blockmap), tree(0), hedges(0), realNum(0), miniNum(0) + Instance(SuperBlockmap& blockmap) + : bmap(blockmap), tree(0), hedges(0), realNum(0), miniNum(0) {} ~Instance() @@ -53,18 +53,18 @@ struct SuperBlock::Instance KdTreeNode_SetUserData(tree, NULL); } - void inline linkHEdge(HEdge& hedge) + inline void linkHEdge(HEdge& hedge) { hedges.push_front(&hedge); } - void inline incrementHEdgeCount(HEdge const& hedge) + inline void incrementHEdgeCount(HEdge const& hedge) { if(hedge.lineDef) realNum++; else miniNum++; } - void inline decrementHEdgeCount(HEdge const& hedge) + inline void decrementHEdgeCount(HEdge const& hedge) { if(hedge.lineDef) realNum--; else miniNum--; @@ -136,14 +136,9 @@ SuperBlock* SuperBlock::addChild(ChildId childId, bool splitVertical) return child; } -SuperBlock::HEdges::const_iterator SuperBlock::hedgesBegin() const +const SuperBlock::HEdges& SuperBlock::hedges() const { - return d->hedges.begin(); -} - -SuperBlock::HEdges::const_iterator SuperBlock::hedgesEnd() const -{ - return d->hedges.end(); + return d->hedges; } uint SuperBlock::hedgeCount(bool addReal, bool addMini) const @@ -171,7 +166,7 @@ void SuperBlock::findHEdgeBounds(AABoxd& bounds) bool initialized = false; AABoxd hedgeAABox; - for(HEdges::iterator it = d->hedges.begin(); it != d->hedges.end(); ++it) + DENG2_FOR_EACH(it, d->hedges, HEdges::iterator) { HEdge* hedge = *it; initAABoxFromHEdgeVertexes(&hedgeAABox, hedge); @@ -191,9 +186,9 @@ void SuperBlock::findHEdgeBounds(AABoxd& bounds) SuperBlock& SuperBlock::push(HEdge& hedge) { SuperBlock* sb = this; - for(;;) + forever { - Q_ASSERT(sb); + DENG2_ASSERT(sb); // Update half-edge counts. sb->d->incrementHEdgeCount(hedge); @@ -241,7 +236,6 @@ SuperBlock& SuperBlock::push(HEdge& hedge) sb = sb->child(p1); } - return *sb; } @@ -344,7 +338,7 @@ void SuperBlockmap::clear() static void findHEdgeBoundsWorker(SuperBlock& block, AABoxd& bounds, bool* initialized) { - Q_ASSERT(initialized); + DENG2_ASSERT(initialized); if(block.hedgeCount(true, true)) { AABoxd blockHEdgeAABox;