Skip to content

Commit

Permalink
Refactor|World|BspLeaf|ConvexSubspace: Moved Polyobj link set from Bs…
Browse files Browse the repository at this point in the history
…pLeaf to ConvexSubspace
  • Loading branch information
danij-deng committed Oct 22, 2014
1 parent 3ca47ae commit 0095b59
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 81 deletions.
32 changes: 0 additions & 32 deletions doomsday/client/include/world/bspleaf.h
Expand Up @@ -21,16 +21,12 @@
#ifndef DENG_WORLD_BSPLEAF_H
#define DENG_WORLD_BSPLEAF_H

#include <QSet>
#include <de/Error>
#include <de/Vector>
#include "MapElement"
#include "ConvexSubspace"
#include "Line"
#include "Sector"

class SectorCluster;
struct polyobj_s;

/**
* Represents a leaf in the map's binary space partition (BSP) tree. Each leaf
Expand Down Expand Up @@ -58,9 +54,6 @@ class BspLeaf : public de::MapElement
/// Required subspace is missing. @ingroup errors
DENG2_ERROR(MissingSubspaceError);

/// Linked-element lists/sets:
typedef QSet<polyobj_s *> Polyobjs;

public:
/**
* Construct a new BSP leaf and optionally attribute it to @a sector.
Expand Down Expand Up @@ -114,31 +107,6 @@ class BspLeaf : public de::MapElement
*/
void setSubspace(ConvexSubspace *newSubspace);

/**
* Remove the given @a polyobj from the set of those linked to the BSP leaf.
*
* @return @c true= @a polyobj was linked and subsequently removed.
*/
bool unlink(polyobj_s const &polyobj);

/**
* Add the given @a polyobj to the set of those linked to the BSP leaf.
* Ownership is unaffected. If the polyobj is already linked in this set
* then nothing will happen.
*/
void link(struct polyobj_s const &polyobj);

/**
* Provides access to the set of polyobjs linked to the BSP leaf.
*/
Polyobjs const &polyobjs() const;

/**
* Convenient method of returning the total number of polyobjs linked to the
* BSP leaf.
*/
inline int polyobjCount() { return polyobjs().count(); }

public: /// Convenience accessors @todo remove ---------------------------------

inline bool hasPoly() const { return hasSubspace(); }
Expand Down
34 changes: 31 additions & 3 deletions doomsday/client/include/world/convexsubspace.h
Expand Up @@ -32,6 +32,7 @@
#include "Sector"

class SectorCluster;
struct polyobj_s;
#ifdef __CLIENT__
class Lumobj;
#endif
Expand All @@ -48,11 +49,13 @@ class ConvexSubspace
/// Required sector cluster attribution is missing. @ingroup errors
DENG2_ERROR(MissingClusterError);

typedef QSet<de::Mesh *> Meshes;
/// Linked-element lists/sets:
typedef QSet<de::Mesh *> Meshes;
typedef QSet<polyobj_s *> Polyobjs;

#ifdef __CLIENT__
typedef QSet<Lumobj *> Lumobjs;
typedef QSet<LineSide *> ShadowLines;
typedef QSet<Lumobj *> Lumobjs;
typedef QSet<LineSide *> ShadowLines;

// Final audio environment characteristics.
typedef uint AudioEnvironmentFactors[NUM_REVERB_DATA];
Expand Down Expand Up @@ -103,6 +106,31 @@ class ConvexSubspace
*/
Meshes const &extraMeshes() const;

/**
* Remove the given @a polyobj from the set of those linked to the BSP leaf.
*
* @return @c true= @a polyobj was linked and subsequently removed.
*/
bool unlink(polyobj_s const &polyobj);

/**
* Add the given @a polyobj to the set of those linked to the BSP leaf.
* Ownership is unaffected. If the polyobj is already linked in this set
* then nothing will happen.
*/
void link(struct polyobj_s const &polyobj);

/**
* Provides access to the set of polyobjs linked to the BSP leaf.
*/
Polyobjs const &polyobjs() const;

/**
* Convenient method of returning the total number of polyobjs linked to the
* BSP leaf.
*/
inline int polyobjCount() { return polyobjs().count(); }

