Skip to content

Commit

Permalink
Refactor|IdTech1Converter|MapInfoTranslator: Track custom status of M…
Browse files Browse the repository at this point in the history
…APINFO data, split output

Partition the translated definitions into two data sets, according
to whether the source MAPINFO data is "custom" (from an add-on).
By separating the data we can continue to track the custom status
for individual definitions, should multiple MAPINFO data be merged
from multiple sources.
  • Loading branch information
danij-deng committed Nov 17, 2014
1 parent 4b1685a commit c2c702b
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 219 deletions.
3 changes: 2 additions & 1 deletion doomsday/api/api_plugin.h
Expand Up @@ -96,7 +96,8 @@ typedef struct {
/// Parameters for HOOK_MAPINFO_CONVERT
typedef struct {
Str paths; // ';' delimited
Str result;
Str translated;
Str translatedCustom;
} ddhook_mapinfo_convert_t;

DENG_API_TYPEDEF(Plug) // v1
Expand Down
56 changes: 35 additions & 21 deletions doomsday/client/src/def_main.cpp
Expand Up @@ -626,29 +626,32 @@ static QStringList allMapInfoUrns()
/**
* @param mapInfoUrns MAPINFO definitions to translate, in load order.
*/
static String translateMapInfos(QStringList const &mapInfoUrns)
static void translateMapInfos(QStringList const &mapInfoUrns, String &xlat, String &xlatCustom)
{
String translated;
xlat.clear();
xlatCustom.clear();

String delimitedPaths = mapInfoUrns.join(";");
if(!delimitedPaths.isEmpty())
if(delimitedPaths.isEmpty()) return;

ddhook_mapinfo_convert_t parm;
Str_InitStd(&parm.paths);
Str_InitStd(&parm.translated);
Str_InitStd(&parm.translatedCustom);
try
{
ddhook_mapinfo_convert_t parm;
Str_InitStd(&parm.paths);
Str_InitStd(&parm.result);
try
Str_Set(&parm.paths, delimitedPaths.toUtf8().constData());
if(DD_CallHooks(HOOK_MAPINFO_CONVERT, 0, &parm))
{
Str_Set(&parm.paths, delimitedPaths.toUtf8().constData());
if(DD_CallHooks(HOOK_MAPINFO_CONVERT, 0, &parm))
{
translated = Str_Text(&parm.result);
}
xlat = Str_Text(&parm.translated);
xlatCustom = Str_Text(&parm.translatedCustom);
}
catch(...)
{}
Str_Free(&parm.result);
Str_Free(&parm.paths);
}
return translated;
catch(...)
{}
Str_Free(&parm.translatedCustom);
Str_Free(&parm.translated);
Str_Free(&parm.paths);
}

static void readAllDefinitions()
Expand Down Expand Up @@ -678,11 +681,22 @@ static void readAllDefinitions()
QStringList mapInfoUrns = allMapInfoUrns();
if(!mapInfoUrns.isEmpty())
{
String translatedDefs = translateMapInfos(mapInfoUrns);
if(!translatedDefs.isEmpty())
String xlat, xlatCustom;
translateMapInfos(mapInfoUrns, xlat, xlatCustom);

if(!xlat.isEmpty())
{
qDebug() << "[TranslatedMapInfos] custom:false\n" << xlat;
if(!DED_ReadData(&defs, xlat.toUtf8().constData(), "[TranslatedMapInfos]"))
{
App_Error("readAllDefinitions: DED parse error:\n%s", DED_Error());
}
}

if(!xlatCustom.isEmpty())
{
qDebug() << "[TranslatedMapInfos]\n" << translatedDefs;
if(!DED_ReadData(&defs, translatedDefs.toUtf8().constData(), "[TranslatedMapInfos]"))
qDebug() << "[TranslatedMapInfos] custom:true\n" << xlatCustom;
if(!DED_ReadData(&defs, xlatCustom.toUtf8().constData(), "[TranslatedMapInfos]"))
{
App_Error("readAllDefinitions: DED parse error:\n%s", DED_Error());
}
Expand Down
Expand Up @@ -41,8 +41,11 @@ class MapInfoTranslator
* 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.
*
* @param translated Definitions from non-custom sources are written here.
* @param translatedCustom Definitions from custom sources are written here.
*/
de::String translate();
void translate(de::String &translated, de::String &translatedCustom);

private:
DENG2_PRIVATE(d)
Expand Down
14 changes: 10 additions & 4 deletions doomsday/plugins/idtech1converter/src/idtech1converter.cpp
Expand Up @@ -83,8 +83,11 @@ int ConvertMapHook(int /*hookType*/, int /*parm*/, void *context)
return false; // failure :(
}

static String convertMapInfos(QList<QString> const &pathsInLoadOrder)
static void convertMapInfos(QList<QString> const &pathsInLoadOrder, String &xlat, String &xlatCustom)
{
xlat.clear();
xlatCustom.clear();

MapInfoTranslator translator;

bool haveTranslation = false;
Expand All @@ -99,9 +102,9 @@ static String convertMapInfos(QList<QString> const &pathsInLoadOrder)
haveTranslation = true;
}
}
if(!haveTranslation) return "";
if(!haveTranslation) return;

return translator.translate() + "\n"; // End with a newline, for neatness sake.
translator.translate(xlat, xlatCustom);
}

/**
Expand All @@ -114,7 +117,10 @@ int ConvertMapInfoHook(int /*hookType*/, int /*parm*/, void *context)
DENG2_ASSERT(context);
auto &parm = *static_cast<ddhook_mapinfo_convert_t *>(context);
QStringList allPathsInLoadOrder = String(Str_Text(&parm.paths)).split(";");
Str_Set(&parm.result, convertMapInfos(allPathsInLoadOrder).toUtf8().constData());
String xlat, xlatCustom;
convertMapInfos(allPathsInLoadOrder, xlat, xlatCustom);
Str_Set(&parm.translated, xlat.toUtf8().constData());
Str_Set(&parm.translatedCustom, xlatCustom.toUtf8().constData());
return true;
}

Expand Down

0 comments on commit c2c702b

Please sign in to comment.