Open Source Tomb Raider Engine
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

main.cpp 4.8KB

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