Skip to content

Commit

Permalink
libcommon: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jul 24, 2014
1 parent 59052b7 commit d524a47
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 30 deletions.
21 changes: 18 additions & 3 deletions doomsday/plugins/common/include/mapinfo.h
Expand Up @@ -95,15 +95,30 @@ struct HexDefs
EpisodeInfo *getEpisodeInfo(de::String id);

/**
* @param mapUri Identifier of the map to lookup info for. Can be @c 0 in which
* case the info for the @em current map will be returned (if set).
* @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 = 0);
MapInfo *getMapInfo(de::Uri const &mapUri);
};
extern HexDefs hexDefs;

/**
* @param id Identifier of the episode to lookup info for.
*
* @return EpisodeInfo for the specified @a id; otherwise @c 0 (not found).
*/
EpisodeInfo *P_EpisodeInfo(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 *P_MapInfo(de::Uri const &mapUri);

MapInfo *P_CurrentMapInfo();

/**
* Translates a warp map number to unique map identifier, if possible.
*
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/fi_lib.cpp
Expand Up @@ -88,12 +88,12 @@ static void initStateConditions(fi_state_t *s)

#if __JHEXEN__
// Leaving the current hub?
if(MapInfo *curMapInfo = hexDefs.getMapInfo(0/*current map*/))
if(MapInfo *curMapInfo = P_CurrentMapInfo())
{
s->conditions.leave_hub = true;
if(!nextMapUri.path().isEmpty())
{
if(curMapInfo->geti("hub") == hexDefs.getMapInfo(&nextMapUri)->geti("hub"))
if(curMapInfo->geti("hub") == P_MapInfo(nextMapUri)->geti("hub"))
{
s->conditions.leave_hub = false;
}
Expand Down
10 changes: 5 additions & 5 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -1193,7 +1193,7 @@ static void printMapBanner()
{
String text = String("Map: ") + gameMapUri.path().asText();
#if __JHEXEN__
MapInfo const *mapInfo = hexDefs.getMapInfo(0/*current map*/);
MapInfo const *mapInfo = P_CurrentMapInfo();
text += String(" (%1)").arg(mapInfo? mapInfo->geti("warpTrans") + 1 : 0);
#endif
text += String(" - " DE2_ESC(b)) + title;
Expand Down Expand Up @@ -1796,7 +1796,7 @@ void G_PlayerLeaveMap(int player)
dd_bool newHub = true;
if(!nextMapUri.path().isEmpty())
{
newHub = (hexDefs.getMapInfo(0/*current map*/)->geti("hub") != hexDefs.getMapInfo(&nextMapUri)->geti("hub"));
newHub = (P_CurrentMapInfo()->geti("hub") != P_MapInfo(nextMapUri)->geti("hub"));
}
#endif

Expand Down Expand Up @@ -2417,7 +2417,7 @@ de::Uri G_ComposeMapUri(uint episode, uint map)
de::Uri G_NextMap(dd_bool secretExit)
{
#if __JHEXEN__
return P_TranslateMap(hexDefs.getMapInfo(&gameMapUri)->geti("nextMap"));
return P_TranslateMap(P_MapInfo(gameMapUri)->geti("nextMap"));
DENG2_UNUSED(secretExit);

#elif __JDOOM64__
Expand Down Expand Up @@ -2582,7 +2582,7 @@ String G_MapTitle(de::Uri const *mapUri)
// In Hexen we can also look in MAPINFO for the map title.
if(title.isEmpty())
{
if(MapInfo const *mapInfo = hexDefs.getMapInfo(mapUri))
if(MapInfo const *mapInfo = P_MapInfo(*mapUri))
{
title = mapInfo->gets("title");
}
Expand Down Expand Up @@ -2696,7 +2696,7 @@ char const *G_InFineDebriefing(de::Uri const *mapUri)
#if __JHEXEN__
if(cfg.overrideHubMsg && G_GameState() == GS_MAP && !nextMapUri.path().isEmpty())
{
if(hexDefs.getMapInfo(mapUri)->geti("hub") != hexDefs.getMapInfo(&nextMapUri)->geti("hub"))
if(P_MapInfo(*mapUri)->geti("hub") != P_MapInfo(nextMapUri)->geti("hub"))
{
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/gamesession.cpp
Expand Up @@ -970,7 +970,7 @@ void GameSession::leaveMap()

// Are we entering a new hub?
#if __JHEXEN__
if(hexDefs.getMapInfo(0/*current map*/)->geti("hub") != hexDefs.getMapInfo(&nextMapUri)->geti("hub"))
if(P_CurrentMapInfo()->geti("hub") != P_MapInfo(nextMapUri)->geti("hub"))
#endif
{
// Clear all saved map states in the old hub.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/hu_menu.cpp
Expand Up @@ -4651,7 +4651,7 @@ void Hu_MenuInitNewGame(dd_bool confirmed)
GameRuleset newRules(defaultGameRules);
newRules.skill = mnSkillmode;

EpisodeInfo *info = hexDefs.getEpisodeInfo(mnEpisode);
EpisodeInfo *info = P_EpisodeInfo(mnEpisode);
DENG2_ASSERT(info != 0);
G_SetGameActionNewSession(de::Uri(info->gets("startMap"), RC_NULL), 0/*default*/, newRules);
}
Expand Down
33 changes: 23 additions & 10 deletions doomsday/plugins/common/src/mapinfo.cpp
Expand Up @@ -403,7 +403,7 @@ DENG2_PIMPL(MapInfoParser)
}

// Lookup an existing map info from the database.
info = db.getMapInfo(&mapUri);
info = db.getMapInfo(mapUri);

if(!info)
{
Expand Down Expand Up @@ -1087,21 +1087,34 @@ EpisodeInfo *HexDefs::getEpisodeInfo(String id)
return 0; // Not found.
}

MapInfo *HexDefs::getMapInfo(de::Uri const *mapUri)
MapInfo *HexDefs::getMapInfo(de::Uri const &mapUri)
{
if(!mapUri) mapUri = &gameMapUri;

if(mapUri->scheme().compareWithoutCase("Maps")) return 0;

MapInfos::iterator found = mapInfos.find(mapUri->path().toString().toLower().toStdString());
if(found != mapInfos.end())
if(!mapUri.scheme().compareWithoutCase("Maps"))
{
return &found->second;
MapInfos::iterator found = mapInfos.find(mapUri.path().toString().toLower().toStdString());
if(found != mapInfos.end())
{
return &found->second;
}
}
//LOGDEV_MAP_NOTE("Unknown MAPINFO definition '%s'") << Str_Text(mapUriStr);
return 0; // Not found.
}

EpisodeInfo *P_EpisodeInfo(String id)
{
return hexDefs.getEpisodeInfo(id);
}

MapInfo *P_MapInfo(de::Uri const &mapUri)
{
return hexDefs.getMapInfo(mapUri);
}

MapInfo *P_CurrentMapInfo()
{
return hexDefs.getMapInfo(gameMapUri);
}

de::Uri P_TranslateMapIfExists(uint map)
{
de::Uri matchedWithoutHub("Maps:", RC_NULL);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/p_mapsetup.cpp
Expand Up @@ -661,7 +661,7 @@ static void initFog(ddmapinfo_t *ddMapInfo)
}

#if __JHEXEN__
if(MapInfo const *mapInfo = hexDefs.getMapInfo(0/*current map*/))
if(MapInfo const *mapInfo = P_CurrentMapInfo())
{
int fadeTable = CentralLumpIndex().findLast(mapInfo->gets("fadeTable") + ".lmp");
if(fadeTable == CentralLumpIndex().findLast("COLORMAP.lmp"))
Expand Down
5 changes: 2 additions & 3 deletions doomsday/plugins/common/src/p_sound.cpp
Expand Up @@ -40,7 +40,7 @@ void S_MapMusic(de::Uri const *mapUri)
if(!mapUri) mapUri = &gameMapUri;

#ifdef __JHEXEN__
MapInfo const *mapInfo = hexDefs.getMapInfo(mapUri);
MapInfo const *mapInfo = P_MapInfo(*mapUri);
int const cdTrack = mapInfo->geti("cdTrack");
String const lump = mapInfo->gets("songLump").compareWithoutCase("DEFSONG")? mapInfo->gets("songLump") : "";

Expand Down Expand Up @@ -131,8 +131,7 @@ void SndInfoParser(ddstring_s const *path)

if(mapNumber > 0)
{
de::Uri mapUri = G_ComposeMapUri(0, mapNumber - 1);
if(MapInfo *mapInfo = hexDefs.getMapInfo(&mapUri))
if(MapInfo *mapInfo = P_MapInfo(G_ComposeMapUri(0, mapNumber - 1)))
{
mapInfo->set("songLump", Str_Text(lumpName));
}
Expand Down
8 changes: 4 additions & 4 deletions doomsday/plugins/hexen/src/p_spec.cpp
Expand Up @@ -79,7 +79,7 @@ void P_InitLava(void)

void P_InitSky(de::Uri const &mapUri)
{
if(MapInfo const *mapInfo = hexDefs.getMapInfo(&mapUri))
if(MapInfo const *mapInfo = P_MapInfo(mapUri))
{
sky1Material = Materials_ResolveUriCString(mapInfo->gets("sky1Material").toUtf8().constData());
sky2Material = Materials_ResolveUriCString(mapInfo->gets("sky2Material").toUtf8().constData());
Expand Down Expand Up @@ -1036,15 +1036,15 @@ static void P_LightningFlash(void)
}
}

void P_ForceLightning(void)
void P_ForceLightning()
{
nextLightningFlash = 0;
}

void P_InitLightning(void)
void P_InitLightning()
{
int i, secCount;
MapInfo const *mapInfo = hexDefs.getMapInfo(0/*current map*/);
MapInfo const *mapInfo = P_CurrentMapInfo();

if(!mapInfo || !mapInfo->getb("lightning"))
{
Expand Down

0 comments on commit d524a47

Please sign in to comment.