Skip to content

Commit

Permalink
Refactor: Consolidated and cleaned up methods of querying map author/…
Browse files Browse the repository at this point in the history
…title info

Map author and title info is now primarily available through read-only
console variables 'map-author' and 'map-name'. The old app variables
DD_MAP_NAME and DD_MAP_TITLE have been removed (obsolete).

Note that it is currently the games' responsibility to update these
accordingly, when the current map changes (because the engine has no
knowledge of Hexen's MAPINFO lump).

Further improved 'inspectmap' output to include the author and source
file path (if loaded from an add-on).
  • Loading branch information
danij-deng committed Jan 20, 2014
1 parent b423204 commit f99399f
Show file tree
Hide file tree
Showing 19 changed files with 330 additions and 418 deletions.
4 changes: 2 additions & 2 deletions doomsday/api/dd_share.h
Expand Up @@ -225,8 +225,8 @@ enum {
DD_UNUSED4, // DD_TRACE_ADDRESS
DD_SPRITE_REPLACEMENT, ///< Sprite <-> model replacement.
DD_ACTION_LINK, ///< State action routine addresses.
DD_MAP_NAME,
DD_MAP_AUTHOR,
DD_UNUSED10, // DD_MAP_NAME
DD_UNUSED11, // DD_MAP_AUTHOR
DD_MAP_MUSIC,
DD_MAP_MIN_X,
DD_MAP_MIN_Y,
Expand Down
29 changes: 0 additions & 29 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -2439,35 +2439,6 @@ void *DD_GetVariable(int ddvalue)
value = App_WorldSystem().hasMap()? App_WorldSystem().map().polyobjCount() : 0;
return &value;

case DD_MAP_NAME:
if(App_WorldSystem().hasMap())
{
de::Uri mapUri = App_WorldSystem().map().uri();
ded_mapinfo_t *mapInfo = Def_GetMapInfo(reinterpret_cast<uri_s *>(&mapUri));
if(mapInfo && mapInfo->name[0])
{
int id = Def_Get(DD_DEF_TEXT, mapInfo->name, NULL);
if(id != -1)
{
return defs.text[id].text;
}
return mapInfo->name;
}
}
return NULL;

case DD_MAP_AUTHOR:
if(App_WorldSystem().hasMap())
{
de::Uri mapUri = App_WorldSystem().map().uri();
ded_mapinfo_t *mapInfo = Def_GetMapInfo(reinterpret_cast<uri_s *>(&mapUri));
if(mapInfo && mapInfo->author[0])
{
return mapInfo->author;
}
}
return NULL;

case DD_MAP_MIN_X:
valueD = App_WorldSystem().hasMap()? App_WorldSystem().map().bounds().minX : 0;
return &valueD;
Expand Down
24 changes: 17 additions & 7 deletions doomsday/client/src/world/map.cpp
Expand Up @@ -3259,20 +3259,30 @@ D_CMD(InspectMap)
}

Map &map = App_WorldSystem().map();
LOG_SCR_NOTE(_E(b) "%s" _E(.)) << Con_GetString("map-name");

LOG_SCR_NOTE(_E(b) "%s - %s")
<< Con_GetString("map-name")
<< Con_GetString("map-author");
LOG_SCR_MSG("\n");

LOG_SCR_MSG( _E(l) "Uri: " _E(.) _E(i) "%s"/*_E(.)
" " _E(l) "OldUid: " _E(.) _E(i) "%s" _E(.)*/)
<< map.uri().asText()/*
<< map.oldUniqueId()*/;
LOG_SCR_MSG( _E(l) "Uri: " _E(.) _E(i) "%s" _E(.)
/*" " _E(l) "OldUid: " _E(.) _E(i) "%s" _E(.)*/
_E(l) "Music: " _E(.) _E(i) "%i")
<< map.uri().asText()
/*<< map.oldUniqueId()*/
<< Con_GetInteger("map-music");

if(P_MapIsCustom(map.uri().asText().toUtf8().constData()))
{
NativePath sourceFile(Str_Text(P_MapSourceFile(map.uri().asText().toUtf8().constData())));
LOG_SCR_MSG(_E(l) "Source: " _E(.) _E(i) "\"%s\"") << sourceFile.pretty();
}

LOG_SCR_MSG(_E(l) "Music: " _E(.) _E(i) "%i") << Con_GetInteger("map-music");
LOG_SCR_MSG("\n");

if(map.isEditable())
{
LOG_MSG(_E(D) "Editing Enabled");
LOG_MSG(_E(D) "Editing " _E(b) "Enabled");
}

LOG_SCR_MSG(_E(D) "Elements:");
Expand Down
9 changes: 5 additions & 4 deletions doomsday/plugins/common/include/p_mapsetup.h
Expand Up @@ -46,11 +46,12 @@ void P_FinalizeMapChange(Uri const *uri);
*/
void P_SetupMap(Uri *uri);

char const *P_GetMapNiceName(void);
char const *P_MapAuthor(uint episode, uint map, dd_bool supressGameAuthor);
char const *P_MapTitle(uint episode, uint map);
patchid_t P_MapTitlePatch(uint episode, uint map);

patchid_t P_FindMapTitlePatch(uint episode, uint map);

char const *P_GetMapAuthor(dd_bool supressGameAuthor);
char const *P_CurrentMapAuthor(dd_bool supressGameAuthor);
char const *P_CurrentMapTitle(void);

#if __JDOOM__ || __JDOOM64__ || __JHERETIC__
void P_FindSecrets(void);
Expand Down
410 changes: 171 additions & 239 deletions doomsday/plugins/common/src/g_game.c

Large diffs are not rendered by default.

40 changes: 13 additions & 27 deletions doomsday/plugins/common/src/hu_stuff.cpp
Expand Up @@ -751,15 +751,11 @@ static void drawMapMetaData(float x, float y, float alpha)
{
#define BORDER 2

static const char* unnamed = "Unnamed";
char const *title = P_CurrentMapTitle();
if(!title) title = "Unnamed";

const char* lname = P_GetMapNiceName();
char buf[256];

if(!lname)
lname = unnamed;

dd_snprintf(buf, 256, "map: %s gamemode: %s", lname, P_GetGameModeName());
dd_snprintf(buf, 256, "map: %s gamemode: %s", title, P_GetGameModeName());

FR_SetColorAndAlpha(1, 1, 1, alpha);
FR_DrawTextXY2(buf, x + BORDER, y - BORDER, ALIGN_BOTTOMLEFT);
Expand Down Expand Up @@ -1469,7 +1465,7 @@ dd_bool Hu_IsStatusBarVisible(int player)
#if __JDOOM__ || __JDOOM64__
patchid_t Hu_MapTitlePatchId(void)
{
return P_FindMapTitlePatch(gameEpisode, gameMap);
return P_MapTitlePatch(gameEpisode, gameMap);
}

int Hu_MapTitleFirstLineHeight(void)
Expand All @@ -1486,7 +1482,7 @@ int Hu_MapTitleFirstLineHeight(void)

dd_bool Hu_IsMapTitleAuthorVisible(void)
{
char const *author = P_GetMapAuthor(cfg.hideIWADAuthor);
char const *author = P_CurrentMapAuthor(cfg.hideIWADAuthor);
return author != 0 && (actualMapTime <= 6 * TICSPERSEC);
}

Expand All @@ -1505,20 +1501,10 @@ int Hu_MapTitleHeight(void)

void Hu_DrawMapTitle(float alpha, dd_bool mapIdInsteadOfAuthor)
{
char const *lname = 0, *lauthor = 0;
float y = 0;
char const *title = P_CurrentMapTitle();
char const *author = P_CurrentMapAuthor(cfg.hideIWADAuthor);

// Get the strings from Doomsday.
lname = P_GetMapNiceName();
lauthor = P_GetMapAuthor(cfg.hideIWADAuthor);

#if __JHEXEN__
if(!lname)
{
// Use stardard map name if DED didn't define it.
lname = P_GetMapName(gameMap);
}
#endif
float y = 0;

DGL_Enable(DGL_TEXTURE_2D);
DGL_Color4f(1, 1, 1, alpha);
Expand All @@ -1529,15 +1515,15 @@ void Hu_DrawMapTitle(float alpha, dd_bool mapIdInsteadOfAuthor)

#if __JDOOM__ || __JDOOM64__
patchid_t patchId = Hu_MapTitlePatchId();
WI_DrawPatchXY3(patchId, Hu_ChoosePatchReplacement2(PRM_ALLOW_TEXT, patchId, lname), 0, 0, ALIGN_TOP, 0, DTF_ONLY_SHADOW);
WI_DrawPatchXY3(patchId, Hu_ChoosePatchReplacement2(PRM_ALLOW_TEXT, patchId, title), 0, 0, ALIGN_TOP, 0, DTF_ONLY_SHADOW);

// Following line of text placed according to patch height.
y += Hu_MapTitleFirstLineHeight();

#elif __JHERETIC__ || __JHEXEN__
if(lname)
if(title)
{
FR_DrawTextXY3(lname, 0, 0, ALIGN_TOP, DTF_ONLY_SHADOW);
FR_DrawTextXY3(title, 0, 0, ALIGN_TOP, DTF_ONLY_SHADOW);
y += 20;
}
#endif
Expand All @@ -1554,11 +1540,11 @@ void Hu_DrawMapTitle(float alpha, dd_bool mapIdInsteadOfAuthor)
FR_DrawTextXY3(Str_Text(Uri_ToString(mapUri)), 0, y, ALIGN_TOP, DTF_ONLY_SHADOW);
Uri_Delete(mapUri);
}
else if(lauthor)
else if(author)
{
FR_SetFont(FID(GF_FONTA));
FR_SetColorAndAlpha(.5f, .5f, .5f, alpha);
FR_DrawTextXY3(lauthor, 0, y, ALIGN_TOP, DTF_ONLY_SHADOW);
FR_DrawTextXY3(author, 0, y, ALIGN_TOP, DTF_ONLY_SHADOW);
}

DGL_Disable(DGL_TEXTURE_2D);
Expand Down
120 changes: 84 additions & 36 deletions doomsday/plugins/common/src/p_mapsetup.cpp
Expand Up @@ -1031,30 +1031,101 @@ static void P_ResetWorldState()
#endif
}

char const *P_GetMapNiceName()
char const *P_MapTitle(uint episode, uint map)
{
char const *lname = (char *) DD_GetVariable(DD_MAP_NAME);
char const *title = "";

Uri *mapUri = G_ComposeMapUri(episode, map);

// Perhaps a MapInfo definition exists for the map?
ddmapinfo_t mapInfo;
if(Def_Get(DD_DEF_MAP_INFO, Str_Text(Uri_Compose(mapUri)), &mapInfo))
{
if(mapInfo.name[0])
{
// Perhaps the title string is a reference to a Text definition?
void *ptr;
if(Def_Get(DD_DEF_TEXT, mapInfo.name, &ptr) != -1)
{
title = (char const *) ptr; // Yes, use the resolved text string.
}
else
{
title = mapInfo.name;
}
}
}
Uri_Delete(mapUri);

#if __JHEXEN__
// In Hexen we can also look in MAPINFO for the map name.
if(!lname)
lname = P_GetMapName(gameMap);
// In Hexen we can also look in MAPINFO for the map title.
if(!title)
{
title = P_MapInfoMapTitle(map);
}
#endif

if(!lname || !lname[0])
return NULL;
if(!title || !title[0])
return 0;

// Skip the "ExMx" part, if present.
if(char const *ptr = strchr(lname, ':'))
if(char const *ptr = strchr(title, ':'))
{
lname = ptr + 1;
while(*lname && isspace(*lname))
lname++;
title = ptr + 1;
while(*title && isspace(*title))
{
title++;
}
}

return lname;
return title;
}

patchid_t P_FindMapTitlePatch(uint episode, uint map)
char const *P_MapAuthor(uint episode, uint map, dd_bool supressGameAuthor)
{
char const *author = "";

Uri *mapUri = G_ComposeMapUri(episode, map);
AutoStr *path = Uri_Resolved(mapUri);

// Perhaps a MapInfo definition exists for the map?
ddmapinfo_t mapInfo;
if(Def_Get(DD_DEF_MAP_INFO, Str_Text(Uri_Compose(mapUri)), &mapInfo))
{
if(mapInfo.author[0])
{
author = mapInfo.author;
}
}
Uri_Delete(mapUri);

if(!author || !author[0])
return 0;

// Should we suppress the author?
/// @todo Do not do this here.
GameInfo gameInfo;
DD_GameInfo(&gameInfo);
if(supressGameAuthor || P_MapIsCustom(Str_Text(path)))
{
if(!Str_CompareIgnoreCase(gameInfo.author, author))
return 0;
}

return author;
}

char const *P_CurrentMapTitle()
{
return P_MapTitle(gameEpisode, gameMap);
}

char const *P_CurrentMapAuthor(dd_bool supressGameAuthor)
{
return P_MapAuthor(gameEpisode, gameMap, supressGameAuthor);
}

patchid_t P_MapTitlePatch(uint episode, uint map)
{
#if __JDOOM__ || __JDOOM64__
# if __JDOOM__
Expand All @@ -1071,29 +1142,6 @@ patchid_t P_FindMapTitlePatch(uint episode, uint map)
return 0;
}

char const *P_GetMapAuthor(dd_bool supressGameAuthor)
{
char const *author = (char const *) DD_GetVariable(DD_MAP_AUTHOR);
if(!author || !author[0])
return 0;

// Should we suppress the author?
/// @todo Do not do this here.
Uri *uri = G_ComposeMapUri(gameEpisode, gameMap);
AutoStr *path = Uri_Resolved(uri);

dd_bool mapIsCustom = P_MapIsCustom(Str_Text(path));

Uri_Delete(uri);

GameInfo gameInfo;
DD_GameInfo(&gameInfo);
if((mapIsCustom || supressGameAuthor) && !Str_CompareIgnoreCase(gameInfo.author, author))
return 0;

return author;
}

#if __JDOOM__ || __JDOOM64__ || __JHERETIC__
void P_FindSecrets()
{
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/doom/src/st_stuff.c
Expand Up @@ -2469,7 +2469,7 @@ void MapName_Drawer(uiwidget_t* obj, const Point2Raw* offset)
const float scale = .75f;
const float textAlpha = uiRendState->pageAlpha;
const patchid_t patch = P_FindMapTitlePatch(gameEpisode, gameMap);
const char* text = Hu_ChoosePatchReplacement2(PRM_ALLOW_TEXT, patch, P_GetMapNiceName());
const char* text = Hu_ChoosePatchReplacement2(PRM_ALLOW_TEXT, patch, P_CurrentMapTitle());
assert(obj->type == GUI_MAPNAME);

if(!text && 0 == patch) return;
Expand All @@ -2494,7 +2494,7 @@ void MapName_Drawer(uiwidget_t* obj, const Point2Raw* offset)
void MapName_UpdateGeometry(uiwidget_t* obj)
{
const patchid_t patch = P_FindMapTitlePatch(gameEpisode, gameMap);
const char* text = Hu_ChoosePatchReplacement2(PRM_ALLOW_TEXT, patch, P_GetMapNiceName());
const char* text = Hu_ChoosePatchReplacement2(PRM_ALLOW_TEXT, patch, P_CurrentMapTitle());
const float scale = .75f;
patchinfo_t info;
assert(obj && obj->type == GUI_MAPNAME);
Expand Down

0 comments on commit f99399f

Please sign in to comment.