diff --git a/doomsday/engine/portable/include/dd_main.h b/doomsday/engine/portable/include/dd_main.h index 43d486903b..ff5d3f1bf9 100644 --- a/doomsday/engine/portable/include/dd_main.h +++ b/doomsday/engine/portable/include/dd_main.h @@ -54,6 +54,9 @@ extern finaleid_t titleFinale; extern GETGAMEAPI GetGameAPI; #endif +/// Currently active game. +extern Game* theGame; + int DD_EarlyInit(void); int DD_Main(void); void DD_CheckTimeDemo(void); @@ -98,9 +101,6 @@ const char* value_Str(int val); /// @return @c true iff there is presently a game loaded. boolean DD_GameLoaded(void); -/// @return Currently active Game record (always succeeds). -Game* DD_CurrentGame(void); - /// @return Current number of Game records. int DD_GameCount(void); diff --git a/doomsday/engine/portable/src/cl_main.c b/doomsday/engine/portable/src/cl_main.c index 8ff08c1146..6ab5199d5a 100644 --- a/doomsday/engine/portable/src/cl_main.c +++ b/doomsday/engine/portable/src/cl_main.c @@ -134,7 +134,7 @@ void Cl_SendHello(void) // The game mode is included in the hello packet. memset(buf, 0, sizeof(buf)); - strncpy(buf, Str_Text(Game_IdentityKey(DD_CurrentGame())), sizeof(buf) - 1); + strncpy(buf, Str_Text(Game_IdentityKey(theGame)), sizeof(buf) - 1); #ifdef _DEBUG Con_Message("Cl_SendHello: game mode = %s\n", buf); diff --git a/doomsday/engine/portable/src/con_config.c b/doomsday/engine/portable/src/con_config.c index fa06048521..1acfe60576 100644 --- a/doomsday/engine/portable/src/con_config.c +++ b/doomsday/engine/portable/src/con_config.c @@ -272,7 +272,7 @@ boolean Con_WriteState(const char* fileName, const char* bindingsFileName) */ void Con_SaveDefaults(void) { - Con_WriteState(cfgFile, (!isDedicated? Str_Text(Game_BindingConfig(DD_CurrentGame())) : 0)); + Con_WriteState(cfgFile, (!isDedicated? Str_Text(Game_BindingConfig(theGame)) : 0)); } D_CMD(WriteConsole) diff --git a/doomsday/engine/portable/src/dam_main.c b/doomsday/engine/portable/src/dam_main.c index 71c166d83a..e7b92baa1e 100644 --- a/doomsday/engine/portable/src/dam_main.c +++ b/doomsday/engine/portable/src/dam_main.c @@ -406,7 +406,7 @@ ddstring_t* DAM_ComposeCacheDir(const char* sourcePath) if(!sourcePath || !sourcePath[0]) return NULL; - gameIdentityKey = Game_IdentityKey(DD_CurrentGame()); + gameIdentityKey = Game_IdentityKey(theGame); mapPathIdentifier = calculateIdentifierForMapPath(sourcePath); Str_Init(&mapFileName); F_FileName(&mapFileName, sourcePath); diff --git a/doomsday/engine/portable/src/dd_help.c b/doomsday/engine/portable/src/dd_help.c index 890e31ec0b..d8e6f7ecea 100644 --- a/doomsday/engine/portable/src/dd_help.c +++ b/doomsday/engine/portable/src/dd_help.c @@ -326,7 +326,7 @@ void DD_ReadGameHelp(void) return; // Nothing to do. Str_Init(&helpFileName); - Str_Appendf(&helpFileName, "%sconhelp.txt", Str_Text(Game_DataPath(DD_CurrentGame()))); + Str_Appendf(&helpFileName, "%sconhelp.txt", Str_Text(Game_DataPath(theGame))); F_ExpandBasePath(&helpFileName, &helpFileName); DH_ReadStrings(Str_Text(&helpFileName)); Str_Free(&helpFileName); diff --git a/doomsday/engine/portable/src/dd_main.c b/doomsday/engine/portable/src/dd_main.c index 0b15fcc6a0..9a685df9b3 100644 --- a/doomsday/engine/portable/src/dd_main.c +++ b/doomsday/engine/portable/src/dd_main.c @@ -116,10 +116,12 @@ finaleid_t titleFinale = 0; static ddstring_t** gameResourceFileList = 0; static size_t numGameResourceFileList = 0; -// Game records and associated found-file lists. -static Game* nullGame; // Special "null-game" object. +Game* theGame = NULL; // Currently active game. + +// Game collection. static Game** games = 0; -static int gamesCount = 0, currentGameIndex = 0; +static int gamesCount = 0; +static Game* nullGame; // Special "null-game" object. // CODE -------------------------------------------------------------------- @@ -248,7 +250,7 @@ static Game* addGame(Game* game) boolean DD_GameLoaded(void) { - return !DD_IsNullGame(DD_CurrentGame()); + return !DD_IsNullGame(theGame); } int DD_GameCount(void) @@ -270,10 +272,10 @@ Game* DD_GameByIdentityKey(const char* identityKey) return NULL; } -Game* DD_CurrentGame(void) +gameid_t DD_GameId(Game* game) { - if(currentGameIndex <= 0) return nullGame; - return games[currentGameIndex-1]; + if(!game || game == nullGame) return 0; // Invalid id. + return (gameid_t)gameIndex(game); } boolean DD_IsNullGame(const Game* game) @@ -303,7 +305,7 @@ boolean DD_GameInfo(GameInfo* info) if(DD_GameLoaded()) { - populateGameInfo(info, DD_CurrentGame()); + populateGameInfo(info, theGame); return true; } @@ -403,7 +405,7 @@ gameid_t DD_DefineGame(const GameDef* def) if(game) { Game_SetPluginId(game, DD_PluginIdForActiveHook()); - return (gameid_t)gameIndex(game); + return DD_GameId(game); } return 0; // Invalid id. } @@ -428,7 +430,7 @@ void DD_DestroyGames(void) Game_Delete(nullGame); nullGame = NULL; } - currentGameIndex = 0; + theGame = NULL; } /** @@ -557,15 +559,15 @@ static boolean isRequiredResource(Game* game, const char* absolutePath) static void locateGameResources(Game* game) { - int oldGameIndex = currentGameIndex; + Game* oldGame = theGame; uint i; if(!game) return; - if(DD_CurrentGame() != game) + if(theGame != game) { /// \kludge Temporarily switch Game. - currentGameIndex = gameIndex(game); + theGame = game; // Re-init the resource locator using the search paths of this Game. F_ResetAllResourceNamespaces(); } @@ -587,10 +589,10 @@ static void locateGameResources(Game* game) } } - if(currentGameIndex != oldGameIndex) + if(theGame != oldGame) { /// \kludge Restore the old Game. - currentGameIndex = oldGameIndex; + theGame = oldGame; // Re-init the resource locator using the search paths of this Game. F_ResetAllResourceNamespaces(); } @@ -731,7 +733,7 @@ void DD_PrintGame(Game* game, int flags) } if(flags & PGF_STATUS) - Con_Printf("Status: %s\n", DD_CurrentGame() == game? "Loaded" : + Con_Printf("Status: %s\n", theGame == game? "Loaded" : allGameResourcesFound(game)? "Complete/Playable" : "Incomplete/Not playable"); } @@ -786,7 +788,7 @@ static int addFilesFromAutoData(boolean loadFiles) for(i = 0; extensions[i]; ++i) { Str_Clear(&pattern); - Str_Appendf(&pattern, "%sauto/*.%s", Str_Text(Game_DataPath(DD_CurrentGame())), extensions[i]); + Str_Appendf(&pattern, "%sauto/*.%s", Str_Text(Game_DataPath(theGame)), extensions[i]); F_AllResourcePaths2(Str_Text(&pattern), autoDataAdder, (void*)&data); } Str_Free(&pattern); @@ -908,7 +910,7 @@ static int DD_ChangeGameWorker(void* paramaters) // Now that resources have been located we can begin to initialize the game. if(!DD_IsNullGame(p->game) && gx.PreInit) - gx.PreInit((gameid_t)gameIndex(p->game)); + gx.PreInit(DD_GameId(p->game)); /** * Parse the game's main config file. @@ -1025,7 +1027,7 @@ boolean DD_ChangeGame2(Game* game, boolean allowReload) assert(game); // Ignore attempts to re-load the current game? - if(DD_CurrentGame() == game) + if(theGame == game) { if(!allowReload) { @@ -1100,7 +1102,7 @@ boolean DD_ChangeGame2(Game* game, boolean allowReload) Con_ClearDatabases(); // The current game is now the special "null-game". - currentGameIndex = 0; + theGame = nullGame; Con_InitDatabases(); DD_Register(); @@ -1147,14 +1149,7 @@ boolean DD_ChangeGame2(Game* game, boolean allowReload) } // This is now the current game. - if(!DD_IsNullGame(game)) - { - currentGameIndex = gameIndex(game); - } - else - { - currentGameIndex = 0; - } + theGame = game; DD_ComposeMainWindowTitle(buf); Sys_SetWindowTitle(windowIDX, buf); @@ -1318,8 +1313,7 @@ int DD_EarlyInit(void) if(Str_RAt(&defsPath, 0) != '/') Str_AppendChar(&defsPath, '/'); - nullGame = Game_New("null-game", &dataPath, &defsPath, "doomsday.cfg", 0, 0); - currentGameIndex = 0; + theGame = nullGame = Game_New("null-game", &dataPath, &defsPath, "doomsday.cfg", 0, 0); Str_Free(&defsPath); Str_Free(&dataPath); @@ -2378,7 +2372,7 @@ D_CMD(Unload) continue; // Do not attempt to unload a resource required by the current game. - if(isRequiredResource(DD_CurrentGame(), Str_Text(&foundPath))) + if(isRequiredResource(theGame, Str_Text(&foundPath))) { Con_Message("\"%s\" is required by the current game and cannot be unloaded in isolation.\n", F_PrettyPath(Str_Text(&foundPath))); @@ -2410,7 +2404,7 @@ D_CMD(ReloadGame) Con_Message("No game is presently loaded.\n"); return true; } - DD_ChangeGame2(DD_CurrentGame(), true); + DD_ChangeGame2(theGame, true); return true; } @@ -2442,7 +2436,7 @@ D_CMD(ListGames) { Game* game = gamePtrs[i]; - Con_Printf(" %s %-16s %s (%s)\n", DD_CurrentGame() == game? "*" : + Con_Printf(" %s %-16s %s (%s)\n", theGame == game? "*" : !allGameResourcesFound(game)? "!" : " ", Str_Text(Game_IdentityKey(game)), Str_Text(Game_Title(game)), Str_Text(Game_Author(game))); diff --git a/doomsday/engine/portable/src/dd_pinit.c b/doomsday/engine/portable/src/dd_pinit.c index 3768ad0892..8ea1fcc3df 100644 --- a/doomsday/engine/portable/src/dd_pinit.c +++ b/doomsday/engine/portable/src/dd_pinit.c @@ -114,7 +114,7 @@ void DD_ComposeMainWindowTitle(char* title) if(DD_GameLoaded() && gx.GetVariable) { sprintf(title, DOOMSDAY_NICENAME " " DOOMSDAY_VERSION_TEXT "%s - %s (%s %s)", - (isDedicated? " (Dedicated)" : ""), Str_Text(Game_Title(DD_CurrentGame())), + (isDedicated? " (Dedicated)" : ""), Str_Text(Game_Title(theGame)), (char*) gx.GetVariable(DD_PLUGIN_NAME), (char*) gx.GetVariable(DD_PLUGIN_VERSION_SHORT)); } else diff --git a/doomsday/engine/portable/src/def_main.c b/doomsday/engine/portable/src/def_main.c index d23893be37..e4e2713129 100644 --- a/doomsday/engine/portable/src/def_main.c +++ b/doomsday/engine/portable/src/def_main.c @@ -829,7 +829,7 @@ static void readAllDefinitions(void) // Now any definition files required by the game on load. if(DD_GameLoaded()) { - Game* game = DD_CurrentGame(); + Game* game = theGame; AbstractResource* const* records = Game_Resources(game, RC_DEFINITION, 0); AbstractResource* const* recordIt; @@ -858,7 +858,7 @@ static void readAllDefinitions(void) { ddstring_t pattern; Str_Init(&pattern); - Str_Appendf(&pattern, "%sauto/*.ded", Str_Text(Game_DefsPath(DD_CurrentGame()))); + Str_Appendf(&pattern, "%sauto/*.ded", Str_Text(Game_DefsPath(theGame))); F_AllResourcePaths(Str_Text(&pattern), autoDefsReader); Str_Free(&pattern); } diff --git a/doomsday/engine/portable/src/def_read.c b/doomsday/engine/portable/src/def_read.c index 89fbf5e099..f06c28d004 100644 --- a/doomsday/engine/portable/src/def_read.c +++ b/doomsday/engine/portable/src/def_read.c @@ -697,7 +697,7 @@ static boolean DED_CheckCondition(const char* cond, boolean expected) } else if(isalnum(cond[0])) { // A game mode. - value = !stricmp(cond, Str_Text(Game_IdentityKey(DD_CurrentGame()))); + value = !stricmp(cond, Str_Text(Game_IdentityKey(theGame))); } return value == expected; diff --git a/doomsday/engine/portable/src/edit_bias.c b/doomsday/engine/portable/src/edit_bias.c index bd1e37d170..39572b0e4a 100644 --- a/doomsday/engine/portable/src/edit_bias.c +++ b/doomsday/engine/portable/src/edit_bias.c @@ -423,7 +423,7 @@ static boolean SBE_Save(const char* name) // Since there can be quite a lot of these, make sure we'll skip // the ones that are definitely not suitable. - fprintf(file, "SkipIf Not %s\n", Str_Text(Game_IdentityKey(DD_CurrentGame()))); + fprintf(file, "SkipIf Not %s\n", Str_Text(Game_IdentityKey(theGame))); s = SB_GetSource(0); { int i; diff --git a/doomsday/engine/portable/src/finaleinterpreter.c b/doomsday/engine/portable/src/finaleinterpreter.c index ef3827d241..828bf41f6c 100644 --- a/doomsday/engine/portable/src/finaleinterpreter.c +++ b/doomsday/engine/portable/src/finaleinterpreter.c @@ -1354,7 +1354,7 @@ DEFFC(If) else if(!strnicmp(token, "mode:", 5)) { if(DD_GameLoaded()) - val = !stricmp(token + 5, Str_Text(Game_IdentityKey(DD_CurrentGame()))); + val = !stricmp(token + 5, Str_Text(Game_IdentityKey(theGame))); else val = 0; } diff --git a/doomsday/engine/portable/src/p_data.c b/doomsday/engine/portable/src/p_data.c index 4c84992f25..e7c4885475 100644 --- a/doomsday/engine/portable/src/p_data.c +++ b/doomsday/engine/portable/src/p_data.c @@ -150,7 +150,7 @@ const char* P_GenerateUniqueMapId(const char* mapID) Str_Init(&fileName); F_FileName(&fileName, F_LumpSourceFile(lumpNum)); dd_snprintf(uid, 255, "%s|%s|%s|%s", mapID, Str_Text(&fileName), - (!F_LumpIsCustom(lumpNum) ? "iwad" : "pwad"), Str_Text(Game_IdentityKey(DD_CurrentGame()))); + (!F_LumpIsCustom(lumpNum) ? "iwad" : "pwad"), Str_Text(Game_IdentityKey(theGame))); strlwr(uid); Str_Free(&fileName); diff --git a/doomsday/engine/portable/src/rend_console.c b/doomsday/engine/portable/src/rend_console.c index dd0df94f40..8e11f5b211 100644 --- a/doomsday/engine/portable/src/rend_console.c +++ b/doomsday/engine/portable/src/rend_console.c @@ -287,7 +287,7 @@ void Rend_ConsoleUpdateTitle(void) if(DD_GameLoaded()) { dd_snprintf(secondaryTitleText, sizeof(secondaryTitleText)-1, "%s %s", (char*) gx.GetVariable(DD_PLUGIN_NAME), (char*) gx.GetVariable(DD_PLUGIN_VERSION_SHORT)); - strncpy(statusText, Str_Text(Game_Title(DD_CurrentGame())), sizeof(statusText) - 1); + strncpy(statusText, Str_Text(Game_Title(theGame)), sizeof(statusText) - 1); return; } diff --git a/doomsday/engine/portable/src/sv_main.c b/doomsday/engine/portable/src/sv_main.c index 0220eabbc2..bd746f9e72 100644 --- a/doomsday/engine/portable/src/sv_main.c +++ b/doomsday/engine/portable/src/sv_main.c @@ -94,7 +94,7 @@ void Sv_GetInfo(serverinfo_t* info) // Let's figure out what we want to tell about ourselves. info->version = DOOMSDAY_VERSION; dd_snprintf(info->plugin, sizeof(info->plugin) - 1, "%s %s", (char*) gx.GetVariable(DD_PLUGIN_NAME), (char*) gx.GetVariable(DD_PLUGIN_VERSION_SHORT)); - strncpy(info->gameIdentityKey, Str_Text(Game_IdentityKey(DD_CurrentGame())), sizeof(info->gameIdentityKey) - 1); + strncpy(info->gameIdentityKey, Str_Text(Game_IdentityKey(theGame)), sizeof(info->gameIdentityKey) - 1); strncpy(info->gameConfig, gx.GetVariable(DD_GAME_CONFIG), sizeof(info->gameConfig) - 1); strncpy(info->name, serverName, sizeof(info->name) - 1); strncpy(info->description, serverInfo, sizeof(info->description) - 1); @@ -418,7 +418,7 @@ void Sv_HandlePacket(void) { // Check the game mode (max 16 chars). Reader_Read(msgReader, buf, 16); - if(strnicmp(buf, Str_Text(Game_IdentityKey(DD_CurrentGame())), 16)) + if(strnicmp(buf, Str_Text(Game_IdentityKey(theGame)), 16)) { Con_Printf(" Bad Game ID: %-.16s\n", buf); N_TerminateClient(from); diff --git a/doomsday/engine/portable/src/sys_reslocator.c b/doomsday/engine/portable/src/sys_reslocator.c index f9ecb64d06..a8bd229e09 100644 --- a/doomsday/engine/portable/src/sys_reslocator.c +++ b/doomsday/engine/portable/src/sys_reslocator.c @@ -1236,7 +1236,7 @@ boolean F_MapResourcePath(resourcenamespaceid_t rni, ddstring_t* path) if(nameLen <= pathLen && Str_At(path, nameLen) == '/' && !strnicmp(Str_Text(&info->name), Str_Text(path), nameLen)) { - Str_Prepend(path, Str_Text(Game_DataPath(DD_CurrentGame()))); + Str_Prepend(path, Str_Text(Game_DataPath(theGame))); return true; } } diff --git a/doomsday/engine/portable/src/ui_mpi.c b/doomsday/engine/portable/src/ui_mpi.c index 251ceec30e..0c38c25428 100644 --- a/doomsday/engine/portable/src/ui_mpi.c +++ b/doomsday/engine/portable/src/ui_mpi.c @@ -481,11 +481,11 @@ void MPIUpdateServerList(void) N_MasterGet(i, &info); // Is this suitable? - if(info.version != DOOMSDAY_VERSION || stricmp(info.gameIdentityKey, Str_Text(Game_IdentityKey(DD_CurrentGame()))) || !info.canJoin) + if(info.version != DOOMSDAY_VERSION || stricmp(info.gameIdentityKey, Str_Text(Game_IdentityKey(theGame))) || !info.canJoin) { Con_Message("Server %s filtered out:\n", info.name); Con_Message(" remote = %i, local = %i\n", info.version, DOOMSDAY_VERSION); - Con_Message(" remote = %s, local = %s\n", info.gameIdentityKey, Str_Text(Game_IdentityKey(DD_CurrentGame()))); + Con_Message(" remote = %s, local = %s\n", info.gameIdentityKey, Str_Text(Game_IdentityKey(theGame))); Con_Message(" can join = %i\n", info.canJoin); continue; } diff --git a/doomsday/engine/portable/src/uri.c b/doomsday/engine/portable/src/uri.c index 8fd3fc7787..4afce28f7f 100644 --- a/doomsday/engine/portable/src/uri.c +++ b/doomsday/engine/portable/src/uri.c @@ -126,7 +126,7 @@ static ddstring_t* resolveUri(const Uri* uri) else if(!Str_CompareIgnoreCase(&part, "Game.DataPath")) { /// \note DataPath already has ending '/'. - Game* game = DD_CurrentGame(); + Game* game = theGame; if(DD_IsNullGame(game)) goto parseEnded; Str_PartAppend(dest, Str_Text(Game_DataPath(game)), 0, Str_Length(Game_DataPath(game))-1); @@ -134,14 +134,14 @@ static ddstring_t* resolveUri(const Uri* uri) else if(!Str_CompareIgnoreCase(&part, "Game.DefsPath")) { /// \note DefsPath already has ending '/'. - Game* game = DD_CurrentGame(); + Game* game = theGame; if(DD_IsNullGame(game)) goto parseEnded; Str_PartAppend(dest, Str_Text(Game_DefsPath(game)), 0, Str_Length(Game_DefsPath(game))-1); } else if(!Str_CompareIgnoreCase(&part, "Game.IdentityKey")) { - Game* game = DD_CurrentGame(); + Game* game = theGame; if(DD_IsNullGame(game)) goto parseEnded; Str_Append(dest, Str_Text(Game_IdentityKey(game))); diff --git a/doomsday/engine/portable/src/zipfile.c b/doomsday/engine/portable/src/zipfile.c index 48b2403cbc..6333e254a0 100644 --- a/doomsday/engine/portable/src/zipfile.c +++ b/doomsday/engine/portable/src/zipfile.c @@ -137,7 +137,7 @@ static void ZipFile_ApplyPathMappings(ddstring_t* dest, const ddstring_t* src) { ddstring_t* out = (dest == src? Str_New() : dest); - Str_Appendf(out, "%sauto/", Str_Text(Game_DefsPath(DD_CurrentGame()))); + Str_Appendf(out, "%sauto/", Str_Text(Game_DefsPath(theGame))); Str_PartAppend(out, Str_Text(src), 1, Str_Length(src)-1); if(dest == src) @@ -153,7 +153,7 @@ static void ZipFile_ApplyPathMappings(ddstring_t* dest, const ddstring_t* src) { ddstring_t* out = (dest == src? Str_New() : dest); - Str_Appendf(out, "%sauto/", Str_Text(Game_DataPath(DD_CurrentGame()))); + Str_Appendf(out, "%sauto/", Str_Text(Game_DataPath(theGame))); Str_PartAppend(out, Str_Text(src), 1, Str_Length(src)-1); if(dest == src) @@ -199,10 +199,10 @@ static void ZipFile_ApplyPathMappings(ddstring_t* dest, const ddstring_t* src) switch(rclass) { case RC_PACKAGE: // Mapped to the Data directory. - Str_Appendf(&mapped, "%sauto/", Str_Text(Game_DataPath(DD_CurrentGame()))); + Str_Appendf(&mapped, "%sauto/", Str_Text(Game_DataPath(theGame))); break; case RC_DEFINITION: // Mapped to the Defs directory. - Str_Appendf(&mapped, "%sauto/", Str_Text(Game_DefsPath(DD_CurrentGame()))); + Str_Appendf(&mapped, "%sauto/", Str_Text(Game_DefsPath(theGame))); break; default: /* Not mapped */ break; }