Skip to content

Commit

Permalink
Refactor: Moved mobjNodes, lineNodes and lineLinks into GameMap
Browse files Browse the repository at this point in the history
Also moved most of the remaining map data object iterator functions.
  • Loading branch information
danij-deng committed Mar 5, 2012
1 parent fa9c500 commit 8a412ae
Show file tree
Hide file tree
Showing 7 changed files with 426 additions and 296 deletions.
38 changes: 34 additions & 4 deletions doomsday/engine/portable/include/gamemap.h
Expand Up @@ -371,6 +371,9 @@ int GameMap_IterateCellMobjs(GameMap* map, const uint coords[2],
int GameMap_IterateCellBlockMobjs(GameMap* map, const GridmapBlock* blockCoords,
int (*callback) (struct mobj_s*, void*), void* paramaters);

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

/**
* Construct an initial (empty) LineDef Blockmap for this map.
*
Expand All @@ -386,6 +389,27 @@ int GameMap_IterateCellLineDefs(GameMap* map, const uint coords[2],
int GameMap_IterateCellBlockLineDefs(GameMap* map, const GridmapBlock* blockCoords,
int (*callback) (linedef_t*, void*), void* paramaters);

int GameMap_IterateCellPolyobjLineDefs(GameMap* map, const uint coords[2],
int (*callback) (linedef_t*, void*), void* paramaters);
int GameMap_IterateCellBlockPolyobjLineDefs(GameMap* map, const GridmapBlock* blockCoords,
int (*callback) (linedef_t*, void*), void* paramaters);

int GameMap_LineDefsBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (linedef_t*, void*), void* paramaters);

int GameMap_PolyobjLinesBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (linedef_t*, void*), void* 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_AllLineDefsBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (linedef_t*, void*), void* paramaters);

/**
* Construct an initial (empty) Subsector Blockmap for this map.
*
Expand All @@ -403,6 +427,9 @@ int GameMap_IterateCellBlockSubsectors(GameMap* map, const GridmapBlock* blockCo
sector_t* sector, const AABoxf* box, int localValidCount,
int (*callback) (subsector_t*, void*), void* paramaters);

int GameMap_SubsectorsBoxIterator(GameMap* map, const AABoxf* box, sector_t* sector,
int (*callback) (subsector_t*, void*), void* parameters);

/**
* Construct an initial (empty) Polyobj Blockmap for this map.
*
Expand All @@ -419,10 +446,13 @@ int GameMap_IterateCellPolyobjs(GameMap* map, const uint coords[2],
int GameMap_IterateCellBlockPolyobjs(GameMap* map, const GridmapBlock* blockCoords,
int (*callback) (polyobj_t*, void*), void* paramaters);

int GameMap_IterateCellPolyobjLineDefs(GameMap* map, const uint coords[2],
int (*callback) (linedef_t*, void*), void* paramaters);
int GameMap_IterateCellBlockPolyobjLineDefs(GameMap* map, const GridmapBlock* blockCoords,
int (*callback) (linedef_t*, void*), void* paramaters);
/**
* The validCount flags are used to avoid checking polys that are marked in
* multiple mapblocks, so increment validCount before the first call, then
* make one or more calls to it.
*/
int GameMap_PolyobjsBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (struct polyobj_s*, void*), void* parameters);

/**
* Traces a line between @a from and @a to, making a callback for each
Expand Down
73 changes: 48 additions & 25 deletions doomsday/engine/portable/include/p_maputil.h
Expand Up @@ -128,41 +128,64 @@ boolean P_IsPointXYInSector(float x, float y, const sector_t* sector);
*/
boolean P_IsPointXYInSubsector(float x, float y, const subsector_t* subsector);

void P_MobjLink(mobj_t* mo, byte flags);
int P_MobjUnlink(mobj_t* mo);
void P_MobjLink(mobj_t* mo, byte flags);
int P_MobjUnlink(mobj_t* mo);

int PIT_AddLineDefIntercepts(linedef_t* ld, void* paramaters);
int PIT_AddMobjIntercepts(mobj_t* mobj, void* paramaters);
/**
* @important Caller must ensure that the mobj is currently unlinked.
*/
void P_LinkMobjToLineDefs(mobj_t* mo);

