Skip to content

Commit

Permalink
Refactor|libcommon|libhexen: Access MapInfo defs from the DED database
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jul 28, 2014
1 parent 4c9426b commit bf9ddd9
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 47 deletions.
14 changes: 0 additions & 14 deletions doomsday/plugins/common/include/g_defs.h
Expand Up @@ -30,20 +30,6 @@
*/
ded_t &Defs();

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

/**
* Translates a warp map number to unique map identifier. Always returns a valid
* map identifier.
Expand Down
7 changes: 4 additions & 3 deletions doomsday/plugins/common/src/fi_lib.cpp
Expand Up @@ -33,6 +33,7 @@

#include <cstring>

using namespace de;
using namespace common;

struct fi_state_conditions_t
Expand Down Expand Up @@ -92,7 +93,7 @@ static void initStateConditions(fi_state_t *s)
s->conditions.leave_hub = true;
if(!nextMapUri.path().isEmpty())
{
if(curMapInfo->geti("hub") == P_MapInfo(nextMapUri)->geti("hub"))
if(curMapInfo->geti("hub") == Defs().mapInfos.find("id", nextMapUri.compose()).geti("hub"))
{
s->conditions.leave_hub = false;
}
Expand Down Expand Up @@ -177,7 +178,7 @@ static void NetSv_SendFinaleState(fi_state_t *s)
{
DENG2_ASSERT(s != 0);

Writer *writer = D_NetWrite();
writer_s *writer = D_NetWrite();

// First the flags.
Writer_WriteByte(writer, s->mode);
Expand All @@ -192,7 +193,7 @@ static void NetSv_SendFinaleState(fi_state_t *s)
Net_SendPacket(DDSP_ALL_PLAYERS, GPT_FINALE_STATE, Writer_Data(writer), Writer_Size(writer));
}

void NetCl_UpdateFinaleState(Reader *msg)
void NetCl_UpdateFinaleState(reader_s *msg)
{
DENG2_ASSERT(msg != 0);

Expand Down
10 changes: 0 additions & 10 deletions doomsday/plugins/common/src/g_defs.cpp
Expand Up @@ -55,16 +55,6 @@ void GetDefState(char const *def, int *val)
if(*val < 0) *val = 0;
}

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

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

/// @todo fixme: What about the episode?
de::Uri P_TranslateMap(uint map)
{
Expand Down
18 changes: 9 additions & 9 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -1802,7 +1802,7 @@ void G_PlayerLeaveMap(int player)
dd_bool newHub = true;
if(!nextMapUri.path().isEmpty())
{
newHub = (COMMON_GAMESESSION->mapInfo()->geti("hub") != P_MapInfo(nextMapUri)->geti("hub"));
newHub = (COMMON_GAMESESSION->mapInfo()->geti("hub") != Defs().mapInfos.find("id", ::nextMapUri.compose()).geti("hub"));
}
#endif

Expand Down Expand Up @@ -2570,17 +2570,17 @@ String G_MapTitle(de::Uri const *mapUri)
ddmapinfo_t mapInfo;
if(Def_Get(DD_DEF_MAP_INFO, mapUri->compose().toUtf8().constData(), &mapInfo))
{
if(mapInfo.name[0])
if(Str_Text(mapInfo.name))
{
// Perhaps the title string is a reference to a Text definition?
void *ptr;
if(Def_Get(DD_DEF_TEXT, mapInfo.name, &ptr) != -1)
if(Def_Get(DD_DEF_TEXT, Str_Text(mapInfo.name), &ptr) != -1)
{
title = (char const *) ptr; // Yes, use the resolved text string.
}
else
{
title = mapInfo.name;
title = Str_Text(mapInfo.name);
}
}
}
Expand All @@ -2589,7 +2589,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 = P_MapInfo(*mapUri))
if(Record const *mapInfo = Defs().mapInfos.tryFind("id", mapUri->compose()))
{
title = mapInfo->gets("title");
}
Expand Down Expand Up @@ -2621,7 +2621,7 @@ String G_MapAuthor(de::Uri const *mapUri, bool supressGameAuthor)
String author;
if(Def_Get(DD_DEF_MAP_INFO, mapUriAsText.toUtf8().constData(), &mapInfo))
{
author = mapInfo.author;
author = Str_Text(mapInfo.author);
}

if(!author.isEmpty())
Expand Down Expand Up @@ -2695,15 +2695,15 @@ char const *G_InFineBriefing(de::Uri const *mapUri)

char const *G_InFineDebriefing(de::Uri const *mapUri)
{
if(!mapUri) mapUri = &gameMapUri;
if(!mapUri) mapUri = &::gameMapUri;

// If we're already in the INFINE state, don't start a finale.
if(briefDisabled) return 0;

#if __JHEXEN__
if(cfg.overrideHubMsg && G_GameState() == GS_MAP && !nextMapUri.path().isEmpty())
if(cfg.overrideHubMsg && G_GameState() == GS_MAP && !::nextMapUri.path().isEmpty())
{
if(P_MapInfo(*mapUri)->geti("hub") != P_MapInfo(nextMapUri)->geti("hub"))
if(Defs().mapInfos.find("id", mapUri->compose()).geti("hub") != Defs().mapInfos.find("id", ::nextMapUri.compose()).geti("hub"))
{
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/gamesession.cpp
Expand Up @@ -782,7 +782,7 @@ bool GameSession::savingPossible()
return true;
}

Record *GameSession::episode()
Record *GameSession::episodeDef()
{
if(hasBegun())
{
Expand Down Expand Up @@ -992,7 +992,7 @@ void GameSession::leaveMap()

// Are we entering a new hub?
#if __JHEXEN__
if(mapInfo()->geti("hub") != P_MapInfo(nextMapUri)->geti("hub"))
if(mapInfo()->geti("hub") != Defs().mapInfos.find("id", ::nextMapUri.compose()).geti("hub"))
#endif
{
// Clear all saved map states in the old hub.
Expand Down
5 changes: 2 additions & 3 deletions doomsday/plugins/common/src/hu_menu.cpp
Expand Up @@ -4650,9 +4650,8 @@ void Hu_MenuInitNewGame(dd_bool confirmed)
GameRuleset newRules(defaultGameRules);
newRules.skill = mnSkillmode;

EpisodeInfo *info = P_EpisodeInfo(mnEpisode);
DENG2_ASSERT(info != 0);
G_SetGameActionNewSession(de::Uri(info->gets("startMap"), RC_NULL), 0/*default*/, newRules);
Record const episodeDef = Defs().episodes.find("id", mnEpisode);
G_SetGameActionNewSession(de::Uri(episodeDef.gets("startMap"), RC_NULL), 0/*default*/, newRules);
}

