From 6e54aa9d905c8a5f919bcea75e775105eac29679 Mon Sep 17 00:00:00 2001 From: danij Date: Tue, 12 Feb 2013 13:51:58 +0000 Subject: [PATCH] Refactor: Use App_GameLoaded() to determine if a game is loaded --- doomsday/client/include/dd_main.h | 2 +- doomsday/client/src/con_config.cpp | 4 +-- doomsday/client/src/con_main.cpp | 10 +++--- doomsday/client/src/dd_loop.cpp | 6 ++-- doomsday/client/src/dd_main.cpp | 36 ++++++++++---------- doomsday/client/src/dd_pinit.cpp | 2 +- doomsday/client/src/def_main.cpp | 8 ++--- doomsday/client/src/def_read.cpp | 2 +- doomsday/client/src/map/dam_main.cpp | 2 +- doomsday/client/src/network/ui_mpi.cpp | 2 +- doomsday/client/src/render/rend_console.cpp | 2 +- doomsday/client/src/render/rend_particle.cpp | 2 +- doomsday/client/src/resource/zip.cpp | 2 +- doomsday/client/src/sys_system.cpp | 2 +- doomsday/client/src/ui/b_main.cpp | 4 +-- doomsday/client/src/ui/dd_input.cpp | 2 +- doomsday/client/src/ui/finaleinterpreter.cpp | 2 +- doomsday/client/src/ui/window.cpp | 6 ++-- doomsday/client/src/uri.cpp | 11 +++--- doomsday/server/src/shelluser.cpp | 2 +- 20 files changed, 54 insertions(+), 55 deletions(-) diff --git a/doomsday/client/include/dd_main.h b/doomsday/client/include/dd_main.h index 43924c76f3..0d01dde53d 100644 --- a/doomsday/client/include/dd_main.h +++ b/doomsday/client/include/dd_main.h @@ -84,7 +84,7 @@ boolean DD_Init(void); boolean DD_IsShuttingDown(void); /// @return @c true iff there is presently a game loaded. -boolean DD_GameLoaded(void); +boolean App_GameLoaded(void); void DD_CheckTimeDemo(void); void DD_UpdateEngineState(void); diff --git a/doomsday/client/src/con_config.cpp b/doomsday/client/src/con_config.cpp index 0a1eee1130..877990c4f5 100644 --- a/doomsday/client/src/con_config.cpp +++ b/doomsday/client/src/con_config.cpp @@ -36,7 +36,7 @@ static int flagsAllow = 0; static void writeHeaderComment(FILE* file) { - if(!DD_GameLoaded()) + if(!App_GameLoaded()) fprintf(file, "# " DOOMSDAY_NICENAME " " DOOMSDAY_VERSION_TEXT "\n"); else fprintf(file, "# %s %s / " DOOMSDAY_NICENAME " " DOOMSDAY_VERSION_TEXT "\n", @@ -274,7 +274,7 @@ boolean Con_WriteState(const char* fileName, const char* bindingsFileName) void Con_SaveDefaults() { - Con_WriteState(cfgFile, (!isDedicated && !de::isNullGame(App_CurrentGame())? + Con_WriteState(cfgFile, (!isDedicated && App_GameLoaded()? Str_Text(App_CurrentGame().bindingConfig()) : 0)); } diff --git a/doomsday/client/src/con_main.cpp b/doomsday/client/src/con_main.cpp index f308aac762..2b3462a73e 100644 --- a/doomsday/client/src/con_main.cpp +++ b/doomsday/client/src/con_main.cpp @@ -789,7 +789,7 @@ static int executeSubCmd(const char *subCmd, byte src, boolean isNetCmd) // Trying to issue a command requiring a loaded game? // dj: This should be considered a short-term solution. Ideally we want some namespacing mechanics. - if((ccmd->flags & CMDF_NO_NULLGAME) && !DD_GameLoaded()) + if((ccmd->flags & CMDF_NO_NULLGAME) && !App_GameLoaded()) { Con_Printf("Execution of command '%s' not possible with no game loaded.\n", ccmd->name); return true; @@ -1499,7 +1499,7 @@ boolean Con_Responder(const ddevent_t* ev) if(!IS_KEY_TOGGLE(ev)) return false; - if(DD_GameLoaded()) + if(App_GameLoaded()) { // Special console key: Shift-Escape opens the Control Panel. if(!conInputLock && shiftDown && IS_TOGGLE_DOWN_ID(ev, DDKEY_ESCAPE)) @@ -1522,7 +1522,7 @@ boolean Con_Responder(const ddevent_t* ev) else if(!ConsoleActive) { // Any key will open the console. - if(!DD_GameLoaded() && IS_TOGGLE_DOWN(ev)) + if(!App_GameLoaded() && IS_TOGGLE_DOWN(ev)) { Con_Open(true); return true; @@ -2182,7 +2182,7 @@ D_CMD(Version) Con_Printf("Homepage: %s\n", DOOMSDAY_HOMEURL); Con_Printf("Project homepage: %s\n", DENGPROJECT_HOMEURL); // Print the version info of the current game if loaded. - if(DD_GameLoaded()) + if(App_GameLoaded()) { Con_Printf("Game: %s\n", (char*) gx.GetVariable(DD_PLUGIN_VERSION_LONG)); } @@ -2201,7 +2201,7 @@ D_CMD(Quit) } #endif - if(argv[0][4] == '!' || isDedicated || !DD_GameLoaded() || + if(argv[0][4] == '!' || isDedicated || !App_GameLoaded() || gx.TryShutdown == 0) { // No questions asked. diff --git a/doomsday/client/src/dd_loop.cpp b/doomsday/client/src/dd_loop.cpp index 5d2a3043d9..521d5cb3b0 100644 --- a/doomsday/client/src/dd_loop.cpp +++ b/doomsday/client/src/dd_loop.cpp @@ -239,7 +239,7 @@ void DD_GameLoopDrawer(void) if(drawGame) { - if(DD_GameLoaded()) + if(App_GameLoaded()) { // Interpolate the world ready for drawing view(s) of it. if(theMap) @@ -267,7 +267,7 @@ void DD_GameLoopDrawer(void) UI2_Drawer(); // Draw any full window game graphics. - if(DD_GameLoaded() && gx.DrawWindow) + if(App_GameLoaded() && gx.DrawWindow) gx.DrawWindow(Window_Size(theWindow)); } } @@ -372,7 +372,7 @@ static void baseTicker(timespan_t time) FI_Ticker(); // Game logic. - if(DD_GameLoaded() && gx.Ticker) + if(App_GameLoaded() && gx.Ticker) { gx.Ticker(time); } diff --git a/doomsday/client/src/dd_main.cpp b/doomsday/client/src/dd_main.cpp index dcb10e714e..8fdb853f5f 100644 --- a/doomsday/client/src/dd_main.cpp +++ b/doomsday/client/src/dd_main.cpp @@ -659,13 +659,13 @@ static void destroyPathList(ddstring_t*** list, size_t* listSize) *listSize = 0; } -boolean DD_GameLoaded(void) +boolean App_GameLoaded() { - DENG_ASSERT(games); + if(!games) return false; return !isNullGame(games->current()); } -void DD_DestroyGames(void) +void DD_DestroyGames() { destroyPathList(&sessionResourceFileList, &numSessionResourceFileList); @@ -860,7 +860,7 @@ static int DD_LoadGameStartupResourcesWorker(void* parameters) if(p->initiatedBusyMode) Con_SetProgress(50); - if(DD_GameLoaded()) + if(App_GameLoaded()) { // Create default Auto mappings in the runtime directory. @@ -1079,7 +1079,7 @@ static int DD_LoadAddonResourcesWorker(void* parameters) if(p->initiatedBusyMode) Con_SetProgress(50); - if(DD_GameLoaded()) + if(App_GameLoaded()) { /** * Phase 3: Add real files from the Auto directory. @@ -1129,7 +1129,7 @@ static int DD_ActivateGameWorker(void* parameters) Con_SetProgress(50); // Now that resources have been located we can begin to initialize the game. - if(DD_GameLoaded() && gx.PreInit) + if(App_GameLoaded() && gx.PreInit) { DENG_ASSERT(games->current().pluginId() != 0); @@ -1165,7 +1165,7 @@ static int DD_ActivateGameWorker(void* parameters) } #ifdef __CLIENT__ - if(DD_GameLoaded()) + if(App_GameLoaded()) { // Apply default control bindings for this game. B_BindGameDefaults(); @@ -1258,7 +1258,7 @@ boolean DD_GameInfo(GameInfo *info) std::memset(info, 0, sizeof(*info)); - if(DD_GameLoaded()) + if(App_GameLoaded()) { populateGameInfo(*info, games->current()); return true; @@ -1362,7 +1362,7 @@ bool DD_ChangeGame(de::Game& game, bool allowReload = false) { if(!allowReload) { - if(DD_GameLoaded()) + if(App_GameLoaded()) Con_Message("%s (%s) - already loaded.\n", Str_Text(game.title()), Str_Text(game.identityKey())); return true; } @@ -1385,7 +1385,7 @@ bool DD_ChangeGame(de::Game& game, bool allowReload = false) #endif // If a game is presently loaded; unload it. - if(DD_GameLoaded()) + if(App_GameLoaded()) { if(gx.Shutdown) gx.Shutdown(); @@ -1560,7 +1560,7 @@ bool DD_ChangeGame(de::Game& game, bool allowReload = false) p.initiatedBusyMode = !BusyMode_Active(); - if(DD_GameLoaded()) + if(App_GameLoaded()) { // Tell the plugin it is being loaded. /// @todo Must this be done in the main thread? @@ -1586,7 +1586,7 @@ bool DD_ChangeGame(de::Game& game, bool allowReload = false) Rend_ParticleLoadExtraTextures(); #endif - if(DD_GameLoaded()) + if(App_GameLoaded()) { de::Game::printBanner(games->current()); } @@ -1947,7 +1947,7 @@ boolean DD_Init(void) * One-time execution of network commands on the command line. * Commands are only executed if we have loaded a game during startup. */ - if(DD_GameLoaded()) + if(App_GameLoaded()) { // Client connection command. if(CommandLine_CheckWith("-connect", 1)) @@ -2220,7 +2220,7 @@ void DD_UpdateEngineState(void) R_InitFlatTextures(); R_InitSpriteTextures(); - if(DD_GameLoaded() && gx.UpdateState) + if(App_GameLoaded() && gx.UpdateState) gx.UpdateState(DD_PRE); hadFog = usingFog; @@ -2253,7 +2253,7 @@ void DD_UpdateEngineState(void) } } - if(DD_GameLoaded() && gx.UpdateState) + if(App_GameLoaded() && gx.UpdateState) gx.UpdateState(DD_POST); // Reset the anim groups (if in-game) @@ -2834,7 +2834,7 @@ D_CMD(Unload) // No arguments; unload the current game if loaded. if(argc == 1) { - if(!DD_GameLoaded()) + if(!App_GameLoaded()) { Con_Message("There is no game currently loaded.\n"); return true; @@ -2867,7 +2867,7 @@ D_CMD(Unload) { de::Game& game = games->byIdentityKey(Str_Text(&searchPath)); Str_Free(&searchPath); - if(DD_GameLoaded()) + if(App_GameLoaded()) { return DD_ChangeGame(games->nullGame()); } @@ -2915,7 +2915,7 @@ D_CMD(ReloadGame) { DENG_UNUSED(src); DENG_UNUSED(argc); DENG_UNUSED(argv); - if(!DD_GameLoaded()) + if(!App_GameLoaded()) { Con_Message("No game is presently loaded.\n"); return true; diff --git a/doomsday/client/src/dd_pinit.cpp b/doomsday/client/src/dd_pinit.cpp index 6d8c26426e..a1a1e0061b 100644 --- a/doomsday/client/src/dd_pinit.cpp +++ b/doomsday/client/src/dd_pinit.cpp @@ -72,7 +72,7 @@ int DD_CheckArg(char const *tag, const char** value) void DD_ComposeMainWindowTitle(char* title) { - if(DD_GameLoaded() && gx.GetVariable) + if(App_GameLoaded() && gx.GetVariable) { sprintf(title, DOOMSDAY_NICENAME " " DOOMSDAY_VERSION_TEXT "%s - %s", (isDedicated? " (Dedicated)" : ""), Str_Text(App_CurrentGame().title())); diff --git a/doomsday/client/src/def_main.cpp b/doomsday/client/src/def_main.cpp index 00ed05c8ba..d6af67196f 100644 --- a/doomsday/client/src/def_main.cpp +++ b/doomsday/client/src/def_main.cpp @@ -305,7 +305,7 @@ acfnptr_t Def_GetActionPtr(const char* name) actionlink_t* linkIt; if(!name || !name[0]) return 0; - if(!DD_GameLoaded()) return 0; + if(!App_GameLoaded()) return 0; // Action links are provided by the game, who owns the actual action functions. for(linkIt = (actionlink_t*) gx.GetVariable(DD_ACTION_LINK); @@ -320,7 +320,7 @@ acfnptr_t Def_GetActionPtr(const char* name) int Def_GetActionNum(const char* name) { - if(name && name[0] && DD_GameLoaded()) + if(name && name[0] && App_GameLoaded()) { // Action links are provided by the game, who owns the actual action functions. actionlink_t* links = (actionlink_t*) gx.GetVariable(DD_ACTION_LINK); @@ -865,7 +865,7 @@ static void readAllDefinitions(void) } // Now any definition files required by the game on load. - if(DD_GameLoaded()) + if(App_GameLoaded()) { de::Game::Manifests const& gameResources = App_CurrentGame().manifests(); int packageIdx = 0; @@ -890,7 +890,7 @@ static void readAllDefinitions(void) } // Next up are definition files in the Games' /auto directory. - if(!CommandLine_Exists("-noauto") && DD_GameLoaded()) + if(!CommandLine_Exists("-noauto") && App_GameLoaded()) { FS1::PathList found; if(App_FileSystem()->findAllPaths(de::Uri("$(App.DefsPath)/$(GamePlugin.Name)/auto/*.ded", RC_NULL).resolved(), 0, found)) diff --git a/doomsday/client/src/def_read.cpp b/doomsday/client/src/def_read.cpp index 86be643e45..2feab9da9d 100644 --- a/doomsday/client/src/def_read.cpp +++ b/doomsday/client/src/def_read.cpp @@ -688,7 +688,7 @@ static boolean DED_CheckCondition(const char* cond, boolean expected) // A command line option. value = (CommandLine_Check(token) != 0); } - else if(isalnum(cond[0]) && !de::isNullGame(App_CurrentGame())) + else if(isalnum(cond[0]) && App_GameLoaded()) { // A game mode. value = !stricmp(cond, Str_Text(App_CurrentGame().identityKey())); diff --git a/doomsday/client/src/map/dam_main.cpp b/doomsday/client/src/map/dam_main.cpp index 579d6dc9f2..80c2a2bdca 100644 --- a/doomsday/client/src/map/dam_main.cpp +++ b/doomsday/client/src/map/dam_main.cpp @@ -157,7 +157,7 @@ AutoStr* DAM_ComposeCacheDir(char const* sourcePath) { if(!sourcePath || !sourcePath[0]) return NULL; - DENG_ASSERT(!de::isNullGame(App_CurrentGame())); + DENG_ASSERT(App_GameLoaded()); Str const *gameIdentityKey = App_CurrentGame().identityKey(); ushort mapPathIdentifier = calculateIdentifierForMapPath(sourcePath); diff --git a/doomsday/client/src/network/ui_mpi.cpp b/doomsday/client/src/network/ui_mpi.cpp index dd7f32127d..0d66f6b992 100644 --- a/doomsday/client/src/network/ui_mpi.cpp +++ b/doomsday/client/src/network/ui_mpi.cpp @@ -623,7 +623,7 @@ void MPIUpdatePublicButton(void) */ void DD_NetSetup(int serverMode) { - if(!DD_GameLoaded()) + if(!App_GameLoaded()) { Con_Message("%s setup can only be activated when a game is loaded.\n", serverMode? "Server" : "Client"); return; diff --git a/doomsday/client/src/render/rend_console.cpp b/doomsday/client/src/render/rend_console.cpp index c858d8d231..960cdeb32b 100644 --- a/doomsday/client/src/render/rend_console.cpp +++ b/doomsday/client/src/render/rend_console.cpp @@ -273,7 +273,7 @@ void Rend_ConsoleUpdateTitle() if(isDedicated || !inited) return; // Update the secondary title and the game status. - if(DD_GameLoaded()) + if(App_GameLoaded()) { dd_snprintf(secondaryTitleText, sizeof(secondaryTitleText)-1, "%s", (char *) gx.GetVariable(DD_PLUGIN_NICENAME)); strncpy(statusText, Str_Text(App_CurrentGame().title()), sizeof(statusText) - 1); diff --git a/doomsday/client/src/render/rend_particle.cpp b/doomsday/client/src/render/rend_particle.cpp index 07e03e2c75..cad5a7c3da 100644 --- a/doomsday/client/src/render/rend_particle.cpp +++ b/doomsday/client/src/render/rend_particle.cpp @@ -171,7 +171,7 @@ void Rend_ParticleLoadExtraTextures(void) if(novideo) return; Rend_ParticleReleaseExtraTextures(); - if(!DD_GameLoaded()) return; + if(!App_GameLoaded()) return; for(i = 0; i < MAX_PTC_TEXTURES; ++i) { diff --git a/doomsday/client/src/resource/zip.cpp b/doomsday/client/src/resource/zip.cpp index 2d43981891..fffe94473d 100644 --- a/doomsday/client/src/resource/zip.cpp +++ b/doomsday/client/src/resource/zip.cpp @@ -438,7 +438,7 @@ struct Zip::Instance compressedSize = ULONG(header->size); } - if(DD_GameLoaded()) + if(App_GameLoaded()) { // In some cases the path to the file is mapped to some // other location in the virtual file system. diff --git a/doomsday/client/src/sys_system.cpp b/doomsday/client/src/sys_system.cpp index f47985351d..f846325190 100644 --- a/doomsday/client/src/sys_system.cpp +++ b/doomsday/client/src/sys_system.cpp @@ -126,7 +126,7 @@ void Sys_Shutdown(void) appShutdown = true; // Time to unload *everything*. - if(DD_GameLoaded()) + if(App_GameLoaded()) Con_Execute(CMDS_DDAY, "unload", true, false); Net_Shutdown(); diff --git a/doomsday/client/src/ui/b_main.cpp b/doomsday/client/src/ui/b_main.cpp index 19efb0d85e..a812c3f507 100644 --- a/doomsday/client/src/ui/b_main.cpp +++ b/doomsday/client/src/ui/b_main.cpp @@ -190,7 +190,7 @@ static int globalContextFallback(const ddevent_t* ddev) #endif if(Con_Responder(ddev)) return true; // Eaten. - if(DD_GameLoaded()) + if(App_GameLoaded()) { event_t ev; DD_ConvertEvent(ddev, &ev); @@ -313,7 +313,7 @@ void B_BindDefaults(void) void B_BindGameDefaults(void) { - if(!DD_GameLoaded()) return; + if(!App_GameLoaded()) return; Con_Executef(CMDS_DDAY, false, "defaultgamebindings"); } diff --git a/doomsday/client/src/ui/dd_input.cpp b/doomsday/client/src/ui/dd_input.cpp index 31e9aab150..5000b25a6f 100644 --- a/doomsday/client/src/ui/dd_input.cpp +++ b/doomsday/client/src/ui/dd_input.cpp @@ -1082,7 +1082,7 @@ static void updateDeviceAxes(timespan_t ticLength) */ static void dispatchEvents(eventqueue_t* q, timespan_t ticLength, boolean updateAxes) { - const boolean callGameResponders = DD_GameLoaded(); + const boolean callGameResponders = App_GameLoaded(); ddevent_t* ddev; while((ddev = nextFromQueue(q))) diff --git a/doomsday/client/src/ui/finaleinterpreter.cpp b/doomsday/client/src/ui/finaleinterpreter.cpp index e0d035f8e5..a7c22800a9 100644 --- a/doomsday/client/src/ui/finaleinterpreter.cpp +++ b/doomsday/client/src/ui/finaleinterpreter.cpp @@ -1483,7 +1483,7 @@ DEFFC(If) } else if(!strnicmp(token, "mode:", 5)) { - if(DD_GameLoaded()) + if(App_GameLoaded()) val = !stricmp(token + 5, Str_Text(App_CurrentGame().identityKey())); else val = 0; diff --git a/doomsday/client/src/ui/window.cpp b/doomsday/client/src/ui/window.cpp index 8cdbc9bd1b..b7229ae641 100644 --- a/doomsday/client/src/ui/window.cpp +++ b/doomsday/client/src/ui/window.cpp @@ -607,7 +607,7 @@ struct ddwindow_s #ifdef __CLIENT__ // Update viewports. R_SetViewGrid(0, 0); - if(BusyMode_Active() || UI_IsActive() || !DD_GameLoaded()) + if(BusyMode_Active() || UI_IsActive() || !App_GameLoaded()) { // Update for busy mode. R_UseViewPort(0); @@ -859,7 +859,7 @@ static boolean setDDWindow(Window *window, int newWidth, int newHeight, hadFog = usingFog; GL_TotalReset(); - if(DD_GameLoaded() && gx.UpdateState) + if(App_GameLoaded() && gx.UpdateState) gx.UpdateState(DD_RENDER_RESTART_PRE); R_UnloadSvgs(); @@ -882,7 +882,7 @@ static boolean setDDWindow(Window *window, int newWidth, int newHeight, if(hadFog) GL_UseFog(true); - if(DD_GameLoaded() && gx.UpdateState) + if(App_GameLoaded() && gx.UpdateState) gx.UpdateState(DD_RENDER_RESTART_POST); } #endif diff --git a/doomsday/client/src/uri.cpp b/doomsday/client/src/uri.cpp index a5f5ecd413..adf0f2fab9 100644 --- a/doomsday/client/src/uri.cpp +++ b/doomsday/client/src/uri.cpp @@ -137,18 +137,17 @@ struct Uri::Instance } else if(!symbol.compare("Game.IdentityKey", Qt::CaseInsensitive)) { - de::Game &game = App_CurrentGame(); - if(de::isNullGame(game)) + if(!App_GameLoaded()) { /// @throw ResolveSymbolError An unresolveable symbol was encountered. throw ResolveSymbolError("Uri::resolveSymbol", "Symbol 'Game' did not resolve (no game loaded)"); } - return Str_Text(game.identityKey()); + return Str_Text(App_CurrentGame().identityKey()); } else if(!symbol.compare("GamePlugin.Name", Qt::CaseInsensitive)) { - if(!DD_GameLoaded() || !gx.GetVariable) + if(!App_GameLoaded() || !gx.GetVariable) { /// @throw ResolveSymbolError An unresolveable symbol was encountered. throw ResolveSymbolError("Uri::resolveSymbol", "Symbol 'GamePlugin' did not resolve (no game plugin loaded)"); @@ -353,7 +352,7 @@ String Uri::resolved() const String const &Uri::resolvedRef() const { #ifndef LIBDENG_DISABLE_URI_RESOLVE_CACHING - if(d->resolvedForGame && d->resolvedForGame == (void *) &App_CurrentGame()) + if(d->resolvedForGame && d->resolvedForGame == (void *) (App_GameLoaded()? &App_CurrentGame() : 0)) { // We can just return the previously prepared resolved URI. return d->resolvedPath.toStringRef(); @@ -367,7 +366,7 @@ String const &Uri::resolvedRef() const DENG2_ASSERT(d->resolvedPath.separator() == QChar('/')); - d->resolvedForGame = (void *) &App_CurrentGame(); + d->resolvedForGame = (void *) (App_GameLoaded()? &App_CurrentGame() : 0); return d->resolvedPath.toStringRef(); } diff --git a/doomsday/server/src/shelluser.cpp b/doomsday/server/src/shelluser.cpp index 8ec71b297a..c1442eb065 100644 --- a/doomsday/server/src/shelluser.cpp +++ b/doomsday/server/src/shelluser.cpp @@ -101,7 +101,7 @@ void ShellUser::sendInitialUpdate() void ShellUser::sendGameState() { de::Game &game = App_CurrentGame(); - String mode = (!de::isNullGame(game)? Str_Text(game.identityKey()) : ""); + String mode = (App_GameLoaded()? Str_Text(game.identityKey()) : ""); /** * @todo The server is not the right place to compose a packet about