Skip to content

Commit

Permalink
Refactor|Client|Server|libgui: Checking for existence of singletons
Browse files Browse the repository at this point in the history
Renamed methods that check for singleton existence to
“somethingExists()”. Also don’t have redundant methods in ClientApp
and ServerApp for this purpose.
  • Loading branch information
skyjake committed Jan 3, 2014
1 parent 756d02e commit 4a06593
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 43 deletions.
1 change: 0 additions & 1 deletion doomsday/client/include/clientapp.h
Expand Up @@ -62,7 +62,6 @@ class ClientApp : public de::GuiApp
static void alert(de::String const &msg, de::LogEntry::Level level = de::LogEntry::MESSAGE);

public:
static bool haveApp();
static ClientApp &app();
static Updater &updater();
static SettingsRegister &audioSettings(); ///< @todo Belongs in AudioSystem.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/busymode.cpp
Expand Up @@ -248,7 +248,7 @@ void BusyMode_FreezeGameForBusyMode(void)
{
#ifdef __CLIENT__
// This is only possible from the main thread.
if(ClientWindow::hasMain() && busyModeAllowed && de::App::inMainThread())
if(ClientWindow::mainExists() && busyModeAllowed && de::App::inMainThread())
{
ClientWindow::main().busy().renderTransitionFrame();
}
Expand Down
7 changes: 1 addition & 6 deletions doomsday/client/src/clientapp.cpp
Expand Up @@ -406,7 +406,7 @@ void ClientApp::postFrame()

void ClientApp::alert(String const &msg, LogEntry::Level level)
{
if(ClientWindow::hasMain())
if(ClientWindow::mainExists())
{
ClientWindow::main().alerts()
.newAlert(msg, level >= LogEntry::ERROR? AlertDialog::Major :
Expand All @@ -419,11 +419,6 @@ void ClientApp::alert(String const &msg, LogEntry::Level level)
*/
}

bool ClientApp::haveApp()
{
return clientAppSingleton != 0;
}

ClientApp &ClientApp::app()
{
DENG2_ASSERT(clientAppSingleton != 0);
Expand Down
30 changes: 9 additions & 21 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -454,19 +454,15 @@ void DD_CreateFileSystemSchemes()

ResourceSystem &App_ResourceSystem()
{
#ifdef __CLIENT__
if(ClientApp::haveApp())
if(App::appExists())
{
#ifdef __CLIENT__
return ClientApp::resourceSystem();
}
#endif

#ifdef __SERVER__
if(ServerApp::haveApp())
{
return ServerApp::resourceSystem();
}
#endif
}
throw Error("App_ResourceSystem", "App not yet initialized");
}

Expand Down Expand Up @@ -1112,30 +1108,22 @@ static int DD_ActivateGameWorker(void *context)

de::Games &App_Games()
{
#ifdef __CLIENT__
if(ClientApp::haveApp())
if(App::appExists())
{
#ifdef __CLIENT__
return ClientApp::games();
}
#endif

#ifdef __SERVER__
if(ServerApp::haveApp())
{
return ServerApp::games();
}
#endif
}
throw Error("App_Games", "App not yet initialized");
}

boolean App_GameLoaded()
{
#ifdef __CLIENT__
if(!ClientApp::haveApp()) return false;
#endif
#ifdef __SERVER__
if(!ServerApp::haveApp()) return false;
#endif
if(!App::appExists()) return false;

return !App_CurrentGame().isNull();
}

Expand Down Expand Up @@ -1262,7 +1250,7 @@ de::Game &App_CurrentGame()
bool App_ChangeGame(Game &game, bool allowReload)
{
#ifdef __CLIENT__
DENG_ASSERT(ClientWindow::hasMain());
DENG_ASSERT(ClientWindow::mainExists());
#endif

//LOG_AS("App_ChangeGame");
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -377,7 +377,7 @@ void GL_ShutdownRefresh()

void GL_Shutdown()
{
if(!initGLOk || !ClientWindow::hasMain())
if(!initGLOk || !ClientWindow::mainExists())
return; // Not yet initialized fully.

DENG_ASSERT_IN_MAIN_THREAD();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/vr.cpp
Expand Up @@ -118,7 +118,7 @@ static void vrLatencyChanged()
// see also rend_main.cpp
static void vrModeChanged()
{
if(ClientWindow::hasMain())
if(ClientWindow::mainExists())
{
// The logical UI size may need to be changed.
ClientWindow &win = ClientWindow::main();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libgui/include/de/gui/canvaswindow.h
Expand Up @@ -171,7 +171,7 @@ class LIBGUI_PUBLIC CanvasWindow : public QMainWindow,
void *nativeHandle() const;

public:
static bool hasMain();
static bool mainExists();
static CanvasWindow &main();
static void setMain(CanvasWindow *window);

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libgui/src/canvaswindow.cpp
Expand Up @@ -267,7 +267,7 @@ void *CanvasWindow::nativeHandle() const
return reinterpret_cast<void *>(winId());
}

bool CanvasWindow::hasMain()
bool CanvasWindow::mainExists()
{
return mainWindow != 0;
}
Expand Down
6 changes: 3 additions & 3 deletions doomsday/libgui/src/persistentcanvaswindow.cpp
Expand Up @@ -469,7 +469,7 @@ DENG2_PIMPL(PersistentCanvasWindow)
// Keep a global pointer to the main window.
if(id == MAIN_WINDOW_ID)
{
DENG2_ASSERT(!hasMain());
DENG2_ASSERT(!mainExists());
setMain(thisPublic);
}

Expand Down Expand Up @@ -877,8 +877,8 @@ String PersistentCanvasWindow::configName(String const &key) const

PersistentCanvasWindow &PersistentCanvasWindow::main()
{
DENG2_ASSERT(hasMain() != 0);
if(!hasMain())
DENG2_ASSERT(mainExists());
if(!mainExists())
{
throw InvalidIdError("PersistentCanvasWindow::main",
"No window found with id \"" + MAIN_WINDOW_ID + "\"");
Expand Down
1 change: 0 additions & 1 deletion doomsday/server/include/serverapp.h
Expand Up @@ -42,7 +42,6 @@ class ServerApp : public de::TextApp
void initialize();

public:
static bool haveApp();
static ServerApp &app();
static ServerSystem &serverSystem();
static ResourceSystem &resourceSystem();
Expand Down
5 changes: 0 additions & 5 deletions doomsday/server/src/serverapp.cpp
Expand Up @@ -171,11 +171,6 @@ void ServerApp::initialize()
DD_FinishInitializationAfterWindowReady();
}

bool ServerApp::haveApp()
{
return serverAppSingleton != 0;
}

ServerApp &ServerApp::app()
{
DENG2_ASSERT(serverAppSingleton != 0);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/server/src/serversystem.cpp
Expand Up @@ -117,7 +117,7 @@ DENG2_PIMPL(ServerSystem)
if(!inited) return;
inited = false;

if(ServerApp::haveApp())
if(ServerApp::appExists())
{
App_World().audienceForMapChange -= shellUsers;
}
Expand Down

0 comments on commit 4a06593

Please sign in to comment.