Skip to content

Commit

Permalink
Refactor|BspLeaf|Segment|BiasTracker: Various cleanup refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Aug 2, 2013
1 parent 613fd6c commit e6c22ba
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 64 deletions.
12 changes: 7 additions & 5 deletions doomsday/client/include/render/biastracker.h
Expand Up @@ -52,10 +52,6 @@ class BiasTracker
*/
static void consoleRegister();

uint lastUpdateOnFrame() const;

void setLastUpdateOnFrame(uint newLastUpdateFrameNumber);

/**
* Remove all light contributors. Existing contributions are put into a
* "latent" state, so that if they are added again the contribution is then
Expand Down Expand Up @@ -108,7 +104,13 @@ class BiasTracker
*/
void applyChanges(BiasDigest &changes);

void updateAfterGeometryMove();
public: /// @todo The following logic does not belong at this level ------------

uint lastUpdateOnFrame() const;

void setLastUpdateOnFrame(uint newLastUpdateFrameNumber);

void updateAllContributors();

/**
* Perform lighting for the supplied geometry. It is assumed that this
Expand Down
8 changes: 1 addition & 7 deletions doomsday/client/include/world/bspleaf.h
Expand Up @@ -272,13 +272,7 @@ class BspLeaf : public de::MapElement
*/
int numFanVertices() const;

/**
* Retrieve the bias tracker for the specified geometry @a group. If no
* tracker has yet been initialized for the group it will be at this time.
*
* @param group Geometry group identifier for the bias tracker.
*/
BiasTracker &biasTracker(int group);
void updateAfterGeometryMove(int group);

/**
* @param changes
Expand Down
8 changes: 1 addition & 7 deletions doomsday/client/include/world/segment.h
Expand Up @@ -236,13 +236,7 @@ class Segment : public de::MapElement

#ifdef __CLIENT__

/**
* Retrieve the bias tracker for the specified geometry @a group. If no
* tracker has yet been initialized for the group it will be at this time.
*
* @param group Geometry group identifier for the bias tracker.
*/
BiasTracker &biasTracker(int group);
void updateAfterGeometryMove(int group);

/**
* @param allChanges
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/biastracker.cpp
Expand Up @@ -49,7 +49,7 @@ struct Contributor
* @todo Defer allocation of most data -- adopt a 'fly-weight' approach.
*
* @todo Do not observe source deletion. A better solution would represent any
* source deletions within the change tracker.
* source deletions in BiasDigest.
*/
DENG2_PIMPL_NOREF(BiasTracker),
DENG2_OBSERVES(BiasSource, Deletion)
Expand Down Expand Up @@ -261,7 +261,7 @@ void BiasTracker::applyChanges(BiasDigest &changes)
}
}

void BiasTracker::updateAfterGeometryMove()
void BiasTracker::updateAllContributors()
{
Contributor *ctbr = d->contributors;
for(int i = 0; i < MAX_CONTRIBUTORS; ++i, ctbr++)
Expand Down
50 changes: 31 additions & 19 deletions doomsday/client/src/world/bspleaf.cpp
Expand Up @@ -282,6 +282,30 @@ DENG2_PIMPL(BspLeaf)
#undef MIN_TRIANGLE_EPSILON
}

/**
* Retrieve the bias tracker for the specified geometry @a group.
*
* @param group Geometry group identifier for the bias tracker.
* @param canAlloc @c true= to allocate if no tracker exists.
*/
BiasTracker *biasTracker(int group, bool canAlloc = true)
{
DENG_ASSERT(sector && !self.isDegenerate()); // sanity check
DENG_ASSERT(group >= 0 && group < sector->planeCount()); // sanity check

BiasTrackers::iterator foundAt = biasTrackers.find(group);
if(foundAt != biasTrackers.end())
{
return *foundAt;
}

if(!canAlloc) return 0;

BiasTracker *newTracker = new BiasTracker(self.numFanVertices());
biasTrackers.insert(group, newTracker);
return newTracker;
}

/**
* @todo This could be enhanced so that only the lights on the right
* side of the surface are taken into consideration.
Expand Down Expand Up @@ -529,24 +553,12 @@ int BspLeaf::numFanVertices() const
return d->poly->hedgeCount() + (fanBase()? 0 : 2);
}

BiasTracker &BspLeaf::biasTracker(int group)
void BspLeaf::updateAfterGeometryMove(int group)
{
if(!d->sector)
/// @throw MissingSectorError Attempted with no sector attributed.
throw MissingSectorError("BspLeaf::biasTracker", "No sector is attributed");

DENG_ASSERT(group >= 0 && group < d->sector->planeCount()); // sanity check
DENG_ASSERT(!isDegenerate()); // sanity check

BiasTrackers::iterator foundAt = d->biasTrackers.find(group);
if(foundAt != d->biasTrackers.end())
if(BiasTracker *biasTracker = d->biasTracker(group, false /*don't allocate*/))
{
return **foundAt;
biasTracker->updateAllContributors();
}

