Skip to content

Commit

Permalink
World|Map: Removed unnecessary sector filter from Map::bspLeafBoxIter…
Browse files Browse the repository at this point in the history
…ator()

The caller can just as easily implement this in the callback.
  • Loading branch information
danij-deng committed Oct 11, 2013
1 parent 1d7f6c0 commit 14d3956
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 38 deletions.
2 changes: 1 addition & 1 deletion doomsday/api/api_map.h
Expand Up @@ -353,7 +353,7 @@ DENG_API_TYPEDEF(Map)
*/
void (*PO_SetCallback)(void (*func)(struct mobj_s *, void *, void *));

int (*BL_BoxIterator)(AABoxd const *box, Sector *sector, int (*callback) (BspLeaf *, void *), void *context);
int (*BL_BoxIterator)(AABoxd const *box, int (*callback) (BspLeaf *, void *), void *context);

// Traversers

Expand Down
11 changes: 2 additions & 9 deletions doomsday/client/include/world/map.h
Expand Up @@ -404,7 +404,7 @@ class Map
* the BspLeaf pointer. Can be called without unlinking first.
* Should be called AFTER mobj translation to (re-)insert the mobj.
*/
void link(struct mobj_s &mobj, byte flags);
void link(struct mobj_s &mobj, int flags);

