diff options
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/app.cpp | 12 | ||||
-rw-r--r-- | src/app/app.h | 7 | ||||
-rw-r--r-- | src/app/main.cpp | 62 |
3 files changed, 52 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<Math::IntPoint> &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; |