Skip to content

Commit

Permalink
BSP Builder|Refactor: Partitioner now has owership of the HEdgeTips
Browse files Browse the repository at this point in the history
Added a set of VertexInfo structures for each vertex in the map
which holds the HEdgeTip list head.
  • Loading branch information
danij-deng committed Apr 6, 2012
1 parent 65e9a75 commit feb1849
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 155 deletions.
7 changes: 3 additions & 4 deletions doomsday/engine/portable/include/edit_bsp.h
Expand Up @@ -24,8 +24,8 @@

#include "dd_types.h"

struct vertex_s;
struct gamemap_s;
struct vertex_s;

#ifdef __cplusplus
extern "C" {
Expand All @@ -39,7 +39,7 @@ extern int bspFactor;

void BspBuilder_Register(void);

BspBuilder_c* BspBuilder_New(struct gamemap_s* map);
BspBuilder_c* BspBuilder_New(struct gamemap_s* map, uint* numEditableVertexes, struct vertex_s*** editableVertexes);

void BspBuilder_Delete(BspBuilder_c* builder);

Expand All @@ -54,8 +54,7 @@ BspBuilder_c* BspBuilder_SetSplitCostFactor(BspBuilder_c* builder, int factor);
*/
boolean BspBuilder_Build(BspBuilder_c* builder);

void MPE_SaveBsp(BspBuilder_c* builder, struct gamemap_s* map, struct vertex_s*** editableVertexes,
uint* numEditableVertexes);
void MPE_SaveBsp(BspBuilder_c* builder, struct gamemap_s* map, uint* numEditableVertexes, struct vertex_s*** editableVertexes);

#ifdef __cplusplus
} // extern "C"
Expand Down
21 changes: 0 additions & 21 deletions doomsday/engine/portable/include/edit_map.h
Expand Up @@ -100,27 +100,6 @@ void MPE_PruneRedundantMapData(editmap_t* map, int flags);
GameMap* MPE_GetLastBuiltMap(void);
Vertex* createVertex(void);

#define ET_prev link[0]
#define ET_next link[1]
#define ET_edge hedges

// An edge tip is where an edge meets a vertex.
typedef struct edgetip_s {
// Link in list. List is kept in ANTI-clockwise order.
struct edgetip_s* link[2]; // {prev, next};

/// Angle that line makes at vertex (degrees; 0 is E, 90 is N).
double angle;

// Half-edge on each side of the edge. Left is the side of increasing
// angles, right is the side of decreasing angles. Either can be NULL
// for one sided edges.
struct hedge_s* hedges[2];
} edgetip_t;

struct edgetip_s* MPE_NewEdgeTip(void);
void MPE_DeleteEdgeTip(struct edgetip_s* tip);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
66 changes: 55 additions & 11 deletions doomsday/engine/portable/include/map/bsp/partitioner.h
Expand Up @@ -33,10 +33,38 @@
#include "map/bsp/bsptreenode.h"
#include "map/bsp/bsphedgeinfo.h"
#include "map/bsp/linedefinfo.h"
#include "map/bsp/vertexinfo.h"

#include <vector>
#include <list>

#define ET_prev link[0]
#define ET_next link[1]
#define ET_edge hedges

// An edge tip is where an edge meets a vertex.
struct HEdgeTip
{
// Link in list. List is kept in ANTI-clockwise order.
HEdgeTip* link[2]; // {prev, next};

/// Angle that line makes at vertex (degrees; 0 is E, 90 is N).
double angle;

// Half-edge on each side of the edge. Left is the side of increasing
// angles, right is the side of decreasing angles. Either can be NULL
// for one sided edges.
struct hedge_s* hedges[2];

HEdgeTip() : angle()
{
link[0] = 0;
link[1] = 0;
hedges[0] = 0;
hedges[1] = 0;
}
};

