Skip to content

Commit

Permalink
Refactor|LineDef: Replaced last of the LineDef accessor/helper macros
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 13, 2013
1 parent 52c2985 commit e86755b
Show file tree
Hide file tree
Showing 29 changed files with 486 additions and 347 deletions.
2 changes: 1 addition & 1 deletion doomsday/client/include/map/bsp/linedefinfo.h
Expand Up @@ -74,7 +74,7 @@ struct LineDefInfo
(fabs(from.origin()[VY] - to.origin()[VY]) < distEpsilon))
flags |= ZeroLength;

if(lineDef->L_backsidedef && lineDef->L_frontsidedef)
if(lineDef->hasBackSideDef() && lineDef->hasFrontSideDef())
{
flags |= Twosided;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/map/hedge.h
Expand Up @@ -45,7 +45,7 @@
#define HEDGE_BACK_SECTOR(h) ((h)->twin ? (h)->twin->sector : NULL)

#define HEDGE_SIDE(h) ((h)->lineDef ? &(h)->lineDef->side((h)->side) : NULL)
#define HEDGE_SIDEDEF(h) ((h)->lineDef ? (h)->lineDef->L_sidedef((h)->side) : NULL)
#define HEDGE_SIDEDEF(h) ((h)->lineDef ? (h)->lineDef->sideDefPtr((h)->side) : NULL)

// HEdge frame flags
#define HEDGEINF_FACINGFRONT 0x0001
Expand Down
160 changes: 139 additions & 21 deletions doomsday/client/include/map/linedef.h
Expand Up @@ -34,20 +34,6 @@ class Sector;
class SideDef;
class HEdge;

/*
* Helper macros for accessing linedef data elements:
*/
/// @addtogroup map
///@{
#define L_vo(n) vo[(n)? 1:0]
#define L_vo1 L_vo(0)
#define L_vo2 L_vo(1)

#define L_sidedef(n) side(n).sideDef
#define L_frontsidedef L_sidedef(FRONT)
#define L_backsidedef L_sidedef(BACK)
///@}

// Internal flags:
#define LF_POLYOBJ 0x1 ///< Line is part of a polyobject.
#define LF_BSPWINDOW 0x2 ///< Line produced a BSP window. @todo Refactor away.
Expand Down Expand Up @@ -107,6 +93,9 @@ class LineDef : public de::MapElement
/// Required sector attribution is missing. @ingroup errors
DENG2_ERROR(MissingSectorError);

/// Required sidedef attribution is missing. @ingroup errors
DENG2_ERROR(MissingSideDefError);

/// The referenced property does not exist. @ingroup errors
DENG2_ERROR(UnknownPropertyError);

Expand All @@ -123,16 +112,16 @@ class LineDef : public de::MapElement
Sector *_sector;

/// SideDef on this side.
SideDef *sideDef;
SideDef *_sideDef;

/// Left-most HEdge on this side.
HEdge *hedgeLeft;
HEdge *_leftHEdge;

/// Right-most HEdge on this side.
HEdge *hedgeRight;
HEdge *_rightHEdge;

/// Framecount of last time shadows were drawn on this side.
ushort shadowVisFrame;
int _shadowVisCount;

public:
/**
Expand All @@ -148,19 +137,54 @@ class LineDef : public de::MapElement
Sector &sector() const;

/**
* Returns a pointer to the sector attributed to the side; otherwise @c 0.
* Returns a pointer to the Sector attributed to the side; otherwise @c 0.
*
* @see hasSector()
*/
inline Sector *sectorPtr() const { return hasSector()? &sector() : 0; }

/**
* Returns @c true iff a Sector is attributed to the side.
*/
bool hasSideDef() const;

/**
* Returns the SideDef attributed to the side.
*
* @see hasSideDef()
*/
SideDef &sideDef() const;

/**
* Returns a pointer to the SideDef attributed to the side; otherwise @c 0.
*
* @see hasSideDef()
*/
inline SideDef *sideDefPtr() const { return hasSideDef()? &sideDef() : 0; }

/**
* Returns the left-moset HEdge for the side.
*/
HEdge &leftHEdge() const;

/**
* Returns the right-most HEdge for the side.
*/
HEdge &rightHEdge() const;

/**
* Returns the frame number of the last time shadows linked to the side
* were drawn.
*/
int shadowVisCount() const;
};

public: /// @todo make private:
/// Vertexes [From, To]
Vertex *_v[2];

/// Links to vertex line owner nodes [From, To].
LineOwner *vo[2];
LineOwner *_vo[2];

/// Logical sides [Front, Back]
Side _sides[2];
Expand Down Expand Up @@ -239,6 +263,23 @@ class LineDef : public de::MapElement
*/
inline bool hasBackSector() const { return hasSector(BACK); }

/**
* Returns @c true iff a sidedef is attributed to the specified side of the line.
*
* @param back If not @c 0 test the Back side; otherwise the Front side.
*/
inline bool hasSideDef(int back) const { return side(back).hasSideDef(); }

/**
* Returns @c true iff a sidedef is attributed to the Front side of the line.
*/
inline bool hasFrontSideDef() const { return hasSideDef(FRONT); }

