Skip to content

Commit

Permalink
BspLeaf: Multiple polyobjs can now be linked to a BSP leaf
Browse files Browse the repository at this point in the history
Note that this does not mean that intersecting geometry is now dealt
with, however.
  • Loading branch information
danij-deng committed Jun 13, 2013
1 parent 8eea97e commit 7737cb0
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 51 deletions.
24 changes: 16 additions & 8 deletions doomsday/client/include/world/bspleaf.h
Expand Up @@ -22,6 +22,7 @@
#define DENG_WORLD_BSPLEAF_H

#include <QList>
#include <QSet>

#include <de/Error>
#include <de/Vector>
Expand Down Expand Up @@ -71,7 +72,8 @@ class BspLeaf : public de::MapElement
DENG2_ERROR(UnknownGeometryGroupError);
#endif

typedef QList<Segment *> Segments;
typedef QSet<polyobj_s *> Polyobjs;
typedef QList<Segment *> Segments;

public: /// @todo Make private:
#ifdef __CLIENT__
Expand Down Expand Up @@ -202,20 +204,26 @@ class BspLeaf : public de::MapElement
/**
* Returns @c true iff at least one polyobj is linked to the BSP leaf.
*/
inline bool hasPolyobj() { return firstPolyobj() != 0; }
inline bool hasPolyobj() { return !polyobjs().isEmpty(); }

/**
* Returns a pointer to the first polyobj linked to the BSP leaf; otherwise @c 0.
* 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.
*/
struct polyobj_s *firstPolyobj() const;
void addOnePolyobj(struct polyobj_s const &polyobj);

/**
* Change the first polyobj linked to the BSP leaf.
* Remove the given @a polyobj from the set of those linked to the BSP leaf.
*
* @param newPolyobj New polyobj to be attributed. Ownership is unaffected.
* Can be @c 0 (to clear the attribution).
* @return @c true= @a polyobj was linked and subsequently removed.
*/
void setFirstPolyobj(struct polyobj_s *newPolyobj);
bool removeOnePolyobj(polyobj_s const &polyobj);

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

