Skip to content

Commit

Permalink
Refactor|MapInfo|libcommon: Derive MapInfo from de::Record
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jul 6, 2014
1 parent 2008955 commit a701375
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 93 deletions.
18 changes: 1 addition & 17 deletions doomsday/plugins/common/include/mapinfo.h
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/fi_lib.cpp
Expand Up @@ -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;
}
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 = 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());
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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__
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/gamesession.cpp
Expand Up @@ -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.
Expand Down
113 changes: 54 additions & 59 deletions doomsday/plugins/common/src/mapinfo.cpp
Expand Up @@ -39,43 +39,37 @@ using namespace de;
typedef std::map<std::string, MapInfo> 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");
}

/**
Expand Down Expand Up @@ -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;
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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");
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/p_mapsetup.cpp
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions doomsday/plugins/common/src/p_sound.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions doomsday/plugins/hexen/src/p_spec.cpp
Expand Up @@ -79,11 +79,11 @@ void P_InitSky(de::Uri const &mapUri)
{
if(MapInfo const *mapInfo = P_MapInfo(&mapUri))
{
sky1Material = Materials_ResolveUri(reinterpret_cast<uri_s const *>(&mapInfo->sky1Material));
sky2Material = Materials_ResolveUri(reinterpret_cast<uri_s const *>(&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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a701375

Please sign in to comment.