Skip to content

Commit

Permalink
Map Renderer|Client: Use a viewer-local QBitArray for flagging visibl…
Browse files Browse the repository at this point in the history
…e BSP leafs; cleanup
  • Loading branch information
danij-deng committed Oct 9, 2013
1 parent ee2dc17 commit a349f76
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 83 deletions.
12 changes: 12 additions & 0 deletions doomsday/client/include/render/r_main.h
Expand Up @@ -161,6 +161,18 @@ void R_ClearViewData(void);
*/
void R_BeginFrame(void);

/**
* Returns @c true iff the BSP leaf is marked as visible for the current frame.
* @see markVisible()
*/
bool R_ViewerBspLeafIsVisible(BspLeaf const &bspLeaf);

/**
* Mark the BSP leaf as visible for the current frame.
* @see isVisible()
*/
void R_ViewerBspLeafMarkVisible(BspLeaf const &bspLeaf, bool yes = true);

/// @return Distance in map space units between the lumobj and viewer.
double R_ViewerLumobjDistance(int idx);

Expand Down
12 changes: 0 additions & 12 deletions doomsday/client/include/world/bspleaf.h
Expand Up @@ -371,18 +371,6 @@ class BspLeaf : public de::MapElement
*/
void setLastSpriteProjectFrame(int newFrame);

/**
* Returns @c true iff the BSP leaf is marked as visible for the current frame.
* @see markVisible()
*/
bool isVisible() const;

/**
* Mark the BSP leaf as visible for the current frame.
* @see isVisible()
*/
void markVisible(bool yes = true);

#endif // __CLIENT__

private:
Expand Down
16 changes: 7 additions & 9 deletions doomsday/client/src/render/r_fakeradio.cpp
Expand Up @@ -224,9 +224,6 @@ void Rend_RadioInitForMap(Map &map)
* shadow edges cross one of the BSP leaf's edges (not parallel),
* link the line to the BspLeaf.
*/

AABoxd bounds;

