Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Apr 25, 2013
1 parent da174fa commit 179ff76
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 143 deletions.
28 changes: 14 additions & 14 deletions doomsday/client/include/map/bsp/hedgeintercept.h
@@ -1,4 +1,4 @@
/** @file hedgeintercept.h BSP Builder half-edge intercept info.
/** @file map/hedgeintercept.h BSP Builder half-edge intercept info.
*
* Originally based on glBSP 2.24 (in turn, based on BSP 2.3)
* @see http://sourceforge.net/projects/glbsp/
Expand All @@ -23,8 +23,8 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_BSP_HEDGEINTERCEPT
#define LIBDENG_BSP_HEDGEINTERCEPT
#ifndef DENG_WORLD_MAP_BSP_HEDGEINTERCEPT
#define DENG_WORLD_MAP_BSP_HEDGEINTERCEPT

#include "dd_types.h"
#include "map/p_mapdata.h"
Expand Down Expand Up @@ -56,20 +56,20 @@ struct HEdgeIntercept
Sector *before;
Sector *after;

DENG_DEBUG_ONLY(
static void DebugPrint(HEdgeIntercept const &inst)
#ifdef DENG_DEBUG
void debugPrint() const
{
LOG_INFO("Vertex #%i [x:%f, y:%f] beforeSector: #%d afterSector: #%d %s")
<< inst.vertex->indexInMap()
<< inst.vertex->origin()[VX]
<< inst.vertex->origin()[VY]
<< (inst.before? inst.before->indexInMap() : -1)
<< (inst.after? inst.after->indexInMap() : -1)
<< (inst.selfRef? "SELFREF" : "");
})
LOG_INFO("Vertex #%i %s beforeSector: #%d afterSector: #%d %s")
<< vertex->indexInMap()
<< vertex->origin().asText()
<< (before? before->indexInMap() : -1)
<< (after? after->indexInMap() : -1)
<< (selfRef? "SELFREF" : "");
}
#endif
};

} // namespace bsp
} // namespace de

#endif // LIBDENG_BSP_HEDGEINTERCEPT
#endif // DENG_WORLD_MAP_BSP_HEDGEINTERCEPT
3 changes: 1 addition & 2 deletions doomsday/client/include/map/bsp/lineinfo.h
Expand Up @@ -70,8 +70,7 @@ struct LineInfo
Vertex const &to = line->to();

// Check for zero-length line.
if((de::abs(from.origin()[VX] - to.origin()[VX]) < distEpsilon) &&
(de::abs(from.origin()[VY] - to.origin()[VY]) < distEpsilon))
if(de::abs(Vector2d(to.origin() - from.origin()).length()) < distEpsilon)
flags |= ZeroLength;

if(line->hasFrontSections() && line->hasBackSections())
Expand Down
10 changes: 7 additions & 3 deletions doomsday/client/include/map/bspleaf.h
Expand Up @@ -22,9 +22,9 @@
#define DENG_WORLD_MAP_BSPLEAF

#include <de/aabox.h>
#include <de/vector1.h>

#include <de/Error>
#include <de/Vector>

#include "MapElement"
#ifdef __CLIENT__
Expand Down Expand Up @@ -98,7 +98,7 @@ class BspLeaf : public de::MapElement
* vertexes which define the geometry of the BSP leaf in map coordinate space
* units.
*/
vec2d_t const &center() const;
de::Vector2d const &center() const;

/**
* Update the center point in the map coordinate space.
Expand Down Expand Up @@ -197,7 +197,7 @@ class BspLeaf : public de::MapElement
*
* @see aaBox()
*/
vec2d_t const &worldGridOffset() const;
de::Vector2d const &worldGridOffset() const;

