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
Polyobj lookups and traversals.
  • Loading branch information
danij-deng committed Apr 3, 2013
1 parent 36245cd commit e530776
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 101 deletions.
65 changes: 30 additions & 35 deletions doomsday/client/include/map/gamemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,31 @@ class GameMap

inline uint sectorCount() const { return sectors().size(); }

/**
* Locate a polyobj in the map by unique in-map index number (0-based).
*
* @param index Index of the polyobj to be located.
* @return Pointer to the referenced polyobj instance; otherwise @c 0.
*/
Polyobj *polyobjByIndex(uint id) const;

/**
* Locate a polyobj in the map by unique in-map tag.
*
* @param tag Tag associated with the polyobj to be located.
* @return Pointer to the referenced polyobj instance; otherwise @c 0.
*/
Polyobj *polyobjByTag(int tag) const;

/**
* Locate a polyobj in the map by mobj base.
*
* @param ddMobjBase Base mobj to search for.
*
* @return Pointer to the referenced polyobj instance; otherwise @c 0.
*/
Polyobj *polyobjByBase(ddmobj_base_t const &ddMobjBase) const;

/**
* Returns the root element for the map's BSP tree.
*/
Expand Down Expand Up @@ -390,6 +415,11 @@ class GameMap
*/
void updateBounds();

/**
* Initialize all polyobjs in the map. To be called after map load.
*/
void initPolyobjs();

/**
* Fixing the sky means that for adjacent sky sectors the lower sky
* ceiling is lifted to match the upper sky. The raising only affects
Expand Down Expand Up @@ -528,34 +558,6 @@ int GameMap_BspNodeIndex(GameMap *map, BspNode const *bspNode);
*/
uint GameMap_PolyobjCount(GameMap *map);

/**
* Lookup a Polyobj in the map by unique ID.
*
* @param map GameMap instance.
* @param id Unique identifier of the Polyobj to be found.
* @return Found Polyobj instance else @c NULL.
*/
Polyobj *GameMap_PolyobjByID(GameMap *map, uint id);

/**
* Lookup a Polyobj in the map by tag.
*
* @param map GameMap instance.
* @param tag Tag associated with the Polyobj to be found.
* @return Found Polyobj instance else @c NULL.
*/
Polyobj *GameMap_PolyobjByTag(GameMap *map, int tag);

/**
* Lookup a Polyobj in the map by origin.
*
* @param map GameMap instance.
* @param ddMobjBase ddmobj_base_t to search for.
*
* @return Found Polyobj instance else @c NULL.
*/
Polyobj *GameMap_PolyobjByBase(GameMap *map, void *ddMobjBase);

/**
* Have the thinker lists been initialized yet?
* @param map GameMap instance.
Expand Down Expand Up @@ -668,13 +670,6 @@ boolean GameMap_ClMobjIterator(GameMap *map, boolean (*callback) (struct mobj_s
struct clplane_s *GameMap_NewClPlane(GameMap *map, uint sectornum, clplanetype_t type,
coord_t dest, float speed);

/**
* Initialize all Polyobjs in the map. To be called after map load.
*
* @param map GameMap instance.
*/
void GameMap_InitPolyobjs(GameMap *map);

