2017-11-05 02:33:15 +01:00
|
|
|
#define SDL_MAIN_HANDLED
|
2018-12-09 22:43:42 +01:00
|
|
|
|
2016-09-09 22:13:20 +02:00
|
|
|
#include <iostream>
|
2018-12-09 22:43:42 +01:00
|
|
|
|
2014-09-16 20:22:43 +02:00
|
|
|
#include "RWGame.hpp"
|
2018-02-27 23:25:05 +01:00
|
|
|
#include <SDL.h>
|
2013-07-01 02:22:29 +02:00
|
|
|
|
2016-10-15 02:39:15 +02:00
|
|
|
#include <core/Logger.hpp>
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
#include "RWConfig.hpp"
|
|
|
|
|
|
|
|
int main(int argc, const 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 });
|
|
|
|
|
2018-12-12 18:51:04 +01:00
|
|
|
RWArgumentParser argParser;
|
|
|
|
auto argLayerOpt = argParser.parseArguments(argc, argv);
|
|
|
|
if (!argLayerOpt.has_value()) {
|
|
|
|
argParser.printHelp(std::cerr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (argLayerOpt->help) {
|
|
|
|
argParser.printHelp(std::cout);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_SetMainReady();
|
|
|
|
|
2016-09-09 22:13:20 +02:00
|
|
|
try {
|
2018-12-12 18:51:04 +01:00
|
|
|
RWGame game(logger, argLayerOpt);
|
2013-07-01 02:22:29 +02:00
|
|
|
|
2016-09-09 22:13:20 +02:00
|
|
|
return game.run();
|
|
|
|
} 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.
|
2014-08-01 22:04:58 +02:00
|
|
|
|
2018-12-28 16:22:01 +01:00
|
|
|
static constexpr char const* kErrorTitle = "Fatal Error";
|
2016-08-24 23:13:07 +02:00
|
|
|
|
2016-10-15 02:39:15 +02:00
|
|
|
logger.error("exception", ex.what());
|
2016-08-24 23:13:07 +02:00
|
|
|
|
2016-09-09 22:13:20 +02:00
|
|
|
if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, kErrorTitle,
|
2018-02-18 01:22:03 +01:00
|
|
|
ex.what(), nullptr) < 0) {
|
2016-09-09 22:13:20 +02:00
|
|
|
SDL_Log("Failed to show message box\n");
|
|
|
|
}
|
2016-08-24 23:13:07 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2013-07-01 02:22:29 +02:00
|
|
|
}
|