Skip to content

Commit

Permalink
Refactor|Map Renderer: Consolidated more map geometry construction logic
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Apr 17, 2013
1 parent d8dab9f commit e946848
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 77 deletions.
22 changes: 14 additions & 8 deletions doomsday/client/include/map/r_world.h
Expand Up @@ -160,19 +160,25 @@ coord_t R_VisOpenRange(Line const &line, int side, coord_t *bottom, coord_t *top
*
* @return @c true iff Line::Side @a front has a "middle" Material which completely
* covers the open range defined by sectors @a frontSec and @a backSec.
*
* @note Anything calling this is likely working at the wrong level (should work with
* half-edges instead).
*/
boolean R_MiddleMaterialCoversOpening(int lineFlags, Sector const *frontSec,
bool R_MiddleMaterialCoversOpening(int lineFlags, Sector const *frontSec,
Sector const *backSec, Line::Side const *front, Line::Side const *back,
boolean ignoreOpacity = true);
bool ignoreOpacity = false);

/**
* Same as @ref R_MiddleMaterialCoversOpening except all arguments are derived from
* the specified line @a line.
*
* @note Anything calling this is likely working at the wrong level (should work with
* hedges instead).
* Same as @ref R_MiddleMaterialCoversOpening() except all arguments are derived from
* the specified line @a side.
*/
boolean R_MiddleMaterialCoversLineOpening(Line const *line, int side, boolean ignoreOpacity);
inline bool R_MiddleMaterialCoversLineOpening(Line::Side const &side,
bool ignoreOpacity = false)
{
return R_MiddleMaterialCoversOpening(side.line().flags(), side.sectorPtr(), side.back().sectorPtr(),
&side, &side.back(), ignoreOpacity);
}

#endif // __CLIENT__

void R_UpdateSector(Sector &sector, bool forceUpdate = false);
Expand Down
3 changes: 1 addition & 2 deletions doomsday/client/src/map/p_objlink.cpp
Expand Up @@ -384,8 +384,7 @@ static void processSeg(HEdge *hedge, void *parameters)

if(backSec && !back.hasSections()) return; // One-sided window.

if(R_MiddleMaterialCoversOpening(line.flags(), frontSec, backSec, &front, &back,
false /*do not ignore material opacity*/)) return;
if(R_MiddleMaterialCoversOpening(line.flags(), frontSec, backSec, &front, &back)) return;
}

// During next step, obj will continue spreading from there.
Expand Down
19 changes: 5 additions & 14 deletions doomsday/client/src/map/r_world.cpp
Expand Up @@ -316,9 +316,9 @@ coord_t R_VisOpenRange(Line const &line, int side, coord_t *bottom, coord_t *top
}

