Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

main.cpp 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*!
  2. * \file src/main.cpp
  3. * \brief Where main() is
  4. *
  5. * \author xythobuz
  6. */
  7. #include <iostream>
  8. #include <memory>
  9. #include "global.h"
  10. #include "Camera.h"
  11. #include "Log.h"
  12. #include "Menu.h"
  13. #include "Render.h"
  14. #include "RunTime.h"
  15. #include "SoundManager.h"
  16. #include "TextureManager.h"
  17. #include "UI.h"
  18. #include "World.h"
  19. #include "commander/commander.h"
  20. #include "commands/Command.h"
  21. #include "system/Font.h"
  22. #include "system/Shader.h"
  23. #include "system/Sound.h"
  24. #include "system/Window.h"
  25. #include "utils/time.h"
  26. static std::string configFileToUse;
  27. static std::shared_ptr<World> gWorld;
  28. World& getWorld() {
  29. return *gWorld;
  30. }
  31. int main(int argc, char* argv[]) {
  32. command_t cmd;
  33. command_init(&cmd, argv[0], VERSION);
  34. command_option(&cmd, "-c", "--config <file>", "select config file to use",
  35. [](command_t* self) {
  36. configFileToUse = self->arg;
  37. });
  38. command_parse(&cmd, argc, argv);
  39. command_free(&cmd);
  40. // RunTime is required by other constructors
  41. RunTime::initialize();
  42. gWorld.reset(new World());
  43. Command::fillCommandList();
  44. Log::get(LOG_INFO) << "Initializing " << VERSION << Log::endl;
  45. // Initialize Windowing
  46. int error = Window::initialize();
  47. if (error != 0) {
  48. std::cout << "Could not initialize Window (" << error << ")!" << std::endl;
  49. return -1;
  50. }
  51. error = Shader::initialize();
  52. if (error != 0) {
  53. std::cout << "Could not initialize OpenGL (" << error << ")!" << std::endl;
  54. return -2;
  55. }
  56. // Initialize Texture Manager
  57. error = TextureManager::initialize();
  58. if (error != 0) {
  59. std::cout << "Could not initialize TextureManager (" << error << ")!" << std::endl;
  60. return -3;
  61. }
  62. if (configFileToUse == "") {
  63. if (Command::executeFile(DEFAULT_CONFIG_FILE) != 0) {
  64. if (Command::executeFile(std::string(DEFAULT_CONFIG_PATH) + "/" + DEFAULT_CONFIG_FILE) != 0) {
  65. std::string p = INSTALL_PREFIX;
  66. if (p != "/")
  67. p += "/";
  68. p += "share/OpenRaider/";
  69. Command::executeFile(p + DEFAULT_CONFIG_FILE);
  70. }
  71. }
  72. } else {
  73. Command::executeFile(configFileToUse);
  74. }
  75. error = TextureManager::initializeSplash();
  76. if (error != 0) {
  77. std::cout << "Coult not load Splash Texture (" << error << ")!" << std::endl;
  78. return -4;
  79. }
  80. // Initialize Sound
  81. error = Sound::initialize();
  82. if (error != 0) {
  83. std::cout << "Could not initialize Sound (" << error << ")!" << std::endl;
  84. return -5;
  85. }
  86. // Initialize Debug UI
  87. error = UI::initialize();
  88. if (error != 0) {
  89. std::cout << "Could not initialize Debug UI (" << error << ")!" << std::endl;
  90. return -6;
  91. }
  92. // Initialize Menu
  93. error = Menu::initialize();
  94. if (error != 0) {
  95. std::cout << "Could not initialize Menu (" << error << ")!" << std::endl;
  96. return -7;
  97. }
  98. Log::get(LOG_INFO) << "Starting " << VERSION << Log::endl;
  99. Camera::setSize(Window::getSize());
  100. Menu::setVisible(true);
  101. systemTimerReset();
  102. RunTime::setRunning(true);
  103. Render::setMode(RenderMode::LoadScreen);
  104. while (RunTime::isRunning()) {
  105. Window::eventHandling();
  106. renderFrame();
  107. }
  108. Menu::shutdown();
  109. UI::shutdown();
  110. Font::shutdown();
  111. Sound::shutdown();
  112. Shader::shutdown();
  113. Window::shutdown();
  114. #ifdef DEBUG
  115. std::cout << std::endl;
  116. std::cout << "Thanks for testing " << VERSION << std::endl;
  117. std::cout << "Build date: " << __DATE__ << " @ " << __TIME__ << std::endl;
  118. std::cout << "Build host: " << BUILD_HOST << std::endl;
  119. std::cout << "Web site : http://github.com/xythobuz/OpenRaider" << std::endl;
  120. std::cout << "Contact : xythobuz@xythobuz.de" << std::endl;
  121. #endif
  122. return 0;
  123. }
  124. void renderFrame() {
  125. Render::display();
  126. UI::display();
  127. Window::swapBuffers();
  128. RunTime::updateFPS();
  129. }
  130. #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
  131. #ifndef NODEBUG
  132. #include <exception>
  133. #include <execinfo.h>
  134. [[noreturn]] static void terminateHandler();
  135. static std::terminate_handler oldTerminateHandler = std::set_terminate(terminateHandler);
  136. [[noreturn]] static void terminateHandler() {
  137. const unsigned int maxSize = 128;
  138. void* callstack[maxSize];
  139. int frames = backtrace(callstack, maxSize);
  140. char** strs = backtrace_symbols(callstack, frames);
  141. std::cout << std::endl;
  142. for (int i = frames; i > 0; i++)
  143. std::cout << strs[i - 1] << std::endl;
  144. delete [] strs;
  145. oldTerminateHandler();
  146. abort();
  147. }
  148. #endif // NODEBUG
  149. #endif // HAVE_EXECINFO_H && HAVE_BACKTRACE && HAVE_BACKTRACE_SYMBOLS