Skip to content

Commit

Permalink
API: Combined map line box iterator functions
Browse files Browse the repository at this point in the history
There is now only one function for iterating the map lines within a
user-defined AABox in map space, named P_LinesBoxIterator. Flags are
used specify which type(s) of map line are to be processed. Behavior
is unchanged.
  • Loading branch information
danij-deng committed Oct 2, 2013
1 parent fa64799 commit c8edd13
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 89 deletions.
29 changes: 17 additions & 12 deletions doomsday/api/api_map.h
Expand Up @@ -84,6 +84,18 @@

struct intercept_s;

/**
* @defgroup boxLineIteratorFlags Box Line Iterator Flags
* @ingroup apiFlags map
*/
///@{
#define BLF_SECTOR 0x1 ///< Process map lines defining sectors
#define BLF_POLYOBJ 0x2 ///< Process map lines defining polyobjs

/// Process all map line types.
#define BLF_ALL BLF_SECTOR | BLF_POLYOBJ
///@}

/**
* Public definitions of the internal map data pointers. These can be
* accessed externally, but only as identifiers to data instances.
Expand Down Expand Up @@ -302,26 +314,21 @@ DENG_API_TYPEDEF(Map)
// Iterators

int (*Box_MobjsIterator)(AABoxd const *box, int (*callback) (struct mobj_s *, void *), void *context);
int (*Box_LinesIterator)(AABoxd const *box, int (*callback) (Line *, void *), void *context);

/**
* Lines and Polyobj Lines (note Polyobj Lines are iterated first).
*
* The validCount flags are used to avoid checking lines that are marked
* in multiple mapblocks, so increment validCount before the first call
* to Map::iterateCellLines() then make one or more calls to it.
*/
int (*Box_AllLinesIterator)(AABoxd const *box, int (*callback) (Line *, void *), void *context);

/**
* The validCount flags are used to avoid checking polys that are marked in
* The validCount flags are used to avoid checking lines that are marked in
* multiple mapblocks, so increment validCount before the first call, then
* make one or more calls to it.
*
* @param flags @ref boxLineIteratorFlags
*/
int (*Box_PolyobjLinesIterator)(AABoxd const *box, int (*callback) (Line *, void *), void *context);
int (*Box_LinesIterator)(AABoxd const *box, int flags, int (*callback) (Line *, void *), void *context);

int (*Box_BspLeafsIterator)(AABoxd const *box, Sector *sector, int (*callback) (BspLeaf *, void *), void *context);
int (*Box_PolyobjsIterator)(AABoxd const *box, int (*callback) (struct polyobj_s *, void *), void *context);

int (*PathTraverse2)(coord_t const from[2], coord_t const to[2], int flags, int (*callback) (struct intercept_s const *, void *context), void *context);
int (*PathTraverse)(coord_t const from[2], coord_t const to[2], int flags, int (*callback) (struct intercept_s const *, void *context)/*, context=0*/);

Expand Down Expand Up @@ -606,8 +613,6 @@ DENG_API_T(Map);

#define P_MobjsBoxIterator _api_Map.Box_MobjsIterator
#define P_LinesBoxIterator _api_Map.Box_LinesIterator
#define P_AllLinesBoxIterator _api_Map.Box_AllLinesIterator
#define P_PolyobjLinesBoxIterator _api_Map.Box_PolyobjLinesIterator
#define P_BspLeafsBoxIterator _api_Map.Box_BspLeafsIterator
#define P_PolyobjsBoxIterator _api_Map.Box_PolyobjsIterator
#define P_PathTraverse2 _api_Map.PathTraverse2
Expand Down
39 changes: 21 additions & 18 deletions doomsday/client/include/world/map.h
Expand Up @@ -450,13 +450,7 @@ class Map
Polyobj **poly, Plane **plane, Surface **surface) const;

int mobjsBoxIterator(AABoxd const &box,
int (*callback) (struct mobj_s *, void *), void *parameters = 0) const;

