Skip to content

Commit

Permalink
Refactor|Map Renderer|BspLeaf: Replaced the fake radio ShadowLink lis…
Browse files Browse the repository at this point in the history
…t with a QSet
  • Loading branch information
danij-deng committed Aug 16, 2013
1 parent 57af8a3 commit 5ddeff7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 69 deletions.
10 changes: 0 additions & 10 deletions doomsday/client/include/render/rend_fakeradio.h
Expand Up @@ -42,16 +42,6 @@

#include "render/rendpoly.h" // r_vertex_t

/**
* Used to link a line side to a BSP leaf for the purposes of FakeRadio shadowing.
* @ingroup render
*/
struct ShadowLink
{
ShadowLink *next;
Line::Side *side;
};

/**
* FakeRadio shadow data.
* @ingroup render
Expand Down
24 changes: 19 additions & 5 deletions doomsday/client/include/world/bspleaf.h
Expand Up @@ -39,7 +39,6 @@ struct polyobj_s;

#ifdef __CLIENT__
class BiasDigest;
struct ShadowLink;
#endif

/**
Expand Down Expand Up @@ -80,12 +79,13 @@ class BspLeaf : public de::MapElement
*/
typedef QSet<de::Mesh *> Meshes;
typedef QSet<polyobj_s *> Polyobjs;
#ifdef __CLIENT__
typedef QSet<Line::Side *> ShadowLines;
#endif

public: /// @todo Make private:
#ifdef __CLIENT__

ShadowLink *_shadows;

uint _reverb[NUM_REVERB_DATA];

#endif // __CLIENT__
Expand Down Expand Up @@ -288,9 +288,23 @@ class BspLeaf : public de::MapElement
void applyBiasDigest(BiasDigest &changes);

/**
* Returns a pointer to the first ShadowLink; otherwise @c 0.
* Clear the list of fake radio shadow line sides for the BSP leaf.
*/
void clearShadowLines();

/**
* Add the specified line @a side to the set of fake radio shadow lines for
* the BSP leaf. If the line is already present in this set then nothing
* will happen.
*
* @param side Map line side to add to the set.
*/
void addShadowLine(Line::Side &side);

/**
* Provides access to the set of fake radio shadow lines for the BSP leaf.
*/
ShadowLink *firstShadowLink() const;
ShadowLines const &shadowLines() const;

/**
* Returns the frame number of the last time mobj sprite projection was
Expand Down
29 changes: 2 additions & 27 deletions doomsday/client/src/render/r_fakeradio.cpp
Expand Up @@ -18,7 +18,7 @@
* 02110-1301 USA</small>
*/

#include <de/memoryzone.h>
//#include <de/memoryzone.h>
#include <de/vector1.h> /// @todo remove me
#include <de/Vector>

Expand All @@ -38,7 +38,6 @@
using namespace de;

static LineSideRadioData *lineSideRadioData;
static zblockset_t *shadowLinksBlockSet;

bool Rend_RadioLineCastsShadow(Line const &line)
{
Expand Down Expand Up @@ -192,32 +191,9 @@ void Rend_RadioUpdateVertexShadowOffsets(Vertex &vtx)
} while(own != base);
}

/**
* Link @a line to @a bspLeaf for the purposes of shadowing.
*/
static void linkShadowLineToBspLeaf(Line::Side &side, BspLeaf &bspLeaf)
{
#ifdef DENG_DEBUG
// Check the links for dupes!
for(ShadowLink *i = bspLeaf.firstShadowLink(); i; i = i->next)
{
if(i->side == &side)
throw Error("R_LinkShadow", "Already here!!");
}
#endif

// We'll need to allocate a new link.
ShadowLink *link = (ShadowLink *) ZBlockSet_Allocate(shadowLinksBlockSet);

link->side = &side;
// The links are stored into a linked list.
link->next = bspLeaf._shadows;
bspLeaf._shadows = link;
}

static int linkShadowLineToBspLeafWorker(BspLeaf *bspLeaf, void *context)
{
linkShadowLineToBspLeaf(*static_cast<Line::Side *>(context), *bspLeaf);
bspLeaf->addShadowLine(*static_cast<Line::Side *>(context));
return false; // Continue iteration.
}

