Skip to content

Commit

Permalink
Refactor|GameMap: Refactor|GameMap: Moved more GameMap_* functions to…
Browse files Browse the repository at this point in the history
… methods of GameMap

All Blockmap and NodePile initialization.
  • Loading branch information
danij-deng committed Apr 3, 2013
1 parent 5bbae62 commit 8113509
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 92 deletions.
84 changes: 37 additions & 47 deletions doomsday/client/include/map/gamemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,43 @@ class GameMap
*/
void updateBounds();

/**
* Construct an initial (empty) Mobj Blockmap for this map.
*
* @param min Minimal coordinates for the map.
* @param max Maximal coordinates for the map.
*/
void initMobjBlockmap(const_pvec2d_t min, const_pvec2d_t max);

/**
* Construct an initial (empty) LineDef Blockmap for this map.
*
* @param min Minimal coordinates for the map.
* @param max Maximal coordinates for the map.
*/
void initLineBlockmap(const_pvec2d_t min, const_pvec2d_t max);

/**
* Construct an initial (empty) BspLeaf Blockmap for this map.
*
* @param min Minimal coordinates for the map.
* @param max Maximal coordinates for the map.
*/
void initBspLeafBlockmap(const_pvec2d_t min, const_pvec2d_t max);

/**
* Construct an initial (empty) Polyobj Blockmap for this map.
*
* @param min Minimal coordinates for the map.
* @param max Maximal coordinates for the map.
*/
void initPolyobjBlockmap(const_pvec2d_t min, const_pvec2d_t max);

/**
* Initialize the node piles and link rings. To be called after map load.
*/
void initNodePiles();

/**
* Initialize all polyobjs in the map. To be called after map load.
*/
Expand Down Expand Up @@ -661,13 +698,6 @@ boolean GameMap_IsUsedMobjID(GameMap* map, thid_t id);
*/
void GameMap_SetMobjID(GameMap *map, thid_t id, boolean inUse);

/**
* Initialize the node piles and link rings. To be called after map load.
*
* @param map GameMap instance.
*/
void GameMap_InitNodePiles(GameMap *map);

int GameMap_MobjsBoxIterator(GameMap *map, AABoxd const *box,
int (*callback) (struct mobj_s *, void *), void *parameters);

Expand Down Expand Up @@ -716,46 +746,6 @@ inline int GameMap_PathTraverse(GameMap *map, coord_t fromX, coord_t fromY,
return GameMap_PathTraverse(map, from, to, flags, callback, parameters);
}

/**
* Private member functions:
*/

/**
* Construct an initial (empty) Mobj Blockmap for this map.
*
* @param map GameMap instance.
* @param min Minimal coordinates for the map.
* @param max Maximal coordinates for the map.
*/
void GameMap_InitMobjBlockmap(GameMap *map, const_pvec2d_t min, const_pvec2d_t max);

/**
* Construct an initial (empty) LineDef Blockmap for this map.
*
* @param map GameMap instance.
* @param min Minimal coordinates for the map.
* @param max Maximal coordinates for the map.
*/
void GameMap_InitLineDefBlockmap(GameMap *map, const_pvec2d_t min, const_pvec2d_t max);

/**
* Construct an initial (empty) BspLeaf Blockmap for this map.
*
* @param map GameMap instance.
* @param min Minimal coordinates for the map.
* @param max Maximal coordinates for the map.
*/
void GameMap_InitBspLeafBlockmap(GameMap *map, const_pvec2d_t min, const_pvec2d_t max);

/**
* Construct an initial (empty) Polyobj Blockmap for this map.
*
* @param map GameMap instance.
* @param min Minimal coordinates for the map.
* @param max Maximal coordinates for the map.
*/
void GameMap_InitPolyobjBlockmap(GameMap *map, const_pvec2d_t min, const_pvec2d_t max);

// The current map.
DENG_EXTERN_C GameMap *theMap;

Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/edit_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1701,15 +1701,15 @@ boolean MPE_End()
vec2d_t min, max;
findBounds(editMap.vertexes, min, max);

GameMap_InitLineDefBlockmap(gamemap, min, max);
gamemap->initLineBlockmap(min, max);
for(int i = 0; i < gamemap->_lines.count(); ++i)
{
gamemap->linkLine(*gamemap->_lines[i]);
}

