Skip to content

Commit

Permalink
Refactor: Moved Blockmap class definition into blockmap.h
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 4, 2012
1 parent 845e09e commit 129d3bf
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 107 deletions.
1 change: 1 addition & 0 deletions doomsday/engine/engine.pro
Expand Up @@ -116,6 +116,7 @@ DENG_HEADERS = \
portable/include/abstractresource.h \
portable/include/audiodriver.h \
portable/include/bitmapfont.h \
portable/include/blockmap.h \
portable/include/blockmapvisual.h \
portable/include/blockset.h \
portable/include/bsp_edge.h \
Expand Down
136 changes: 136 additions & 0 deletions doomsday/engine/portable/include/blockmap.h
@@ -0,0 +1,136 @@
/**
* @file blockmap.h
* Blockmap. @ingroup map
*
* @authors Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2012 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_MAP_BLOCKMAP_H
#define LIBDENG_MAP_BLOCKMAP_H

#include "dd_types.h"
#include "m_vector.h"
#include "p_mapdata.h"
#include "m_gridmap.h"

struct blockmap_s; // The Blockmap instance (opaque).
typedef struct blockmap_s Blockmap;

Blockmap* Blockmap_New(const pvec2_t min, const pvec2_t max, uint cellWidth, uint cellHeight);

/**
* @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.
*/
const AABoxf* Blockmap_Bounds(Blockmap* blockmap);

/// @return Width of the Blockmap in cells.
uint Blockmap_Width(Blockmap* blockmap);

/// @return Height of the Blockmap in cells.
uint 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]);

/// @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.
float Blockmap_CellHeight(Blockmap* blockmap);

/// @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.
*/
uint 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.
*/
uint 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);

/**
* 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.
* @return @c true iff clamping was necessary.
*/
boolean Blockmap_ClipCellY(Blockmap* bm, uint* 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.
*
* @return @c true iff clamping was necessary.
*/
boolean Blockmap_CellCoords(Blockmap* blockmap, uint coords[2], 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.
*
* @return @c true iff Clamping was necessary.
*/
boolean Blockmap_CellBlockCoords(Blockmap* blockmap, GridmapBlock* blockCoords, const AABoxf* box);

boolean Blockmap_CreateCellAndLinkObject(Blockmap* blockmap, uint 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_UnlinkObjectInCellXY(Blockmap* blockmap, uint x, uint y, void* object);

void Blockmap_UnlinkObjectInCellBlock(Blockmap* blockmap, GridmapBlock* blockCoords, void* object);

int Blockmap_IterateCellObjects(Blockmap* blockmap, const uint coords[2],
int (*callback) (void* object, void* context), void* context);

int Blockmap_IterateCellBlockObjects(Blockmap* blockmap, const GridmapBlock* blockCoords,
int (*callback) (void* object, void* context), void* context);

#endif /// LIBDENG_MAP_BLOCKMAP_H
108 changes: 1 addition & 107 deletions doomsday/engine/portable/include/p_mapdata.h
Expand Up @@ -123,113 +123,7 @@ typedef struct biassurface_s {
struct biassurface_s* next;
} biassurface_t;

#include "m_gridmap.h"

struct blockmap_s; // The Blockmap instance (opaque).
typedef struct blockmap_s Blockmap;

Blockmap* Blockmap_New(const pvec2_t min, const pvec2_t max, uint cellWidth, uint cellHeight);

/**
* @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.
*/
const AABoxf* Blockmap_Bounds(Blockmap* blockmap);

/// @return Width of the Blockmap in cells.
uint Blockmap_Width(Blockmap* blockmap);

/// @return Height of the Blockmap in cells.
uint 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]);

/// @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.
float Blockmap_CellHeight(Blockmap* blockmap);

/// @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.
*/
uint 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.
*/
uint 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);

/**
* 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.
* @return @c true iff clamping was necessary.
*/
boolean Blockmap_ClipCellY(Blockmap* bm, uint* 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.
*
* @return @c true iff clamping was necessary.
*/
boolean Blockmap_CellCoords(Blockmap* blockmap, uint coords[2], 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.
*
* @return @c true iff Clamping was necessary.
*/
boolean Blockmap_CellBlockCoords(Blockmap* blockmap, GridmapBlock* blockCoords, const AABoxf* box);

boolean Blockmap_CreateCellAndLinkObject(Blockmap* blockmap, uint 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_UnlinkObjectInCellXY(Blockmap* blockmap, uint x, uint y, void* object);

void Blockmap_UnlinkObjectInCellBlock(Blockmap* blockmap, GridmapBlock* blockCoords, void* object);

int Blockmap_IterateCellObjects(Blockmap* blockmap, const uint coords[2],
int (*callback) (void* object, void* context), void* context);

int Blockmap_IterateCellBlockObjects(Blockmap* blockmap, const GridmapBlock* blockCoords,
int (*callback) (void* object, void* context), void* context);

#include "blockmap.h"
#include "p_polyob.h"
#include "p_maptypes.h"

Expand Down

0 comments on commit 129d3bf

Please sign in to comment.