Skip to content

Commit

Permalink
GameMap: Added PolyobjCount() query function
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 3, 2012
1 parent 9bd91f6 commit ee1e41a
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 36 deletions.
8 changes: 8 additions & 0 deletions doomsday/engine/portable/include/gamemap.h
Expand Up @@ -273,6 +273,14 @@ uint GameMap_HEdgeCount(GameMap* map);
*/
uint GameMap_NodeCount(GameMap* map);

/**
* Retrieve the number of Polyobj instances owned by this.
*
* @param map GameMap instance.
* @return Number Polyobj.
*/
uint GameMap_PolyobjCount(GameMap* map);

void GameMap_InitNodePiles(GameMap* map);

#endif /// LIBDENG_GAMEMAP_H
3 changes: 3 additions & 0 deletions doomsday/engine/portable/include/p_mapdata.h
Expand Up @@ -66,6 +66,8 @@
#define NUM_HEDGES GameMap_HEdgeCount(theMap)
#define NUM_NODES GameMap_NodeCount(theMap)

#define NUM_POLYOBJS GameMap_PolyobjCount(theMap)

// Node flags.
#define NF_SUBSECTOR 0x80000000

Expand Down Expand Up @@ -277,6 +279,7 @@ extern subsector_t* subsectors;
extern node_t* nodes;
extern linedef_t* lineDefs;
extern sidedef_t* sideDefs;
extern polyobj_t** polyObjs; ///< List of all polyobjs on the current map.

extern watchedplanelist_t* watchedPlaneList;
extern surfacelist_t* movingSurfaceList;
Expand Down
3 changes: 0 additions & 3 deletions doomsday/engine/portable/include/p_polyob.h
Expand Up @@ -30,9 +30,6 @@ DD_BASE_POLYOBJ_ELEMENTS()

#define POLYOBJ_SIZE gx.polyobjSize

extern polyobj_t** polyObjs; ///< List of all polyobjs on the current map.
extern uint numPolyObjs; ///< Number of polyobjs on the current map.