/**
* Returns the vector described by the offset from the map coordinate space
* origin to the top most, left most point of the geometry of the BSP leaf.
Expand Down
51 changes: 28 additions & 23 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -2597,22 +2597,22 @@ static void writeAllWallSections(HEdge *hedge)

static void writeLeafWallSections()
{
BspLeaf *leaf = currentBspLeaf;
ConvexSubspace &subspace = currentBspLeaf->subspace();

HEdge *base = leaf->subspace().poly().hedge();
HEdge *base = subspace.poly().hedge();
HEdge *hedge = base;
do
{
writeAllWallSections(hedge);
} while((hedge = &hedge->next()) != base);

foreach(Mesh *mesh, leaf->subspace().extraMeshes())
foreach(Mesh *mesh, subspace.extraMeshes())
foreach(HEdge *hedge, mesh->hedges())
{
writeAllWallSections(hedge);
}

foreach(Polyobj *po, leaf->polyobjs())
foreach(Polyobj *po, subspace.polyobjs())
foreach(HEdge *hedge, po->mesh().hedges())
{
writeAllWallSections(hedge);
Expand Down Expand Up @@ -2647,22 +2647,22 @@ static void markFrontFacingWalls(HEdge *hedge)

static void markLeafFrontFacingWalls()
{
BspLeaf *leaf = currentBspLeaf;
ConvexSubspace &subspace = currentBspLeaf->subspace();

HEdge *base = leaf->subspace().poly().hedge();
HEdge *base = subspace.poly().hedge();
HEdge *hedge = base;
do
{
markFrontFacingWalls(hedge);
} while((hedge = &hedge->next()) != base);

foreach(Mesh *mesh, leaf->subspace().extraMeshes())
foreach(Mesh *mesh, subspace.extraMeshes())
foreach(HEdge *hedge, mesh->hedges())
{
markFrontFacingWalls(hedge);
}

foreach(Polyobj *po, leaf->polyobjs())
foreach(Polyobj *po, subspace.polyobjs())
foreach(HEdge *hedge, po->mesh().hedges())
{
markFrontFacingWalls(hedge);
Expand Down Expand Up @@ -2803,22 +2803,22 @@ static void clipFrontFacingWalls(HEdge *hedge)

static void clipLeafFrontFacingWalls()
{
BspLeaf *leaf = currentBspLeaf;
ConvexSubspace &subspace = currentBspLeaf->subspace();

HEdge *base = leaf->subspace().poly().hedge();
HEdge *base = subspace.poly().hedge();
HEdge *hedge = base;
do
{
clipFrontFacingWalls(hedge);
} while((hedge = &hedge->next()) != base);

foreach(Mesh *mesh, leaf->subspace().extraMeshes())
foreach(Mesh *mesh, subspace.extraMeshes())
foreach(HEdge *hedge, mesh->hedges())
{
clipFrontFacingWalls(hedge);
}

foreach(Polyobj *po, leaf->polyobjs())
foreach(Polyobj *po, subspace.polyobjs())
foreach(HEdge *hedge, po->mesh().hedges())
{
clipFrontFacingWalls(hedge);
Expand Down Expand Up @@ -2892,14 +2892,15 @@ static int generatorMarkVisibleWorker(Generator *generator, void * /*context*/)
static void drawCurrentLeaf()
{
BspLeaf *leaf = currentBspLeaf;
ConvexSubspace &subspace = leaf->subspace();

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

markLeafFrontFacingWalls();

// Perform contact spreading for this map region.
leaf->map().spreadAllContacts(leaf->poly().aaBox());
leaf->map().spreadAllContacts(subspace.poly().aaBox());

Rend_RadioBspLeafEdges(*leaf);

Expand All @@ -2915,7 +2916,7 @@ static void drawCurrentLeaf()

clipLeafFrontFacingWalls();

if(leaf->polyobjCount())
if(subspace.polyobjCount())
{
// Polyobjs don't obstruct - clip lights with another algorithm.
clipLeafLumobjsBySight();
Expand Down Expand Up @@ -4613,20 +4614,21 @@ static void drawSurfaceTangentVectors(SectorCluster *cluster)

foreach(BspLeaf *bspLeaf, cluster->bspLeafs())
{
HEdge const *base = bspLeaf->subspace().poly().hedge();
ConvexSubspace &subspace = bspLeaf->subspace();
HEdge const *base = subspace.poly().hedge();
HEdge const *hedge = base;
do
{
drawTangentVectorsForWallSections(hedge);
} while((hedge = &hedge->next()) != base);

foreach(Mesh *mesh, bspLeaf->subspace().extraMeshes())
foreach(Mesh *mesh, subspace.extraMeshes())
foreach(HEdge *hedge, mesh->hedges())
{
drawTangentVectorsForWallSections(hedge);
}

foreach(Polyobj *polyobj, bspLeaf->polyobjs())
foreach(Polyobj *polyobj, subspace.polyobjs())
foreach(HEdge *hedge, polyobj->mesh().hedges())
{
drawTangentVectorsForWallSections(hedge);
Expand Down Expand Up @@ -4971,13 +4973,16 @@ static int drawBspLeafVertexWorker(BspLeaf *bspLeaf, void *context)
{
drawVertexVisual_params_t &parms = *static_cast<drawVertexVisual_params_t *>(context);

if(!bspLeaf->hasCluster())
if(!bspLeaf->hasSubspace())
return false; // Continue iteration.

ddouble min = bspLeaf->cluster(). visFloor().heightSmoothed();
ddouble max = bspLeaf->cluster().visCeiling().heightSmoothed();
ConvexSubspace &subspace = bspLeaf->subspace();
SectorCluster &cluster = subspace.cluster();

ddouble min = cluster. visFloor().heightSmoothed();
ddouble max = cluster.visCeiling().heightSmoothed();

HEdge *base = bspLeaf->subspace().poly().hedge();
HEdge *base = subspace.poly().hedge();
HEdge *hedge = base;
do
{
Expand All @@ -4989,14 +4994,14 @@ static int drawBspLeafVertexWorker(BspLeaf *bspLeaf, void *context)

} while((hedge = &hedge->next()) != base);

foreach(Mesh *mesh, bspLeaf->subspace().extraMeshes())
foreach(Mesh *mesh, subspace.extraMeshes())
foreach(HEdge *hedge, mesh->hedges())
{
drawVertexVisual(hedge->vertex(), min, max, parms);
drawVertexVisual(hedge->twin().vertex(), min, max, parms);
}

foreach(Polyobj *polyobj, bspLeaf->polyobjs())
foreach(Polyobj *polyobj, subspace.polyobjs())
foreach(Line *line, polyobj->lines())
{
drawVertexVisual(line->from(), min, max, parms);
Expand Down
3 changes: 2 additions & 1 deletion doomsday/client/src/render/viewports.cpp
Expand Up @@ -1315,6 +1315,7 @@ void R_ViewerClipLumobj(Lumobj *lum)
void R_ViewerClipLumobjBySight(Lumobj *lum, BspLeaf *bspLeaf)
{
if(!lum || !bspLeaf) return;
if(!bspLeaf->hasSubspace()) return;

// Already clipped?
int lumIdx = lum->indexInMap();
Expand All @@ -1325,7 +1326,7 @@ void R_ViewerClipLumobjBySight(Lumobj *lum, BspLeaf *bspLeaf)
// between the viewpoint and the lumobj.
Vector3d const eye = Rend_EyeOrigin().xzy();

foreach(Polyobj *po, bspLeaf->polyobjs())
foreach(Polyobj *po, bspLeaf->subspace().polyobjs())
foreach(HEdge *hedge, po->mesh().hedges())
{
// Is this on the back of a one-sided line?
Expand Down
19 changes: 0 additions & 19 deletions doomsday/client/src/world/bspleaf.cpp
Expand Up @@ -24,15 +24,13 @@
# include "world/map.h"
#endif
#include "Face"
#include "Polyobj"
#include "Sector"

using namespace de;

DENG2_PIMPL_NOREF(BspLeaf)
{
QScopedPointer<ConvexSubspace> subspace;
Polyobjs polyobjs; ///< Linked polyobjs (if any, not owned).
};

BspLeaf::BspLeaf(Sector *sector)
Expand Down Expand Up @@ -70,20 +68,3 @@ void BspLeaf::setSubspace(ConvexSubspace *newSubspace)
d->subspace->poly().setMapElement(this);
}
}

void BspLeaf::link(Polyobj const &polyobj)
{
d->polyobjs.insert(const_cast<Polyobj *>(&polyobj));
}

bool BspLeaf::unlink(polyobj_s const &polyobj)
{
int sizeBefore = d->polyobjs.size();
d->polyobjs.remove(const_cast<Polyobj *>(&polyobj));
return d->polyobjs.size() != sizeBefore;
}

BspLeaf::Polyobjs const &BspLeaf::polyobjs() const
{
return d->polyobjs;
}
19 changes: 19 additions & 0 deletions doomsday/client/src/world/convexsubspace.cpp
Expand Up @@ -21,6 +21,7 @@
#include "de_base.h"
#include "world/convexsubspace.h"
#include "Face"
#include "Polyobj"
#include "SectorCluster"
#include "Surface"
#include <de/Log>
Expand All @@ -44,6 +45,7 @@ DENG2_PIMPL(ConvexSubspace)
{
Face &poly; ///< Convex polygon geometry (not owned).
Meshes extraMeshes; ///< Additional meshes (owned).
Polyobjs polyobjs; ///< Linked polyobjs (if any, not owned).
SectorCluster *cluster; ///< Attributed cluster (if any, not owned).
int validCount; ///< Used to prevent repeated processing.
Vector2d worldGridOffset; ///< For aligning the materials to the map space grid.
Expand Down Expand Up @@ -223,6 +225,23 @@ ConvexSubspace::Meshes const &ConvexSubspace::extraMeshes() const
return d->extraMeshes;
}

void ConvexSubspace::link(Polyobj const &polyobj)
{
d->polyobjs.insert(const_cast<Polyobj *>(&polyobj));
}

bool ConvexSubspace::unlink(polyobj_s const &polyobj)
{
int sizeBefore = d->polyobjs.size();
d->polyobjs.remove(const_cast<Polyobj *>(&polyobj));
return d->polyobjs.size() != sizeBefore;
}

ConvexSubspace::Polyobjs const &ConvexSubspace::polyobjs() const
{
return d->polyobjs;
}

Vector2d const &ConvexSubspace::worldGridOffset() const
{
return d->worldGridOffset;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/world/linesighttest.cpp
Expand Up @@ -238,7 +238,7 @@ DENG2_PIMPL(LineSightTest)
ConvexSubspace const &subspace = bspLeaf.subspace();

// Check polyobj lines.
foreach(Polyobj *po, bspLeaf.polyobjs())
foreach(Polyobj *po, subspace.polyobjs())
foreach(Line *line, po->lines())
{
if(!crossLine(line->front()))
Expand Down

0 comments on commit 0095b59

Please sign in to comment.