Skip to content

Commit

Permalink
Refactor: Separated Segment from HEdge; BspLeaf provides ordered segm…
Browse files Browse the repository at this point in the history
…ent lists
  • Loading branch information
danij-deng committed Jun 4, 2013
1 parent 8bbbbb2 commit 547dba3
Show file tree
Hide file tree
Showing 57 changed files with 1,401 additions and 1,126 deletions.
32 changes: 16 additions & 16 deletions doomsday/api/api_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@

#define DMT_VERTEX_ORIGIN DDVT_DOUBLE

#define DMT_HEDGE_SIDE DDVT_PTR

#define DMT_HEDGE_V DDVT_PTR // [Start, End] of the segment.
#define DMT_HEDGE_LINE DDVT_PTR
#define DMT_HEDGE_SECTOR DDVT_PTR
#define DMT_HEDGE_BSPLEAF DDVT_PTR
#define DMT_HEDGE_TWIN DDVT_PTR
#define DMT_HEDGE_ANGLE DDVT_ANGLE
#define DMT_HEDGE_SIDEID DDVT_BYTE // 0=front, 1=back
#define DMT_HEDGE_LENGTH DDVT_DOUBLE // Accurate length of the segment (v1 -> v2).
#define DMT_HEDGE_OFFSET DDVT_DOUBLE
#define DMT_HEDGE_NEXT DDVT_PTR
#define DMT_HEDGE_PREV DDVT_PTR
#define DMT_SEGMENT_SIDE DDVT_PTR

#define DMT_SEGMENT_V DDVT_PTR // [Start, End] of the segment.
#define DMT_SEGMENT_LINE DDVT_PTR
#define DMT_SEGMENT_SECTOR DDVT_PTR
#define DMT_SEGMENT_BSPLEAF DDVT_PTR
#define DMT_SEGMENT_TWIN DDVT_PTR
#define DMT_SEGMENT_ANGLE DDVT_ANGLE
#define DMT_SEGMENT_SIDEID DDVT_BYTE // 0=front, 1=back
#define DMT_SEGMENT_LENGTH DDVT_DOUBLE // Accurate length of the segment (v1 -> v2).
#define DMT_SEGMENT_OFFSET DDVT_DOUBLE
#define DMT_SEGMENT_NEXT DDVT_PTR
#define DMT_SEGMENT_PREV DDVT_PTR

#define DMT_BSPLEAF_HEDGECOUNT DDVT_UINT
#define DMT_BSPLEAF_HEDGE DDVT_PTR
Expand Down Expand Up @@ -124,7 +124,7 @@ struct intercept_s;
// Opaque types for public use.
struct bspleaf_s;
struct bspnode_s;
struct hedge_s;
struct segment_s;
struct line_s;
struct mobj_s;
struct plane_s;
Expand All @@ -135,7 +135,7 @@ struct material_s;

typedef struct bspleaf_s BspLeaf;
typedef struct bspnode_s BspNode;
typedef struct hedge_s HEdge;
typedef struct segment_s Segment;
typedef struct line_s Line;
typedef struct plane_s Plane;
typedef struct sector_s Sector;
Expand All @@ -146,10 +146,10 @@ typedef struct material_s Material;
#elif defined __cplusplus

// Foward declarations.
class BspLeaf;
class Line;
class Sector;
class Material;
class BspLeaf;

#endif

