Skip to content

Commit

Permalink
Refactor: Made bspleaf_s an opaque type, moved members to BspLeaf class
Browse files Browse the repository at this point in the history
Also updated BspLeaf_New() and BspLeaf_Delete(). In the future all
the functions will become C++ methods of the class.
  • Loading branch information
skyjake committed Jan 14, 2013
1 parent 074b567 commit b187ba8
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 58 deletions.
17 changes: 5 additions & 12 deletions doomsday/engine/api/api_map.h
Expand Up @@ -106,15 +106,6 @@

#define DMT_BSPNODE_CHILDREN DDVT_PTR

/*
#if defined __cplusplus && defined __DOOMSDAY__
class LineDef;
class SideDef;
class Sector;
class Vertex;
#endif
*/

struct intercept_s;

/**
Expand Down Expand Up @@ -149,8 +140,10 @@ typedef struct plane_s Plane;

#elif defined __cplusplus

// Foward declarations.
class LineDef;
class Sector;
class BspLeaf;

#endif

Expand Down Expand Up @@ -282,7 +275,7 @@ DENG_API_TYPEDEF(Map)

// BSP Leaves

struct bspleaf_s* (*BL_AtPoint)(coord_t const point[2]);
BspLeaf* (*BL_AtPoint)(coord_t const point[2]);

/**
* Determine the BSP leaf on the back side of the BS partition that lies in
Expand All @@ -296,7 +289,7 @@ DENG_API_TYPEDEF(Map)
*
* @return BspLeaf instance for that BSP node's leaf.
*/
struct bspleaf_s* (*BL_AtPointXY)(coord_t x, coord_t y);
BspLeaf* (*BL_AtPointXY)(coord_t x, coord_t y);

// Iterators

Expand All @@ -319,7 +312,7 @@ DENG_API_TYPEDEF(Map)
*/
int (*Box_PolyobjLinesIterator)(const AABoxd* box, int (*callback) (LineDef*, void*), void* parameters);

