diff --git a/doomsday/plugins/wadmapconverter/include/id1map_util.h b/doomsday/plugins/wadmapconverter/include/id1map_util.h new file mode 100644 index 0000000000..a8b4b9289d --- /dev/null +++ b/doomsday/plugins/wadmapconverter/include/id1map_util.h @@ -0,0 +1,60 @@ +/** + * @file id1map_util.h @ingroup wadmapconverter + * + * @authors Copyright © 2007-2012 Daniel Swanson + * + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html + * + * 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 + */ + +#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__ */ diff --git a/doomsday/plugins/wadmapconverter/include/wadmapconverter.h b/doomsday/plugins/wadmapconverter/include/wadmapconverter.h index 281eb0c78e..8478d68536 100644 --- a/doomsday/plugins/wadmapconverter/include/wadmapconverter.h +++ b/doomsday/plugins/wadmapconverter/include/wadmapconverter.h @@ -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__ */ diff --git a/doomsday/plugins/wadmapconverter/src/id1map_util.cpp b/doomsday/plugins/wadmapconverter/src/id1map_util.cpp new file mode 100644 index 0000000000..98d353f840 --- /dev/null +++ b/doomsday/plugins/wadmapconverter/src/id1map_util.cpp @@ -0,0 +1,82 @@ +/** + * @file id1map_util.cpp @ingroup wadmapconverter + * + * Miscelaneous map conversion utility routines. + * + * @authors Copyright © 2003-2012 Jaakko Keränen + * @authors Copyright © 2006-2012 Daniel Swanson + * + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html + * + * 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 + */ + +#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; +} diff --git a/doomsday/plugins/wadmapconverter/src/wadmapconverter.cpp b/doomsday/plugins/wadmapconverter/src/wadmapconverter.cpp index a60d9a8c84..3b6bd71c4d 100644 --- a/doomsday/plugins/wadmapconverter/src/wadmapconverter.cpp +++ b/doomsday/plugins/wadmapconverter/src/wadmapconverter.cpp @@ -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. */ @@ -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)); } /** @@ -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); diff --git a/doomsday/plugins/wadmapconverter/wadmapconverter.pro b/doomsday/plugins/wadmapconverter/wadmapconverter.pro index baa50cdbc3..6d698680eb 100644 --- a/doomsday/plugins/wadmapconverter/wadmapconverter.pro +++ b/doomsday/plugins/wadmapconverter/wadmapconverter.pro @@ -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