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.

Loader.cpp 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*!
  2. * \file test/Loader.cpp
  3. * \brief Level Loader Unit Test
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "loader/Loader.h"
  9. int main(int argc, char* argv[]) {
  10. if (argc != 2) {
  11. std::cout << "Usage:" << std::endl;
  12. std::cout << "\t" << argv[0] << " /path/to/level.tr2" << std::endl;
  13. return 0; // Don't fail when just running this test...
  14. }
  15. // Print file engine version
  16. std::cout << "Loading \"" << argv[1] << "\"" << std::endl;
  17. std::cout << "Trying to detect engine version... ";
  18. Loader::LoaderVersion v = Loader::checkFile(argv[1]);
  19. switch (v) {
  20. case Loader::TR_1:
  21. std::cout << "TR 1";
  22. break;
  23. case Loader::TR_2:
  24. std::cout << "TR 2";
  25. break;
  26. case Loader::TR_3:
  27. std::cout << "TR 3";
  28. break;
  29. case Loader::TR_4:
  30. std::cout << "TR 4";
  31. break;
  32. case Loader::TR_5:
  33. std::cout << "TR 5";
  34. break;
  35. case Loader::TR_UNKNOWN:
  36. std::cout << "Unknown version!" << std::endl;
  37. return 2;
  38. }
  39. std::cout << " detected!" << std::endl;
  40. // Create matching loader
  41. std::cout << std::endl << "Creating level loader... ";
  42. std::unique_ptr<Loader> loader = Loader::createLoader(argv[1]);
  43. if (!loader) {
  44. std::cout << "Failed!" << std::endl;
  45. return 3;
  46. } else {
  47. std::cout << "Success!" << std::endl;
  48. }
  49. // Try to load the level
  50. std::cout << "Trying to load level... ";
  51. int error = loader->load(argv[1]);
  52. if (error != 0) {
  53. std::cout << "Failure!" << std::endl;
  54. std::cout << "Error code: " << error << std::endl;
  55. } else {
  56. std::cout << "Success!" << std::endl;
  57. }
  58. return error;
  59. }