Expand Down
2 changes: 1 addition & 1 deletion doomsday/api/dd_share.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ enum {
*/
DMU_FIRST_ELEMENT_TYPE_ID = 1,
DMU_VERTEX = DMU_FIRST_ELEMENT_TYPE_ID,
DMU_HEDGE,
DMU_SEGMENT,
DMU_LINE,
DMU_SIDE,
DMU_BSPNODE,
Expand Down
3 changes: 3 additions & 0 deletions doomsday/client/client.pro
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ DENG_HEADERS += \
include/WallEdge \
include/WallSpec \
include/Sector \
include/Segment \
include/Surface \
include/Vertex

Expand Down Expand Up @@ -267,6 +268,7 @@ DENG_HEADERS += \
include/map/r_world.h \
include/map/reject.h \
include/map/sector.h \
include/map/segment.h \
include/map/surface.h \
include/map/vertex.h \
include/network/masterserver.h \
Expand Down Expand Up @@ -543,6 +545,7 @@ SOURCES += \
src/map/r_world.cpp \
src/map/reject.cpp \
src/map/sector.cpp \
src/map/segment.cpp \
src/map/surface.cpp \
src/map/vertex.cpp \
src/network/masterserver.cpp \
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/include/Segment
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "map/segment.h"
2 changes: 1 addition & 1 deletion doomsday/client/include/audio/s_environ.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef enum audioenvironmentclass_e {
/**
* Requests re-calculation of the reverb properties of the given sector. Should
* be called whenever any of the properties governing reverb properties have
* changed (i.e. hedge/plane texture or plane height changes).
* changed (i.e. segment/plane texture or plane height changes).
*
* Call S_UpdateReverbForSector() to do the actual calculation.
*
Expand Down
3 changes: 1 addition & 2 deletions doomsday/client/include/de_play.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
#include "Line"
#include "map/linesighttest.h"
#include "Plane"
#include "HEdge"
#include "BspLeaf"
#include "Segment"
#include "BspNode"
#include "Sector"
#include "Polyobj"
Expand Down
35 changes: 17 additions & 18 deletions doomsday/client/include/map/bsp/linesegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
/// Rounding threshold within which two points are considered as co-incident.
#define LINESEGMENT_INCIDENT_DISTANCE_EPSILON 1.0 / 128

class HEdge;

namespace de {
namespace bsp {

Expand Down Expand Up @@ -98,8 +96,8 @@ class LineSegment
/// Required map line side attribution is missing. @ingroup errors
DENG2_ERROR(MissingMapSideError);

/// Required half-edge is missing. @ingroup errors
DENG2_ERROR(MissingHEdgeError);
/// Required segment is missing. @ingroup errors
DENG2_ERROR(MissingSegmentError);

public:
Side(LineSegment &line);
Expand Down Expand Up @@ -398,35 +396,36 @@ class LineSegment
inline AABoxd aaBox() const { return line().aaBox(); }

/**
* Returns @c true iff a half-edge is linked to "this" side of the line segment.
* Returns @c true iff a built segment is linked to "this" side of the line
* segment.
*
* @see hedge()
* @see segment()
*/
bool hasHEdge() const;
bool hasSegment() const;

/**
* Returns the linked half-edge for "this" side of the line segment.
* Returns the built segment for "this" side of the line segment.
*
* @see hasHEdge()
* @see hasSegment()
*/
HEdge &hedge() const;
Segment &segment() const;

/**
* Returns a pointer to the linked half-edge of "this" side of the line segment;
* otherwise @c 0.
* Returns a pointer to the built segment linked to "this" side of the line
* segment. otherwise @c 0.
*
* @see hasHEdge()
* @see hasSegment()
*/
inline HEdge *hedgePtr() const { return hasHEdge()? &hedge() : 0; }
inline Segment *segmentPtr() const { return hasSegment()? &segment() : 0; }

/**
* Change the linked half-edge for "this" side of the line segment.
* Change the built segment linked to "this" side of the line segment.
*
* @param newHEdge New half-edge. Can be @c 0.
* @param newSegment New segment. Can be @c 0.
*
* @see hedge()
* @see segment()
*/
void setHEdge(HEdge *newHEdge);
void setSegment(Segment *newSegment);

/**
* Returns a pointer to the ConvexSubspace to which "this" side of the
Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/include/map/bsp/partitioner.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class GameMap;
class BspLeaf;
class HEdge;
class Segment;
class Line;
class Sector;

Expand Down Expand Up @@ -97,14 +97,14 @@ class Partitioner
BspTreeNode *root() const;

/**
* Retrieve the number of HEdges owned by the partitioner. When the build
* completes this number will be the total number of half-edges that were
* Retrieve the number of Segments owned by the partitioner. When the build
* completes this number will be the total number of line segments that were
* produced during that process. Note that as BspLeaf ownership is claimed
* this number will decrease respectively.
*
* @return Current number of HEdges owned by the partitioner.
* @return Current number of Segments owned by the partitioner.
*/
int numHEdges();
int numSegments();

/**
* Retrieve the number of BspLeafs owned by the partitioner. When the
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/include/map/bspbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ class BspBuilder
BspTreeNode *root() const;

/**
* Retrieve the number of HEdges owned by this Partitioner. When the build
* completes this number will be the total number of half-edges that were
* Retrieve the number of Segments owned by this Partitioner. When the build
* completes this number will be the total number of line segments that were
* produced during that process. Note that as BspLeaf ownership is claimed
* this number will decrease respectively.
*
* @return Current number of HEdges owned by this Partitioner.
* @return Current number of Segments owned by this Partitioner.
*/
int numHEdges();
int numSegments();

/**
* Retrieve the number of BspLeafs owned by this Partitioner. When the
Expand Down
41 changes: 17 additions & 24 deletions doomsday/client/include/map/bspleaf.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
#ifndef DENG_WORLD_MAP_BSPLEAF
#define DENG_WORLD_MAP_BSPLEAF

#include <QList>

#include <de/Error>
#include <de/Vector>

#include "MapElement"
#include "Line"
#include "Polygon"

class HEdge;
class Sector;
class Segment;
struct polyobj_s;

#ifdef __CLIENT__
Expand All @@ -50,7 +53,7 @@ class BspLeaf : public de::MapElement
/// An invalid polygon was specified @ingroup errors
DENG2_ERROR(InvalidPolygonError);

/// No polygon is assigned. @ingroup errors
/// Required polygon geometry is missing. @ingroup errors
DENG2_ERROR(MissingPolygonError);

/// Required sector attribution is missing. @ingroup errors
Expand All @@ -61,6 +64,8 @@ class BspLeaf : public de::MapElement
DENG2_ERROR(UnknownGeometryGroupError);
#endif

typedef QList<Segment *> Segments;

public: /// @todo Make private:
#ifdef __CLIENT__

Expand Down Expand Up @@ -118,23 +123,18 @@ class BspLeaf : public de::MapElement
*/
void setPoly(de::Polygon *newPolygon);

Segment *newSegment(Line::Side *mapSide, de::HEdge *hedge);

/**
* Convenience accessor which returns a pointer to the first HEdge from the
* convex Polygon geometry attributed to the BSP leaf. If no geometry is
* attributed @c 0 is returned.
*
* @see hasPoly(), Polygon::firstHEdge()
* Provides a clockwise ordered list of all the line segments which comprise
* the convex geometry assigned to the BSP leaf.
*/
inline HEdge *firstHEdge() const { return hasPoly()? poly().firstHEdge() : 0; }
Segments const &clockwiseSegments() const;

/**
* Convenience accessor which returns the total number of half-edges in the
* convex Polygon geometry attributed to the BSP leaf. If no geometry is
* attributed @c 0 is returned.
*
* @see hasPoly(), Polygon::hedgeCount()
* Provides a list of all the line segments attributed to the BSP leaf.
*/
inline int hedgeCount() const { return hasPoly()? poly().hedgeCount() : 0; }
Segments const &segments() const;

/**
* Returns @c true iff a sector is attributed to the BSP leaf. The only time
Expand Down Expand Up @@ -199,13 +199,6 @@ class BspLeaf : public de::MapElement
*/
void setFirstPolyobj(struct polyobj_s *newPolyobj);

/**
* Update the world grid offset.
*
* @pre Axis-aligned bounding box must have been initialized.
*/
void updateWorldGridOffset();

/**
* Returns the vector described by the offset from the map coordinate space
* origin to the top most, left most point of the geometry of the BSP leaf.
Expand All @@ -228,15 +221,15 @@ class BspLeaf : public de::MapElement
#ifdef __CLIENT__

/**
* Returns a pointer to the HEdge of the BSP leaf which has been chosen for
* Returns a pointer to the half-edge 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.
*/
HEdge *fanBase() const;
de::HEdge *fanBase() const;

/**
* Returns the number of vertices needed for the BSP leaf's triangle fan.
* @note May incurr updating the fan base HEdge if not already determined.
* @note May incurr updating the fan base Segment if not already determined.
*
* @see fanBase()
*/
Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/include/map/gamemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class GameMap
typedef QList<Line *> Lines;
typedef QList<Polyobj *> Polyobjs;

typedef QList<HEdge *> HEdges;
typedef QList<Segment *> Segments;
typedef QList<BspNode *> BspNodes;
typedef QList<BspLeaf *> BspLeafs;

Expand Down Expand Up @@ -238,14 +238,14 @@ class GameMap
de::MapElement *bspRoot() const;

/**
* Provides access to the list of half-edges for efficient traversal.
* Provides access to the list of line segments for efficient traversal.
*/
HEdges const &hedges() const;
Segments const &segments() const;

/**
* Returns the total number of HEdges in the map.
* Returns the total number of line segments in the map.
*/
inline int hedgeCount() const { return hedges().count(); }
inline int segmentCount() const { return segments().count(); }

/**
* Provides access to the list of BSP nodes for efficient traversal.
Expand Down
Loading

0 comments on commit 547dba3

Please sign in to comment.