diff --git a/doomsday/plugins/common/include/mapinfo.h b/doomsday/plugins/common/include/mapinfo.h index b0b449f68e..5891a3cc8b 100644 --- a/doomsday/plugins/common/include/mapinfo.h +++ b/doomsday/plugins/common/include/mapinfo.h @@ -25,24 +25,8 @@ #include "common.h" -class MapInfo +class MapInfo : public de::Record { -public: - uint map; ///< Logical map number. - int hub; - uint warpTrans; - uint nextMap; - int cdTrack; - de::String title; - de::Uri sky1Material; - de::Uri sky2Material; - float sky1ScrollDelta; - float sky2ScrollDelta; - bool doubleSky; - bool lightning; - de::String fadeTable; - de::String songLump; - public: MapInfo(); diff --git a/doomsday/plugins/common/src/fi_lib.cpp b/doomsday/plugins/common/src/fi_lib.cpp index 52e00dee74..d4e4563461 100644 --- a/doomsday/plugins/common/src/fi_lib.cpp +++ b/doomsday/plugins/common/src/fi_lib.cpp @@ -91,7 +91,7 @@ static void initStateConditions(fi_state_t *s) s->conditions.leave_hub = true; if(!nextMapUri.path().isEmpty()) { - if(curMapInfo->hub == P_MapInfo(&nextMapUri)->hub) + if(curMapInfo->geti("hub") == P_MapInfo(&nextMapUri)->geti("hub")) { s->conditions.leave_hub = false; } diff --git a/doomsday/plugins/common/src/g_game.cpp b/doomsday/plugins/common/src/g_game.cpp index 84289e01cb..ec7d8053f2 100644 --- a/doomsday/plugins/common/src/g_game.cpp +++ b/doomsday/plugins/common/src/g_game.cpp @@ -1193,7 +1193,7 @@ static void printMapBanner() String text = String("Map: ") + gameMapUri.path().asText(); #if __JHEXEN__ MapInfo const *mapInfo = P_MapInfo(0/*current map*/); - text += String(" (%1)").arg(mapInfo? mapInfo->warpTrans + 1 : 0); + text += String(" (%1)").arg(mapInfo? mapInfo->geti("warpTrans") + 1 : 0); #endif text += String(" - " DE2_ESC(b)) + title; App_Log(DE2_LOG_NOTE, "%s", text.toUtf8().constData()); @@ -1790,7 +1790,7 @@ void G_PlayerLeaveMap(int player) dd_bool newHub = true; if(!nextMapUri.path().isEmpty()) { - newHub = (P_MapInfo(0/*current map*/)->hub != P_MapInfo(&nextMapUri)->hub); + newHub = (P_MapInfo(0/*current map*/)->geti("hub") != P_MapInfo(&nextMapUri)->geti("hub")); } #endif @@ -2415,7 +2415,7 @@ de::Uri G_ComposeMapUri(uint episode, uint map) de::Uri G_NextMap(dd_bool secretExit) { #if __JHEXEN__ - return G_ComposeMapUri(G_CurrentEpisodeNumber(), P_TranslateMap(P_MapInfo(&gameMapUri)->nextMap)); + return G_ComposeMapUri(G_CurrentEpisodeNumber(), P_TranslateMap(P_MapInfo(&gameMapUri)->geti("nextMap"))); DENG2_UNUSED(secretExit); #elif __JDOOM64__ @@ -2582,7 +2582,7 @@ String G_MapTitle(de::Uri const *mapUri) { if(MapInfo const *mapInfo = P_MapInfo(mapUri)) { - title = mapInfo->title; + title = mapInfo->gets("title"); } } #endif @@ -2694,7 +2694,7 @@ char const *G_InFineDebriefing(de::Uri const *mapUri) #if __JHEXEN__ if(cfg.overrideHubMsg && G_GameState() == GS_MAP && !nextMapUri.path().isEmpty()) { - if(P_MapInfo(mapUri)->hub != P_MapInfo(&nextMapUri)->hub) + if(P_MapInfo(mapUri)->geti("hub") != P_MapInfo(&nextMapUri)->geti("hub")) { return 0; } diff --git a/doomsday/plugins/common/src/gamesession.cpp b/doomsday/plugins/common/src/gamesession.cpp index cd3bb4ce3b..843e9f0596 100644 --- a/doomsday/plugins/common/src/gamesession.cpp +++ b/doomsday/plugins/common/src/gamesession.cpp @@ -967,7 +967,7 @@ void GameSession::leaveMap() // Are we entering a new hub? #if __JHEXEN__ - if(P_MapInfo(0/*current map*/)->hub != P_MapInfo(&nextMapUri)->hub) + if(P_MapInfo(0/*current map*/)->geti("hub") != P_MapInfo(&nextMapUri)->geti("hub")) #endif { // Clear all saved map states in the old hub. diff --git a/doomsday/plugins/common/src/mapinfo.cpp b/doomsday/plugins/common/src/mapinfo.cpp index 5c5b2c629c..4ad0f9bec8 100644 --- a/doomsday/plugins/common/src/mapinfo.cpp +++ b/doomsday/plugins/common/src/mapinfo.cpp @@ -39,43 +39,37 @@ using namespace de; typedef std::map MapInfos; static MapInfos mapInfos; -MapInfo::MapInfo() - : map (0) - , hub (0) - , warpTrans (0) - , nextMap (0) - , cdTrack (1) - , title ("Untitled") - , sky1Material ("Textures:SKY1", RC_NULL) - , sky2Material ("Textures:SKY1", RC_NULL) - , sky1ScrollDelta(0) - , sky2ScrollDelta(0) - , doubleSky (false) - , lightning (false) - , fadeTable ("COLORMAP") - , songLump ("DEFSONG") -{} - -void MapInfo::resetToDefaults() +static inline String defaultSkyMaterial() { - map = 0; // Unknown. - hub = 0; - warpTrans = 0; - nextMap = 0; // Always go to map 0 if not specified. - cdTrack = 1; - title = "Untitled"; #ifdef __JHEXEN__ - sky1Material = sky2Material = - de::Uri((gameMode == hexen_demo || gameMode == hexen_betademo? "Textures:SKY2" : "Textures:SKY1"), RC_NULL); -#else - sky1Material = sky2Material = de::Uri("Textures:SKY1", RC_NULL); + if(gameMode == hexen_demo || gameMode == hexen_betademo) + return "Textures:SKY2"; #endif - sky1ScrollDelta = 0; - sky2ScrollDelta = 0; - doubleSky = false; - lightning = false; - fadeTable = "COLORMAP"; - songLump = "DEFSONG"; // Unknown. + return "Textures:SKY1"; +} + +MapInfo::MapInfo() : Record() +{ + resetToDefaults(); +} + +void MapInfo::resetToDefaults() +{ + // Add all expected fields with their default values. + addNumber ("map", 0); // Unknown. + addNumber ("hub", 0); + addNumber ("warpTrans", 0); + addNumber ("nextMap", 0); // Always go to map 0 if not specified. + addNumber ("cdTrack", 1); + addText ("title", "Untitled"); + addText ("sky1Material", defaultSkyMaterial()); + addText ("sky2Material", defaultSkyMaterial()); + addNumber ("sky1ScrollDelta", 0); + addNumber ("sky2ScrollDelta", 0); + addBoolean("doubleSky", false); + addBoolean("lightning", false); + addText ("fadeTable", "COLORMAP"); + addText ("songLump", "DEFSONG"); } /** @@ -153,80 +147,81 @@ void MapInfoParser(ddstring_s const *path) info->resetToDefaults(); // Assign a logical map index. - info->map = tmap - 1; + info->set("map", tmap - 1); // The warp translation defaults to the logical map index. - info->warpTrans = tmap - 1; + info->set("warpTrans", tmap - 1); } // Map title must follow the number. - info->title = Str_Text(lexer.readString()); + info->set("title", Str_Text(lexer.readString())); // Process optional tokens. while(lexer.readToken()) { if(!Str_CompareIgnoreCase(lexer.token(), "sky1")) { - info->sky1Material = lexer.readUri("Textures"); - info->sky1ScrollDelta = (float) lexer.readNumber() / 256; + info->set("sky1Material", lexer.readUri("Textures").compose()); + info->set("sky1ScrollDelta", lexer.readNumber() / 256.f); continue; } if(!Str_CompareIgnoreCase(lexer.token(), "sky2")) { - info->sky2Material = lexer.readUri("Textures"); - info->sky2ScrollDelta = (float) lexer.readNumber() / 256; + info->set("sky2Material", lexer.readUri("Textures").compose()); + info->set("sky2ScrollDelta", lexer.readNumber() / 256.f); continue; } if(!Str_CompareIgnoreCase(lexer.token(), "doublesky")) { - info->doubleSky = true; + info->set("doubleSky", true); continue; } if(!Str_CompareIgnoreCase(lexer.token(), "lightning")) { - info->lightning = true; + info->set("lightning", true); continue; } if(!Str_CompareIgnoreCase(lexer.token(), "fadetable")) { - info->fadeTable = Str_Text(lexer.readString()); + info->set("fadeTable", Str_Text(lexer.readString())); continue; } if(!Str_CompareIgnoreCase(lexer.token(), "cluster")) { - info->hub = lexer.readNumber(); - if(info->hub < 1) + int const hubNum = lexer.readNumber(); + if(hubNum < 1) { Con_Error("MapInfoParser: Invalid 'cluster' (i.e., hub) number '%s' in \"%s\" on line #%i", lexer.token(), F_PrettyPath(Str_Text(path)), lexer.lineNumber()); } + info->set("hub", hubNum); continue; } if(!Str_CompareIgnoreCase(lexer.token(), "warptrans")) { - int mapWarpNum = lexer.readNumber(); + int const mapWarpNum = lexer.readNumber(); if(mapWarpNum < 1) { Con_Error("MapInfoParser: Invalid map warp-number '%s' in \"%s\" on line #%i", lexer.token(), F_PrettyPath(Str_Text(path)), lexer.lineNumber()); } - info->warpTrans = (unsigned) mapWarpNum - 1; + info->set("warpTrans", mapWarpNum - 1); continue; } if(!Str_CompareIgnoreCase(lexer.token(), "next")) { - int map = lexer.readNumber(); + int const map = lexer.readNumber(); if(map < 1) { Con_Error("MapInfoParser: Invalid map number '%s' in \"%s\" on line #%i", lexer.token(), F_PrettyPath(Str_Text(path)), lexer.lineNumber()); } - info->nextMap = (unsigned) map - 1; + info->set("nextMap", map - 1); continue; } if(!Str_CompareIgnoreCase(lexer.token(), "cdtrack")) { - info->cdTrack = lexer.readNumber(); + info->set("cdTrack", lexer.readNumber()); continue; } @@ -252,8 +247,8 @@ void MapInfoParser(ddstring_s const *path) { MapInfo const &info = i->second; App_Log(DE2_DEV_RES_MSG, "MAPINFO %s { title: \"%s\" hub: %i map: %i warp: %i }", - i->first.c_str(), info.title.toUtf8().constData(), - info.hub, info.map, info.warpTrans); + i->first.c_str(), info.gets("title").toUtf8().constData(), + info.geti("hub"), info.geti("map"), info.geti("warpTrans")); } #endif } @@ -281,16 +276,16 @@ uint P_TranslateMapIfExists(uint map) { MapInfo const &info = i->second; - if(info.warpTrans == map) + if(info.geti("warpTrans") == map) { - if(info.hub) + if(info.geti("hub")) { - App_Log(DE2_DEV_MAP_VERBOSE, "Warp %i translated to logical map %i, hub %i", map, info.map, info.hub); - return info.map; + App_Log(DE2_DEV_MAP_VERBOSE, "Warp %i translated to logical map %i, hub %i", map, info.geti("map"), info.geti("hub")); + return (unsigned) info.geti("map"); } - App_Log(DE2_DEV_MAP_VERBOSE, "Warp %i matches logical map %i, but it has no hub", map, info.map); - matchedWithoutHub = info.map; + App_Log(DE2_DEV_MAP_VERBOSE, "Warp %i matches logical map %i, but it has no hub", map, info.geti("map")); + matchedWithoutHub = (unsigned) info.geti("map"); } } diff --git a/doomsday/plugins/common/src/p_mapsetup.cpp b/doomsday/plugins/common/src/p_mapsetup.cpp index e3fe04d9e5..c18f246c0e 100644 --- a/doomsday/plugins/common/src/p_mapsetup.cpp +++ b/doomsday/plugins/common/src/p_mapsetup.cpp @@ -662,7 +662,7 @@ static void initFog(ddmapinfo_t *ddMapInfo) #if __JHEXEN__ if(MapInfo const *mapInfo = P_MapInfo(0/*current map*/)) { - int fadeTable = CentralLumpIndex().findLast(mapInfo->fadeTable + ".lmp"); + int fadeTable = CentralLumpIndex().findLast(mapInfo->gets("fadeTable") + ".lmp"); if(fadeTable == CentralLumpIndex().findLast("COLORMAP.lmp")) { // We don't want fog in this case. diff --git a/doomsday/plugins/common/src/p_sound.cpp b/doomsday/plugins/common/src/p_sound.cpp index 15199d1b7c..ac7aa01652 100644 --- a/doomsday/plugins/common/src/p_sound.cpp +++ b/doomsday/plugins/common/src/p_sound.cpp @@ -38,8 +38,8 @@ void S_MapMusic(de::Uri const *mapUri) #ifdef __JHEXEN__ MapInfo const *mapInfo = P_MapInfo(mapUri); - int const cdTrack = mapInfo->cdTrack; - String const lump = mapInfo->songLump.compareWithoutCase("DEFSONG")? mapInfo->songLump : ""; + int const cdTrack = mapInfo->geti("cdTrack"); + String const lump = mapInfo->gets("songLump").compareWithoutCase("DEFSONG")? mapInfo->gets("songLump") : ""; App_Log(DE2_RES_VERBOSE, "S_MapMusic: %s lump: %s", mapUri->compose().toUtf8().constData(), lump); @@ -131,7 +131,7 @@ void SndInfoParser(ddstring_s const *path) de::Uri mapUri = G_ComposeMapUri(0, mapNumber - 1); if(MapInfo *mapInfo = P_MapInfo(&mapUri)) { - mapInfo->songLump = Str_Text(lumpName); + mapInfo->set("songLump", Str_Text(lumpName)); } } continue; diff --git a/doomsday/plugins/hexen/src/p_spec.cpp b/doomsday/plugins/hexen/src/p_spec.cpp index 9037942233..8a123d2b87 100644 --- a/doomsday/plugins/hexen/src/p_spec.cpp +++ b/doomsday/plugins/hexen/src/p_spec.cpp @@ -79,11 +79,11 @@ void P_InitSky(de::Uri const &mapUri) { if(MapInfo const *mapInfo = P_MapInfo(&mapUri)) { - sky1Material = Materials_ResolveUri(reinterpret_cast(&mapInfo->sky1Material)); - sky2Material = Materials_ResolveUri(reinterpret_cast(&mapInfo->sky2Material)); - sky1ScrollDelta = mapInfo->sky1ScrollDelta; - sky2ScrollDelta = mapInfo->sky2ScrollDelta; - doubleSky = mapInfo->doubleSky; + sky1Material = Materials_ResolveUriCString(mapInfo->gets("sky1Material").toUtf8().constData()); + sky2Material = Materials_ResolveUriCString(mapInfo->gets("sky2Material").toUtf8().constData()); + sky1ScrollDelta = mapInfo->getd("sky1ScrollDelta"); + sky2ScrollDelta = mapInfo->getd("sky2ScrollDelta"); + doubleSky = mapInfo->getb("doubleSky"); } sky1ColumnOffset = sky2ColumnOffset = 0; @@ -1044,7 +1044,7 @@ void P_InitLightning(void) int i, secCount; MapInfo const *mapInfo = P_MapInfo(0/*current map*/); - if(!mapInfo || !mapInfo->lightning) + if(!mapInfo || !mapInfo->getb("lightning")) { mapHasLightning = false; lightningFlash = 0;