From b187ba8f4c66428eb6747c741e8534707b39e1d9 Mon Sep 17 00:00:00 2001 From: skyjake Date: Mon, 14 Jan 2013 14:49:40 +0200 Subject: [PATCH] Refactor: Made bspleaf_s an opaque type, moved members to BspLeaf class Also updated BspLeaf_New() and BspLeaf_Delete(). In the future all the functions will become C++ methods of the class. --- doomsday/engine/api/api_map.h | 17 ++--- doomsday/engine/api/dd_share.h | 4 +- doomsday/engine/api/dd_types.h | 8 +-- doomsday/engine/include/map/bspleaf.h | 12 +++- doomsday/engine/include/map/hedge.h | 2 +- doomsday/engine/include/map/sector.h | 4 +- doomsday/engine/include/render/r_things.h | 2 +- doomsday/engine/src/map/bspleaf.cpp | 79 ++++++++++++++--------- 8 files changed, 70 insertions(+), 58 deletions(-) diff --git a/doomsday/engine/api/api_map.h b/doomsday/engine/api/api_map.h index e31d735006..05ba2ce75a 100644 --- a/doomsday/engine/api/api_map.h +++ b/doomsday/engine/api/api_map.h @@ -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; /** @@ -149,8 +140,10 @@ typedef struct plane_s Plane; #elif defined __cplusplus +// Foward declarations. class LineDef; class Sector; +class BspLeaf; #endif @@ -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 @@ -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 @@ -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*/); diff --git a/doomsday/engine/api/dd_share.h b/doomsday/engine/api/dd_share.h index 1a83258ede..9dda3b7b4f 100644 --- a/doomsday/engine/api/dd_share.h +++ b/doomsday/engine/api/dd_share.h @@ -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 */ \ @@ -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; \ diff --git a/doomsday/engine/api/dd_types.h b/doomsday/engine/api/dd_types.h index 9fd39136ad..5697a37c27 100644 --- a/doomsday/engine/api/dd_types.h +++ b/doomsday/engine/api/dd_types.h @@ -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; diff --git a/doomsday/engine/include/map/bspleaf.h b/doomsday/engine/include/map/bspleaf.h index 8ca51bbf3a..b2bf81c640 100644 --- a/doomsday/engine/include/map/bspleaf.h +++ b/doomsday/engine/include/map/bspleaf.h @@ -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" @@ -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. @@ -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); diff --git a/doomsday/engine/include/map/hedge.h b/doomsday/engine/include/map/hedge.h index 6d8507705e..aefc5a252e 100644 --- a/doomsday/engine/include/map/hedge.h +++ b/doomsday/engine/include/map/hedge.h @@ -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; diff --git a/doomsday/engine/include/map/sector.h b/doomsday/engine/include/map/sector.h index bbe15a015c..b247e3e2d4 100644 --- a/doomsday/engine/include/map/sector.h +++ b/doomsday/engine/include/map/sector.h @@ -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. diff --git a/doomsday/engine/include/render/r_things.h b/doomsday/engine/include/render/r_things.h index 32117b8b41..27ac969d75 100644 --- a/doomsday/engine/include/render/r_things.h +++ b/doomsday/engine/include/render/r_things.h @@ -100,7 +100,7 @@ typedef struct rendspriteparams_s { uint vLightListIdx; // Misc - struct bspleaf_s *bspLeaf; + BspLeaf *bspLeaf; } rendspriteparams_t; /** @name rendFlareFlags */ diff --git a/doomsday/engine/src/map/bspleaf.cpp b/doomsday/engine/src/map/bspleaf.cpp index 61861da222..1c9eb23f98 100644 --- a/doomsday/engine/src/map/bspleaf.cpp +++ b/doomsday/engine/src/map/bspleaf.cpp @@ -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(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); @@ -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; @@ -115,7 +134,7 @@ 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; @@ -123,7 +142,7 @@ BspLeaf* BspLeaf_UpdateWorldGridOffset(BspLeaf* 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. @@ -131,7 +150,7 @@ int BspLeaf_SetProperty(BspLeaf* leaf, const setargs_t* args) int BspLeaf_GetProperty(const BspLeaf* leaf, setargs_t* args) { - Q_ASSERT(leaf); + DENG2_ASSERT(leaf); switch(args->prop) { case DMU_SECTOR: