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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "config.h"
  11. #include "main.h"
  12. #include "utils/time.h"
  13. OpenRaider *gOpenRaider = NULL;
  14. void cleanupHandler() {
  15. if (gOpenRaider)
  16. delete gOpenRaider;
  17. printf("\nThanks for testing %s\n", VERSION);
  18. printf("Build date: %s @ %s\n", __DATE__, __TIME__);
  19. printf("Build host: %s\n", BUILD_HOST);
  20. printf("Web site : http://github.com/xythobuz/OpenRaider\n");
  21. printf("Contact : xythobuz@xythobuz.de\n");
  22. }
  23. int main(int argc, char *argv[]) {
  24. const char *config = NULL;
  25. systemTimerReset();
  26. // Handle arguments
  27. if (argc == 1) {
  28. // Use default rc file path
  29. config = DEFAULT_CONFIG_PATH DEFAULT_CONFIG_FILE;
  30. } else if (argc == 2) {
  31. // Check for command line switches
  32. if ((strcmp("-h", argv[1]) == 0)
  33. || (strcmp("--help", argv[1]) == 0)) {
  34. // Display help text
  35. printf("%s [OPTIONS | /path/to/config]\n"
  36. "Options:\n"
  37. "\t--help\n\t-h\tDisplay this help text\n"
  38. "\t--version\n\t-v\tDisplay version information\n"
  39. "If no options are given, the default config will be loaded from:\n"
  40. "\t" DEFAULT_CONFIG_PATH DEFAULT_CONFIG_FILE "\n", argv[0]);
  41. return 0;
  42. } else if ((strcmp("-v", argv[1]) == 0)
  43. || (strcmp("--version", argv[1]) == 0)) {
  44. // Display version
  45. printf(VERSION "\n");
  46. return 0;
  47. } else {
  48. // Interpret as rc file name
  49. config = argv[1];
  50. }
  51. } else {
  52. printf("Usage:\n%s -h\n", argv[0]);
  53. return 1;
  54. }
  55. // Create globals
  56. atexit(cleanupHandler);
  57. printf("Initializing %s\n", VERSION);
  58. gOpenRaider = new OpenRaider();
  59. // Try to load a configuration
  60. if (gOpenRaider->loadConfig(config) != 0) {
  61. if (gOpenRaider->loadConfig(DEFAULT_CONFIG_PATH DEFAULT_CONFIG_FILE) != 0) {
  62. if (gOpenRaider->loadConfig(DEFAULT_CONFIG_FILE) != 0) {
  63. printf("Could not find a config file. Aborting...\n");
  64. return 2;
  65. }
  66. }
  67. }
  68. // Initialize the "subsystems"
  69. gOpenRaider->initialize();
  70. // Enter Main loop
  71. gOpenRaider->mConsole->print("Starting %s", VERSION);
  72. gOpenRaider->run();
  73. return 0;
  74. }