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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /*!
  2. * \file src/loader/LoaderTR2.cpp
  3. * \brief TR2 level file loader
  4. *
  5. * \author xythobuz
  6. */
  7. #include <vector>
  8. #include "global.h"
  9. #include "Console.h"
  10. #include "loader/LoaderTR2.h"
  11. LoaderTR2::LoaderTR2() {
  12. numTextiles = 0;
  13. textiles = nullptr;
  14. }
  15. LoaderTR2::~LoaderTR2() {
  16. if (textiles != nullptr) {
  17. for (unsigned int i = 0; i < numTextiles; i++)
  18. delete [] textiles[i];
  19. delete [] textiles;
  20. }
  21. }
  22. int LoaderTR2::load(std::string f) {
  23. if (file.open(f.c_str()) != 0) {
  24. return 1; // Could not open file
  25. }
  26. if (file.readU32() != 0x2D) {
  27. return 2; // Not a TR2 level?!
  28. }
  29. loadPaletteTextiles();
  30. getConsole() << "->loaded palette" << Console::endl;
  31. file.seek(file.tell() + 4); // Unused value?
  32. loadRooms();
  33. getConsole() << "->loaded rooms" << Console::endl;
  34. loadFloorData();
  35. getConsole() << "->loaded floor data" << Console::endl;
  36. loadMeshes();
  37. getConsole() << "->loaded meshes" << Console::endl;
  38. loadMoveables();
  39. getConsole() << "->loaded moveables" << Console::endl;
  40. loadStaticMeshes();
  41. getConsole() << "->loaded static meshes" << Console::endl;
  42. loadTextures();
  43. getConsole() << "->loaded textures" << Console::endl;
  44. loadSprites();
  45. getConsole() << "->loaded sprites" << Console::endl;
  46. loadCameras();
  47. getConsole() << "->loaded cameras" << Console::endl;
  48. loadSoundSources();
  49. getConsole() << "->loaded sound sources" << Console::endl;
  50. loadBoxesOverlapsZones();
  51. getConsole() << "->loaded boxes overlaps zones" << Console::endl;
  52. loadAnimatedTextures();
  53. getConsole() << "->loaded animated textures" << Console::endl;
  54. loadItems();
  55. getConsole() << "->loaded items" << Console::endl;
  56. file.seek(file.tell() + 8192); // Skip Light map, only for 8bit coloring
  57. loadCinematicFrames();
  58. getConsole() << "->loaded cinematic frames" << Console::endl;
  59. loadDemoData();
  60. getConsole() << "->loaded demo data" << Console::endl;
  61. loadSoundMap();
  62. getConsole() << "->loaded sound map" << Console::endl;
  63. loadSoundDetails();
  64. getConsole() << "->loaded sound details" << Console::endl;
  65. loadSampleIndices();
  66. getConsole() << "->loaded sample indices" << Console::endl;
  67. return 0;
  68. }
  69. void LoaderTR2::loadPaletteTextiles() {
  70. file.seek(file.tell() + 768); // Skip 8bit palette, 256 * 3 bytes
  71. // Read the 16bit palette, 256 * 4 bytes, RGBA, A unused
  72. for (auto &x : palette)
  73. x = file.readU32();
  74. numTextiles = file.readU32();
  75. file.seek(file.tell() + (numTextiles * 256 * 256)); // Skip 8bit textiles
  76. // Read the 16bit textiles, numTextiles * 256 * 256 * 2 bytes
  77. textiles = new uint16_t *[numTextiles];
  78. for (unsigned int i = 0; i < numTextiles; i++) {
  79. textiles[i] = new uint16_t[256 * 256];
  80. for (unsigned int j = 0; j < (256 * 256); j++) {
  81. textiles[i][j] = file.readU16();
  82. }
  83. }
  84. }
  85. void LoaderTR2::loadRooms() {
  86. uint16_t numRooms = file.readU16();
  87. for (unsigned int i = 0; i < numRooms; i++) {
  88. // Room Header
  89. int32_t xOffset = file.read32();
  90. int32_t zOffset = file.read32();
  91. int32_t yBottom = file.read32(); // lowest point == largest y value
  92. int32_t yTop = file.read32(); // highest point == smallest y value
  93. // Number of data words (2 bytes) to follow
  94. uint32_t dataToFollow = file.readU32();
  95. uint16_t numVertices = file.readU16();
  96. for (unsigned int v = 0; v < numVertices; v++) {
  97. // Vertex coordinates, relative to x/zOffset
  98. int16_t relativeX = file.read16();
  99. int16_t relativeY = file.read16();
  100. int16_t relativeZ = file.read16();
  101. int16_t lighting1 = file.read16();
  102. // Set of flags for special rendering effects
  103. // 0x8000 - Something to do with water surface?
  104. // 0x4000 - Underwater lighting modulation/movement if seen from above
  105. // 0x2000 - Water/Quicksand surface movement
  106. // 0x0010 - Normal?
  107. uint16_t attributes = file.readU16();
  108. int16_t lighting2; // Almost always equal to lighting1
  109. // TODO store vertex somewhere
  110. }
  111. uint16_t numRectangles = file.readU16();
  112. for (unsigned int r = 0; r < numRectangles; r++) {
  113. // Indices into the vertex list read just before
  114. uint16_t vertex1 = file.readU16();
  115. uint16_t vertex2 = file.readU16();
  116. uint16_t vertex3 = file.readU16();
  117. uint16_t vertex4 = file.readU16();
  118. // Index into the object-texture list
  119. uint16_t texture = file.readU16();
  120. // TODO store rectangles somewhere
  121. }
  122. uint16_t numTriangles = file.readU16();
  123. for (unsigned int t = 0; t < numTriangles; t++) {
  124. // Indices into the room vertex list
  125. uint16_t vertex1 = file.readU16();
  126. uint16_t vertex2 = file.readU16();
  127. uint16_t vertex3 = file.readU16();
  128. // Index into the object-texture list
  129. uint16_t texture = file.readU16();
  130. // TODO store triangles somewhere
  131. }
  132. uint16_t numSprites = file.readU16();
  133. for (unsigned int s = 0; s < numSprites; s++) {
  134. uint16_t vertex = file.readU16(); // Index into vertex list
  135. uint16_t texture = file.readU16(); // Index into object-texture list
  136. // TODO store sprites somewhere
  137. }
  138. uint16_t numPortals = file.readU16();
  139. for (unsigned int p = 0; p < numPortals; p++) {
  140. // Which room this portal leads to
  141. uint16_t adjoiningRoom = file.readU16();
  142. // Which way the portal faces
  143. // The normal points away from the adjacent room
  144. // To be seen through, it must point toward the viewpoint
  145. int16_t xNormal = file.read16();
  146. int16_t yNormal = file.read16();
  147. int16_t zNormal = file.read16();
  148. // The corners of this portal
  149. // The right-hand rule applies with respect to the normal
  150. int16_t xCorner1 = file.read16();
  151. int16_t yCorner1 = file.read16();
  152. int16_t zCorner1 = file.read16();
  153. int16_t xCorner2 = file.read16();
  154. int16_t yCorner2 = file.read16();
  155. int16_t zCorner2 = file.read16();
  156. int16_t xCorner3 = file.read16();
  157. int16_t yCorner3 = file.read16();
  158. int16_t zCorner3 = file.read16();
  159. // TODO store portals somewhere
  160. }
  161. uint16_t numZSectors = file.readU16();
  162. uint16_t numXSectors = file.readU16();
  163. for (unsigned int s = 0; s < (numZSectors * numXSectors); s++) {
  164. // Sectors are 1024*1024 world coordinates. Floor and Ceiling are
  165. // signed numbers of 256 units of height.
  166. // Floor/Ceiling value of 0x81 is used to indicate impenetrable
  167. // walls around the sector.
  168. // Floor values are used by the original engine to determine
  169. // what objects can be traversed and how. Relative steps of 1 (256)
  170. // can be walked up, 2..7 must be jumped up, larger than 7 is too high
  171. // If RoomAbove/Below is not none, the Ceiling/Floor is a collisional
  172. // portal to that room
  173. uint16_t indexFloorData = file.readU16();
  174. uint16_t indexBox = file.readU16(); // 0xFFFF if none
  175. uint8_t roomBelow = file.readU8(); // 0xFF if none
  176. int8_t floor = file.read8(); // Absolute height of floor (divided by 256)
  177. uint8_t roomAbove = file.readU8(); // 0xFF if none
  178. int8_t ceiling = file.read8(); // Absolute height of ceiling (/ 256)
  179. // TODO store sectors somewhere
  180. }
  181. int16_t intensity1 = file.read16();
  182. int16_t intensity2 = file.read16();
  183. int16_t lightMode = file.read16();
  184. uint16_t numLights = file.readU16();
  185. for (unsigned int l = 0; l < numLights; l++) {
  186. // Position of light, in world coordinates
  187. int32_t x = file.read32();
  188. int32_t y = file.read32();
  189. int32_t z = file.read32();
  190. uint16_t intensity1 = file.readU16();
  191. uint16_t intensity2 = file.readU16(); // Almost always equal to intensity1
  192. uint32_t fade1 = file.readU32(); // Falloff value?
  193. uint32_t fade2 = file.readU32(); // Falloff value?
  194. // TODO store light somewhere
  195. }
  196. uint16_t numStaticMeshes = file.readU16();
  197. for (unsigned int s = 0; s < numStaticMeshes; s++) {
  198. // Absolute position in world coordinates
  199. int32_t x = file.read32();
  200. int32_t y = file.read32();
  201. int32_t z = file.read32();
  202. // High two bits (0xC000) indicate steps of
  203. // 90 degrees (eg. (rotation >> 14) * 90)
  204. uint16_t rotation = file.readU16();
  205. // Constant lighting, 0xFFFF means use mesh lighting
  206. uint16_t intensity1 = file.readU16();
  207. uint16_t intensity2 = file.readU16();
  208. // Which StaticMesh item to draw
  209. uint16_t objectID = file.readU16();
  210. // TODO store static meshes somewhere
  211. }
  212. int16_t alternateRoom = file.read16();
  213. uint16_t flags = file.readU16();
  214. }
  215. }
  216. void LoaderTR2::loadFloorData() {
  217. uint32_t numFloorData = file.readU32();
  218. for (unsigned int f = 0; f < numFloorData; f++) {
  219. uint16_t unused = file.readU16();
  220. // TODO store floor data somewhere
  221. }
  222. }
  223. void LoaderTR2::loadMeshes() {
  224. // Number of bitu16s of mesh data to follow
  225. // Read all the mesh data into a buffer, because
  226. // only afterward we can read the number of meshes
  227. // in this data block
  228. uint32_t numMeshData = file.readU32();
  229. std::vector<uint16_t> buffer;
  230. for (unsigned int i = 0; i < numMeshData; i++) {
  231. buffer.push_back(file.readU16());
  232. }
  233. uint32_t numMeshPointers = file.readU32();
  234. std::vector<uint32_t> meshPointers;
  235. for (unsigned int i = 0; i < numMeshPointers; i++) {
  236. meshPointers.push_back(file.readU32());
  237. }
  238. // TODO interpret the buffered mesh data
  239. }
  240. void LoaderTR2::loadMoveables() {
  241. uint32_t numAnimations = file.readU32();
  242. for (unsigned int a = 0; a < numAnimations; a++) {
  243. // *Byte* Offset into Frames[] (so divide by 2!)
  244. uint32_t frameOffset = file.readU32();
  245. uint8_t frameRate = file.readU8(); // Engine ticks per frame
  246. // Number of bit16s in Frames[] used by this animation
  247. // Be careful when parsing frames using the FrameSize value
  248. // as the size of each frame, since an animations frame range
  249. // may extend into the next animations frame range, and that
  250. // may have a different FrameSize value.
  251. uint8_t frameSize = file.readU8();
  252. uint16_t stateID = file.readU16();
  253. file.seek(file.tell() + 8); // Skip 8 unknown bytes
  254. uint16_t frameStart = file.readU16(); // First frame in this animation
  255. uint16_t frameEnd = file.readU16(); // Last frame in this animation
  256. uint16_t nextAnimation = file.readU16();
  257. uint16_t nextFrame = file.readU16();
  258. uint16_t numStateChanges = file.readU16();
  259. uint16_t stateChangeOffset = file.readU16(); // Index into StateChanges[]
  260. uint16_t numAnimCommands; // How many animation commands to use
  261. uint16_t animCommandOffset; // Index into AnimCommand[]
  262. // TODO store animations somewhere
  263. }
  264. uint32_t numStateChanges = file.readU32();
  265. for (unsigned int s = 0; s < numStateChanges; s++) {
  266. uint16_t stateID = file.readU16();
  267. uint16_t numAnimDispatches = file.readU16();
  268. uint16_t animDispatchOffset = file.readU16(); // Index into AnimDispatches[]
  269. // TODO store state changes somewhere
  270. }
  271. uint32_t numAnimDispatches = file.readU32();
  272. for (unsigned int a = 0; a < numAnimDispatches; a++) {
  273. int16_t low = file.read16(); // Lowest frame that uses this range
  274. int16_t high = file.read16(); // Highest frame (+1?) that uses this range
  275. int16_t nextAnimation = file.read16(); // Animation to go to
  276. int16_t nextFrame = file.read16(); // Frame offset to go to
  277. // TODO store animation dispatches somewhere
  278. }
  279. uint32_t numAnimCommands = file.readU32();
  280. std::vector<int16_t> animCommands;
  281. for (unsigned int a = 0; a < numAnimCommands; a++) {
  282. animCommands.push_back(file.read16());
  283. }
  284. uint32_t numMeshTrees = file.readU32();
  285. for (unsigned int m = 0; m < numMeshTrees; m++) {
  286. // 0x0002 - Put parent mesh on the mesh stack
  287. // 0x0001 - Pop mesh from stack, use as parent mesh
  288. // When both are not set, use previous mesh as parent mesh
  289. // When both are set, do 0x0001 first, then 0x0002, thereby
  290. // reading the stack but not changing it
  291. uint32_t flags = file.readU32();
  292. // Offset of mesh origin from the parent mesh origin
  293. int32_t x = file.read32();
  294. int32_t y = file.read32();
  295. int32_t z = file.read32();
  296. // TODO store mesh trees somewhere
  297. }
  298. uint32_t numFrames = file.readU32();
  299. std::vector<uint16_t> frames;
  300. for (unsigned int f = 0; f < numFrames; f++) {
  301. frames.push_back(file.readU16());
  302. }
  303. uint32_t numMoveables = file.readU32();
  304. for (unsigned int m = 0; m < numMoveables; m++) {
  305. // Item identifier, matched in Items[]
  306. uint32_t objectID = file.readU32();
  307. uint16_t numMeshes = file.readU16();
  308. uint16_t startingMesh = file.readU16(); // Offset into MeshPointers[]
  309. uint32_t meshTree = file.readU32(); // Offset into MeshTree[]
  310. // *Byte* offset into Frames[] (divide by 2 for Frames[i])
  311. uint32_t frameOffset = file.readU32();
  312. // If animation index is 0xFFFF, the object is stationary or
  313. // animated by the engine (ponytail)
  314. uint16_t animation = file.readU16();
  315. // TODO store moveables somewhere
  316. }
  317. // TODO combine all this into moveables with their animations
  318. }
  319. void LoaderTR2::loadStaticMeshes() {
  320. uint32_t numStaticMeshes = file.readU32();
  321. for (unsigned int s = 0; s < numStaticMeshes; s++) {
  322. uint32_t objectID = file.readU32(); // Matched in Items[]
  323. uint16_t mesh = file.readU16(); // Offset into MeshPointers[]
  324. // tr2_vertex BoundingBox[2][2];
  325. // // First index is which one, second index is opposite corners
  326. int16_t x11 = file.read16();
  327. int16_t y11 = file.read16();
  328. int16_t z11 = file.read16();
  329. int16_t x12 = file.read16();
  330. int16_t y12 = file.read16();
  331. int16_t z12 = file.read16();
  332. int16_t x21 = file.read16();
  333. int16_t y21 = file.read16();
  334. int16_t z21 = file.read16();
  335. int16_t x22 = file.read16();
  336. int16_t y22 = file.read16();
  337. int16_t z22 = file.read16();
  338. // Meaning uncertain. Usually 2, and 3 for objects Lara can
  339. // travel through, like TR2s skeletons and underwater plants
  340. uint16_t flags = file.readU16();
  341. // TODO store static meshes somewhere
  342. }
  343. }
  344. void LoaderTR2::loadTextures() {
  345. uint32_t numObjectTextures = file.readU32();
  346. for (unsigned int o = 0; o < numObjectTextures; o++) {
  347. // 0 means that a texture is all-opaque, and that transparency
  348. // information is ignored.
  349. // 1 means that transparency information is used. In 8-bit color,
  350. // index 0 is the transparent color, while in 16-bit color, the
  351. // top bit (0x8000) is the alpha channel (1 = opaque, 0 = transparent)
  352. uint16_t attribute = file.readU16();
  353. // Index into the textile list
  354. uint16_t tile = file.readU16();
  355. // The four corner vertices of the texture
  356. // The Pixel values are the actual coordinates of the vertexs pixel
  357. // The Coordinate values depend on where the other vertices are in
  358. // the object texture. And if the object texture is used to specify
  359. // a triangle, then the fourth vertexs values will all be zero
  360. // Coordinate is 1 if Pixel is the low val, 255 if high val in object texture
  361. uint8_t xCoordinate1 = file.readU8();
  362. uint8_t xPixel1 = file.readU8();
  363. uint8_t yCoordinate1 = file.readU8();
  364. uint8_t yPixel1 = file.readU8();
  365. uint8_t xCoordinate2 = file.readU8();
  366. uint8_t xPixel2 = file.readU8();
  367. uint8_t yCoordinate2 = file.readU8();
  368. uint8_t yPixel2 = file.readU8();
  369. uint8_t xCoordinate3 = file.readU8();
  370. uint8_t xPixel3 = file.readU8();
  371. uint8_t yCoordinate3 = file.readU8();
  372. uint8_t yPixel3 = file.readU8();
  373. uint8_t xCoordinate4 = file.readU8();
  374. uint8_t xPixel4 = file.readU8();
  375. uint8_t yCoordinate4 = file.readU8();
  376. uint8_t yPixel4 = file.readU8();
  377. // TODO store object textures somewhere
  378. }
  379. }
  380. void LoaderTR2::loadSprites() {
  381. uint32_t numSpriteTextures = file.readU32();
  382. for (unsigned int s = 0; s < numSpriteTextures; s++) {
  383. uint16_t tile = file.readU16();
  384. uint8_t x = file.readU8();
  385. uint8_t y = file.readU8();
  386. uint16_t width = file.readU16(); // Actually (width * 256) + 255
  387. uint16_t height = file.readU16(); // Actually (height * 256) + 255
  388. int16_t leftSide = file.read16();
  389. int16_t topSide = file.read16();
  390. int16_t rightSide = file.read16();
  391. int16_t bottomSide = file.read16();
  392. // TODO store sprite textures somewhere
  393. }
  394. uint32_t numSpriteSequences = file.readU32();
  395. for (unsigned int s = 0; s < numSpriteSequences; s++) {
  396. int32_t objectID = file.read32(); // Item identifier, matched in Items[]
  397. int16_t negativeLength = file.read16(); // Negative sprite count
  398. int16_t offset = file.read16(); // Where sequence starts in sprite texture list
  399. // TODO store sprite sequences somewhere
  400. }
  401. }
  402. void LoaderTR2::loadCameras() {
  403. uint32_t numCameras = file.readU32();
  404. for (unsigned int c = 0; c < numCameras; c++) {
  405. int32_t x = file.read32();
  406. int32_t y = file.read32();
  407. int32_t z = file.read32();
  408. int16_t room = file.read16();
  409. file.seek(file.tell() + 2); // Unknown, correlates to Boxes? Zones?
  410. // TODO store cameras somewhere
  411. }
  412. }
  413. void LoaderTR2::loadSoundSources() {
  414. uint32_t numSoundSources = file.readU32();
  415. for (unsigned int s = 0; s < numSoundSources; s++) {
  416. // Absolute world coordinate positions of sound source
  417. int32_t x = file.read32();
  418. int32_t y = file.read32();
  419. int32_t z = file.read32();
  420. // Internal sound index
  421. uint16_t soundID = file.readU16();
  422. // Unknown, 0x40, 0x80 or 0xC0
  423. uint16_t flags = file.readU16();
  424. // TODO store sound sources somewhere
  425. }
  426. }
  427. void LoaderTR2::loadBoxesOverlapsZones() {
  428. uint32_t numBoxes = file.readU32();
  429. for (unsigned int b = 0; b < numBoxes; b++) {
  430. // Sectors (* 1024 units)
  431. uint8_t zMin = file.readU8();
  432. uint8_t zMax = file.readU8();
  433. uint8_t xMin = file.readU8();
  434. uint8_t xMax = file.readU8();
  435. int16_t trueFloor = file.read16(); // Y value (no scaling)
  436. // Index into overlaps[]. The high bit is sometimes set
  437. // this occurs in front of swinging doors and the like
  438. int16_t overlapIndex = file.read16();
  439. // TODO store boxes somewhere
  440. }
  441. uint32_t numOverlaps = file.readU32();
  442. std::vector<uint16_t> overlaps;
  443. for (unsigned int o = 0; o < numOverlaps; o++) {
  444. overlaps.push_back(file.readU16());
  445. }
  446. // TODO store overlaps somewhere
  447. std::vector<int16_t> zones;
  448. for (unsigned int z = 0; z < numBoxes; z++) {
  449. for (unsigned int i = 0; i < 10; i++) {
  450. zones.push_back(file.read16());
  451. }
  452. }
  453. // TODO store zones somewhere
  454. }
  455. void LoaderTR2::loadAnimatedTextures() {
  456. uint32_t numAnimatedTextures = file.readU32();
  457. std::vector<uint16_t> animatedTextures;
  458. for (unsigned int a = 0; a < numAnimatedTextures; a++) {
  459. animatedTextures.push_back(file.readU16());
  460. }
  461. // TODO store animated textures somewhere. Format?
  462. }
  463. void LoaderTR2::loadItems() {
  464. uint32_t numItems = file.readU32();
  465. for (unsigned int i = 0; i < numItems; i++) {
  466. int16_t objectID = file.read16();
  467. int16_t room = file.read16();
  468. // Item position in world coordinates
  469. int32_t x = file.read32();
  470. int32_t y = file.read32();
  471. int32_t z = file.read32();
  472. int16_t angle = file.read16(); // (0xC000 >> 14) * 90deg
  473. int16_t intensity1 = file.read16(); // Constant lighting; -1 means mesh lighting
  474. int16_t intensity2 = file.read16(); // Almost always like intensity1
  475. // 0x0100 - Initially visible
  476. // 0x3E00 - Activation mask, open, can be XORed with related FloorData list fields.
  477. uint16_t flags = file.readU16();
  478. // TODO store items somewhere
  479. }
  480. }
  481. void LoaderTR2::loadCinematicFrames() {
  482. uint16_t numCinematicFrames = file.readU16();
  483. for (unsigned int c = 0; c < numCinematicFrames; c++) {
  484. int16_t rotY = file.read16(); // Y rotation, +-32767 = +-180deg
  485. int16_t rotZ = file.read16(); // Z rotation, like rotY
  486. int16_t rotZ2 = file.read16(); // Like rotZ?
  487. int16_t posZ = file.read16(); // Camera pos relative to what?
  488. int16_t posY = file.read16();
  489. int16_t posX = file.read16();
  490. int16_t unknown = file.read16(); // Changing this can cause runtime error
  491. int16_t rotX = file.read16(); // X rotation, like rotY
  492. // TODO store cinematic frames somewhere
  493. }
  494. }
  495. void LoaderTR2::loadDemoData() {
  496. uint16_t numDemoData = file.readU16();
  497. for (unsigned int d = 0; d < numDemoData; d++)
  498. file.readU8();
  499. // TODO store demo data somewhere, find out meaning
  500. }
  501. void LoaderTR2::loadSoundMap() {
  502. std::array<int16_t, 370> soundMap;
  503. for (auto &x : soundMap) {
  504. x = file.read16();
  505. }
  506. // TODO store sound map somewhere
  507. }
  508. void LoaderTR2::loadSoundDetails() {
  509. uint32_t numSoundDetails = file.readU32();
  510. for (unsigned int s = 0; s < numSoundDetails; s++) {
  511. int16_t sample = file.read16(); // Index into SampleIndices[]
  512. int16_t volume = file.read16();
  513. // sound range? distance at which this sound can be heard?
  514. int16_t unknown1 = file.read16();
  515. // Bits 8-15: priority?
  516. // Bits 2-7: number of samples in this group
  517. // Bits 0-1: channel number?
  518. int16_t unknown2 = file.read16();
  519. // TODO store sound details somewhere
  520. }
  521. }
  522. void LoaderTR2::loadSampleIndices() {
  523. uint32_t numSampleIndices = file.readU32();
  524. std::vector<uint32_t> sampleIndices;
  525. for (unsigned int i = 0; i < numSampleIndices; i++) {
  526. sampleIndices.push_back(file.readU32());
  527. }
  528. // TODO store sample indices somewhere
  529. }