Skip to content

Commit

Permalink
Refactor|World|Map: Continued work on removing the Segment map elemen…
Browse files Browse the repository at this point in the history
…t (obsolete)
  • Loading branch information
danij-deng committed Aug 10, 2013
1 parent fab3b17 commit 2e21bad
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 131 deletions.
8 changes: 4 additions & 4 deletions doomsday/client/include/render/skyfixedge.h
Expand Up @@ -22,12 +22,12 @@

#include <de/Vector>

#include "Segment"

#include "TriangleStripBuilder" /// @todo remove me

namespace de {

class HEdge;

/**
* @ingroup render
*/
Expand Down Expand Up @@ -57,10 +57,10 @@ class SkyFixEdge : public WorldEdge

public:
/**
* @param segment Segment from which to determine sky fix coordinates.
* @param hedge HEdge from which to determine sky fix coordinates.
* @param fixType Fix type.
*/
SkyFixEdge(Segment &segment, FixType fixType, int edge, float materialOffsetS = 0);
SkyFixEdge(HEdge &hedge, FixType fixType, int edge, float materialOffsetS = 0);

Vector3d const &pOrigin() const;
Vector3d const &pDirection() const;
Expand Down
10 changes: 7 additions & 3 deletions doomsday/client/include/render/walledge.h
Expand Up @@ -31,14 +31,15 @@
#include "TriangleStripBuilder"
#include "IHPlane"

class Segment;
class Surface;

/// Maximum number of intercepts in a WallEdge.
#define WALLEDGE_MAX_INTERCEPTS 64

namespace de {

class HEdge;

/**
* Helper/utility class intended to simplify the process of generating
* sections of wall geometry from a map Line segment.
Expand Down Expand Up @@ -73,9 +74,12 @@ class WallEdge : public WorldEdge

public:
/**
* @param spec Geometry specification for the wall section. A copy is made.
* @param spec Geometry specification for the wall section. A copy is made.
*
* @param hedge Assumed to have a mapped Segment attributed to a Line::Side
* with sections.
*/
WallEdge(WallSpec const &spec, Segment &segment, int edge);
WallEdge(WallSpec const &spec, HEdge &hedge, int edge);

inline Event const &operator [] (EventIndex index) const {
return at(index);
Expand Down
37 changes: 3 additions & 34 deletions doomsday/client/include/world/segment.h
Expand Up @@ -68,24 +68,22 @@ class Segment : public de::MapElement

de::HEdge &hedge() const;

bool hasBack() const;

/**
* Returns the segment on the back side of "this".
*/
Segment &back() const;

void setBack(Segment *newBack);

inline Vertex &from() const { return hedge().vertex(); }
//inline Vertex &from() const { return hedge().vertex(); }

inline Vertex &to() const { return hedge().twin().vertex(); }
//inline Vertex &to() const { return hedge().twin().vertex(); }

/**
* Returns the point on the line segment which lies at the exact center of
* the two vertexes.
*/
inline de::Vector2d center() const { return (from().origin() + to().origin()) / 2; }
//inline de::Vector2d center() const { return (from().origin() + to().origin()) / 2; }

/**
* Returns @c true iff a polygon attributed to a BSP leaf is associated
Expand Down Expand Up @@ -155,14 +153,6 @@ class Segment : public de::MapElement
/// @todo Refactor away.
void setLineSideOffset(coord_t newOffset);

/**
* Returns the world angle of the line segment.
*/
angle_t angle() const;

/// @todo Refactor away.
void setAngle(angle_t newAngle);

/**
* Returns the accurate length of the line segment, from the 'from' vertex to
* the 'to' vertex in map coordinate space units.
Expand All @@ -172,27 +162,6 @@ class Segment : public de::MapElement
/// @todo Refactor away.
void setLength(coord_t newLength);

/**
* Returns the distance from @a point to the nearest point along the Segment
* (in the inclussive range 0..1).
*
* @param point Point to measure the distance to in the map coordinate space.
*/
coord_t pointDistance(const_pvec2d_t point, coord_t *offset) const;

/**
* Returns the distance from @a point to the nearest point along the Segment
* (in the inclussive range 0..1).
*
* @param x X axis point to measure the distance to in the map coordinate space.
* @param y Y axis point to measure the distance to in the map coordinate space.
*/
inline coord_t pointDistance(coord_t x, coord_t y, coord_t *offset) const
{
coord_t point[2] = { x, y };
return pointDistance(point, offset);
}

/**
* On which side of the Segment does the specified @a point lie?
*
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/lumobj.cpp
Expand Up @@ -1172,8 +1172,8 @@ boolean LOIT_ClipLumObjBySight(void *data, void *context)
// Ignore half-edges facing the wrong way.
if(segment->isFlagged(Segment::FacingFront))
{
coord_t fromV1[2] = { segment->from().origin().x, segment->from().origin().y };
coord_t toV1[2] = { segment->to().origin().x, segment->to().origin().y };
coord_t fromV1[2] = { segment->hedge().origin().x, segment->hedge().origin().y };
coord_t toV1[2] = { segment->hedge().twin().origin().x, segment->hedge().twin().origin().y };
if(V2d_Intercept2(lum->origin, eye, fromV1, toV1, 0, 0, 0))
{
luminousClipped[lumIdx] = 1;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_fakeradio.cpp
Expand Up @@ -1083,7 +1083,7 @@ void Rend_RadioWallSection(WallEdge const &leftEdge, WallEdge const &rightEdge,
Line::Side &side = leftEdge.mapSide();
Segment const *segment = side.leftSegment();
Sector const *frontSec = segment->sectorPtr();
Sector const *backSec = (segment->hasBack() && segment->back().hasBspLeaf() && !segment->back().bspLeaf().isDegenerate() &&
Sector const *backSec = (segment->hedge().twin().hasFace() &&
leftEdge.spec().section != Line::Side::Middle)? segment->back().sectorPtr() : 0;

coord_t const lineLength = side.line().length();
Expand Down
22 changes: 11 additions & 11 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -1401,8 +1401,8 @@ static void writeWallSection(Segment &segment, int section,
// Generate edge geometries.
WallSpec const wallSpec = WallSpec::fromMapSide(side, section);

WallEdge leftEdge(wallSpec, segment, Line::From);
WallEdge rightEdge(wallSpec, segment, Line::To);
WallEdge leftEdge(wallSpec, segment.hedge(), Line::From);
WallEdge rightEdge(wallSpec, segment.hedge(), Line::To);

// Do the edge geometries describe a valid polygon?
if(!leftEdge.isValid() || !rightEdge.isValid() ||
Expand Down Expand Up @@ -1837,7 +1837,7 @@ static void writeLeafSkyMaskStrips(SkyFixEdge::FixType fixType)
startMaterialOffset = seg.lineSideOffset();

// Prepare the edge geometry
SkyFixEdge skyEdge(seg, fixType, (direction == Anticlockwise)? Line::To : Line::From,
SkyFixEdge skyEdge(*hedge, fixType, (direction == Anticlockwise)? Line::To : Line::From,
startMaterialOffset);

if(skyEdge.isValid() && skyEdge.bottom().z() < skyEdge.top().z())
Expand All @@ -1862,7 +1862,7 @@ static void writeLeafSkyMaskStrips(SkyFixEdge::FixType fixType)
startMaterialOffset += seg.length() * (direction == Anticlockwise? -1 : 1);

// Prepare the edge geometry
SkyFixEdge skyEdge(seg, fixType, (direction == Anticlockwise)? Line::From : Line::To,
SkyFixEdge skyEdge(*hedge, fixType, (direction == Anticlockwise)? Line::From : Line::To,
startMaterialOffset);

// Stop if we've reached a "null" edge.
Expand Down Expand Up @@ -2162,7 +2162,7 @@ static void writeLeafPolyobjs()
// is not in the void).
if(!P_IsInVoid(viewPlayer) && wroteOpaqueMiddle)
{
C_AddRangeFromViewRelPoints(seg->from().origin(), seg->to().origin());
C_AddRangeFromViewRelPoints(seg->hedge().origin(), seg->hedge().twin().origin());
}
}
}
Expand All @@ -2185,7 +2185,7 @@ static void markOneFrontFacingSegment(Segment *seg)
if(seg->hasLineSide())
{
// Which way is it facing?
facingFront = viewFacingDot(seg->from().origin(), seg->to().origin()) >= 0;
facingFront = viewFacingDot(seg->hedge().origin(), seg->hedge().twin().origin()) >= 0;
}
seg->setFlags(Segment::FacingFront, facingFront? SetFlags : UnsetFlags);
}
Expand Down Expand Up @@ -2304,7 +2304,7 @@ static void clipOneFrontFacingSegment(Segment *seg)

if(seg->isFlagged(Segment::FacingFront))
{
if(!C_CheckRangeFromViewRelPoints(seg->from().origin(), seg->to().origin()))
if(!C_CheckRangeFromViewRelPoints(seg->hedge().origin(), seg->hedge().twin().origin()))
{
seg->setFlags(Segment::FacingFront, UnsetFlags);
}
Expand Down Expand Up @@ -3162,7 +3162,7 @@ static void drawTangentSpaceVectorsForSegment(Segment *seg)
{
coord_t const bottom = seg->sector().floor().visHeight();
coord_t const top = seg->sector().ceiling().visHeight();
Vector2d center = (seg->to().origin() + seg->from().origin()) / 2;
Vector2d center = (seg->hedge().twin().origin() + seg->hedge().origin()) / 2;
Surface *suf = &seg->lineSide().middle();

Vector3d origin = Vector3d(center, bottom + (top - bottom) / 2);
Expand All @@ -3177,7 +3177,7 @@ static void drawTangentSpaceVectorsForSegment(Segment *seg)
{
coord_t const bottom = seg->sector().floor().visHeight();
coord_t const top = seg->sector().ceiling().visHeight();
Vector2d center = (seg->to().origin() + seg->from().origin()) / 2;
Vector2d center = (seg->hedge().twin().origin() + seg->hedge().origin()) / 2;
Surface *suf = &side.middle();

Vector3d origin = Vector3d(center, bottom + (top - bottom) / 2);
Expand All @@ -3191,7 +3191,7 @@ static void drawTangentSpaceVectorsForSegment(Segment *seg)
{
coord_t const bottom = backSec->ceiling().visHeight();
coord_t const top = seg->sector().ceiling().visHeight();
Vector2d center = (seg->to().origin() + seg->from().origin()) / 2;
Vector2d center = (seg->hedge().twin().origin() + seg->hedge().origin()) / 2;
Surface *suf = &side.top();

Vector3d origin = Vector3d(center, bottom + (top - bottom) / 2);
Expand All @@ -3205,7 +3205,7 @@ static void drawTangentSpaceVectorsForSegment(Segment *seg)
{
coord_t const bottom = seg->sector().floor().visHeight();
coord_t const top = backSec->floor().visHeight();
Vector2d center = (seg->to().origin() + seg->from().origin()) / 2;
Vector2d center = (seg->hedge().twin().origin() + seg->hedge().origin()) / 2;
Surface *suf = &side.bottom();

Vector3d origin = Vector3d(center, bottom + (top - bottom) / 2);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/shadowedge.cpp
Expand Up @@ -126,7 +126,7 @@ void ShadowEdge::prepare(int planeIndex)
// there won't be a shadow at all. Open neighbor sectors cause some changes
// in the polygon corner vertices (placement, opacity).

if(d->leftMostSegment->hasBack() &&
if(d->leftMostSegment->hedge().twin().hasFace() &&
d->leftMostSegment->back().hasBspLeaf() &&
!d->leftMostSegment->back().bspLeaf().isDegenerate() &&
d->leftMostSegment->back().sectorPtr() != 0)
Expand Down
26 changes: 13 additions & 13 deletions doomsday/client/src/render/skyfixedge.cpp
Expand Up @@ -82,7 +82,7 @@ Vector3d SkyFixEdge::Event::origin() const

DENG2_PIMPL(SkyFixEdge)
{
Segment *segment;
HEdge *hedge;
FixType fixType;
int edge;

Expand All @@ -97,10 +97,10 @@ DENG2_PIMPL(SkyFixEdge)

Vector2f materialOrigin;

Instance(Public *i, Segment &segment, FixType fixType, int edge,
Instance(Public *i, HEdge &hedge, FixType fixType, int edge,
Vector2f const &materialOrigin)
: Base(i),
segment(&segment),
hedge(&hedge),
fixType(fixType),
edge(edge),
bottom(*i, 0),
Expand All @@ -114,16 +114,17 @@ DENG2_PIMPL(SkyFixEdge)
*/
bool wallSectionNeedsSkyFix() const
{
DENG_ASSERT(segment->hasBspLeaf());
DENG_ASSERT(hedge->hasFace() && hedge->mapElement() != 0);

bool const lower = fixType == SkyFixEdge::Lower;

Segment *segment = hedge->mapElement()->as<Segment>();

// Partition line segments have no map line sides.
if(!segment->hasLineSide()) return false;

Sector const *frontSec = segment->sectorPtr();
Sector const *backSec = segment->hasBack() && segment->back().hasBspLeaf() &&
!segment->back().bspLeaf().isDegenerate()? segment->back().sectorPtr() : 0;
Sector const *frontSec = hedge->face().mapElement()->as<BspLeaf>()->sectorPtr();
Sector const *backSec = hedge->twin().hasFace()? hedge->twin().face().mapElement()->as<BspLeaf>()->sectorPtr() : 0;

if(!(!backSec || backSec != frontSec)) return false;

Expand Down Expand Up @@ -172,9 +173,8 @@ DENG2_PIMPL(SkyFixEdge)
return;
}

Sector const *frontSec = segment->sectorPtr();
Sector const *backSec = segment->hasBack() && segment->back().hasBspLeaf() &&
!segment->back().bspLeaf().isDegenerate()? segment->back().sectorPtr() : 0;
Sector const *frontSec = hedge->face().mapElement()->as<BspLeaf>()->sectorPtr();
Sector const *backSec = hedge->twin().hasFace()? hedge->twin().face().mapElement()->as<BspLeaf>()->sectorPtr() : 0;
Plane const *ffloor = &frontSec->floor();
Plane const *fceil = &frontSec->ceiling();
Plane const *bceil = backSec? &backSec->ceiling() : 0;
Expand All @@ -200,9 +200,9 @@ DENG2_PIMPL(SkyFixEdge)
}
};

SkyFixEdge::SkyFixEdge(Segment &segment, FixType fixType, int edge, float materialOffsetS)
: WorldEdge((edge? segment.to() : segment.from()).origin()),
d(new Instance(this, segment, fixType, edge, Vector2f(materialOffsetS, 0)))
SkyFixEdge::SkyFixEdge(HEdge &hedge, FixType fixType, int edge, float materialOffsetS)
: WorldEdge((edge? hedge.twin() : hedge).origin()),
d(new Instance(this, hedge, fixType, edge, Vector2f(materialOffsetS, 0)))
{
/// @todo Defer until necessary.
d->prepare();
Expand Down
14 changes: 6 additions & 8 deletions doomsday/client/src/render/walledge.cpp
Expand Up @@ -496,14 +496,12 @@ DENG2_PIMPL(WallEdge), public IHPlane
}
};

