Skip to content

Commit

Permalink
IdTech1Converter: Fleshing out MAPINFO => DED translation
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Aug 7, 2014
1 parent 0a855bb commit d8cad81
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 116 deletions.
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -1553,7 +1553,7 @@ static void runGameAction()
}
#endif
#if __JDOOM__ || __JDOOM64__ || __JHERETIC__
nextMapUri = COMMON_GAMESESSION->mapUriForNamedExit(secretExit? "secretNext" : "next");
nextMapUri = COMMON_GAMESESSION->mapUriForNamedExit(secretExit? "secret" : "next");
#endif

G_IntermissionBegin();
Expand Down
1 change: 0 additions & 1 deletion doomsday/plugins/common/src/hu_menu.cpp
Expand Up @@ -3078,7 +3078,6 @@ void Hu_MenuInitEpisodePage()
}

de::Uri startMap(episodeDef.gets("startMap"), RC_NULL);
/// @todo Translate Hexen warp numbers.
if(P_MapExists(startMap.compose().toUtf8().constData()))
{
btn->actions[Widget::MNA_ACTIVEOUT].callback = Hu_MenuSelectEpisode;
Expand Down
71 changes: 41 additions & 30 deletions doomsday/plugins/idtech1converter/include/mapinfotranslator.h
Expand Up @@ -29,8 +29,6 @@

namespace idtech1 {

struct HexDefs; // Forward

class MapInfo : public de::Record
{
public:
Expand All @@ -49,6 +47,36 @@ class EpisodeInfo : public de::Record
void resetToDefaults();
};

/**
* Central database of definitions read from Hexen-derived definition formats.
*
* @note Ultimately the definitions this contains should instead have their sources
* translated into DED syntax and be made available from the main DED db instead.
*/
struct HexDefs
{
typedef std::map<std::string, EpisodeInfo> EpisodeInfos;
EpisodeInfos episodeInfos;
typedef std::map<std::string, MapInfo> MapInfos;
MapInfos mapInfos;

void clear();

/**
* @param id Identifier of the episode to lookup info for.
*
* @return EpisodeInfo for the specified @a id; otherwise @c 0 (not found).
*/
EpisodeInfo *getEpisodeInfo(de::String id);

/**
* @param mapUri Identifier of the map to lookup info for.
*
* @return MapInfo for the specified @a mapUri; otherwise @c 0 (not found).
*/
MapInfo *getMapInfo(de::Uri const &mapUri);
};

/**
* Parser for Hexen's MAPINFO definition lumps.
*/
Expand All @@ -75,42 +103,25 @@ class MapInfoParser
};

/**
* Central database of definitions read from Hexen-derived definition formats.
*
* @note Ultimately the definitions this contains should instead have their sources
* translated into DED syntax and be made available from the main DED db instead.
* Hexen MAPINFO => DED translator.
*/
struct HexDefs
class MapInfoTranslator
{
typedef std::map<std::string, EpisodeInfo> EpisodeInfos;
EpisodeInfos episodeInfos;
typedef std::map<std::string, MapInfo> MapInfos;
MapInfos mapInfos;

void clear();

/**
* @param id Identifier of the episode to lookup info for.
*
* @return EpisodeInfo for the specified @a id; otherwise @c 0 (not found).
*/
EpisodeInfo *getEpisodeInfo(de::String id);
public:
MapInfoTranslator();

/**
* @param mapUri Identifier of the map to lookup info for.
*
* @return MapInfo for the specified @a mapUri; otherwise @c 0 (not found).
*/
MapInfo *getMapInfo(de::Uri const &mapUri);
void reset();
void mergeFromFile(de::String sourceFile);

/**
* To be called once all definitions have been parsed to translate Hexen's
* map "warp numbers" to URIs where used as map definition references.
* Translate the current MAPINFO data set into DED syntax. Note that the internal
* state of the definition database is modified in the process and will therefore
* be reset automatically once translation has completed.
*/
void translateMapWarpNumbers();
de::String translate();

private:
de::Uri translateMapWarpNumber(uint map);
DENG2_PRIVATE(d)
};

} // namespace idtech1
Expand Down
60 changes: 5 additions & 55 deletions doomsday/plugins/idtech1converter/src/idtech1converter.cpp
Expand Up @@ -21,7 +21,6 @@

#include "idtech1converter.h"
#include "mapinfotranslator.h"
#include <de/Error>
#include <de/Log>

using namespace de;
Expand Down Expand Up @@ -72,65 +71,16 @@ int ConvertMapHook(int /*hookType*/, int /*parm*/, void *context)
return false; // failure :(
}

static void readOneMapInfoDefinition(MapInfoParser &parser, AutoStr const &buffer, String sourceFile)
{
LOG_RES_VERBOSE("Parsing \"%s\"...") << NativePath(sourceFile).pretty();
try
{
parser.parse(buffer, sourceFile);
}
catch(MapInfoParser::ParseError const &er)
{
LOG_RES_WARNING("Failed parsing \"%s\" as MAPINFO:\n%s")
<< NativePath(sourceFile).pretty() << er.asText();
}
}

void ConvertMapInfo()
{
HexDefs hexDefs;

// Initialize a new parser.
MapInfoParser parser(hexDefs);
// Initialize a new translator.
MapInfoTranslator xltr;

// Read the primary MAPINFO (from the IWAD).
AutoStr *sourceFile = AutoStr_FromText("Lumps:MAPINFO");
dd_bool sourceIsCustom;
AutoStr *buffer = M_ReadFileIntoString(sourceFile, &sourceIsCustom);
if(buffer && !Str_IsEmpty(buffer))
{
readOneMapInfoDefinition(parser, *buffer, Str_Text(sourceFile));
xltr.mergeFromFile("Lumps:MAPINFO");

#ifdef __JHEXEN__
// MAPINFO in the Hexen IWAD contains a bunch of broken definitions.
// As later map definitions now replace earlier ones, these broken defs
// override the earlier "good" defs. For now we'll kludge around this
// issue by patching the affected defs with the expected values.
if(!sourceIsCustom && (gameModeBits & (GM_HEXEN|GM_HEXEN_V10)))
{
MapInfo *info = hexDefs.getMapInfo(de::Uri("Maps:MAP07", RC_NULL));
info->set("warpTrans", "@wt:7");
}
#endif
}
else
{
LOG_RES_WARNING("MapInfoParser: Failed to open definition/script file \"%s\" for reading")
<< NativePath(Str_Text(sourceFile)).pretty();
}

// Translate internal "warp trans" numbers to URIs.
hexDefs.translateMapWarpNumbers();

#ifdef DENG_IDTECH1CONVERTER_DEBUG
for(HexDefs::MapInfos::const_iterator i = hexDefs.mapInfos.begin(); i != hexDefs.mapInfos.end(); ++i)
{
MapInfo const &info = i->second;
LOG_RES_MSG("MAPINFO %s { title: \"%s\" hub: %i map: %s warp: %i nextMap: %s }")
<< i->first.c_str() << info.gets("title")
<< info.geti("hub") << info.gets("map") << info.geti("warpTrans") << info.gets("nextMap");
}
#endif
String text = xltr.translate() + "\n"; // End with a newline, for neatness sake.
qDebug() << text;
}

/**
Expand Down

0 comments on commit d8cad81

Please sign in to comment.