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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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/Shader.h"
  22. #include "system/Sound.h"
  23. #include "system/Window.h"
  24. #include "utils/time.h"
  25. #include <glbinding/Binding.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. glbinding::Binding::initialize();
  41. Log::initialize();
  42. RunTime::initialize(); // RunTime is required by other constructors
  43. gWorld.reset(new World());
  44. Command::fillCommandList();
  45. Log::get(LOG_INFO) << "Initializing " << VERSION << Log::endl;
  46. // Initialize Windowing
  47. int error = Window::initialize();
  48. if (error != 0) {
  49. std::cout << "Could not initialize Window (" << error << ")!" << std::endl;
  50. return -1;
  51. }
  52. error = Shader::initialize();
  53. if (error != 0) {
  54. std::cout << "Could not initialize OpenGL (" << error << ")!" << std::endl;
  55. return -2;
  56. }
  57. // Initialize Texture Manager
  58. error = TextureManager::initialize();
  59. if (error != 0) {
  60. std::cout << "Could not initialize TextureManager (" << error << ")!" << std::endl;
  61. return -3;
  62. }
  63. if (configFileToUse == "") {
  64. if (Command::executeFile(DEFAULT_CONFIG_FILE) != 0) {
  65. if (Command::executeFile(std::string(DEFAULT_CONFIG_PATH) + "/" + DEFAULT_CONFIG_FILE) != 0) {
  66. std::string p = INSTALL_PREFIX;
  67. if (p != "/")
  68. p += "/";
  69. p += "share/OpenRaider/";
  70. Command::executeFile(p + DEFAULT_CONFIG_FILE);
  71. }
  72. }
  73. } else {
  74. Command::executeFile(configFileToUse);
  75. }
  76. error = TextureManager::initializeSplash();
  77. if (error != 0) {
  78. std::cout << "Coult not load Splash Texture (" << error << ")!" << std::endl;
  79. return -4;
  80. }
  81. // Initialize Sound
  82. error = Sound::initialize();
  83. if (error != 0) {
  84. std::cout << "Could not initialize Sound (" << error << ")!" << std::endl;
  85. return -5;
  86. }
  87. // Initialize Debug UI
  88. error = UI::initialize();
  89. if (error != 0) {
  90. std::cout << "Could not initialize Debug UI (" << error << ")!" << std::endl;
  91. return -6;
  92. }
  93. // Initialize Menu
  94. error = Menu::initialize();
  95. if (error != 0) {
  96. std::cout << "Could not initialize Menu (" << error << ")!" << std::endl;
  97. return -7;
  98. }
  99. Log::get(LOG_INFO) << "Starting " << VERSION << Log::endl;
  100. Camera::setSize(Window::getSize());
  101. Menu::setVisible(true);
  102. systemTimerReset();
  103. RunTime::setRunning(true);
  104. Render::setMode(RenderMode::LoadScreen);
  105. while (RunTime::isRunning()) {
  106. Window::eventHandling();
  107. renderFrame();
  108. }
  109. Menu::shutdown();
  110. UI::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 NDEBUG
  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 // NDEBUG
  149. #endif // HAVE_EXECINFO_H && HAVE_BACKTRACE && HAVE_BACKTRACE_SYMBOLS