/**
* Link the specified @a polyobj in any internal data structures for
Expand Down Expand Up @@ -489,16 +489,9 @@ class Map
return linePathIterator(from, to, LIF_ALL, callback, context);
}

int bspLeafBoxIterator(AABoxd const &box, Sector *sector,
int bspLeafBoxIterator(AABoxd const &box,
int (*callback) (BspLeaf *bspLeaf, void *context), void *context = 0) const;

/// @copydoc bspLeafsBoxIterator()
inline int bspLeafBoxIterator(AABoxd const &box,
int (*callback) (BspLeaf *bspLeaf, void *context), void *context = 0) const
{
return bspLeafBoxIterator(box, 0, callback, context);
}

/**
* @note validCount should be incremented before calling this to begin a
* new logical traversal. Otherwise Lines marked with a validCount equal
Expand Down
9 changes: 6 additions & 3 deletions doomsday/client/src/render/r_fakeradio.cpp
Expand Up @@ -194,7 +194,11 @@ void Rend_RadioUpdateVertexShadowOffsets(Vertex &vtx)

static int linkShadowLineToBspLeafWorker(BspLeaf *bspLeaf, void *context)
{
bspLeaf->addShadowLine(*static_cast<LineSide *>(context));
LineSide &side = *static_cast<LineSide *>(context);
if(bspLeaf->sectorPtr() == side.sectorPtr())
{
bspLeaf->addShadowLine(side);
}
return false; // Continue iteration.
}

Expand Down Expand Up @@ -252,8 +256,7 @@ void Rend_RadioInitForMap(Map &map)

// Link the shadowing line to all the BspLeafs whose axis-aligned
// bounding box intersects 'bounds'.
map.bspLeafBoxIterator(bounds, side.sectorPtr(),
linkShadowLineToBspLeafWorker, &side);
map.bspLeafBoxIterator(bounds, linkShadowLineToBspLeafWorker, &side);
}
}

Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/world/api_map.cpp
Expand Up @@ -1618,11 +1618,11 @@ DENG_EXTERN_C int Line_BoxIterator(AABoxd const *box, int flags,
}

#undef BspLeaf_BoxIterator
DENG_EXTERN_C int BspLeaf_BoxIterator(AABoxd const *box, Sector *sector,
DENG_EXTERN_C int BspLeaf_BoxIterator(AABoxd const *box,
int (*callback) (BspLeaf *, void *), void *context)
{
if(!box || !App_World().hasMap()) return false; // Continue iteration.
return App_World().map().bspLeafBoxIterator(*box, sector, callback, context);
return App_World().map().bspLeafBoxIterator(*box, callback, context);
}

static void collectLineIntercept(Line &line, divline_t const &traceLos)
Expand Down Expand Up @@ -1698,7 +1698,7 @@ static void collectMobjIntercept(mobj_t &mobj, divline_t const &traceLos)
dl.origin[VY] = DBL2FIX(from[VY]);
dl.direction[VX] = DBL2FIX(to[VX] - from[VX]);
dl.direction[VY] = DBL2FIX(to[VY] - from[VY]);
coord_t distance = FIX2FLT(Divline_Intersection(&dl, &traceLos));
float distance = FIX2FLT(Divline_Intersection(&dl, &traceLos));

// On the correct side of the trace origin?
if(distance >= 0)
Expand Down
36 changes: 16 additions & 20 deletions doomsday/client/src/world/map.cpp
Expand Up @@ -1678,7 +1678,6 @@ static int blockmapCellLinesIterator(void *mapElement, void *context)
struct blockmapcellbspleafsiterator_params_t
{
AABoxd const *box;
Sector *sector;
int localValidCount;
int (*callback) (BspLeaf *, void *);
void *context;
Expand All @@ -1694,31 +1693,29 @@ static int blockmapCellBspLeafsIterator(void *object, void *context)
// This BspLeaf has now been processed for the current iteration.
bspLeaf->setValidCount(parm.localValidCount);

// Check the sector restriction.
bool ok = !(parm.sector && bspLeaf->sectorPtr() != parm.sector);

// Check the bounds.
AABoxd const &leafAABox = bspLeaf->poly().aaBox();
if(parm.box &&
(leafAABox.maxX < parm.box->minX ||
leafAABox.minX > parm.box->maxX ||
leafAABox.minY > parm.box->maxY ||
leafAABox.maxY < parm.box->minY))
ok = false;

if(ok)
if(parm.box)
{
// Action the callback.
if(int result = parm.callback(bspLeaf, parm.context))
return result; // Stop iteration.
if(leafAABox.maxX < parm.box->minX ||
leafAABox.minX > parm.box->maxX ||
leafAABox.minY > parm.box->maxY ||
leafAABox.maxY < parm.box->minY)
{
return false; // Continue iteration.
}
}

// Action the callback.
if(int result = parm.callback(bspLeaf, parm.context))
return result; // Stop iteration.
}

return false; // Continue iteration.
}

int Map::bspLeafBoxIterator(AABoxd const &box, Sector *sector,
int (*callback) (BspLeaf *, void *), void *context) const
int Map::bspLeafBoxIterator(AABoxd const &box, int (*callback) (BspLeaf *, void *),
void *context) const
{
if(!d->bspLeafBlockmap.isNull())
{
Expand All @@ -1730,7 +1727,6 @@ int Map::bspLeafBoxIterator(AABoxd const &box, Sector *sector,
parm.localValidCount = localValidCount;
parm.callback = callback;
parm.context = context;
parm.sector = sector;
parm.box = &box;

return d->bspLeafBlockmap->iterate(box, blockmapCellBspLeafsIterator, &parm);
Expand Down Expand Up @@ -1896,7 +1892,7 @@ int Map::unlink(mobj_t &mo)
return links;
}

void Map::link(mobj_t &mo, byte flags)
void Map::link(mobj_t &mo, int flags)
{
BspLeaf &bspLeafAtOrigin = bspLeafAt_FixedPrecision(Mobj_Origin(mo));

Expand Down Expand Up @@ -2088,7 +2084,7 @@ int Map::linePathIterator(Vector2d const &from, Vector2d const &to, int flags,
}

// Process sector lines?
if((flags & LIF_SECTOR))
if(flags & LIF_SECTOR)
{
if(d->lineBlockmap.isNull())
/// @throw MissingBlockmapError The line blockmap is not yet initialized.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/world/sectorcluster.cpp
Expand Up @@ -695,7 +695,7 @@ DENG2_OBSERVES(Plane, HeightChange)

// Link all non-degenerate BspLeafs whose axis-aligned bounding box intersects
// with the affection bounds to the reverb set.
self.sector().map().bspLeafBoxIterator(affectionBounds, 0, addReverbBspLeafWorker, this);
self.sector().map().bspLeafBoxIterator(affectionBounds, addReverbBspLeafWorker, this);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/hu_automap.c
Expand Up @@ -710,7 +710,7 @@ static void drawMapLines(uiwidget_t *obj, int objType, boolean addToLists)
{
AABoxd aaBox;
UIAutomap_PVisibleAABounds(obj, &aaBox.minX, &aaBox.maxX, &aaBox.minY, &aaBox.maxY);
BspLeaf_BoxIterator(&aaBox, NULL, drawMapLinesForBspLeafWorker, obj);
BspLeaf_BoxIterator(&aaBox, drawMapLinesForBspLeafWorker, obj);
}
else
{
Expand Down

0 comments on commit 14d3956

Please sign in to comment.