From 26376c652d59de271147027bb5c365b22c2765c2 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 25 Oct 2014 18:34:29 +0200 Subject: Nothing else works, so restart the game on resolution change Fixes #339 for now, but we'll need alternative solution later --- src/app/app.cpp | 12 ++++++++++ src/app/app.h | 7 ++++++ src/app/main.cpp | 62 +++++++++++++++++++++++++++------------------------ src/ui/maindialog.cpp | 7 ++++++ 4 files changed, 59 insertions(+), 29 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 1b53a28..ea54cf1 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -113,6 +113,7 @@ CApplication::CApplication() m_exitCode = 0; m_active = false; m_debugModes = 0; + m_restart = false; m_windowTitle = "COLOBOT: Gold Edition"; @@ -675,6 +676,17 @@ void CApplication::Destroy() SDL_Quit(); } +void CApplication::Restart() +{ + m_restart = true; + m_eventQueue->AddEvent(Event(EVENT_SYS_QUIT)); +} + +bool CApplication::IsRestarting() +{ + return m_restart; +} + bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig) { static bool restore = false; diff --git a/src/app/app.h b/src/app/app.h index c73cb53..500cb2f 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -227,6 +227,11 @@ public: //! Cleans up before exit void Destroy(); + + //! Restart + void Restart(); + //! Should we restart after app quits? + bool IsRestarting(); //! Returns a list of possible video modes VideoQueryResult GetVideoResolutionList(std::vector &resolutions, @@ -413,6 +418,8 @@ protected: bool m_active; //! Bit array of active debug modes long m_debugModes; + //! If we are restarting the app + bool m_restart; //! Message to be displayed as error to the user std::string m_errorMessage; diff --git a/src/app/main.cpp b/src/app/main.cpp index e30a83d..88a7a73 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -86,42 +86,46 @@ int SDL_MAIN_FUNC(int argc, char *argv[]) InitializeRestext(); InitializeEventTypeTexts(); - CSystemUtils* systemUtils = CSystemUtils::Create(); // platform-specific utils - systemUtils->Init(); - logger.Info("Colobot starting\n"); - - CApplication* app = new CApplication(); // single instance of the application - - ParseArgsStatus status = app->ParseArguments(argc, argv); - if (status == PARSE_ARGS_FAIL) - { - systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", "Invalid commandline arguments!\n"); - return app->GetExitCode(); - } - else if (status == PARSE_ARGS_HELP) - { - return app->GetExitCode(); - } - + int code = 0; + while(true) { + CSystemUtils* systemUtils = CSystemUtils::Create(); // platform-specific utils + systemUtils->Init(); + + CApplication* app = new CApplication(); // single instance of the application + + ParseArgsStatus status = app->ParseArguments(argc, argv); + if (status == PARSE_ARGS_FAIL) + { + systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", "Invalid commandline arguments!\n"); + return app->GetExitCode(); + } + else if (status == PARSE_ARGS_HELP) + { + return app->GetExitCode(); + } - if (! app->Create()) - { - app->Destroy(); // ensure a clean exit - code = app->GetExitCode(); - if ( code != 0 && !app->GetErrorMessage().empty() ) + + if (! app->Create()) { - systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", app->GetErrorMessage()); + app->Destroy(); // ensure a clean exit + code = app->GetExitCode(); + if ( code != 0 && !app->GetErrorMessage().empty() ) + { + systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", app->GetErrorMessage()); + } + logger.Info("Didn't run main loop. Exiting with code %d\n", code); + return code; } - logger.Info("Didn't run main loop. Exiting with code %d\n", code); - return code; - } - code = app->Run(); + code = app->Run(); + bool restarting = app->IsRestarting(); - delete app; - delete systemUtils; + delete app; + delete systemUtils; + if(!restarting) break; + } logger.Info("Exiting with code %d\n", code); return code; diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 0ab9085..ede7453 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -4677,7 +4677,13 @@ void CMainDialog::ChangeDisplay() bFull = pc->TestState(STATE_CHECK); m_setupFull = bFull; + SetupMemorize(); + #if !PLATFORM_LINUX + // Windows causes problems, so we'll restart the game + // Mac OS was not tested so let's restart just to be sure + m_app->Restart(); + #else std::vector modes; m_app->GetVideoResolutionList(modes, true, true); @@ -4685,6 +4691,7 @@ void CMainDialog::ChangeDisplay() config.size = modes[m_setupSelMode]; config.fullScreen = bFull; m_app->ChangeVideoConfig(config); + #endif } -- cgit v1.2.3-1-g7c22