Skip to content

Commit

Permalink
Refactor|BspLeaf: Applied pimpl idiom to BspLeaf; most instance data …
Browse files Browse the repository at this point in the history
…now private
  • Loading branch information
danij-deng committed Apr 15, 2013
1 parent 6cb0f62 commit 9cedd47
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 230 deletions.
104 changes: 46 additions & 58 deletions doomsday/client/include/map/bspleaf.h
Expand Up @@ -27,8 +27,6 @@
#include <de/Error>

#include "MapElement"
//#include "resource/r_data.h"
//#include "p_mapdata.h"
#include "p_dmu.h"
#ifdef __CLIENT__
# include "render/rend_bias.h"
Expand All @@ -40,15 +38,6 @@ struct polyobj_s;

#ifdef __CLIENT__
struct ShadowLink;

/**
* @defgroup bspLeafFlags Bsp Leaf Flags
* @ingroup flags
*/
///@{
#define BLF_UPDATE_FANBASE 0x1 ///< The tri-fan base requires an update.
///@}

#endif // __CLIENT__

/**
Expand Down Expand Up @@ -77,42 +66,14 @@ class BspLeaf : public de::MapElement
DENG2_ERROR(WritePropertyError);

public: /// @todo Make private:
/// First HEdge in this leaf.
/// First half-edge in the leaf. Ordered by angle, clockwise starting from
/// the smallest angle.
HEdge *_hedge;

/// Unique. Set when saving the BSP.
uint _index;

int _validCount;

/// Number of HEdge's in this leaf.
/// Number of HEdge's in the leaf.
uint _hedgeCount;

Sector *_sector;

/// First Polyobj in this leaf. Can be @c NULL.
struct polyobj_s *_polyObj;

/// Vertex bounding box in the map coordinate space.
AABoxd _aaBox;

/// Center of vertices.
coord_t _center[2];

/// Offset to align the top left of materials in the built geometry to the
/// map coordinate space grid.
coord_t _worldGridOffset[2];

#ifdef __CLIENT__
/// @ref bspLeafFlags.
int _flags;

/// Frame number of last R_AddSprites.
int _addSpriteCount;

/// HEdge whose vertex to use as the base for a trifan.
/// If @c NULL then midPoint will be used instead.
HEdge *_fanBase;

ShadowLink *_shadows;

Expand Down Expand Up @@ -185,20 +146,38 @@ class BspLeaf : public de::MapElement
inline Sector *sectorPtr() const { return hasSector()? &sector() : 0; }

/**
* Returns a pointer to the first polyobj linked to the BSP leaf; otherwise @c 0.
* Change the sector attributed to the BSP leaf.
*
* @param newSector New sector to be attributed. Can be @c 0.
*
* @todo Refactor away.
*/
struct polyobj_s *firstPolyobj() const;
void setSector(Sector *newSector);

/**
* Returns @c true iff there is at least one polyobj linked with the BSP leaf.
*/
inline bool hasPolyobj() { return firstPolyobj() != 0; }

/**
* Returns a pointer to the first polyobj linked to the BSP leaf; otherwise @c 0.
*/
struct polyobj_s *firstPolyobj() const;

/**
* Change the first polyobj linked to the BSP leaf.
*
* @param newPolyobj New polyobj. Can be @c 0.
*/
void setFirstPolyobj(struct polyobj_s *newPolyobj);

/**
* Returns the original index of the BSP leaf.
*/
uint origIndex() const;

void setOrigIndex(uint newOrigIndex);

/**
* Returns the @em validCount of the BSP leaf. Used by some legacy iteration
* algorithms for marking leafs as processed/visited.
Expand All @@ -207,6 +186,9 @@ class BspLeaf : public de::MapElement
*/
int validCount() const;

/// @todo Refactor away.
void setValidCount(int newValidCount);

/**
* Update the world grid offset.
*
Expand All @@ -225,15 +207,11 @@ class BspLeaf : public de::MapElement
#ifdef __CLIENT__

/**
* Returns the @ref bspLeafFlags of the BSP leaf.
*/
int flags() const;

/**
* Returns the frame number of the last time sprites were projected for the
* BSP leaf.
* Returns a pointer to the HEdge of the BSP leaf which has been chosen for
* use as the base for a triangle fan geometry. May return @c 0 if no suitable
* base was determined.
*/
int addSpriteCount() const;
HEdge *fanBase() const;

/**
* Retrieve the bias surface for specified geometry @a groupId
Expand All @@ -243,16 +221,23 @@ class BspLeaf : public de::MapElement
biassurface_t &biasSurfaceForGeometryGroup(uint groupId);

/**
* Returns a pointer to the HEdge of the BSP lead which has been chosen for
* use as the base for a triangle fan geometry. May return @c 0 if no suitable
* base is configured.
* Returns the first ShadowLink associated with the BSP leaf; otherwise @c 0.
*/
HEdge *fanBase() const;
ShadowLink *firstShadowLink() const;

/**
* Returns the first ShadowLink associated with the BSP leaf; otherwise @c 0.
* Returns the frame number of the last time sprites were projected for the
* BSP leaf.
*/
ShadowLink *firstShadowLink() const;
int addSpriteCount() const;

/**
* Change the frame number of the last time sprites were projected for the
* BSP leaf.
*
* @param newFrameCount New frame number.
*/
void setAddSpriteCount(int newFrameCount);

#endif // __CLIENT__

Expand All @@ -271,6 +256,9 @@ class BspLeaf : public de::MapElement
* @return Always @c 0 (can be used as an iterator).
*/
int setProperty(setargs_t const &args);

private:
DENG2_PRIVATE(d)
};

#endif // DENG_WORLD_MAP_BSPLEAF
2 changes: 1 addition & 1 deletion doomsday/client/src/map/blockmapvisual.cpp
Expand Up @@ -139,7 +139,7 @@ static int rendBspLeaf(BspLeaf *bspLeaf, void * /*parameters*/)
} while((hedge = &hedge->next()) != base);
}

bspLeaf->_validCount = validCount;
bspLeaf->setValidCount(validCount);
}
return false; // Continue iteration.
}
Expand Down
5 changes: 2 additions & 3 deletions doomsday/client/src/map/bsp/partitioner.cpp
Expand Up @@ -1849,10 +1849,9 @@ DENG2_PIMPL(Partitioner)
} while((hedge = &hedge->next()) != base);
}

leaf->_sector = chooseSectorForBspLeaf(leaf);
if(!leaf->_sector)
leaf->setSector(chooseSectorForBspLeaf(leaf));
if(!leaf->hasSector())
{
leaf->_sector = 0;
LOG_WARNING("BspLeaf %p is degenerate/orphan (%d HEdges).")
<< de::dintptr(leaf) << leaf->hedgeCount();
}
Expand Down

0 comments on commit 9cedd47

Please sign in to comment.