Skip to content

Commit

Permalink
Refactor|Blockmap: Made const various Blockmap function arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 10, 2012
1 parent ec79a14 commit 4c8f9bd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
8 changes: 4 additions & 4 deletions doomsday/engine/portable/include/blockmap.h
Expand Up @@ -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,
Expand Down
46 changes: 23 additions & 23 deletions doomsday/engine/portable/src/blockmap.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions doomsday/engine/portable/src/blockmapvisual.c
Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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];
Expand All @@ -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];
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4c8f9bd

Please sign in to comment.