/**
* Returns the @em validCount of the BSP leaf. Used by some legacy iteration
Expand Down Expand Up @@ -259,6 +259,10 @@ class BspLeaf : public de::MapElement

#endif // __CLIENT__

#ifdef DENG_DEBUG
void printHEdges() const;
#endif

protected:
int property(setargs_t &args) const;

Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/audio/s_environ.cpp
Expand Up @@ -166,10 +166,10 @@ static void findBspLeafsAffectingSector(GameMap *map, Sector *sec)
{
// Is this BSP leaf close enough?
if(bspLeaf->sectorPtr() == sec || // leaf is IN this sector
(bspLeaf->center()[VX] > affectionBounds.minX &&
bspLeaf->center()[VY] > affectionBounds.minY &&
bspLeaf->center()[VX] < affectionBounds.maxX &&
bspLeaf->center()[VY] < affectionBounds.maxY))
(bspLeaf->center().x > affectionBounds.minX &&
bspLeaf->center().y > affectionBounds.minY &&
bspLeaf->center().x < affectionBounds.maxX &&
bspLeaf->center().y < affectionBounds.maxY))
{
// It will contribute to the reverb settings of this sector.
setBspLeafSectorOwner(&bspLeafOwnerList, bspLeaf);
Expand Down
12 changes: 6 additions & 6 deletions doomsday/client/src/edit_map.cpp
Expand Up @@ -165,11 +165,11 @@ class EditableMap
if(vertex == other.vertex) return 0;

// Order is firstly X axis major.
if(int(vertex->origin()[VX]) != int(other.vertex->origin()[VX]))
return int(vertex->origin()[VX]) - int(other.vertex->origin()[VX]);
if(int(vertex->origin().x) != int(other.vertex->origin().x))
return int(vertex->origin().x) - int(other.vertex->origin().x);

// Order is secondly Y axis major.
return int(vertex->origin()[VY]) - int(other.vertex->origin()[VY]);
return int(vertex->origin().y) - int(other.vertex->origin().y);
}

bool operator < (VertexInfo const &other) const {
Expand Down Expand Up @@ -460,8 +460,8 @@ static int lineAngleSorter(void const *a, void const *b)
Line *line = &own[i]->line();
Vertex const &otherVtx = line->vertex(&line->v1() == rootVtx? 1:0);

fixed_t dx = otherVtx.origin()[VX] - rootVtx->origin()[VX];
fixed_t dy = otherVtx.origin()[VY] - rootVtx->origin()[VY];
fixed_t dx = otherVtx.origin().x - rootVtx->origin().x;
fixed_t dy = otherVtx.origin().y - rootVtx->origin().y;

own[i]->_angle = angles[i] = bamsAtan2(-100 *dx, 100 * dy);

Expand Down Expand Up @@ -1024,7 +1024,7 @@ int MPE_LineCreate(int v1, int v2, int frontSectorIdx, int backSectorIdx, int fl
/// @todo fixme: We need to allow these... -ds
Vertex *vtx1 = editMap.vertexes[v1];
Vertex *vtx2 = editMap.vertexes[v2];
if(Vector2d(vtx1->origin() - vtx2->origin()).length() <= 0) return -1;
if(de::abs(Vector2d(vtx1->origin() - vtx2->origin()).length()) <= 0.0001) return -1;

Sector *frontSector = (frontSectorIdx >= 0? editMap.sectors[frontSectorIdx] : 0);
Sector *backSector = (backSectorIdx >= 0? editMap.sectors[ backSectorIdx] : 0);
Expand Down
74 changes: 18 additions & 56 deletions doomsday/client/src/map/bsp/partitioner.cpp
Expand Up @@ -83,9 +83,7 @@ static LineRelationship lineRelationship(coord_t a, coord_t b,

static Vector2d findBspLeafCenter(BspLeaf const &leaf);

//DENG_DEBUG_ONLY(static bool bspLeafHasRealHEdge(BspLeaf const &leaf));
//DENG_DEBUG_ONLY(static void printBspLeafHEdges(BspLeaf const &leaf));
//DENG_DEBUG_ONLY(static void printPartitionIntercepts(HPlane const &partition));
//static void printPartitionIntercepts(HPlane const &partition);

DENG2_PIMPL(Partitioner)
{
Expand Down Expand Up @@ -578,23 +576,15 @@ DENG2_PIMPL(Partitioner)
{
if(!cur->selfRef)
{
Vector2d nearPoint = Vector2d(cur->vertex->origin())
+ Vector2d(next->vertex->origin());
nearPoint.x /= 2;
nearPoint.y /= 2;

Vector2d nearPoint = (cur->vertex->origin() + next->vertex->origin()) / 2;
notifyUnclosedSectorFound(*cur->after, nearPoint);
}
}
else if(!cur->after && next->before)
{
if(!next->selfRef)
{
Vector2d nearPoint = Vector2d(cur->vertex->origin())
+ Vector2d(next->vertex->origin());
nearPoint.x /= 2;
nearPoint.y /= 2;

Vector2d nearPoint = (cur->vertex->origin() + next->vertex->origin()) / 2;
notifyUnclosedSectorFound(*next->before, nearPoint);
}
}
Expand All @@ -608,9 +598,9 @@ DENG2_PIMPL(Partitioner)
{
LOG_DEBUG("Sector mismatch (#%d %s != #%d %s.")
<< cur->after->indexInMap()
<< Vector2d(cur->vertex->origin()).asText()
<< cur->vertex->origin().asText()
<< next->before->indexInMap()
<< Vector2d(next->vertex->origin()).asText();
<< next->vertex->origin().asText();
}

if(cur->selfRef && !next->selfRef)
Expand All @@ -631,12 +621,12 @@ DENG2_PIMPL(Partitioner)
"\n %p LEFT sector #%d %s to %s")
<< de::dintptr(right)
<< (hedgeInfo(*right).sector? hedgeInfo(*right).sector->indexInMap() : -1)
<< Vector2d(right->v1Origin()).asText()
<< Vector2d(right->v2Origin()).asText()
<< right->v1Origin().asText()
<< right->v2Origin().asText()
<< de::dintptr(left)
<< (hedgeInfo(*left).sector? hedgeInfo(*left).sector->indexInMap() : -1)
<< Vector2d(left->v1Origin()).asText()
<< Vector2d(left->v2Origin()).asText()
<< left->v1Origin().asText()
<< left->v2Origin().asText()
*/
}
}
Expand Down Expand Up @@ -1611,17 +1601,16 @@ DENG2_PIMPL(Partitioner)
clearPartitionIntercepts();