WallEdge::WallEdge(WallSpec const &spec, Segment &segment, int edge)
: WorldEdge((edge? segment.to() : segment.from()).origin()),
d(new Instance(this, spec, &segment.lineSide(), edge,
segment.lineSideOffset() + (edge? segment.length() : 0),
segment.lineSide().line().vertexOwner(edge? segment.to() : segment.from())))
{
DENG_ASSERT(segment.hasLineSide() && segment.lineSide().hasSections());
}
WallEdge::WallEdge(WallSpec const &spec, HEdge &hedge, int edge)
: WorldEdge((edge? hedge.twin() : hedge).origin()),
d(new Instance(this, spec, &hedge.mapElement()->as<Segment>()->lineSide(), edge,
hedge.mapElement()->as<Segment>()->lineSideOffset() + (edge? hedge.mapElement()->as<Segment>()->length() : 0),
hedge.mapElement()->as<Segment>()->lineSide().line().vertexOwner(edge? hedge.twin().vertex() : hedge.vertex())))
{}

Vector3d const &WallEdge::pOrigin() const
{
Expand Down
6 changes: 0 additions & 6 deletions doomsday/client/src/world/bsp/convexsubspace.cpp
Expand Up @@ -441,9 +441,6 @@ void ConvexSubspace::buildGeometry(BspLeaf &leaf, Mesh &mesh) const

seg->setLength(Vector2d(lineSeg->to().origin() - lineSeg->from().origin()).length());

seg->setAngle(bamsAtan2(int( lineSeg->to().origin().y - lineSeg->from().origin().y ),
int( lineSeg->to().origin().x - lineSeg->from().origin().x )) << FRACBITS);

// Link the new half-edge for this line segment to the head of
// the list in the new face geometry.
hedge->setNext(face->hedge());
Expand Down Expand Up @@ -543,9 +540,6 @@ void ConvexSubspace::buildGeometry(BspLeaf &leaf, Mesh &mesh) const

seg->setLength(Vector2d(lineSeg->to().origin() - lineSeg->from().origin()).length());

seg->setAngle(bamsAtan2(int( lineSeg->to().origin().y - lineSeg->from().origin().y ),
int( lineSeg->to().origin().x - lineSeg->from().origin().x )) << FRACBITS);

// Link the new half-edge for this line segment to the head of
// the list in the new Face geometry.
hedge->setNext(face->hedge());
Expand Down
5 changes: 2 additions & 3 deletions doomsday/client/src/world/line.cpp
Expand Up @@ -165,11 +165,10 @@ bool Line::Side::considerOneSided() const
return true;

Segment &segment = *d->leftSegment;
if(!segment.hasBack() || !segment.back().hasBspLeaf())
if(!segment.hedge().twin().hasFace())
return true;

BspLeaf &backLeaf = segment.back().bspLeaf();
if(!backLeaf.hasSector() || backLeaf.isDegenerate())
if(!segment.hedge().twin().face().mapElement()->as<BspLeaf>()->hasSector())
return true;
}

Expand Down
6 changes: 0 additions & 6 deletions doomsday/client/src/world/polyobj.cpp
Expand Up @@ -449,9 +449,6 @@ bool Polyobj::rotate(angle_t delta)
{
line->updateAABox();
line->updateSlopeType();

// Segment angle must be kept in sync.
line->front().leftSegment()->setAngle(BANG_TO_ANGLE(line->angle()));
}
updateAABox();
angle += delta;
Expand All @@ -476,9 +473,6 @@ bool Polyobj::rotate(angle_t delta)
{
line->updateAABox();
line->updateSlopeType();

// Segment angle must be kept in sync.
line->front().leftSegment()->setAngle(BANG_TO_ANGLE(line->angle()));
}
updateAABox();
angle -= delta;
Expand Down

0 comments on commit 2e21bad

Please sign in to comment.