Skip to content

Commit

Permalink
HEdge: Moved wallSectionSectors() logic into HEdge
Browse files Browse the repository at this point in the history
Plus a wall section draw state optimization.
  • Loading branch information
danij-deng committed May 2, 2013
1 parent ccad74c commit 54f4ca1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 41 deletions.
11 changes: 11 additions & 0 deletions doomsday/client/include/map/hedge.h
Expand Up @@ -378,6 +378,17 @@ class HEdge : public de::MapElement
return pointOnSide(point);
}

/**
* Determines the side relative sectors for producing wall section geometry.
*
* @pre A map line side is attributed (@ref hasLineSide()).
*
* Return values:
* @param frontSec Front sector for the wall section is written here. Can be @c 0.
* @param backSec Back sector for the wall section is written here. Can be @c 0.
*/
void wallSectionSectors(Sector **frontSec = 0, Sector **backSec = 0) const;

/**
* Retrieve the bias surface for specified geometry @a groupId
*
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/render/rend_fakeradio.h
Expand Up @@ -158,7 +158,7 @@ struct RendRadioWallSectionParms
coord_t segOffset;
coord_t segLength;
Line const *line;
Sector const *frontSec, *backSec;
Sector *frontSec, *backSec;
SectionEdge const *leftEdge;
SectionEdge const *rightEdge;
};
Expand Down
25 changes: 25 additions & 0 deletions doomsday/client/src/map/hedge.cpp
Expand Up @@ -174,6 +174,31 @@ coord_t HEdge::length() const
return _length;
}

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

if(d->lineSide->line().isFromPolyobj())
{
if(frontSec) *frontSec = bspLeaf().sectorPtr();
if(backSec) *backSec = 0;
return;
}

if(!d->lineSide->line().isSelfReferencing())
{
if(frontSec) *frontSec = bspLeaf().sectorPtr();
if(backSec) *backSec = hasTwin()? twin().bspLeaf().sectorPtr() : 0;
return;
}

// Special case: so called "self-referencing" lines use the sector's of the map line.
if(frontSec) *frontSec = d->lineSide->sectorPtr();
if(backSec) *backSec = d->lineSide->sectorPtr();
}

biassurface_t &HEdge::biasSurfaceForGeometryGroup(uint groupId)
{
if(groupId <= Line::Side::Top)
Expand Down
49 changes: 9 additions & 40 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -1715,14 +1715,14 @@ static bool writeWallSection(SectionEdge const &leftEdge, SectionEdge const &rig
// Dynamic Lights?
if(flags & WSF_ADD_DYNLIGHTS)
{
lightListIdx = projectSurfaceLights(side.middle(), glowStrength, texTL, texBR,
lightListIdx = projectSurfaceLights(surface, glowStrength, texTL, texBR,
(section == Line::Side::Middle && isTwoSided));
}

// Dynamic shadows?
if(flags & WSF_ADD_DYNSHADOWS)
{
shadowListIdx = projectSurfaceShadows(side.middle(), glowStrength, texTL, texBR);
shadowListIdx = projectSurfaceShadows(surface, glowStrength, texTL, texBR);
}

if(glowStrength > 0)
Expand All @@ -1748,7 +1748,8 @@ static bool writeWallSection(SectionEdge const &leftEdge, SectionEdge const &rig
deltaL += (sectionOffset / lineLength) * deltaDiff;
}

if(section == Line::Side::Middle && isTwoSided)
if(section == Line::Side::Middle && isTwoSided &&
side.sectorPtr() != currentBspLeaf->sectorPtr())
{
// Temporarily modify the draw state.
currentSectorLightColor = R_GetSectorLightColor(side.sector());
Expand Down Expand Up @@ -1840,7 +1841,8 @@ static bool writeWallSection(SectionEdge const &leftEdge, SectionEdge const &rig

radioParms.segOffset = leftEdge.offset();
radioParms.segLength = width;
radioParms.frontSec = bspLeaf->sectorPtr();

leftEdge.hedge().wallSectionSectors(&radioParms.frontSec);

radioParms.leftEdge = parm.wall.leftEdge;
radioParms.rightEdge = parm.wall.rightEdge;
Expand Down Expand Up @@ -1899,7 +1901,8 @@ static bool writeWallSection(SectionEdge const &leftEdge, SectionEdge const &rig
}
}

if(section == Line::Side::Middle && isTwoSided)
if(section == Line::Side::Middle && isTwoSided &&
side.sectorPtr() != currentBspLeaf->sectorPtr())
{
// Undo temporary draw state changes.
currentSectorLightColor = R_GetSectorLightColor(currentBspLeaf->sector());
Expand All @@ -1911,40 +1914,6 @@ static bool writeWallSection(SectionEdge const &leftEdge, SectionEdge const &rig
return opaque && !didNearBlend;
}

/**
* Determines the side relative sectors for producing wall section geometry.
*
* @pre @a hedge has an attributed map line side.
*
* @param hedge Half-edge describing the map line segment.
*
* Return values:
* @param frontSec Front sector for the wall section is written here. Can be @c 0.
* @param backSec Back sector for the wall section is written here. Can be @c 0.
*/
static void wallSectionSectors(HEdge &hedge, Sector **frontSec, Sector **backSec)
{
DENG_ASSERT(hedge.hasLineSide());

if(hedge.line().isFromPolyobj())
{
if(frontSec) *frontSec = hedge.bspLeaf().sectorPtr();
if(backSec) *backSec = 0;
return;
}

if(!hedge.line().isSelfReferencing())
{
if(frontSec) *frontSec = hedge.bspLeafSectorPtr();
if(backSec) *backSec = hedge.hasTwin()? hedge.twin().bspLeafSectorPtr() : 0;
return;
}

// Special case: so called "self-referencing" lines use the sector's of the map line.
if(frontSec) *frontSec = hedge.lineSide().sectorPtr();
if(backSec) *backSec = hedge.lineSide().sectorPtr();
}

/**
* Prepare wall section edge data for a map line segment.
*
Expand All @@ -1962,7 +1931,7 @@ static bool prepareWallSectionEdges(SectionEdge &leftEdge, SectionEdge &rightEdg
int const section = leftEdge.section();

Sector *frontSec, *backSec;
wallSectionSectors(hedge, &frontSec, &backSec);
hedge.wallSectionSectors(&frontSec, &backSec);

coord_t bottom, top;
bool visible = R_SideSectionCoords(hedge.lineSide(), section, frontSec, backSec,
Expand Down

0 comments on commit 54f4ca1

Please sign in to comment.