/**
* Returns @c true iff a sidedef is attributed to the Back side of the line.
*/
inline bool hasBackSideDef() const { return hasSideDef(BACK); }

/**
* Convenient accessor method for returning the sector attributed to the
* specified side of the line.
Expand Down Expand Up @@ -297,6 +338,64 @@ class LineDef : public de::MapElement
/// @copydoc frontSectorPtr()
inline Sector const *backSectorPtr() const { return sectorPtr(BACK); }

/**
* Convenient accessor method for returning the sidedef attributed to the
* specified side of the line.
*
* @param back If not @c 0 return the sidedef for the Back side; otherwise
* the sidedef of the Front side.
*/
inline SideDef &sideDef(int back) { return side(back).sideDef(); }

/// @copydoc sideDef()
inline SideDef const &sideDef(int back) const { return side(back).sideDef(); }

/**
* Convenient accessor method for returning a pointer to the sidedef attributed
* to the specified side of the line.
*
* @param back If not @c 0 return the sidedef for the Back side; otherwise
* the sidedef of the Front side.
*/
inline SideDef *sideDefPtr(int back) { return side(back).sideDefPtr(); }

/// @copydoc sideDef()
inline SideDef const *sideDefPtr(int back) const { return side(back).sideDefPtr(); }

/**
* Returns the sidedef attributed to the Front side of the line.
*/
inline SideDef &frontSideDef() { return sideDef(FRONT); }

/// @copydoc backSideDef()
inline SideDef const &frontSideDef() const { return sideDef(FRONT); }

/**
* Returns the sidedef attributed to the Back side of the line.
*/
inline SideDef &backSideDef() { return sideDef(BACK); }

/// @copydoc backSideDef()
inline SideDef const &backSideDef() const { return sideDef(BACK); }

/**
* Convenient accessor method for returning a pointer to the sidedef attributed
* to the front side of the line.
*/
inline SideDef *frontSideDefPtr() { return sideDefPtr(FRONT); }

/// @copydoc frontSideDefPtr()
inline SideDef const *frontSideDefPtr() const { return sideDefPtr(FRONT); }

/**
* Convenient accessor method for returning a pointer to the sidedef attributed
* to the back side of the line.
*/
inline SideDef *backSideDefPtr() { return sideDefPtr(BACK); }

/// @copydoc frontSideDefPtr()
inline SideDef const *backSideDefPtr() const { return sideDefPtr(BACK); }

/**
* Returns @c true iff the line is considered @em self-referencing.
* In this context, self-referencing (a term whose origins stem from the
Expand All @@ -306,7 +405,7 @@ class LineDef : public de::MapElement
*/
inline bool isSelfReferencing() const
{
return L_frontsidedef && L_backsidedef && frontSectorPtr() == backSectorPtr();
return hasFrontSideDef() && hasBackSideDef() && frontSectorPtr() == backSectorPtr();
}

/**
Expand All @@ -330,6 +429,15 @@ class LineDef : public de::MapElement
return vertex(to).origin();
}

/**
* Returns a pointer to the line owner node for the specified edge vertex
* of the line.
*
* @param to If not @c 0 return the owner for the To vertex; otherwise the
* From vertex.
*/
LineOwner *vertexOwner(int to) const;

/**
* Returns the From/Start vertex for the line.
*/
Expand Down Expand Up @@ -358,6 +466,11 @@ class LineDef : public de::MapElement
/// An alias of v1Origin()
inline const_pvec2d_t &fromOrigin() const { return v1Origin(); }

/**
* Returns a pointer to the line owner node for the From/Start vertex of the line.
*/
inline LineOwner *v1Owner() const { return vertexOwner(FROM); }

/**
* Returns the To/End vertex for the line.
*/
Expand Down Expand Up @@ -386,6 +499,11 @@ class LineDef : public de::MapElement
/// An alias of v2Origin()
inline const_pvec2d_t &toOrigin() const { return v2Origin(); }

/**
* Returns a pointer to the line owner node for the To/End vertex of the line.
*/
inline LineOwner *v2Owner() const { return vertexOwner(FROM); }

/**
* On which side of the line does the specified box lie?
*
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/include/map/vertex.h
Expand Up @@ -48,7 +48,7 @@ class LineOwner
};

public: /// @todo Make private:
LineDef *_lineDef;
LineDef *_line;

/// {Previous, Next} (i.e. {anticlk, clk}).
LineOwner *_link[2];
Expand All @@ -62,7 +62,7 @@ class LineOwner
} _shadowOffsets;

public:
/*LineOwner() : _lineDef(0), _angle(0)
/*LineOwner() : _line(0), _angle(0)
{
_link[Previous] = 0;
_link[Next] = 0;
Expand Down Expand Up @@ -119,9 +119,9 @@ class LineOwner
inline LineOwner const &next() const { return navigate(Next); }

/**
* Returns the LineDef "owner".
* Returns the line "owner".
*/
LineDef &lineDef() const { return *_lineDef; }
LineDef &line() const { return *_line; }

/**
* Returns the angle between the line owner and the next in the ring (clockwise).
Expand Down

0 comments on commit e86755b

Please sign in to comment.