Skip to content

Commit

Permalink
Refactor: Use App_GameLoaded() to determine if a game is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Feb 12, 2013
1 parent 3984314 commit 6e54aa9
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 55 deletions.
2 changes: 1 addition & 1 deletion doomsday/client/include/dd_main.h
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/con_config.cpp
Expand Up @@ -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",
Expand Down Expand Up @@ -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));
}

Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/src/con_main.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/dd_loop.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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);
}
Expand Down
36 changes: 18 additions & 18 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
Expand Down Expand Up @@ -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?
Expand All @@ -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());
}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/dd_pinit.cpp
Expand Up @@ -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()));
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/def_main.cpp
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/def_read.cpp
Expand Up @@ -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()));
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/map/dam_main.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/network/ui_mpi.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_console.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_particle.cpp
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/resource/zip.cpp
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/sys_system.cpp
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/b_main.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/dd_input.cpp
Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/finaleinterpreter.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 6e54aa9

Please sign in to comment.