Skip to content

Commit

Permalink
Refactor|GameMap: Moved more GameMap_* functions to methods of GameMap
Browse files Browse the repository at this point in the history
Map element in-box and path traversals.
  • Loading branch information
danij-deng committed Apr 3, 2013
1 parent 0b97574 commit cb7e87d
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 129 deletions.
102 changes: 56 additions & 46 deletions doomsday/client/include/map/gamemap.h
Expand Up @@ -292,6 +292,38 @@ class GameMap
return bspLeafAtPoint(point);
}

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

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

int polyobjLinesBoxIterator(AABoxd const &box,
int (*callback) (LineDef *, void *), void *parameters = 0);

/**
* LineDefs and Polyobj lines (note polyobj lines are iterated first).
*
* @note validCount should be incremented before calling this to begin
* a new logical traversal. Otherwise LineDefs 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.
*/
int allLinesBoxIterator(AABoxd const &box,
int (*callback) (LineDef *, void *), void *parameters = 0);

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

/**
* @note validCount should be incremented before calling this to begin a
* new logical traversal. Otherwise LineDefs 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.
*/
int polyobjsBoxIterator(AABoxd const &box,
int (*callback) (struct polyobj_s *, void *), void *parameters = 0);

/**
* Traces a line of sight.
*
Expand All @@ -305,6 +337,30 @@ class GameMap
bool lineOfSight(const_pvec3d_t from, const_pvec3d_t to, coord_t bottomSlope,
coord_t topSlope, int flags);

/**
* 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);

/**
* @copybrief pathTraverse()
*
* @param fromX X axis map space coordinate for the path origin.
* @param fromY Y axis map space coordinate for the path origin.
* @param toX X axis map space coordinate for the path origin.
* @param toY Y axis map space coordinate for the path origin.
*/
inline int pathTraverse(coord_t fromX, coord_t fromY, coord_t toX, coord_t toY,
int flags, traverser_t callback, void *parameters = 0)
{
coord_t from[2] = { fromX, fromY };
coord_t to[2] = { toX, toY };
return pathTraverse(from, to, flags, callback, parameters);
}

coord_t skyFix(bool ceiling) const;

inline coord_t skyFixFloor() const { return skyFix(false /*the floor*/); }
Expand Down Expand Up @@ -683,52 +739,6 @@ boolean GameMap_IsUsedMobjID(GameMap* map, thid_t id);
*/
void GameMap_SetMobjID(GameMap *map, thid_t id, boolean inUse);

int GameMap_MobjsBoxIterator(GameMap *map, AABoxd const *box,
int (*callback) (struct mobj_s *, void *), void *parameters);

int GameMap_LinesBoxIterator(GameMap *map, AABoxd const *box,
int (*callback) (LineDef *, void *), void *parameters);

int GameMap_PolyobjLinesBoxIterator(GameMap *map, AABoxd const *box,
int (*callback) (LineDef *, void *), void *parameters);

/**
* LineDefs and Polyobj lines (note polyobj lines are iterated first).
*
* @note validCount should be incremented before calling this to begin a new logical traversal.
* Otherwise LineDefs 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.
*/
int GameMap_AllLinesBoxIterator(GameMap *map, AABoxd const *box,
int (*callback) (LineDef *, void *), void *parameters);

int GameMap_BspLeafsBoxIterator(GameMap *map, AABoxd const *box, Sector *sector,
int (*callback) (BspLeaf *, void *), void *parameters);

/**
* @note validCount should be incremented before calling this to begin a new logical traversal.
* Otherwise LineDefs 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.
*/
int GameMap_PolyobjsBoxIterator(GameMap *map, AABoxd const *box,
int (*callback) (struct polyobj_s *, void *), void *parameters);

