diff --git a/doomsday/client/include/world/bspnode.h b/doomsday/client/include/world/bspnode.h index ddba2d03bb..097b800b81 100644 --- a/doomsday/client/include/world/bspnode.h +++ b/doomsday/client/include/world/bspnode.h @@ -69,6 +69,11 @@ class BspNode : public de::MapElement */ de::Partition const &partition() const; + /** + * Calculates the height of this BSP subtree (note result is not cached). + */ + size_t height() const; + /** * Returns @c true iff the specified child is configured. */ @@ -91,7 +96,14 @@ class BspNode : public de::MapElement * * @see hasChild() */ - de::MapElement &child(int left) const; + de::MapElement &child(int left); + de::MapElement const &child(int left) const; + + inline de::MapElement &right() { return child(Right); } + inline de::MapElement const &right() const { return child(Right); } + + inline de::MapElement &left() { return child(Left); } + inline de::MapElement const &left() const { return child(Left); } /** * Returns a pointer to the specified child of the BSP node, which may be @@ -101,7 +113,10 @@ class BspNode : public de::MapElement * * @see hasChild() */ - inline de::MapElement *childPtr(int left) const { + inline de::MapElement *childPtr(int left) { + return hasChild(left)? &child(left) : 0; + } + inline de::MapElement const *childPtr(int left) const { return hasChild(left)? &child(left) : 0; } diff --git a/doomsday/client/src/world/bspnode.cpp b/doomsday/client/src/world/bspnode.cpp index d13ff581bf..b8a834116a 100644 --- a/doomsday/client/src/world/bspnode.cpp +++ b/doomsday/client/src/world/bspnode.cpp @@ -67,12 +67,24 @@ Partition const &BspNode::partition() const return d->partition; } +size_t BspNode::height() const +{ + DENG2_ASSERT(hasLeft() || hasRight()); + size_t rHeight = 0; + if(hasRight() && right().type() == DMU_BSPNODE) + rHeight = right().as().height(); + size_t lHeight = 0; + if(hasLeft() && left().type() == DMU_BSPNODE) + lHeight = left().as().height(); + return (rHeight> lHeight? rHeight : lHeight) + 1; +} + bool BspNode::hasChild(int left) const { return *d->childAdr(left) != 0; } -MapElement &BspNode::child(int left) const +MapElement &BspNode::child(int left) { if(MapElement *childElm = *d->childAdr(left)) { @@ -82,6 +94,11 @@ MapElement &BspNode::child(int left) const throw MissingChildError("BspNode::child", QString("No %1 child is configured").arg(left? "left" : "right")); } +MapElement const &BspNode::child(int left) const +{ + return const_cast(const_cast(this)->child(left)); +} + void BspNode::setChild(int left, MapElement *newChild) { if(!newChild || newChild != this)