Skip to content

Commit

Permalink
Refactor|Partitioner: Separated partition intercept list from the hal…
Browse files Browse the repository at this point in the history
…f-plane

Wrapping the partition and the list of intercepts into an object
with the associated semantics of object access has little practical
benefit. It makes the intercept list harder to manipulate and it
demands a robust API to manage them in such a manner.

The only benefit to this abstraction is that it ensure that the list
of intersections is always sorted. However, this can be achieved by
other more practical means (todo).
  • Loading branch information
danij-deng committed Apr 25, 2013
1 parent 60ff606 commit 56a102a
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 367 deletions.
4 changes: 2 additions & 2 deletions doomsday/client/client.pro
Expand Up @@ -227,7 +227,7 @@ DENG_HEADERS += \
include/map/bsp/hedgeinfo.h \
include/map/bsp/hedgeintercept.h \
include/map/bsp/hedgetip.h \
include/map/bsp/hplane.h \
include/map/bsp/intersections.h \
include/map/bsp/lineinfo.h \
include/map/bsp/partitioncost.h \
include/map/bsp/partitioner.h \
Expand Down Expand Up @@ -498,7 +498,7 @@ SOURCES += \
src/main_client.cpp \
src/map/blockmap.cpp \
src/map/blockmapvisual.cpp \
src/map/bsp/hplane.cpp \
src/map/bsp/intersections.cpp \
src/map/bsp/partitioner.cpp \
src/map/bsp/superblockmap.cpp \
src/map/bspbuilder.cpp \
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/map/bsp/hedgeintercept.h
Expand Up @@ -39,7 +39,7 @@ namespace bsp {
* half-plane intercept point where the geometry intersects (an incident vertex
* can be found here (or at there will be upon insertion.)).
*
* There is always a corresponding HPlaneIntercept in the owning HPlane.
* There is always a corresponding Intercept in the owning Intercepts.
*
* @ingroup bsp
*/
Expand Down
155 changes: 0 additions & 155 deletions doomsday/client/include/map/bsp/hplane.h

This file was deleted.

118 changes: 118 additions & 0 deletions doomsday/client/include/map/bsp/intersections.h
@@ -0,0 +1,118 @@
/** @file map/bsp/intersections.h BSP Builder half-plane intercept list.
*
* Originally based on glBSP 2.24 (in turn, based on BSP 2.3)
* @see http://sourceforge.net/projects/glbsp/
*
* @authors Copyright © 2007-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2000-2007 Andrew Apted <ajapted@gmail.com>
* @authors Copyright © 1998-2000 Colin Reed <cph@moria.org.uk>
* @authors Copyright © 1998-2000 Lee Killough <killough@rsn.hp.com>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef DENG_WORLD_MAP_BSP_INTERSECTIONS
#define DENG_WORLD_MAP_BSP_INTERSECTIONS

#include <list>

namespace de {
namespace bsp {

/**
* @ingroup bsp
*/
class Intersections
{
public:
class Intercept
{
public:
Intercept() : _distance(0), _userData(0)
{}

Intercept(double distance, void *userData)
: _distance(distance), _userData(userData)
{}

/**
* Determine the distance between two intercepts. It does not matter
* if the intercepts are from different half-planes.
*/
double operator - (Intercept const &other) const {
return _distance - other.distance();
}

/**
* Distance from the owning Intercepts's origin point. Negative values
* mean this intercept is positioned to the left of the origin.
*/
double distance() const { return _distance; }

/**
* Retrieve the data pointer associated with this intercept.
*/
void *userData() const { return _userData; }

private:
/**
* Distance along the owning Intercepts in the map coordinate space.
*/
double _distance;

/// User data pointer associated with this intercept.
void *_userData;
};

typedef std::list<Intercept> Intercepts;

typedef bool (*mergepredicate_t)(Intercept &a, Intercept &b, void *userData);

public:
Intersections();
~Intersections();

/**
* Empty all intersections from the specified Intercepts.
*/
void clear();

/**
* Insert a point at the given intersection into the intersection list.
*
* @param distance Distance along the partition for the new intercept,
* in map units.
* @param userData User data object to link with the new intercept.
* Ownership remains unchanged.
*/
Intercept &insert(double distance, void *userData = 0);

void merge(mergepredicate_t predicate, void *userData);

Intercepts const &all() const;

#ifdef DENG_DEBUG
void debugPrint() const;
#endif

private:
/// The intercept list. Kept sorted by distance, in ascending order.
Intercepts _intercepts;
};

} // namespace bsp
} // namespace de

#endif // DENG_WORLD_MAP_BSP_INTERSECTIONS
4 changes: 3 additions & 1 deletion doomsday/client/include/partition.h
Expand Up @@ -39,12 +39,14 @@ class Partition
Vector2d direction;

public:
Partition(Vector2d const &origin, Vector2d const &direction)
Partition(Vector2d const &origin = Vector2d(0, 0),
Vector2d const &direction = Vector2d(0, 0))
: origin(origin), direction(direction) {}

Partition(Partition const &other)
: origin(other.origin), direction(other.direction) {}


/**
* Where does the given @a point lie relative to the partition line?
*
Expand Down

0 comments on commit 56a102a

Please sign in to comment.