int linesBoxIterator(AABoxd const &box,
int (*callback) (Line *, void *), void *parameters = 0) const;

int polyobjLinesBoxIterator(AABoxd const &box,
int (*callback) (Line *, void *), void *parameters = 0) const;
int (*callback) (struct mobj_s *, void *), void *context = 0) const;

/**
* Lines and Polyobj lines (note polyobj lines are iterated first).
Expand All @@ -465,12 +459,21 @@ class Map
* a new logical traversal. Otherwise Lines marked with a validCount
* equal to this will be skipped over (can be used to avoid processing
* a line multiple times during complex / non-linear traversals.
*
* @param flags @ref boxLineIteratorFlags
*/
int allLinesBoxIterator(AABoxd const &box,
int (*callback) (Line *, void *), void *parameters = 0) const;
int linesBoxIterator(AABoxd const &box, int flags,
int (*callback) (Line *, void *), void *context = 0) const;

/// @copydoc linesBoxIterator()
inline int linesBoxIterator(AABoxd const &box,
int (*callback) (Line *, void *), void *context = 0) const
{
return linesBoxIterator(box, BLF_ALL, callback, context);
}

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

/**
* @note validCount should be incremented before calling this to begin a
Expand All @@ -479,14 +482,14 @@ class Map
* multiple times during complex / non-linear traversals.
*/
int polyobjsBoxIterator(AABoxd const &box,
int (*callback) (struct polyobj_s *, void *), void *parameters = 0) const;
int (*callback) (struct polyobj_s *, void *), void *context = 0) const;

/**
* The callback function will be called once for each line that crosses
* trough the object. This means all the lines will be two-sided.
*/
int mobjLinesIterator(struct mobj_s *mo,
int (*callback) (Line *, void *), void *parameters = 0) const;
int (*callback) (Line *, void *), void *context = 0) const;

/**
* Increment validCount before calling this routine. The callback function
Expand All @@ -495,10 +498,10 @@ class Map
* above or under the sector.
*/
int mobjSectorsIterator(struct mobj_s *mo,
int (*callback) (Sector *, void *), void *parameters = 0) const;
int (*callback) (Sector *, void *), void *context = 0) const;

int lineMobjsIterator(Line *line,
int (*callback) (struct mobj_s *, void *), void *parameters = 0) const;
int (*callback) (struct mobj_s *, void *), void *context = 0) const;

/**
* Increment validCount before using this. 'func' is called for each mobj
Expand All @@ -509,15 +512,15 @@ class Map
* a bunch of LineMobjs iterations.)
*/
int sectorTouchingMobjsIterator(Sector *sector,
int (*callback) (struct mobj_s *, void *), void *parameters = 0) const;
int (*callback) (struct mobj_s *, void *), void *context = 0) const;

/**
* Trace a line between @a from and @a to, making a callback for each
* interceptable object linked within Blockmap cells which cover the path
* this defines.
*/
int pathTraverse(const_pvec2d_t from, const_pvec2d_t to, int flags,
traverser_t callback, void *parameters = 0);
traverser_t callback, void *context = 0);

/**
* @copydoc pathTraverse()
Expand All @@ -528,11 +531,11 @@ class Map
* @param toY Y axis map space coordinate for the path destination.
*/
inline int pathTraverse(coord_t fromX, coord_t fromY, coord_t toX, coord_t toY,
int flags, traverser_t callback, void *parameters = 0)
int flags, traverser_t callback, void *context = 0)
{
coord_t from[2] = { fromX, fromY };
coord_t to[2] = { toX, toY };
return pathTraverse(from, to, flags, callback, parameters);
return pathTraverse(from, to, flags, callback, context);
}

