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
Sound emitter location and map element to index lookups.
  • Loading branch information
danij-deng committed Apr 3, 2013
1 parent 8113509 commit 7821233
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 215 deletions.
175 changes: 82 additions & 93 deletions doomsday/client/include/map/gamemap.h
Expand Up @@ -207,6 +207,29 @@ class GameMap

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

/**
* Locate a sector in the map by sound emitter.
*
* @param soundEmitter ddmobj_base_t to search for.
*
* @return Pointer to the referenced Sector instance; otherwise @c 0.
*/
Sector *sectorBySoundEmitter(ddmobj_base_t const &soundEmitter) const;

/**
* Locate a surface in the map by sound emitter.
*
* @param soundEmitter ddmobj_base_t to search for.
*
* @return Pointe to the referenced Surface instance; otherwise @c 0.
*/
Surface *surfaceBySoundEmitter(ddmobj_base_t const &soundEmitter) const;

/**
* Returns the total number of Polyobjs in the map.
*/
uint polyobjCount() const;

/**
* Locate a polyobj in the map by unique in-map index number (0-based).
*
Expand Down Expand Up @@ -445,7 +468,64 @@ class GameMap
*/
PlaneSet /*const*/ &trackedPlanes();

public: ///@ todo make private:
public: /// @todo Replace with object level methods:
/**
* Lookup the in-map unique index for @a vertex.
*
* @param vtx Vertex to lookup.
* @return Unique index for the Vertex else @c -1 if not present.
*/
int vertexIndex(Vertex const *vtx) const;

/**
* Lookup the in-map unique index for @a line.
*
* @param line LineDef to lookup.
* @return Unique index for the Line else @c -1 if not present.
*/
int lineIndex(LineDef const *line) const;

/**
* Lookup the in-map unique index for @a sideDef.
*
* @param side SideDef to lookup.
* @return Unique index for the SideDef else @c -1 if not present.
*/
int sideDefIndex(SideDef const *side) const;

/**
* Lookup the in-map unique index for @a sector.
*
* @param sector Sector to lookup.
* @return Unique index for the Sector else @c -1 if not present.
*/
int sectorIndex(Sector const *sector) const;

/**
* Lookup the in-map unique index for @a bspLeaf.
*
* @param bspLeaf BspLeaf to lookup.
* @return Unique index for the BspLeaf else @c -1 if not present.
*/
int bspLeafIndex(BspLeaf const *bspLeaf) const;

/**
* Lookup the in-map unique index for @a hedge.
*
* @param hedge HEdge to lookup.
* @return Unique index for the HEdge else @c -1 if not present.
*/
int hedgeIndex(HEdge const *hedge) const;

/**
* Lookup the in-map unique index for @a node.
*
* @param bspNode BspNode to lookup.
* @return Unique index for the BspNode else @c -1 if not present.
*/
int bspNodeIndex(BspNode const *bspNode) const;

public: /// @todo Make private:

/**
* @pre Axis-aligned bounding boxes of all Sectors must be initialized.
Expand Down Expand Up @@ -501,9 +581,9 @@ class GameMap
*/
void initSkyFix();

#ifdef __CLIENT__
void addSurfaceToLists(Surface &suf);

#ifdef __CLIENT__
void buildSurfaceLists();
#endif

Expand Down Expand Up @@ -541,97 +621,6 @@ TraceOpening const *GameMap_TraceOpening(GameMap *map);
*/
void GameMap_SetTraceOpening(GameMap *map, LineDef *line);

/**
* Lookup a Sector in the map by it's sound emitter.
*
* @param map GameMap instance.
* @param soundEmitter ddmobj_base_t to search for.
*
* @return Found Sector instance else @c NULL.
*/
Sector *GameMap_SectorBySoundEmitter(GameMap *map, void const *soundEmitter);

/**
* Lookup a Surface in the map by it's sound emitter.
*
* @param map GameMap instance.
* @param soundEmitter ddmobj_base_t to search for.
*
* @return Found Surface instance else @c NULL.
*/
Surface *GameMap_SurfaceBySoundEmitter(GameMap* map, void const *soundEmitter);

/**
* Lookup the unique index for @a vertex.
*
* @param map GameMap instance.
* @param vtx Vertex to lookup.
* @return Unique index for the Vertex else @c -1 if not present.
*/
int GameMap_VertexIndex(GameMap *map, Vertex const *vtx);

/**
* Lookup the unique index for @a line.
*
* @param map GameMap instance.
* @param line Line to lookup.
* @return Unique index for the Line else @c -1 if not present.
*/
int GameMap_LineDefIndex(GameMap *map, LineDef const *line);

/**
* Lookup the unique index for @a sideDef.
*
* @param map GameMap instance.
* @param side SideDef to lookup.
* @return Unique index for the SideDef else @c -1 if not present.
*/
int GameMap_SideDefIndex(GameMap *map, SideDef const *side);

/**
* Lookup the unique index for @a sector.
*
* @param map GameMap instance.
* @param sector Sector to lookup.
* @return Unique index for the Sector else @c -1 if not present.
*/
int GameMap_SectorIndex(GameMap *map, Sector const *sector);

/**
* Lookup the unique index for @a bspLeaf.
*
* @param map GameMap instance.
* @param bspLeaf BspLeaf to lookup.
* @return Unique index for the BspLeaf else @c -1 if not present.
*/
int GameMap_BspLeafIndex(GameMap *map, BspLeaf const *bspLeaf);