foreach(Line *line, map.lines())
{
if(!Rend_RadioLineCastsShadow(*line)) continue;
Expand All @@ -236,14 +233,15 @@ void Rend_RadioInitForMap(Map &map)
{
LineSide &side = line->side(i);

if(!side.hasSector() || !side.hasSections()) continue;
if(!side.hasSector()) continue;
if(!side.hasSections()) continue;

Vertex &vtx0 = line->vertex(i);
Vertex &vtx1 = line->vertex(i^1);
LineOwner &vo0 = line->vertexOwner(i)->next();
LineOwner &vo1 = line->vertexOwner(i^1)->prev();
Vertex const &vtx0 = line->vertex(i);
Vertex const &vtx1 = line->vertex(i^1);
LineOwner const &vo0 = line->vertexOwner(i)->next();
LineOwner const &vo1 = line->vertexOwner(i^1)->prev();

V2d_CopyBox(bounds.arvec2, line->aaBox().arvec2);
AABoxd bounds = line->aaBox();

// Use the extended points, they are wider than inoffsets.
Vector2d point = vtx0.origin() + vo0.extendedShadowOffset();
Expand Down
24 changes: 23 additions & 1 deletion doomsday/client/src/render/r_main.cpp
Expand Up @@ -21,6 +21,10 @@
#include <cmath>
#include <cstring>

#ifdef __CLIENT__
#include <QBitArray>
#endif

#include "de_base.h"
#include "de_console.h"
#include "de_system.h"
Expand Down Expand Up @@ -99,6 +103,7 @@ boolean loInited;
static coord_t *luminousDist;
static byte *luminousClipped;
static uint *luminousOrder;
static QBitArray bspLeafsVisible;
#endif

int psp3d;
Expand Down Expand Up @@ -1091,7 +1096,8 @@ DENG_EXTERN_C void R_RenderPlayerView(int num)

// Too early? Game has not configured the view window?
viewdata_t *vd = &viewDataOfConsole[num];
if(vd->window.size.width == 0 || vd->window.size.height == 0) return;
if(vd->window.size.width == 0 || vd->window.size.height == 0)
return;

// Setup for rendering the frame.
R_SetupFrame(player);
Expand Down Expand Up @@ -1304,6 +1310,18 @@ void R_ClearViewData()
M_Free(luminousOrder); luminousOrder = 0;
}

bool R_ViewerBspLeafIsVisible(BspLeaf const &bspLeaf)
{
DENG2_ASSERT(bspLeaf.indexInMap() != MapElement::NoIndex);
return bspLeafsVisible.testBit(bspLeaf.indexInMap());
}

void R_ViewerBspLeafMarkVisible(BspLeaf const &bspLeaf, bool yes)
{
DENG2_ASSERT(bspLeaf.indexInMap() != MapElement::NoIndex);
bspLeafsVisible.setBit(bspLeaf.indexInMap(), yes);
}

double R_ViewerLumobjDistance(int idx)
{
/// @todo Do not assume the current map.
Expand Down Expand Up @@ -1359,6 +1377,10 @@ void R_BeginFrame()
Rend_ProjectorReset();

Map &map = App_World().map();

bspLeafsVisible.resize(map.bspLeafCount());
bspLeafsVisible.fill(false);

int numLuminous = map.lumobjCount();
if(!(numLuminous > 0)) return;

Expand Down
7 changes: 5 additions & 2 deletions doomsday/client/src/render/rend_fakeradio.cpp
Expand Up @@ -1292,8 +1292,11 @@ void Rend_RadioBspLeafEdges(BspLeaf &bspLeaf)
{
DENG_ASSERT(bspLeaf.hasCluster());

if(!rendFakeRadio || levelFullBright)
return;
if(!rendFakeRadio) return;

if(levelFullBright) return;

if(bspLeaf.shadowLines().isEmpty()) return;

static int doPlaneSize = 0;
static byte *doPlanes = 0;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -2496,7 +2496,7 @@ static void drawCurrentLeaf()
BspLeaf *leaf = currentBspLeaf;

// Mark the leaf as visible for this frame.
leaf->markVisible();
R_ViewerBspLeafMarkVisible(*leaf);

markLeafFrontFacingWalls();

Expand Down Expand Up @@ -3172,7 +3172,7 @@ static int drawMobjBBox(thinker_t *th, void * /*context*/)
if(mo == ddPlayers[consolePlayer].shared.mo)
return false; // Continue iteration.
// Is it vissible?
if(!Mobj_IsLinked(*mo) || !Mobj_BspLeafAtOrigin(*mo).isVisible())
if(!Mobj_IsLinked(*mo) || !R_ViewerBspLeafIsVisible(Mobj_BspLeafAtOrigin(*mo)))
return false; // Continue iteration.

ddouble const distToEye = (eyeOrigin - Mobj_Origin(*mo)).length();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_particle.cpp
Expand Up @@ -321,7 +321,7 @@ static int populateSortBuffer(ptcgen_t *gen, void *parameters)
continue;

// Is the particle's sector visible?
if(!pt->bspLeaf->isVisible())
if(!R_ViewerBspLeafIsVisible(*pt->bspLeaf))
continue; // No; this particle can't be seen.

// Don't allow zero distance.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/world/blockmap.cpp
Expand Up @@ -466,7 +466,7 @@ bool Blockmap::link(CellBlock const &cellBlock_, void *elem)
for(cell.y = cellBlock.min.y; cell.y < cellBlock.max.y; ++cell.y)
for(cell.x = cellBlock.min.x; cell.x < cellBlock.max.x; ++cell.x)
{
Instance::Node *node = d->findLeaf(cell);
Instance::Node *node = d->findLeaf(cell, true/* can create*/);
if(!node) continue;

if(CellData *cellData = node->leafData)
Expand Down
12 changes: 0 additions & 12 deletions doomsday/client/src/world/bspleaf.cpp
Expand Up @@ -87,8 +87,6 @@ DENG2_PIMPL(BspLeaf)
Lumobjs lumobjs; ///< Linked lumobjs (not owned).
ShadowLines shadowLines; ///< Linked map lines for fake radio shadowing.
AudioEnvironmentFactors reverb; ///< Cached characteristics.

bool visible; ///< @c true= marked as visible for the current frame.
#endif // __CLIENT__

/// Used by legacy algorithms to prevent repeated processing.
Expand All @@ -102,7 +100,6 @@ DENG2_PIMPL(BspLeaf)
fanBase(0),
needUpdateFanBase(true),
addSpriteCount(0),
visible(false),
#endif
validCount(0)
{
Expand Down Expand Up @@ -678,13 +675,4 @@ void BspLeaf::setLastSpriteProjectFrame(int newFrameCount)
d->addSpriteCount = newFrameCount;
}

bool BspLeaf::isVisible() const
{
return d->visible;
}

void BspLeaf::markVisible(bool yes)
{
d->visible = yes;
}
#endif // __CLIENT__

0 comments on commit a349f76

Please sign in to comment.