From 4a065932c456da9074ecbc8efbf8cadffbc770e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= Date: Fri, 3 Jan 2014 20:29:20 +0200 Subject: [PATCH] Refactor|Client|Server|libgui: Checking for existence of singletons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Renamed methods that check for singleton existence to “somethingExists()”. Also don’t have redundant methods in ClientApp and ServerApp for this purpose. --- doomsday/client/include/clientapp.h | 1 - doomsday/client/src/busymode.cpp | 2 +- doomsday/client/src/clientapp.cpp | 7 +---- doomsday/client/src/dd_main.cpp | 30 ++++++------------- doomsday/client/src/gl/gl_main.cpp | 2 +- doomsday/client/src/render/vr.cpp | 2 +- doomsday/libgui/include/de/gui/canvaswindow.h | 2 +- doomsday/libgui/src/canvaswindow.cpp | 2 +- .../libgui/src/persistentcanvaswindow.cpp | 6 ++-- doomsday/server/include/serverapp.h | 1 - doomsday/server/src/serverapp.cpp | 5 ---- doomsday/server/src/serversystem.cpp | 2 +- 12 files changed, 19 insertions(+), 43 deletions(-) diff --git a/doomsday/client/include/clientapp.h b/doomsday/client/include/clientapp.h index 8e610688f8..3b8c8fbe0a 100644 --- a/doomsday/client/include/clientapp.h +++ b/doomsday/client/include/clientapp.h @@ -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. diff --git a/doomsday/client/src/busymode.cpp b/doomsday/client/src/busymode.cpp index 7948e6ee89..bfce8eb7b9 100644 --- a/doomsday/client/src/busymode.cpp +++ b/doomsday/client/src/busymode.cpp @@ -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(); } diff --git a/doomsday/client/src/clientapp.cpp b/doomsday/client/src/clientapp.cpp index 61a8fbfd3f..3a14b0117e 100644 --- a/doomsday/client/src/clientapp.cpp +++ b/doomsday/client/src/clientapp.cpp @@ -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 : @@ -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); diff --git a/doomsday/client/src/dd_main.cpp b/doomsday/client/src/dd_main.cpp index 052b146c2b..a20155613f 100644 --- a/doomsday/client/src/dd_main.cpp +++ b/doomsday/client/src/dd_main.cpp @@ -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"); } @@ -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(); } @@ -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"); diff --git a/doomsday/client/src/gl/gl_main.cpp b/doomsday/client/src/gl/gl_main.cpp index 7568a72643..7d4b853c7f 100644 --- a/doomsday/client/src/gl/gl_main.cpp +++ b/doomsday/client/src/gl/gl_main.cpp @@ -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(); diff --git a/doomsday/client/src/render/vr.cpp b/doomsday/client/src/render/vr.cpp index e5200c7777..c9fbd0c5bb 100644 --- a/doomsday/client/src/render/vr.cpp +++ b/doomsday/client/src/render/vr.cpp @@ -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(); diff --git a/doomsday/libgui/include/de/gui/canvaswindow.h b/doomsday/libgui/include/de/gui/canvaswindow.h index 46af21aa15..d4fc2e8492 100644 --- a/doomsday/libgui/include/de/gui/canvaswindow.h +++ b/doomsday/libgui/include/de/gui/canvaswindow.h @@ -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); diff --git a/doomsday/libgui/src/canvaswindow.cpp b/doomsday/libgui/src/canvaswindow.cpp index 85efada32a..0e67ca2216 100644 --- a/doomsday/libgui/src/canvaswindow.cpp +++ b/doomsday/libgui/src/canvaswindow.cpp @@ -267,7 +267,7 @@ void *CanvasWindow::nativeHandle() const return reinterpret_cast(winId()); } -bool CanvasWindow::hasMain() +bool CanvasWindow::mainExists() { return mainWindow != 0; } diff --git a/doomsday/libgui/src/persistentcanvaswindow.cpp b/doomsday/libgui/src/persistentcanvaswindow.cpp index 61f00f0ed7..76a665a617 100644 --- a/doomsday/libgui/src/persistentcanvaswindow.cpp +++ b/doomsday/libgui/src/persistentcanvaswindow.cpp @@ -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); } @@ -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 + "\""); diff --git a/doomsday/server/include/serverapp.h b/doomsday/server/include/serverapp.h index 94f9f9ed43..ea5e87c435 100644 --- a/doomsday/server/include/serverapp.h +++ b/doomsday/server/include/serverapp.h @@ -42,7 +42,6 @@ class ServerApp : public de::TextApp void initialize(); public: - static bool haveApp(); static ServerApp &app(); static ServerSystem &serverSystem(); static ResourceSystem &resourceSystem(); diff --git a/doomsday/server/src/serverapp.cpp b/doomsday/server/src/serverapp.cpp index 9859f74e16..32f5466512 100644 --- a/doomsday/server/src/serverapp.cpp +++ b/doomsday/server/src/serverapp.cpp @@ -171,11 +171,6 @@ void ServerApp::initialize() DD_FinishInitializationAfterWindowReady(); } -bool ServerApp::haveApp() -{ - return serverAppSingleton != 0; -} - ServerApp &ServerApp::app() { DENG2_ASSERT(serverAppSingleton != 0); diff --git a/doomsday/server/src/serversystem.cpp b/doomsday/server/src/serversystem.cpp index 414e0b1897..90a145f14c 100644 --- a/doomsday/server/src/serversystem.cpp +++ b/doomsday/server/src/serversystem.cpp @@ -117,7 +117,7 @@ DENG2_PIMPL(ServerSystem) if(!inited) return; inited = false; - if(ServerApp::haveApp()) + if(ServerApp::appExists()) { App_World().audienceForMapChange -= shellUsers; }