Skip to content

Commit

Permalink
Renderer|Shard: Made Shard internal data private, applied pimpl
Browse files Browse the repository at this point in the history
Todo: The API for bias contributor updating needs improving...
  • Loading branch information
danij-deng committed Apr 29, 2014
1 parent d2979fe commit f1751c6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 32 deletions.
21 changes: 10 additions & 11 deletions doomsday/client/include/render/shard.h
Expand Up @@ -22,30 +22,20 @@
#include <QList>
#include <de/Matrix>
#include <de/Vector>
#include "BiasTracker"

class BiasDigest;
class BiasIllum;
class BiasSource;

/**
* 3D map geometry fragment.
*/
class Shard
{
public: /// @todo make private:
struct BiasData {
uint lastUpdateFrame;
typedef QList<BiasIllum *> BiasIllums;
BiasIllums illums;
BiasTracker tracker;
} bias;

public:
/**
* @param numBiasIllums Number of bias illumination points for the geometry.
*/
Shard(int numBiasIllums);
~Shard();

/**
* Perform bias lighting for the supplied vertex geometry.
Expand Down Expand Up @@ -77,6 +67,15 @@ class Shard
* Schedule a bias lighting update for the Shard following a move.
*/
void updateBiasAfterMove();

uint lastBiasUpdateFrame();
void setLastBiasUpdateFrame(uint updateFrame);
void clearBiasContributors();
void addBiasContributor(BiasSource *source, float intensity);
void markBiasIllumUpdateCompleted();

private:
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_RENDER_SHARD_H
56 changes: 44 additions & 12 deletions doomsday/client/src/render/shard.cpp
Expand Up @@ -20,26 +20,33 @@
#include <QtAlgorithms>
#include "BiasDigest"
#include "BiasIllum"
#include "BiasTracker"

using namespace de;

Shard::Shard(int numBiasIllums)
DENG2_PIMPL_NOREF(Shard)
{
BiasTracker biasTracker;
typedef QList<BiasIllum *> BiasIllums;
BiasIllums biasIllums;
uint biasLastUpdateFrame;

Instance() : biasLastUpdateFrame(0) {}
~Instance() { qDeleteAll(biasIllums); }
};

Shard::Shard(int numBiasIllums) : d(new Instance)
{
if(numBiasIllums)
{
bias.illums.reserve(numBiasIllums);
d->biasIllums.reserve(numBiasIllums);
for(int i = 0; i < numBiasIllums; ++i)
{
bias.illums << new BiasIllum(&bias.tracker);
d->biasIllums << new BiasIllum(&d->biasTracker);
}
}
}

Shard::~Shard()
{
qDeleteAll(bias.illums);
}

void Shard::lightWithBiasSources(Vector3f const *posCoords, Vector4f *colorCoords,
Matrix3f const &tangentMatrix, uint biasTime)
{
Expand All @@ -49,18 +56,43 @@ void Shard::lightWithBiasSources(Vector3f const *posCoords, Vector4f *colorCoord

Vector3f const *posIt = posCoords;
Vector4f *colorIt = colorCoords;
for(int i = 0; i < bias.illums.count(); ++i, posIt++, colorIt++)
for(int i = 0; i < d->biasIllums.count(); ++i, posIt++, colorIt++)
{
*colorIt += bias.illums[i]->evaluate(*posIt, sufNormal, biasTime);
*colorIt += d->biasIllums[i]->evaluate(*posIt, sufNormal, biasTime);
}
}

void Shard::applyBiasDigest(BiasDigest &changes)
{
bias.tracker.applyChanges(changes);
d->biasTracker.applyChanges(changes);
}

void Shard::updateBiasAfterMove()
{
bias.tracker.updateAllContributors();
d->biasTracker.updateAllContributors();
}

uint Shard::lastBiasUpdateFrame()
{
return d->biasLastUpdateFrame;
}

void Shard::setLastBiasUpdateFrame(uint updateFrame)
{
d->biasLastUpdateFrame = updateFrame;
}

void Shard::clearBiasContributors()
{
d->biasTracker.clearContributors();
}

void Shard::addBiasContributor(BiasSource *source, float intensity)
{
d->biasTracker.addContributor(source, intensity);
}

void Shard::markBiasIllumUpdateCompleted()
{
d->biasTracker.markIllumUpdateCompleted();
}
18 changes: 9 additions & 9 deletions doomsday/client/src/world/sectorcluster.cpp
Expand Up @@ -783,12 +783,12 @@ DENG2_PIMPL(SectorCluster)

// If the data is already up to date, nothing needs to be done.
uint lastChangeFrame = map.biasLastChangeOnFrame();
if(shard.bias.lastUpdateFrame == lastChangeFrame)
if(shard.lastBiasUpdateFrame() == lastChangeFrame)
return;

shard.bias.lastUpdateFrame = lastChangeFrame;
shard.setLastBiasUpdateFrame(lastChangeFrame);

shard.bias.tracker.clearContributors();
shard.clearBiasContributors();

Plane const &plane = self.visPlane(geomId);
Surface const &surface = plane.surface();
Expand Down Expand Up @@ -818,7 +818,7 @@ DENG2_PIMPL(SectorCluster)
if(sourceToSurface.dot(surface.normal()) < 0)
continue;

shard.bias.tracker.addContributor(source, source->evaluateIntensity() / de::max(distance, 1.0));
shard.addBiasContributor(source, source->evaluateIntensity() / de::max(distance, 1.0));
}
}

Expand All @@ -832,12 +832,12 @@ DENG2_PIMPL(SectorCluster)

// If the data is already up to date, nothing needs to be done.
uint lastChangeFrame = map.biasLastChangeOnFrame();
if(shard.bias.lastUpdateFrame == lastChangeFrame)
if(shard.lastBiasUpdateFrame() == lastChangeFrame)
return;

shard.bias.lastUpdateFrame = lastChangeFrame;
shard.setLastBiasUpdateFrame(lastChangeFrame);

shard.bias.tracker.clearContributors();
shard.clearBiasContributors();

Surface const &surface = seg.lineSide().middle();
Vector2d const &from = seg.hedge().origin();
Expand All @@ -864,7 +864,7 @@ DENG2_PIMPL(SectorCluster)
if(sourceToSurface.dot(surface.normal()) < 0)
continue;

shard.bias.tracker.addContributor(source, source->evaluateIntensity() / de::max(distance, 1.0));
shard.addBiasContributor(source, source->evaluateIntensity() / de::max(distance, 1.0));
}
}

Expand Down Expand Up @@ -1302,7 +1302,7 @@ void SectorCluster::applyBiasLightSources(MapElement &mapElement, int geomId,
surface->map().biasCurrentTime());

// Any changes from contributors will have now been applied.
shard->bias.tracker.markIllumUpdateCompleted();
shard->markBiasIllumUpdateCompleted();
}

void SectorCluster::updateBiasAfterGeometryMove(MapElement &mapElement, int geomId)
Expand Down

0 comments on commit f1751c6

Please sign in to comment.