int (*Box_BspLeafsIterator)(const AABoxd* box, Sector* sector, int (*callback) (struct bspleaf_s*, void*), void* parameters);
int (*Box_BspLeafsIterator)(const AABoxd* box, Sector* sector, int (*callback) (BspLeaf*, void*), void* parameters);
int (*Box_PolyobjsIterator)(const AABoxd* box, int (*callback) (struct polyobj_s*, void*), void* parameters);
int (*PathTraverse2)(coord_t const from[2], coord_t const to[2], int flags, int (*callback) (const struct intercept_s*, void* paramaters), void* parameters);
int (*PathTraverse)(coord_t const from[2], coord_t const to[2], int flags, int (*callback) (const struct intercept_s*, void* paramaters)/*parameters=NULL*/);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -736,7 +736,7 @@ enum { MX, MY, MZ };
nodeindex_t lineRoot; /* lines to which this is linked */ \
struct mobj_s* sNext, **sPrev; /* links in sector (if needed) */ \
\
struct bspleaf_s* bspLeaf; /* bspLeaf in which this resides */ \
BspLeaf *bspLeaf; /* bspLeaf in which this resides */ \
coord_t mom[3]; \
angle_t angle; \
spritenum_t sprite; /* used to find patch_t and flip value */ \
Expand Down Expand Up @@ -780,7 +780,7 @@ typedef struct povertex_s {
#define DD_BASE_POLYOBJ_ELEMENTS() \
DD_BASE_DDMOBJ_ELEMENTS() \
\
struct bspleaf_s* bspLeaf; /* bspLeaf in which this resides */ \
BspLeaf *bspLeaf; /* bspLeaf in which this resides */ \
unsigned int idx; /* Idx of polyobject. */ \
int tag; /* Reference tag. */ \
int validCount; \
Expand Down
8 changes: 1 addition & 7 deletions doomsday/engine/api/dd_types.h
Expand Up @@ -62,15 +62,9 @@ typedef char filename_t[FILENAME_T_MAXLEN];

typedef void (*con_textfilter_t) (char* text);

// Forward declarations for map data types. The contents of these structs is
// declared in p_maptypes.h.
// Forward declarations for map data types.
struct bspnode_s;
//struct vertex_s;
//struct linedef_s;
struct side_s;
struct hedge_s;
struct bspleaf_s;
//struct sector_s;
struct polyblock_s;
struct polyobj_s;
struct plane_s;
Expand Down
12 changes: 9 additions & 3 deletions doomsday/engine/include/map/bspleaf.h
Expand Up @@ -27,6 +27,7 @@
# error "map/bspleaf.h requires C++"
#endif

#include "MapElement"
#include "resource/r_data.h"
#include "render/rend_bias.h"
#include "p_mapdata.h"
Expand All @@ -42,8 +43,9 @@

class Sector;

typedef struct bspleaf_s {
runtime_mapdata_header_t header;
class BspLeaf : public de::MapElement
{
public:
struct hedge_s* hedge; /// First HEdge in this leaf.
int flags; /// @ref bspLeafFlags.
uint index; /// Unique. Set when saving the BSP.
Expand All @@ -59,7 +61,11 @@ typedef struct bspleaf_s {
coord_t worldGridOffset[2]; /// Offset to align the top left of materials in the built geometry to the map coordinate space grid.
struct biassurface_s** bsuf; /// [sector->planeCount] size.
unsigned int reverb[NUM_REVERB_DATA];
} BspLeaf;

public:
BspLeaf();
~BspLeaf();
};

BspLeaf* BspLeaf_New(void);

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/include/map/hedge.h
Expand Up @@ -67,7 +67,7 @@ typedef struct hedge_s {
// is always one-to-one -- if one of the half-edges is split, the twin
// must also be split.
struct hedge_s* twin;
struct bspleaf_s* bspLeaf;
BspLeaf* bspLeaf;

LineDef* lineDef;
Sector *sector;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/include/map/sector.h
Expand Up @@ -105,9 +105,9 @@ class Sector : public de::MapElement
unsigned int lineDefCount;
LineDef** lineDefs; // [lineDefCount+1] size.
unsigned int bspLeafCount;
struct bspleaf_s** bspLeafs; // [bspLeafCount+1] size.
BspLeaf** bspLeafs; // [bspLeafCount+1] size.
unsigned int numReverbBspLeafAttributors;
struct bspleaf_s** reverbBspLeafs; // [numReverbBspLeafAttributors] size.
BspLeaf** reverbBspLeafs; // [numReverbBspLeafAttributors] size.
ddmobj_base_t base;
unsigned int planeCount;
struct plane_s** planes; // [planeCount+1] size.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/include/render/r_things.h
Expand Up @@ -100,7 +100,7 @@ typedef struct rendspriteparams_s {
uint vLightListIdx;

// Misc
struct bspleaf_s *bspLeaf;
BspLeaf *bspLeaf;
} rendspriteparams_t;

/** @name rendFlareFlags */
Expand Down
79 changes: 49 additions & 30 deletions doomsday/engine/src/map/bspleaf.cpp
Expand Up @@ -27,66 +27,85 @@
#include "de_play.h"
#include "m_misc.h"

BspLeaf* BspLeaf_New(void)
BspLeaf::BspLeaf() : de::MapElement(DMU_BSPLEAF)
{
BspLeaf* leaf = static_cast<BspLeaf*>(Z_Calloc(sizeof(*leaf), PU_MAP, 0));
leaf->header.type = DMU_BSPLEAF;
leaf->flags |= BLF_UPDATE_FANBASE;
return leaf;
hedge = 0;
flags = 0;
index = 0;
addSpriteCount = 0;
validCount = 0;
hedgeCount = 0;
sector = 0;
polyObj = 0;
fanBase = 0;
shadows = 0;
memset(&aaBox, 0, sizeof(aaBox));
memset(midPoint, 0, sizeof(midPoint));
memset(worldGridOffset, 0, sizeof(worldGridOffset));
bsuf = 0;
memset(reverb, 0, sizeof(reverb));
}

void BspLeaf_Delete(BspLeaf* leaf)
BspLeaf::~BspLeaf()
{
Q_ASSERT(leaf);

if(leaf->bsuf)
if(bsuf)
{
Sector* sec = leaf->sector;
for(uint i = 0; i < sec->planeCount; ++i)
for(uint i = 0; i < sector->planeCount; ++i)
{
SB_DestroySurface(leaf->bsuf[i]);
SB_DestroySurface(bsuf[i]);
}
Z_Free(leaf->bsuf);
Z_Free(bsuf);
}

// Clear the HEdges.
if(leaf->hedge)
if(hedge)
{
HEdge* hedge = leaf->hedge;
if(hedge->next == hedge)
HEdge *he = hedge;
if(he->next == he)
{
HEdge_Delete(hedge);
HEdge_Delete(he);
}
else
{
// Break the ring, if linked.
if(hedge->prev)
if(he->prev)
{
hedge->prev->next = NULL;
he->prev->next = NULL;
}

while(hedge)
while(he)
{
HEdge* next = hedge->next;
HEdge_Delete(hedge);
hedge = next;
HEdge *next = he->next;
HEdge_Delete(he);
he = next;
}
}
}
}

BspLeaf* BspLeaf_New(void)
{
BspLeaf* leaf = new BspLeaf;
//leaf->header.type = DMU_BSPLEAF;
leaf->flags |= BLF_UPDATE_FANBASE;
return leaf;
}

Z_Free(leaf);
void BspLeaf_Delete(BspLeaf* leaf)
{
delete leaf;
}

biassurface_t* BspLeaf_BiasSurfaceForGeometryGroup(BspLeaf* leaf, uint groupId)
{
Q_ASSERT(leaf);
DENG2_ASSERT(leaf);
if(!leaf->sector || groupId > leaf->sector->planeCount) return NULL;
return leaf->bsuf[groupId];
}

BspLeaf* BspLeaf_UpdateAABox(BspLeaf* leaf)
{
Q_ASSERT(leaf);
DENG2_ASSERT(leaf);

V2d_Set(leaf->aaBox.min, DDMAXFLOAT, DDMAXFLOAT);
V2d_Set(leaf->aaBox.max, DDMINFLOAT, DDMINFLOAT);
Expand All @@ -106,7 +125,7 @@ BspLeaf* BspLeaf_UpdateAABox(BspLeaf* leaf)

BspLeaf* BspLeaf_UpdateMidPoint(BspLeaf* leaf)
{
Q_ASSERT(leaf);
DENG2_ASSERT(leaf);
// The middle is the center of our AABox.
leaf->midPoint[VX] = leaf->aaBox.minX + (leaf->aaBox.maxX - leaf->aaBox.minX) / 2;
leaf->midPoint[VY] = leaf->aaBox.minY + (leaf->aaBox.maxY - leaf->aaBox.minY) / 2;
Expand All @@ -115,23 +134,23 @@ BspLeaf* BspLeaf_UpdateMidPoint(BspLeaf* leaf)

BspLeaf* BspLeaf_UpdateWorldGridOffset(BspLeaf* leaf)
{
Q_ASSERT(leaf);
DENG2_ASSERT(leaf);
leaf->worldGridOffset[VX] = fmod(leaf->aaBox.minX, 64);
leaf->worldGridOffset[VY] = fmod(leaf->aaBox.maxY, 64);
return leaf;
}

int BspLeaf_SetProperty(BspLeaf* leaf, const setargs_t* args)
{
Q_ASSERT(leaf);
DENG2_ASSERT(leaf);
DENG_UNUSED(leaf);
Con_Error("BspLeaf::SetProperty: Property %s is not writable.\n", DMU_Str(args->prop));
exit(1); // Unreachable.
}

int BspLeaf_GetProperty(const BspLeaf* leaf, setargs_t* args)
{
Q_ASSERT(leaf);
DENG2_ASSERT(leaf);
switch(args->prop)
{
case DMU_SECTOR:
Expand Down

0 comments on commit b187ba8

Please sign in to comment.