Skip to content

Commit

Permalink
Refactor|Map Renderer: Consolidated more geometry construction logic
Browse files Browse the repository at this point in the history
Also fixed a bunch of id Tech 1 map hacks in the process.
  • Loading branch information
danij-deng committed May 10, 2013
1 parent 0fe52f3 commit 13fb5b1
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 139 deletions.
13 changes: 0 additions & 13 deletions doomsday/client/include/map/hedge.h
Expand Up @@ -255,19 +255,6 @@ class HEdge : public de::MapElement
/// Variant of @ref bspLeafSector() which returns a pointer.
inline Sector *bspLeafSectorPtr() const { return bspLeaf().sectorPtr(); }

/**
* Determines the side relative sector to be used for producing wall
* section geometry. Takes into account doom.exe map hack constructs.
* Also suitable for Polyobj lines.
*
* @pre A map line side is attributed (@ref hasLineSide()).
*
* @param side If non-zero return the back sector; otherwise the front.
*
* @return Map sector for the specified side. Can be @c 0.
*/
Sector *wallSectionSector(int side = Front) const;

/**
* Returns @c true iff a Line::Side is attributed to the half-edge.
*/
Expand Down
18 changes: 2 additions & 16 deletions doomsday/client/include/map/r_world.h
Expand Up @@ -40,28 +40,14 @@ extern boolean ddMapSetup;
*
* @param side Line side to determine Z heights for.
* @param section Line::Side section to determine coordinates for.
* @param frontSec Sector in front of the wall.
* @param backSec Sector behind the wall. Can be @c NULL
*
* Return values:
* @param bottom Z map space coordinate at the bottom of the wall section. Can be @c 0.
* @param top Z map space coordinate at the top of the wall section. Can be @c 0.
* @param materialOrigin Surface space material coordinate offset. Can be @c 0.
*/
void R_SideSectionCoords(Line::Side const &side, int section, Sector const *frontSec,
Sector const *backSec, coord_t *bottom = 0, coord_t *top = 0,
de::Vector2f *materialOrigin = 0);

/**
* Same as @ref R_SideSectionCoords() except that the sector arguments are taken from
* the specified line @a side.
*/
inline void R_SideSectionCoords(Line::Side const &side, int section, coord_t *bottom = 0,
coord_t *top = 0, de::Vector2f *materialOrigin = 0)
{
R_SideSectionCoords(side, section, side.sectorPtr(), side.back().sectorPtr(),
bottom, top, materialOrigin);
}
void R_SideSectionCoords(Line::Side const &side, int section,
coord_t *bottom = 0, coord_t *top = 0, de::Vector2f *materialOrigin = 0);

/**
* Find the "sharp" Z coordinate range of the opening between sectors @a frontSec
Expand Down
3 changes: 1 addition & 2 deletions doomsday/client/include/map/sectionedge.h
Expand Up @@ -64,8 +64,7 @@ class SectionEdge

public:
SectionEdge(Line::Side &lineSide, int section, coord_t lineOffset,
Vertex &lineVertex, ClockDirection neighborScanDirection,
Sector *frontSec, Sector *backSec);
Vertex &lineVertex, ClockDirection neighborScanDirection);

SectionEdge(HEdge &hedge, int section, int edge);

Expand Down
4 changes: 1 addition & 3 deletions doomsday/client/include/render/rend_fakeradio.h
Expand Up @@ -148,11 +148,9 @@ float Rend_RadioCalcShadowDarkness(float lightLevel);
* @param rightEdge Geometry for the right edge of the wall section.
* @param shadowDark Shadow darkness scale factor.
* @param shadowSize Shadow size scale factor.
* @param frontSec @todo refactor away
* @param backSec @todo refactor away
*/
void Rend_RadioWallSection(SectionEdge const &leftEdge, SectionEdge const &rightEdge,
float shadowDark, float shadowSize, Sector *frontSec, Sector *backSec);
float shadowDark, float shadowSize);

