Navigation Menu

Skip to content

Commit

Permalink
Refactor|BspBuilder: Removed unnecessary recalculation of the map bounds
Browse files Browse the repository at this point in the history
The world bounds of the map geometry are already known by the time
the BSP build begins - reuse the same values.
  • Loading branch information
danij-deng committed Apr 7, 2013
1 parent e6dd0fc commit 49cf3cd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 60 deletions.
5 changes: 5 additions & 0 deletions doomsday/client/include/map/hedge.h
Expand Up @@ -264,6 +264,11 @@ class HEdge : public de::MapElement
*/
inline HEdge *twinPtr() const { return hasTwin()? &twin() : 0; }

/**
* Returns @c true iff a BspLeaf is linked to the half-edge.
*/
bool hasBspLeaf() const;

/**
* Returns the BSP leaf for the half-edge.
*/
Expand Down
8 changes: 6 additions & 2 deletions doomsday/client/src/edit_map.cpp
Expand Up @@ -1058,11 +1058,15 @@ boolean MPE_End()
}
}

map->updateBounds();
AABoxd const &mapBounds = map->bounds();
LOG_INFO("Map bounds: min%s max%s")
<< Vector2d(mapBounds.min).asText()
<< Vector2d(mapBounds.max).asText();

/*
* Build blockmaps.
*/
map->updateBounds();

vec2d_t min, max;
map->bounds(min, max);

Expand Down
62 changes: 4 additions & 58 deletions doomsday/client/src/map/bsp/partitioner.cpp
Expand Up @@ -73,7 +73,6 @@ enum LineRelationship
};

static LineRelationship lineRelationship(coord_t a, coord_t b, coord_t distEpsilon);
static AABoxd findMapBounds(GameMap *map);
static AABox blockmapBounds(AABoxd const &mapBounds);
static bool findBspLeafCenter(BspLeaf const &leaf, pvec2d_t midPoint);
static void initAABoxFromEditableLineDefVertexes(AABoxd *aaBox, LineDef const *line);
Expand Down Expand Up @@ -382,7 +381,7 @@ struct Partitioner::Instance

void initForMap()
{
mapBounds = findMapBounds(map);
mapBounds = map->bounds();

// Initialize vertex info for the initial set of vertexes.
vertexInfos.resize(map->vertexCount());
Expand Down Expand Up @@ -732,13 +731,13 @@ struct Partitioner::Instance
hedgeInfo(newHEdge.twin()).initFromHEdge(newHEdge.twin());

// Has this already been added to a leaf?
if(oldHEdge.twin()._bspLeaf)
if(oldHEdge.twin().hasBspLeaf())
{
// Update the in-leaf references.
oldHEdge.twin()._next = newHEdge.twinPtr();

// There is now one more half-edge in this leaf.
oldHEdge.twin()._bspLeaf->_hedgeCount += 1;
oldHEdge.twin().bspLeaf()._hedgeCount += 1;
}
}

Expand Down Expand Up @@ -847,7 +846,7 @@ struct Partitioner::Instance

// Ensure the new twin half-edge is inserted into the same block as the old twin.
/// @todo This logic can now be moved into splitHEdge().
if(hedge->hasTwin() && !hedge->twin()._bspLeaf)
if(hedge->hasTwin() && !hedge->twin().hasBspLeaf())
{
SuperBlock *bmapBlock = hedgeInfo(hedge->twin()).bmapBlock;
DENG2_ASSERT(bmapBlock);
Expand Down Expand Up @@ -2559,59 +2558,6 @@ static void printPartitionIntercepts(HPlane const &partition)
})
#endif

static void initAABoxFromEditableLineDefVertexes(AABoxd *aaBox, LineDef const *line)
{
const_pvec2d_t &from = line->fromOrigin();
const_pvec2d_t &to = line->toOrigin();
aaBox->minX = de::min(from[VX], to[VX]);
aaBox->minY = de::min(from[VY], to[VY]);
aaBox->maxX = de::max(from[VX], to[VX]);
aaBox->maxY = de::max(from[VY], to[VY]);
}

static AABoxd findMapBounds2(GameMap *map)
{
DENG2_ASSERT(map);
AABoxd bounds;
bool initialized = false;

foreach(LineDef *line, map->lines())
{
// Do not consider zero-length lines (already screened at a higher level).
//if(lineDefInfo(*line).flags.testFlag(LineDefInfo::ZEROLENGTH)) continue;

AABoxd lineAABox;
initAABoxFromEditableLineDefVertexes(&lineAABox, line);

if(initialized)
{
V2d_UniteBox(bounds.arvec2, lineAABox.arvec2);
}
else
{
V2d_CopyBox(bounds.arvec2, lineAABox.arvec2);
initialized = true;
}
}

if(!initialized)
{
// Clear.
V2d_Set(bounds.min, DDMAXFLOAT, DDMAXFLOAT);
V2d_Set(bounds.max, DDMINFLOAT, DDMINFLOAT);
}
return bounds;
}

static AABoxd findMapBounds(GameMap *map)
{
AABoxd mapBounds = findMapBounds2(map);
LOG_VERBOSE("Map bounds:")
<< " min[x:" << mapBounds.minX << ", y:" << mapBounds.minY << "]"
<< " max[x:" << mapBounds.maxX << ", y:" << mapBounds.maxY << "]";
return mapBounds;
}

static AABox blockmapBounds(AABoxd const &mapBounds)
{
AABox mapBoundsi;
Expand Down
5 changes: 5 additions & 0 deletions doomsday/client/src/map/hedge.cpp
Expand Up @@ -122,6 +122,11 @@ HEdge &HEdge::twin() const
throw MissingTwinError("HEdge::twin", "No twin half-edge is associated");
}

bool HEdge::hasBspLeaf() const
{
return _bspLeaf != 0;
}

BspLeaf &HEdge::bspLeaf() const
{
DENG2_ASSERT(_bspLeaf != 0);
Expand Down

0 comments on commit 49cf3cd

Please sign in to comment.