Navigation Menu

Skip to content

Commit

Permalink
Wad Map Converter|Refactor: Relocated some utility routines to new so…
Browse files Browse the repository at this point in the history
…urce files
  • Loading branch information
danij-deng committed Jul 23, 2012
1 parent 1fec202 commit ea4483c
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 69 deletions.
60 changes: 60 additions & 0 deletions doomsday/plugins/wadmapconverter/include/id1map_util.h
@@ -0,0 +1,60 @@
/**
* @file id1map_util.h @ingroup wadmapconverter
*
* @authors Copyright &copy; 2007-2012 Daniel Swanson <danij@dengine.net>
*
* @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 __WADMAPCONVERTER_ID1MAP_UTIL_H__
#define __WADMAPCONVERTER_ID1MAP_UTIL_H__

#include "doomsday.h"
#include "dd_types.h"
#include "maplumpinfo.h"

/**
* Logical map format identifier (unique).
*/
typedef enum {
MF_UNKNOWN = -1,
MF_DOOM = 0,
MF_HEXEN,
MF_DOOM64,
NUM_MAPFORMATS
} mapformatid_t;

/**
* Helper macro for determining whether a value can be interpreted as a logical
* map format identifier (@see mapformatid_t).
*/
#define VALID_MAPFORMATID(v) ((v) >= MF_DOOM && (v) < NUM_MAPFORMATS)

/**
* Retrieve the textual name for the identified map format @a id.
* @param id Unique identifier of the map format.
* @return Textual name for this format. Always returns a valid ddstring_t that
* should NOT be free'd.
*/
const ddstring_t* MapFormatNameForId(mapformatid_t id);

/**
* Determine type of a named map data lump.
* @param name Name of the data lump.
* @return MapLumpType associated with the named map data lump.
*/
MapLumpType MapLumpTypeForName(const char* name);

#endif /* __WADMAPCONVERTER_ID1MAP_UTIL_H__ */
12 changes: 2 additions & 10 deletions doomsday/plugins/wadmapconverter/include/wadmapconverter.h
Expand Up @@ -48,19 +48,11 @@
# define WADMAPCONVERTER_TRACE(args)
#endif

typedef enum {
MF_UNKNOWN = -1,
MF_DOOM = 0,
MF_HEXEN,
MF_DOOM64,
NUM_MAPFORMATS
} mapformatid_t;

#define VALID_MAPFORMATID(v) ((v) >= MF_DOOM && (v) < NUM_MAPFORMATS)

extern int DENG_PLUGIN_GLOBAL(verbose);

#define VERBOSE(code) { if(DENG_PLUGIN_GLOBAL(verbose) >= 1) { code; } }
#define VERBOSE2(code) { if(DENG_PLUGIN_GLOBAL(verbose) >= 2) { code; } }

#include "id1map_util.h"

#endif /* end of include guard: __WADMAPCONVERTER_H__ */
82 changes: 82 additions & 0 deletions doomsday/plugins/wadmapconverter/src/id1map_util.cpp
@@ -0,0 +1,82 @@
/**
* @file id1map_util.cpp @ingroup wadmapconverter
*
* Miscelaneous map conversion utility routines.
*
* @authors Copyright &copy; 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright &copy; 2006-2012 Daniel Swanson <danij@dengine.net>
*
* @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>
*/

#include "wadmapconverter.h"
#include "maplumpinfo.h"

const ddstring_t* MapFormatNameForId(mapformatid_t id)
{
static const ddstring_t names[1 + NUM_MAPFORMATS] = {
/* MF_UNKNOWN */ { "Unknown" },
/* MF_DOOM */ { "Doom" },
/* MF_HEXEN */ { "Hexen" },
/* MF_DOOM64 */ { "Doom64" }
};
if(VALID_MAPFORMATID(id))
{
return &names[1+id];
}
return &names[0];
}