/**
* Initialize the node piles and link rings. To be called after map load.
*
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/client/cl_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ void Cl_ReadSoundDelta2(deltatype_t type, boolean skip)
if(index < GameMap_PolyobjCount(theMap))
{
DENG_ASSERT(theMap);
poly = GameMap_PolyobjByID(theMap, index);
poly = theMap->polyobjByIndex(index);
emitter = (mobj_t *) poly;
}
else
{
Con_Message("Cl_ReadSoundDelta2: DT_POLY_SOUND contains "
"invalid polyobj num %u. Skipping.", index);
"invalid polyobj index %u. Skipping.", index);
skip = true;
}
}
Expand Down
11 changes: 2 additions & 9 deletions doomsday/client/src/client/cl_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,15 +861,8 @@ void Cl_ReadPolyDelta2(boolean skip)
if(skip)
return;

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

po = GameMap_PolyobjByID(theMap, num);
DENG_ASSERT(num < GameMap_PolyobjCount(theMap));
po = theMap->polyobjByIndex(num);

if(df & PODF_DEST_X)
po->dest[VX] = destX;
Expand Down
46 changes: 20 additions & 26 deletions doomsday/client/src/map/gamemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,38 +293,33 @@ uint GameMap_PolyobjCount(GameMap *map)
return map->numPolyObjs;
}

Polyobj *GameMap_PolyobjByID(GameMap *map, uint id)
Polyobj *GameMap::polyobjByIndex(uint id) const
{
DENG2_ASSERT(map);
if(id < map->numPolyObjs)
return map->polyObjs[id];
if(id < numPolyObjs)
{
return polyObjs[id];
}
return 0;
}

Polyobj *GameMap_PolyobjByTag(GameMap *map, int tag)
Polyobj *GameMap::polyobjByTag(int tag) const
{
DENG2_ASSERT(map);
for(uint i = 0; i < map->numPolyObjs; ++i)
for(uint i = 0; i < numPolyObjs; ++i)
{
Polyobj *po = map->polyObjs[i];
Polyobj *po = polyObjs[i];
if(po->tag == tag)
{
return po;
}
}
return 0;
}

Polyobj *GameMap_PolyobjByBase(GameMap *map, void *ddMobjBase)
Polyobj *GameMap::polyobjByBase(ddmobj_base_t const &ddMobjBase) const
{
DENG2_ASSERT(map);
for(uint i = 0; i < map->numPolyObjs; ++i)
for(uint i = 0; i < numPolyObjs; ++i)
{
Polyobj *po = map->polyObjs[i];
if(po == ddMobjBase)
{
Polyobj *po = polyObjs[i];
if(reinterpret_cast<ddmobj_base_t *>(po) == &ddMobjBase)
return po;
}
}
return 0;
}
Expand Down Expand Up @@ -363,23 +358,22 @@ static void initPolyobj(Polyobj *po)
P_PolyobjLink(po);
}

Generators *GameMap::generators()
void GameMap::initPolyobjs()
{
// Time to initialize a new collection?
if(!_generators)
for(uint i = 0; i < numPolyObjs; ++i)
{
_generators = Generators_New(sectorCount());
initPolyobj(polyObjs[i]);
}
return _generators;
}

void GameMap_InitPolyobjs(GameMap *map)
Generators *GameMap::generators()
{
DENG2_ASSERT(map);
for(uint i = 0; i < map->numPolyObjs; ++i)
// Time to initialize a new collection?
if(!_generators)
{
initPolyobj(map->polyObjs[i]);
_generators = Generators_New(sectorCount());
}
return _generators;
}

void GameMap_InitNodePiles(GameMap *map)
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/map/p_polyobjs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@ DENG_EXTERN_C void P_PolyobjLink(Polyobj *po)
DENG_EXTERN_C Polyobj *P_PolyobjByID(uint id)
{
if(!theMap) return NULL;
return GameMap_PolyobjByID(theMap, id);
return theMap->polyobjByIndex(id);
}

#undef P_PolyobjByTag
DENG_EXTERN_C Polyobj *P_PolyobjByTag(int tag)
{
if(!theMap) return NULL;
return GameMap_PolyobjByTag(theMap, tag);
return theMap->polyobjByTag(tag);
}

#undef P_PolyobjByBase
DENG_EXTERN_C Polyobj *P_PolyobjByBase(void *ddMobjBase)
{
if(!theMap) return NULL;
return GameMap_PolyobjByBase(theMap, ddMobjBase);
if(!theMap || !ddMobjBase) return NULL;
return theMap->polyobjByBase(*reinterpret_cast<ddmobj_base_t *>(ddMobjBase));
}

#undef P_PolyobjMove
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/map/r_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ DENG_EXTERN_C void R_SetupMap(int mode, int flags)

updateAllMapSectors(*theMap, true /*force*/);
initAllMapSurfaceMaterialOrigins(*theMap);
GameMap_InitPolyobjs(theMap);
theMap->initPolyobjs();
DD_ResetTimer();
return;

Expand All @@ -869,7 +869,7 @@ DENG_EXTERN_C void R_SetupMap(int mode, int flags)
// Recalculate the light range mod matrix.
Rend_CalcLightModRange();

GameMap_InitPolyobjs(theMap);
theMap->initPolyobjs();
P_MapSpawnPlaneParticleGens();

