Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Wad Map Converter|Refactor: Made private all of Id1Map's data structures
  • Loading branch information
danij-deng committed Jul 28, 2012
1 parent f76a56a commit 35fde8c
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 85 deletions.
54 changes: 41 additions & 13 deletions doomsday/plugins/wadmapconverter/include/id1map.h
@@ -1,5 +1,5 @@
/**
* @file id1map_load.h @ingroup wadmapconverter
* @file id1map.h @ingroup wadmapconverter
*
* @authors Copyright &copy; 2007-2012 Daniel Swanson <danij@dengine.net>
*
Expand Down Expand Up @@ -37,21 +37,11 @@ typedef std::vector<mthing_t> Things;
typedef std::vector<surfacetint_t> SurfaceTints;
typedef std::list<mpolyobj_t> Polyobjs;

typedef std::list<uint> LineList;

class Id1Map
{
public:
uint numVertexes;
coord_t* vertexes; ///< Array of vertex coords [v0:X, vo:Y, v1:X, v1:Y, ..]

Lines lines;
Sides sides;
Sectors sectors;
Things things;
SurfaceTints surfaceTints;
Polyobjs polyobjs;

StringPool* materials; ///< Material dictionary.

Id1Map();
~Id1Map();

Expand All @@ -76,12 +66,50 @@ class Id1Map
bool loadThings(Reader* reader, uint numElements);
bool loadSurfaceTints(Reader* reader, uint numElements);

/**
* Create a temporary polyobj.
*/
mpolyobj_t* createPolyobj(LineList& lineList, int tag, int sequenceType,
int16_t anchorX, int16_t anchorY);
/**
* @param lineList @c NULL, will cause IterFindPolyLines to count
* the number of lines in the polyobj.
*/
void iterFindPolyLines(LineList& lineList, coord_t x, coord_t y);

void collectPolyobjLines(LineList& lineList, Lines::iterator lineIt);

/**
* Find all linedefs marked as belonging to a polyobject with the given tag
* and attempt to create a polyobject from them.
*
* @param tag Line tag of linedefs to search for.
*
* @return @c true = successfully created polyobj.
*/
bool findAndCreatePolyobj(int16_t tag, int16_t anchorX, int16_t anchorY);

void findPolyobjs(void);

void transferVertexes(void);
void transferSectors(void);
void transferLinesAndSides(void);
void transferSurfaceTints(void);
void transferPolyobjs(void);
void transferThings(void);

private:
uint numVertexes;
coord_t* vertexes; ///< Array of vertex coords [v0:X, vo:Y, v1:X, v1:Y, ..]

Lines lines;
Sides sides;
Sectors sectors;
Things things;
SurfaceTints surfaceTints;
Polyobjs polyobjs;

StringPool* materials; ///< Material dictionary.
};

#endif /* __WADMAPCONVERTER_ID1MAP_H__ */
79 changes: 29 additions & 50 deletions doomsday/plugins/wadmapconverter/src/id1map_analyze.cpp
Expand Up @@ -23,26 +23,17 @@

#include "wadmapconverter.h"
#include <de/Log>
#include <list>

#define mapFormat DENG_PLUGIN_GLOBAL(mapFormat)
#define map DENG_PLUGIN_GLOBAL(map)

static uint validCount = 0; // Used for Polyobj LineDef collection.

typedef std::list<uint> LineList;

