Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.cpp 3.2KB

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