Skip to content

Commit

Permalink
Refactor: Use the relevant GameMap function instead of the helper macros
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Apr 2, 2013
1 parent 047d776 commit 179f00f
Show file tree
Hide file tree
Showing 19 changed files with 130 additions and 160 deletions.
46 changes: 7 additions & 39 deletions doomsday/client/include/map/p_mapdata.h
@@ -1,8 +1,4 @@
/**
* @file p_mapdata.h
* Playsim Data Structures, Macros and Constants. @ingroup play
*
* These are internal to Doomsday. The games have no direct access to this data.
/** @file p_mapdata.h Map entity definitions.
*
* @authors Copyright &copy; 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright &copy; 2006-2013 Daniel Swanson <danij@dengine.net>
Expand All @@ -22,12 +18,8 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_PLAY_MAPDATA_H
#define LIBDENG_PLAY_MAPDATA_H

#if defined(__JDOOM__) || defined(__JHERETIC__) || defined(__JHEXEN__)
# error Attempted to include internal Doomsday p_mapdata.h from a game
#endif
#ifndef LIBDENG_PLAY_MAPENTIYDEF_H
#define LIBDENG_PLAY_MAPENTIYDEF_H

#include "dd_share.h"
#include "api_mapedit.h"
Expand All @@ -36,33 +28,6 @@
#include <de/binangle.h>
#include <de/vector1.h>

#define GET_VERTEX_IDX(vtx) GameMap_VertexIndex(theMap, vtx)
#define GET_LINE_IDX(li) GameMap_LineDefIndex(theMap, li)
#define GET_SIDE_IDX(si) GameMap_SideDefIndex(theMap, si)
#define GET_SECTOR_IDX(sec) GameMap_SectorIndex(theMap, sec)
#define GET_HEDGE_IDX(he) GameMap_HEdgeIndex(theMap, he)
#define GET_BSPLEAF_IDX(bl) GameMap_BspLeafIndex(theMap, bl)
#define GET_BSPNODE_IDX(nd) GameMap_BspNodeIndex(theMap, nd)

#define VERTEX_PTR(idx) GameMap_Vertex(theMap, idx)
#define LINE_PTR(idx) GameMap_LineDef(theMap, idx)
#define SIDE_PTR(idx) GameMap_SideDef(theMap, idx)
#define SECTOR_PTR(idx) GameMap_Sector(theMap, idx)
#define HEDGE_PTR(idx) GameMap_HEdge(theMap, idx)
#define BSPLEAF_PTR(idx) GameMap_BspLeaf(theMap, idx)
#define BSPNODE_PTR(idx) GameMap_BspNode(theMap, idx)

#define NUM_VERTEXES GameMap_VertexCount(theMap)
#define NUM_LINEDEFS GameMap_LineDefCount(theMap)
#define NUM_SIDEDEFS GameMap_SideDefCount(theMap)
#define NUM_SECTORS GameMap_SectorCount(theMap)
#define NUM_HEDGES GameMap_HEdgeCount(theMap)
#define NUM_BSPLEAFS GameMap_BspLeafCount(theMap)
#define NUM_BSPNODES GameMap_BspNodeCount(theMap)

#define NUM_POLYOBJS GameMap_PolyobjCount(theMap)

// Map entity definitions.
struct mapentitydef_s;

typedef struct mapentitypropertydef_s {
Expand All @@ -79,6 +44,9 @@ typedef struct mapentitypropertydef_s {
struct mapentitydef_s* entity;
} MapEntityPropertyDef;

/**
* @ingroup play
*/
typedef struct mapentitydef_s {
/// Unique identifier associated with this entity.
int id;
Expand Down Expand Up @@ -184,4 +152,4 @@ void P_ShutdownMapEntityDefs(void);
} // extern "C"
#endif

#endif // LIBDENG_PLAY_MAPDATA_H
#endif // LIBDENG_PLAY_MAPENTIYDEF_H
2 changes: 1 addition & 1 deletion doomsday/client/src/audio/s_environ.cpp
Expand Up @@ -306,7 +306,7 @@ static boolean calcBspLeafReverb(BspLeaf *bspLeaf)
bspLeaf->_reverb[SRD_DAMPING] = v;

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