namespace de {
namespace bsp {

Expand Down Expand Up @@ -83,16 +111,7 @@ class SuperBlockmap;
class Partitioner
{
public:
Partitioner(GameMap* _map, int _splitCostFactor=7) :
splitCostFactor(_splitCostFactor),
map(_map),
rootNode(0), partition(0),
unclosedSectors(), migrantHEdges(),
builtOK(false)
{
initPartitionInfo();
}

Partitioner(GameMap* _map, uint* numEditableVertexes, Vertex*** editableVertexes, int _splitCostFactor=7);
~Partitioner();

void setSplitCostFactor(int factor)
Expand Down Expand Up @@ -127,6 +146,17 @@ class Partitioner
return lineDefInfos[lineDef.buildData.index - 1];
}

/**
* Retrieve the extended build info for the specified @a vertex.
* @return Extended info for that Vertex.
*/
VertexInfo& vertexInfo(const Vertex& vertex) {
return vertexInfos[vertex.buildData.index - 1];
}
const VertexInfo& vertexInfo(const Vertex& vertex) const {
return vertexInfos[vertex.buildData.index - 1];
}

void findMapBounds(AABoxf* aaBox) const;

/**
Expand Down Expand Up @@ -154,7 +184,7 @@ class Partitioner

void buildHEdgesAtIntersectionGaps(SuperBlock& rightList, SuperBlock& leftList);

void addEdgeTip(Vertex* vert, double angle, HEdge* back, HEdge* front);
void addHEdgeTip(Vertex* vert, double angle, HEdge* back, HEdge* front);

/// @c true Iff @a hedge has been added to a BSP leaf (i.e., it is no longer
/// linked in the hedge blockmap).
Expand Down Expand Up @@ -296,6 +326,12 @@ class Partitioner
HEdge* newHEdge(LineDef* line, LineDef* sourceLine, Vertex* start, Vertex* end,
Sector* sec, bool back);

HEdgeTip* newHEdgeTip();

void deleteHEdgeTip(HEdgeTip* tip);

void deleteHEdgeTips(Vertex* vtx);

/**
* Create a clone of an existing half-edge.
*/
Expand Down Expand Up @@ -349,10 +385,18 @@ class Partitioner
/// Current map which we are building BSP data for.
GameMap* map;

/// @todo Refactor me away:
uint* numEditableVertexes;
Vertex*** editableVertexes;

/// Extra info about LineDefs in the current map.
typedef std::vector<LineDefInfo> LineDefInfos;
LineDefInfos lineDefInfos;

/// Extra info about Vertexes in the current map.
typedef std::vector<VertexInfo> VertexInfos;
VertexInfos vertexInfos;

/// Root node of our internal binary tree around which the final BSP data
/// objects are constructed.
BspTreeNode* rootNode;
Expand Down
50 changes: 50 additions & 0 deletions doomsday/engine/portable/include/map/bsp/vertexinfo.h
@@ -0,0 +1,50 @@
/**
* @file vertexinfo.h
* BSP Builder Vertex info. @ingroup bsp
*
* Based on glBSP 2.24 (in turn, based on BSP 2.3), which is hosted on
* SourceForge: http://sourceforge.net/projects/glbsp/
*
* @authors Copyright © 2007-2012 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 LIBDENG_BSP_VERTEXINFO
#define LIBDENG_BSP_VERTEXINFO

struct HEdgeTip;

namespace de {
namespace bsp {

/**
* Plain old data (POD) structure used to record additional information and
* precalculated values for a Vertex in the current map.
*/
struct VertexInfo
{
struct HEdgeTip* tipSet;
VertexInfo::VertexInfo() : tipSet(0)
{}
};

} // namespace bsp
} // namespace de

#endif /// LIBDENG_BSP_VERTEXINFO
3 changes: 2 additions & 1 deletion doomsday/engine/portable/include/map/bspbuilder.h
Expand Up @@ -53,7 +53,8 @@ class BspBuilder
* @param map GameMap for which to construct a BSP object tree.
* @param splitCostFactor Cost factor attributed to splitting an existing half-edge.
*/
explicit BspBuilder(GameMap* map, int splitCostFactor = DEFAULT_PARTITION_COST_HEDGESPLIT);
explicit BspBuilder(GameMap* map, uint* numEditableVertexes, Vertex*** editableVertexes,
int splitCostFactor = DEFAULT_PARTITION_COST_HEDGESPLIT);
~BspBuilder();