updateAllMapSectors(*theMap, true /*force*/);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/r_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ static void R_UpdateMap()
/// @todo Is this even necessary?
for(uint i = 0; i < GameMap_PolyobjCount(theMap); ++i)
{
Polyobj *po = GameMap_PolyobjByID(theMap, i);
Polyobj *po = theMap->polyobjByIndex(i);

for(LineDef **lineIter = po->lines; *lineIter; lineIter++)
{
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/rend_bias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void SB_InitForMap(char const *uniqueID)

for(uint i = 0; i < GameMap_PolyobjCount(theMap); ++i)
{
Polyobj *po = GameMap_PolyobjByID(theMap, i);
Polyobj *po = theMap->polyobjByIndex(i);
numVertIllums += po->lineCount * 3 * 4;
}

Expand Down Expand Up @@ -345,7 +345,7 @@ void SB_InitForMap(char const *uniqueID)

for(uint i = 0; i < GameMap_PolyobjCount(theMap); ++i)
{
Polyobj *po = GameMap_PolyobjByID(theMap, i);
Polyobj *po = theMap->polyobjByIndex(i);

for(uint j = 0; j < po->lineCount; ++j)
{
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/rend_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3077,7 +3077,7 @@ void Rend_RenderSurfaceVectors()

for(uint i = 0; i < GameMap_PolyobjCount(theMap); ++i)
{
Polyobj const *po = GameMap_PolyobjByID(theMap, i);
Polyobj const *po = theMap->polyobjByIndex(i);
Sector const &sector = po->bspLeaf->sector();
float zPos = sector.floor().height() + (sector.ceiling().height() - sector.floor().height())/2;

Expand Down Expand Up @@ -3892,7 +3892,7 @@ static void Rend_RenderBoundingBoxes()
{
for(uint i = 0; i < GameMap_PolyobjCount(theMap); ++i)
{
Polyobj const *po = GameMap_PolyobjByID(theMap, i);
Polyobj const *po = theMap->polyobjByIndex(i);
Sector const &sec = po->bspLeaf->sector();
coord_t width = (po->aaBox.maxX - po->aaBox.minX)/2;
coord_t length = (po->aaBox.maxY - po->aaBox.minY)/2;
Expand Down
30 changes: 16 additions & 14 deletions doomsday/server/src/server/sv_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ void Sv_RegisterSector(dt_sector_t *reg, uint number)
*/
void Sv_RegisterSide(dt_side_t *reg, uint number)
{
DENG_ASSERT(reg);
DENG_ASSERT(reg != 0);

SideDef *sideDef = theMap->sideDefs().at(number);

Expand All @@ -481,25 +481,27 @@ void Sv_RegisterSide(dt_side_t *reg, uint number)
* Store the state of the polyobj into the register-poly.
* Called at register init and after each delta generation.
*/
void Sv_RegisterPoly(dt_poly_t* reg, uint number)
void Sv_RegisterPoly(dt_poly_t *reg, uint number)
{
Polyobj* poly = GameMap_PolyobjByID(theMap, number);
DENG_ASSERT(reg != 0);

reg->dest[VX] = poly->dest[VX];
reg->dest[VY] = poly->dest[VY];
reg->speed = poly->speed;
reg->destAngle = poly->destAngle;
Polyobj *poly = theMap->polyobjByIndex(number);

reg->dest[VX] = poly->dest[VX];
reg->dest[VY] = poly->dest[VY];
reg->speed = poly->speed;
reg->destAngle = poly->destAngle;
reg->angleSpeed = poly->angleSpeed;
}

/**
* @return @c true, if the result is not void.
* @return @c true if the result is not void.
*/
boolean Sv_RegisterCompareMobj(cregister_t* reg, const mobj_t* s, mobjdelta_t* d)
boolean Sv_RegisterCompareMobj(cregister_t *reg, mobj_t const *s, mobjdelta_t *d)
{
int df;
reg_mobj_t* regMo = NULL;
const dt_mobj_t* r = &dummyZeroMobj;
int df;
reg_mobj_t *regMo = 0;
dt_mobj_t const *r = &dummyZeroMobj;

if((regMo = Sv_RegisterFindMobj(reg, s->thinker.id)) != NULL)
{
Expand Down Expand Up @@ -1581,7 +1583,7 @@ coord_t Sv_DeltaDistance(void const *deltaPtr, ownerinfo_t const *info)

if(delta->type == DT_POLY)
{
Polyobj *po = GameMap_PolyobjByID(theMap, delta->id);
Polyobj *po = theMap->polyobjByIndex(delta->id);
return M_ApproxDistance(info->origin[VX] - po->origin[VX],
info->origin[VY] - po->origin[VY]);
}
Expand All @@ -1604,7 +1606,7 @@ coord_t Sv_DeltaDistance(void const *deltaPtr, ownerinfo_t const *info)

if(delta->type == DT_POLY_SOUND)
{
Polyobj *po = GameMap_PolyobjByID(theMap, delta->id);
Polyobj *po = theMap->polyobjByIndex(delta->id);
return M_ApproxDistance(info->origin[VX] - po->origin[VX],
info->origin[VY] - po->origin[VY]);
}
Expand Down
9 changes: 5 additions & 4 deletions doomsday/server/src/server/sv_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ static inline boolean isRealMobj(const mobj_t* base)
/**
* Find the map object to whom @a base belongs.
*/
static void Sv_IdentifySoundBase(mobj_t** base, Sector** sector, Polyobj** poly,
Surface** surface)
static void Sv_IdentifySoundBase(mobj_t **base, Sector **sector, Polyobj **poly,
Surface **surface)
{
*sector = 0;
*poly = 0;
*surface = 0;

if(!*base || isRealMobj(*base)) return;

/// @todo Optimize: Performance here could be a LOT better...
/// @todo Optimize: All sound emitters in a sector are linked together forming
/// a chain. Make use of the chains instead.

// No mobj ID => it's not a real mobj.
*poly = GameMap_PolyobjByBase(theMap, *base);
*poly = theMap->polyobjByBase(*reinterpret_cast<ddmobj_base_t *>(base));
if(!*poly)
{
// Not a polyobj. Try the sectors next.
Expand Down

0 comments on commit e530776

Please sign in to comment.