Expand Down Expand Up @@ -247,7 +223,6 @@ void Rend_RadioInitForMap(Map &map)
* shadow edges cross one of the BSP leaf's edges (not parallel),
* link the line to the BspLeaf.
*/
shadowLinksBlockSet = ZBlockSet_New(sizeof(ShadowLink), 1024, PU_MAP);

AABoxd bounds;

Expand Down
29 changes: 10 additions & 19 deletions doomsday/client/src/render/rend_fakeradio.cpp
Expand Up @@ -1277,22 +1277,6 @@ static void writeShadowSection(int planeIndex, Line::Side &side, float shadowDar
writeShadowSection2(leftEdge, rightEdge, suf->normal()[VZ] > 0, shadowDark);
}

static void drawLinkedEdgeShadows(ShadowLink &link, Sector &sector,
byte const *doPlanes, float shadowDark)
{
DENG_ASSERT(doPlanes != 0);

if(!(shadowDark > .0001f)) return;

for(int pln = 0; pln < sector.planeCount(); ++pln)
{
writeShadowSection(pln, *link.side, shadowDark);
}

// Mark it rendered for this frame.
link.side->setShadowVisCount(frameCount);
}

/**
* @attention Do not use the global radio state in here, as @a bspLeaf can be
* part of any sector, not the one chosen for wall rendering.
Expand Down Expand Up @@ -1353,13 +1337,20 @@ void Rend_RadioBspLeafEdges(BspLeaf &bspLeaf)

// We need to check all the shadow lines linked to this BspLeaf for
// the purpose of fakeradio shadowing.
for(ShadowLink *link = bspLeaf.firstShadowLink(); link != NULL; link = link->next)
foreach(Line::Side *side, bspLeaf.shadowLines())
{
// Already rendered during the current frame? We only want to
// render each shadow once per frame.
if(link->side->shadowVisCount() == frameCount) continue;
if(side->shadowVisCount() == frameCount)
continue;

for(int pln = 0; pln < sector.planeCount(); ++pln)
{
writeShadowSection(pln, *side, shadowDark);
}

drawLinkedEdgeShadows(*link, sector, doPlanes, shadowDark);
// Mark it rendered for this frame.
side->setShadowVisCount(frameCount);
}
}

Expand Down
24 changes: 16 additions & 8 deletions doomsday/client/src/world/bspleaf.cpp
Expand Up @@ -18,17 +18,13 @@
* 02110-1301 USA</small>
*/

#include <cmath> // fmod

#include <QMap>
#include <QSet>
#include <QtAlgorithms>

#include <de/Log>

#include "dd_main.h" // App_World()

#include "Face"

#include "Polyobj"
#include "Sector"

Expand Down Expand Up @@ -98,6 +94,9 @@ DENG2_PIMPL(BspLeaf)
/// Bias lighting data for each geometry group (i.e., each plane).
GeometryGroups geomGroups;

/// Set of fake radio shadow lines.
ShadowLines shadowLines;

#endif // __CLIENT__

/// Used by legacy algorithms to prevent repeated processing.
Expand Down Expand Up @@ -286,7 +285,6 @@ BspLeaf::BspLeaf(Sector *sector)
: MapElement(DMU_BSPLEAF), d(new Instance(this, sector))
{
#ifdef __CLIENT__
_shadows = 0;
zap(_reverb);
#endif
}
Expand Down Expand Up @@ -557,9 +555,19 @@ void BspLeaf::lightBiasPoly(int group, Vector3f const *posCoords, Vector4f *colo
geomGroup->biasTracker.markIllumUpdateCompleted();
}

ShadowLink *BspLeaf::firstShadowLink() const
void BspLeaf::clearShadowLines()
{
d->shadowLines.clear();
}

void BspLeaf::addShadowLine(Line::Side &side)
{
d->shadowLines.insert(&side);
}

BspLeaf::ShadowLines const &BspLeaf::shadowLines() const
{
return _shadows;
return d->shadowLines;
}

int BspLeaf::addSpriteCount() const
Expand Down

0 comments on commit 5ddeff7

Please sign in to comment.