Skip to content

Commit

Permalink
Refactor|Map Renderer: Began extracting geometry construction from th…
Browse files Browse the repository at this point in the history
…e map renderer
  • Loading branch information
danij-deng committed Apr 18, 2013
1 parent 13c0af7 commit 2f3c4eb
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 256 deletions.
62 changes: 47 additions & 15 deletions doomsday/client/include/map/bspleaf.h
Expand Up @@ -124,6 +124,12 @@ class BspLeaf : public de::MapElement
*/
uint hedgeCount() const;

/**
* Returns @c true iff the BSP leaf is "degenerate", which is to say it is
* composed of fewer than @em three half-edges.
*/
inline bool isDegenerate() const { return hedgeCount() < 3; }

/**
* Returns @c true iff a sector is attributed to the BSP leaf. The only time
* a leaf might not be attributed to a sector is if the leaf was @em orphaned
Expand Down Expand Up @@ -154,6 +160,20 @@ class BspLeaf : public de::MapElement
*/
void setSector(Sector *newSector);

/**
* Determines whether the BSP leaf has a positive world volume. For this to
* be true the following criteria must be met:
*
* - The leaf is @em not degenerate (see @ref isDegenerate()).
* - A sector is attributed (see @ref hasSector())
* - The height of floor is lower than that of the ceiling plane for the
* attributed sector.
*
* @param useVisualHeights @c true= use the visual (i.e., smoothed) plane
* heights instead of the @em sharp heights.
*/
bool hasWorldVolume(bool useVisualHeights = true) const;

/**
* Returns @c true iff there is at least one polyobj linked with the BSP leaf.
*/
Expand All @@ -171,6 +191,21 @@ 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.
*
* @see aaBox()
*/
vec2d_t const &worldGridOffset() const;

/**
* Returns the original index of the BSP leaf.
*/
Expand All @@ -189,21 +224,6 @@ class BspLeaf : public de::MapElement
/// @todo Refactor away.
void setValidCount(int newValidCount);

/**
* 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.
*
* @see aaBox()
*/
vec2d_t const &worldGridOffset() const;

#ifdef __CLIENT__

/**
Expand All @@ -213,6 +233,18 @@ class BspLeaf : public de::MapElement
*/
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.
*
* @see fanBase()
*/
inline uint BspLeaf::numFanVertices() const
{
// Are we to use one of the half-edge vertexes as the fan base?
return hedgeCount() + (fanBase()? 0 : 2);
}

/**
* Retrieve the bias surface for specified geometry @a groupId
*
Expand Down
3 changes: 3 additions & 0 deletions doomsday/client/include/map/line.h
Expand Up @@ -444,6 +444,9 @@ class Line : public de::MapElement
*/
inline bool isFlagged(int flagsToTest) const { return (flags() & flagsToTest) != 0; }

void chooseSurfaceTintColors(int sectionId, de::Vector3f const **topColor,
de::Vector3f const **bottomColor) const;

/**
* Returns the frame number of the last time shadows were drawn for the side.
*/
Expand Down
10 changes: 10 additions & 0 deletions doomsday/client/include/map/r_world.h
Expand Up @@ -187,6 +187,16 @@ inline bool R_MiddleMaterialCoversOpening(Line::Side const &side, bool ignoreOpa

#endif // __CLIENT__

/**
* @param side Line::Side instance.
* @param ignoreOpacity @c true= do not consider Material opacity.
*
* @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.
*/
bool R_SideBackClosed(Line::Side const &side, bool ignoreOpacity = true);

void R_UpdateSector(Sector &sector, bool forceUpdate = false);

/// @return Current glow strength for the plane.
Expand Down
9 changes: 4 additions & 5 deletions doomsday/client/include/render/rend_main.h
Expand Up @@ -83,7 +83,11 @@ void Rend_ModelViewMatrix(boolean use_angles);

#define Rend_PointDist2D(c) (fabs((vOrigin[VZ]-c[VY])*viewsidex - (vOrigin[VX]-c[VX])*viewsidey))

/**
* Approximated! The Z axis aspect ratio is corrected.
*/
coord_t Rend_PointDist3D(coord_t const point[3]);

void Rend_ApplyTorchLight(float *color, float distance);

/**
Expand All @@ -105,11 +109,6 @@ float Rend_LightAdaptationDelta(float lightvalue);
*/
void Rend_CalcLightModRange();

/**
* Number of vertices needed for this leaf's trifan.
*/
uint Rend_NumFanVerticesForBspLeaf(BspLeaf *bspLeaf);

void R_DrawLightRange(void);

#ifdef __cplusplus
Expand Down
11 changes: 11 additions & 0 deletions doomsday/client/src/map/bspleaf.cpp
Expand Up @@ -292,6 +292,17 @@ void BspLeaf::setSector(Sector *newSector)
d->sector = newSector;
}

