From a72f302a5e6970e667c77337661f3053cf20515a Mon Sep 17 00:00:00 2001 From: danij Date: Sun, 11 Mar 2012 00:41:41 +0000 Subject: [PATCH] GameMap|Blockmap|Gridmap|Refactor: Enforce data hiding - GameMap's use of Blockmap is now invisible --- doomsday/engine/portable/include/blockmap.h | 95 +++++-- doomsday/engine/portable/include/gamemap.h | 141 +++++----- doomsday/engine/portable/include/gridmap.h | 55 ++-- doomsday/engine/portable/src/blockmap.c | 106 ++++---- doomsday/engine/portable/src/blockmapvisual.c | 8 +- doomsday/engine/portable/src/dam_main.c | 2 +- doomsday/engine/portable/src/edit_map.c | 2 +- doomsday/engine/portable/src/gamemap.c | 131 +++++----- doomsday/engine/portable/src/gridmap.c | 246 +++++++++--------- doomsday/engine/portable/src/p_maputil.c | 4 +- doomsday/engine/portable/src/p_polyobjs.c | 4 +- 11 files changed, 431 insertions(+), 363 deletions(-) diff --git a/doomsday/engine/portable/include/blockmap.h b/doomsday/engine/portable/include/blockmap.h index bada028a2d..d4a3861247 100644 --- a/doomsday/engine/portable/include/blockmap.h +++ b/doomsday/engine/portable/include/blockmap.h @@ -25,112 +25,153 @@ #include "dd_types.h" #include "m_vector.h" -#include "p_mapdata.h" + +/// @todo It should not be necessary to expose the Gridmap implementation. #include "gridmap.h" struct blockmap_s; // The Blockmap instance (opaque). typedef struct blockmap_s Blockmap; +typedef GridmapCoord BlockmapCoord; +typedef GridmapCell BlockmapCell; +typedef const_GridmapCell const_BlockmapCell; + +typedef GridmapCellBlock BlockmapCellBlock; + Blockmap* Blockmap_New(const pvec2_t min, const pvec2_t max, uint cellWidth, uint cellHeight); /** + * @param blockmap Blockmap instance. * @return "Origin" map space point for the Blockmap (minimal [x,y]). */ const pvec2_t Blockmap_Origin(Blockmap* blockmap); /** * Retrieve the extremal map space points covered by the Blockmap. + * + * @param blockmap Blockmap instance. */ const AABoxf* Blockmap_Bounds(Blockmap* blockmap); -/// @return Width of the Blockmap in cells. -uint Blockmap_Width(Blockmap* blockmap); +/** + * @param blockmap Blockmap instance. + * @return Width of the Blockmap in cells. + */ +BlockmapCoord Blockmap_Width(Blockmap* blockmap); -/// @return Height of the Blockmap in cells. -uint Blockmap_Height(Blockmap* blockmap); +/** + * @param blockmap Blockmap instance. + * @return Height of the Blockmap in cells. + */ +BlockmapCoord Blockmap_Height(Blockmap* blockmap); /** * Retrieve the size of the Blockmap in cells. * * @param widthHeight Size of the Blockmap [width,height] written here. */ -void Blockmap_Size(Blockmap* blockmap, uint widthHeight[2]); +void Blockmap_Size(Blockmap* blockmap, BlockmapCoord widthHeight[2]); -/// @return Width of a Blockmap cell in map space units. +/** + * @param blockmap Blockmap instance. + * @return Width of a Blockmap cell in map space units. + */ float Blockmap_CellWidth(Blockmap* blockmap); -/// @return Height of a Blockmap cell in map space units. +/** + * @param blockmap Blockmap instance. + * @return Height of a Blockmap cell in map space units. + */ float Blockmap_CellHeight(Blockmap* blockmap); -/// @return Size [width,height] of a Blockmap cell in map space units. +/** + * @param blockmap Blockmap instance. + * @return Size [width,height] of a Blockmap cell in map space units. + */ const pvec2_t Blockmap_CellSize(Blockmap* blockmap); /** * Given map space X coordinate @a x, return the corresponding cell coordinate. * If @a x is outside the Blockmap it will be clamped to the nearest edge on * the X axis. + * + * @param blockmap Blockmap instance. + * @param x Map space X coordinate to be translated. + * + * @return Translated Blockmap cell X coordinate. */ -uint Blockmap_CellX(Blockmap* blockmap, float x); +BlockmapCoord Blockmap_CellX(Blockmap* blockmap, float x); /** * Given map space Y coordinate @a y, return the corresponding cell coordinate. * If @a y is outside the Blockmap it will be clamped to the nearest edge on * the Y axis. * - * @param outY Blockmap cell X coordinate written here. - * @param y Map space X coordinate to be translated. - * @return @c true iff clamping was necessary. + * @param blockmap Blockmap instance. + * @param y Map space Y coordinate to be translated. + * + * @return Translated Blockmap cell Y coordinate. */ -uint Blockmap_CellY(Blockmap* blockmap, float y); +BlockmapCoord Blockmap_CellY(Blockmap* blockmap, float y); /** * Same as @a Blockmap::CellX with alternative semantics for when the caller * needs to know if the coordinate specified was inside/outside the Blockmap. */ -boolean Blockmap_ClipCellX(Blockmap* bm, uint* outX, float x); +boolean Blockmap_ClipCellX(Blockmap* blockmap, BlockmapCoord* outX, float x); /** * Same as @a Blockmap::CellY with alternative semantics for when the caller * needs to know if the coordinate specified was inside/outside the Blockmap. * - * @param outY Blockmap cell Y coordinate written here. - * @param y Map space Y coordinate to be translated. + * @param blockmap Blockmap instance. + * @param outY Blockmap cell Y coordinate written here. + * @param y Map space Y coordinate to be translated. + * * @return @c true iff clamping was necessary. */ -boolean Blockmap_ClipCellY(Blockmap* bm, uint* outY, float y); +boolean Blockmap_ClipCellY(Blockmap* blockmap, BlockmapCoord* outY, float y); /** * Given map space XY coordinates @a pos, output the Blockmap cell[x, y] it * resides in. If @a pos is outside the Blockmap it will be clamped to the * nearest edge on one or more axes as necessary. * + * @param blockmap Blockmap instance. + * @param cell Blockmap cell coordinates will be written here. + * @param pos Map space coordinates to translate. + * * @return @c true iff clamping was necessary. */ -boolean Blockmap_CellCoords(Blockmap* blockmap, uint coords[2], float const pos[2]); +boolean Blockmap_Cell(Blockmap* blockmap, BlockmapCell cell, float const pos[2]); /** * Given map space box XY coordinates @a box, output the blockmap cells[x, y] * they reside in. If any point defined by @a box lies outside the blockmap * it will be clamped to the nearest edge on one or more axes as necessary. * + * @param blockmap Blockmap instance. + * @param cellBlock Blockmap cell coordinates will be written here. + * @param box Map space coordinates to translate. + * * @return @c true iff Clamping was necessary. */ -boolean Blockmap_CellBlockCoords(Blockmap* blockmap, GridmapBlock* blockCoords, const AABoxf* box); +boolean Blockmap_CellBlock(Blockmap* blockmap, BlockmapCellBlock* cellBlock, const AABoxf* box); -boolean Blockmap_CreateCellAndLinkObject(Blockmap* blockmap, uint const coords[2], void* object); +boolean Blockmap_CreateCellAndLinkObject(Blockmap* blockmap, const_BlockmapCell cell, void* object); -boolean Blockmap_CreateCellAndLinkObjectXY(Blockmap* blockmap, uint x, uint y, void* object); +boolean Blockmap_CreateCellAndLinkObjectXY(Blockmap* blockmap, BlockmapCoord x, BlockmapCoord y, void* object); -boolean Blockmap_UnlinkObjectInCell(Blockmap* blockmap, uint const coords[2], void* object); +boolean Blockmap_UnlinkObjectInCell(Blockmap* blockmap, const_BlockmapCell cell, void* object); -boolean Blockmap_UnlinkObjectInCellXY(Blockmap* blockmap, uint x, uint y, void* object); +boolean Blockmap_UnlinkObjectInCellXY(Blockmap* blockmap, BlockmapCoord x, BlockmapCoord y, void* object); -void Blockmap_UnlinkObjectInCellBlock(Blockmap* blockmap, const GridmapBlock* blockCoords, void* object); +void Blockmap_UnlinkObjectInCellBlock(Blockmap* blockmap, const BlockmapCellBlock* blockCoords, void* object); -int Blockmap_IterateCellObjects(Blockmap* blockmap, uint const coords[2], +int Blockmap_IterateCellObjects(Blockmap* blockmap, const_BlockmapCell cell, int (*callback) (void* object, void* context), void* context); -int Blockmap_IterateCellBlockObjects(Blockmap* blockmap, const GridmapBlock* blockCoords, +int Blockmap_IterateCellBlockObjects(Blockmap* blockmap, const BlockmapCellBlock* blockCoords, int (*callback) (void* object, void* context), void* context); #endif /// LIBDENG_MAP_BLOCKMAP_H diff --git a/doomsday/engine/portable/include/gamemap.h b/doomsday/engine/portable/include/gamemap.h index 1f2f927c9d..eb19576a03 100644 --- a/doomsday/engine/portable/include/gamemap.h +++ b/doomsday/engine/portable/include/gamemap.h @@ -29,11 +29,8 @@ struct thinkerlist_s; struct clmoinfo_s; struct generators_s; -/// Size of Blockmap blocks in map units. Must be an integer power of two. -#define MAPBLOCKUNITS (128) - +/// @todo Remove me. struct blockmap_s; -struct gridmapblock_s; /** * The client mobjs are stored into a hash for quickly locating a ClMobj by its identifier. @@ -506,8 +503,7 @@ void GameMap_SetMobjID(GameMap* map, thid_t id, boolean state); void GameMap_InitClMobjs(GameMap* map); /** - * Called when the client is shut down. Unlinks everything from the - * sectors and the blockmap and clears the clmobj list. + * To be called when the client is shut down. */ void GameMap_DestroyClMobjs(GameMap* map); @@ -601,46 +597,36 @@ void GameMap_InitPolyobjs(GameMap* map); void GameMap_InitNodePiles(GameMap* map); /** - * Construct an initial (empty) Mobj Blockmap for this map. + * Link the specified @a mobj in any internal data structures for bookkeeping purposes. + * Should be called AFTER mobj translation to (re-)insert the mobj. * - * @param min Minimal coordinates for the map. - * @param max Maximal coordinates for the map. + * @param map GameMap instance. + * @param mobj Mobj to be linked. */ -void GameMap_InitMobjBlockmap(GameMap* map, const_pvec2_t min, const_pvec2_t max); - -void GameMap_LinkMobjInBlockmap(GameMap* map, struct mobj_s* mo); -boolean GameMap_UnlinkMobjInBlockmap(GameMap* map, struct mobj_s* mo); +void GameMap_LinkMobj(GameMap* map, struct mobj_s* mobj); -int GameMap_IterateCellMobjs(GameMap* map, const uint coords[2], - int (*callback) (struct mobj_s*, void*), void* parameters); -int GameMap_IterateCellBlockMobjs(GameMap* map, const struct gridmapblock_s* blockCoords, - int (*callback) (struct mobj_s*, void*), void* parameters); +/** + * Unlink the specified @a mobj from any internal data structures for bookkeeping purposes. + * Should be called BEFORE mobj translation to extract the mobj. + * + * @param map GameMap instance. + * @param mobj Mobj to be unlinked. + */ +boolean GameMap_UnlinkMobj(GameMap* map, struct mobj_s* mobj); int GameMap_MobjsBoxIterator(GameMap* map, const AABoxf* box, int (*callback) (struct mobj_s*, void*), void* parameters); /** - * Construct an initial (empty) LineDef Blockmap for this map. + * Link the specified @a lineDef in any internal data structures for bookkeeping purposes. * - * @param min Minimal coordinates for the map. - * @param max Maximal coordinates for the map. + * @param map GameMap instance. + * @param lineDef LineDef to be linked. */ -void GameMap_InitLineDefBlockmap(GameMap* map, const_pvec2_t min, const_pvec2_t max); - -void GameMap_LinkLineDefInBlockmap(GameMap* map, LineDef* lineDef); - -int GameMap_IterateCellLineDefs(GameMap* map, const uint coords[2], - int (*callback) (LineDef*, void*), void* parameters); -int GameMap_IterateCellBlockLineDefs(GameMap* map, const struct gridmapblock_s* blockCoords, - int (*callback) (LineDef*, void*), void* parameters); +void GameMap_LinkLineDef(GameMap* map, LineDef* lineDef); int GameMap_LineDefIterator(GameMap* map, int (*callback) (LineDef*, void*), void* parameters); -int GameMap_IterateCellPolyobjLineDefs(GameMap* map, const uint coords[2], - int (*callback) (LineDef*, void*), void* parameters); -int GameMap_IterateCellBlockPolyobjLineDefs(GameMap* map, const struct gridmapblock_s* blockCoords, - int (*callback) (LineDef*, void*), void* parameters); - int GameMap_LineDefsBoxIterator(GameMap* map, const AABoxf* box, int (*callback) (LineDef*, void*), void* parameters); @@ -650,29 +636,20 @@ int GameMap_PolyobjLinesBoxIterator(GameMap* map, const AABoxf* box, /** * LineDefs and Polyobj LineDefs (note Polyobj LineDefs are iterated first). * - * The validCount flags are used to avoid checking lines that are marked - * in multiple mapblocks, so increment validCount before the first call - * to GameMap_IterateCellLineDefs(), then make one or more calls to it. + * @note validCount should be incremented before calling this to begin a new logical traversal. + * Otherwise LineDefs marked with a validCount equal to this will be skipped over (can + * be used to avoid processing a LineDef multiple times during complex / non-linear traversals. */ int GameMap_AllLineDefsBoxIterator(GameMap* map, const AABoxf* box, int (*callback) (LineDef*, void*), void* parameters); /** - * Construct an initial (empty) BspLeaf Blockmap for this map. + * Link the specified @a bspLeaf in internal data structures for bookkeeping purposes. * - * @param min Minimal coordinates for the map. - * @param max Maximal coordinates for the map. + * @param map GameMap instance. + * @param bspLeaf BspLeaf to be linked. */ -void GameMap_InitBspLeafBlockmap(GameMap* map, const_pvec2_t min, const_pvec2_t max); - -void GameMap_LinkBspLeafInBlockmap(GameMap* map, BspLeaf* bspLeaf); - -int GameMap_IterateCellBspLeafs(GameMap* map, const uint coords[2], - Sector* sector, const AABoxf* box, int localValidCount, - int (*callback) (BspLeaf*, void*), void* parameters); -int GameMap_IterateCellBlockBspLeafs(GameMap* map, const struct gridmapblock_s* blockCoords, - Sector* sector, const AABoxf* box, int localValidCount, - int (*callback) (BspLeaf*, void*), void* parameters); +void GameMap_LinkBspLeaf(GameMap* map, BspLeaf* bspLeaf); int GameMap_BspLeafsBoxIterator(GameMap* map, const AABoxf* box, Sector* sector, int (*callback) (BspLeaf*, void*), void* parameters); @@ -680,25 +657,27 @@ int GameMap_BspLeafsBoxIterator(GameMap* map, const AABoxf* box, Sector* sector, int GameMap_BspLeafIterator(GameMap* map, int (*callback) (BspLeaf*, void*), void* parameters); /** - * Construct an initial (empty) Polyobj Blockmap for this map. + * Link the specified @a polyobj in any internal data structures for bookkeeping purposes. + * Should be called AFTER Polyobj rotation and/or translation to (re-)insert the polyobj. * - * @param min Minimal coordinates for the map. - * @param max Maximal coordinates for the map. + * @param map GameMap instance. + * @param polyobj Polyobj to be linked. */ -void GameMap_InitPolyobjBlockmap(GameMap* map, const_pvec2_t min, const_pvec2_t max); - -void GameMap_LinkPolyobjInBlockmap(GameMap* map, Polyobj* po); -void GameMap_UnlinkPolyobjInBlockmap(GameMap* map, Polyobj* po); +void GameMap_LinkPolyobj(GameMap* map, Polyobj* polyobj); -int GameMap_IterateCellPolyobjs(GameMap* map, const uint coords[2], - int (*callback) (Polyobj*, void*), void* parameters); -int GameMap_IterateCellBlockPolyobjs(GameMap* map, const struct gridmapblock_s* blockCoords, - int (*callback) (Polyobj*, void*), void* parameters); +/** + * Unlink the specified @a polyobj from any internal data structures for bookkeeping purposes. + * Should be called BEFORE Polyobj rotation and/or translation to extract the polyobj. + * + * @param map GameMap instance. + * @param polyobj Polyobj to be unlinked. + */ +void GameMap_UnlinkPolyobj(GameMap* map, Polyobj* polyobj); /** - * The validCount flags are used to avoid checking polys that are marked in - * multiple mapblocks, so increment validCount before the first call, then - * make one or more calls to it. + * @note validCount should be incremented before calling this to begin a new logical traversal. + * Otherwise LineDefs marked with a validCount equal to this will be skipped over (can + * be used to avoid processing a LineDef multiple times during complex / non-linear traversals. */ int GameMap_PolyobjsBoxIterator(GameMap* map, const AABoxf* box, int (*callback) (struct polyobj_s*, void*), void* parameters); @@ -745,4 +724,40 @@ int GameMap_PathXYTraverse(GameMap* map, float fromX, float fromY, float toX, fl BspLeaf* GameMap_BspLeafAtPoint(GameMap* map, float point[2]); BspLeaf* GameMap_BspLeafAtPointXY(GameMap* map, float x, float y); +/** + * Private member functions: + */ + +/** + * Construct an initial (empty) Mobj Blockmap for this map. + * + * @param min Minimal coordinates for the map. + * @param max Maximal coordinates for the map. + */ +void GameMap_InitMobjBlockmap(GameMap* map, const_pvec2_t min, const_pvec2_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 GameMap_InitLineDefBlockmap(GameMap* map, const_pvec2_t min, const_pvec2_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 GameMap_InitBspLeafBlockmap(GameMap* map, const_pvec2_t min, const_pvec2_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 GameMap_InitPolyobjBlockmap(GameMap* map, const_pvec2_t min, const_pvec2_t max); + #endif /// LIBDENG_GAMEMAP_H diff --git a/doomsday/engine/portable/include/gridmap.h b/doomsday/engine/portable/include/gridmap.h index 7ad9bbda9c..878083fa5d 100644 --- a/doomsday/engine/portable/include/gridmap.h +++ b/doomsday/engine/portable/include/gridmap.h @@ -32,33 +32,38 @@ #include "dd_types.h" +typedef uint GridmapCoord; +typedef GridmapCoord GridmapCell[2]; +typedef const GridmapCoord const_GridmapCell[2]; + /** - * GridmapBlock. Handy POD structure for representing a rectangular range of cells + * GridmapCellBlock. Handy POD structure for representing a rectangular range of cells * (a "cell block"). */ -typedef struct gridmapblock_s { +typedef struct gridmapcellblock_s { union { struct { - uint minX; - uint minY; - uint maxX; - uint maxY; + GridmapCoord minX; + GridmapCoord minY; + GridmapCoord maxX; + GridmapCoord maxY; }; struct { - uint min[2]; - uint max[2]; + GridmapCell min; + GridmapCell max; }; struct { - uint box[4]; + GridmapCell box[2]; }; }; -} GridmapBlock; +} GridmapCellBlock; /** * Initialize @a block using the specified coordinates. */ -void GridmapBlock_SetCoords(GridmapBlock* block, uint const min[2], uint const max[2]); -void GridmapBlock_SetCoordsXY(GridmapBlock* block, uint minX, uint minY, uint maxX, uint maxY); +void GridmapBlock_SetCoords(GridmapCellBlock* block, const_GridmapCell min, const_GridmapCell max); +void GridmapBlock_SetCoordsXY(GridmapCellBlock* block, GridmapCoord minX, GridmapCoord minY, + GridmapCoord maxX, GridmapCoord maxY); struct gridmap_s; // The Gridmap instance (opaque). @@ -75,7 +80,7 @@ typedef struct gridmap_s Gridmap; * @param sizeOfCell Amount of memory to be allocated for the user data associated with each cell. * @param zoneTag Zone memory tag for the allocated user data. */ -Gridmap* Gridmap_New(uint width, uint height, size_t sizeOfCell, int zoneTag); +Gridmap* Gridmap_New(GridmapCoord width, GridmapCoord height, size_t sizeOfCell, int zoneTag); void Gridmap_Delete(Gridmap* gridmap); @@ -86,7 +91,7 @@ void Gridmap_Delete(Gridmap* gridmap); * * @return Width of the Gridmap in cells. */ -uint Gridmap_Width(const Gridmap* gridmap); +GridmapCoord Gridmap_Width(const Gridmap* gridmap); /** * Retrieve the height of the Gridmap in cells. @@ -95,7 +100,7 @@ uint Gridmap_Width(const Gridmap* gridmap); * * @return Height of the Gridmap in cells. */ -uint Gridmap_Height(const Gridmap* gridmap); +GridmapCoord Gridmap_Height(const Gridmap* gridmap); /** * Retrieve the dimensions of the Gridmap in cells. @@ -103,7 +108,7 @@ uint Gridmap_Height(const Gridmap* gridmap); * @param gridmap Gridmap instance. * @param widthHeight Dimensions will be written here. */ -void Gridmap_Size(const Gridmap* gridmap, uint widthHeight[2]); +void Gridmap_Size(const Gridmap* gridmap, GridmapCoord widthHeight[2]); /** * Retrieve the user data associated with the identified cell. @@ -116,12 +121,12 @@ void Gridmap_Size(const Gridmap* gridmap, uint widthHeight[2]); * @return User data for the identified cell else @c NULL if an invalid reference or no * there is no data present (and not allocating). */ -void* Gridmap_Cell(Gridmap* gridmap, uint const coords[2], boolean alloc); +void* Gridmap_Cell(Gridmap* gridmap, const_GridmapCell cell, boolean alloc); /** * Same as Gridmap::Cell except cell coordinates are expressed with @a x and @a y arguments. */ -void* Gridmap_CellXY(Gridmap* gridmap, uint x, uint y, boolean alloc); +void* Gridmap_CellXY(Gridmap* gridmap, GridmapCoord x, GridmapCoord y, boolean alloc); /** * Iteration. @@ -154,19 +159,19 @@ int Gridmap_Iterate(Gridmap* gridmap, Gridmap_IterateCallback callback); /*param * * @return @c 0 iff iteration completed wholly. */ -int Gridmap_BlockIterate2(Gridmap* gridmap, const GridmapBlock* block, +int Gridmap_BlockIterate2(Gridmap* gridmap, const GridmapCellBlock* block, Gridmap_IterateCallback callback, void* paramates); -int Gridmap_BlockIterate(Gridmap* gridmap, const GridmapBlock* block, +int Gridmap_BlockIterate(Gridmap* gridmap, const GridmapCellBlock* block, Gridmap_IterateCallback callback); /*parameters=NULL*/ /** * Same as Gridmap::BlockIterate except cell block coordinates are expressed with * independent X and Y coordinate arguments. For convenience. */ -int Gridmap_BlockXYIterate2(Gridmap* gridmap, uint minX, uint minY, uint maxX, uint maxY, - Gridmap_IterateCallback callback, void* parameters); -int Gridmap_BlockXYIterate(Gridmap* gridmap, uint minX, uint minY, uint maxX, uint maxY, - Gridmap_IterateCallback callback); /*parameters=NULL*/ +int Gridmap_BlockXYIterate2(Gridmap* gridmap, GridmapCoord minX, GridmapCoord minY, + GridmapCoord maxX, GridmapCoord maxY, Gridmap_IterateCallback callback, void* parameters); +int Gridmap_BlockXYIterate(Gridmap* gridmap, GridmapCoord minX, GridmapCoord minY, + GridmapCoord maxX, GridmapCoord maxY, Gridmap_IterateCallback callback/*, parameters=NULL*/); /** * Clip the cell coordinates in @a block vs the dimensions of this Gridmap so that they @@ -177,7 +182,7 @@ int Gridmap_BlockXYIterate(Gridmap* gridmap, uint minX, uint minY, uint maxX, ui * * @return @c true iff the block coordinates were changed. */ -boolean Gridmap_ClipBlock(Gridmap* gridmap, GridmapBlock* block); +boolean Gridmap_ClipBlock(Gridmap* gridmap, GridmapCellBlock* block); /** * Render a visual for this Gridmap to assist in debugging (etc...). diff --git a/doomsday/engine/portable/src/blockmap.c b/doomsday/engine/portable/src/blockmap.c index 2cbd9b107e..a17023805c 100644 --- a/doomsday/engine/portable/src/blockmap.c +++ b/doomsday/engine/portable/src/blockmap.c @@ -37,7 +37,7 @@ typedef struct blockmap_ringnode_s { typedef struct { BlockmapRingNode* ringNodes; -} BlockmapCell; +} BlockmapCellData; struct blockmap_s { @@ -64,13 +64,13 @@ Blockmap* Blockmap_New(const pvec2_t min, const pvec2_t max, uint cellWidth, uin width = (uint)ceil((max[0] - min[0]) / (float)cellWidth); height = (uint)ceil((max[1] - min[1]) / (float)cellHeight); - bm->gridmap = Gridmap_New(width, height, sizeof(BlockmapCell), PU_MAPSTATIC); + bm->gridmap = Gridmap_New(width, height, sizeof(BlockmapCellData), PU_MAPSTATIC); VERBOSE( Con_Message("Blockmap::New: Width:%u Height:%u\n", width, height) ) return bm; } -uint Blockmap_CellX(Blockmap* bm, float x) +BlockmapCoord Blockmap_CellX(Blockmap* bm, float x) { uint result; assert(bm); @@ -78,7 +78,7 @@ uint Blockmap_CellX(Blockmap* bm, float x) return result; } -uint Blockmap_CellY(Blockmap* bm, float y) +BlockmapCoord Blockmap_CellY(Blockmap* bm, float y) { uint result; assert(bm); @@ -86,7 +86,7 @@ uint Blockmap_CellY(Blockmap* bm, float y) return result; } -boolean Blockmap_ClipCellX(Blockmap* bm, uint* outX, float x) +boolean Blockmap_ClipCellX(Blockmap* bm, BlockmapCoord* outX, float x) { boolean adjusted = false; assert(bm); @@ -107,7 +107,7 @@ boolean Blockmap_ClipCellX(Blockmap* bm, uint* outX, float x) return adjusted; } -boolean Blockmap_ClipCellY(Blockmap* bm, uint* outY, float y) +boolean Blockmap_ClipCellY(Blockmap* bm, BlockmapCoord* outY, float y) { boolean adjusted = false; assert(bm); @@ -128,26 +128,26 @@ boolean Blockmap_ClipCellY(Blockmap* bm, uint* outY, float y) return adjusted; } -boolean Blockmap_CellCoords(Blockmap* bm, uint coords[2], float const pos[2]) +boolean Blockmap_Cell(Blockmap* bm, BlockmapCell cell, float const pos[2]) { assert(bm); - if(coords && pos) + if(cell && pos) { // Deliberate bitwise OR - we need to clip both X and Y. - return Blockmap_ClipCellX(bm, &coords[0], pos[VX]) | - Blockmap_ClipCellY(bm, &coords[1], pos[VY]); + return Blockmap_ClipCellX(bm, &cell[0], pos[VX]) | + Blockmap_ClipCellY(bm, &cell[1], pos[VY]); } return false; } -boolean Blockmap_CellBlockCoords(Blockmap* bm, GridmapBlock* blockCoords, const AABoxf* box) +boolean Blockmap_CellBlock(Blockmap* bm, BlockmapCellBlock* cellBlock, const AABoxf* box) { assert(bm); - if(blockCoords && box) + if(cellBlock && box) { // Deliberate bitwise OR - we need to clip both Min and Max. - return Blockmap_CellCoords(bm, blockCoords->min, box->min) | - Blockmap_CellCoords(bm, blockCoords->max, box->max); + return Blockmap_Cell(bm, cellBlock->min, box->min) | + Blockmap_Cell(bm, cellBlock->max, box->max); } return false; } @@ -164,19 +164,19 @@ const AABoxf* Blockmap_Bounds(Blockmap* bm) return &bm->bounds; } -uint Blockmap_Width(Blockmap* bm) +BlockmapCoord Blockmap_Width(Blockmap* bm) { assert(bm); return Gridmap_Width(bm->gridmap); } -uint Blockmap_Height(Blockmap* bm) +BlockmapCoord Blockmap_Height(Blockmap* bm) { assert(bm); return Gridmap_Height(bm->gridmap); } -void Blockmap_Size(Blockmap* bm, uint v[2]) +void Blockmap_Size(Blockmap* bm, BlockmapCoord v[]) { assert(bm); Gridmap_Size(bm->gridmap, v); @@ -260,71 +260,71 @@ static boolean unlinkObjectFromRing(void* object, BlockmapRingNode** list) static int unlinkObjectInCell(void* ptr, void* paramaters) { - BlockmapCell* cell = (BlockmapCell*) ptr; + BlockmapCellData* cell = (BlockmapCellData*) ptr; unlinkObjectFromRing(paramaters/*object ptr*/, &cell->ringNodes); return false; // Continue iteration. } static int linkObjectInCell(void* ptr, void* paramaters) { - BlockmapCell* cell = (BlockmapCell*) ptr; - linkObjectToRing(paramaters/*object ptr*/, &cell->ringNodes); + BlockmapCellData* data = (BlockmapCellData*) ptr; + linkObjectToRing(paramaters/*object ptr*/, &data->ringNodes); return false; // Continue iteration. } -boolean Blockmap_CreateCellAndLinkObjectXY(Blockmap* blockmap, uint x, uint y, void* object) +boolean Blockmap_CreateCellAndLinkObjectXY(Blockmap* blockmap, BlockmapCoord x, BlockmapCoord y, void* object) { - BlockmapCell* cell; + BlockmapCellData* data; assert(blockmap && object); - cell = (BlockmapCell*) Gridmap_CellXY(blockmap->gridmap, x, y, true); - if(!cell) return false; // Outside the blockmap? - linkObjectInCell((void*)cell, object); + data = (BlockmapCellData*) Gridmap_CellXY(blockmap->gridmap, x, y, true); + if(!data) return false; // Outside the blockmap? + linkObjectInCell((void*)data, object); return true; // Link added. } -boolean Blockmap_CreateCellAndLinkObject(Blockmap* blockmap, uint const coords[2], void* object) +boolean Blockmap_CreateCellAndLinkObject(Blockmap* blockmap, const_BlockmapCell cell, void* object) { - assert(coords); - return Blockmap_CreateCellAndLinkObjectXY(blockmap, coords[VX], coords[VY], object); + assert(cell); + return Blockmap_CreateCellAndLinkObjectXY(blockmap, cell[VX], cell[VY], object); } -boolean Blockmap_UnlinkObjectInCell(Blockmap* blockmap, uint const coords[2], void* object) +boolean Blockmap_UnlinkObjectInCell(Blockmap* blockmap, const_BlockmapCell cell, void* object) { boolean unlinked = false; - BlockmapCell* cell; + BlockmapCellData* data; assert(blockmap); - cell = (BlockmapCell*) Gridmap_Cell(blockmap->gridmap, coords, false); - if(cell) + data = (BlockmapCellData*) Gridmap_Cell(blockmap->gridmap, cell, false); + if(data) { - unlinked = unlinkObjectInCell((void*)cell, (void*)object); + unlinked = unlinkObjectInCell((void*)data, (void*)object); } return unlinked; } -boolean Blockmap_UnlinkObjectInCellXY(Blockmap* blockmap, uint x, uint y, void* object) +boolean Blockmap_UnlinkObjectInCellXY(Blockmap* blockmap, BlockmapCoord x, BlockmapCoord y, void* object) { - uint coords[2]; - coords[0] = x; - coords[1] = y; - return Blockmap_UnlinkObjectInCell(blockmap, coords, object); + BlockmapCell cell; + cell[VX] = x; + cell[VY] = y; + return Blockmap_UnlinkObjectInCell(blockmap, cell, object); } -void Blockmap_UnlinkObjectInCellBlock(Blockmap* blockmap, const GridmapBlock* blockCoords, void* object) +void Blockmap_UnlinkObjectInCellBlock(Blockmap* blockmap, const BlockmapCellBlock* cellBlock, void* object) { assert(blockmap); - if(!blockCoords) return; + if(!cellBlock) return; - Gridmap_BlockIterate2(blockmap->gridmap, blockCoords, unlinkObjectInCell, object); + Gridmap_BlockIterate2(blockmap->gridmap, cellBlock, unlinkObjectInCell, object); } -int BlockmapCell_IterateObjects(BlockmapCell* cell, +int BlockmapCellData_IterateObjects(BlockmapCellData* data, int (*callback) (void* object, void* context), void* context) { BlockmapRingNode* next, *link; - assert(cell); + assert(data); - link = cell->ringNodes; + link = data->ringNodes; while(link) { next = link->next; @@ -340,16 +340,16 @@ int BlockmapCell_IterateObjects(BlockmapCell* cell, return false; // Continue iteration. } -int Blockmap_IterateCellObjects(Blockmap* blockmap, uint const coords[2], +int Blockmap_IterateCellObjects(Blockmap* blockmap, const_BlockmapCell cell, int (*callback) (void* object, void* context), void* context) { - BlockmapCell* cell; + BlockmapCellData* data; assert(blockmap); - cell = Gridmap_Cell(blockmap->gridmap, coords, false); - if(cell) + data = Gridmap_Cell(blockmap->gridmap, cell, false); + if(data) { - return BlockmapCell_IterateObjects(cell, callback, context); + return BlockmapCellData_IterateObjects(data, callback, context); } return false; // Continue iteration. } @@ -361,14 +361,14 @@ typedef struct { static int cellObjectIterator(void* userData, void* context) { - BlockmapCell* cell = (BlockmapCell*)userData; + BlockmapCellData* data = (BlockmapCellData*)userData; cellobjectiterator_params_t* args = (cellobjectiterator_params_t*)context; assert(args); - return BlockmapCell_IterateObjects(cell, args->callback, args->context); + return BlockmapCellData_IterateObjects(data, args->callback, args->context); } -int Blockmap_IterateCellBlockObjects(Blockmap* blockmap, const GridmapBlock* blockCoords, +int Blockmap_IterateCellBlockObjects(Blockmap* blockmap, const BlockmapCellBlock* cellBlock, int (*callback) (void* object, void* context), void* context) { cellobjectiterator_params_t args; @@ -377,5 +377,5 @@ int Blockmap_IterateCellBlockObjects(Blockmap* blockmap, const GridmapBlock* blo args.callback = callback; args.context = context; - return Gridmap_BlockIterate2(blockmap->gridmap, blockCoords, cellObjectIterator, (void*)&args); + return Gridmap_BlockIterate2(blockmap->gridmap, cellBlock, cellObjectIterator, (void*)&args); } diff --git a/doomsday/engine/portable/src/blockmapvisual.c b/doomsday/engine/portable/src/blockmapvisual.c index 55e7ac79d5..7a7b3e6a9d 100644 --- a/doomsday/engine/portable/src/blockmapvisual.c +++ b/doomsday/engine/portable/src/blockmapvisual.c @@ -395,7 +395,7 @@ static void rendBlockmap(Blockmap* blockmap, mobj_t* followMobj, int (*cellDrawer) (Blockmap* blockmap, uint const coords[2], void* paramaters)) { uint x, y, vCoords[2]; - GridmapBlock vBlockCoords; + GridmapCellBlock vBlockCoords; vec2_t start, end, cellSize; void* cell; @@ -404,7 +404,7 @@ static void rendBlockmap(Blockmap* blockmap, mobj_t* followMobj, if(followMobj) { // Determine the followed Mobj's blockmap coords. - if(Blockmap_CellCoords(blockmap, vCoords, followMobj->pos)) + if(Blockmap_Cell(blockmap, vCoords, followMobj->pos)) followMobj = NULL; // Outside the blockmap. if(followMobj) @@ -417,7 +417,7 @@ static void rendBlockmap(Blockmap* blockmap, mobj_t* followMobj, V2_Set(end, followMobj->pos[VX] + radius, followMobj->pos[VY] + radius); V2_InitBox(aaBox.arvec2, start); V2_AddToBox(aaBox.arvec2, end); - Blockmap_CellBlockCoords(blockmap, &vBlockCoords, &aaBox); + Blockmap_CellBlock(blockmap, &vBlockCoords, &aaBox); } } @@ -659,7 +659,7 @@ void Rend_BlockmapDebug(void) { // About the cell the followed Mobj is in. uint coords[2]; - if(!Blockmap_CellCoords(blockmap, coords, followMobj->pos)) + if(!Blockmap_Cell(blockmap, coords, followMobj->pos)) { origin.x = theWindow->geometry.size.width / 2; origin.y = 30; diff --git a/doomsday/engine/portable/src/dam_main.c b/doomsday/engine/portable/src/dam_main.c index b7247b34b0..3c20b59bc6 100644 --- a/doomsday/engine/portable/src/dam_main.c +++ b/doomsday/engine/portable/src/dam_main.c @@ -563,7 +563,7 @@ boolean DAM_AttemptMapLoad(const Uri* uri) GameMap_InitBspLeafBlockmap(map, min, max); for(i = 0; i < map->numBspLeafs; ++i) { - GameMap_LinkBspLeafInBlockmap(map, map->bspLeafs + i); + GameMap_LinkBspLeaf(map, map->bspLeafs + i); } map->uri = Uri_NewCopy(dam->uri); diff --git a/doomsday/engine/portable/src/edit_map.c b/doomsday/engine/portable/src/edit_map.c index d831062a7e..615ef22757 100644 --- a/doomsday/engine/portable/src/edit_map.c +++ b/doomsday/engine/portable/src/edit_map.c @@ -1698,7 +1698,7 @@ boolean MPE_End(void) GameMap_InitLineDefBlockmap(gamemap, min, max); for(i = 0; i < gamemap->numLineDefs; ++i) { - GameMap_LinkLineDefInBlockmap(gamemap, gamemap->lineDefs + i); + GameMap_LinkLineDef(gamemap, gamemap->lineDefs + i); } // Mobj and Polyobj blockmaps are maintained dynamically. diff --git a/doomsday/engine/portable/src/gamemap.c b/doomsday/engine/portable/src/gamemap.c index 3f900e7dcc..93abd42273 100644 --- a/doomsday/engine/portable/src/gamemap.c +++ b/doomsday/engine/portable/src/gamemap.c @@ -32,6 +32,9 @@ #include "generators.h" #include "gamemap.h" +/// Size of Blockmap blocks in map units. Must be an integer power of two. +#define MAPBLOCKUNITS (128) + const Uri* GameMap_Uri(GameMap* map) { assert(map); @@ -507,10 +510,10 @@ void GameMap_InitBspLeafBlockmap(GameMap* map, const_pvec2_t min_, const_pvec2_t #undef BLOCKMAP_MARGIN } -void GameMap_LinkMobjInBlockmap(GameMap* map, mobj_t* mo) +void GameMap_LinkMobj(GameMap* map, mobj_t* mo) { Blockmap* blockmap; - uint coords[2]; + BlockmapCell cell; assert(map); // Do not link NULL mobjs. @@ -521,11 +524,11 @@ void GameMap_LinkMobjInBlockmap(GameMap* map, mobj_t* mo) } blockmap = map->mobjBlockmap; - Blockmap_CellCoords(blockmap, coords, mo->pos); - Blockmap_CreateCellAndLinkObject(blockmap, coords, mo); + Blockmap_Cell(blockmap, cell, mo->pos); + Blockmap_CreateCellAndLinkObject(blockmap, cell, mo); } -boolean GameMap_UnlinkMobjInBlockmap(GameMap* map, mobj_t* mo) +boolean GameMap_UnlinkMobj(GameMap* map, mobj_t* mo) { boolean unlinked = false; assert(map); @@ -533,9 +536,9 @@ boolean GameMap_UnlinkMobjInBlockmap(GameMap* map, mobj_t* mo) if(mo) { Blockmap* blockmap = map->mobjBlockmap; - uint coords[2]; - Blockmap_CellCoords(blockmap, coords, mo->pos); - return Blockmap_UnlinkObjectInCell(blockmap, coords, mo); + BlockmapCell cell; + Blockmap_Cell(blockmap, cell, mo->pos); + return Blockmap_UnlinkObjectInCell(blockmap, cell, mo); } return unlinked; } @@ -564,7 +567,7 @@ static int blockmapCellMobjsIterator(void* object, void* context) return false; // Continue iteration. } -int GameMap_IterateCellMobjs(GameMap* map, const uint coords[2], +static int GameMap_IterateCellMobjs(GameMap* map, const_BlockmapCell cell, int (*callback) (mobj_t*, void*), void* context) { bmapmoiterparams_t args; @@ -574,11 +577,11 @@ int GameMap_IterateCellMobjs(GameMap* map, const uint coords[2], args.func = callback; args.param = context; - return Blockmap_IterateCellObjects(map->mobjBlockmap, coords, + return Blockmap_IterateCellObjects(map->mobjBlockmap, cell, blockmapCellMobjsIterator, (void*)&args); } -int GameMap_IterateCellBlockMobjs(GameMap* map, const GridmapBlock* blockCoords, +static int GameMap_IterateCellBlockMobjs(GameMap* map, const BlockmapCellBlock* cellBlock, int (*callback) (mobj_t*, void*), void* context) { bmapmoiterparams_t args; @@ -588,23 +591,23 @@ int GameMap_IterateCellBlockMobjs(GameMap* map, const GridmapBlock* blockCoords, args.func = callback; args.param = context; - return Blockmap_IterateCellBlockObjects(map->mobjBlockmap, blockCoords, + return Blockmap_IterateCellBlockObjects(map->mobjBlockmap, cellBlock, blockmapCellMobjsIterator, (void*) &args); } int GameMap_MobjsBoxIterator(GameMap* map, const AABoxf* box, int (*callback) (mobj_t*, void*), void* parameters) { - GridmapBlock blockCoords; + BlockmapCellBlock cellBlock; assert(map); - Blockmap_CellBlockCoords(map->mobjBlockmap, &blockCoords, box); - return GameMap_IterateCellBlockMobjs(map, &blockCoords, callback, parameters); + Blockmap_CellBlock(map->mobjBlockmap, &cellBlock, box); + return GameMap_IterateCellBlockMobjs(map, &cellBlock, callback, parameters); } -void GameMap_LinkLineDefInBlockmap(GameMap* map, LineDef* lineDef) +void GameMap_LinkLineDef(GameMap* map, LineDef* lineDef) { vec2_t origin, cellSize, cell, from, to; - GridmapBlock blockCoords; + BlockmapCellBlock cellBlock; Blockmap* blockmap; uint x, y; assert(map); @@ -624,10 +627,10 @@ void GameMap_LinkLineDefInBlockmap(GameMap* map, LineDef* lineDef) V2_Copy(cellSize, Blockmap_CellSize(blockmap)); // Determine the block of cells we'll be working within. - Blockmap_CellBlockCoords(blockmap, &blockCoords, &lineDef->aaBox); + Blockmap_CellBlock(blockmap, &cellBlock, &lineDef->aaBox); - for(y = blockCoords.minY; y <= blockCoords.maxY; ++y) - for(x = blockCoords.minX; x <= blockCoords.maxX; ++x) + for(y = cellBlock.minY; y <= cellBlock.maxY; ++y) + for(x = cellBlock.minX; x <= cellBlock.maxX; ++x) { if(lineDef->slopeType == ST_VERTICAL || lineDef->slopeType == ST_HORIZONTAL) { @@ -686,7 +689,7 @@ static int blockmapCellLinesIterator(void* object, void* context) return false; // Continue iteration. } -int GameMap_IterateCellLineDefs(GameMap* map, const uint coords[2], +static int GameMap_IterateCellLineDefs(GameMap* map, const_BlockmapCell cell, int (*callback) (LineDef*, void*), void* context) { bmapiterparams_t args; @@ -696,11 +699,11 @@ int GameMap_IterateCellLineDefs(GameMap* map, const uint coords[2], args.func = callback; args.param = context; - return Blockmap_IterateCellObjects(map->lineDefBlockmap, coords, + return Blockmap_IterateCellObjects(map->lineDefBlockmap, cell, blockmapCellLinesIterator, (void*)&args); } -int GameMap_IterateCellBlockLineDefs(GameMap* map, const GridmapBlock* blockCoords, +static int GameMap_IterateCellBlockLineDefs(GameMap* map, const BlockmapCellBlock* cellBlock, int (*callback) (LineDef*, void*), void* context) { bmapiterparams_t args; @@ -710,7 +713,7 @@ int GameMap_IterateCellBlockLineDefs(GameMap* map, const GridmapBlock* blockCoor args.func = callback; args.param = context; - return Blockmap_IterateCellBlockObjects(map->lineDefBlockmap, blockCoords, + return Blockmap_IterateCellBlockObjects(map->lineDefBlockmap, cellBlock, blockmapCellLinesIterator, (void*) &args); } @@ -726,10 +729,10 @@ int GameMap_LineDefIterator(GameMap* map, int (*callback) (LineDef*, void*), voi return false; // Continue iteration. } -void GameMap_LinkBspLeafInBlockmap(GameMap* map, BspLeaf* bspLeaf) +void GameMap_LinkBspLeaf(GameMap* map, BspLeaf* bspLeaf) { Blockmap* blockmap; - GridmapBlock blockCoords; + BlockmapCellBlock cellBlock; AABoxf aaBox; uint x, y; assert(map); @@ -749,10 +752,10 @@ void GameMap_LinkBspLeafInBlockmap(GameMap* map, BspLeaf* bspLeaf) aaBox.minY = bspLeaf->aaBox.minY; aaBox.maxX = bspLeaf->aaBox.maxX; aaBox.maxY = bspLeaf->aaBox.maxY; - Blockmap_CellBlockCoords(blockmap, &blockCoords, &aaBox); + Blockmap_CellBlock(blockmap, &cellBlock, &aaBox); - for(y = blockCoords.minY; y <= blockCoords.maxY; ++y) - for(x = blockCoords.minX; x <= blockCoords.maxX; ++x) + for(y = cellBlock.minY; y <= cellBlock.maxY; ++y) + for(x = cellBlock.minX; x <= cellBlock.maxX; ++x) { Blockmap_CreateCellAndLinkObjectXY(blockmap, x, y, bspLeaf); } @@ -799,7 +802,7 @@ static int blockmapCellBspLeafsIterator(void* object, void* context) return false; // Continue iteration. } -int GameMap_IterateCellBspLeafs(GameMap* map, const uint coords[2], +static int GameMap_IterateCellBspLeafs(GameMap* map, const_BlockmapCell cell, Sector* sector, const AABoxf* box, int localValidCount, int (*callback) (BspLeaf*, void*), void* context) { @@ -812,11 +815,11 @@ int GameMap_IterateCellBspLeafs(GameMap* map, const uint coords[2], args.sector = sector; args.box = box; - return Blockmap_IterateCellObjects(map->bspLeafBlockmap, coords, + return Blockmap_IterateCellObjects(map->bspLeafBlockmap, cell, blockmapCellBspLeafsIterator, (void*)&args); } -int GameMap_IterateCellBlockBspLeafs(GameMap* map, const GridmapBlock* blockCoords, +static int GameMap_IterateCellBlockBspLeafs(GameMap* map, const BlockmapCellBlock* cellBlock, Sector* sector, const AABoxf* box, int localValidCount, int (*callback) (BspLeaf*, void*), void* context) { @@ -829,7 +832,7 @@ int GameMap_IterateCellBlockBspLeafs(GameMap* map, const GridmapBlock* blockCoor args.sector = sector; args.box = box; - return Blockmap_IterateCellBlockObjects(map->bspLeafBlockmap, blockCoords, + return Blockmap_IterateCellBlockObjects(map->bspLeafBlockmap, cellBlock, blockmapCellBspLeafsIterator, (void*) &args); } @@ -837,14 +840,14 @@ int GameMap_BspLeafsBoxIterator(GameMap* map, const AABoxf* box, Sector* sector, int (*callback) (BspLeaf*, void*), void* parameters) { static int localValidCount = 0; - GridmapBlock blockCoords; + BlockmapCellBlock cellBlock; assert(map); // This is only used here. localValidCount++; - Blockmap_CellBlockCoords(map->bspLeafBlockmap, &blockCoords, box); - return GameMap_IterateCellBlockBspLeafs(map, &blockCoords, sector, box, + Blockmap_CellBlock(map->bspLeafBlockmap, &cellBlock, box); + return GameMap_IterateCellBlockBspLeafs(map, &cellBlock, sector, box, localValidCount, callback, parameters); } @@ -860,10 +863,10 @@ int GameMap_BspLeafIterator(GameMap* map, int (*callback) (BspLeaf*, void*), voi return false; // Continue iteration. } -void GameMap_LinkPolyobjInBlockmap(GameMap* map, Polyobj* po) +void GameMap_LinkPolyobj(GameMap* map, Polyobj* po) { Blockmap* blockmap; - GridmapBlock blockCoords; + BlockmapCellBlock cellBlock; uint x, y; assert(map); @@ -875,26 +878,26 @@ void GameMap_LinkPolyobjInBlockmap(GameMap* map, Polyobj* po) } blockmap = map->polyobjBlockmap; - Blockmap_CellBlockCoords(blockmap, &blockCoords, &po->aaBox); + Blockmap_CellBlock(blockmap, &cellBlock, &po->aaBox); - for(y = blockCoords.minY; y <= blockCoords.maxY; ++y) - for(x = blockCoords.minX; x <= blockCoords.maxX; ++x) + for(y = cellBlock.minY; y <= cellBlock.maxY; ++y) + for(x = cellBlock.minX; x <= cellBlock.maxX; ++x) { Blockmap_CreateCellAndLinkObjectXY(blockmap, x, y, po); } } -void GameMap_UnlinkPolyobjInBlockmap(GameMap* map, Polyobj* po) +void GameMap_UnlinkPolyobj(GameMap* map, Polyobj* po) { Blockmap* blockmap; - GridmapBlock blockCoords; + BlockmapCellBlock cellBlock; assert(map); if(!po) return; blockmap = map->polyobjBlockmap; - Blockmap_CellBlockCoords(map->polyobjBlockmap, &blockCoords, &po->aaBox); - Blockmap_UnlinkObjectInCellBlock(blockmap, &blockCoords, po); + Blockmap_CellBlock(map->polyobjBlockmap, &cellBlock, &po->aaBox); + Blockmap_UnlinkObjectInCellBlock(blockmap, &cellBlock, po); } typedef struct bmappoiterparams_s { @@ -921,7 +924,7 @@ static int blockmapCellPolyobjsIterator(void* object, void* context) return false; // Continue iteration. } -int GameMap_IterateCellPolyobjs(GameMap* map, const uint coords[2], +static int GameMap_IterateCellPolyobjs(GameMap* map, const_BlockmapCell cell, int (*callback) (Polyobj*, void*), void* context) { bmappoiterparams_t args; @@ -931,11 +934,11 @@ int GameMap_IterateCellPolyobjs(GameMap* map, const uint coords[2], args.func = callback; args.param = context; - return Blockmap_IterateCellObjects(map->polyobjBlockmap, coords, + return Blockmap_IterateCellObjects(map->polyobjBlockmap, cell, blockmapCellPolyobjsIterator, (void*)&args); } -int GameMap_IterateCellBlockPolyobjs(GameMap* map, const GridmapBlock* blockCoords, +static int GameMap_IterateCellBlockPolyobjs(GameMap* map, const BlockmapCellBlock* cellBlock, int (*callback) (Polyobj*, void*), void* context) { bmappoiterparams_t args; @@ -945,17 +948,17 @@ int GameMap_IterateCellBlockPolyobjs(GameMap* map, const GridmapBlock* blockCoor args.func = callback; args.param = context; - return Blockmap_IterateCellBlockObjects(map->polyobjBlockmap, blockCoords, + return Blockmap_IterateCellBlockObjects(map->polyobjBlockmap, cellBlock, blockmapCellPolyobjsIterator, (void*) &args); } int GameMap_PolyobjsBoxIterator(GameMap* map, const AABoxf* box, int (*callback) (struct polyobj_s*, void*), void* parameters) { - GridmapBlock blockCoords; + BlockmapCellBlock cellBlock; assert(map); - Blockmap_CellBlockCoords(map->polyobjBlockmap, &blockCoords, box); - return GameMap_IterateCellBlockPolyobjs(map, &blockCoords, callback, parameters); + Blockmap_CellBlock(map->polyobjBlockmap, &cellBlock, box); + return GameMap_IterateCellBlockPolyobjs(map, &cellBlock, callback, parameters); } int GameMap_PolyobjIterator(GameMap* map, int (*callback) (Polyobj*, void*), void* parameters) @@ -983,7 +986,7 @@ int PTR_PolyobjLines(void* object, void* context) return Polyobj_LineIterator(po, args->func, args->param); } -int GameMap_IterateCellPolyobjLineDefsIterator(GameMap* map, const uint coords[2], +static int GameMap_IterateCellPolyobjLineDefsIterator(GameMap* map, const_BlockmapCell cell, int (*callback) (LineDef*, void*), void* context) { bmappoiterparams_t args; @@ -997,11 +1000,11 @@ int GameMap_IterateCellPolyobjLineDefsIterator(GameMap* map, const uint coords[2 args.func = PTR_PolyobjLines; args.param = &poargs; - return Blockmap_IterateCellObjects(map->polyobjBlockmap, coords, + return Blockmap_IterateCellObjects(map->polyobjBlockmap, cell, blockmapCellPolyobjsIterator, &args); } -int GameMap_IterateCellBlockPolyobjLineDefs(GameMap* map, const GridmapBlock* blockCoords, +static int GameMap_IterateCellBlockPolyobjLineDefs(GameMap* map, const BlockmapCellBlock* cellBlock, int (*callback) (LineDef*, void*), void* context) { bmappoiterparams_t args; @@ -1015,26 +1018,26 @@ int GameMap_IterateCellBlockPolyobjLineDefs(GameMap* map, const GridmapBlock* bl args.func = PTR_PolyobjLines; args.param = &poargs; - return Blockmap_IterateCellBlockObjects(map->polyobjBlockmap, blockCoords, + return Blockmap_IterateCellBlockObjects(map->polyobjBlockmap, cellBlock, blockmapCellPolyobjsIterator, (void*) &args); } int GameMap_LineDefsBoxIterator(GameMap* map, const AABoxf* box, int (*callback) (LineDef*, void*), void* parameters) { - GridmapBlock blockCoords; + BlockmapCellBlock cellBlock; assert(map); - Blockmap_CellBlockCoords(map->lineDefBlockmap, &blockCoords, box); - return GameMap_IterateCellBlockLineDefs(map, &blockCoords, callback, parameters); + Blockmap_CellBlock(map->lineDefBlockmap, &cellBlock, box); + return GameMap_IterateCellBlockLineDefs(map, &cellBlock, callback, parameters); } int GameMap_PolyobjLinesBoxIterator(GameMap* map, const AABoxf* box, int (*callback) (LineDef*, void*), void* parameters) { - GridmapBlock blockCoords; + BlockmapCellBlock cellBlock; assert(map); - Blockmap_CellBlockCoords(map->polyobjBlockmap, &blockCoords, box); - return GameMap_IterateCellBlockPolyobjLineDefs(map, &blockCoords, callback, parameters); + Blockmap_CellBlock(map->polyobjBlockmap, &cellBlock, box); + return GameMap_IterateCellBlockPolyobjLineDefs(map, &cellBlock, callback, parameters); } /** @@ -1287,8 +1290,8 @@ static int traverseCellPath(GameMap* map, Blockmap* bmap, float const from_[2], } // Clipping already applied above, so we don't need to check it again... - Blockmap_CellCoords(bmap, fromBlock, from); - Blockmap_CellCoords(bmap, toBlock, to); + Blockmap_Cell(bmap, fromBlock, from); + Blockmap_Cell(bmap, toBlock, to); V2_Subtract(from, from, min); V2_Subtract(to, to, min); diff --git a/doomsday/engine/portable/src/gridmap.c b/doomsday/engine/portable/src/gridmap.c index b83a0aaa9f..25bcf7061e 100644 --- a/doomsday/engine/portable/src/gridmap.c +++ b/doomsday/engine/portable/src/gridmap.c @@ -52,10 +52,10 @@ typedef struct treecell_s void* userData; /// Origin of this cell in Gridmap space [x,y]. - uint origin[2]; + GridmapCoord origin[2]; /// Size of this cell in Gridmap space (width=height). - uint size; + GridmapCoord size; /// Child cells of this, one for each subquadrant. struct treecell_s* children[4]; @@ -68,7 +68,7 @@ typedef struct treecell_s struct gridmap_s { /// Dimensions of the space we are indexing (in cells). - uint dimensions[2]; + GridmapCoord dimensions[2]; /// Zone memory tag used for both the Gridmap and user data. int zoneTag; @@ -76,30 +76,30 @@ struct gridmap_s /// Size of the memory block to be allocated for each leaf. size_t sizeOfCell; - /// Root cell for our Quadtree. Allocated along with the Gridmap instance. + /// Root tree for our Quadtree. Allocated along with the Gridmap instance. TreeCell root; }; /** - * Initialize @a cell. Assumes that @a cell has not yet been initialized + * Initialize @a tree. Assumes that @a tree has not yet been initialized * (i.e., existing references to child cells will be overwritten). * - * @param cell TreeCell instance to be initialized. + * @param tree TreeCell instance to be initialized. * @param x X coordinate in Gridmap space. * @param y Y coordinate in Gridmap space. * @param size Size in Gridmap space units. * - * @return Same as @a cell for caller convenience. + * @return Same as @a tree for caller convenience. */ -static TreeCell* initCell(TreeCell* cell, uint x, uint y, uint size) +static TreeCell* initCell(TreeCell* tree, GridmapCoord x, GridmapCoord y, GridmapCoord size) { - assert(cell); - cell->origin[X] = x; - cell->origin[Y] = y; - cell->size = size; - cell->userData = NULL; - memset(cell->children, 0, sizeof cell->children); - return cell; + assert(tree); + tree->origin[X] = x; + tree->origin[Y] = y; + tree->size = size; + tree->userData = NULL; + memset(tree->children, 0, sizeof tree->children); + return tree; } /** @@ -112,38 +112,38 @@ static TreeCell* initCell(TreeCell* cell, uint x, uint y, uint size) * * @return Newly allocated and initialized TreeCell instance. */ -static TreeCell* newCell(uint x, uint y, uint size, int zoneTag) +static TreeCell* newCell(GridmapCoord x, GridmapCoord y, GridmapCoord size, int zoneTag) { - TreeCell* cell = Z_Malloc(sizeof *cell, zoneTag, NULL); - if(!cell) Con_Error("Gridmap::newCell: Failed on allocation of %lu bytes for new Cell.", (unsigned long) sizeof *cell); - return initCell(cell, x, y, size); + TreeCell* tree = Z_Malloc(sizeof *tree, zoneTag, NULL); + if(!tree) Con_Error("Gridmap::newCell: Failed on allocation of %lu bytes for new Cell.", (unsigned long) sizeof *tree); + return initCell(tree, x, y, size); } -static void deleteCell(TreeCell* cell) +static void deleteCell(TreeCell* tree) { - assert(cell); + assert(tree); // Deletion is a depth-first traversal. - if(cell->children[TOPLEFT]) deleteCell(cell->children[TOPLEFT]); - if(cell->children[TOPRIGHT]) deleteCell(cell->children[TOPRIGHT]); - if(cell->children[BOTTOMLEFT]) deleteCell(cell->children[BOTTOMLEFT]); - if(cell->children[BOTTOMRIGHT]) deleteCell(cell->children[BOTTOMRIGHT]); - if(cell->userData) Z_Free(cell->userData); - Z_Free(cell); + if(tree->children[TOPLEFT]) deleteCell(tree->children[TOPLEFT]); + if(tree->children[TOPRIGHT]) deleteCell(tree->children[TOPRIGHT]); + if(tree->children[BOTTOMLEFT]) deleteCell(tree->children[BOTTOMLEFT]); + if(tree->children[BOTTOMRIGHT]) deleteCell(tree->children[BOTTOMRIGHT]); + if(tree->userData) Z_Free(tree->userData); + Z_Free(tree); } -/// @return @c true= @a cell is a a leaf (i.e., equal to a unit in Gridmap space). -static boolean isLeaf(TreeCell* cell) +/// @return @c true= @a tree is a a leaf (i.e., equal to a unit in Gridmap space). +static boolean isLeaf(TreeCell* tree) { - assert(cell); - return cell->size == 1; + assert(tree); + return tree->size == 1; } /** - * Depth-first traversal of the children of this cell, making a callback + * Depth-first traversal of the children of this tree, making a callback * for each cell. Iteration ends when all selected cells have been visited * or a callback returns a non-zero value. * - * @param cell TreeCell to traverse. + * @param tree TreeCell to traverse. * @param leafOnly Caller is only interested in leaves. * @param callback Callback function. * @param parameters Passed to the callback. @@ -151,38 +151,38 @@ static boolean isLeaf(TreeCell* cell) * @return Zero iff iteration completed wholly, else the value returned by the * last callback made. */ -static int iterateCell(TreeCell* cell, boolean leafOnly, - int (C_DECL *callback) (TreeCell* cell, void* parameters), void* parameters) +static int iterateCell(TreeCell* tree, boolean leafOnly, + int (C_DECL *callback) (TreeCell* tree, void* parameters), void* parameters) { int result = false; // Continue traversal. - assert(cell && callback); + assert(tree && callback); - if(!isLeaf(cell)) + if(!isLeaf(tree)) { - if(cell->children[TOPLEFT]) + if(tree->children[TOPLEFT]) { - result = iterateCell(cell->children[TOPLEFT], leafOnly, callback, parameters); + result = iterateCell(tree->children[TOPLEFT], leafOnly, callback, parameters); if(result) return result; } - if(cell->children[TOPRIGHT]) + if(tree->children[TOPRIGHT]) { - result = iterateCell(cell->children[TOPRIGHT], leafOnly, callback, parameters); + result = iterateCell(tree->children[TOPRIGHT], leafOnly, callback, parameters); if(result) return result; } - if(cell->children[BOTTOMLEFT]) + if(tree->children[BOTTOMLEFT]) { - result = iterateCell(cell->children[BOTTOMLEFT], leafOnly, callback, parameters); + result = iterateCell(tree->children[BOTTOMLEFT], leafOnly, callback, parameters); if(result) return result; } - if(cell->children[BOTTOMRIGHT]) + if(tree->children[BOTTOMRIGHT]) { - result = iterateCell(cell->children[BOTTOMRIGHT], leafOnly, callback, parameters); + result = iterateCell(tree->children[BOTTOMRIGHT], leafOnly, callback, parameters); if(result) return result; } } - if(!leafOnly || isLeaf(cell)) + if(!leafOnly || isLeaf(tree)) { - result = callback(cell, parameters); + result = callback(tree, parameters); } return result; } @@ -190,7 +190,7 @@ static int iterateCell(TreeCell* cell, boolean leafOnly, static void deleteTree(Gridmap* gm) { assert(gm); - // The root cell is allocated along with Gridmap. + // The root tree is allocated along with Gridmap. if(gm->root.children[TOPLEFT]) deleteCell(gm->root.children[TOPLEFT]); if(gm->root.children[TOPRIGHT]) deleteCell(gm->root.children[TOPRIGHT]); if(gm->root.children[BOTTOMLEFT]) deleteCell(gm->root.children[BOTTOMLEFT]); @@ -198,81 +198,81 @@ static void deleteTree(Gridmap* gm) if(gm->root.userData) Z_Free(gm->root.userData); } -static TreeCell* findLeafDescend(Gridmap* gm, TreeCell* cell, uint x, uint y, boolean alloc) +static TreeCell* findLeafDescend(Gridmap* gm, TreeCell* tree, GridmapCoord x, GridmapCoord y, boolean alloc) { Quadrant q; - assert(cell); + assert(tree); - if(isLeaf(cell)) + if(isLeaf(tree)) { - return cell; + return tree; } // Into which quadrant do we need to descend? - if(x < cell->origin[X] + (cell->size >> 1)) + if(x < tree->origin[X] + (tree->size >> 1)) { - q = (y < cell->origin[Y] + (cell->size >> 1))? TOPLEFT : BOTTOMLEFT; + q = (y < tree->origin[Y] + (tree->size >> 1))? TOPLEFT : BOTTOMLEFT; } else { - q = (y < cell->origin[Y] + (cell->size >> 1))? TOPRIGHT : BOTTOMRIGHT; + q = (y < tree->origin[Y] + (tree->size >> 1))? TOPRIGHT : BOTTOMRIGHT; } // Has this quadrant been initialized yet? - if(!cell->children[q]) + if(!tree->children[q]) { - uint subOrigin[2], subSize; + GridmapCoord subOrigin[2], subSize; // Are we allocating cells? if(!alloc) return NULL; - // Subdivide this cell and construct the new. - subSize = cell->size >> 1; + // Subdivide this tree and construct the new. + subSize = tree->size >> 1; switch(q) { case TOPLEFT: - subOrigin[X] = cell->origin[X]; - subOrigin[Y] = cell->origin[Y]; + subOrigin[X] = tree->origin[X]; + subOrigin[Y] = tree->origin[Y]; break; case TOPRIGHT: - subOrigin[X] = cell->origin[X] + subSize; - subOrigin[Y] = cell->origin[Y]; + subOrigin[X] = tree->origin[X] + subSize; + subOrigin[Y] = tree->origin[Y]; break; case BOTTOMLEFT: - subOrigin[X] = cell->origin[X]; - subOrigin[Y] = cell->origin[Y] + subSize; + subOrigin[X] = tree->origin[X]; + subOrigin[Y] = tree->origin[Y] + subSize; break; case BOTTOMRIGHT: - subOrigin[X] = cell->origin[X] + subSize; - subOrigin[Y] = cell->origin[Y] + subSize; + subOrigin[X] = tree->origin[X] + subSize; + subOrigin[Y] = tree->origin[Y] + subSize; break; default: Con_Error("Gridmap::findUserDataAdr: Invalid quadrant %i.", (int) q); exit(1); // Unreachable. } - cell->children[q] = newCell(subOrigin[X], subOrigin[Y], subSize, gm->zoneTag); + tree->children[q] = newCell(subOrigin[X], subOrigin[Y], subSize, gm->zoneTag); } - return findLeafDescend(gm, cell->children[q], x, y, alloc); + return findLeafDescend(gm, tree->children[q], x, y, alloc); } -static TreeCell* findLeaf(Gridmap* gm, uint x, uint y, boolean alloc) +static TreeCell* findLeaf(Gridmap* gm, GridmapCoord x, GridmapCoord y, boolean alloc) { assert(gm); return findLeafDescend(gm, &gm->root, x, y, alloc); } -static uint ceilPow2(uint unit) +static GridmapCoord ceilPow2(GridmapCoord unit) { - uint cumul; + GridmapCoord cumul; for(cumul = 1; unit > cumul; cumul <<= 1); return cumul; } -Gridmap* Gridmap_New(uint width, uint height, size_t cellSize, int zoneTag) +Gridmap* Gridmap_New(GridmapCoord width, GridmapCoord height, size_t cellSize, int zoneTag) { Gridmap* gm = Z_Calloc(sizeof *gm, zoneTag, 0); - uint size; + GridmapCoord size; if(!gm) Con_Error("Gridmap::New: Failed on allocation of %lu bytes for new Gridmap.", (unsigned long) sizeof *gm); gm->dimensions[X] = width; @@ -294,19 +294,19 @@ void Gridmap_Delete(Gridmap* gm) Z_Free(gm); } -uint Gridmap_Width(const Gridmap* gm) +GridmapCoord Gridmap_Width(const Gridmap* gm) { assert(gm); return gm->dimensions[X]; } -uint Gridmap_Height(const Gridmap* gm) +GridmapCoord Gridmap_Height(const Gridmap* gm) { assert(gm); return gm->dimensions[Y]; } -void Gridmap_Size(const Gridmap* gm, uint widthHeight[2]) +void Gridmap_Size(const Gridmap* gm, GridmapCoord widthHeight[]) { assert(gm); if(!widthHeight) return; @@ -314,30 +314,33 @@ void Gridmap_Size(const Gridmap* gm, uint widthHeight[2]) widthHeight[Y] = gm->dimensions[Y]; } -void* Gridmap_CellXY(Gridmap* gm, uint x, uint y, boolean alloc) +void* Gridmap_Cell(Gridmap* gm, const_GridmapCell cell, boolean alloc) { - TreeCell* cell; + TreeCell* tree; assert(gm); // Outside our boundary? - if(x >= gm->dimensions[X] || y >= gm->dimensions[Y]) return NULL; + if(cell[X] >= gm->dimensions[X] || cell[Y] >= gm->dimensions[Y]) return NULL; // Try to locate this leaf (may fail if not present and we are // not allocating user data (there will be no corresponding cell)). - cell = findLeaf(gm, x, y, alloc); - if(!cell) return NULL; + tree = findLeaf(gm, cell[X], cell[Y], alloc); + if(!tree) return NULL; // Exisiting user data for this cell? - if(cell->userData) return cell->userData; + if(tree->userData) return tree->userData; // Allocate new user data? if(!alloc) return NULL; - return cell->userData = Z_Calloc(gm->sizeOfCell, gm->zoneTag, 0); + return tree->userData = Z_Calloc(gm->sizeOfCell, gm->zoneTag, 0); } -void* Gridmap_Cell(Gridmap* gm, uint const coords[2], boolean alloc) +void* Gridmap_CellXY(Gridmap* gm, GridmapCoord x, GridmapCoord y, boolean alloc) { - return Gridmap_CellXY(gm, coords[X], coords[Y], alloc); + GridmapCell cell; + cell[X] = x; + cell[Y] = y; + return Gridmap_Cell(gm, cell, alloc); } typedef struct { @@ -349,12 +352,12 @@ typedef struct { * Callback actioner. Executes the callback and then returns the result * to the current iteration to determine if it should continue. */ -static int actionCallback(TreeCell* cell, void* parameters) +static int actionCallback(TreeCell* tree, void* parameters) { actioncallback_paramaters_t* p = (actioncallback_paramaters_t*) parameters; - assert(cell && p); - if(cell->userData) - return p->callback(cell->userData, p->callbackParamaters); + assert(tree && p); + if(tree->userData) + return p->callback(tree->userData, p->callbackParamaters); return 0; // Continue traversal. } @@ -373,12 +376,12 @@ int Gridmap_Iterate(Gridmap* gm, Gridmap_IterateCallback callback) return Gridmap_Iterate2(gm, callback, NULL/*no params*/); } -int Gridmap_BlockIterate2(Gridmap* gm, const GridmapBlock* block_, +int Gridmap_BlockIterate2(Gridmap* gm, const GridmapCellBlock* block_, Gridmap_IterateCallback callback, void* parameters) { - GridmapBlock block; - TreeCell* cell; - uint x, y; + GridmapCellBlock block; + TreeCell* tree; + GridmapCoord x, y; int result; assert(gm); @@ -393,36 +396,36 @@ int Gridmap_BlockIterate2(Gridmap* gm, const GridmapBlock* block_, for(y = block.minY; y <= block.maxY; ++y) for(x = block.minX; x <= block.maxX; ++x) { - cell = findLeaf(gm, x, y, false); - if(!cell || !cell->userData) continue; + tree = findLeaf(gm, x, y, false); + if(!tree || !tree->userData) continue; - result = callback(cell->userData, parameters); + result = callback(tree->userData, parameters); if(result) return result; } return false; } -int Gridmap_BlockIterate(Gridmap* gm, const GridmapBlock* block, +int Gridmap_BlockIterate(Gridmap* gm, const GridmapCellBlock* block, Gridmap_IterateCallback callback) { - return Gridmap_BlockIterate2(gm, block, callback, NULL/*no params*/); + return Gridmap_BlockIterate2(gm, block, callback, NULL/*no parameters*/); } -int Gridmap_BlockXYIterate2(Gridmap* gm, uint minX, uint minY, uint maxX, uint maxY, - Gridmap_IterateCallback callback, void* parameters) +int Gridmap_BlockXYIterate2(Gridmap* gm, GridmapCoord minX, GridmapCoord minY, + GridmapCoord maxX, GridmapCoord maxY, Gridmap_IterateCallback callback, void* parameters) { - GridmapBlock block; + GridmapCellBlock block; GridmapBlock_SetCoordsXY(&block, minX, maxX, minY, maxY); return Gridmap_BlockIterate2(gm, &block, callback, parameters); } -int Gridmap_BlockXYIterate(Gridmap* gm, uint minX, uint minY, uint maxX, uint maxY, - Gridmap_IterateCallback callback) +int Gridmap_BlockXYIterate(Gridmap* gm, GridmapCoord minX, GridmapCoord minY, + GridmapCoord maxX, GridmapCoord maxY, Gridmap_IterateCallback callback) { - return Gridmap_BlockXYIterate2(gm, minX, minY, maxX, maxY, callback, NULL/*no params*/); + return Gridmap_BlockXYIterate2(gm, minX, minY, maxX, maxY, callback, NULL/*no parameters*/); } -boolean Gridmap_ClipBlock(Gridmap* gm, GridmapBlock* block) +boolean Gridmap_ClipBlock(Gridmap* gm, GridmapCellBlock* block) { boolean adjusted = false; assert(gm); @@ -452,41 +455,42 @@ boolean Gridmap_ClipBlock(Gridmap* gm, GridmapBlock* block) return adjusted; } -void GridmapBlock_SetCoords(GridmapBlock* block, uint const min[2], uint const max[2]) +void GridmapBlock_SetCoords(GridmapCellBlock* block, const_GridmapCell min, const_GridmapCell max) { assert(block); if(min) { - block->minX = min[0]; - block->minY = min[1]; + block->minX = min[X]; + block->minY = min[Y]; } if(max) { - block->maxX = max[0]; - block->maxY = max[1]; + block->maxX = max[X]; + block->maxY = max[Y]; } } -void GridmapBlock_SetCoordsXY(GridmapBlock* block, uint minX, uint minY, uint maxX, uint maxY) +void GridmapBlock_SetCoordsXY(GridmapCellBlock* block, GridmapCoord minX, GridmapCoord minY, + GridmapCoord maxX, GridmapCoord maxY) { - uint min[2], max[2]; - min[0] = minX; - min[1] = minY; - max[0] = maxX; - max[1] = maxY; + GridmapCoord min[2], max[2]; + min[X] = minX; + min[Y] = minY; + max[X] = maxX; + max[Y] = maxY; GridmapBlock_SetCoords(block, min, max); } #define UNIT_WIDTH 1 #define UNIT_HEIGHT 1 -static int drawCell(TreeCell* cell, void* parameters) +static int drawCell(TreeCell* tree, void* parameters) { vec2_t topLeft, bottomRight; - V2_Set(topLeft, UNIT_WIDTH * cell->origin[X], UNIT_HEIGHT * cell->origin[Y]); - V2_Set(bottomRight, UNIT_WIDTH * (cell->origin[X] + cell->size), - UNIT_HEIGHT * (cell->origin[Y] + cell->size)); + V2_Set(topLeft, UNIT_WIDTH * tree->origin[X], UNIT_HEIGHT * tree->origin[Y]); + V2_Set(bottomRight, UNIT_WIDTH * (tree->origin[X] + tree->size), + UNIT_HEIGHT * (tree->origin[Y] + tree->size)); glBegin(GL_LINE_LOOP); glVertex2fv((GLfloat*)topLeft); diff --git a/doomsday/engine/portable/src/p_maputil.c b/doomsday/engine/portable/src/p_maputil.c index f9624109fd..5d6413df1e 100644 --- a/doomsday/engine/portable/src/p_maputil.c +++ b/doomsday/engine/portable/src/p_maputil.c @@ -1000,14 +1000,14 @@ void P_LinkMobjInBlockmap(mobj_t* mo) { /// @fixme Do not assume mobj is from the current map. if(!theMap) return; - GameMap_LinkMobjInBlockmap(theMap, mo); + GameMap_LinkMobj(theMap, mo); } boolean P_UnlinkMobjFromBlockmap(mobj_t* mo) { /// @fixme Do not assume mobj is from the current map. if(!theMap) return false; - return GameMap_UnlinkMobjInBlockmap(theMap, mo); + return GameMap_UnlinkMobj(theMap, mo); } void P_LinkMobjToLineDefs(mobj_t* mo) diff --git a/doomsday/engine/portable/src/p_polyobjs.c b/doomsday/engine/portable/src/p_polyobjs.c index 75038710f8..b72b863b57 100644 --- a/doomsday/engine/portable/src/p_polyobjs.c +++ b/doomsday/engine/portable/src/p_polyobjs.c @@ -59,13 +59,13 @@ void P_PolyobjChanged(Polyobj* po) void P_PolyobjUnlink(Polyobj* po) { GameMap* map = theMap; /// @fixme Do not assume polyobj is from the CURRENT map. - GameMap_UnlinkPolyobjInBlockmap(map, po); + GameMap_UnlinkPolyobj(map, po); } void P_PolyobjLink(Polyobj* po) { GameMap* map = theMap; /// @fixme Do not assume polyobj is from the CURRENT map. - GameMap_LinkPolyobjInBlockmap(map, po); + GameMap_LinkPolyobj(map, po); } /// @note Part of the Doomsday public API