/**
* Initialize polyobjs on the current map. To be called after map load.
*/
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/cl_sound.c
Expand Up @@ -108,7 +108,7 @@ void Cl_ReadSoundDelta2(deltatype_t type, boolean skip)
{
uint index = Reader_ReadUInt16(msgReader);

if(index < numPolyObjs)
if(index < NUM_POLYOBJS)
{
poly = polyObjs[index];
emitter = (mobj_t *) poly;
Expand Down
10 changes: 5 additions & 5 deletions doomsday/engine/portable/src/cl_world.c
Expand Up @@ -829,11 +829,11 @@ void Cl_ReadPolyDelta2(boolean skip)
return;

#ifdef _DEBUG
if(num >= numPolyObjs)
{
// This is worrisome.
Con_Error("Cl_ReadPolyDelta2: PO %i out of range.\n", num);
}
if(num >= NUM_POLYOBJS)
{
// This is worrisome.
Con_Error("Cl_ReadPolyDelta2: PO %i out of range.\n", num);
}
#endif

po = polyObjs[num];
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/portable/src/dd_main.c
Expand Up @@ -2112,7 +2112,8 @@ void* DD_GetVariable(int ddvalue)
return &valueU;

case DD_POLYOBJ_COUNT:
return &numPolyObjs;
valueU = GameMap_PolyobjCount(theMap);
return &valueU;

case DD_HEDGE_COUNT:
valueU = GameMap_HEdgeCount(theMap);
Expand Down
6 changes: 6 additions & 0 deletions doomsday/engine/portable/src/gamemap.c
Expand Up @@ -196,6 +196,12 @@ uint GameMap_NodeCount(GameMap* map)
return map->numNodes;
}

uint GameMap_PolyobjCount(GameMap* map)
{
assert(map);
return map->numPolyObjs;
}

void GameMap_InitNodePiles(GameMap* map)
{
uint i, starttime = 0;
Expand Down
8 changes: 3 additions & 5 deletions doomsday/engine/portable/src/p_data.c
Expand Up @@ -79,6 +79,7 @@ subsector_t* subsectors = NULL;
node_t* nodes = NULL;
linedef_t* lineDefs = NULL;
sidedef_t* sideDefs = NULL;
polyobj_t** polyObjs = NULL; // List of all poly-objects in the map.

watchedplanelist_t* watchedPlaneList = NULL;
surfacelist_t* movingSurfaceList = NULL;
Expand Down Expand Up @@ -173,14 +174,13 @@ void P_SetCurrentMap(GameMap* map)
nodes = 0;
lineDefs = 0;
sideDefs = 0;
polyObjs = 0;

watchedPlaneList = 0;
movingSurfaceList = 0;
decoratedSurfaceList = 0;
glowingSurfaceList = 0;

numPolyObjs = 0;
polyObjs = 0;

mobjNodes = 0;
lineNodes = 0;
Expand All @@ -201,15 +201,13 @@ void P_SetCurrentMap(GameMap* map)
nodes = map->nodes;
lineDefs = map->lineDefs;
sideDefs = map->sideDefs;
polyObjs = map->polyObjs;

watchedPlaneList = &map->watchedPlaneList;
movingSurfaceList = &map->movingSurfaceList;
decoratedSurfaceList = &map->decoratedSurfaceList;
glowingSurfaceList = &map->glowingSurfaceList;

numPolyObjs = map->numPolyObjs;
polyObjs = map->polyObjs;

mobjNodes = &map->mobjNodes;
lineNodes = &map->lineNodes;
linelinks = map->lineLinks;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/p_maputil.c
Expand Up @@ -933,7 +933,7 @@ int P_PolyobjLinesBoxIterator(const AABoxf* box, int (*callback) (linedef_t*, vo
*/
int P_AllLinesBoxIterator(const AABoxf* box, int (*callback) (linedef_t*, void*), void* paramaters)
{
if(numPolyObjs > 0)
if(NUM_POLYOBJS > 0)
{
int result = P_PolyobjLinesBoxIterator(box, callback, paramaters);
if(result) return result;
Expand Down Expand Up @@ -1258,7 +1258,7 @@ int Map_PathTraverse(GameMap* map, float const from[2], float const to[2],
// Step #1: Collect intercepts.
if(flags & PT_ADDLINES)
{
if(numPolyObjs != 0)
if(NUM_POLYOBJS != 0)
{
traverseCellPath(map->polyobjBlockmap, from, to, collectPolyobjLineDefIntercepts, (void*)map);
}
Expand Down
11 changes: 4 additions & 7 deletions doomsday/engine/portable/src/p_polyob.c
Expand Up @@ -32,25 +32,22 @@ static boolean checkMobjBlocking(linedef_t* line, polyobj_t* po);
// Called when the polyobj hits a mobj.
static void (*po_callback) (mobj_t* mobj, void* line, void* polyobj);

polyobj_t** polyObjs; // List of all poly-objects in the map.
uint numPolyObjs;

void P_SetPolyobjCallback(void (*func) (struct mobj_s*, void*, void*))
{
po_callback = func;
}

polyobj_t* P_PolyobjByID(uint id)
{
if(id < numPolyObjs)
if(id < NUM_POLYOBJS)
return polyObjs[id];
return NULL;
}

polyobj_t* P_PolyobjByTag(int tag)
{
uint i;
for(i = 0; i < numPolyObjs; ++i)
for(i = 0; i < NUM_POLYOBJS; ++i)
{
polyobj_t* po = polyObjs[i];
if(po->tag == tag)
Expand All @@ -64,7 +61,7 @@ polyobj_t* P_PolyobjByTag(int tag)
polyobj_t* P_PolyobjByOrigin(void* ddMobjBase)
{
uint i;
for(i = 0; i < numPolyObjs; ++i)
for(i = 0; i < NUM_POLYOBJS; ++i)
{
polyobj_t* po = polyObjs[i];
if(po == ddMobjBase)
Expand Down Expand Up @@ -167,7 +164,7 @@ void P_MapInitPolyobj(polyobj_t* po)
void P_MapInitPolyobjs(void)
{
uint i;
for(i = 0; i < numPolyObjs; ++i)
for(i = 0; i < NUM_POLYOBJS; ++i)
{
P_MapInitPolyobj(polyObjs[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/r_main.c
Expand Up @@ -591,7 +591,7 @@ void R_Update(void)
}}

{ uint i;
for(i = 0; i < numPolyObjs; ++i)
for(i = 0; i < NUM_POLYOBJS; ++i)
{
polyobj_t* po = polyObjs[i];
linedef_t** lineIter;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/rend_bias.c
Expand Up @@ -381,7 +381,7 @@ void SB_InitForMap(const char* uniqueID)
}
}

for(i = 0; i < numPolyObjs; ++i)
for(i = 0; i < NUM_POLYOBJS; ++i)
{
polyobj_t* po = polyObjs[i];
numVertIllums += po->lineCount * 3 * 4;
Expand Down Expand Up @@ -439,7 +439,7 @@ void SB_InitForMap(const char* uniqueID)
}
}

for(i = 0; i < numPolyObjs; ++i)
for(i = 0; i < NUM_POLYOBJS; ++i)
{
polyobj_t* po = polyObjs[i];
uint j;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/rend_main.c
Expand Up @@ -3056,7 +3056,7 @@ void Rend_RenderSurfaceVectors(void)
}
}

for(i = 0; i < numPolyObjs; ++i)
for(i = 0; i < NUM_POLYOBJS; ++i)
{
const polyobj_t* po = polyObjs[i];
const sector_t* sec = po->subsector->sector;
Expand Down Expand Up @@ -3796,7 +3796,7 @@ static void Rend_RenderBoundingBoxes(void)
P_IterateThinkers(gx.MobjThinker, 0x1, drawMobjBBox, NULL);

if(devPolyobjBBox)
for(i = 0; i < numPolyObjs; ++i)
for(i = 0; i < NUM_POLYOBJS; ++i)
{
const polyobj_t* po = polyObjs[i];
const sector_t* sec = po->subsector->sector;
Expand Down
20 changes: 13 additions & 7 deletions doomsday/engine/portable/src/sv_pool.c
Expand Up @@ -999,7 +999,7 @@ boolean Sv_IsPlayerIgnored(int plrNum)
*/
void Sv_RegisterWorld(cregister_t* reg, boolean isInitial)
{
uint i;
uint i, numPolyobjs;

memset(reg, 0, sizeof(*reg));
reg->gametic = SECONDS_TO_TICKS(gameTime);
Expand All @@ -1022,12 +1022,18 @@ void Sv_RegisterWorld(cregister_t* reg, boolean isInitial)
}

// Init polyobjs.
reg->polyObjs =
(numPolyObjs ?
Z_Calloc(sizeof(dt_poly_t) * numPolyObjs, PU_MAP, 0) : NULL);
for(i = 0; i < numPolyObjs; ++i)
numPolyobjs = NUM_POLYOBJS;
if(numPolyobjs)
{
reg->polyObjs = Z_Calloc(sizeof(dt_poly_t) * NUM_POLYOBJS, PU_MAP, 0);
for(i = 0; i < numPolyobjs; ++i)
{
Sv_RegisterPoly(&reg->polyObjs[i], i);
}
}
else
{
Sv_RegisterPoly(&reg->polyObjs[i], i);
reg->polyObjs = NULL;
}
}

Expand Down Expand Up @@ -2332,7 +2338,7 @@ void Sv_NewPolyDeltas(cregister_t* reg, boolean doUpdate, pool_t** targets)
uint i;
polydelta_t delta;

for(i = 0; i < numPolyObjs; ++i)
for(i = 0; i < NUM_POLYOBJS; ++i)
{
if(Sv_RegisterComparePoly(reg, i, &delta))
{
Expand Down

0 comments on commit ee1e41a

Please sign in to comment.