// Mobj and Polyobj blockmaps are maintained dynamically.
GameMap_InitMobjBlockmap(gamemap, min, max);
GameMap_InitPolyobjBlockmap(gamemap, min, max);
gamemap->initMobjBlockmap(min, max);
gamemap->initPolyobjBlockmap(min, max);

/*
* Build a BSP for this map.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/map/dam_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ boolean DAM_AttemptMapLoad(uri_s const *_uri)
P_InitUnusedMobjList();

// Must be called before any mobjs are spawned.
GameMap_InitNodePiles(map);
map->initNodePiles();

#ifdef __CLIENT__
// Prepare the client-side data.
Expand All @@ -302,7 +302,7 @@ boolean DAM_AttemptMapLoad(uri_s const *_uri)
map->bounds(min, max);

// Init blockmap for searching BSP leafs.
GameMap_InitBspLeafBlockmap(map, min, max);
map->initBspLeafBlockmap(min, max);
foreach(BspLeaf *bspLeaf, map->bspLeafs())
{
map->linkBspLeaf(*bspLeaf);
Expand Down
74 changes: 34 additions & 40 deletions doomsday/client/src/map/gamemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,110 +376,104 @@ Generators *GameMap::generators()
return _generators;
}

void GameMap_InitNodePiles(GameMap *map)
void GameMap::initNodePiles()
{
uint starttime = 0;

DENG2_ASSERT(map);

VERBOSE( Con_Message("GameMap::InitNodePiles: Initializing...") )
VERBOSE2( starttime = Timer_RealMilliseconds() )

// Initialize node piles and line rings.
NP_Init(&map->mobjNodes, 256); // Allocate a small pile.
NP_Init(&map->lineNodes, map->lineCount() + 1000);
NP_Init(&mobjNodes, 256); // Allocate a small pile.
NP_Init(&lineNodes, lineCount() + 1000);

// Allocate the rings.
map->lineLinks = (nodeindex_t *) Z_Malloc(sizeof(*map->lineLinks) * map->lineCount(), PU_MAPSTATIC, 0);
lineLinks = (nodeindex_t *) Z_Malloc(sizeof(*lineLinks) * lineCount(), PU_MAPSTATIC, 0);

for(uint i = 0; i < map->lineCount(); ++i)
for(uint i = 0; i < lineCount(); ++i)
{
map->lineLinks[i] = NP_New(&map->lineNodes, NP_ROOT_NODE);
lineLinks[i] = NP_New(&lineNodes, NP_ROOT_NODE);
}

// How much time did we spend?
VERBOSE2( Con_Message(" Done in %.2f seconds.", (Timer_RealMilliseconds() - starttime) / 1000.0f) )
}

void GameMap_InitLineDefBlockmap(GameMap* map, const_pvec2d_t min_, const_pvec2d_t max_)
void GameMap::initLineBlockmap(const_pvec2d_t min_, const_pvec2d_t max_)
{
#define BLOCKMAP_MARGIN 8 // size guardband around map
#define CELL_SIZE MAPBLOCKUNITS

vec2d_t min, max;
DENG2_ASSERT(map && min_ && max_);
DENG2_ASSERT(min_ && max_);

// Setup the blockmap area to enclose the whole map, plus a margin
// (margin is needed for a map that fits entirely inside one blockmap cell).
V2d_Set(min, min_[VX] - BLOCKMAP_MARGIN,
min_[VY] - BLOCKMAP_MARGIN);
V2d_Set(max, max_[VX] + BLOCKMAP_MARGIN,
max_[VY] + BLOCKMAP_MARGIN);
vec2d_t min; V2d_Set(min, min_[VX] - BLOCKMAP_MARGIN,
min_[VY] - BLOCKMAP_MARGIN);
vec2d_t max; V2d_Set(max, max_[VX] + BLOCKMAP_MARGIN,
max_[VY] + BLOCKMAP_MARGIN);

map->lineBlockmap = Blockmap_New(min, max, CELL_SIZE, CELL_SIZE);
lineBlockmap = Blockmap_New(min, max, CELL_SIZE, CELL_SIZE);

#undef CELL_SIZE
#undef BLOCKMAP_MARGIN
}

void GameMap_InitMobjBlockmap(GameMap* map, const_pvec2d_t min_, const_pvec2d_t max_)
void GameMap::initMobjBlockmap(const_pvec2d_t min_, const_pvec2d_t max_)
{
#define BLOCKMAP_MARGIN 8 // size guardband around map
#define CELL_SIZE MAPBLOCKUNITS

vec2d_t min, max;
DENG2_ASSERT(map && min_ && max_);
DENG2_ASSERT(min_ && max_);

// Setup the blockmap area to enclose the whole map, plus a margin
// (margin is needed for a map that fits entirely inside one blockmap cell).
V2d_Set(min, min_[VX] - BLOCKMAP_MARGIN,
min_[VY] - BLOCKMAP_MARGIN);
V2d_Set(max, max_[VX] + BLOCKMAP_MARGIN,
max_[VY] + BLOCKMAP_MARGIN);
vec2d_t min; V2d_Set(min, min_[VX] - BLOCKMAP_MARGIN,
min_[VY] - BLOCKMAP_MARGIN);
vec2d_t max; V2d_Set(max, max_[VX] + BLOCKMAP_MARGIN,
max_[VY] + BLOCKMAP_MARGIN);

map->mobjBlockmap = Blockmap_New(min, max, CELL_SIZE, CELL_SIZE);
mobjBlockmap = Blockmap_New(min, max, CELL_SIZE, CELL_SIZE);

#undef CELL_SIZE
#undef BLOCKMAP_MARGIN
}

void GameMap_InitPolyobjBlockmap(GameMap* map, const_pvec2d_t min_, const_pvec2d_t max_)
void GameMap::initPolyobjBlockmap(const_pvec2d_t min_, const_pvec2d_t max_)
{
#define BLOCKMAP_MARGIN 8 // size guardband around map
#define CELL_SIZE MAPBLOCKUNITS

vec2d_t min, max;
DENG2_ASSERT(map && min_ && max_);
DENG2_ASSERT(min_ && max_);

// Setup the blockmap area to enclose the whole map, plus a margin
// (margin is needed for a map that fits entirely inside one blockmap cell).
V2d_Set(min, min_[VX] - BLOCKMAP_MARGIN,
min_[VY] - BLOCKMAP_MARGIN);
V2d_Set(max, max_[VX] + BLOCKMAP_MARGIN,
max_[VY] + BLOCKMAP_MARGIN);
vec2d_t min; V2d_Set(min, min_[VX] - BLOCKMAP_MARGIN,
min_[VY] - BLOCKMAP_MARGIN);
vec2d_t max; V2d_Set(max, max_[VX] + BLOCKMAP_MARGIN,
max_[VY] + BLOCKMAP_MARGIN);

map->polyobjBlockmap = Blockmap_New(min, max, CELL_SIZE, CELL_SIZE);
polyobjBlockmap = Blockmap_New(min, max, CELL_SIZE, CELL_SIZE);

#undef CELL_SIZE
#undef BLOCKMAP_MARGIN
}

void GameMap_InitBspLeafBlockmap(GameMap* map, const_pvec2d_t min_, const_pvec2d_t max_)
void GameMap::initBspLeafBlockmap(const_pvec2d_t min_, const_pvec2d_t max_)
{
#define BLOCKMAP_MARGIN 8 // size guardband around map
#define CELL_SIZE MAPBLOCKUNITS

vec2d_t min, max;
DENG2_ASSERT(map && min_ && max_);
DENG2_ASSERT(min_ && max_);

// Setup the blockmap area to enclose the whole map, plus a margin
// (margin is needed for a map that fits entirely inside one blockmap cell).
V2d_Set(min, min_[VX] - BLOCKMAP_MARGIN,
min_[VY] - BLOCKMAP_MARGIN);
V2d_Set(max, max_[VX] + BLOCKMAP_MARGIN,
max_[VY] + BLOCKMAP_MARGIN);
vec2d_t min; V2d_Set(min, min_[VX] - BLOCKMAP_MARGIN,
min_[VY] - BLOCKMAP_MARGIN);
vec2d_t max; V2d_Set(max, max_[VX] + BLOCKMAP_MARGIN,
max_[VY] + BLOCKMAP_MARGIN);

map->bspLeafBlockmap = Blockmap_New(min, max, CELL_SIZE, CELL_SIZE);
bspLeafBlockmap = Blockmap_New(min, max, CELL_SIZE, CELL_SIZE);

#undef CELL_SIZE
#undef BLOCKMAP_MARGIN
Expand Down

0 comments on commit 8113509

Please sign in to comment.