Skip to content

Commit

Permalink
Refactor|GameMap: Use a regular QList for the map elements
Browse files Browse the repository at this point in the history
Also replaced the various GameMap_* functions for traversing these
lists with an appropriate in-place traversal of the relevant list.
  • Loading branch information
danij-deng committed Apr 2, 2013
1 parent 2d4791d commit 5d4ea4d
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 329 deletions.
41 changes: 21 additions & 20 deletions doomsday/client/include/map/gamemap.h
Expand Up @@ -72,6 +72,11 @@ typedef struct skyfix_s {
class GameMap
{
public:
typedef QList<Vertex *> Vertexes;
typedef QList<Sector *> Sectors;
typedef QList<LineDef *> Lines;
typedef QList<SideDef *> SideDefs;

typedef QList<HEdge *> HEdges;
typedef QList<BspNode *> BspNodes;
typedef QList<BspLeaf *> BspLeafs;
Expand All @@ -98,10 +103,10 @@ class GameMap
struct clpolyobj_s *clActivePolyobjs[CLIENT_MAX_MOVERS];
// End client only data.

de::MapElementList<Vertex> vertexes;
de::MapElementList<Sector> sectors;
de::MapElementList<LineDef> lines;
de::MapElementList<SideDef> sideDefs;
Vertexes _vertexes;
Sectors _sectors;
Lines _lines;
SideDefs _sideDefs;

uint numPolyObjs;
Polyobj **polyObjs;
Expand Down Expand Up @@ -151,13 +156,21 @@ class GameMap

virtual ~GameMap();

uint vertexCount() const { return vertexes.size(); }
Vertexes const &vertexes() const { return _vertexes; }

inline uint vertexCount() const { return vertexes().size(); }

SideDefs const &sideDefs() const { return _sideDefs; }

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

uint sideDefCount() const { return sideDefs.size(); }
Lines const &lines() const { return _lines; }

uint lineCount() const { return lines.size(); }
inline uint lineCount() const { return lines().size(); }

Sectors const &sectors() const { return _sectors; }

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

/**
* Returns the root element for the map's BSP tree.
Expand Down Expand Up @@ -767,8 +780,6 @@ int GameMap_MobjsBoxIterator(GameMap *map, AABoxd const *box,
*/
void GameMap_LinkLineDef(GameMap *map, LineDef *line);

int GameMap_LineDefIterator(GameMap *map, int (*callback) (LineDef *, void *), void *parameters);

int GameMap_LineDefsBoxIterator(GameMap *map, AABoxd const *box,
int (*callback) (LineDef *, void *), void *parameters);

Expand Down Expand Up @@ -826,16 +837,6 @@ int GameMap_PolyobjsBoxIterator(GameMap *map, AABoxd const *box,

int GameMap_PolyobjIterator(GameMap *map, int (*callback) (Polyobj *, void *), void *parameters);

int GameMap_VertexIterator(GameMap *map, int (*callback) (Vertex *, void *), void *parameters);

int GameMap_SideDefIterator(GameMap *map, int (*callback) (SideDef *, void *), void *parameters);

int GameMap_SectorIterator(GameMap *map, int (*callback)(Sector *, void *), void *parameters);

int GameMap_HEdgeIterator(GameMap *map, int (*callback) (HEdge *, void *), void *parameters);

int GameMap_BspNodeIterator(GameMap *map, int (*callback) (BspNode *, void *), void *parameters);

/**
* Traces a line between @a from and @a to, making a callback for each
* interceptable object linked within Blockmap cells which cover the path this
Expand Down
19 changes: 9 additions & 10 deletions doomsday/client/src/client/cl_world.cpp
Expand Up @@ -388,24 +388,23 @@ void Cl_MoverThinker(clplane_t* mover)
}
}

clplane_t* GameMap_NewClPlane(GameMap* map, uint sectorIndex, clplanetype_t type, coord_t dest, float speed)
clplane_t *GameMap_NewClPlane(GameMap *map, uint sectorIndex, clplanetype_t type, coord_t dest, float speed)
{
DENG_ASSERT(map);

int dmuPlane = (type == CPT_FLOOR ? DMU_FLOOR_OF_SECTOR : DMU_CEILING_OF_SECTOR);
clplane_t* mov;
int i;
assert(map);

DEBUG_Message(("GameMap_NewClPlane: Sector #%i, type:%s, dest:%f, speed:%f\n",
sectorIndex, type==CPT_FLOOR? "floor" : "ceiling", dest, speed));

if((int)sectorIndex >= map->sectors.size())
if(int( sectorIndex ) >= map->_sectors.size())
{
assert(0); // Invalid Sector index.
return NULL;
DENG_ASSERT(false); // Invalid Sector index.
return 0;
}

// Remove any existing movers for the same plane.
for(i = 0; i < CLIENT_MAX_MOVERS; ++i)
for(int i = 0; i < CLIENT_MAX_MOVERS; ++i)
{
if(GameMap_IsValidClPlane(map, i) &&
map->clActivePlanes[i]->sectorIndex == sectorIndex &&
Expand All @@ -419,14 +418,14 @@ clplane_t* GameMap_NewClPlane(GameMap* map, uint sectorIndex, clplanetype_t type
}

// Add a new mover.
for(i = 0; i < CLIENT_MAX_MOVERS; ++i)
for(int i = 0; i < CLIENT_MAX_MOVERS; ++i)
{
if(map->clActivePlanes[i]) continue;

DEBUG_Message(("GameMap_NewClPlane: ...new mover [%i]\n", i));

// Allocate a new clplane_t thinker.
mov = map->clActivePlanes[i] = (clplane_t *) Z_Calloc(sizeof(clplane_t), PU_MAP, &map->clActivePlanes[i]);
clplane_t *mov = map->clActivePlanes[i] = (clplane_t *) Z_Calloc(sizeof(clplane_t), PU_MAP, &map->clActivePlanes[i]);
mov->thinker.function = reinterpret_cast<thinkfunc_t>(Cl_MoverThinker);
mov->type = type;
mov->sectorIndex = sectorIndex;
Expand Down

0 comments on commit 5d4ea4d

Please sign in to comment.