Skip to content

Commit

Permalink
Refactor|Client|BiasSurface|BspLeaf|Segment: Bias surfaces now provid…
Browse files Browse the repository at this point in the history
…e access to their BiasTrackers
  • Loading branch information
danij-deng committed Aug 9, 2013
1 parent 082114e commit 206500a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
8 changes: 5 additions & 3 deletions doomsday/client/include/render/biassurface.h
Expand Up @@ -23,14 +23,15 @@

#include "render/rendpoly.h" /// @todo remove me

#include "BiasDigest"
#include "BiasTracker"

/**
* Base class for a surface which supports lighting within the Shadow Bias
* lighting model.
*/
class BiasSurface
{

public:
virtual ~BiasSurface() {}

Expand Down Expand Up @@ -60,9 +61,10 @@ class BiasSurface
virtual void updateBiasAfterGeometryMove(int group) {}

/**
* @param changes Digest of bias lighting changes to apply.
* Returns the bias change tracker for the specified geometry @a group,
* otherwise @c 0 (if the group is unknown).
*/
virtual void applyBiasDigest(BiasDigest &changes) = 0;
virtual BiasTracker *biasTracker(int group) = 0;
};

extern int devUpdateBiasContributors; //cvar
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/world/bspleaf.h
Expand Up @@ -279,6 +279,8 @@ class BspLeaf : public de::MapElement

void updateBiasAfterGeometryMove(int group);

BiasTracker *biasTracker(int group);

/**
* Apply bias lighting changes to @em all map element geometries at this
* leaf of the BSP.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/world/segment.h
Expand Up @@ -254,7 +254,7 @@ class Segment : public de::MapElement

void updateBiasAfterGeometryMove(int group);

void applyBiasDigest(BiasDigest &changes);
BiasTracker *biasTracker(int group);

#endif // __CLIENT__

Expand Down
41 changes: 32 additions & 9 deletions doomsday/client/src/world/bspleaf.cpp
Expand Up @@ -474,8 +474,7 @@ static void updateBiasAfterGeometryMoveToFaceEdges(Face const &face)

void BspLeaf::updateBiasAfterGeometryMove(int group)
{
if(isDegenerate())
return;
if(isDegenerate()) return;

if(GeometryGroup *geomGroup = d->geometryGroup(group, false /*don't allocate*/))
{
Expand All @@ -491,15 +490,39 @@ void BspLeaf::updateBiasAfterGeometryMove(int group)
}
}

static void applyBiasDigestToFaceEdges(Face const &face, BiasDigest &changes)
BiasTracker *BspLeaf::biasTracker(int group)
{
if(GeometryGroup *geomGroup = d->geometryGroup(group, false /*don't allocate*/))
{
return &geomGroup->biasTracker;
}
return 0;
}

static void applyBiasDigestToSegment(Segment *seg, BiasDigest &changes)
{
if(!seg) return;
if(BiasTracker *tracker = seg->biasTracker(Line::Side::Middle))
{
tracker->applyChanges(changes);
}
if(BiasTracker *tracker = seg->biasTracker(Line::Side::Bottom))
{
tracker->applyChanges(changes);
}
if(BiasTracker *tracker = seg->biasTracker(Line::Side::Top))
{
tracker->applyChanges(changes);
}
}

static void applyBiasDigestToSegmentsForFace(Face const &face, BiasDigest &changes)
{
HEdge *base = face.hedge();
HEdge *hedge = base;
do
{
DENG_ASSERT(hedge->mapElement() != 0);
Segment *seg = hedge->mapElement()->as<Segment>();
seg->applyBiasDigest(changes);
applyBiasDigestToSegment(hedge->mapElement()->as<Segment>(), changes);
} while((hedge = &hedge->next()) != base);
}

Expand All @@ -513,18 +536,18 @@ void BspLeaf::applyBiasDigest(BiasDigest &changes)
it.value().biasTracker.applyChanges(changes);
}

applyBiasDigestToFaceEdges(poly(), changes);
applyBiasDigestToSegmentsForFace(poly(), changes);

foreach(Mesh *mesh, extraMeshes())
foreach(Face *face, mesh->faces())
{
applyBiasDigestToFaceEdges(*face, changes);
applyBiasDigestToSegmentsForFace(*face, changes);
}

foreach(Polyobj *polyobj, d->polyobjs)
foreach(Line *line, polyobj->lines())
{
line->front().leftSegment()->applyBiasDigest(changes);
applyBiasDigestToSegment(line->front().leftSegment(), changes);
}
}

Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/world/segment.cpp
Expand Up @@ -288,13 +288,13 @@ void Segment::updateBiasAfterGeometryMove(int group)
}
}

void Segment::applyBiasDigest(BiasDigest &changes)
BiasTracker *Segment::biasTracker(int group)
{
for(GeometryGroups::iterator it = d->geomGroups.begin();
it != d->geomGroups.end(); ++it)
if(GeometryGroup *geomGroup = d->geometryGroup(group, false /*don't allocate*/))
{
it.value().biasTracker.applyChanges(changes);
return &geomGroup->biasTracker;
}
return 0;
}

void Segment::lightBiasPoly(int group, Vector3f const *posCoords, Vector4f *colorCoords)
Expand Down

0 comments on commit 206500a

Please sign in to comment.