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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*!
  2. * \file src/main.cpp
  3. * \brief Where main() is
  4. *
  5. * \author xythobuz
  6. */
  7. #include <cstdlib>
  8. #include <cstdio>
  9. #include <cstring>
  10. #include <assert.h>
  11. #include "config.h"
  12. #include "main.h"
  13. #include "utils/time.h"
  14. #ifdef USING_AL
  15. #include "SoundAL.h"
  16. #else
  17. #error No Sound Library selected!
  18. #endif
  19. #ifdef USING_SDL
  20. #include "WindowSDL.h"
  21. #else
  22. #error No Windowing Library selected!
  23. #endif
  24. Camera gCamera;
  25. Console gConsole;
  26. Game gGame;
  27. Menu gMenu;
  28. OpenRaider gOpenRaider;
  29. Render gRender;
  30. World gWorld;
  31. #ifdef USING_AL
  32. SoundAL gSound;
  33. #endif
  34. #ifdef USING_SDL
  35. WindowSDL gWindow;
  36. #endif
  37. Camera &getCamera() {
  38. return gCamera;
  39. }
  40. Console &getConsole() {
  41. return gConsole;
  42. }
  43. Game &getGame() {
  44. return gGame;
  45. }
  46. Menu &getMenu() {
  47. return gMenu;
  48. }
  49. OpenRaider &getOpenRaider() {
  50. return gOpenRaider;
  51. }
  52. Render &getRender() {
  53. return gRender;
  54. }
  55. Sound &getSound() {
  56. return gSound;
  57. }
  58. Window &getWindow() {
  59. return gWindow;
  60. }
  61. World &getWorld() {
  62. return gWorld;
  63. }
  64. void cleanupHandler(void) {
  65. #ifdef DEBUG
  66. printf("\nThanks for testing %s\n", VERSION);
  67. printf("Build date: %s @ %s\n", __DATE__, __TIME__);
  68. printf("Build host: %s\n", BUILD_HOST);
  69. printf("Web site : http://github.com/xythobuz/OpenRaider\n");
  70. printf("Contact : xythobuz@xythobuz.de\n");
  71. #endif
  72. }
  73. int main(int argc, char *argv[]) {
  74. const char *config = NULL;
  75. // Handle arguments
  76. if (argc == 1) {
  77. // Use default rc file path
  78. config = DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE;
  79. } else if (argc == 2) {
  80. // Check for command line switches
  81. if ((strcmp("-h", argv[1]) == 0)
  82. || (strcmp("--help", argv[1]) == 0)) {
  83. // Display help text
  84. printf("%s [OPTIONS | /path/to/config]\n"
  85. "Options:\n"
  86. "\t--help\n\t-h\tDisplay this help text\n"
  87. "\t--version\n\t-v\tDisplay version information\n"
  88. "If no options are given, the default config will be loaded from:\n"
  89. "\t" DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE "\n", argv[0]);
  90. return 0;
  91. } else if ((strcmp("-v", argv[1]) == 0)
  92. || (strcmp("--version", argv[1]) == 0)) {
  93. // Display version
  94. printf(VERSION "\n");
  95. return 0;
  96. } else {
  97. // Interpret as rc file name
  98. config = argv[1];
  99. }
  100. } else {
  101. printf("Usage:\n%s -h\n", argv[0]);
  102. return 1;
  103. }
  104. #ifdef DEBUG
  105. printf("Initializing %s\n", VERSION);
  106. #endif
  107. atexit(cleanupHandler);
  108. // Try to load a configuration
  109. if (gOpenRaider.loadConfig(config) != 0) {
  110. if (gOpenRaider.loadConfig(DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE) != 0) {
  111. if (gOpenRaider.loadConfig(DEFAULT_CONFIG_FILE) != 0) {
  112. printf("Could not find a config file. Aborting...\n");
  113. return 2;
  114. }
  115. }
  116. }
  117. // Initialize everything
  118. int error = gOpenRaider.initialize();
  119. if (error != 0) {
  120. printf("Could not initialize OpenRaider (%d)!\n", error);
  121. return 3;
  122. }
  123. // Enter Main loop
  124. gConsole.print("Starting %s", VERSION);
  125. gOpenRaider.run();
  126. return 0;
  127. }