/**
Expand Down
2 changes: 0 additions & 2 deletions doomsday/engine/portable/include/mapdata.hs
Expand Up @@ -43,8 +43,6 @@ typedef struct mvertex_s {
// previous vertex. Only used during the pruning phase.
struct vertex_s* equiv;

struct edgetip_s* tipSet; // Set of wall_tips.

// Final data.
double pos[2];
} mvertex_t;
Expand Down
4 changes: 1 addition & 3 deletions doomsday/engine/portable/include/p_maptypes.h
Expand Up @@ -9,7 +9,7 @@ struct bsphedgeinfo_s;

// Each Sector and SideDef has an origin in the world (used for distance based delta queuing)
typedef struct origin_s {
float pos[2];
float pos[2];
} origin_t;

#define LO_prev link[0]
Expand Down Expand Up @@ -42,8 +42,6 @@ typedef struct mvertex_s {
// previous vertex. Only used during the pruning phase.
struct vertex_s *equiv;

struct edgetip_s *tipSet; // Set of wall_tips.

// Final data.
double pos[2];
} mvertex_t;
Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/portable/src/edit_bsp.cpp
Expand Up @@ -44,10 +44,10 @@ void BspBuilder_Register(void)
C_VAR_INT("bsp-factor", &bspFactor, CVF_NO_MAX, 0, 0);
}

BspBuilder_c* BspBuilder_New(GameMap* map)
BspBuilder_c* BspBuilder_New(GameMap* map, uint* numEditableVertexes, Vertex*** editableVertexes)
{
BspBuilder_c* builder = static_cast<BspBuilder_c*>(malloc(sizeof *builder));
builder->inst = new BspBuilder(map);
builder->inst = new BspBuilder(map, numEditableVertexes, editableVertexes);
return builder;
}

Expand Down Expand Up @@ -293,7 +293,7 @@ static void updateVertexLinks(GameMap* map)
}
}

void MPE_SaveBsp(BspBuilder_c* builder, GameMap* map, Vertex*** vertexes, uint* numVertexes)
void MPE_SaveBsp(BspBuilder_c* builder, GameMap* map, uint* numVertexes, Vertex*** vertexes)
{
Q_ASSERT(builder);

Expand Down
27 changes: 2 additions & 25 deletions doomsday/engine/portable/src/edit_map.c
Expand Up @@ -211,19 +211,6 @@ static void destroyEditableSectors(editmap_t* map)
map->numSectors = 0;
}

edgetip_t* MPE_NewEdgeTip(void)
{
return (edgetip_t*)M_Calloc(sizeof(edgetip_t));
}

void MPE_DeleteEdgeTip(struct edgetip_s* tip)
{
if(tip)
{
M_Free(tip);
}
}

static void destroyEditableVertexes(editmap_t* map)
{
if(map->vertexes)
Expand All @@ -232,16 +219,6 @@ static void destroyEditableVertexes(editmap_t* map)
for(i = 0; i < map->numVertexes; ++i)
{
Vertex* vtx = map->vertexes[i];
edgetip_t* tip, *n;

tip = vtx->buildData.tipSet;
while(tip)
{
n = tip->ET_next;
MPE_DeleteEdgeTip(tip);
tip = n;
}

M_Free(vtx);
}

Expand Down Expand Up @@ -1595,13 +1572,13 @@ static boolean buildBsp(GameMap* gamemap)
// It begins...
startTime = Sys_GetRealTime();

bspBuilder = BspBuilder_New(gamemap);
bspBuilder = BspBuilder_New(gamemap, &map->numVertexes, &map->vertexes);
BspBuilder_SetSplitCostFactor(bspBuilder, bspFactor);

builtOK = BspBuilder_Build(bspBuilder);
if(builtOK)
{
MPE_SaveBsp(bspBuilder, gamemap, &map->vertexes, &map->numVertexes);
MPE_SaveBsp(bspBuilder, gamemap, &map->numVertexes, &map->vertexes);
}

BspBuilder_Delete(bspBuilder);
Expand Down

0 comments on commit feb1849

Please sign in to comment.