Skip to content

Commit

Permalink
Refactor|LineDef: Replaced more LineDef accessor/helper macros
Browse files Browse the repository at this point in the history
Plus various const-correctness refactorings.
  • Loading branch information
danij-deng committed Mar 13, 2013
1 parent 5ee6498 commit 13174c0
Show file tree
Hide file tree
Showing 20 changed files with 363 additions and 259 deletions.
2 changes: 1 addition & 1 deletion doomsday/client/include/map/bsp/linedefinfo.h
Expand Up @@ -78,7 +78,7 @@ struct LineDefInfo
{
flags |= Twosided;

if(lineDef->L_backsector == lineDef->L_frontsector)
if(lineDef->isSelfReferencing())
flags |= SelfRef;
}
}
Expand Down
105 changes: 96 additions & 9 deletions doomsday/client/include/map/linedef.h
Expand Up @@ -46,10 +46,6 @@ class HEdge;
#define L_sidedef(n) side(n).sideDef
#define L_frontsidedef L_sidedef(FRONT)
#define L_backsidedef L_sidedef(BACK)

#define L_sector(n) side(n).sector
#define L_frontsector L_sector(FRONT)
#define L_backsector L_sector(BACK)
///@}

// Internal flags:
Expand Down Expand Up @@ -108,6 +104,9 @@ class HEdge;
class LineDef : public de::MapElement
{
public:
/// Required sector attribution is missing. @ingroup errors
DENG2_ERROR(MissingSectorError);

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

Expand All @@ -121,7 +120,7 @@ class LineDef : public de::MapElement
{
public: /// @todo make private:
/// Sector on this side.
Sector *sector;
Sector *_sector;

/// SideDef on this side.
SideDef *sideDef;
Expand All @@ -134,14 +133,36 @@ class LineDef : public de::MapElement

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

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

/**
* Returns the Sector attributed to the side.
*
* @see hasSector()
*/
Sector &sector() const;

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

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

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

/// Logical sides [Front, Back]
Side _sides[2];

/// Public DDLF_* flags.
Expand All @@ -150,6 +171,7 @@ class LineDef : public de::MapElement
/// Internal LF_* flags.
byte inFlags;

/// Logical slope type.
slopetype_t slopeType;

int validCount;
Expand Down Expand Up @@ -200,15 +222,80 @@ class LineDef : public de::MapElement
/// @copydoc back()
inline Side const &back() const { return side(BACK); }

/**
* Returns @c true iff a sector 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 hasSector(int back) const { return side(back).hasSector(); }

/**
* Returns @c true iff a sector is attributed to the Front side of the line.
*/
inline bool hasFrontSector() const { return !!front().sector; }
inline bool hasFrontSector() const { return hasSector(FRONT); }

/**
* Returns @c true iff a sector is attributed to the Back side of the line.
*/
inline bool hasBackSector() const { return !!back().sector; }
inline bool hasBackSector() const { return hasSector(BACK); }

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

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

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

/// @copydoc sector()
inline Sector const *sectorPtr(int back) const { return side(back).sectorPtr(); }

/**
* Returns the sector attributed to the Front side of the line.
*/
inline Sector &frontSector() { return sector(FRONT); }

/// @copydoc backSector()
inline Sector const &frontSector() const { return sector(FRONT); }

/**
* Returns the sector attributed to the Back side of the line.
*/
inline Sector &backSector() { return sector(BACK); }

/// @copydoc backSector()
inline Sector const &backSector() const { return sector(BACK); }

/**
* Convenient accessor method for returning a pointer to the sector attributed
* to the front side of the line.
*/
inline Sector *frontSectorPtr() { return sectorPtr(FRONT); }

/// @copydoc frontSectorPtr()
inline Sector const *frontSectorPtr() const { return sectorPtr(FRONT); }

/**
* Convenient accessor method for returning a pointer to the sector attributed
* to the back side of the line.
*/
inline Sector *backSectorPtr() { return sectorPtr(BACK); }

/// @copydoc frontSectorPtr()
inline Sector const *backSectorPtr() const { return sectorPtr(BACK); }

/**
* Returns @c true iff the line is considered @em self-referencing.
Expand All @@ -219,7 +306,7 @@ class LineDef : public de::MapElement
*/
inline bool isSelfReferencing() const
{
return L_frontsidedef && L_backsidedef && L_frontsector == L_backsector;
return L_frontsidedef && L_backsidedef && frontSectorPtr() == backSectorPtr();
}

/**
Expand Down
13 changes: 7 additions & 6 deletions doomsday/client/include/map/r_world.h
Expand Up @@ -108,11 +108,11 @@ void R_OrderVertices(LineDef *line, Sector const *sector, Vertex *verts[2]);
* @return @c true iff the determined wall section height is @c >0
*/
boolean R_FindBottomTop2(SideDefSection section, int lineFlags,
Sector* frontSec, Sector* backSec, SideDef* frontDef, SideDef* backDef,
coord_t* low, coord_t* hi, float matOffset[2]);
Sector const *frontSec, Sector const *backSec, SideDef const *frontDef, SideDef const *backDef,
coord_t *low, coord_t *hi, float matOffset[2]);
boolean R_FindBottomTop(SideDefSection section, int lineFlags,
Sector* frontSec, Sector* backSec, SideDef* frontDef, SideDef* backDef,
coord_t* low, coord_t* hi) /* matOffset = 0 */;
Sector const *frontSec, Sector const *backSec, SideDef const *frontDef, SideDef const *backDef,
coord_t *low, coord_t *hi) /* matOffset = 0 */;

/**
* Find the "sharp" Z coordinate range of the opening between sectors @a frontSec
Expand Down Expand Up @@ -144,8 +144,9 @@ coord_t R_VisOpenRange(Sector const* frontSec, Sector const* backSec, coord_t* r
* @return @c true iff SideDef @a frontDef has a "middle" Material which completely
* covers the open range defined by sectors @a frontSec and @a backSec.
*/
boolean R_MiddleMaterialCoversOpening(int lineFlags, Sector* frontSec, Sector* backSec,
SideDef* frontDef, SideDef* backDef, boolean ignoreOpacity);
boolean R_MiddleMaterialCoversOpening(int lineFlags, Sector const *frontSec,
Sector const *backSec, SideDef const *frontDef, SideDef const *backDef,
boolean ignoreOpacity);

/**
* Same as @ref R_MiddleMaterialCoversOpening except all arguments are derived from
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/edit_bsp.cpp
Expand Up @@ -134,7 +134,7 @@ static void finishHEdges(GameMap *map)
{
Vertex const &vtx = hedge->lineDef->vertex(hedge->side);

hedge->sector = hedge->lineDef->L_sector(hedge->side);
hedge->sector = hedge->lineDef->sectorPtr(hedge->side);
hedge->offset = V2d_Distance(hedge->HE_v1origin, vtx.origin());
}

Expand Down

0 comments on commit 13174c0

Please sign in to comment.