Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.cpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*!
  2. * \file src/main.cpp
  3. * \brief Where main() is
  4. *
  5. * \author xythobuz
  6. */
  7. #include <iostream>
  8. #include "global.h"
  9. #include "Console.h"
  10. #include "Exception.h"
  11. #include "OpenRaider.h"
  12. #include "commander/commander.h"
  13. #ifndef UNIT_TEST
  14. namespace {
  15. bool configFileWasSpecified = false;
  16. void configFileCallback(command_t *self) {
  17. getOpenRaider().loadConfig(self->arg);
  18. configFileWasSpecified = true;
  19. }
  20. void cleanupHandler(void) {
  21. #ifdef DEBUG
  22. std::cout << std::endl;
  23. std::cout << "Thanks for testing " << VERSION << std::endl;
  24. std::cout << "Build date: " << __DATE__ << " @ " << __TIME__ << std::endl;
  25. std::cout << "Build host: " << BUILD_HOST << std::endl;
  26. std::cout << "Web site : http://github.com/xythobuz/OpenRaider" << std::endl;
  27. std::cout << "Contact : xythobuz@xythobuz.de" << std::endl;
  28. #endif
  29. }
  30. }
  31. int main(int argc, char* argv[]) {
  32. command_t cmd;
  33. command_init(&cmd, argv[0], VERSION);
  34. //command_option(&cmd, "-v", "--verbose", "enable verbose output", functionPointer);
  35. command_option(&cmd, "-c", "--config <file>", "select config file to use", configFileCallback);
  36. command_parse(&cmd, argc, argv);
  37. if (!configFileWasSpecified) {
  38. if (getOpenRaider().loadConfig(DEFAULT_CONFIG_FILE) != 0) {
  39. getOpenRaider().loadConfig(DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE);
  40. }
  41. }
  42. #ifdef DEBUG
  43. getConsole() << "Initializing " << VERSION << Console::endl;
  44. #endif
  45. atexit(cleanupHandler);
  46. int error = getOpenRaider().initialize();
  47. if (error != 0) {
  48. std::cout << "Could not initialize OpenRaider (" << error << ")!" << std::endl;
  49. return -1;
  50. }
  51. command_free(&cmd);
  52. getConsole() << "Starting " << VERSION << Console::endl;
  53. getOpenRaider().run();
  54. return 0;
  55. }
  56. #endif // UNIT_TEST
  57. #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
  58. #ifndef NDEBUG
  59. #include <exception>
  60. #include <execinfo.h>
  61. namespace {
  62. extern std::terminate_handler oldTerminateHandler;
  63. [[noreturn]] void terminateHandler() {
  64. const unsigned int maxSize = 128;
  65. void *callstack[maxSize];
  66. int frames = backtrace(callstack, maxSize);
  67. char **strs = backtrace_symbols(callstack, frames);
  68. std::cout << std::endl;
  69. for (int i = 0; i < frames; i++)
  70. std::cout << strs[i] << std::endl;
  71. delete [] strs;
  72. std::cout << std::endl << "Last custom Exception:" << std::endl;
  73. std::cout << " " << Exception::getLastException() << std::endl << std::endl;
  74. oldTerminateHandler();
  75. abort();
  76. }
  77. std::terminate_handler oldTerminateHandler = std::set_terminate(terminateHandler);
  78. }
  79. #endif // NDEBUG
  80. #endif // HAVE_EXECINFO_H && HAVE_BACKTRACE && HAVE_BACKTRACE_SYMBOLS