1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-23 02:42:39 +01:00
openrw/rwgame/main.cpp

41 lines
1.2 KiB
C++
Raw Normal View History

2016-09-09 22:13:20 +02:00
#include <iostream>
#include "RWGame.hpp"
#include "SDL.h"
2016-10-15 02:39:15 +02:00
#include <core/Logger.hpp>
2016-09-09 22:13:20 +02:00
int main(int argc, char* argv[]) {
2016-10-15 02:39:15 +02:00
// Initialise Logging before anything else happens
2016-12-28 22:15:44 +01:00
StdOutReceiver logstdout;
2016-10-15 02:39:15 +02:00
Logger logger({ &logstdout });
2016-09-09 22:13:20 +02:00
try {
2016-10-15 02:39:15 +02:00
RWGame game(logger, argc, argv);
2016-09-09 22:13:20 +02:00
return game.run();
} catch (std::invalid_argument& ex) {
// This exception is thrown when either an invalid command line option
// or a --help is found. The RWGame constructor prints a usage message
// in this case and then throws this exception.
return -2;
} catch (std::runtime_error& ex) {
// Catch runtime_error as these are fatal issues the user may want to
// know about like corrupted files or GL initialisation failure.
// Catching other types (out_of_range, bad_alloc) would just make
// debugging them more difficult.
2016-09-09 22:13:20 +02:00
const char* kErrorTitle = "Fatal Error";
2016-10-15 02:39:15 +02:00
logger.error("exception", ex.what());
2016-09-09 22:13:20 +02:00
if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, kErrorTitle,
ex.what(), NULL) < 0) {
SDL_Log("Failed to show message box\n");
}
2016-09-09 22:13:20 +02:00
SDL_Quit();
2016-09-01 22:58:06 +02:00
2016-09-09 22:13:20 +02:00
return -1;
}
}