Skip to content

Commit

Permalink
Refactor|Blockmap|Gridmap: Gridmap, Blockmap now C++ classes; free'd …
Browse files Browse the repository at this point in the history
…with Map
  • Loading branch information
danij-deng committed Jun 11, 2013
1 parent 1f2d633 commit 9eb9a55
Show file tree
Hide file tree
Showing 10 changed files with 1,101 additions and 1,437 deletions.
379 changes: 201 additions & 178 deletions doomsday/client/include/gridmap.h

Large diffs are not rendered by default.

298 changes: 118 additions & 180 deletions doomsday/client/include/world/blockmap.h
@@ -1,6 +1,4 @@
/**
* @file blockmap.h
* Blockmap. @ingroup world
/** @file world/blockmap.h World map element blockmap.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
Expand All @@ -20,184 +18,124 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_MAP_BLOCKMAP_H
#define LIBDENG_MAP_BLOCKMAP_H

#include "dd_types.h"
#include <de/vector1.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;

#ifdef __cplusplus
extern "C" {
#endif

Blockmap* Blockmap_New(coord_t const min[2], coord_t const max[2], uint cellWidth, uint cellHeight);

/**
* @param blockmap Blockmap instance.
* @return "Origin" map space point for the Blockmap (minimal [x,y]).
*/
pcvec2d_t Blockmap_Origin(Blockmap* blockmap);

/**
* Retrieve the extremal map space points covered by the Blockmap.
*
* @param blockmap Blockmap instance.
*/
const AABoxd* Blockmap_Bounds(Blockmap* blockmap);
#ifndef DENG_WORLD_BLOCKMAP_H
#define DENG_WORLD_BLOCKMAP_H

/**
* @param blockmap Blockmap instance.
* @return Width of the Blockmap in cells.
*/
BlockmapCoord Blockmap_Width(Blockmap* blockmap);
#include <de/aabox.h>

/**
* @param blockmap Blockmap instance.
* @return Height of the Blockmap in cells.
*/
BlockmapCoord Blockmap_Height(Blockmap* blockmap);
#include <de/Vector>

/**
* Retrieve the size of the Blockmap in cells.
*
* @param blockmap Blockmap instance.
* @param widthHeight Size of the Blockmap [width,height] written here.
*/
void Blockmap_Size(Blockmap* blockmap, BlockmapCoord widthHeight[2]);

/**
* @param blockmap Blockmap instance.
* @return Width of a Blockmap cell in map space units.
*/
coord_t Blockmap_CellWidth(Blockmap* blockmap);

/**
* @param blockmap Blockmap instance.
* @return Height of a Blockmap cell in map space units.
*/
coord_t Blockmap_CellHeight(Blockmap* blockmap);

/**
* @param blockmap Blockmap instance.
* @return Size [width,height] of a Blockmap cell in map space units.
*/
pcvec2d_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.
*/
BlockmapCoord Blockmap_CellX(Blockmap* blockmap, coord_t 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 blockmap Blockmap instance.
* @param y Map space Y coordinate to be translated.
*
* @return Translated Blockmap cell Y coordinate.
*/
BlockmapCoord Blockmap_CellY(Blockmap* blockmap, coord_t y);

/**
* Same as @ref 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* blockmap, BlockmapCoord* outX, coord_t x);

/**
* Same as @ref Blockmap_CellY() with alternative semantics for when the caller
* needs to know if the coordinate specified was inside/outside the Blockmap.
*
* @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* blockmap, BlockmapCoord* outY, coord_t 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_Cell(Blockmap* blockmap, BlockmapCell cell, coord_t 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_CellBlock(Blockmap* blockmap, BlockmapCellBlock* cellBlock, const AABoxd* box);

/**
* Retrieve the number objects linked in the specified @a cell.
*
* @param blockmap Blockmap instance.
* @param cell Blockmap cell to lookup.
*
* @return Number of unique objects linked into the cell, or @c 0 if invalid.
*/
uint Blockmap_CellObjectCount(Blockmap* blockmap, const_BlockmapCell cell);
uint Blockmap_CellXYObjectCount(Blockmap* blockmap, BlockmapCoord x, BlockmapCoord y);

boolean Blockmap_CreateCellAndLinkObject(Blockmap* blockmap, const_BlockmapCell cell, void* object);

boolean Blockmap_CreateCellAndLinkObjectXY(Blockmap* blockmap, BlockmapCoord x, BlockmapCoord y, void* object);

boolean Blockmap_UnlinkObjectInCell(Blockmap* blockmap, const_BlockmapCell cell, void* object);

boolean Blockmap_UnlinkObjectInCellXY(Blockmap* blockmap, BlockmapCoord x, BlockmapCoord y, void* object);

void Blockmap_UnlinkObjectInCellBlock(Blockmap* blockmap, const BlockmapCellBlock* blockCoords, void* object);

int Blockmap_IterateCellObjects(Blockmap* blockmap, const_BlockmapCell cell,
int (*callback) (void* object, void* context), void* context);

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

/**
* Retrieve an immutable pointer to the underlying Gridmap instance (mainly for
* for debug purposes).
*/
const Gridmap* Blockmap_Gridmap(Blockmap* blockmap);

#ifdef __cplusplus
} // extern "C"
#endif
#include "gridmap.h"

