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.7KB

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