#ifdef __CLIENT__
boolean R_MiddleMaterialCoversOpening(int lineFlags, Sector const *frontSec,
bool R_MiddleMaterialCoversOpening(int lineFlags, Sector const *frontSec,
Sector const *backSec, Line::Side const *front, Line::Side const *back,
boolean ignoreOpacity)
bool ignoreOpacity)
{
if(!frontSec || !front || !front->hasSections()) return false; // Never.

Expand All @@ -332,7 +332,8 @@ boolean R_MiddleMaterialCoversOpening(int lineFlags, Sector const *frontSec,
coord_t openRange, openBottom, openTop;

// Stretched middles always cover the opening.
if(front->isFlagged(SDF_MIDDLE_STRETCH)) return true;
if(front->isFlagged(SDF_MIDDLE_STRETCH))
return true;

// Might the material cover the opening?
openRange = R_VisOpenRange(frontSec, backSec, &openBottom, &openTop);
Expand All @@ -351,16 +352,6 @@ boolean R_MiddleMaterialCoversOpening(int lineFlags, Sector const *frontSec,
return false;
}

boolean R_MiddleMaterialCoversLineOpening(Line const *line, int side, boolean ignoreOpacity)
{
DENG_ASSERT(line != 0);
Sector const *frontSec = line->sectorPtr(side);
Sector const *backSec = line->sectorPtr(side ^ 1);
Line::Side const &front = line->side(side);
Line::Side const &back = line->side(side ^ 1);
return R_MiddleMaterialCoversOpening(line->flags(), frontSec, backSec, &front, &back, ignoreOpacity);
}

Line *R_FindLineNeighbor(Sector const *sector, Line const *line,
LineOwner const *own, bool antiClockwise, binangle_t *diff)
{
Expand Down Expand Up @@ -442,7 +433,7 @@ Line *R_FindSolidLineNeighbor(Sector const *sector, Line const *line,
oFCeil > sector->floor().visHeight()))) )
{

if(!R_MiddleMaterialCoversLineOpening(other, side, false))
if(!R_MiddleMaterialCoversLineOpening(other->side(side)))
return 0;
}
}
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/render/rend_fakeradio.cpp
Expand Up @@ -385,7 +385,7 @@ static void scanNeighbors(shadowcorner_t top[2], shadowcorner_t bottom[2],

for(uint i = 0; i < 2; ++i)
{
shadowcorner_t *corner = (i == 0 ? &bottom[!toLeft] : &top[(int)!toLeft]);
shadowcorner_t *corner = (i == 0 ? &bottom[(int)!toLeft] : &top[(int)!toLeft]);
edge_t *edge = &edges[i];
edgespan_t *span = &spans[i];

Expand Down Expand Up @@ -1224,7 +1224,7 @@ static uint radioEdgeHackType(Line const *line, Sector const *front, Sector cons
// Check for unmasked midtextures on twosided lines that completely
// fill the gap between floor and ceiling (we don't want to give away
// the location of any secret areas (false walls)).
if(R_MiddleMaterialCoversLineOpening(const_cast<Line *>(line), backside, false))
if(R_MiddleMaterialCoversLineOpening(line->side(backside)))
return 1; // Consider it fully closed.

return 0;
Expand Down Expand Up @@ -1372,10 +1372,10 @@ static void processEdgeShadow(BspLeaf const &bspLeaf, Line const *line,
}
else if(!(neighbor == line || !neighbor->hasBackSections()))
{
byte otherSide = (&line->vertex(i^side) == &neighbor->v1()? i : i^1);
int otherSide = (&line->vertex(i ^ side) == &neighbor->v1()? i : i ^ 1);
Sector *othersec = neighbor->sectorPtr(otherSide);

if(R_MiddleMaterialCoversLineOpening(neighbor, otherSide^1, false))
if(R_MiddleMaterialCoversLineOpening(neighbor->side(otherSide ^ 1)))
{
sideOpen[i] = 0;
}
Expand Down
68 changes: 19 additions & 49 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -1545,44 +1545,44 @@ static void writePlane(Plane::Type type, coord_t height,
}
}

static float calcLightLevelDelta(Vector3f const &normal)
{
return (1.0f / 255) * (normal.x * 18) * rendLightWallAngle;
}

/**
* @param side Line::Side instance.
* @param ignoreOpacity @c true= do not consider Material opacity.
* @return @c true if this Line's side is considered "closed" (i.e.,
* there is no opening through which the back Sector can be seen).
* Tests consider all Planes which interface with this and the "middle"
* Material used on the relative front side (if any).
*
* @return @c true if this side is considered "closed" (i.e., there is no opening
* through which the relative back Sector can be seen). Tests consider all Planes
* which interface with this and the "middle" Material used on the "this" side.
*/
static bool sideBackClosedForBlend(Line::Side const &side, bool ignoreOpacity = true)
static bool sideBackClosed(Line::Side const &side, bool ignoreOpacity = true)
{
if(!side.hasSections()) return false;
if(!side.back().hasSections()) return true;
if(side.line().isSelfReferencing()) return false; // Never.

if(side.hasSector() && side.back().hasSector())
{
Sector const *frontSec = side.sectorPtr();
Sector const *backSec = side.back().sectorPtr();
Sector const &frontSec = side.sector();
Sector const &backSec = side.back().sector();

if(backSec->floor().visHeight() >= backSec->ceiling().visHeight()) return true;
if(backSec->ceiling().visHeight() <= frontSec->floor().visHeight()) return true;
if(backSec->floor().visHeight() >= frontSec->ceiling().visHeight()) return true;
if(backSec.floor().visHeight() >= backSec.ceiling().visHeight()) return true;
if(backSec.ceiling().visHeight() <= frontSec.floor().visHeight()) return true;
if(backSec.floor().visHeight() >= frontSec.ceiling().visHeight()) return true;
}

return R_MiddleMaterialCoversLineOpening(&side.line(), side.lineSideId(), ignoreOpacity);
return R_MiddleMaterialCoversLineOpening(side, ignoreOpacity);
}

static float calcLightLevelDelta(Vector3f const &normal)
{
return (1.0f / 255) * (normal.x * 18) * rendLightWallAngle;
}

static Line::Side *findSideBlendNeighbor(Line::Side const &side, bool right, binangle_t *diff = 0)
{
LineOwner const *farVertOwner = side.line().vertexOwner((int)right ^ side.lineSideId());
LineOwner const *farVertOwner = side.line().vertexOwner(side.lineSideId() ^ (int)right);

Line *neighbor;
if(sideBackClosedForBlend(side))
if(sideBackClosed(side))
{
neighbor = R_FindSolidLineNeighbor(side.sectorPtr(), &side.line(), farVertOwner, right, diff);
}
Expand Down Expand Up @@ -2244,36 +2244,6 @@ static void skyFixZCoords(HEdge *hedge, int skyCap, coord_t *bottom, coord_t *to
}
}

/**
* @return @c true if this half-edge is considered "closed" (i.e.,
* there is no opening through which the back Sector can be seen).
* Tests consider all Planes which interface with this and the "middle"
* Material used on the relative front side (if any).
*/
static bool hedgeBackClosedForSkyFix(HEdge const &hedge)
{
Line const &line = hedge.line();
Line::Side const &front = line.side(hedge.lineSideId());
Line::Side const &back = line.side(hedge.lineSideId()^1);
Sector const *frontSec = line.sectorPtr(hedge.lineSideId());
Sector const *backSec = line.sectorPtr(hedge.lineSideId()^1);

if(!front.hasSections()) return false;
if(!back.hasSections()) return true;

if(frontSec == backSec) return false; // Never.

if(frontSec && backSec)
{
if(backSec->floor().visHeight() >= backSec->ceiling().visHeight()) return true;
if(backSec->ceiling().visHeight() <= frontSec->floor().visHeight()) return true;
if(backSec->floor().visHeight() >= frontSec->ceiling().visHeight()) return true;
}

return R_MiddleMaterialCoversOpening(line.flags(), frontSec, backSec, &front, &back,
false/*don't ignore opacity*/);
}

/**
* Determine which sky fixes are necessary for the specified @a hedge.
* @param hedge HEdge to be evaluated.
Expand All @@ -2296,7 +2266,7 @@ static int chooseHEdgeSkyFixes(HEdge *hedge, int skyCap)

if(hasSkyFloor || hasSkyCeiling)
{
bool const hasClosedBack = hedgeBackClosedForSkyFix(*hedge);
bool const hasClosedBack = sideBackClosed(hedge->lineSide());

// Lower fix?
if(hasSkyFloor && (skyCap & SKYCAP_LOWER))
Expand Down

0 comments on commit e946848

Please sign in to comment.