#endif // LIBDENG_MAP_BLOCKMAP_H
namespace de {

/**
* @ingroup world
*/
class Blockmap
{
public:
typedef Gridmap::Cell Cell;
typedef Gridmap::CellBlock CellBlock;

public:
/**
* @param bounds
* @param cellDimensions Dimensions of a cell in map coordinate space units.
*/
Blockmap(AABoxd const &bounds, Vector2ui const &cellDimensions);

/**
* Returns the origin of the blockmap in the map coordinate space.
*/
Vector2d origin() const;

/**
* Returns the bounds of the blockmap in the map coordinate space.
*/
AABoxd const &bounds() const;

/**
* Returns the dimensions of the blockmap in cells.
*/
Cell const &dimensions() const;

/**
* Returns the width of the blockmap in cells.
*/
inline uint width() const { return dimensions().x; }

/**
* Returns the height of the blockmap in cells.
*/
inline uint height() const { return dimensions().y; }

/**
* Returns the dimension of a cell in map coordinate space units.
*/
Vector2d const &cellDimensions() const;

/**
* Returns the width of a cell in map coordinate space units.
*/
inline coord_t cellWidth() const { return cellDimensions().x; }

/**
* Returns the height of a cell in map coordinate space units.
*/
inline coord_t cellHeight() const { return cellDimensions().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 point Map coordinate space point to be translated.
* @param didClip Set to @c true iff clamping was necessary.
*/
Cell toCell(Vector2d const &point, bool *didClip = 0) const;

/**
* 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 box Map space coordinates to translate.
* @param didClip Set to @c true iff clamping was necessary.
*/
CellBlock toCellBlock(AABoxd const &box, bool *didClip = 0) const;

/**
* Retrieve the number of elements linked in the specified @a cell.
*
* @param cell Cell to lookup.
*
* @return Number of unique objects linked into the cell, or @c 0 if invalid.
*/
int cellElementCount(Cell const &cell) const;

bool link(Cell const &cell, void *elem);

bool link(CellBlock const &cellBlock, void *elem);

bool unlink(Cell const &cell, void *elem);

bool unlink(CellBlock const &cellBlock, void *elem);

int iterate(Cell const &cell, int (*callback) (void *elem, void *context), void *context);

int iterate(CellBlock const &cellBlock, int (*callback) (void *elem, void *context), void *context);

/**
* Retrieve an immutable pointer to the underlying Gridmap instance
* (primarily intended for debug purposes).
*/
Gridmap const &gridmap() const;

private:
DENG2_PRIVATE(d)
};

} //namespace de

#endif // DENG_WORLD_BLOCKMAP_H
10 changes: 8 additions & 2 deletions doomsday/client/include/world/line.h
Expand Up @@ -678,11 +678,17 @@ class Line : public de::MapElement
return V2d_PointOnLineSide(point, fromV1, directionV1);
}

/// @copydoc pointOnSide()
inline coord_t pointOnSide(de::Vector2d const &point) const
{
coord_t pointV1[2] = { point.x, point.y };
return pointOnSide(pointV1);
}

/// @copydoc pointOnSide()
inline coord_t pointOnSide(coord_t x, coord_t y) const
{
coord_t point[2] = { x, y };
return pointOnSide(point);
return pointOnSide(de::Vector2d(x, y));
}

/**
Expand Down
12 changes: 6 additions & 6 deletions doomsday/client/include/world/map.h
Expand Up @@ -68,6 +68,7 @@ struct clpolyobj_s;

namespace de {

class Blockmap;
class EntityDatabase;
#ifdef __CLIENT__
class LightGrid;
Expand Down Expand Up @@ -102,7 +103,7 @@ class Map
typedef QSet<Plane *> PlaneSet;
typedef QSet<Surface *> SurfaceSet;

public:
public: /// @todo make private:
Uri _uri;
char _oldUniqueId[256];

Expand Down Expand Up @@ -131,7 +132,6 @@ class Map
struct clpolyobj_s *clActivePolyobjs[CLIENT_MAX_MOVERS];
#endif

public:
nodepile_t mobjNodes, lineNodes; // All kinds of wacky links.
nodeindex_t *lineLinks; // Indices to roots.

Expand Down Expand Up @@ -308,22 +308,22 @@ class Map
/**
* Provides access to the mobj blockmap.
*/
struct blockmap_s /*const*/ *mobjBlockmap() const;
Blockmap /*const*/ *mobjBlockmap() const;

/**
* Provides access to the polyobj blockmap.
*/
struct blockmap_s /*const*/ *polyobjBlockmap() const;
Blockmap /*const*/ *polyobjBlockmap() const;

/**
* Provides access to the line blockmap.
*/
struct blockmap_s /*const*/ *lineBlockmap() const;
Blockmap /*const*/ *lineBlockmap() const;

/**
* Provides access to the BSP leaf blockmap.
*/
struct blockmap_s /*const*/ *bspLeafBlockmap() const;
Blockmap /*const*/ *bspLeafBlockmap() const;

int mobjsBoxIterator(AABoxd const &box,
int (*callback) (struct mobj_s *, void *), void *parameters = 0) const;
Expand Down

0 comments on commit 9eb9a55

Please sign in to comment.