/**
* Returns the vector described by the offset from the map coordinate space
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/lumobj.cpp
Expand Up @@ -1164,7 +1164,7 @@ boolean LOIT_ClipLumObjBySight(void *data, void *context)
// We need to figure out if any of the polyobj's segments lies
// between the viewpoint and the lumobj.
BspLeaf *bspLeaf = (BspLeaf *) context;
Polyobj *po = bspLeaf->firstPolyobj();
foreach(Polyobj *po, bspLeaf->polyobjs())
foreach(Line *line, po->lines())
{
Segment *segment = line->front().leftSegment();
Expand Down
26 changes: 10 additions & 16 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -2124,9 +2124,7 @@ static void writeLeafPolyobjs()
BspLeaf *leaf = currentBspLeaf;
DENG_ASSERT(!isNullLeaf(leaf));

Polyobj *po = leaf->firstPolyobj();
if(!po) return;

foreach(Polyobj *po, leaf->polyobjs())
foreach(Line *line, po->lines())
{
Segment *seg = line->front().leftSegment();
Expand Down Expand Up @@ -2182,16 +2180,14 @@ static void markFrontFacingSegments()
seg->setFlags(Segment::FacingFront, dot < 0? UnsetFlags : SetFlags);
}

if(Polyobj *po = bspLeaf->firstPolyobj())
foreach(Polyobj *po, bspLeaf->polyobjs())
foreach(Line *line, po->lines())
{
foreach(Line *line, po->lines())
{
Segment *seg = line->front().leftSegment();
Segment *seg = line->front().leftSegment();

// Which way is it facing?
double dot = viewFacingDot(seg->from().origin(), seg->to().origin());
seg->setFlags(Segment::FacingFront, dot < 0? UnsetFlags : SetFlags);
}
// Which way is it facing?
double dot = viewFacingDot(seg->from().origin(), seg->to().origin());
seg->setFlags(Segment::FacingFront, dot < 0? UnsetFlags : SetFlags);
}
}

Expand Down Expand Up @@ -2290,12 +2286,10 @@ static void clipFrontFacingSegments()
clipFrontFacingSegment(*seg);
}

if(Polyobj *po = bspLeaf->firstPolyobj())
foreach(Polyobj *po, bspLeaf->polyobjs())
foreach(Line *line, po->lines())
{
foreach(Line *line, po->lines())
{
clipFrontFacingSegment(*line->front().leftSegment());
}
clipFrontFacingSegment(*line->front().leftSegment());
}
}

Expand Down
20 changes: 13 additions & 7 deletions doomsday/client/src/world/bspleaf.cpp
Expand Up @@ -76,8 +76,8 @@ DENG2_PIMPL(BspLeaf)
/// Sector attributed to the leaf. @note can be @c 0 (degenerate!).
Sector *sector;

/// First Polyobj in the leaf. Can be @c 0 (none).
Polyobj *polyobj;
/// Set of polyobjs linked to the leaf (not owned).
Polyobjs polyobjs;

#ifdef __CLIENT__

Expand All @@ -103,7 +103,6 @@ DENG2_PIMPL(BspLeaf)
needUpdateClockwiseSegments(false),
needUpdateAllSegments(false),
sector(sector),
polyobj(0),
#ifdef __CLIENT__
fanBase(0),
needUpdateFanBase(true),
Expand Down Expand Up @@ -413,14 +412,21 @@ void BspLeaf::setSector(Sector *newSector)
d->sector = newSector;
}

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

void BspLeaf::setFirstPolyobj(Polyobj *newPolyobj)
bool BspLeaf::removeOnePolyobj(polyobj_s const &polyobj)
{
d->polyobj = newPolyobj;
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;
}

int BspLeaf::validCount() const
Expand Down
18 changes: 8 additions & 10 deletions doomsday/client/src/world/linesighttest.cpp
Expand Up @@ -238,19 +238,17 @@ DENG2_PIMPL(LineSightTest)
if(bspLeaf.isDegenerate())
return false;

if(Polyobj *po = bspLeaf.firstPolyobj())
// Check polyobj lines.
foreach(Polyobj *po, bspLeaf.polyobjs())
foreach(Line *line, po->lines())
{
// Check polyobj lines.
foreach(Line *line, po->lines())
{
if(line->validCount() == validCount)
continue;
if(line->validCount() == validCount)
continue;

line->setValidCount(validCount);
line->setValidCount(validCount);

if(!crossLine(line->front()))
return false; // Stop traversal.
}
if(!crossLine(line->front()))
return false; // Stop traversal.
}

// Check the line segment geometries.
Expand Down
13 changes: 4 additions & 9 deletions doomsday/client/src/world/polyobj.cpp
Expand Up @@ -131,9 +131,11 @@ void Polyobj::unlink()
{
if(_bspLeaf)
{
_bspLeaf->removeOnePolyobj(*this);
_bspLeaf = 0;

/// @todo Do not assume polyobj is from the CURRENT map.
App_World().map().unlinkPolyobj(*this);
_bspLeaf = 0;
}
}

Expand All @@ -155,14 +157,7 @@ void Polyobj::link()
/// @todo Do not assume polyobj is from the CURRENT map.
if(BspLeaf *bspLeaf = App_World().map().bspLeafAtPoint(avg))
{
if(bspLeaf->hasPolyobj())
{
LOG_WARNING("Multiple polyobjs in a single BSP leaf\n"
" (BSP leaf %i, sector %i). Previous polyobj overridden.")
<< bspLeaf->indexInMap()
<< bspLeaf->sector().indexInMap();
}
bspLeaf->setFirstPolyobj(this);
bspLeaf->addOnePolyobj(*this);
_bspLeaf = bspLeaf;
}
}
Expand Down

0 comments on commit 7737cb0

Please sign in to comment.