MapLumpType MapLumpTypeForName(const char* name)
{
static const struct maplumpinfo_s {
const char* name;
MapLumpType type;
} lumptypeForNameDict[] =
{
{ "THINGS", ML_THINGS },
{ "LINEDEFS", ML_LINEDEFS },
{ "SIDEDEFS", ML_SIDEDEFS },
{ "VERTEXES", ML_VERTEXES },
{ "SEGS", ML_SEGS },
{ "SSECTORS", ML_SSECTORS },
{ "NODES", ML_NODES },
{ "SECTORS", ML_SECTORS },
{ "REJECT", ML_REJECT },
{ "BLOCKMAP", ML_BLOCKMAP },
{ "BEHAVIOR", ML_BEHAVIOR },
{ "SCRIPTS", ML_SCRIPTS },
{ "LIGHTS", ML_LIGHTS },
{ "MACROS", ML_MACROS },
{ "LEAFS", ML_LEAFS },
{ "GL_VERT", ML_GLVERT },
{ "GL_SEGS", ML_GLSEGS },
{ "GL_SSECT", ML_GLSSECT },
{ "GL_NODES", ML_GLNODES },
{ "GL_PVS", ML_GLPVS},
{ NULL }
};

DENG_ASSERT(name);

if(name[0])
for(int i = 0; lumptypeForNameDict[i].name; ++i)
{
if(!strnicmp(lumptypeForNameDict[i].name, name, strlen(lumptypeForNameDict[i].name)))
return lumptypeForNameDict[i].type;
}

return ML_INVALID;
}
61 changes: 2 additions & 59 deletions doomsday/plugins/wadmapconverter/src/wadmapconverter.cpp
Expand Up @@ -37,63 +37,6 @@ static void configure(void)
DENG_PLUGIN_GLOBAL(verbose) = CommandLine_Exists("-verbose");
}

static const ddstring_t* mapFormatNameForId(mapformatid_t id)
{
static const ddstring_t names[1 + NUM_MAPFORMATS] = {
/* MF_UNKNOWN */ { "Unknown" },
/* MF_DOOM */ { "Doom" },
/* MF_HEXEN */ { "Hexen" },
/* MF_DOOM64 */ { "Doom64" }
};
if(VALID_MAPFORMATID(id))
{
return &names[1+id];
}
return &names[0];
}

static MapLumpType mapLumpTypeForName(const char* name)
{
static const struct maplumpinfo_s {
const char* name;
MapLumpType type;
} lumptypeForNameDict[] =
{
{ "THINGS", ML_THINGS },
{ "LINEDEFS", ML_LINEDEFS },
{ "SIDEDEFS", ML_SIDEDEFS },
{ "VERTEXES", ML_VERTEXES },
{ "SEGS", ML_SEGS },
{ "SSECTORS", ML_SSECTORS },
{ "NODES", ML_NODES },
{ "SECTORS", ML_SECTORS },
{ "REJECT", ML_REJECT },
{ "BLOCKMAP", ML_BLOCKMAP },
{ "BEHAVIOR", ML_BEHAVIOR },
{ "SCRIPTS", ML_SCRIPTS },
{ "LIGHTS", ML_LIGHTS },
{ "MACROS", ML_MACROS },
{ "LEAFS", ML_LEAFS },
{ "GL_VERT", ML_GLVERT },
{ "GL_SEGS", ML_GLSEGS },
{ "GL_SSECT", ML_GLSSECT },
{ "GL_NODES", ML_GLNODES },
{ "GL_PVS", ML_GLPVS},
{ NULL }
};

DENG_ASSERT(name);

if(name[0])
for(int i = 0; lumptypeForNameDict[i].name; ++i)
{
if(!strnicmp(lumptypeForNameDict[i].name, name, strlen(lumptypeForNameDict[i].name)))
return lumptypeForNameDict[i].type;
}

return ML_INVALID;
}

/**
* Allocate and initialize a new MapLumpInfo record.
*/
Expand All @@ -113,7 +56,7 @@ static lumpnum_t locateMapMarkerLumpForUri(const Uri* uri)
static MapLumpType recogniseMapLump(lumpnum_t lumpNum)
{
/// @todo Relocate recognition logic from IsSupportedFormat() here.
return mapLumpTypeForName(W_LumpName(lumpNum));
return MapLumpTypeForName(W_LumpName(lumpNum));
}

/**
Expand Down Expand Up @@ -207,7 +150,7 @@ int ConvertMapHook(int hookType, int parm, void* context)
}

VERBOSE( Con_Message("WadMapConverter: Recognised a %s format map.\n",
Str_Text(mapFormatNameForId(mapFormat))) );
Str_Text(MapFormatNameForId(mapFormat))) );

// Read the archived map.
int loadError = !LoadMap(lumpInfos);
Expand Down
2 changes: 2 additions & 0 deletions doomsday/plugins/wadmapconverter/wadmapconverter.pro
Expand Up @@ -15,12 +15,14 @@ deng_debug: DEFINES += DENG_WADMAPCONVERTER_DEBUG
INCLUDEPATH += include

HEADERS += \
include/id1map_util.h \
include/map.h \
include/maplumpinfo.h \
include/version.h \
include/wadmapconverter.h

SOURCES += \
src/id1map_util.cpp \
src/load.cpp \
src/wadmapconverter.cpp

Expand Down

0 comments on commit ea4483c

Please sign in to comment.