Skip to content

Commit

Permalink
IdTech1Converter: Connect MAPINFO translation to HOOK_GAME_INIT
Browse files Browse the repository at this point in the history
Parse and merge the content of all loaded MAPINFO lumps, in load order.

Todo: Output the translated DED definitions to a temporary file which
will be parsed automatically later, during game initialization.
  • Loading branch information
danij-deng committed Sep 9, 2014
1 parent 2c79f4c commit bfb3748
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions doomsday/plugins/idtech1converter/src/idtech1converter.cpp
Expand Up @@ -21,6 +21,8 @@

#include "idtech1converter.h"
#include "mapinfotranslator.h"
#include <doomsday/filesys/lumpindex.h>
#include <de/App>
#include <de/Log>

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

void ConvertMapInfo()
/**
* This function will be called when Doomsday begins to initialize a loaded game.
*
* Our job is to determine whether the game resources include any Hexen, MAPINFO-syntax
* definitions that need to be converted into DED format, for parsing later.
*
* @return @c true if successful (always).
*/
int ConvertMapInfo(int /*hookType*/, int /*parm*/, void * /*context*/)
{
// Initialize a new translator.
MapInfoTranslator xltr;

// Read the primary MAPINFO (from the IWAD).
xltr.mergeFromFile("Lumps:MAPINFO");
// Process all MAPINFO lumps, in load order.
bool needTranslate = false;
LumpIndex const &lumpIndex = *reinterpret_cast<LumpIndex const *>(F_LumpIndex());
for(int i = 0; i < lumpIndex.size(); ++i)
{
String const &fileName = lumpIndex[i].name();
if(fileName.fileNameWithoutExtension().toLower() == "mapinfo")
{
xltr.mergeFromFile("LumpIndex:" + String::number(i));
needTranslate = true;
}
}

if(needTranslate)
{
/// @todo: Output the translated MAPINFOs to the auto-load directory for definitions.
String text = xltr.translate() + "\n"; // End with a newline, for neatness sake.
qDebug() << text;
}

String text = xltr.translate() + "\n"; // End with a newline, for neatness sake.
qDebug() << text;
return true; // success
}

/**
Expand All @@ -89,6 +115,7 @@ void ConvertMapInfo()
*/
extern "C" void DP_Initialize()
{
Plug_AddHook(HOOK_GAME_INIT, ConvertMapInfo);
Plug_AddHook(HOOK_MAP_CONVERT, ConvertMapHook);
}

Expand Down

0 comments on commit bfb3748

Please sign in to comment.