/**
* Create a temporary polyobj (read from the original map data).
*/
static mpolyobj_t* createPolyobj(LineList& lineList, int tag, int sequenceType,
int16_t anchorX, int16_t anchorY)
mpolyobj_t* Id1Map::createPolyobj(LineList& lineList, int tag,
int sequenceType, int16_t anchorX, int16_t anchorY)
{
// Allocate the new polyobj.
map->polyobjs.push_back(mpolyobj_t());
mpolyobj_t* po = &map->polyobjs.back();
polyobjs.push_back(mpolyobj_t());
mpolyobj_t* po = &polyobjs.back();

po->idx = map->polyobjs.size()-1;
po->idx = polyobjs.size()-1;
po->tag = tag;
po->seqType = sequenceType;
po->anchor[VX] = anchorX;
Expand All @@ -54,7 +45,7 @@ static mpolyobj_t* createPolyobj(LineList& lineList, int tag, int sequenceType,
for(LineList::iterator i = lineList.begin(); i != lineList.end(); ++i, ++n)
{
uint lineIdx = *i;
mline_t* line = &map->lines[lineIdx];
mline_t* line = &lines[lineIdx];

line->aFlags |= LAF_POLYOBJ;
/**
Expand All @@ -75,29 +66,25 @@ static mpolyobj_t* createPolyobj(LineList& lineList, int tag, int sequenceType,
return po;
}

/**
* @param lineList @c NULL, will cause IterFindPolyLines to count
* the number of lines in the polyobj.
*/
static void iterFindPolyLines(LineList& lineList, coord_t x, coord_t y)
void Id1Map::iterFindPolyLines(LineList& lineList, coord_t x, coord_t y)
{
DENG2_FOR_EACH(i, map->lines, Lines::iterator)
DENG2_FOR_EACH(i, lines, Lines::iterator)
{
if((i)->aFlags & LAF_POLYOBJ) continue;
if((i)->validCount == validCount) continue;

coord_t v1[2];
v1[VX] = map->vertexes[( (i)->v[0] - 1 ) * 2];
v1[VY] = map->vertexes[( (i)->v[0] - 1 ) * 2 + 1];
v1[VX] = vertexes[( (i)->v[0] - 1 ) * 2];
v1[VY] = vertexes[( (i)->v[0] - 1 ) * 2 + 1];

coord_t v2[2];
v2[VX] = map->vertexes[( (i)->v[1] - 1 ) * 2];
v2[VY] = map->vertexes[( (i)->v[1] - 1 ) * 2 + 1];
v2[VX] = vertexes[( (i)->v[1] - 1 ) * 2];
v2[VY] = vertexes[( (i)->v[1] - 1 ) * 2 + 1];

if(FEQUAL(v1[VX], x) && FEQUAL(v1[VY], y))
{
(i)->validCount = validCount;
lineList.push_back( i - map->lines.begin() );
lineList.push_back( i - lines.begin() );
iterFindPolyLines(lineList, v2[VX], v2[VY]);
}
}
Expand All @@ -107,41 +94,33 @@ static void iterFindPolyLines(LineList& lineList, coord_t x, coord_t y)
* @todo This terribly inefficent (naive) algorithm may need replacing
* (it is far outside an acceptable polynomial range!).
*/
static void collectPolyobjLines(LineList& lineList, Lines::iterator lineIt)
void Id1Map::collectPolyobjLines(LineList& lineList, Lines::iterator lineIt)
{
mline_t* line = &*lineIt;
line->xType = 0;
line->xArgs[0] = 0;

coord_t v1[2];
v1[VX] = map->vertexes[(line->v[0]-1) * 2];
v1[VY] = map->vertexes[(line->v[0]-1) * 2 + 1];
v1[VX] = vertexes[(line->v[0]-1) * 2];
v1[VY] = vertexes[(line->v[0]-1) * 2 + 1];

coord_t v2[2];
v2[VX] = map->vertexes[(line->v[1]-1) * 2];
v2[VY] = map->vertexes[(line->v[1]-1) * 2 + 1];
v2[VX] = vertexes[(line->v[1]-1) * 2];
v2[VY] = vertexes[(line->v[1]-1) * 2 + 1];

validCount++;
// Insert the first line.
lineList.push_back(lineIt - map->lines.begin());
lineList.push_back(lineIt - lines.begin());
line->validCount = validCount;
iterFindPolyLines(lineList, v2[VX], v2[VY]);
}

/**
* Find all linedefs marked as belonging to a polyobject with the given tag
* and attempt to create a polyobject from them.
*
* @param tag Line tag of linedefs to search for.
*
* @return @c true = successfully created polyobj.
*/
static bool findAndCreatePolyobj(int16_t tag, int16_t anchorX, int16_t anchorY)
bool Id1Map::findAndCreatePolyobj(int16_t tag, int16_t anchorX, int16_t anchorY)
{
LineList polyLines;

// First look for a PO_LINE_START linedef with this tag.
DENG2_FOR_EACH(i, map->lines, Lines::iterator)
DENG2_FOR_EACH(i, lines, Lines::iterator)
{
if((i)->aFlags & LAF_POLYOBJ) continue;
if(!((i)->xType == PO_LINE_START && (i)->xArgs[0] == tag)) continue;
Expand All @@ -166,7 +145,7 @@ static bool findAndCreatePolyobj(int16_t tag, int16_t anchorX, int16_t anchorY)
{
bool foundAnotherLine = false;

DENG2_FOR_EACH(i, map->lines, Lines::iterator)
DENG2_FOR_EACH(i, lines, Lines::iterator)
{
if((i)->aFlags & LAF_POLYOBJ) continue;

Expand All @@ -181,7 +160,7 @@ static bool findAndCreatePolyobj(int16_t tag, int16_t anchorX, int16_t anchorY)
if((i)->xArgs[1] == n+1)
{
// Add this line to the list.
polyLines.push_back( i - map->lines.begin() );
polyLines.push_back( i - lines.begin() );
foundAnotherLine = true;

// Clear any special.
Expand All @@ -196,7 +175,7 @@ static bool findAndCreatePolyobj(int16_t tag, int16_t anchorX, int16_t anchorY)
// Check if an explicit line order has been skipped.
// A line has been skipped if there are any more explicit lines with
// the current tag value.
DENG2_FOR_EACH(i, map->lines, Lines::iterator)
DENG2_FOR_EACH(i, lines, Lines::iterator)
{
if((i)->xType == PO_LINE_EXPLICIT && (i)->xArgs[0] == tag)
{
Expand All @@ -209,7 +188,7 @@ static bool findAndCreatePolyobj(int16_t tag, int16_t anchorX, int16_t anchorY)

if(!polyLines.empty())
{
mline_t* line = &map->lines[ polyLines.front() ];
mline_t* line = &lines[ polyLines.front() ];
const int8_t sequenceType = line->xArgs[3];

// Setup the mirror if it exists.
Expand All @@ -222,10 +201,10 @@ static bool findAndCreatePolyobj(int16_t tag, int16_t anchorX, int16_t anchorY)
return false;
}

static void findPolyobjs(void)
void Id1Map::findPolyobjs(void)
{
LOG_TRACE("Locating polyobjs...");
DENG2_FOR_EACH(i, map->things, Things::iterator)
DENG2_FOR_EACH(i, things, Things::iterator)
{
// A polyobj anchor?
if((i)->doomEdNum == PO_ANCHOR_DOOMEDNUM)
Expand All @@ -238,8 +217,8 @@ static void findPolyobjs(void)

void Id1Map::analyze(void)
{
LOG_AS("WadMapConverter::Id1Map");
if(mapFormat == MF_HEXEN)
LOG_AS("Id1Map");
if(DENG_PLUGIN_GLOBAL(mapFormat) == MF_HEXEN)
{
findPolyobjs();
}
Expand Down

0 comments on commit 35fde8c

Please sign in to comment.