bool BspLeaf::hasWorldVolume(bool useVisualHeights) const
{
if(isDegenerate()) return false;
if(!hasSector()) return false;

coord_t const floorHeight = useVisualHeights? d->sector->floor().visHeight() : d->sector->floor().height();
coord_t const ceilHeight = useVisualHeights? d->sector->ceiling().visHeight() : d->sector->ceiling().height();

return (ceilHeight - floorHeight > 0);
}

Polyobj *BspLeaf::firstPolyobj() const
{
return d->polyobj;
Expand Down
58 changes: 58 additions & 0 deletions doomsday/client/src/map/line.cpp
Expand Up @@ -344,6 +344,64 @@ void Line::Side::setFlags(int flagsToChange, bool set)
else d->flags &= ~flagsToChange;
}

void Line::Side::chooseSurfaceTintColors(int sectionId, Vector3f const **topColor,
Vector3f const **bottomColor) const
{
if(hasSections())
{
switch(sectionId)
{
case Middle:
if(isFlagged(SDF_BLENDMIDTOTOP))
{
*topColor = &top().tintColor();
*bottomColor = &middle().tintColor();
}
else if(isFlagged(SDF_BLENDMIDTOBOTTOM))
{
*topColor = &middle().tintColor();
*bottomColor = &bottom().tintColor();
}
else
{
*topColor = &middle().tintColor();
*bottomColor = 0;
}
break;

case Top:
if(isFlagged(SDF_BLENDTOPTOMID))
{
*topColor = &top().tintColor();
*bottomColor = &middle().tintColor();
}
else
{
*topColor = &top().tintColor();
*bottomColor = 0;
}
break;

case Bottom:
if(isFlagged(SDF_BLENDBOTTOMTOMID))
{
*topColor = &middle().tintColor();
*bottomColor = &bottom().tintColor();
}
else
{
*topColor = &bottom().tintColor();
*bottomColor = 0;
}
break;

default: DENG_ASSERT(false); // Invalid section.
}
}
/// @throw Line::InvalidSectionIdError The given section identifier is not valid.
throw Line::InvalidSectionIdError("Line::Side::chooseSurfaceTintColors", QString("Invalid section id %1").arg(sectionId));
}

int Line::Side::shadowVisCount() const
{
return d->shadowVisCount;
Expand Down
27 changes: 27 additions & 0 deletions doomsday/client/src/map/r_world.cpp
Expand Up @@ -348,6 +348,33 @@ bool R_MiddleMaterialCoversOpening(Line::Side const &side,
return false;
}

/**
* @param side Line::Side instance.
* @param ignoreOpacity @c true= do not consider Material opacity.
*
* @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.
*/
bool R_SideBackClosed(Line::Side const &side, bool ignoreOpacity)
{
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.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;
}

return R_MiddleMaterialCoversOpening(side, ignoreOpacity);
}

Line *R_FindLineNeighbor(Sector const *sector, Line const *line,
LineOwner const *own, bool antiClockwise, binangle_t *diff)
{
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/rend_bias.cpp
Expand Up @@ -294,7 +294,7 @@ void SB_InitForMap(char const *uniqueID)
foreach(Sector *sector, theMap->sectors())
foreach(BspLeaf *bspLeaf, sector->bspLeafs())
{
numVertIllums += Rend_NumFanVerticesForBspLeaf(bspLeaf) * sector->planeCount();
numVertIllums += bspLeaf->numFanVertices() * sector->planeCount();
}

foreach(Polyobj *polyobj, theMap->polyobjs())
Expand Down Expand Up @@ -333,7 +333,7 @@ void SB_InitForMap(char const *uniqueID)
{
biassurface_t *bsuf = SB_CreateSurface();

bsuf->size = Rend_NumFanVerticesForBspLeaf(bspLeaf);
bsuf->size = bspLeaf->numFanVertices();
bsuf->illum = illums;
illums += bsuf->size;

Expand Down

0 comments on commit 2f3c4eb

Please sign in to comment.