/**
* Render FakeRadio for the given BSP leaf. Draws all shadow geometry linked to the
Expand Down
8 changes: 2 additions & 6 deletions doomsday/client/src/map/gamemap.cpp
Expand Up @@ -333,16 +333,12 @@ DENG2_PIMPL(GameMap)
if(!side->hasSections()) continue;
if(!side->middle().hasMaterial()) continue;

HEdge const *hedge = side->leftHEdge();
Sector const *frontSec = hedge->wallSectionSector(HEdge::Front);
Sector const *backSec = hedge->wallSectionSector(HEdge::Back);

// There must be a sector on both sides.
if(!frontSec || !backSec) continue;
if(!side->hasSector() || !side->back().hasSector()) continue;

coord_t bottomZ, topZ;
Vector2f materialOrigin;
R_SideSectionCoords(*side, Line::Side::Middle, frontSec, backSec,
R_SideSectionCoords(*side, Line::Side::Middle,
&bottomZ, &topZ, &materialOrigin);
if(skyCeil && topZ + materialOrigin.y > self.skyFixCeiling())
{
Expand Down
24 changes: 0 additions & 24 deletions doomsday/client/src/map/hedge.cpp
Expand Up @@ -174,30 +174,6 @@ coord_t HEdge::length() const
return _length;
}

Sector *HEdge::wallSectionSector(int side) const
{
if(!d->lineSide)
/// @throw MissingLineError Attempted with no line attributed.
throw MissingLineSideError("HEdge::wallSectionSector", "No line.side is attributed");

Line::Side const &mapSide = *d->lineSide;
if(mapSide.line().isFromPolyobj())
{
if(side == Front) return bspLeaf().sectorPtr();
return 0;
}

if(!mapSide.line().isSelfReferencing())
{
if(side == Front) return bspLeaf().sectorPtr();
return hasTwin()? twin().bspLeaf().sectorPtr() : 0;
}

// Special case: so called "self-referencing" lines should use the
// sector of the map line side.
return mapSide.sectorPtr();
}

HEdge::Flags HEdge::flags() const
{
return _flags;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/map/p_objlink.cpp
Expand Up @@ -398,7 +398,7 @@ static void processHEdge(HEdge *hedge, void *parameters)
{
// Possibly; check the placement.
coord_t bottom, top;
R_SideSectionCoords(side, Line::Side::Middle, frontSec, backSec, &bottom, &top);
R_SideSectionCoords(side, Line::Side::Middle, &bottom, &top);
if(top > bottom && top >= openTop && bottom <= openBottom)
return;
}
Expand Down
33 changes: 27 additions & 6 deletions doomsday/client/src/map/r_world.cpp
Expand Up @@ -67,10 +67,11 @@ DENG_EXTERN_C void R_SetupFogDefaults()
}

void R_SideSectionCoords(Line::Side const &side, int section,
Sector const *frontSec, Sector const *backSec,
coord_t *retBottom, coord_t *retTop, Vector2f *retMaterialOrigin)
{
Line const &line = side.line();
Sector const *frontSec = side.sectorPtr();
Sector const *backSec = side.back().sectorPtr();
Line const &line = side.line();
bool const unpegBottom = (line.flags() & DDLF_DONTPEGBOTTOM) != 0;
bool const unpegTop = (line.flags() & DDLF_DONTPEGTOP) != 0;

Expand Down Expand Up @@ -156,8 +157,16 @@ void R_SideSectionCoords(Line::Side const &side, int section,
break; }

case Line::Side::Middle:
bottom = de::max(bfloor->visHeight(), ffloor->visHeight());
top = de::min(bceil->visHeight(), fceil->visHeight());
if(!side.line().isSelfReferencing())
{
bottom = de::max(bfloor->visHeight(), ffloor->visHeight());
top = de::min(bceil->visHeight(), fceil->visHeight());
}
else
{
bottom = ffloor->visHeight();
top = bceil->visHeight();
}

if(retMaterialOrigin)
{
Expand All @@ -175,8 +184,20 @@ void R_SideSectionCoords(Line::Side const &side, int section,
bool const clipTop = !(fceil->surface().hasSkyMaskedMaterial() && bceil->surface().hasSkyMaskedMaterial());
#endif

coord_t const openBottom = bottom;
coord_t const openTop = top;
HEdge &hedge = *side.leftHEdge();

coord_t openBottom, openTop;
if(!side.line().isSelfReferencing())
{
openBottom = bottom;
openTop = top;
}
else
{
openBottom = hedge.bspLeaf().sector().floor().visHeight();
openTop = hedge.bspLeaf().sector().ceiling().visHeight();
}

int const matHeight = surface->material().height();
coord_t const matYOffset = surface->visMaterialOrigin().y;

Expand Down
22 changes: 6 additions & 16 deletions doomsday/client/src/map/sectionedge.cpp
Expand Up @@ -55,8 +55,6 @@ DENG2_PIMPL(SectionEdge), public IHPlane
ClockDirection neighborScanDirection;
coord_t lineOffset;
Vertex *lineVertex;
Sector *frontSec;
Sector *backSec;

bool isValid;
Vector2f materialOrigin;
Expand All @@ -83,16 +81,14 @@ DENG2_PIMPL(SectionEdge), public IHPlane
} hplane;

Instance(Public *i, Line::Side *lineSide, int section,
ClockDirection neighborScanDirection, coord_t lineOffset,
Vertex *lineVertex, Sector *frontSec, Sector *backSec)
ClockDirection neighborScanDirection,
coord_t lineOffset, Vertex *lineVertex)
: Base(i),
lineSide(lineSide),
section(section),
neighborScanDirection(neighborScanDirection),
lineOffset(lineOffset),
lineVertex(lineVertex),
frontSec(frontSec),
backSec(backSec),
isValid(false)
{}

Expand All @@ -103,8 +99,6 @@ DENG2_PIMPL(SectionEdge), public IHPlane
neighborScanDirection(other.neighborScanDirection),
lineOffset (other.lineOffset),
lineVertex (other.lineVertex),
frontSec (other.frontSec),
backSec (other.backSec),
isValid (other.isValid),
materialOrigin (other.materialOrigin),
hplane (other.hplane)
Expand Down Expand Up @@ -327,10 +321,9 @@ DENG2_PIMPL(SectionEdge), public IHPlane
};

SectionEdge::SectionEdge(Line::Side &lineSide, int section,
coord_t lineOffset, Vertex &lineVertex, ClockDirection neighborScanDirection,
Sector *frontSec, Sector *backSec)
coord_t lineOffset, Vertex &lineVertex, ClockDirection neighborScanDirection)
: d(new Instance(this, &lineSide, section, neighborScanDirection,
lineOffset, &lineVertex, frontSec, backSec))
lineOffset, &lineVertex))
{
DENG_ASSERT(lineSide.hasSections());
}
Expand All @@ -339,9 +332,7 @@ SectionEdge::SectionEdge(HEdge &hedge, int section, int edge)
: d(new Instance(this, &hedge.lineSide(), section,
edge? Anticlockwise : Clockwise,
hedge.lineOffset() + (edge? hedge.length() : 0),
&hedge.vertex(edge),
hedge.wallSectionSector(),
hedge.wallSectionSector(HEdge::Back)))
&hedge.vertex(edge)))
{
DENG_ASSERT(hedge.hasLineSide() && hedge.lineSide().hasSections());
}
Expand Down Expand Up @@ -418,8 +409,7 @@ Vector2f const &SectionEdge::materialOrigin() const
void SectionEdge::prepare()
{
coord_t bottom, top;
R_SideSectionCoords(*d->lineSide, d->section, d->frontSec, d->backSec,
&bottom, &top, &d->materialOrigin);
R_SideSectionCoords(*d->lineSide, d->section, &bottom, &top, &d->materialOrigin);

d->isValid = (top >= bottom);
if(!d->isValid) return;
Expand Down
6 changes: 5 additions & 1 deletion doomsday/client/src/render/rend_fakeradio.cpp
Expand Up @@ -1074,14 +1074,18 @@ static void drawWallSectionShadow(rvertex_t const *origVertices,
}

void Rend_RadioWallSection(SectionEdge const &leftEdge, SectionEdge const &rightEdge,
float shadowDark, float shadowSize, Sector *frontSec, Sector *backSec)
float shadowDark, float shadowSize)
{
// Disabled?
if(!rendFakeRadio || levelFullBright) return;

if(shadowSize <= 0) return;

Line::Side &side = leftEdge.lineSide();
HEdge const *hedge = side.leftHEdge();
Sector const *frontSec = hedge->bspLeafSectorPtr();
Sector const *backSec = hedge->hasTwin() && leftEdge.section() != Line::Side::Middle? hedge->twin().bspLeafSectorPtr() : 0;

coord_t const lineLength = side.line().length();
coord_t const sectionOffset = leftEdge.lineOffset();
coord_t const sectionWidth = de::abs(Vector2d(rightEdge.origin() - leftEdge.origin()).length());
Expand Down
75 changes: 24 additions & 51 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -1645,21 +1645,7 @@ static bool writeWallSection(SectionEdge const &leftEdge, SectionEdge const &rig
float shadowSize = 2 * (8 + 16 - currentSectorLightLevel * 16);
float shadowDark = Rend_RadioCalcShadowDarkness(currentSectorLightLevel);

Sector *frontSec = 0, *backSec = 0;
{
HEdge *hedge = mapElement.castTo<HEdge>();
frontSec = hedge->wallSectionSector();
if(hedge->hasTwin() && !isTwoSidedMiddle)
{
if(hedge->twin().hasLineSide() && hedge->twin().lineSide().hasSector())
{
backSec = hedge->twin().bspLeaf().sectorPtr();
}
}
}

Rend_RadioWallSection(leftEdge, rightEdge, shadowDark, shadowSize,
frontSec, backSec);
Rend_RadioWallSection(leftEdge, rightEdge, shadowDark, shadowSize);
}
}

Expand Down Expand Up @@ -2308,28 +2294,19 @@ static bool coveredOpenRangeTwoSided(HEdge &hedge,
if(hedge.line().isSelfReferencing())
return false; /// @todo Why? -ds

Sector const &frontSec = hedge.bspLeaf().sector();
Sector const &backSec = hedge.twin().bspLeaf().sector();

bool middleCoversOpening = false;
if(wroteOpaqueMiddle)
{
Sector *frontSec = hedge.wallSectionSector();
Sector *backSec = hedge.wallSectionSector(HEdge::Back);
coord_t const ffloor = frontSec.floor().visHeight();
coord_t const fceil = frontSec.ceiling().visHeight();
coord_t const bfloor = backSec.floor().visHeight();
coord_t const bceil = backSec.ceiling().visHeight();

coord_t const ffloor = frontSec->floor().visHeight();
coord_t const fceil = frontSec->ceiling().visHeight();
coord_t const bfloor = backSec->floor().visHeight();
coord_t const bceil = backSec->ceiling().visHeight();

coord_t xbottom, xtop;
if(hedge.line().isSelfReferencing())
{
xbottom = de::min(bfloor, ffloor);
xtop = de::max(bceil, fceil);
}
else
{
xbottom = de::max(bfloor, ffloor);
xtop = de::min(bceil, fceil);
}
coord_t xbottom = de::max(bfloor, ffloor);
coord_t xtop = de::min(bceil, fceil);

Surface const &middle = hedge.lineSide().middle();
xbottom += middle.visMaterialOrigin().y;
Expand All @@ -2342,26 +2319,22 @@ static bool coveredOpenRangeTwoSided(HEdge &hedge,
if(wroteOpaqueMiddle && middleCoversOpening)
return true;

// We'll have to determine whether we can...
Sector *frontSec = hedge.wallSectionSector();
Sector *backSec = hedge.wallSectionSector(HEdge::Back);

Line::Side const &front = hedge.lineSide();

coord_t const ffloor = frontSec->floor().visHeight();
coord_t const fceil = frontSec->ceiling().visHeight();
coord_t const bfloor = backSec->floor().visHeight();
coord_t const bceil = backSec->ceiling().visHeight();
coord_t const ffloor = frontSec.floor().visHeight();
coord_t const fceil = frontSec.ceiling().visHeight();
coord_t const bfloor = backSec.floor().visHeight();
coord_t const bceil = backSec.ceiling().visHeight();

if( (bceil <= ffloor &&
(front.top().hasMaterial() || front.middle().hasMaterial()))
|| (bfloor >= fceil &&
(front.bottom().hasMaterial() || front.middle().hasMaterial())))
{
Surface const &ffloorSurface = frontSec->floor().surface();
Surface const &fceilSurface = frontSec->ceiling().surface();
Surface const &bfloorSurface = backSec->floor().surface();
Surface const &bceilSurface = backSec->ceiling().surface();
Surface const &ffloorSurface = frontSec.floor().surface();
Surface const &fceilSurface = frontSec.ceiling().surface();
Surface const &bfloorSurface = backSec.floor().surface();
Surface const &bceilSurface = backSec.ceiling().surface();

// A closed gap?
if(de::fequal(fceil, bfloor))
Expand Down Expand Up @@ -2430,12 +2403,12 @@ static int pvisibleWallSections(HEdge &hedge, bool &twoSided)
}

// Regular two-sided.
Sector *frontSec = hedge.wallSectionSector(HEdge::Front);
Sector *backSec = hedge.wallSectionSector(HEdge::Back);
Plane const &fceil = frontSec->ceiling();
Plane const &ffloor = frontSec->floor();
Plane const &bceil = backSec->ceiling();
Plane const &bfloor = backSec->floor();
Sector const &frontSec = hedge.bspLeaf().sector();
Sector const &backSec = hedge.twin().bspLeaf().sector();
Plane const &fceil = frontSec.ceiling();
Plane const &ffloor = frontSec.floor();
Plane const &bceil = backSec.ceiling();
Plane const &bfloor = backSec.floor();

int sections = 0;

Expand Down

0 comments on commit 13fb5b1

Please sign in to comment.