/**
* Unlinks the mobj from all the lines it's been linked to. Can be called
* without checking that the list does indeed contain lines.
*/
boolean P_UnlinkMobjFromLineDefs(mobj_t* mo);

/**
* @important The mobj must be currently unlinked.
*/
void P_LinkMobjInBlockmap(mobj_t* mo);

boolean P_UnlinkMobjFromBlockmap(mobj_t* mo);

int P_MobjLinesIterator(mobj_t *mo,
int (*func) (linedef_t *, void *),
void *);
int P_MobjSectorsIterator(mobj_t *mo,
int (*func) (sector_t *, void *),
void *data);
int P_LineMobjsIterator(linedef_t *line,
int (*func) (mobj_t *, void *),
void *data);
int P_SectorTouchingMobjsIterator(sector_t *sector,
int (*func) (mobj_t *,
void *),
void *data);
int PIT_AddLineDefIntercepts(linedef_t* ld, void* parameters);
int PIT_AddMobjIntercepts(mobj_t* mobj, void* parameters);

int P_MobjsBoxIterator(const AABoxf* box, int (*callback) (mobj_t*, void*), void* paramaters);
int P_MobjLinesIterator(mobj_t* mo, int (*func) (linedef_t*, void*), void* parameters);

int P_LinesBoxIterator(const AABoxf* box, int (*callback) (linedef_t*, void*), void* paramaters);
int P_MobjSectorsIterator(mobj_t* mo, int (*func) (sector_t*, void*), void* parameters);

int P_PolyobjsBoxIterator(const AABoxf* box, int (*callback) (polyobj_t*, void*), void* paramaters);
int P_LineMobjsIterator(linedef_t* lineDef, int (*func) (mobj_t*, void*), void* parameters);

int P_PolyobjLinesBoxIterator(const AABoxf* box, int (*callback) (linedef_t*, void*), void* paramaters);
int P_SectorTouchingMobjsIterator(sector_t* sector, int (*func) (mobj_t*, void*), void *parameters);

// LineDefs and Polyobj in LineDefs (note Polyobj LineDefs are iterated first).
int P_AllLinesBoxIterator(const AABoxf* box, int (*callback) (linedef_t*, void*), void* paramaters);
int P_MobjsBoxIterator(const AABoxf* box, int (*callback) (mobj_t*, void*), void* parameters);

int P_LinesBoxIterator(const AABoxf* box, int (*callback) (linedef_t*, void*), void* parameters);

/**
* The validCount flags are used to avoid checking polys that are marked in
* multiple mapblocks, so increment validCount before the first call, then
* make one or more calls to it.
*/
int P_PolyobjsBoxIterator(const AABoxf* box, int (*callback) (polyobj_t*, void*), void* parameters);

