Skip to content

Commit

Permalink
Sector: Redefined the aabox as the union of the BSP leaf's aaboxs
Browse files Browse the repository at this point in the history
As a sector in Doomsday has no geometry of its own, the aabox (and
thus the rough area approximation) should be taken from BSP leafs
instead.

This also means that the rough area approximation for a sector is
now derived from the BSP leafs, addressing a shortcoming in the
space volume calculation done to determine the environmental audio
characteristics of the sector.
  • Loading branch information
danij-deng committed Apr 12, 2013
1 parent 81f5bcc commit caad4ae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 40 deletions.
40 changes: 18 additions & 22 deletions doomsday/client/include/map/sector.h
Expand Up @@ -291,32 +291,26 @@ class Sector : public de::MapElement
inline uint reverbBspLeafCount() const { return uint(reverbBspLeafs().count()); }

/**
* Returns the axis-aligned bounding box which encompases all vertex
* origin points for lines which reference the sector, in map coordinate
* space units. Note that if no lines reference the sector the bounding
* box will be invalid (has negative dimensions).
*
* @deprecated Algorithms which are dependent on this are likely making
* invalid assumptions about the geometry of the map.
* Returns the axis-aligned bounding box which encompases the geometry of
* all BSP leafs attributed to the sector (map units squared). Note that if
* no BSP leafs reference the sector the bounding box will be invalid (has
* negative dimensions).
*/
AABoxd const &aaBox() const;

/**
* Update the sector's map space axis-aligned bounding box to encompass
* the points defined by it's LineDefs' vertexes.
* the geometry of all BSP leafs attributed to the sector.
*
* @pre Line list must have be initialized.
* @pre BSP leaf list must have be initialized.
*
* @see buildLines()
* @see buildBspLeafs()
*/
void updateAABox();

/**
* Returns a rough approximation of the area of the sector in the map
* coordinate space (units squared).
*
* @deprecated Algorithms which are dependent on this are likely making
* invalid assumptions about the geometry of the map.
* Returns a rough approximation of the total combined area of the geometry
* for all BSP leafs attributed to the sector (map units squared).
*
* @see updateRoughArea()
*/
Expand All @@ -325,22 +319,24 @@ class Sector : public de::MapElement
/**
* Update the sector's rough area approximation.
*
* @pre Axis-aligned bounding box must be initialized.
* @pre BSP leaf list must have be initialized.
*
* @see updateAABox()
* @see buildBspLeafs(), roughArea()
*/
void updateRoughArea();

/**
* @param base Mobj base to link in @a sector. Caller should ensure that the
* same object is not linked multiple times into the chain.
* @param newEmitter Mobj base to link to the sector. Caller must ensure
* that the object is not linked multiple times into
* the chain.
*/
void linkSoundEmitter(ddmobj_base_t &newEmitter);

/**
* Update the origin of the sector according to the point defined by the
* center of the sector's axis-aligned bounding box (which must be
* initialized before calling).
* Update the sound emitter origin of the sector according to the point
* defined by the center of the sector's axis-aligned bounding box (which
* must be initialized before calling) and the mid point on the map up
* axis between floor and ceiling planes.
*/
void updateSoundEmitterOrigin();

Expand Down
9 changes: 1 addition & 8 deletions doomsday/client/src/audio/s_environ.cpp
Expand Up @@ -314,14 +314,7 @@ static void calculateSectorReverb(Sector *sec)
{
if(!sec || !sec->lineCount()) return;

/// @todo fixme: This 3D volume rough estimate may be massively off.
/// Consider the case of a single sector used over an entire map
/// with multiple disjoint groups of small geometries.
/// In general a sector should never be considered as playing any
/// part in the definition of a map's geometry. -ds
uint spaceVolume = (int) (sec->ceiling().height() - sec->floor().height()) *
(sec->aaBox().maxX - sec->aaBox().minX) *
(sec->aaBox().maxY - sec->aaBox().minY);
uint spaceVolume = int((sec->ceiling().height() - sec->floor().height()) * sec->roughArea());

sec->_reverb[SRD_SPACE] = sec->_reverb[SRD_VOLUME] =
sec->_reverb[SRD_DECAY] = sec->_reverb[SRD_DAMPING] = 0;
Expand Down
32 changes: 22 additions & 10 deletions doomsday/client/src/map/sector.cpp
Expand Up @@ -312,25 +312,37 @@ void Sector::updateAABox()
V2d_Set(d->aaBox.min, DDMAXFLOAT, DDMAXFLOAT);
V2d_Set(d->aaBox.max, DDMINFLOAT, DDMINFLOAT);

if(!d->lines.count()) return;
if(!d->bspLeafs.count()) return;

QListIterator<LineDef *> lineIt(d->lines);
QListIterator<BspLeaf *> leafIt(d->bspLeafs);

LineDef *line = lineIt.next();
V2d_CopyBox(d->aaBox.arvec2, line->aaBox().arvec2);
BspLeaf *leaf = leafIt.next();
V2d_CopyBox(d->aaBox.arvec2, leaf->aaBox().arvec2);

while(lineIt.hasNext())
while(leafIt.hasNext())
{
line = lineIt.next();
V2d_UniteBox(d->aaBox.arvec2, line->aaBox().arvec2);
leaf = leafIt.next();
V2d_UniteBox(d->aaBox.arvec2, leaf->aaBox().arvec2);
}
}

void Sector::updateRoughArea()
{
// Only a very rough estimate is required.
d->roughArea = ((d->aaBox.maxX - d->aaBox.minX) / 128) *
((d->aaBox.maxY - d->aaBox.minY) / 128);
d->roughArea = 0;
if(!d->bspLeafs.count()) return;

QListIterator<BspLeaf *> leafIt(d->bspLeafs);

BspLeaf *leaf = leafIt.next();
d->roughArea += (leaf->aaBox().maxX - leaf->aaBox().minX) *
(leaf->aaBox().maxY - leaf->aaBox().minY);

while(leafIt.hasNext())
{
leaf = leafIt.next();
d->roughArea += (leaf->aaBox().maxX - leaf->aaBox().minX) *
(leaf->aaBox().maxY - leaf->aaBox().minY);
}
}

void Sector::linkSoundEmitter(ddmobj_base_t &newEmitter)
Expand Down

0 comments on commit caad4ae

Please sign in to comment.