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.

LoaderTR2.cpp 42KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  1. /*!
  2. * \file src/loader/LoaderTR2.cpp
  3. * \brief TR2 level file loader
  4. *
  5. * \author xythobuz
  6. */
  7. #include <vector>
  8. #include <glm/glm.hpp>
  9. #include <glm/gtc/matrix_transform.hpp>
  10. #include "global.h"
  11. #include "Game.h"
  12. #include "Log.h"
  13. #include "Mesh.h"
  14. #include "Room.h"
  15. #include "SoundManager.h"
  16. #include "TextureManager.h"
  17. #include "World.h"
  18. #include "system/Sound.h"
  19. #include "utils/pixel.h"
  20. #include "loader/LoaderTR2.h"
  21. LoaderTR2::LoaderTR2() {
  22. }
  23. LoaderTR2::~LoaderTR2() {
  24. }
  25. int LoaderTR2::load(std::string f) {
  26. if (file.open(f) != 0) {
  27. return 1; // Could not open file
  28. }
  29. if (file.readU32() != 0x2D) {
  30. return 2; // Not a TR2 level?!
  31. }
  32. loadPaletteTextiles();
  33. file.seek(file.tell() + 4); // Unused value?
  34. loadRooms();
  35. loadFloorData();
  36. loadMeshes();
  37. loadMoveables();
  38. loadStaticMeshes();
  39. loadTextures();
  40. loadSprites();
  41. loadCameras();
  42. loadSoundSources();
  43. loadBoxesOverlapsZones();
  44. loadAnimatedTextures();
  45. loadItems();
  46. file.seek(file.tell() + 8192); // Skip Light map, only for 8bit coloring
  47. loadCinematicFrames();
  48. loadDemoData();
  49. loadSoundMap();
  50. loadSoundDetails();
  51. loadSampleIndices();
  52. loadExternalSoundFile(f);
  53. return 0; // TODO Not finished with implementation!
  54. }
  55. // ---- Textures ----
  56. void LoaderTR2::loadPaletteTextiles() {
  57. file.seek(file.tell() + 768); // Skip 8bit palette, 256 * 3 bytes
  58. // Read the 16bit palette, 256 * 4 bytes, RGBA, A unused
  59. for (auto& x : palette)
  60. x = file.readU32();
  61. uint32_t numTextiles = file.readU32();
  62. file.seek(file.tell() + (numTextiles * 256 * 256)); // Skip 8bit textiles
  63. // Read the 16bit textiles, numTextiles * 256 * 256 * 2 bytes
  64. for (unsigned int i = 0; i < numTextiles; i++) {
  65. std::array<uint8_t, 256 * 256 * 2> arr;
  66. for (auto& x : arr) {
  67. x = file.readU8();
  68. }
  69. // Convert 16bit textile to 32bit textile
  70. unsigned char* img = argb16to32(&arr[0], 256, 256);
  71. int r = getTextureManager().loadBufferSlot(img, 256, 256,
  72. TextureManager::ColorMode::ARGB, 32,
  73. TextureManager::TextureStorage::GAME, i);
  74. assert(r >= 0); //! \fixme properly handle error when texture could not be loaded!
  75. delete [] img;
  76. }
  77. if (numTextiles > 0)
  78. getLog() << "LoaderTR2: Found " << numTextiles << " Textures!" << Log::endl;
  79. else
  80. getLog() << "LoaderTR2: No Textures in this level?!" << Log::endl;
  81. }
  82. void LoaderTR2::loadTextures() {
  83. uint32_t numObjectTextures = file.readU32();
  84. for (unsigned int o = 0; o < numObjectTextures; o++) {
  85. // 0 means that a texture is all-opaque, and that transparency
  86. // information is ignored.
  87. // 1 means that transparency information is used. In 8-bit color,
  88. // index 0 is the transparent color, while in 16-bit color, the
  89. // top bit (0x8000) is the alpha channel (1 = opaque, 0 = transparent)
  90. uint16_t attribute = file.readU16();
  91. // Index into the textile list
  92. uint16_t tile = file.readU16();
  93. TextureTile* t = new TextureTile(attribute, tile);
  94. // The four corner vertices of the texture
  95. // The Pixel values are the actual coordinates of the vertexs pixel
  96. // The Coordinate values depend on where the other vertices are in
  97. // the object texture. And if the object texture is used to specify
  98. // a triangle, then the fourth vertexs values will all be zero
  99. // Coordinate is 1 if Pixel is the low val, 255 if high val in object texture
  100. for (int i = 0; i < 4; i++) {
  101. uint8_t xCoordinate = file.readU8();
  102. uint8_t xPixel = file.readU8();
  103. uint8_t yCoordinate = file.readU8();
  104. uint8_t yPixel = file.readU8();
  105. assert((xCoordinate == 1) || (xCoordinate == 255) || (xCoordinate == 0));
  106. assert((yCoordinate == 1) || (yCoordinate == 255) || (yCoordinate == 0));
  107. t->add(TextureTileVertex(xCoordinate, xPixel, yCoordinate, yPixel));
  108. }
  109. getTextureManager().addTile(t);
  110. }
  111. if (numObjectTextures > 0)
  112. getLog() << "LoaderTR2: Found " << numObjectTextures << " Textiles!" << Log::endl;
  113. else
  114. getLog() << "LoaderTR2: No Textiles in this level?!" << Log::endl;
  115. }
  116. void LoaderTR2::loadAnimatedTextures() {
  117. uint32_t numWords = file.readU32() - 1;
  118. uint16_t numAnimatedTextures = file.readU16();
  119. std::vector<uint16_t> animatedTextures;
  120. for (unsigned int a = 0; a < numWords; a++) {
  121. animatedTextures.push_back(file.readU16());
  122. }
  123. int pos = 0;
  124. for (unsigned int a = 0; a < numAnimatedTextures; a++) {
  125. int count = animatedTextures.at(pos) + 1;
  126. if ((pos + count) >= numWords) {
  127. getLog() << "LoaderTR2: Invalid AnimatedTextures ("
  128. << pos + count << " >= " << numWords << ")!" << Log::endl;
  129. return;
  130. }
  131. for (int i = 0; i < count; i++) {
  132. getTextureManager().addAnimatedTile(a, animatedTextures.at(pos + i + 1));
  133. }
  134. pos += count + 1;
  135. }
  136. if ((numAnimatedTextures > 0) || (numWords > 0))
  137. getLog() << "LoaderTR2: Found " << numAnimatedTextures << " Animated Textures!" << Log::endl;
  138. else
  139. getLog() << "LoaderTR2: No Animated Textures in this level?!" << Log::endl;
  140. if (pos != numWords)
  141. getLog() << "LoaderTR2: Extra bytes at end of AnimatedTextures?!" << Log::endl;
  142. }
  143. // ---- Rooms ----
  144. void LoaderTR2::loadRooms() {
  145. uint16_t numRooms = file.readU16();
  146. for (unsigned int i = 0; i < numRooms; i++) {
  147. // Room Header
  148. int32_t xOffset = file.read32();
  149. int32_t zOffset = file.read32();
  150. int32_t yBottom = file.read32(); // lowest point == largest y value
  151. int32_t yTop = file.read32(); // highest point == smallest y value
  152. glm::vec3 pos(xOffset, 0.0f, zOffset);
  153. // Number of data words (2 bytes) to follow
  154. uint32_t dataToFollow = file.readU32();
  155. glm::vec3 bbox[2] = {
  156. glm::vec3(0.0f, 0.0f, 0.0f),
  157. glm::vec3(0.0f, 0.0f, 0.0f)
  158. };
  159. uint16_t numVertices = file.readU16();
  160. std::vector<RoomVertexTR2> vertices;
  161. for (unsigned int v = 0; v < numVertices; v++) {
  162. RoomVertexTR2 vert;
  163. vert.x = file.read16();
  164. vert.y = file.read16();
  165. vert.z = file.read16();
  166. vert.light1 = file.read16();
  167. vert.attributes = file.readU16();
  168. vert.light2 = file.read16();
  169. vertices.push_back(vert);
  170. // Fill bounding box
  171. if (v == 0) {
  172. for (int i = 0; i < 2; i++) {
  173. bbox[i].x = vert.x;
  174. bbox[i].y = vert.y;
  175. bbox[i].z = vert.z;
  176. }
  177. } else {
  178. if (vert.x < bbox[0].x)
  179. bbox[0].x = vert.x;
  180. if (vert.x > bbox[1].x)
  181. bbox[1].x = vert.x;
  182. if (vert.y < bbox[0].y)
  183. bbox[0].y = vert.y;
  184. if (vert.y > bbox[1].y)
  185. bbox[1].y = vert.y;
  186. if (vert.z < bbox[0].z)
  187. bbox[0].z = vert.z;
  188. if (vert.z > bbox[1].z)
  189. bbox[1].z = vert.z;
  190. }
  191. }
  192. bbox[0] += pos;
  193. bbox[1] += pos;
  194. uint16_t numRectangles = file.readU16();
  195. std::vector<RoomRectangleTR2> rectangles;
  196. for (unsigned int r = 0; r < numRectangles; r++) {
  197. // Indices into the vertex list read just before
  198. uint16_t vertex1 = file.readU16();
  199. uint16_t vertex2 = file.readU16();
  200. uint16_t vertex3 = file.readU16();
  201. uint16_t vertex4 = file.readU16();
  202. // Index into the object-texture list
  203. uint16_t texture = file.readU16();
  204. rectangles.emplace_back(vertex1, vertex2, vertex3, vertex4, texture);
  205. }
  206. uint16_t numTriangles = file.readU16();
  207. std::vector<RoomTriangleTR2> triangles;
  208. for (unsigned int t = 0; t < numTriangles; t++) {
  209. // Indices into the room vertex list
  210. uint16_t vertex1 = file.readU16();
  211. uint16_t vertex2 = file.readU16();
  212. uint16_t vertex3 = file.readU16();
  213. // Index into the object-texture list
  214. uint16_t texture = file.readU16();
  215. triangles.emplace_back(vertex1, vertex2, vertex3, texture);
  216. }
  217. uint16_t numSprites = file.readU16();
  218. for (unsigned int s = 0; s < numSprites; s++) {
  219. uint16_t vertex = file.readU16(); // Index into vertex list
  220. uint16_t sprite = file.readU16(); // Index into sprite list
  221. // TODO store sprites somewhere
  222. }
  223. //room->addAdjacentRoom(i); // Always set room itself as first
  224. uint16_t numPortals = file.readU16();
  225. for (unsigned int p = 0; p < numPortals; p++) {
  226. // Which room this portal leads to
  227. uint16_t adjoiningRoom = file.readU16();
  228. // Which way the portal faces
  229. // The normal points away from the adjacent room
  230. // To be seen through, it must point toward the viewpoint
  231. int16_t xNormal = file.read16();
  232. int16_t yNormal = file.read16();
  233. int16_t zNormal = file.read16();
  234. // The corners of this portal
  235. // The right-hand rule applies with respect to the normal
  236. int16_t xCorner1 = file.read16();
  237. int16_t yCorner1 = file.read16();
  238. int16_t zCorner1 = file.read16();
  239. int16_t xCorner2 = file.read16();
  240. int16_t yCorner2 = file.read16();
  241. int16_t zCorner2 = file.read16();
  242. int16_t xCorner3 = file.read16();
  243. int16_t yCorner3 = file.read16();
  244. int16_t zCorner3 = file.read16();
  245. int16_t xCorner4 = file.read16();
  246. int16_t yCorner4 = file.read16();
  247. int16_t zCorner4 = file.read16();
  248. // TODO store portals
  249. }
  250. uint16_t numZSectors = file.readU16();
  251. uint16_t numXSectors = file.readU16();
  252. //room->setNumXSectors(numXSectors);
  253. //room->setNumZSectors(numZSectors);
  254. for (unsigned int s = 0; s < (numZSectors * numXSectors); s++) {
  255. // Sectors are 1024*1024 world coordinates. Floor and Ceiling are
  256. // signed numbers of 256 units of height.
  257. // Floor/Ceiling value of 0x81 is used to indicate impenetrable
  258. // walls around the sector.
  259. // Floor values are used by the original engine to determine
  260. // what objects can be traversed and how. Relative steps of 1 (256)
  261. // can be walked up, 2..7 must be jumped up, larger than 7 is too high
  262. // If RoomAbove/Below is not none, the Ceiling/Floor is a collisional
  263. // portal to that room
  264. uint16_t indexFloorData = file.readU16();
  265. uint16_t indexBox = file.readU16(); // 0xFFFF if none
  266. uint8_t roomBelow = file.readU8(); // 0xFF if none
  267. int8_t floor = file.read8(); // Absolute height of floor (divided by 256)
  268. uint8_t roomAbove = file.readU8(); // 0xFF if none
  269. int8_t ceiling = file.read8(); // Absolute height of ceiling (/ 256)
  270. bool wall = false;
  271. if ((((uint8_t)floor) == 0x81) || (((uint8_t)ceiling) == 0x81)) {
  272. wall = true;
  273. }
  274. //room->addSector(new Sector(floor * 256.0f, ceiling * 256.0f, wall));
  275. }
  276. int16_t intensity1 = file.read16();
  277. int16_t intensity2 = file.read16();
  278. int16_t lightMode = file.read16();
  279. uint16_t numLights = file.readU16();
  280. for (unsigned int l = 0; l < numLights; l++) {
  281. // Position of light, in world coordinates
  282. int32_t x = file.read32();
  283. int32_t y = file.read32();
  284. int32_t z = file.read32();
  285. uint16_t intensity1 = file.readU16();
  286. uint16_t intensity2 = file.readU16(); // Almost always equal to intensity1
  287. uint32_t fade1 = file.readU32(); // Falloff value?
  288. uint32_t fade2 = file.readU32(); // Falloff value?
  289. // TODO store light somewhere
  290. }
  291. uint16_t numStaticMeshes = file.readU16();
  292. for (unsigned int s = 0; s < numStaticMeshes; s++) {
  293. // Absolute position in world coordinates
  294. int32_t x = file.read32();
  295. int32_t y = file.read32();
  296. int32_t z = file.read32();
  297. // High two bits (0xC000) indicate steps of
  298. // 90 degrees (eg. (rotation >> 14) * 90)
  299. uint16_t rotation = file.readU16();
  300. // Constant lighting, 0xFFFF means use mesh lighting
  301. uint16_t intensity1 = file.readU16();
  302. uint16_t intensity2 = file.readU16();
  303. // Which StaticMesh item to draw
  304. uint16_t objectID = file.readU16();
  305. // TODO store static meshes somewhere
  306. }
  307. int16_t alternateRoom = file.read16(); // TODO
  308. uint16_t flags = file.readU16();
  309. unsigned int roomFlags = 0;
  310. if (flags & 0x0001) {
  311. roomFlags |= RoomFlagUnderWater;
  312. }
  313. BoundingBox* boundingbox = new BoundingBox(bbox[0], bbox[1]);
  314. Mesh* mesh = new Mesh(vertices, rectangles, triangles);
  315. Room* room = new Room(pos, boundingbox, mesh, roomFlags);
  316. getWorld().addRoom(room);
  317. // Sanity check
  318. if ((numPortals == 0) && (numVertices == 0)
  319. && (numRectangles == 0) && (numTriangles == 0))
  320. getLog() << "LoaderTR2: Room " << i << " seems invalid: " << numPortals << "p "
  321. << numRectangles << "r " << numTriangles << "t " << numVertices
  322. << "v" << Log::endl;
  323. }
  324. if (numRooms > 0)
  325. getLog() << "LoaderTR2: Found " << numRooms << " Rooms!" << Log::endl;
  326. else
  327. getLog() << "LoaderTR2: No Rooms in this Level?!" << Log::endl;
  328. }
  329. void LoaderTR2::loadFloorData() {
  330. uint32_t numFloorData = file.readU32();
  331. for (unsigned int f = 0; f < numFloorData; f++) {
  332. uint16_t unused = file.readU16();
  333. // TODO store floor data somewhere
  334. }
  335. if (numFloorData > 0)
  336. getLog() << "LoaderTR2: Found " << numFloorData << " words FloorData, unimplemented!" << Log::endl;
  337. else
  338. getLog() << "LoaderTR2: No FloorData in this level?!" << Log::endl;
  339. }
  340. void LoaderTR2::loadSprites() {
  341. uint32_t numSpriteTextures = file.readU32();
  342. std::vector<Sprite> sprites;
  343. for (unsigned int s = 0; s < numSpriteTextures; s++) {
  344. uint16_t tile = file.readU16();
  345. uint8_t x = file.readU8();
  346. uint8_t y = file.readU8();
  347. uint16_t width = file.readU16(); // Actually (width * 256) + 255
  348. uint16_t height = file.readU16(); // Actually (height * 256) + 255
  349. // Required for what?
  350. int16_t leftSide = file.read16();
  351. int16_t topSide = file.read16();
  352. int16_t rightSide = file.read16();
  353. int16_t bottomSide = file.read16();
  354. sprites.emplace_back(tile, x, y, width, height);
  355. }
  356. uint32_t numSpriteSequences = file.readU32();
  357. for (unsigned int s = 0; s < numSpriteSequences; s++) {
  358. int32_t objectID = file.read32(); // Item identifier, matched in Items[]
  359. int16_t negativeLength = file.read16(); // Negative sprite count
  360. int16_t offset = file.read16(); // Where sequence starts in sprite texture list
  361. assert(negativeLength < 0);
  362. assert(offset >= 0);
  363. assert((offset + (negativeLength * -1)) <= numSpriteTextures);
  364. SpriteSequence* ss = new SpriteSequence(objectID);
  365. for (int i = 0; i < (negativeLength * -1); i++) {
  366. ss->add(sprites.at(offset + i));
  367. }
  368. getWorld().addSprite(ss);
  369. }
  370. if ((numSpriteTextures > 0) || (numSpriteSequences > 0))
  371. getLog() << "LoaderTR2: Found " << numSpriteTextures << " Sprites in " << numSpriteSequences <<
  372. " Sequences!" << Log::endl;
  373. else
  374. getLog() << "LoaderTR2: No Sprites in this level?!" << Log::endl;
  375. }
  376. // ---- Meshes ----
  377. void LoaderTR2::loadMeshes() {
  378. // Number of bitu16s of mesh data to follow
  379. // Read all the mesh data into a buffer, because
  380. // only afterward we can read the number of meshes
  381. // in this data block
  382. uint32_t numMeshData = file.readU32();
  383. std::vector<uint16_t> buffer;
  384. for (unsigned int i = 0; i < numMeshData; i++) {
  385. buffer.push_back(file.readU16());
  386. }
  387. uint32_t numMeshPointers = file.readU32();
  388. for (unsigned int i = 0; i < numMeshPointers; i++) {
  389. uint32_t meshPointer = file.readU32();
  390. if (numMeshData < (meshPointer / 2)) {
  391. getLog() << "LoaderTR2: Invalid Mesh: "
  392. << (meshPointer / 2) << " > " << numMeshData << Log::endl;
  393. continue;
  394. }
  395. char* tmpPtr = reinterpret_cast<char*>(&buffer[meshPointer / 2]);
  396. BinaryMemory mem(tmpPtr, (numMeshData * 2) - meshPointer);
  397. int16_t mx = mem.read16();
  398. int16_t my = mem.read16();
  399. int16_t mz = mem.read16();
  400. int32_t collisionSize = mem.read32();
  401. // TODO store mesh collision info somewhere
  402. uint16_t numVertices = mem.readU16();
  403. std::vector<glm::vec3> vertices;
  404. for (int v = 0; v < numVertices; v++) {
  405. int16_t x = mem.read16();
  406. int16_t y = mem.read16();
  407. int16_t z = mem.read16();
  408. vertices.emplace_back(x, y, z);
  409. }
  410. //Mesh* mesh = new Mesh();
  411. int16_t numNormals = mem.read16();
  412. if (numNormals > 0) {
  413. // External vertex lighting is used, with the lighting calculated
  414. // from the rooms ambient and point-source lighting values. The
  415. // latter appears to use a simple Lambert law for directionality:
  416. // intensity is proportional to
  417. // max((normal direction).(direction to source), 0)
  418. for (int n = 0; n < numNormals; n++) {
  419. int16_t x = mem.read16();
  420. int16_t y = mem.read16();
  421. int16_t z = mem.read16();
  422. //mesh->addNormal(glm::vec3(x, y, z));
  423. }
  424. } else if (numNormals < 0) {
  425. // Internal vertex lighting is used,
  426. // using the data included with the mesh
  427. for (int l = 0; l < (numNormals * -1); l++) {
  428. int16_t light = mem.read16();
  429. // TODO store lights somewhere
  430. }
  431. }
  432. int16_t numTexturedRectangles = mem.read16();
  433. for (int r = 0; r < numTexturedRectangles; r++) {
  434. uint16_t vertex1 = mem.readU16();
  435. uint16_t vertex2 = mem.readU16();
  436. uint16_t vertex3 = mem.readU16();
  437. uint16_t vertex4 = mem.readU16();
  438. uint16_t texture = mem.readU16();
  439. //mesh->addTexturedRectangle(vertices.at(vertex1), vertices.at(vertex2),
  440. // vertices.at(vertex3), vertices.at(vertex4),
  441. // texture);
  442. }
  443. int16_t numTexturedTriangles = mem.read16();
  444. for (int t = 0; t < numTexturedTriangles; t++) {
  445. uint16_t vertex1 = mem.readU16();
  446. uint16_t vertex2 = mem.readU16();
  447. uint16_t vertex3 = mem.readU16();
  448. uint16_t texture = mem.readU16();
  449. //mesh->addTexturedTriangle(vertices.at(vertex1), vertices.at(vertex2),
  450. // vertices.at(vertex3), texture);
  451. }
  452. int16_t numColoredRectangles = mem.read16();
  453. for (int r = 0; r < numColoredRectangles; r++) {
  454. uint16_t vertex1 = mem.readU16();
  455. uint16_t vertex2 = mem.readU16();
  456. uint16_t vertex3 = mem.readU16();
  457. uint16_t vertex4 = mem.readU16();
  458. uint16_t texture = mem.readU16();
  459. int index = (texture & 0xFF00) >> 8;
  460. float red = (palette.at(index) & 0xFF000000) >> 24,
  461. green = (palette.at(index) & 0x00FF0000) >> 16,
  462. blue = (palette.at(index) & 0x0000FF00) >> 8;
  463. //mesh->addColoredRectangle(vertices.at(vertex1), vertices.at(vertex2),
  464. // vertices.at(vertex3), vertices.at(vertex4),
  465. // red, green, blue);
  466. }
  467. int16_t numColoredTriangles = mem.read16();
  468. for (int t = 0; t < numColoredTriangles; t++) {
  469. uint16_t vertex1 = mem.readU16();
  470. uint16_t vertex2 = mem.readU16();
  471. uint16_t vertex3 = mem.readU16();
  472. uint16_t texture = mem.readU16();
  473. int index = (texture & 0xFF00) >> 8;
  474. float red = (palette.at(index) & 0xFF000000) >> 24,
  475. green = (palette.at(index) & 0x00FF0000) >> 16,
  476. blue = (palette.at(index) & 0x0000FF00) >> 8;
  477. //mesh->addColoredTriangle(vertices.at(vertex1), vertices.at(vertex2),
  478. // vertices.at(vertex3), red, green, blue);
  479. }
  480. //getWorld().addMesh(mesh);
  481. }
  482. if (numMeshPointers > 0)
  483. getLog() << "LoaderTR2: Found " << numMeshPointers << " Meshes!" << Log::endl;
  484. else
  485. getLog() << "LoaderTR2: No Meshes in this level?!" << Log::endl;
  486. }
  487. void LoaderTR2::loadStaticMeshes() {
  488. uint32_t numStaticMeshes = file.readU32();
  489. for (unsigned int s = 0; s < numStaticMeshes; s++) {
  490. uint32_t objectID = file.readU32(); // Matched in Items[]
  491. uint16_t mesh = file.readU16(); // Offset into MeshPointers[]
  492. // tr2_vertex BoundingBox[2][2];
  493. // First index is which one, second index is opposite corners
  494. int16_t x11 = file.read16();
  495. int16_t y11 = file.read16();
  496. int16_t z11 = file.read16();
  497. int16_t x12 = file.read16();
  498. int16_t y12 = file.read16();
  499. int16_t z12 = file.read16();
  500. int16_t x21 = file.read16();
  501. int16_t y21 = file.read16();
  502. int16_t z21 = file.read16();
  503. int16_t x22 = file.read16();
  504. int16_t y22 = file.read16();
  505. int16_t z22 = file.read16();
  506. // Meaning uncertain. Usually 2, and 3 for objects Lara can
  507. // travel through, like TR2s skeletons and underwater plants
  508. uint16_t flags = file.readU16();
  509. getWorld().addStaticMesh(new StaticMesh(objectID, mesh));
  510. }
  511. if (numStaticMeshes > 0)
  512. getLog() << "LoaderTR2: Found " << numStaticMeshes << " StaticMeshes!" << Log::endl;
  513. else
  514. getLog() << "LoaderTR2: No StaticMeshes in this level?!" << Log::endl;
  515. }
  516. // ---- Moveables ----
  517. struct Animation_t {
  518. uint32_t frameOffset;
  519. uint8_t frameRate, frameSize;
  520. uint16_t stateID, frameStart, frameEnd, nextAnimation;
  521. uint16_t nextFrame, numStateChanges, stateChangeOffset;
  522. uint16_t numAnimCommands, animCommandOffset;
  523. Animation_t(uint32_t fo, uint8_t fr, uint8_t fs, uint16_t si,
  524. uint16_t fst, uint16_t fe, uint16_t na, uint16_t nf,
  525. uint16_t ns, uint16_t so, uint16_t nac, uint16_t ao)
  526. : frameOffset(fo), frameRate(fr), frameSize(fs),
  527. stateID(si), frameStart(fst), frameEnd(fe), nextAnimation(na),
  528. nextFrame(nf), numStateChanges(ns), stateChangeOffset(so),
  529. numAnimCommands(nac), animCommandOffset(ao) { }
  530. };
  531. struct StateChange_t {
  532. uint16_t stateID, numAnimDispatches, animDispatchOffset;
  533. StateChange_t(uint16_t s, uint16_t n, uint16_t a)
  534. : stateID(s), numAnimDispatches(n), animDispatchOffset(a) { }
  535. };
  536. struct AnimDispatch_t {
  537. int16_t low, high, nextAnimation, nextFrame;
  538. AnimDispatch_t(int16_t l, int16_t h, int16_t na, int16_t nf)
  539. : low(l), high(h), nextAnimation(na), nextFrame(nf) { }
  540. };
  541. void LoaderTR2::loadMoveables() {
  542. uint32_t numAnimations = file.readU32();
  543. std::vector<Animation_t> animations;
  544. for (unsigned int a = 0; a < numAnimations; a++) {
  545. // *Byte* Offset into Frames[] (so divide by 2!)
  546. uint32_t frameOffset = file.readU32();
  547. uint8_t frameRate = file.readU8(); // Engine ticks per frame
  548. // Number of bit16s in Frames[] used by this animation
  549. // Be careful when parsing frames using the FrameSize value
  550. // as the size of each frame, since an animations frame range
  551. // may extend into the next animations frame range, and that
  552. // may have a different FrameSize value.
  553. uint8_t frameSize = file.readU8();
  554. uint16_t stateID = file.readU16();
  555. file.seek(file.tell() + 8); // Skip 8 unknown bytes
  556. uint16_t frameStart = file.readU16(); // First frame in this animation
  557. uint16_t frameEnd = file.readU16(); // Last frame in this animation
  558. uint16_t nextAnimation = file.readU16();
  559. uint16_t nextFrame = file.readU16();
  560. uint16_t numStateChanges = file.readU16();
  561. uint16_t stateChangeOffset = file.readU16(); // Index into StateChanges[]
  562. uint16_t numAnimCommands = file.readU16(); // How many animation commands to use
  563. uint16_t animCommandOffset = file.readU16(); // Index into AnimCommand[]
  564. animations.emplace_back(frameOffset, frameRate, frameSize,
  565. stateID, frameStart, frameEnd, nextAnimation, nextFrame, numStateChanges,
  566. stateChangeOffset, numAnimCommands, animCommandOffset);
  567. }
  568. if (numAnimations > 0)
  569. getLog() << "LoaderTR2: Found " << numAnimations << " Animations!" << Log::endl;
  570. else
  571. getLog() << "LoaderTR2: No Animations in this level?!" << Log::endl;
  572. uint32_t numStateChanges = file.readU32();
  573. std::vector<StateChange_t> stateChanges;
  574. for (unsigned int s = 0; s < numStateChanges; s++) {
  575. uint16_t stateID = file.readU16();
  576. uint16_t numAnimDispatches = file.readU16(); // Number of ranges (always 1..5?)
  577. uint16_t animDispatchOffset = file.readU16(); // Index into AnimDispatches[]
  578. stateChanges.emplace_back(stateID, numAnimDispatches, animDispatchOffset);
  579. }
  580. if (numStateChanges > 0)
  581. getLog() << "LoaderTR2: Found " << numStateChanges << " StateChanges!" << Log::endl;
  582. else
  583. getLog() << "LoaderTR2: No StateChanges in this level?!" << Log::endl;
  584. uint32_t numAnimDispatches = file.readU32();
  585. std::vector<AnimDispatch_t> animDispatches;
  586. for (unsigned int a = 0; a < numAnimDispatches; a++) {
  587. int16_t low = file.read16(); // Lowest frame that uses this range
  588. int16_t high = file.read16(); // Highest frame (+1?) that uses this range
  589. int16_t nextAnimation = file.read16(); // Animation to go to
  590. int16_t nextFrame = file.read16(); // Frame offset to go to
  591. animDispatches.emplace_back(low, high, nextAnimation, nextFrame);
  592. }
  593. if (numAnimDispatches > 0)
  594. getLog() << "LoaderTR2: Found " << numAnimDispatches << " AnimationDispatches!" << Log::endl;
  595. else
  596. getLog() << "LoaderTR2: No AnimationDispatches in this level?!" << Log::endl;
  597. uint32_t numAnimCommands = file.readU32();
  598. std::vector<int16_t> animCommands;
  599. for (unsigned int a = 0; a < numAnimCommands; a++) {
  600. // A list of Opcodes with zero or more operands each,
  601. // some referring to the whole animation (jump/grab points),
  602. // some to specific frames (sound, bubbles, ...).
  603. animCommands.push_back(file.read16());
  604. }
  605. if (numAnimCommands > 0)
  606. getLog() << "LoaderTR2: Found " << numAnimCommands << " AnimationCommands!" << Log::endl;
  607. else
  608. getLog() << "LoaderTR2: No AnimationCommands in this level?!" << Log::endl;
  609. // This is really one uint32_t flags, followed by
  610. // three int32_t x, y, z. However, we're given the number
  611. // of 32bits, as well as byte indices later, so we store
  612. // it as a single list of int32_t.
  613. uint32_t numMeshTrees = file.readU32();
  614. std::vector<int32_t> meshTrees;
  615. for (unsigned int m = 0; m < numMeshTrees; m++) {
  616. // 0x0002 - Put parent mesh on the mesh stack
  617. // 0x0001 - Pop mesh from stack, use as parent mesh
  618. // When both are not set, use previous mesh as parent mesh
  619. // When both are set, do 0x0001 first, then 0x0002, thereby
  620. // reading the stack but not changing it
  621. //uint32_t flags = file.readU32();
  622. // Offset of mesh origin from the parent mesh origin
  623. //int32_t x = file.read32();
  624. //int32_t y = file.read32();
  625. //int32_t z = file.read32();
  626. meshTrees.push_back(file.read32());
  627. }
  628. if (numMeshTrees > 0)
  629. getLog() << "LoaderTR2: Found " << numMeshTrees << " MeshTrees!" << Log::endl;
  630. else
  631. getLog() << "LoaderTR2: No MeshTrees in this level?!" << Log::endl;
  632. uint32_t numFrames = file.readU32();
  633. std::vector<uint16_t> frames;
  634. for (unsigned int f = 0; f < numFrames; f++) {
  635. // int16 bb1x, bb1y, bb1z
  636. // int16 bb2x, bb2y, bb2z
  637. // int16 offsetX, offsetY, offsetZ
  638. // What follows next is a list of angles with numMeshes (from Moveable) entries.
  639. // If the top bit (0x8000) of the first uint16 is set, a single X angle follows,
  640. // if the second bit (0x4000) is set, a Y angle follows, both are a Z angle.
  641. // If none is set, it's a three-axis rotation. The next 10 bits (0x3FF0) are
  642. // the X rotation, the next 10 (0x000F 0xFC00) are Y, the next (0x03FF) are
  643. // the Z rotation. The scaling is always 0x100->90deg.
  644. // Rotation order: Y, X, Z!
  645. frames.push_back(file.readU16());
  646. }
  647. if (numFrames > 0)
  648. getLog() << "LoaderTR2: Found " << numFrames << " Frames!" << Log::endl;
  649. else
  650. getLog() << "LoaderTR2: No Frames in this level?!" << Log::endl;
  651. uint32_t numMoveables = file.readU32();
  652. for (unsigned int m = 0; m < numMoveables; m++) {
  653. // Item identifier, matched in Items[]
  654. uint32_t objectID = file.readU32();
  655. uint16_t numMeshes = file.readU16();
  656. uint16_t startingMesh = file.readU16(); // Offset into MeshPointers[]
  657. uint32_t meshTree = file.readU32(); // Offset into MeshTree[]
  658. // *Byte* offset into Frames[] (divide by 2 for Frames[i])
  659. uint32_t frameOffset = file.readU32(); // Only needed if no animation
  660. // If animation index is 0xFFFF, the object is stationary or
  661. // animated by the engine (ponytail)
  662. uint16_t animation = file.readU16();
  663. // TODO load all animations, not only the first frame!
  664. //if (animation == 0xFFFF) {
  665. // Just add the frame indicated in frameOffset, nothing else
  666. char* tmp = reinterpret_cast<char*>(&frames[0]) + frameOffset;
  667. BinaryMemory frame(tmp + 12, (numFrames * 2) - frameOffset - 12); // skip two BBs
  668. float pos[3];
  669. pos[0] = frame.read16();
  670. pos[1] = frame.read16();
  671. pos[2] = frame.read16();
  672. BoneFrame* bf = new BoneFrame(pos);
  673. for (int i = 0; i < numMeshes; i++) {
  674. int mesh = startingMesh + i;
  675. float offset[3] = { 0.0f, 0.0f, 0.0f };
  676. float rotation[3] = { 0.0f, 0.0f, 0.0f };
  677. char flag = (i == 0) ? 2 : 0;
  678. // Nonprimary tag - positioned relative to first tag
  679. if (i != 0) {
  680. tmp = reinterpret_cast<char*>(&meshTrees[0]) + meshTree; // TODO (meshTree * 4)?
  681. tmp += (i - 1) * 16; // TODO ?
  682. BinaryMemory tree(tmp, (numMeshTrees * 4) - meshTree - ((i - 1) * 16));
  683. flag = (char)tree.readU32();
  684. offset[0] = tree.read32();
  685. offset[1] = tree.read32();
  686. offset[2] = tree.read32();
  687. uint16_t a = frame.readU16();
  688. if (a & 0xC000) {
  689. // Single angle
  690. int index = 0;
  691. if ((a & 0x8000) && (a & 0x4000))
  692. index = 2;
  693. else if (a & 0x4000)
  694. index = 1;
  695. rotation[index] = ((float)(a & 0x03FF)) * 360.0f / 1024.0f;
  696. } else {
  697. // Three angles
  698. uint16_t b = frame.readU16();
  699. rotation[0] = (a & 0x3FF0) >> 4;
  700. rotation[1] = ((a & 0x000F) << 6) | ((b & 0xFC00) >> 10);
  701. rotation[2] = b & 0x03FF;
  702. for (int i = 0; i < 3; i++)
  703. rotation[i] = rotation[i] * 360.0f / 1024.0f;
  704. }
  705. }
  706. BoneTag* bt = new BoneTag(mesh, offset, rotation, flag);
  707. bf->add(bt);
  708. }
  709. AnimationFrame* af = new AnimationFrame(0);
  710. af->add(bf);
  711. SkeletalModel* sm = new SkeletalModel(objectID);
  712. sm->add(af);
  713. getWorld().addSkeletalModel(sm);
  714. //} else {
  715. // Add the whole animation hierarchy
  716. //}
  717. }
  718. if (numMoveables > 0)
  719. getLog() << "LoaderTR2: Found " << numMoveables << " Moveables!" << Log::endl;
  720. else
  721. getLog() << "LoaderTR2: No Moveables in this level?!" << Log::endl;
  722. }
  723. void LoaderTR2::loadItems() {
  724. uint32_t numItems = file.readU32();
  725. for (unsigned int i = 0; i < numItems; i++) {
  726. int16_t objectID = file.read16();
  727. int16_t room = file.read16();
  728. // Item position in world coordinates
  729. int32_t x = file.read32();
  730. int32_t y = file.read32();
  731. int32_t z = file.read32();
  732. uint16_t angle = file.readU16(); // (0xC000 >> 14) * 90deg
  733. int16_t intensity1 = file.read16(); // Constant lighting; -1 means mesh lighting
  734. int16_t intensity2 = file.read16(); // Almost always like intensity1
  735. // 0x0100 - Initially visible
  736. // 0x3E00 - Activation mask, open, can be XORed with related FloorData list fields.
  737. uint16_t flags = file.readU16();
  738. // TODO for now we're only creating Entities for each Moveable Item
  739. for (int m = 0; m < getWorld().sizeSkeletalModel(); m++) {
  740. if (getWorld().getSkeletalModel(m).getId() == objectID) {
  741. float pos[3] = {
  742. static_cast<float>(x),
  743. static_cast<float>(y),
  744. static_cast<float>(z)
  745. };
  746. float rot[3] = {
  747. 0.0f,
  748. glm::radians(((angle >> 14) & 0x03) * 90.0f),
  749. 0.0f
  750. };
  751. Entity* e = new Entity(pos, rot, objectID, room, m);
  752. getWorld().addEntity(e);
  753. if (objectID == 0) {
  754. getGame().setLara(getWorld().sizeEntity() - 1);
  755. }
  756. }
  757. }
  758. }
  759. if (numItems > 0)
  760. getLog() << "LoaderTR2: Found " << numItems << " Items!" << Log::endl;
  761. else
  762. getLog() << "LoaderTR2: No Items in this level?!" << Log::endl;
  763. }
  764. void LoaderTR2::loadBoxesOverlapsZones() {
  765. uint32_t numBoxes = file.readU32();
  766. for (unsigned int b = 0; b < numBoxes; b++) {
  767. // Sectors (* 1024 units)
  768. uint8_t zMin = file.readU8();
  769. uint8_t zMax = file.readU8();
  770. uint8_t xMin = file.readU8();
  771. uint8_t xMax = file.readU8();
  772. int16_t trueFloor = file.read16(); // Y value (no scaling)
  773. // Index into overlaps[]. The high bit is sometimes set
  774. // this occurs in front of swinging doors and the like
  775. uint16_t overlapIndex = file.readU16();
  776. // TODO store boxes somewhere
  777. }
  778. uint32_t numOverlaps = file.readU32();
  779. std::vector<std::vector<uint16_t>> overlaps;
  780. overlaps.emplace_back();
  781. unsigned int list = 0;
  782. for (unsigned int o = 0; o < numOverlaps; o++) {
  783. // Apparently used by NPCs to decide where to go next.
  784. // List of neighboring boxes for each box.
  785. // Each entry is a uint16, 0x8000 set marks end of list.
  786. uint16_t e = file.readU16();
  787. overlaps.at(list).push_back(e);
  788. if (e & 0x8000) {
  789. overlaps.emplace_back();
  790. list++;
  791. }
  792. }
  793. // TODO store overlaps somewhere
  794. for (unsigned int z = 0; z < numBoxes; z++) {
  795. // Normal room state
  796. int16_t ground1 = file.read16();
  797. int16_t ground2 = file.read16();
  798. int16_t ground3 = file.read16();
  799. int16_t ground4 = file.read16();
  800. int16_t fly = file.read16();
  801. // Alternate room state
  802. int16_t ground1alt = file.read16();
  803. int16_t ground2alt = file.read16();
  804. int16_t ground3alt = file.read16();
  805. int16_t ground4alt = file.read16();
  806. int16_t flyAlt = file.read16();
  807. // TODO store zones somewhere
  808. }
  809. if ((numBoxes > 0) || (numOverlaps > 0))
  810. getLog() << "LoaderTR2: Found NPC NavigationHints (" << numBoxes
  811. << ", " << numOverlaps << ", " << list << "), unimplemented!" << Log::endl;
  812. else
  813. getLog() << "LoaderTR2: No NPC NavigationHints in this level?!" << Log::endl;
  814. }
  815. // ---- Sound ----
  816. void LoaderTR2::loadSoundSources() {
  817. uint32_t numSoundSources = file.readU32();
  818. for (unsigned int s = 0; s < numSoundSources; s++) {
  819. // Absolute world coordinate positions of sound source
  820. int32_t x = file.read32();
  821. int32_t y = file.read32();
  822. int32_t z = file.read32();
  823. // Internal sound index
  824. uint16_t soundID = file.readU16();
  825. // Unknown, 0x40, 0x80 or 0xC0
  826. uint16_t flags = file.readU16();
  827. SoundManager::addSoundSource(x, y, z, soundID, flags);
  828. }
  829. if (numSoundSources > 0)
  830. getLog() << "LoaderTR2: Found " << numSoundSources << " SoundSources" << Log::endl;
  831. else
  832. getLog() << "LoaderTR2: No SoundSources in this level?!" << Log::endl;
  833. }
  834. void LoaderTR2::loadSoundMap() {
  835. for (int i = 0; i < 370; i++) {
  836. SoundManager::addSoundMapEntry(file.read16());
  837. }
  838. }
  839. void LoaderTR2::loadSoundDetails() {
  840. uint32_t numSoundDetails = file.readU32();
  841. for (unsigned int s = 0; s < numSoundDetails; s++) {
  842. uint16_t sample = file.readU16(); // Index into SampleIndices[]
  843. uint16_t volume = file.readU16();
  844. // sound range? distance at which this sound can be heard?
  845. uint16_t unknown1 = file.readU16();
  846. // Bits 8-15: priority?
  847. // Bits 2-7: number of samples in this group
  848. // Bits 0-1: channel number?
  849. uint16_t unknown2 = file.readU16();
  850. SoundManager::addSoundDetail(sample, ((float)volume) / 32767.0f);
  851. }
  852. if (numSoundDetails > 0)
  853. getLog() << "LoaderTR2: Found " << numSoundDetails << " SoundDetails" << Log::endl;
  854. else
  855. getLog() << "LoaderTR2: No SoundDetails in this level?!" << Log::endl;
  856. }
  857. void LoaderTR2::loadSampleIndices() {
  858. uint32_t numSampleIndices = file.readU32();
  859. for (unsigned int i = 0; i < numSampleIndices; i++) {
  860. SoundManager::addSampleIndex(file.readU32());
  861. }
  862. if (numSampleIndices > 0)
  863. getLog() << "LoaderTR2: Found " << numSampleIndices << " SampleIndices" << Log::endl;
  864. else
  865. getLog() << "LoaderTR2: No SampleIndices in this level?!" << Log::endl;
  866. }
  867. void LoaderTR2::loadExternalSoundFile(std::string f) {
  868. size_t dir = f.find_last_of("/\\");
  869. if (dir != std::string::npos) {
  870. f.replace(dir + 1, std::string::npos, "MAIN.SFX");
  871. } else {
  872. f = "MAIN.SFX";
  873. }
  874. BinaryFile sfx;
  875. if (sfx.open(f) != 0) {
  876. getLog() << "LoaderTR2: Can't open \"" << f << "\"!" << Log::endl;
  877. return;
  878. }
  879. int riffCount = 0;
  880. while (!sfx.eof()) {
  881. char test[5];
  882. test[4] = '\0';
  883. for (int i = 0; i < 4; i++)
  884. test[i] = sfx.read8();
  885. if (std::string("RIFF") != std::string(test)) {
  886. getLog() << "LoaderTR2: External SFX invalid! (" << riffCount
  887. << ", \"" << test << "\" != \"RIFF\")" << Log::endl;
  888. return;
  889. }
  890. // riffSize is (fileLength - 8)
  891. uint32_t riffSize = sfx.readU32();
  892. unsigned char buff[riffSize + 8];
  893. sfx.seek(sfx.tell() - 8);
  894. for (int i = 0; i < (riffSize + 8); i++)
  895. buff[i] = sfx.readU8();
  896. unsigned long src;
  897. int ret = Sound::loadBuffer(buff, riffSize + 8);
  898. assert(ret >= 0);
  899. riffCount++;
  900. }
  901. if (riffCount > 0)
  902. getLog() << "LoaderTR2: Found " << riffCount << " SoundSamples in SFX" << Log::endl;
  903. else
  904. getLog() << "LoaderTR2: No SoundSamples in SFX?!" << Log::endl;
  905. }
  906. // ---- Stuff ----
  907. void LoaderTR2::loadCameras() {
  908. uint32_t numCameras = file.readU32();
  909. for (unsigned int c = 0; c < numCameras; c++) {
  910. int32_t x = file.read32();
  911. int32_t y = file.read32();
  912. int32_t z = file.read32();
  913. int16_t room = file.read16();
  914. file.seek(file.tell() + 2); // Unknown, correlates to Boxes? Zones?
  915. // TODO store cameras somewhere
  916. }
  917. if (numCameras > 0)
  918. getLog() << "LoaderTR2: Found " << numCameras << " Cameras, unimplemented!" << Log::endl;
  919. }
  920. void LoaderTR2::loadCinematicFrames() {
  921. uint16_t numCinematicFrames = file.readU16();
  922. for (unsigned int c = 0; c < numCinematicFrames; c++) {
  923. int16_t rotY = file.read16(); // Y rotation, +-32767 = +-180deg
  924. int16_t rotZ = file.read16(); // Z rotation, like rotY
  925. int16_t rotZ2 = file.read16(); // Like rotZ?
  926. int16_t posZ = file.read16(); // Camera pos relative to what?
  927. int16_t posY = file.read16();
  928. int16_t posX = file.read16();
  929. int16_t unknown = file.read16(); // Changing this can cause runtime error
  930. int16_t rotX = file.read16(); // X rotation, like rotY
  931. // TODO store cinematic frames somewhere
  932. }
  933. if (numCinematicFrames > 0)
  934. getLog() << "LoaderTR2: Found " << numCinematicFrames
  935. << " CinematicFrames, unimplemented!" << Log::endl;
  936. }
  937. void LoaderTR2::loadDemoData() {
  938. uint16_t numDemoData = file.readU16();
  939. for (unsigned int d = 0; d < numDemoData; d++)
  940. file.readU8();
  941. // TODO store demo data somewhere, find out meaning
  942. if (numDemoData > 0)
  943. getLog() << "LoaderTR2: Found " << numDemoData << " bytes DemoData, unimplemented!" <<
  944. Log::endl;
  945. }