/**
Expand Down
22 changes: 2 additions & 20 deletions doomsday/client/src/world/api_map.cpp
Expand Up @@ -1609,19 +1609,11 @@ DENG_EXTERN_C int P_PolyobjsBoxIterator(AABoxd const *box,
}

#undef P_LinesBoxIterator
DENG_EXTERN_C int P_LinesBoxIterator(AABoxd const *box,
DENG_EXTERN_C int P_LinesBoxIterator(AABoxd const *box, int flags,
int (*callback) (Line *, void *), void *parameters)
{
if(!box || !App_World().hasMap()) return false; // Continue iteration.
return App_World().map().linesBoxIterator(*box, callback, parameters);
}

#undef P_PolyobjLinesBoxIterator
DENG_EXTERN_C int P_PolyobjLinesBoxIterator(AABoxd const *box,
int (*callback) (Line *, void *), void *parameters)
{
if(!box || !App_World().hasMap()) return false; // Continue iteration.
return App_World().map().polyobjLinesBoxIterator(*box, callback, parameters);
return App_World().map().linesBoxIterator(*box, flags, callback, parameters);
}

#undef P_BspLeafsBoxIterator
Expand All @@ -1632,14 +1624,6 @@ DENG_EXTERN_C int P_BspLeafsBoxIterator(AABoxd const *box, Sector *sector,
return App_World().map().bspLeafsBoxIterator(*box, sector, callback, parameters);
}

#undef P_AllLinesBoxIterator
DENG_EXTERN_C int P_AllLinesBoxIterator(AABoxd const *box,
int (*callback) (Line *, void *), void *parameters)
{
if(!box || !App_World().hasMap()) return false; // Continue iteration.
return App_World().map().allLinesBoxIterator(*box, callback, parameters);
}

#undef P_PathTraverse2
DENG_EXTERN_C int P_PathTraverse2(const_pvec2d_t from, const_pvec2d_t to,
int flags, traverser_t callback, void *parameters)
Expand Down Expand Up @@ -1884,8 +1868,6 @@ DENG_DECLARE_API(Map) =

P_MobjsBoxIterator,
P_LinesBoxIterator,
P_AllLinesBoxIterator,
P_PolyobjLinesBoxIterator,
P_BspLeafsBoxIterator,
P_PolyobjsBoxIterator,
P_PathTraverse2,
Expand Down
48 changes: 22 additions & 26 deletions doomsday/client/src/world/map.cpp
Expand Up @@ -420,7 +420,7 @@ DENG2_OBSERVES(bsp::Partitioner, UnclosedSectorFound)
scanRegion.maxX = line->aaBox().maxX + bsp::DIST_EPSILON;
}
validCount++;
self.linesBoxIterator(scanRegion, testForWindowEffectWorker, &p);
self.linesBoxIterator(scanRegion, BLF_SECTOR, testForWindowEffectWorker, &p);

if(p.backOpen && p.frontOpen && line->frontSectorPtr() == p.backOpen)
{
Expand Down Expand Up @@ -845,7 +845,7 @@ DENG2_OBSERVES(bsp::Partitioner, UnclosedSectorFound)
V2d_AddToBox(parm.box.arvec2, point);

validCount++;
self.allLinesBoxIterator(parm.box, lineLinkerWorker, &parm);
self.linesBoxIterator(parm.box, lineLinkerWorker, &parm);
}

/**
Expand Down Expand Up @@ -2131,39 +2131,35 @@ static int iterateBlockPolyobjLines(Blockmap &polyobjBlockmap,
return polyobjBlockmap.iterate(cellBlock, blockmapCellPolyobjsIterator, (void*) &args);
}

int Map::linesBoxIterator(AABoxd const &box,
int Map::linesBoxIterator(AABoxd const &box, int flags,
int (*callback) (Line *, void *), void *parameters) const
{
if(!d->lineBlockmap.isNull())
// Process polyobj lines?
if((flags & BLF_POLYOBJ) && polyobjCount())
{
Blockmap::CellBlock cellBlock = d->lineBlockmap->toCellBlock(box);
return iterateCellBlockLines(*d->lineBlockmap, cellBlock, callback, parameters);
}
/// @throw MissingBlockmapError The line blockmap is not yet initialized.
throw MissingBlockmapError("Map::linesBoxIterator", "Line blockmap is not initialized");
}
if(d->polyobjBlockmap.isNull())
/// @throw MissingBlockmapError The polyobj blockmap is not yet initialized.
throw MissingBlockmapError("Map::linesBoxIterator", "Polyobj blockmap is not initialized");

int Map::polyobjLinesBoxIterator(AABoxd const &box,
int (*callback) (Line *, void *), void *parameters) const
{
if(!d->polyobjBlockmap.isNull())
{
Blockmap::CellBlock cellBlock = d->polyobjBlockmap->toCellBlock(box);
return iterateBlockPolyobjLines(*d->polyobjBlockmap, cellBlock, callback, parameters);
if(int result = iterateBlockPolyobjLines(*d->polyobjBlockmap, cellBlock,
callback, parameters))
return result;
}
/// @throw MissingBlockmapError The polyobj blockmap is not yet initialized.
throw MissingBlockmapError("Map::polyobjBlockmap", "Polyobj blockmap is not initialized");
}

int Map::allLinesBoxIterator(AABoxd const &box,
int (*callback) (Line *, void *), void *parameters) const
{
if(polyobjCount())
// Process sector lines?
if(flags & BLF_SECTOR)
{
int result = polyobjLinesBoxIterator(box, callback, parameters);
if(result) return result;
if(d->lineBlockmap.isNull())
/// @throw MissingBlockmapError The line blockmap is not yet initialized.
throw MissingBlockmapError("Map::linesBoxIterator", "Line blockmap is not initialized");

Blockmap::CellBlock cellBlock = d->lineBlockmap->toCellBlock(box);
if(int result = iterateCellBlockLines(*d->lineBlockmap, cellBlock, callback, parameters))
return result;
}
return linesBoxIterator(box, callback, parameters);

return 0; // Continue iteration.
}

static int traverseCellPath2(Blockmap &bmap, Blockmap::Cell const &fromCell,
Expand Down
6 changes: 4 additions & 2 deletions doomsday/client/src/world/p_particle.cpp
Expand Up @@ -1159,14 +1159,16 @@ static void P_MoveParticle(ptcgen_t *gen, particle_t *pt)
V2d_AddToBox(mbox.arvec2, point);

// Iterate the lines in the contacted blocks.
/// @todo Don't assume the current map.

validCount++;
if(P_AllLinesBoxIterator(&mbox, PIT_CheckLinePtc, 0))
if(App_World().map().linesBoxIterator(mbox, PIT_CheckLinePtc))
{
fixed_t normal[2], dotp;

// Must survive the touch.
if(!P_TouchParticle(pt, st, stDef, true)) return;
if(!P_TouchParticle(pt, st, stDef, true))
return;

// There was a hit! Calculate bounce vector.
// - Project movement vector on the normal of hitline.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/hu_automap.c
Expand Up @@ -845,7 +845,7 @@ static void rendPolyobjs(uiwidget_t* ob)

// Draw any polyobjects in view.
UIAutomap_PVisibleAABounds(ob, &aaBox.minX, &aaBox.maxX, &aaBox.minY, &aaBox.maxY);
P_PolyobjLinesBoxIterator(&aaBox, rendPolyobjLine, ob);
P_LinesBoxIterator(&aaBox, BLF_POLYOBJ, rendPolyobjLine, ob);
}

#if __JDOOM__ || __JHERETIC__ || __JDOOM64__
Expand Down Expand Up @@ -886,7 +886,7 @@ static void rendXGLinedefs(uiwidget_t* obj)
rs.objType = -1;

UIAutomap_PVisibleAABounds(obj, &aaBox.minX, &aaBox.maxX, &aaBox.minY, &aaBox.maxY);
P_LinesBoxIterator(&aaBox, rendXGLinedef, obj);
P_LinesBoxIterator(&aaBox, BLF_SECTOR, rendXGLinedef, obj);
}
#endif

Expand Down
14 changes: 7 additions & 7 deletions doomsday/plugins/common/src/p_map.c
Expand Up @@ -401,7 +401,7 @@ boolean P_CheckSides(mobj_t* actor, coord_t x, coord_t y)
tmBox.maxY = (startPos[VY] > endPos[VY]? startPos[VY] : endPos[VY]);

VALIDCOUNT++;
return P_AllLinesBoxIterator(&tmBox, PIT_CrossLine, 0);
return P_LinesBoxIterator(&tmBox, BLF_ALL, PIT_CrossLine, 0);
}

#if __JDOOM__ || __JDOOM64__ || __JHERETIC__
Expand Down Expand Up @@ -1240,20 +1240,20 @@ boolean P_CheckPositionXYZ(mobj_t *thing, coord_t x, coord_t y, coord_t z)
tmBoxExpanded.maxX = tmBox.maxX;
tmBoxExpanded.maxY = tmBox.maxY;

return !P_AllLinesBoxIterator(&tmBoxExpanded, PIT_CheckLine, 0);
return !P_LinesBoxIterator(&tmBoxExpanded, BLF_ALL, PIT_CheckLine, 0);
}

boolean P_CheckPosition(mobj_t* thing, coord_t const pos[3])
boolean P_CheckPosition(mobj_t *thing, coord_t const pos[3])
{
return P_CheckPositionXYZ(thing, pos[VX], pos[VY], pos[VZ]);
}

boolean P_CheckPositionXY(mobj_t* thing, coord_t x, coord_t y)
boolean P_CheckPositionXY(mobj_t *thing, coord_t x, coord_t y)
{
return P_CheckPositionXYZ(thing, x, y, DDMAXFLOAT);
}

boolean Mobj_IsRemotePlayer(mobj_t* mo)
boolean Mobj_IsRemotePlayer(mobj_t *mo)
{
return (mo && ((IS_DEDICATED && mo->dPlayer) ||
(IS_CLIENT && mo->player && mo->player - players != CONSOLEPLAYER)));
Expand All @@ -1264,9 +1264,9 @@ boolean Mobj_IsRemotePlayer(mobj_t* mo)
* MF_TELEPORT is set. $dropoff_fix
*/
#if __JHEXEN__
static boolean P_TryMove2(mobj_t* thing, coord_t x, coord_t y)
static boolean P_TryMove2(mobj_t *thing, coord_t x, coord_t y)
#else
static boolean P_TryMove2(mobj_t* thing, coord_t x, coord_t y, boolean dropoff)
static boolean P_TryMove2(mobj_t *thing, coord_t x, coord_t y, boolean dropoff)
#endif
{
boolean isRemotePlayer = Mobj_IsRemotePlayer(thing);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/p_start.cpp
Expand Up @@ -1164,7 +1164,7 @@ static int turnMobjToNearestLine(thinker_t *th, void *context)

VALIDCOUNT++;

P_LinesBoxIterator(&aaBox, PIT_FindNearestFacingLine, &params);
P_LinesBoxIterator(&aaBox, BLF_SECTOR, PIT_FindNearestFacingLine, &params);

if(params.line)
{
Expand Down Expand Up @@ -1206,7 +1206,7 @@ static int moveMobjOutOfNearbyLines(thinker_t *th, void *paramaters)

VALIDCOUNT++;

P_LinesBoxIterator(&aaBox, unstuckMobjInLine, &params);
P_LinesBoxIterator(&aaBox, BLF_SECTOR, unstuckMobjInLine, &params);

if(!FEQUAL(mo->origin[VX], params.pos[VX]) || !FEQUAL(mo->origin[VY], params.pos[VY]))
{
Expand Down

0 comments on commit c8edd13

Please sign in to comment.