Open Source Tomb Raider Engine
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Script.cpp 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*!
  2. * \file test/Script.cpp
  3. * \brief Game script loader unit test
  4. *
  5. * \author xythobuz
  6. */
  7. #include <iostream>
  8. #include "global.h"
  9. #include "utils/strings.h"
  10. #include "Script.h"
  11. #define printStrings(cnt, acc, name) { \
  12. std::cout << name << " (" << cnt << ")" << std::endl; \
  13. for (unsigned int i = 0; i < cnt; i++) { \
  14. std::cout << " " << acc(i) << std::endl; \
  15. } \
  16. std::cout << std::endl; \
  17. }
  18. #define printStrings2D(c, cnt, acc, name) { \
  19. std::cout << name << " (" << c << "*" << cnt << ")" << std::endl; \
  20. for (unsigned int a = 0; a < cnt; a++) { \
  21. std::cout << " "; \
  22. for (unsigned int i = 0; i < c; i++) { \
  23. std::cout << acc(i, a); \
  24. if (i < (c - 1)) \
  25. std::cout << " | "; \
  26. } \
  27. std::cout << std::endl; \
  28. } \
  29. std::cout << std::endl; \
  30. }
  31. #define registerLambda(x, y) { \
  32. s.registerScriptHandler(x, [](bool hasOperand, uint16_t operand) { \
  33. std::cout << "\t" << y; \
  34. if (hasOperand) \
  35. std::cout << " (" << operand << ")"; \
  36. std::cout << std::endl; \
  37. return 0; \
  38. }); \
  39. }
  40. namespace {
  41. int test(const char *f, bool strings) {
  42. Script s;
  43. assertEqual(s.load(f), 0);
  44. if (strings) {
  45. printStrings(s.levelCount(), s.getLevelName, "Level Names");
  46. printStrings(s.levelCount(), s.getLevelFilename, "Level Filenames");
  47. printStrings(s.cutsceneCount(), s.getCutsceneFilename, "Cutscenes");
  48. printStrings(s.titleCount(), s.getTitleFilename, "Titles");
  49. printStrings(s.videoCount(), s.getVideoFilename, "Videos");
  50. printStrings(s.gameStringCount(), s.getGameString, "Game Strings");
  51. printStrings(s.pcStringCount(), s.getPCString, "PC Strings");
  52. printStrings2D(4, s.levelCount(), s.getPuzzleString, "Puzzles");
  53. printStrings2D(2, s.levelCount(), s.getPickupString, "Pickups");
  54. printStrings2D(4, s.levelCount(), s.getKeyString, "Keys");
  55. } else {
  56. registerLambda(Script::OP_PICTURE, "Picture");
  57. registerLambda(Script::OP_PSX_TRACK, "PSX-Track");
  58. registerLambda(Script::OP_PSX_FMV, "PSX-FMV");
  59. registerLambda(Script::OP_FMV, "Show FMV");
  60. registerLambda(Script::OP_GAME, "Load level");
  61. registerLambda(Script::OP_CUT, "Cutscene");
  62. registerLambda(Script::OP_COMPLETE, "Level finished");
  63. registerLambda(Script::OP_DEMO, "Demo sequence");
  64. registerLambda(Script::OP_PSX_DEMO, "PSX-Demo");
  65. registerLambda(Script::OP_END, "End of script");
  66. registerLambda(Script::OP_TRACK, "Sound Track");
  67. registerLambda(Script::OP_SUNSET, "Sunset");
  68. registerLambda(Script::OP_LOAD_PIC, "Load picture");
  69. registerLambda(Script::OP_DEADLY_WATER, "Deadly water");
  70. registerLambda(Script::OP_REMOVE_WEAPONS, "Remove weapons");
  71. registerLambda(Script::OP_GAMECOMPLETE, "End of game!");
  72. registerLambda(Script::OP_CUTANGLE, "Cutscene angle");
  73. registerLambda(Script::OP_NOFLOOR, "No floor, fall death");
  74. registerLambda(Script::OP_STARTINV, "Inventory/Bonus");
  75. registerLambda(Script::OP_STARTANIM, "Start animation");
  76. registerLambda(Script::OP_SECRETS, "Secrets");
  77. registerLambda(Script::OP_KILLTOCOMPLETE, "Kill to complete level");
  78. registerLambda(Script::OP_REMOVE_AMMO, "Remove ammo");
  79. for (unsigned int i = 0; i < (s.levelCount() + 1); i++) {
  80. if (i == 0)
  81. std::cout << "Script for Title:" << std::endl;
  82. else
  83. std::cout << "Script for \"" << s.getLevelName(i - 1) << "\" (" << i - 1 << "):" << std::endl;
  84. int error = s.runScript(i);
  85. if (error != 0)
  86. std::cout << "Returned " << error << "..." << std::endl;
  87. std::cout << std::endl;
  88. }
  89. }
  90. return 0;
  91. }
  92. }
  93. int main(int argc, char *argv[]) {
  94. char *f = fullPath("~/.OpenRaider/paks/tr2/TOMBPC.DAT", 0);
  95. int error = test(f, !((argc > 1) && (argv[1][0] == 's')));
  96. delete [] f;
  97. if (error != 0)
  98. return error;
  99. f = fullPath("~/.OpenRaider/paks/tr3/TOMBPC.DAT", 0);
  100. error = test(f, !((argc > 1) && (argv[1][0] == 's')));
  101. delete [] f;
  102. return error;
  103. }