BiasTracker *newTracker = new BiasTracker(numFanVertices());
d->biasTrackers.insert(group, newTracker);
return *newTracker;
}

void BspLeaf::updateBiasAffection(BiasDigest &changes)
Expand All @@ -560,17 +572,17 @@ void BspLeaf::updateBiasAffection(BiasDigest &changes)
void BspLeaf::lightPoly(int group, int vertCount, rvertex_t const *positions,
ColorRawf *colors)
{
BiasTracker &bsuf = biasTracker(group);
BiasTracker *tracker = d->biasTracker(group);

// Should we update?
//if(devUpdateAffected)
{
d->updateAffected(bsuf, group);
d->updateAffected(*tracker, group);
}

Surface &surface = d->sector->plane(group).surface();
bsuf.lightPoly(surface.normal(), map().biasCurrentTime(),
vertCount, positions, colors);
tracker->lightPoly(surface.normal(), map().biasCurrentTime(),
vertCount, positions, colors);
}

ShadowLink *BspLeaf::firstShadowLink() const
Expand Down
5 changes: 1 addition & 4 deletions doomsday/client/src/world/polyobj.cpp
Expand Up @@ -56,10 +56,7 @@ static void notifyGeometryChanged(Polyobj &po)
Segment *segment = line->front().leftSegment();
if(!segment) continue;

for(int i = 0; i < 3; ++i)
{
segment->biasTracker(i).updateAfterGeometryMove();
}
segment->updateAfterGeometryMove(Line::Side::Middle);
}
}
#else // !__CLIENT__
Expand Down
9 changes: 4 additions & 5 deletions doomsday/client/src/world/sector.cpp
Expand Up @@ -180,13 +180,12 @@ DENG2_OBSERVES(Plane, HeightChange)
if(!seg->hasLineSide())
continue;

for(int i = 0; i < 3; ++i)
{
seg->biasTracker(i).updateAfterGeometryMove();
}
seg->updateAfterGeometryMove(Line::Side::Middle);
seg->updateAfterGeometryMove(Line::Side::Bottom);
seg->updateAfterGeometryMove(Line::Side::Top);
}

bspLeaf->biasTracker(plane.indexInSector()).updateAfterGeometryMove();
bspLeaf->updateAfterGeometryMove(plane.indexInSector());
}
}

Expand Down
46 changes: 31 additions & 15 deletions doomsday/client/src/world/segment.cpp
Expand Up @@ -89,6 +89,30 @@ DENG2_PIMPL(Segment)
}

#ifdef __CLIENT__
/**
* Retrieve the bias tracker for the specified geometry @a group.
*
* @param group Geometry group identifier for the bias tracker.
* @param canAlloc @c true= to allocate if no tracker exists.
*/
BiasTracker *biasTracker(int group, bool canAlloc = true)
{
DENG_ASSERT(group >= 0 && group < 3); // sanity check
DENG_ASSERT(self.hasLineSide()); // sanity check

BiasTrackers::iterator foundAt = biasTrackers.find(group);
if(foundAt != biasTrackers.end())
{
return *foundAt;
}

if(!canAlloc) return 0;

BiasTracker *newTracker = new BiasTracker(4);
biasTrackers.insert(group, newTracker);
return newTracker;
}

/**
* @todo This could be enhanced so that only the lights on the right
* side of the surface are taken into consideration.
Expand Down Expand Up @@ -241,20 +265,12 @@ void Segment::setFlags(Flags flagsToChange, FlagOp operation)

#ifdef __CLIENT__

BiasTracker &Segment::biasTracker(int group)
void Segment::updateAfterGeometryMove(int group)
{
DENG_ASSERT(group >= 0 && group < 3); // sanity check
DENG_ASSERT(hasLineSide()); // sanity check

BiasTrackers::iterator foundAt = d->biasTrackers.find(group);
if(foundAt != d->biasTrackers.end())
if(BiasTracker *biasTracker = d->biasTracker(group, false /*don't allocate*/))
{
return **foundAt;
biasTracker->updateAllContributors();
}

BiasTracker *newTracker = new BiasTracker(4);
d->biasTrackers.insert(group, newTracker);
return *newTracker;
}

void Segment::updateBiasAffection(BiasDigest &changes)
Expand All @@ -270,17 +286,17 @@ void Segment::lightPoly(int group, int vertCount, rvertex_t const *positions,
{
DENG_ASSERT(hasLineSide()); // sanity check

BiasTracker &bsuf = biasTracker(group);
BiasTracker *tracker = d->biasTracker(group);

// Should we update?
//if(devUpdateAffected)
{
d->updateAffected(bsuf, group);
d->updateAffected(*tracker, group);
}

Surface &surface = d->lineSide->middle();
bsuf.lightPoly(surface.normal(), map().biasCurrentTime(),
vertCount, positions, colors);
tracker->lightPoly(surface.normal(), map().biasCurrentTime(),
vertCount, positions, colors);
}

#endif // __CLIENT__
Expand Down

0 comments on commit e6c22ba

Please sign in to comment.