From 4c8f9bd045eb8d7f54a2530830b2da2fa1bc88f1 Mon Sep 17 00:00:00 2001 From: danij Date: Sat, 10 Mar 2012 21:44:40 +0000 Subject: [PATCH] Refactor|Blockmap: Made const various Blockmap function arguments --- doomsday/engine/portable/include/blockmap.h | 8 ++-- doomsday/engine/portable/src/blockmap.c | 46 +++++++++---------- doomsday/engine/portable/src/blockmapvisual.c | 12 ++--- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/doomsday/engine/portable/include/blockmap.h b/doomsday/engine/portable/include/blockmap.h index 9635dd3584..bada028a2d 100644 --- a/doomsday/engine/portable/include/blockmap.h +++ b/doomsday/engine/portable/include/blockmap.h @@ -117,17 +117,17 @@ boolean Blockmap_CellCoords(Blockmap* blockmap, uint coords[2], float const pos[ */ boolean Blockmap_CellBlockCoords(Blockmap* blockmap, GridmapBlock* blockCoords, const AABoxf* box); -boolean Blockmap_CreateCellAndLinkObject(Blockmap* blockmap, uint coords[2], void* object); +boolean Blockmap_CreateCellAndLinkObject(Blockmap* blockmap, uint const coords[2], void* object); boolean Blockmap_CreateCellAndLinkObjectXY(Blockmap* blockmap, uint x, uint y, void* object); -boolean Blockmap_UnlinkObjectInCell(Blockmap* blockmap, uint coords[2], void* object); +boolean Blockmap_UnlinkObjectInCell(Blockmap* blockmap, uint const coords[2], void* object); boolean Blockmap_UnlinkObjectInCellXY(Blockmap* blockmap, uint x, uint y, void* object); -void Blockmap_UnlinkObjectInCellBlock(Blockmap* blockmap, GridmapBlock* blockCoords, void* object); +void Blockmap_UnlinkObjectInCellBlock(Blockmap* blockmap, const GridmapBlock* blockCoords, void* object); -int Blockmap_IterateCellObjects(Blockmap* blockmap, const uint coords[2], +int Blockmap_IterateCellObjects(Blockmap* blockmap, uint const coords[2], int (*callback) (void* object, void* context), void* context); int Blockmap_IterateCellBlockObjects(Blockmap* blockmap, const GridmapBlock* blockCoords, diff --git a/doomsday/engine/portable/src/blockmap.c b/doomsday/engine/portable/src/blockmap.c index ea3128aae9..2cbd9b107e 100644 --- a/doomsday/engine/portable/src/blockmap.c +++ b/doomsday/engine/portable/src/blockmap.c @@ -51,6 +51,25 @@ struct blockmap_s Gridmap* gridmap; }; +Blockmap* Blockmap_New(const pvec2_t min, const pvec2_t max, uint cellWidth, uint cellHeight) +{ + Blockmap* bm = Z_Calloc(sizeof *bm, PU_MAPSTATIC, 0); + uint width, height; + if(!bm) Con_Error("Blockmap::New: Failed on allocation of %lu bytes for new Blockmap.", (unsigned long) sizeof *bm); + + V2_Copy(bm->bounds.min, min); + V2_Copy(bm->bounds.max, max); + bm->cellSize[VX] = cellWidth; + bm->cellSize[VY] = cellHeight; + + 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); + + VERBOSE( Con_Message("Blockmap::New: Width:%u Height:%u\n", width, height) ) + return bm; +} + uint Blockmap_CellX(Blockmap* bm, float x) { uint result; @@ -133,25 +152,6 @@ boolean Blockmap_CellBlockCoords(Blockmap* bm, GridmapBlock* blockCoords, const return false; } -Blockmap* Blockmap_New(const pvec2_t min, const pvec2_t max, uint cellWidth, uint cellHeight) -{ - Blockmap* bm = Z_Calloc(sizeof *bm, PU_MAPSTATIC, 0); - uint width, height; - if(!bm) Con_Error("Blockmap::New: Failed on allocation of %lu bytes for new Blockmap.", (unsigned long) sizeof *bm); - - V2_Copy(bm->bounds.min, min); - V2_Copy(bm->bounds.max, max); - bm->cellSize[VX] = cellWidth; - bm->cellSize[VY] = cellHeight; - - 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); - - VERBOSE( Con_Message("Blockmap::New: Width:%u Height:%u\n", width, height) ) - return bm; -} - const pvec2_t Blockmap_Origin(Blockmap* bm) { assert(bm); @@ -282,13 +282,13 @@ boolean Blockmap_CreateCellAndLinkObjectXY(Blockmap* blockmap, uint x, uint y, v return true; // Link added. } -boolean Blockmap_CreateCellAndLinkObject(Blockmap* blockmap, uint coords[2], void* object) +boolean Blockmap_CreateCellAndLinkObject(Blockmap* blockmap, uint const coords[2], void* object) { assert(coords); return Blockmap_CreateCellAndLinkObjectXY(blockmap, coords[VX], coords[VY], object); } -boolean Blockmap_UnlinkObjectInCell(Blockmap* blockmap, uint coords[2], void* object) +boolean Blockmap_UnlinkObjectInCell(Blockmap* blockmap, uint const coords[2], void* object) { boolean unlinked = false; BlockmapCell* cell; @@ -310,7 +310,7 @@ boolean Blockmap_UnlinkObjectInCellXY(Blockmap* blockmap, uint x, uint y, void* return Blockmap_UnlinkObjectInCell(blockmap, coords, object); } -void Blockmap_UnlinkObjectInCellBlock(Blockmap* blockmap, GridmapBlock* blockCoords, void* object) +void Blockmap_UnlinkObjectInCellBlock(Blockmap* blockmap, const GridmapBlock* blockCoords, void* object) { assert(blockmap); if(!blockCoords) return; @@ -340,7 +340,7 @@ int BlockmapCell_IterateObjects(BlockmapCell* cell, return false; // Continue iteration. } -int Blockmap_IterateCellObjects(Blockmap* blockmap, const uint coords[2], +int Blockmap_IterateCellObjects(Blockmap* blockmap, uint const coords[2], int (*callback) (void* object, void* context), void* context) { BlockmapCell* cell; diff --git a/doomsday/engine/portable/src/blockmapvisual.c b/doomsday/engine/portable/src/blockmapvisual.c index 82fc2ebbf8..e945502d29 100644 --- a/doomsday/engine/portable/src/blockmapvisual.c +++ b/doomsday/engine/portable/src/blockmapvisual.c @@ -338,7 +338,7 @@ static int countCellObject(void* object, void* paramaters) return false; // Continue iteration. } -static void drawLineDefCellInfoBox(Blockmap* blockmap, const Point2Raw* origin, uint coords[2]) +static void drawLineDefCellInfoBox(Blockmap* blockmap, const Point2Raw* origin, uint const coords[2]) { uint count = 0; char info[160]; @@ -350,7 +350,7 @@ static void drawLineDefCellInfoBox(Blockmap* blockmap, const Point2Raw* origin, drawCellInfo(origin, info); } -static void drawMobjCellInfoBox(Blockmap* blockmap, const Point2Raw* origin, uint coords[2]) +static void drawMobjCellInfoBox(Blockmap* blockmap, const Point2Raw* origin, uint const coords[2]) { uint count = 0; char info[160]; @@ -362,7 +362,7 @@ static void drawMobjCellInfoBox(Blockmap* blockmap, const Point2Raw* origin, uin drawCellInfo(origin, info); } -static void drawPolyobjCellInfoBox(Blockmap* blockmap, const Point2Raw* origin, uint coords[2]) +static void drawPolyobjCellInfoBox(Blockmap* blockmap, const Point2Raw* origin, uint const coords[2]) { uint count = 0; char info[160]; @@ -374,7 +374,7 @@ static void drawPolyobjCellInfoBox(Blockmap* blockmap, const Point2Raw* origin, drawCellInfo(origin, info); } -static void drawBspLeafCellInfoBox(Blockmap* blockmap, const Point2Raw* origin, uint coords[2]) +static void drawBspLeafCellInfoBox(Blockmap* blockmap, const Point2Raw* origin, uint const coords[2]) { uint count = 0; char info[160]; @@ -392,7 +392,7 @@ static void drawBspLeafCellInfoBox(Blockmap* blockmap, const Point2Raw* origin, * @param cellDrawer Blockmap cell content drawing callback. Can be @a NULL. */ static void rendBlockmap(Blockmap* blockmap, mobj_t* followMobj, - int (*cellDrawer) (void* cellPtr, void* paramaters)) + int (*cellDrawer) (Blockmap* blockmap, uint const coords[2], void* paramaters)) { uint x, y, vCoords[2]; GridmapBlock vBlockCoords; @@ -573,7 +573,7 @@ void Rend_BlockmapDebug(void) { #if 0 int (*cellDrawer) (void* cellPtr, void* paramaters); - void (*cellInfoDrawer) (Blockmap* blockmap, const Point2Raw* origin, uint coords[2]); + void (*cellInfoDrawer) (Blockmap* blockmap, const Point2Raw* origin, uint const coords[2]); mobj_t* followMobj = NULL; Blockmap* blockmap; Point2Raw origin;