diff options
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/app.cpp | 66 | ||||
-rw-r--r-- | src/app/app.h | 9 | ||||
-rw-r--r-- | src/app/main.cpp | 17 |
3 files changed, 61 insertions, 31 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp index b73adee..6a71f64 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -20,6 +20,7 @@ #include "app/app.h" #include "app/system.h" +#include "common/logger.h" #include "common/iman.h" #include "graphics/opengl/gldevice.h" @@ -153,6 +154,7 @@ bool CApplication::Create() { SystemDialog(SDT_ERROR, "COLOBOT - Error", std::string("Error in CEngine::BeforeCreateInit() :\n") + std::string(m_engine->GetError()) ); + m_exitCode = 1; return false; } @@ -173,6 +175,15 @@ bool CApplication::Create() { SystemDialog( SDT_ERROR, "COLOBOT - Error", "SDL initialization error:\n" + std::string(SDL_GetError()) ); + m_exitCode = 2; + return false; + } + + if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) == 0) + { + SystemDialog( SDT_ERROR, "COLOBOT - Error", std::string("SDL_Image initialization error:\n") + + std::string(IMG_GetError()) ); + m_exitCode = 3; return false; } @@ -181,6 +192,7 @@ bool CApplication::Create() { SystemDialog( SDT_ERROR, "COLOBOT - Error", "SDL error while getting video info:\n " + std::string(SDL_GetError()) ); + m_exitCode = 2; return false; } @@ -219,13 +231,6 @@ bool CApplication::Create() if (m_private->deviceConfig.hardwareAccel) SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); - if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) == 0) - { - SystemDialog( SDT_ERROR, "COLOBOT - Error", std::string("SDL_Image initialization error:\n") + - std::string(IMG_GetError()) ); - return false; - } - m_private->surface = SDL_SetVideoMode(m_private->deviceConfig.width, m_private->deviceConfig.height, m_private->deviceConfig.bpp, videoFlags); @@ -233,6 +238,7 @@ bool CApplication::Create() { SystemDialog( SDT_ERROR, "COLOBT - Error", std::string("SDL error while setting video mode:\n") + std::string(SDL_GetError()) ); + m_exitCode = 2; return false; } @@ -255,6 +261,7 @@ bool CApplication::Create() { SystemDialog( SDT_ERROR, "COLOBT - Error", std::string("Error in CDevice::Create() :\n") + std::string(m_device->GetError()) ); + m_exitCode = 1; return false; } @@ -263,6 +270,7 @@ bool CApplication::Create() { SystemDialog( SDT_ERROR, "COLOBT - Error", std::string("Error in CEngine::Create() :\n") + std::string(m_engine->GetError()) ); + m_exitCode = 1; return false; } @@ -270,6 +278,7 @@ bool CApplication::Create() { SystemDialog( SDT_ERROR, "COLOBT - Error", std::string("Error in CEngine::AfterDeviceSetInit() :\n") + std::string(m_engine->GetError()) ); + m_exitCode = 1; return false; } @@ -478,6 +487,11 @@ end: return m_exitCode; } +int CApplication::GetExitCode() +{ + return m_exitCode; +} + //! Translates SDL press state to PressState PressState TranslatePressState(unsigned char state) { @@ -499,7 +513,6 @@ Math::Point CApplication::WindowToInterfaceCoords(int x, int y) 1.0f - (float)y / (float)m_private->deviceConfig.height); } - void CApplication::ParseEvent() { Event event; @@ -567,6 +580,7 @@ void CApplication::ParseEvent() void CApplication::ProcessEvent(Event event) { + CLogger *l = GetLogger(); // Print the events in debug mode to test the code if (m_debugMode) { @@ -574,34 +588,34 @@ void CApplication::ProcessEvent(Event event) { case EVENT_KEY_DOWN: case EVENT_KEY_UP: - printf("EVENT_KEY_%s:\n", (event.type == EVENT_KEY_DOWN) ? "DOWN" : "UP"); - printf(" key = %4x\n", event.key.key); - printf(" state = %s\n", (event.key.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED"); - printf(" mod = %4x\n", event.key.mod); - printf(" unicode = %4x\n", event.key.unicode); + l->Info("EVENT_KEY_%s:\n", (event.type == EVENT_KEY_DOWN) ? "DOWN" : "UP"); + l->Info(" key = %4x\n", event.key.key); + l->Info(" state = %s\n", (event.key.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED"); + l->Info(" mod = %4x\n", event.key.mod); + l->Info(" unicode = %4x\n", event.key.unicode); break; case EVENT_MOUSE_MOVE: - printf("EVENT_MOUSE_MOVE:\n"); - printf(" state = %s\n", (event.mouseMove.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED"); - printf(" pos = (%f, %f)\n", event.mouseMove.pos.x, event.mouseMove.pos.y); + l->Info("EVENT_MOUSE_MOVE:\n"); + l->Info(" state = %s\n", (event.mouseMove.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED"); + l->Info(" pos = (%f, %f)\n", event.mouseMove.pos.x, event.mouseMove.pos.y); break; case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_BUTTON_UP: - printf("EVENT_MOUSE_BUTTON_%s:\n", (event.type == EVENT_MOUSE_BUTTON_DOWN) ? "DOWN" : "UP"); - printf(" button = %d\n", event.mouseButton.button); - printf(" state = %s\n", (event.mouseButton.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED"); - printf(" pos = (%f, %f)\n", event.mouseButton.pos.x, event.mouseButton.pos.y); + l->Info("EVENT_MOUSE_BUTTON_%s:\n", (event.type == EVENT_MOUSE_BUTTON_DOWN) ? "DOWN" : "UP"); + l->Info(" button = %d\n", event.mouseButton.button); + l->Info(" state = %s\n", (event.mouseButton.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED"); + l->Info(" pos = (%f, %f)\n", event.mouseButton.pos.x, event.mouseButton.pos.y); break; case EVENT_JOY_AXIS: - printf("EVENT_JOY_AXIS:\n"); - printf(" axis = %d\n", event.joyAxis.axis); - printf(" value = %d\n", event.joyAxis.value); + l->Info("EVENT_JOY_AXIS:\n"); + l->Info(" axis = %d\n", event.joyAxis.axis); + l->Info(" value = %d\n", event.joyAxis.value); break; case EVENT_JOY_BUTTON_DOWN: case EVENT_JOY_BUTTON_UP: - printf("EVENT_JOY_BUTTON_%s:\n", (event.type == EVENT_JOY_BUTTON_DOWN) ? "DOWN" : "UP"); - printf(" button = %d\n", event.joyButton.button); - printf(" state = %s\n", (event.joyButton.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED"); + l->Info("EVENT_JOY_BUTTON_%s:\n", (event.type == EVENT_JOY_BUTTON_DOWN) ? "DOWN" : "UP"); + l->Info(" button = %d\n", event.joyButton.button); + l->Info(" state = %s\n", (event.joyButton.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED"); break; default: break; diff --git a/src/app/app.h b/src/app/app.h index 098f0ad..ed2bd9a 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -84,10 +84,13 @@ public: Error ParseArguments(int argc, char *argv[]); //! Initializes the application bool Create(); - //! Cleans up before exit - void Destroy(); //! Main event loop int Run(); + //! Returns the code to be returned at main() exit + int GetExitCode(); + + //! Cleans up before exit + void Destroy(); //! Enters the pause mode void Pause(bool pause); @@ -96,7 +99,7 @@ public: void StepSimulation(float rTime); //! Polls the state of joystick axes and buttons - void UpdateJoystick(); + void UpdateJoystick(); void SetShowStat(bool show); bool GetShowStat(); diff --git a/src/app/main.cpp b/src/app/main.cpp index 1e102d7..ece18d3 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -19,6 +19,7 @@ #include "app/app.h" #include "app/system.h" +#include "common/logger.h" #include "common/misc.h" #include "common/restext.h" @@ -26,6 +27,10 @@ //! Entry point to the program int main(int argc, char *argv[]) { + CLogger logger; // Create the logger + + logger.Info("Colobot starting\n"); + CApplication app; // single instance of the application Error err = app.ParseArguments(argc, argv); @@ -34,11 +39,19 @@ int main(int argc, char *argv[]) SystemDialog(SDT_ERROR, "COLOBOT", "Invalid commandline arguments!\n"); } + int code = 0; + if (! app.Create()) { app.Destroy(); // ensure a clean exit - return 1; + code = app.GetExitCode(); + logger.Info("Didn't run main loop. Exiting with code %d\n", code); + return code; } - return app.Run(); + code = app.Run(); + + logger.Info("Exiting with code %d\n", code); + return code; } + |