Skip to content

Commit

Permalink
Refactor|Renderer: Use a subspacesVisible QBitArray
Browse files Browse the repository at this point in the history
Removes the need for a BspElement to record a unique indexInMap.
  • Loading branch information
danij-deng committed Oct 22, 2014
1 parent 0f55945 commit c74da80
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 41 deletions.
26 changes: 0 additions & 26 deletions doomsday/client/include/world/bspnode.h
Expand Up @@ -29,34 +29,8 @@
class BspElement
{
public:
/// Special identifier used to mark an invalid index.
enum { NoIndex = -1 };

BspElement() : _indexInMap(NoIndex) {}
virtual ~BspElement() {}
DENG2_AS_IS_METHODS()

/**
* Returns the "in-map" index attributed to the BSP element.
*/
int indexInMap() const
{
return _indexInMap;
}

/**
* Change the "in-map" index attributed to the BSP element.
*
* @param newIndex New index to attribute to the BSP element. @c NoIndex
* clears the attribution (not a valid index).
*/
void setIndexInMap(int newIndex = NoIndex)
{
_indexInMap = newIndex;
}

private:
int _indexInMap;
};

/**
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -2940,7 +2940,7 @@ static void makeCurrent(ConvexSubspace &subspace)
}
}

static void traverseBspAndDrawSubspaces(BspTree *bspTree)
static void traverseBspTreeAndDrawSubspaces(BspTree *bspTree)
{
DENG2_ASSERT(bspTree != 0);

Expand All @@ -2953,7 +2953,7 @@ static void traverseBspAndDrawSubspaces(BspTree *bspTree)
int eyeSide = bspNode.partition().pointOnSide(eyeOrigin) < 0;

// Recursively divide front space.
traverseBspAndDrawSubspaces(bspTree->childPtr(BspTree::ChildId(eyeSide)));
traverseBspTreeAndDrawSubspaces(bspTree->childPtr(BspTree::ChildId(eyeSide)));

// If the clipper is full we're pretty much done. This means no geometry
// will be visible in the distance because every direction has already
Expand Down Expand Up @@ -3876,7 +3876,7 @@ void Rend_RenderMap(Map &map)
curSubspace = 0;

// Draw the world!
traverseBspAndDrawSubspaces(&map.bspRoot());
traverseBspTreeAndDrawSubspaces(&map.bspRoot());
}
drawAllLists(map);

Expand Down
16 changes: 7 additions & 9 deletions doomsday/client/src/render/viewports.cpp
Expand Up @@ -71,7 +71,7 @@ static viewport_t *currentViewport;
static coord_t *luminousDist;
static byte *luminousClipped;
static uint *luminousOrder;
static QBitArray bspLeafsVisible;
static QBitArray subspacesVisible;

static QBitArray generatorsVisible(Map::MAX_GENERATORS);

Expand Down Expand Up @@ -1145,16 +1145,14 @@ void R_ClearViewData()

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

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

bool R_ViewerGeneratorIsVisible(Generator const &generator)
Expand Down Expand Up @@ -1223,8 +1221,8 @@ void R_BeginFrame()

Map &map = ClientApp::worldSystem().map();

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

// Clear all generator visibility flags.
generatorsVisible.fill(false);
Expand Down
5 changes: 2 additions & 3 deletions doomsday/client/src/world/map.cpp
Expand Up @@ -574,7 +574,7 @@ DENG2_PIMPL(Map)
{
DENG2_ASSERT(tree.userData() != 0);
BspLeaf &leaf = tree.userData()->as<BspLeaf>();
leaf.setIndexInMap(bsp.leafCount++);
bsp.leafCount++;

if(!leaf.sectorPtr())
{
Expand Down Expand Up @@ -617,8 +617,7 @@ DENG2_PIMPL(Map)
// Else; a node.

DENG2_ASSERT(tree.userData() != 0);
BspNode &node = tree.userData()->as<BspNode>();
node.setIndexInMap(bsp.nodeCount++);
bsp.nodeCount++;
}

/**
Expand Down

0 comments on commit c74da80

Please sign in to comment.