/**
* Traces 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 GameMap_PathTraverse(GameMap *map, const_pvec2d_t from, const_pvec2d_t to,
int flags, traverser_t callback, void *parameters = 0);

inline int GameMap_PathTraverse(GameMap *map, coord_t fromX, coord_t fromY,
coord_t toX, coord_t toY, int flags, traverser_t callback, void *parameters = 0)
{
coord_t from[2] = { fromX, fromY };
coord_t to[2] = { toX, toY };
return GameMap_PathTraverse(map, from, to, flags, callback, parameters);
}

// The current map.
DENG_EXTERN_C GameMap *theMap;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/map/bsp/partitioner.cpp
Expand Up @@ -370,7 +370,7 @@ struct Partitioner::Instance
scanRegion.maxX = de::max(line->v1Origin()[VX], line->v2Origin()[VX]) + DIST_EPSILON;
}
validCount++;
GameMap_LinesBoxIterator(map, &scanRegion, testForWindowEffectWorker, &p);
map->linesBoxIterator(scanRegion, testForWindowEffectWorker, &p);

if(p.backOpen && p.frontOpen && line->frontSectorPtr() == p.backOpen)
{
Expand Down
90 changes: 37 additions & 53 deletions doomsday/client/src/map/gamemap.cpp
Expand Up @@ -512,13 +512,12 @@ static int GameMap_IterateCellBlockMobjs(GameMap *map, BlockmapCellBlock const *
blockmapCellMobjsIterator, (void*) &args);
}

int GameMap_MobjsBoxIterator(GameMap *map, AABoxd const *box,
int GameMap::mobjsBoxIterator(AABoxd const &box,
int (*callback) (mobj_t *, void *), void *parameters)
{
DENG2_ASSERT(map);
BlockmapCellBlock cellBlock;
Blockmap_CellBlock(map->mobjBlockmap, &cellBlock, box);
return GameMap_IterateCellBlockMobjs(map, &cellBlock, callback, parameters);
Blockmap_CellBlock(mobjBlockmap, &cellBlock, &box);
return GameMap_IterateCellBlockMobjs(this, &cellBlock, callback, parameters);
}

void GameMap::linkLine(LineDef &line)
Expand Down Expand Up @@ -721,21 +720,19 @@ static int GameMap_IterateCellBlockBspLeafs(GameMap *map, BlockmapCellBlock cons
blockmapCellBspLeafsIterator, (void*) &args);
}

int GameMap_BspLeafsBoxIterator(GameMap *map, AABoxd const *box, Sector *sector,
int GameMap::bspLeafsBoxIterator(AABoxd const &box, Sector *sector,
int (*callback) (BspLeaf *, void *), void *parameters)
{
DENG2_ASSERT(map);

static int localValidCount = 0;

// This is only used here.
localValidCount++;

BlockmapCellBlock cellBlock;
Blockmap_CellBlock(map->bspLeafBlockmap, &cellBlock, box);
Blockmap_CellBlock(bspLeafBlockmap, &cellBlock, &box);

return GameMap_IterateCellBlockBspLeafs(map, &cellBlock, sector, box,
localValidCount, callback, parameters);
return GameMap_IterateCellBlockBspLeafs(this, &cellBlock, sector, &box,
localValidCount, callback, parameters);
}

void GameMap::linkPolyobj(Polyobj &polyobj)
Expand Down Expand Up @@ -809,13 +806,12 @@ static int GameMap_IterateCellBlockPolyobjs(GameMap* map, const BlockmapCellBloc
blockmapCellPolyobjsIterator, (void*) &args);
}

int GameMap_PolyobjsBoxIterator(GameMap* map, const AABoxd* box,
int (*callback) (struct polyobj_s*, void*), void* parameters)
int GameMap::polyobjsBoxIterator(AABoxd const &box,
int (*callback) (struct polyobj_s *, void *), void *parameters)
{
BlockmapCellBlock cellBlock;
DENG2_ASSERT(map);
Blockmap_CellBlock(map->polyobjBlockmap, &cellBlock, box);
return GameMap_IterateCellBlockPolyobjs(map, &cellBlock, callback, parameters);
Blockmap_CellBlock(polyobjBlockmap, &cellBlock, &box);
return GameMap_IterateCellBlockPolyobjs(this, &cellBlock, callback, parameters);
}

typedef struct poiterparams_s {
Expand Down Expand Up @@ -868,41 +864,31 @@ static int GameMap_IterateCellBlockPolyobjLineDefs(GameMap* map, const BlockmapC
blockmapCellPolyobjsIterator, (void*) &args);
}

int GameMap_LinesBoxIterator(GameMap* map, const AABoxd* box,
int (*callback) (LineDef*, void*), void* parameters)
int GameMap::linesBoxIterator(AABoxd const &box,
int (*callback) (LineDef *, void *), void *parameters)
{
BlockmapCellBlock cellBlock;
DENG2_ASSERT(map);
Blockmap_CellBlock(map->lineBlockmap, &cellBlock, box);
return GameMap_IterateCellBlockLineDefs(map, &cellBlock, callback, parameters);
Blockmap_CellBlock(lineBlockmap, &cellBlock, &box);
return GameMap_IterateCellBlockLineDefs(this, &cellBlock, callback, parameters);
}

int GameMap_PolyobjLinesBoxIterator(GameMap* map, const AABoxd* box,
int (*callback) (LineDef*, void*), void* parameters)
int GameMap::polyobjLinesBoxIterator(AABoxd const &box,
int (*callback) (LineDef *, void *), void *parameters)
{
BlockmapCellBlock cellBlock;
DENG2_ASSERT(map);
Blockmap_CellBlock(map->polyobjBlockmap, &cellBlock, box);
return GameMap_IterateCellBlockPolyobjLineDefs(map, &cellBlock, callback, parameters);
Blockmap_CellBlock(polyobjBlockmap, &cellBlock, &box);
return GameMap_IterateCellBlockPolyobjLineDefs(this, &cellBlock, callback, parameters);
}

/**
* LineDefs and Polyobj LineDefs (note Polyobj LineDefs 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 GameMap_IterateCellLineDefs(), then make one or more calls to it.
*/
int GameMap_AllLinesBoxIterator(GameMap *map, AABoxd const *box,
int GameMap::allLinesBoxIterator(AABoxd const &box,
int (*callback) (LineDef *, void *), void *parameters)
{
DENG2_ASSERT(map);
if(map->polyobjCount() != 0)
if(!_polyobjs.isEmpty())
{
int result = P_PolyobjLinesBoxIterator(box, callback, parameters);
int result = P_PolyobjLinesBoxIterator(&box, callback, parameters);
if(result) return result;
}
return P_LinesBoxIterator(box, callback, parameters);
return P_LinesBoxIterator(&box, callback, parameters);
}

static int traverseCellPath2(Blockmap* bmap, uint const fromBlock[2],
Expand Down Expand Up @@ -1095,48 +1081,46 @@ static int iteratePolyobjLines(Polyobj *po, void *parameters)
return po->lineIterator(p->callback, p->parameters);
}

static int collectPolyobjLineIntercepts(uint const block[2], void* parameters)
static int collectPolyobjLineIntercepts(uint const block[2], void *parameters)
{
GameMap* map = (GameMap*)parameters;
GameMap *map = (GameMap *)parameters;
iteratepolyobjlines_params_t iplParams;
iplParams.callback = PIT_AddLineDefIntercepts;
iplParams.parameters = NULL;
return GameMap_IterateCellPolyobjs(map, block, iteratePolyobjLines, (void*)&iplParams);
iplParams.callback = PIT_AddLineDefIntercepts;
iplParams.parameters = 0;
return GameMap_IterateCellPolyobjs(map, block, iteratePolyobjLines, (void *)&iplParams);
}

static int collectLineIntercepts(uint const block[2], void* parameters)
static int collectLineIntercepts(uint const block[2], void *parameters)
{
GameMap* map = (GameMap*)parameters;
GameMap *map = (GameMap *)parameters;
return GameMap_IterateCellLines(map, block, PIT_AddLineDefIntercepts, NULL);
}

static int collectMobjIntercepts(uint const block[2], void* parameters)
{
GameMap* map = (GameMap*)parameters;
GameMap *map = (GameMap *)parameters;
return GameMap_IterateCellMobjs(map, block, PIT_AddMobjIntercepts, NULL);
}

int GameMap_PathTraverse(GameMap *map, const_pvec2d_t from, const_pvec2d_t to,
int flags, traverser_t callback, void *parameters)
int GameMap::pathTraverse(const_pvec2d_t from, const_pvec2d_t to, int flags,
traverser_t callback, void *parameters)
{
DENG2_ASSERT(map);

// A new intercept trace begins...
P_ClearIntercepts();
validCount++;

// Step #1: Collect intercepts.
if(flags & PT_ADDLINES)
{
if(theMap->polyobjCount() != 0)
if(!_polyobjs.isEmpty())
{
traverseCellPath(map, map->polyobjBlockmap, from, to, collectPolyobjLineIntercepts, (void *)map);
traverseCellPath(this, polyobjBlockmap, from, to, collectPolyobjLineIntercepts, (void *)this);
}
traverseCellPath(map, map->lineBlockmap, from, to, collectLineIntercepts, (void *)map);
traverseCellPath(this, lineBlockmap, from, to, collectLineIntercepts, (void *)this);
}
if(flags & PT_ADDMOBJS)
{
traverseCellPath(map, map->mobjBlockmap, from, to, collectMobjIntercepts, (void *)map);
traverseCellPath(this, mobjBlockmap, from, to, collectMobjIntercepts, (void *)this);
}

// Step #2: Process sorted intercepts.
Expand Down

0 comments on commit cb7e87d

Please sign in to comment.