Expand Down
18 changes: 9 additions & 9 deletions doomsday/client/src/client/cl_sound.cpp
Expand Up @@ -97,9 +97,9 @@ void Cl_ReadSoundDelta2(deltatype_t type, boolean skip)
{
uint index = deltaId;

if(index < NUM_SECTORS)
if(index < GameMap_SectorCount(theMap))
{
sector = SECTOR_PTR(index);
sector = GameMap_Sector(theMap, index);
}
else
{
Expand All @@ -111,9 +111,9 @@ void Cl_ReadSoundDelta2(deltatype_t type, boolean skip)
{
uint index = deltaId;

if(index < NUM_SIDEDEFS)
if(index < GameMap_SideDefCount(theMap))
{
side = SIDE_PTR(index);
side = GameMap_SideDef(theMap, index);
}
else
{
Expand All @@ -127,7 +127,7 @@ void Cl_ReadSoundDelta2(deltatype_t type, boolean skip)

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

if(index < NUM_POLYOBJS)
if(index < GameMap_PolyobjCount(theMap))
{
DENG_ASSERT(theMap);
poly = GameMap_PolyobjByID(theMap, 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", GET_SECTOR_IDX(sector));
else if(sector) Con_Printf(", sector=%i\n", GameMap_SectorIndex(theMap, (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", GET_SECTOR_IDX(sector));
else if(sector) Con_Printf(", sector=%i\n", GameMap_SectorIndex(theMap, (sector));
else if(poly) Con_Printf(", poly=%i\n", GET_POLYOBJ_IDX(poly));
else Con_Printf("\n");
#endif
Expand Down Expand Up @@ -335,12 +335,12 @@ void Cl_Sound(void)
else if(flags & SNDF_SECTOR)
{
num = Reader_ReadPackedUInt16(msgReader);
if(num >= NUM_SECTORS)
if(num >= GameMap_SectorCount(theMap))
{
Con_Message("Cl_Sound: Invalid sector number %i.", num);
return;
}
mo = (mobj_t *) &SECTOR_PTR(num)->soundEmitter();
mo = (mobj_t *) &GameMap_Sector(theMap, num)->soundEmitter();
//S_StopSound(0, mo);
S_LocalSoundAtVolume(sound, mo, volume / 127.0f);
}
Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/src/client/cl_world.cpp
Expand Up @@ -625,13 +625,13 @@ void Cl_ReadSectorDelta2(int deltaType, boolean /*skip*/)

Sector *sec = 0;
#ifdef _DEBUG
if(num >= NUM_SECTORS)
if(num >= GameMap_SectorCount(theMap))
{
// This is worrisome.
Con_Error("Cl_ReadSectorDelta2: Sector %i out of range.\n", num);
}
#endif
sec = SECTOR_PTR(num);
sec = GameMap_Sector(theMap, num);

// Flags.
int df = Reader_ReadPackedUInt32(msgReader);
Expand Down Expand Up @@ -773,14 +773,14 @@ void Cl_ReadSideDelta2(int deltaType, boolean skip)
return;

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

SideDef *sideDef = SIDE_PTR(num);
SideDef *sideDef = GameMap_SideDef(theMap, num);

if(df & SIDF_TOP_MATERIAL)
{
Expand Down Expand Up @@ -874,7 +874,7 @@ void Cl_ReadPolyDelta2(boolean skip)
return;

#ifdef _DEBUG
if(num >= NUM_POLYOBJS)
if(num >= GameMap_PolyobjCount(theMap))
{
// This is worrisome.
Con_Error("Cl_ReadPolyDelta2: PO %i out of range.\n", num);
Expand Down
5 changes: 3 additions & 2 deletions doomsday/client/src/map/gamemap.cpp
Expand Up @@ -465,7 +465,8 @@ static void initPolyobj(Polyobj *po)
{
Con_Message("Warning: GameMap::initPolyobj: Multiple polyobjs in a single BSP leaf\n"
" (BSP leaf %lu, sector %lu). Previous polyobj overridden.",
(unsigned long) GET_BSPLEAF_IDX(bspLeaf), (unsigned long) GET_SECTOR_IDX(bspLeaf->sectorPtr()));
ulong( GameMap_BspLeafIndex(theMap, bspLeaf) ),
ulong( GameMap_SectorIndex(theMap, bspLeaf->sectorPtr()) ));
}
bspLeaf->_polyObj = po;
po->bspLeaf = bspLeaf;
Expand Down Expand Up @@ -1438,7 +1439,7 @@ int GameMap_PathTraverse2(GameMap *map, const_pvec2d_t from, const_pvec2d_t to,
// Step #1: Collect intercepts.
if(flags & PT_ADDLINES)
{
if(NUM_POLYOBJS != 0)
if(GameMap_PolyobjCount(theMap) != 0)
{
traverseCellPath(map, map->polyobjBlockmap, from, to, collectPolyobjLineDefIntercepts, (void *)map);
}
Expand Down
58 changes: 30 additions & 28 deletions doomsday/client/src/map/p_dmu.cpp
Expand Up @@ -294,25 +294,25 @@ uint P_ToIndex(void const *ptr)
switch(elem->type())
{
case DMU_VERTEX:
return GET_VERTEX_IDX(elem->castTo<Vertex>());
return GameMap_VertexIndex(theMap, elem->castTo<Vertex>());

case DMU_HEDGE:
return GET_HEDGE_IDX(elem->castTo<HEdge>());
return GameMap_HEdgeIndex(theMap, elem->castTo<HEdge>());

case DMU_LINEDEF:
return GET_LINE_IDX(elem->castTo<LineDef>());
return GameMap_LineDefIndex(theMap, elem->castTo<LineDef>());

case DMU_SIDEDEF:
return GET_SIDE_IDX(elem->castTo<SideDef>());
return GameMap_SideDefIndex(theMap, elem->castTo<SideDef>());

case DMU_BSPLEAF:
return GET_BSPLEAF_IDX(elem->castTo<BspLeaf>());
return GameMap_BspLeafIndex(theMap, elem->castTo<BspLeaf>());

case DMU_SECTOR:
return GET_SECTOR_IDX(elem->castTo<Sector>());
return GameMap_SectorIndex(theMap, elem->castTo<Sector>());

case DMU_BSPNODE:
return GET_BSPNODE_IDX(elem->castTo<BspNode>());
return GameMap_BspNodeIndex(theMap, elem->castTo<BspNode>());

case DMU_PLANE:
return elem->castTo<Plane>()->inSectorIndex();
Expand All @@ -333,25 +333,25 @@ void *P_ToPtr(int type, uint index)
switch(type)
{
case DMU_VERTEX:
return VERTEX_PTR(index);
return GameMap_Vertex(theMap, index);

case DMU_HEDGE:
return HEDGE_PTR(index);
return GameMap_HEdge(theMap, index);

case DMU_LINEDEF:
return LINE_PTR(index);
return GameMap_LineDef(theMap, index);

case DMU_SIDEDEF:
return SIDE_PTR(index);
return GameMap_SideDef(theMap, index);

case DMU_BSPLEAF:
return BSPLEAF_PTR(index);
return GameMap_BspLeaf(theMap, index);

case DMU_SECTOR:
return SECTOR_PTR(index);
return GameMap_Sector(theMap, index);

case DMU_BSPNODE:
return BSPNODE_PTR(index);
return GameMap_BspNode(theMap, index);

case DMU_PLANE: {
/// @todo Throw exception.
Expand Down Expand Up @@ -449,43 +449,44 @@ int P_Iteratep(void *elPtr, uint prop, void *context, int (*callback) (void *p,
* aborted immediately when the callback function
* returns @c false.
*/
#undef P_Callback
int P_Callback(int type, uint index, void *context, int (*callback)(void *p, void *ctx))
{
switch(type)
{
case DMU_VERTEX:
if(index < NUM_VERTEXES)
return callback(VERTEX_PTR(index), context);
if(index < GameMap_VertexCount(theMap))
return callback(GameMap_Vertex(theMap, index), context);
break;

case DMU_HEDGE:
if(index < NUM_HEDGES)
return callback(HEDGE_PTR(index), context);
if(index < GameMap_HEdgeCount(theMap))
return callback(GameMap_HEdge(theMap, index), context);
break;

case DMU_LINEDEF:
if(index < NUM_LINEDEFS)
return callback(LINE_PTR(index), context);
if(index < GameMap_LineDefCount(theMap))
return callback(GameMap_LineDef(theMap, index), context);
break;

case DMU_SIDEDEF:
if(index < NUM_SIDEDEFS)
return callback(SIDE_PTR(index), context);
if(index < GameMap_SideDefCount(theMap))
return callback(GameMap_SideDef(theMap, index), context);
break;

case DMU_BSPNODE:
if(index < NUM_BSPNODES)
return callback(BSPNODE_PTR(index), context);
if(index < GameMap_BspNodeCount(theMap))
return callback(GameMap_BspNode(theMap, index), context);
break;

case DMU_BSPLEAF:
if(index < NUM_BSPLEAFS)
return callback(BSPLEAF_PTR(index), context);
if(index < GameMap_BspLeafCount(theMap))
return callback(GameMap_BspLeaf(theMap, index), context);
break;

case DMU_SECTOR:
if(index < NUM_SECTORS)
return callback(SECTOR_PTR(index), context);
if(index < GameMap_SectorCount(theMap))
return callback(GameMap_Sector(theMap, index), context);
break;

case DMU_PLANE: {
Expand Down Expand Up @@ -523,6 +524,7 @@ int P_Callback(int type, uint index, void *context, int (*callback)(void *p, voi
* Another version of callback iteration. The set of selected objects is
* determined by 'type' and 'ptr'. Otherwise works like P_Callback.
*/
#undef P_Callbackp
int P_Callbackp(int type, void *elPtr, void *context, int (*callback)(void *p, void *ctx))
{
de::MapElement *elem = IN_ELEM(elPtr);
Expand Down

0 comments on commit 179f00f

Please sign in to comment.