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

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