/**
* Lookup the unique index for @a hedge.
*
* @param map GameMap instance.
* @param hedge HEdge to lookup.
* @return Unique index for the HEdge else @c -1 if not present.
*/
int GameMap_HEdgeIndex(GameMap *map, HEdge const *hedge);

/**
* Lookup the unique index for @a node.
*
* @param map GameMap instance.
* @param bspNode BspNode to lookup.
* @return Unique index for the BspNode else @c -1 if not present.
*/
int GameMap_BspNodeIndex(GameMap *map, BspNode const *bspNode);

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

/**
* Have the thinker lists been initialized yet?
* @param map GameMap instance.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/audio/s_environ.cpp
Expand Up @@ -157,7 +157,7 @@ static void findBspLeafsAffectingSector(GameMap *map, Sector *sec)
aaBox.maxY += 128;

// LOG_DEBUG("sector %u: min[x:%f, y:%f] max[x:%f, y:%f]")
// << GameMap_SectorIndex(map, sec)
// << map->sectorIndex(sec)
// << aaBox.minX << aaBox.minY << aaBox.maxX << aaBox.maxY;

foreach(BspLeaf *bspLeaf, map->bspLeafs())
Expand Down Expand Up @@ -303,7 +303,7 @@ static boolean calcBspLeafReverb(BspLeaf *bspLeaf)
bspLeaf->_reverb[SRD_DAMPING] = v;

/* DEBUG_Message(("bspLeaf %04i: vol:%3i sp:%3i dec:%3i dam:%3i\n",
GameMap_BspLeafIndex(theMap, bspLeaf), bspLeaf->reverb[SRD_VOLUME],
theMap->bspLeafIndex(bspLeaf), bspLeaf->reverb[SRD_VOLUME],
bspLeaf->reverb[SRD_SPACE], bspLeaf->reverb[SRD_DECAY],
bspLeaf->reverb[SRD_DAMPING])); */

Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/client/cl_sound.cpp
Expand Up @@ -127,7 +127,7 @@ void Cl_ReadSoundDelta2(deltatype_t type, boolean skip)

LOG_DEBUG("DT_POLY_SOUND: poly=%i") << index;

if(index < GameMap_PolyobjCount(theMap))
if(index < theMap->polyobjCount())
{
DENG_ASSERT(theMap);
poly = theMap->polyobjByIndex(index);
Expand Down Expand Up @@ -253,7 +253,7 @@ ifdef _DEBUG
Con_Printf("Cl_ReadSoundDelta2(%i): Start snd=%i [%x] vol=%.2f",
type, sound, flags, volume);
if(cmo) Con_Printf(", mo=%i\n", cmo->mo.thinker.id);
else if(sector) Con_Printf(", sector=%i\n", GameMap_SectorIndex(theMap, sector));
else if(sector) Con_Printf(", sector=%i\n", theMap->sectorIndex(sector));
else if(poly) Con_Printf(", poly=%i\n", GET_POLYOBJ_IDX(poly));
else Con_Printf("\n");
#endif
Expand All @@ -272,7 +272,7 @@ else Con_Printf("\n");
Con_Printf("Cl_ReadSoundDelta2(%i): Stop sound %i",
type, sound);
if(cmo) Con_Printf(", mo=%i\n", cmo->mo.thinker.id);
else if(sector) Con_Printf(", sector=%i\n", GameMap_SectorIndex(theMap, sector));
else if(sector) Con_Printf(", sector=%i\n", theMap->sectorIndex(sector));
else if(poly) Con_Printf(", poly=%i\n", GET_POLYOBJ_IDX(poly));
else Con_Printf("\n");
#endif
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/client/cl_world.cpp
Expand Up @@ -859,7 +859,7 @@ void Cl_ReadPolyDelta2(boolean skip)
if(skip)
return;

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

if(df & PODF_DEST_X)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/dd_main.cpp
Expand Up @@ -2471,7 +2471,7 @@ void *DD_GetVariable(int ddvalue)
return &valueU;

case DD_POLYOBJ_COUNT:
valueU = theMap? GameMap_PolyobjCount(theMap) : 0;
valueU = theMap? theMap->polyobjCount() : 0;
return &valueU;

case DD_HEDGE_COUNT:
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/edit_map.cpp
Expand Up @@ -604,7 +604,7 @@ static void buildSectorLineLists(GameMap &map)
{
if(line->hasFrontSector())
{
int const sectorIndex = GameMap_SectorIndex(&map, &line->frontSector());
int const sectorIndex = map.sectorIndex(&line->frontSector());

LineLink *link = (LineLink *) ZBlockSet_Allocate(lineLinksBlockSet);
link->line = line;
Expand All @@ -614,7 +614,7 @@ static void buildSectorLineLists(GameMap &map)

if(line->hasBackSector() && !line->isSelfReferencing())
{
int const sectorIndex = GameMap_SectorIndex(&map, &line->backSector());
int const sectorIndex = map.sectorIndex(&line->backSector());

LineLink *link = (LineLink *) ZBlockSet_Allocate(lineLinksBlockSet);
link->line = line;
Expand All @@ -626,7 +626,7 @@ static void buildSectorLineLists(GameMap &map)
// Build the actual sector line lists.
foreach(Sector *sector, map.sectors())
{
int const sectorIndex = GameMap_SectorIndex(&map, sector);
int const sectorIndex = map.sectorIndex(sector);

sector->_lines.clear();

Expand Down

0 comments on commit 7821233

Please sign in to comment.