int P_PolyobjLinesBoxIterator(const AABoxf* box, int (*callback) (linedef_t*, void*), void* 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 P_AllLinesBoxIterator(const AABoxf* box, int (*callback) (linedef_t*, void*), void* parameters);

int P_SubsectorsBoxIterator(const AABoxf* box, sector_t *sector, int (*callback) (subsector_t*, void*), void* paramaters);
int P_SubsectorsBoxIterator(const AABoxf* box, sector_t* sector, int (*callback) (subsector_t*, void*), void* parameters);

int P_PathTraverse(float const from[2], float const to[2], int flags, traverser_t callback);
int P_PathTraverse2(float const from[2], float const to[2], int flags, traverser_t callback, void* paramaters);
int P_PathTraverse2(float const from[2], float const to[2], int flags, traverser_t callback, void* parameters);

/**
* Same as P_PathTraverse except 'from' and 'to' arguments are specified
Expand Down
4 changes: 1 addition & 3 deletions doomsday/engine/portable/include/r_data.h
Expand Up @@ -276,10 +276,8 @@ typedef struct {

extern colorpaletteid_t defaultColorPalette;

extern nodeindex_t* linelinks;
extern nodepile_t* mobjNodes, *lineNodes;

extern int levelFullBright;

extern byte rendInfoRPolys;
extern byte precacheMapMaterials, precacheSprites, precacheSkins;

Expand Down
114 changes: 92 additions & 22 deletions doomsday/engine/portable/src/gamemap.c
Expand Up @@ -547,6 +547,15 @@ int GameMap_IterateCellBlockMobjs(GameMap* map, const GridmapBlock* blockCoords,
blockmapCellMobjsIterator, (void*) &args);
}

int GameMap_MobjsBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (mobj_t*, void*), void* parameters)
{
GridmapBlock blockCoords;
assert(map);
Blockmap_CellBlockCoords(map->mobjBlockmap, &blockCoords, box);
return GameMap_IterateCellBlockMobjs(map, &blockCoords, callback, parameters);
}

void GameMap_LinkLineDefInBlockmap(GameMap* map, linedef_t* lineDef)
{
vec2_t origin, cellSize, cell, from, to;
Expand Down Expand Up @@ -767,6 +776,21 @@ int GameMap_IterateCellBlockSubsectors(GameMap* map, const GridmapBlock* blockCo
blockmapCellSubsectorsIterator, (void*) &args);
}

int GameMap_SubsectorsBoxIterator(GameMap* map, const AABoxf* box, sector_t* sector,
int (*callback) (subsector_t*, void*), void* parameters)
{
static int localValidCount = 0;
GridmapBlock blockCoords;
assert(map);

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

Blockmap_CellBlockCoords(map->subsectorBlockmap, &blockCoords, box);
return GameMap_IterateCellBlockSubsectors(map, &blockCoords, sector, box,
localValidCount, callback, parameters);
}

void GameMap_LinkPolyobjInBlockmap(GameMap* map, polyobj_t* po)
{
Blockmap* blockmap;
Expand Down Expand Up @@ -856,6 +880,15 @@ int GameMap_IterateCellBlockPolyobjs(GameMap* map, const GridmapBlock* blockCoor
blockmapCellPolyobjsIterator, (void*) &args);
}

int GameMap_PolyobjsBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (struct polyobj_s*, void*), void* parameters)
{
GridmapBlock blockCoords;
assert(map);
Blockmap_CellBlockCoords(map->polyobjBlockmap, &blockCoords, box);
return GameMap_IterateCellBlockPolyobjs(map, &blockCoords, callback, parameters);
}

typedef struct poiterparams_s {
int (*func) (linedef_t*, void*);
void* param;
Expand Down Expand Up @@ -905,9 +938,46 @@ int GameMap_IterateCellBlockPolyobjLineDefs(GameMap* map, const GridmapBlock* bl
blockmapCellPolyobjsIterator, (void*) &args);
}

int GameMap_LineDefsBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (linedef_t*, void*), void* parameters)
{
GridmapBlock blockCoords;
assert(map);
Blockmap_CellBlockCoords(map->lineDefBlockmap, &blockCoords, box);
return GameMap_IterateCellBlockLineDefs(map, &blockCoords, callback, parameters);
}

int GameMap_PolyobjLinesBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (linedef_t*, void*), void* parameters)
{
GridmapBlock blockCoords;
assert(map);
Blockmap_CellBlockCoords(map->polyobjBlockmap, &blockCoords, box);
return GameMap_IterateCellBlockPolyobjLineDefs(map, &blockCoords, 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_AllLineDefsBoxIterator(GameMap* map, const AABoxf* box,
int (*callback) (linedef_t*, void*), void* parameters)
{
assert(map);
if(map->numPolyObjs > 0)
{
int result = P_PolyobjLinesBoxIterator(box, callback, parameters);
if(result) return result;
}
return P_LinesBoxIterator(box, callback, parameters);
}

static int traverseCellPath2(Blockmap* bmap, uint const fromBlock[2],
uint const toBlock[2], float const from[2], float const to[2],
int (*callback) (uint const block[2], void* paramaters), void* paramaters)
int (*callback) (uint const block[2], void* parameters), void* parameters)
{
int result = false; // Continue iteration.
float intercept[2], delta[2], partial;
Expand Down Expand Up @@ -969,7 +1039,7 @@ static int traverseCellPath2(Blockmap* bmap, uint const fromBlock[2],
block[VY] = fromBlock[VY];
for(count = 0; count < 64; ++count)
{
result = callback(block, paramaters);
result = callback(block, parameters);
if(result) return result; // Early out.

if(block[VX] == toBlock[VX] && block[VY] == toBlock[VY])
Expand All @@ -992,8 +1062,8 @@ static int traverseCellPath2(Blockmap* bmap, uint const fromBlock[2],
}

static int traverseCellPath(GameMap* map, Blockmap* bmap, float const from_[2],
float const to_[2], int (*callback) (uint const block[2], void* paramaters),
void* paramaters)
float const to_[2], int (*callback) (uint const block[2], void* parameters),
void* parameters)
{
// Constant terms implicitly defined by DOOM's original version of this
// algorithm (we must honor these fudge factors for compatibility).
Expand Down Expand Up @@ -1081,43 +1151,43 @@ static int traverseCellPath(GameMap* map, Blockmap* bmap, float const from_[2],

V2_Subtract(from, from, min);
V2_Subtract(to, to, min);
return traverseCellPath2(bmap, fromBlock, toBlock, from, to, callback, paramaters);
return traverseCellPath2(bmap, fromBlock, toBlock, from, to, callback, parameters);
}

typedef struct {
int (*callback) (linedef_t*, void*);
void* paramaters;
void* parameters;
} iteratepolyobjlinedefs_params_t;

static int iteratePolyobjLineDefs(polyobj_t* po, void* paramaters)
static int iteratePolyobjLineDefs(polyobj_t* po, void* parameters)
{
const iteratepolyobjlinedefs_params_t* p = (iteratepolyobjlinedefs_params_t*)paramaters;
return Polyobj_LineIterator(po, p->callback, p->paramaters);
const iteratepolyobjlinedefs_params_t* p = (iteratepolyobjlinedefs_params_t*)parameters;
return Polyobj_LineIterator(po, p->callback, p->parameters);
}

static int collectPolyobjLineDefIntercepts(uint const block[2], void* paramaters)
static int collectPolyobjLineDefIntercepts(uint const block[2], void* parameters)
{
GameMap* map = (GameMap*)paramaters;
GameMap* map = (GameMap*)parameters;
iteratepolyobjlinedefs_params_t iplParams;
iplParams.callback = PIT_AddLineDefIntercepts;
iplParams.paramaters = NULL;
iplParams.parameters = NULL;
return GameMap_IterateCellPolyobjs(map, block, iteratePolyobjLineDefs, (void*)&iplParams);
}

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

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

int GameMap_PathTraverse2(GameMap* map, float const from[2], float const to[2],
int flags, traverser_t callback, void* paramaters)
int flags, traverser_t callback, void* parameters)
{
assert(map);

Expand All @@ -1140,28 +1210,28 @@ int GameMap_PathTraverse2(GameMap* map, float const from[2], float const to[2],
}

// Step #2: Process sorted intercepts.
return P_TraverseIntercepts(callback, paramaters);
return P_TraverseIntercepts(callback, parameters);
}

int GameMap_PathTraverse(GameMap* map, float const from[2], float const to[2],
int flags, traverser_t callback)
{
return GameMap_PathTraverse2(map, from, to, flags, callback, NULL/*no paramaters*/);
return GameMap_PathTraverse2(map, from, to, flags, callback, NULL/*no parameters*/);
}

int GameMap_PathXYTraverse2(GameMap* map, float fromX, float fromY, float toX, float toY,
int flags, traverser_t callback, void* paramaters)
int flags, traverser_t callback, void* parameters)
{
vec2_t from, to;
V2_Set(from, fromX, fromY);
V2_Set(to, toX, toY);
return GameMap_PathTraverse2(map, from, to, flags, callback, paramaters);
return GameMap_PathTraverse2(map, from, to, flags, callback, parameters);
}

int GameMap_PathXYTraverse(GameMap* map, float fromX, float fromY, float toX, float toY,
int flags, traverser_t callback)
{
return GameMap_PathXYTraverse2(map, fromX, fromY, toX, toY, flags, callback, NULL/*no paramaters*/);
return GameMap_PathXYTraverse2(map, fromX, fromY, toX, toY, flags, callback, NULL/*no parameters*/);
}

subsector_t* GameMap_SubsectorAtPoint(GameMap* map, float point_[2])
Expand Down

0 comments on commit 8a412ae

Please sign in to comment.