// We can now reconfire the half-plane itself.
setPartitionInfo(hedgeInfo(*hedge), &hedge->lineSide().line());

Vector2d from = Vector2d(hedge->line().vertex(hedge->lineSideId()).origin());
Vector2d to = Vector2d(hedge->line().vertex(hedge->lineSideId()^1).origin());
partition.setOrigin(from);
Line &line = hedge->line();
setPartitionInfo(hedgeInfo(*hedge), &line);

Vector2d angle = to - from;
partition.setDirection(angle);
Vertex const &from = line.vertex(hedge->lineSideId());
Vertex const &to = line.vertex(hedge->lineSideId()^1);
partition.setOrigin(from.origin());
partition.setDirection(to.origin() - from.origin());

//LOG_DEBUG("hedge %p %s %s.")
// << de::dintptr(best) << from.asText() << angle.asText();
// << de::dintptr(best) << partition.origin.asText() << partition.direction.asText();

return true;
}
Expand Down Expand Up @@ -1701,7 +1690,7 @@ DENG2_PIMPL(Partitioner)
}

// LOG_DEBUG("Sorted half-edges around %s" << point.asText();
// printBspLeafHEdges(leaf);
// leaf.printHEdges();
}

/**
Expand Down Expand Up @@ -2476,33 +2465,6 @@ static Vector2d findBspLeafCenter(BspLeaf const &leaf)
}

#if 0
DENG_DEBUG_ONLY(
static bool bspLeafHasRealHEdge(BspLeaf const &leaf)
{
HEdge *hedge = leaf.hedge;
do
{
if(hedge->line) return true;
} while((hedge = hedge->next) != leaf.hedge);
return false;
})

DENG_DEBUG_ONLY(
static void printBspLeafHEdges(BspLeaf const &leaf)
{
for(HEdge *hedge = leaf.hedge; hedge; hedge = hedge->next)
{
coord_t angle = M_DirectionToAngleXY(hedge->v1Origin[VX] - point[VX],
hedge->v1Origin[VY] - point[VY]);

LOG_DEBUG(" half-edge %p: Angle %1.6f (%1.1f, %1.1f) -> (%1.1f, %1.1f)")
<< de::dintptr(hedge) << angle
<< hedge->v1Origin[VX] << hedge->v1Origin[VY]
<< hedge->v2Origin[VX] << hedge->v2Origin[VY];
}
})

DENG_DEBUG_ONLY(
static void printPartitionIntercepts(HPlane const &partition)
{
uint index = 0;
Expand All @@ -2511,5 +2473,5 @@ static void printPartitionIntercepts(HPlane const &partition)
Con_Printf(" %u: >%1.2f ", index++, i->distance());
HEdgeIntercept::DebugPrint(*reinterpret_cast<HEdgeIntercept*>(i->userData()));
}
})
}
#endif
42 changes: 28 additions & 14 deletions doomsday/client/src/map/bspleaf.cpp
Expand Up @@ -20,9 +20,10 @@

#include <cmath> // fmod

#include <de/Log>
#include <de/mathutil.h>
#include <de/memoryzone.h>

#include "de_base.h"
#include <de/Log>

#include "HEdge"
#include "Polyobj"
Expand All @@ -47,11 +48,11 @@ DENG2_PIMPL(BspLeaf)
AABoxd aaBox;

/// Center of vertices.
coord_t center[2];
Vector2d center;

/// Offset to align the top left of materials in the built geometry to the
/// map coordinate space grid.
coord_t worldGridOffset[2];
Vector2d worldGridOffset;

/// Sector attributed to the leaf. @note can be @c 0 (degenerate!).
Sector *sector;
Expand Down Expand Up @@ -85,10 +86,7 @@ DENG2_PIMPL(BspLeaf)
addSpriteCount(0),
#endif
validCount(0)
{
std::memset(center, 0, sizeof(center));
std::memset(worldGridOffset, 0, sizeof(worldGridOffset));
}
{}

#ifdef __CLIENT__

Expand Down Expand Up @@ -242,27 +240,25 @@ void BspLeaf::updateAABox()
}
}

vec2d_t const &BspLeaf::center() const
Vector2d const &BspLeaf::center() const
{
return d->center;
}

void BspLeaf::updateCenter()
{
// The middle is the center of our AABox.
d->center[VX] = d->aaBox.minX + (d->aaBox.maxX - d->aaBox.minX) / 2;
d->center[VY] = d->aaBox.minY + (d->aaBox.maxY - d->aaBox.minY) / 2;
d->center = Vector2d(d->aaBox.min) + (Vector2d(d->aaBox.max) - Vector2d(d->aaBox.min)) / 2;
}

vec2d_t const &BspLeaf::worldGridOffset() const
Vector2d const &BspLeaf::worldGridOffset() const
{
return d->worldGridOffset;
}

void BspLeaf::updateWorldGridOffset()
{
d->worldGridOffset[VX] = fmod(d->aaBox.minX, 64);
d->worldGridOffset[VY] = fmod(d->aaBox.maxY, 64);
d->worldGridOffset = Vector2d(fmod(d->aaBox.minX, 64), fmod(d->aaBox.maxY, 64));
}

HEdge *BspLeaf::firstHEdge() const
Expand Down Expand Up @@ -364,6 +360,24 @@ void BspLeaf::setAddSpriteCount(int newFrameCount)

#endif // __CLIENT__

#ifdef DENG_DEBUG
void BspLeaf::printHEdges() const
{
if(!_hedge) return;
HEdge const *hedge = _hedge;
do
{
coord_t angle = M_DirectionToAngleXY(hedge->v1Origin().x - d->center.x,
hedge->v1Origin().y - d->center.y);

LOG_DEBUG(" half-edge %p: Angle %1.6f %s -> %s")
<< de::dintptr(hedge) << angle
<< hedge->v1Origin().asText() << hedge->v2Origin().asText();

} while((hedge = &hedge->next()) != _hedge);
}
#endif

int BspLeaf::property(setargs_t &args) const
{
switch(args.prop)
Expand Down

0 comments on commit 179ff76

Please sign in to comment.