Skip to content

Commit

Permalink
BSP Builder|Refactor: Moved unclosed sector record keeping into BspBu…
Browse files Browse the repository at this point in the history
…ilder
  • Loading branch information
danij-deng committed Apr 4, 2012
1 parent ee9f271 commit c9a9b2b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 85 deletions.
4 changes: 0 additions & 4 deletions doomsday/engine/portable/include/edit_map.h
Expand Up @@ -97,10 +97,6 @@ boolean MPE_GameObjProperty(const char *objName, uint idx,

void MPE_PruneRedundantMapData(editmap_t* map, int flags);

boolean MPE_RegisterUnclosedSectorNear(Sector* sec, double x, double y);
void MPE_PrintUnclosedSectorList(void);
void MPE_FreeUnclosedSectorList(void);

GameMap* MPE_GetLastBuiltMap(void);
Vertex* createVertex(void);

Expand Down
80 changes: 3 additions & 77 deletions doomsday/engine/portable/src/edit_map.c
Expand Up @@ -34,8 +34,6 @@
#include "de_dam.h"
#include "de_filesys.h"

//#include "bsp_edge.h" /// @todo Remove me.

#include "s_environ.h"

typedef struct usecrecord_s {
Expand Down Expand Up @@ -503,81 +501,13 @@ void MPE_PruneRedundantMapData(editmap_t* map, int flags)
#endif
}

/**
* Register the specified sector in the list of unclosed sectors.
*
* @param sec Ptr to the sector to be registered.
* @param x Approximate X coordinate to the sector's origin.
* @param y Approximate Y coordinate to the sector's origin.
*
* @return @c true, if sector was registered.
*/
boolean MPE_RegisterUnclosedSectorNear(Sector* sec, double x, double y)
{
usecrecord_t* usec;
uint i;

if(!sec) return false; // Wha?

// Has this sector already been registered as unclosed?
for(i = 0; i < numUnclosedSectors; ++i)
{
if(unclosedSectors[i].sec == sec)
return true;
}

// A new one.
unclosedSectors = M_Realloc(unclosedSectors, ++numUnclosedSectors * sizeof(usecrecord_t));
usec = &unclosedSectors[numUnclosedSectors-1];
usec->sec = sec;
usec->nearPos[VX] = x;
usec->nearPos[VY] = y;

// Flag the sector as unclosed.
sec->flags |= SECF_UNCLOSED;

return true;
}

/**
* Print the list of unclosed sectors.
*/
void MPE_PrintUnclosedSectorList(void)
{
uint i;

if(!editMapInited) return;

for(i = 0; i < numUnclosedSectors; ++i)
{
usecrecord_t* usec = &unclosedSectors[i];

Con_Message("Sector #%d is unclosed near (%1.1f,%1.1f)\n",
usec->sec->buildData.index - 1, usec->nearPos[VX],
usec->nearPos[VY]);
}
}

/**
* Free the list of unclosed sectors.
*/
void MPE_FreeUnclosedSectorList(void)
{
if(unclosedSectors)
M_Free(unclosedSectors);
unclosedSectors = NULL;
numUnclosedSectors = 0;
}

/**
* Called to begin the map building process.
*/
boolean MPE_Begin(const char* mapUri)
{
if(editMapInited) return true; // Already been here.

MPE_FreeUnclosedSectorList();

// Init the gameObj lists, and value db.
map->gameObjData.db.numTables = 0;
map->gameObjData.db.tables = NULL;
Expand Down Expand Up @@ -1743,6 +1673,9 @@ boolean MPE_End(void)
GameMap_InitMobjBlockmap(gamemap, min, max);
GameMap_InitPolyobjBlockmap(gamemap, min, max);

// Announce any issues detected with the map.
MPE_PrintMapErrors();

/**
* Build a BSP for this map.
*/
Expand Down Expand Up @@ -1775,9 +1708,6 @@ boolean MPE_End(void)

buildSectorBspLeafLists(gamemap);

// Announce any issues detected with the map.
MPE_PrintMapErrors();

// Map must be polygonized and sector->bspLeafs must be built before
// this is called!
hardenPlanes(gamemap, map);
Expand All @@ -1803,7 +1733,6 @@ boolean MPE_End(void)
prepareBspLeafs(gamemap);

P_FreeBadTexList();
MPE_FreeUnclosedSectorList();

editMapInited = false;

Expand Down Expand Up @@ -1858,9 +1787,6 @@ GameMap* MPE_GetLastBuiltMap(void)
*/
void MPE_PrintMapErrors(void)
{
// Announce unclosed sectors.
MPE_PrintUnclosedSectorList();

// Announce any bad texture names we came across when loading the map.
P_PrintMissingTextureList();
}
Expand Down
35 changes: 33 additions & 2 deletions doomsday/engine/portable/src/map/bspbuilder/bspbuilder_instance.h
Expand Up @@ -40,6 +40,7 @@
#include "map/bspbuilder/superblockmap.h"

#include <vector>
#include <list>

namespace de {
namespace bspbuilder {
Expand All @@ -52,6 +53,18 @@ const double DIST_EPSILON = (1.0 / 128.0);
/// Smallest difference between two angles before being considered equal (in degrees).
const double ANG_EPSILON = (1.0 / 1024.0);

struct UnclosedSectorRecord
{
Sector* sector;
vec2d_t nearPoint;

UnclosedSectorRecord(Sector* _sector, double x, double y)
: sector(_sector)
{
V2d_Set(nearPoint, x, y);
}
};

/**
* @algorithm High-level description (courtesy of Raphael Quinet)
* 1 - Create one Seg for each SideDef: pick each LineDef in turn. If it
Expand Down Expand Up @@ -81,8 +94,11 @@ const double ANG_EPSILON = (1.0 / 1024.0);
struct BspBuilderImp
{
BspBuilderImp(GameMap* _map, int _splitCostFactor=7) :
splitCostFactor(_splitCostFactor), map(_map),
lineDefInfos(0), rootNode(0), partition(0), builtOK(false)
splitCostFactor(_splitCostFactor),
map(_map),
rootNode(0), partition(0),
unclosedSectors(),
builtOK(false)
{
initPartitionInfo();
}
Expand Down Expand Up @@ -330,6 +346,17 @@ struct BspBuilderImp
memcpy(&partitionInfo, &info, sizeof(partitionInfo));
}

/**
* Register the specified sector in the list of unclosed sectors.
*
* @param sector Sector to be registered.
* @param x X coordinate near the open point.
* @param y X coordinate near the open point.
*
* @return @c true iff sector newly registered.
*/
bool registerUnclosedSector(Sector* sector, double x, double y);

/// The Active HEdge split cost factor. @see BSPBUILDER_PARTITION_COST_HEDGESPLIT
int splitCostFactor;

Expand All @@ -350,6 +377,10 @@ struct BspBuilderImp
/// Extra info about the partition plane.
BspHEdgeInfo partitionInfo;

/// Unclosed sectors are recorded here so we don't print too many warnings.
typedef std::list<UnclosedSectorRecord> UnclosedSectors;
UnclosedSectors unclosedSectors;

/// @c true = a BSP for the current map has been built successfully.
bool builtOK;
};
Expand Down
28 changes: 26 additions & 2 deletions doomsday/engine/portable/src/map/bspbuilder/nodes.cpp
Expand Up @@ -1498,7 +1498,7 @@ void BspBuilderImp::buildHEdgesAtIntersectionGaps(SuperBlock& rightList, SuperBl
pos[VX] /= 2;
pos[VY] /= 2;

MPE_RegisterUnclosedSectorNear(cur->after, pos[VX], pos[VY]);
registerUnclosedSector(cur->after, pos[VX], pos[VY]);
}
}
else if(!cur->after && next->before)
Expand All @@ -1512,7 +1512,7 @@ void BspBuilderImp::buildHEdgesAtIntersectionGaps(SuperBlock& rightList, SuperBl
pos[VX] /= 2;
pos[VY] /= 2;

MPE_RegisterUnclosedSectorNear(next->before, pos[VX], pos[VY]);
registerUnclosedSector(next->before, pos[VX], pos[VY]);
}
}
else
Expand Down Expand Up @@ -1670,3 +1670,27 @@ void BspBuilderImp::deleteHEdgeIntercept(HEdgeIntercept& inter)
{
delete &inter;
}

bool BspBuilderImp::registerUnclosedSector(Sector* sector, double x, double y)
{
if(!sector) return false;

// Has this sector already been registered?
for(UnclosedSectors::const_iterator it = unclosedSectors.begin();
it != unclosedSectors.end(); ++it)
{
UnclosedSectorRecord const& record = *it;
if(record.sector == sector)
return false;
}

// Add a new record.
unclosedSectors.push_back(UnclosedSectorRecord(sector, x, y));

// In the absence of a better mechanism, simply log this right away.
/// @todo Implement something better!
LOG_WARNING("Sector %p #%d is unclosed near [%1.1f, %1.1f].")
<< sector << sector->buildData.index - 1 << x << y;

return true;
}

0 comments on commit c9a9b2b

Please sign in to comment.