void Hu_MenuActionInitNewGame(Widget * /*wi*/, Widget::mn_actionid_t action)
Expand Down
10 changes: 5 additions & 5 deletions doomsday/plugins/common/src/p_sound.cpp
Expand Up @@ -36,12 +36,12 @@ using namespace common;

void S_MapMusic(de::Uri const *mapUri)
{
if(!mapUri) mapUri = &gameMapUri;
if(!mapUri) mapUri = &::gameMapUri;

#ifdef __JHEXEN__
MapInfo const *mapInfo = P_MapInfo(*mapUri);
int const cdTrack = mapInfo->geti("cdTrack");
String const lump = mapInfo->gets("songLump").compareWithoutCase("DEFSONG")? mapInfo->gets("songLump") : "";
Record const &mapInfo = Defs().mapInfos.find("id", mapUri->compose());
int const cdTrack = mapInfo.geti("cdTrack");
String const lump = mapInfo.gets("songLump").compareWithoutCase("DEFSONG")? mapInfo.gets("songLump") : "";

LOG_RES_VERBOSE("S_MapMusic: %s lump: %s") << mapUri->compose() << lump;

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

if(mapNumber > 0)
{
if(MapInfo *mapInfo = P_MapInfo(G_ComposeMapUri(0, mapNumber - 1)))
if(Record *mapInfo = Defs().mapInfos.tryFind("id", G_ComposeMapUri(0, mapNumber - 1).compose()))
{
mapInfo->set("songLump", Str_Text(lumpName));
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/hexen/src/p_spec.cpp
Expand Up @@ -80,7 +80,7 @@ void P_InitLava(void)

void P_InitSky(de::Uri const &mapUri)
{
if(Record const *mapInfo = P_MapInfo(mapUri))
if(Record const *mapInfo = Defs().mapInfos.tryFind("id", mapUri.compose()))
{
sky1Material = Materials_ResolveUriCString(mapInfo->gets("sky1Material").toUtf8().constData());
sky2Material = Materials_ResolveUriCString(mapInfo->gets("sky2Material").toUtf8().constData());
Expand Down

0 comments on commit bf9ddd9

Please sign in to comment.