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.

TombRaider.h 74KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921
  1. /*!
  2. * \file include/TombRaider.h
  3. * \brief Loads maps, meshes, textures...
  4. *
  5. * \todo WARNING: No endian routines as of yet
  6. * \author Mongoose
  7. */
  8. #ifndef _TOMBRAIDER_H_
  9. #define _TOMBRAIDER_H_
  10. #include <cstdint>
  11. #ifdef WIN32
  12. // Have to remove GCC packing, by removing in preprocessor
  13. #define __attribute__(packed)
  14. // MSVC++ pragma to pack structs
  15. #define TR2_H 1
  16. #pragma pack(push, tr2_h, 1)
  17. #endif
  18. //#include "games/TombRaider1.h"
  19. typedef enum {
  20. TR_VERSION_UNKNOWN,
  21. TR_VERSION_1,
  22. TR_VERSION_2,
  23. TR_VERSION_3,
  24. TR_VERSION_4,
  25. TR_VERSION_5
  26. } tr2_version_type;
  27. typedef enum {
  28. TR_FREAD_NORMAL = 0,
  29. TR_FREAD_COMPRESSED
  30. } tr_fread_mode_t;
  31. typedef enum {
  32. tombraiderLight_typeDirectional = 1,
  33. tombraiderLight_typeSpot = 2,
  34. tombraiderLight_typePoint = 3
  35. } tombraiderLightType;
  36. typedef enum {
  37. tombraiderLight_useCutoff = 1,
  38. tombraiderLight_useAttenuation = 2
  39. } tombraiderLightFlags;
  40. typedef enum {
  41. tombraiderRoom_underWater = 1
  42. } tombraiderRoomFlags;
  43. typedef enum {
  44. tombraiderSector_wall = 1
  45. } tombraiderSectorFlags;
  46. typedef enum {
  47. tombraiderFace_Alpha = (1 << 0),
  48. tombraiderFace_Colored = (1 << 1),
  49. tombraiderFace_PartialAlpha = (1 << 2)
  50. } tombraiderFace_Flags;
  51. #define TR_SOUND_FOOTSTEP0 1
  52. #define TR_SOUND_F_PISTOL 12
  53. enum TR4_Objects {
  54. TR4_LARA = 0,
  55. TR4_PISTOLS_ANIM = 1,
  56. TR4_UZI_ANIM = 2,
  57. TR4_SHOTGUN_ANIM = 3,
  58. TR4_CROSSBOW_ANIM = 4,
  59. TR4_GRENADE_GUN_ANIM = 5,
  60. TR4_SIXSHOOTER_ANIM = 6,
  61. TR4_FLARE_ANIM = 7,
  62. TR4_LARA_SKIN = 8,
  63. TR4_LARA_SKIN_JOINTS = 9,
  64. TR4_LARA_SCREAM = 10,
  65. TR4_LARA_CROSSBOW_LASER = 11,
  66. TR4_LARA_REVOLVER_LASER = 12,
  67. TR4_LARA_HOLSTERS = 13,
  68. TR4_LARA_HOLSTERS_PISTOLS = 14,
  69. TR4_LARA_HOLSTERS_UZIS = 15,
  70. TR4_LARA_HOLSTERS_SIXSHOOTER = 16,
  71. TR4_LARA_SPEECH_HEAD1 = 17,
  72. TR4_LARA_SPEECH_HEAD2 = 18,
  73. TR4_LARA_SPEECH_HEAD3 = 19,
  74. TR4_LARA_SPEECH_HEAD4 = 20
  75. };
  76. #define TR_ANIAMTION_RUN 0
  77. #define TR_ANIAMTION_STAND 11
  78. #define TR_ANIAMTION_TURN_L 12
  79. #define TR_ANIAMTION_TURN_R 13
  80. #define TR_ANIAMTION_HIT_WALL_FRONT 53
  81. #define TR_ANIAMTION_SWIM_IDLE 87
  82. #define TR_ANIAMTION_SWIM 86
  83. #define TR_ANIAMTION_SWIM_L 143
  84. #define TR_ANIAMTION_SWIM_R 144
  85. #define TR_ANIAMTION_GRAB_LEDGE 96
  86. #define TR_ANIAMTION_PULLING_UP 97
  87. /*!
  88. * \brief Basic 24-bit colour structure.
  89. *
  90. * It appears that only 6 bits per colour are actually
  91. * used, making it 18-bit colour.
  92. */
  93. typedef struct {
  94. unsigned char r; //!< Red part
  95. unsigned char g; //!< Green part
  96. unsigned char b; //!< Blue part
  97. } __attribute__ ((packed)) tr2_colour_t;
  98. /*!
  99. * \brief Basic vertex structure.
  100. *
  101. * Note that all vertices are relative coordinates;
  102. * each mesh (room, object, etc.) has its own offset by
  103. * which the vertex coordinates are translated.
  104. */
  105. typedef struct {
  106. short x;
  107. short y;
  108. short z;
  109. } __attribute__ ((packed)) tr2_vertex_t;
  110. /*!
  111. * \brief A rectangular (quad) face definition.
  112. *
  113. * Four vertices (the values are indices into the
  114. * appropriate vertex list) and a texture (an index
  115. * into the texture list) or colour (index into 8-bit palette).
  116. *
  117. * I've seen a few coloured polygons where Texture is
  118. * greater than 255, but ANDing the value with 0xFF
  119. * seems to produce acceptable results.
  120. */
  121. typedef struct {
  122. unsigned short vertices[4];
  123. unsigned short texture;
  124. } __attribute__ ((packed)) tr2_quad_t; // was tr2_face4
  125. typedef struct {
  126. unsigned short vertices[4]; //!< The 4 vertices of a quad
  127. unsigned short texture; //!< Object-texture index
  128. unsigned short lighting; //!< Transparency flag & strength of the highlight
  129. /*!<
  130. * Bit 0: if set, alpha channel = intensity (same meaning that when the
  131. * Attribute field of tr2_object_texture is 2. Cf TRosetta stone document)
  132. *
  133. * Bit 1-7: strength of the highlight. In TR4, objects can exhibit some kind
  134. * of light reflection when seen from some particular angles. These bits give
  135. * the strength of this effect:
  136. * the more bigger the value is, the more visible is the effect.
  137. */
  138. } __attribute__ ((packed)) tr4_quad_t;
  139. /*!
  140. * \brief A triangular face definition.
  141. *
  142. * Three vertices (the values are indices into the
  143. * appropriate vertex list) and a texture (an index into the
  144. * texture list) or colour (index into palette).
  145. *
  146. * In the case of a colour, (Texture & 0xff) is the index
  147. * into the 8-bit palette, while (Texture >> 8) is
  148. * the index into the 16-bit palette.
  149. */
  150. typedef struct {
  151. unsigned short vertices[3];
  152. unsigned short texture;
  153. } __attribute__ ((packed)) tr2_tri_t; // was tr2_face3
  154. typedef struct {
  155. unsigned short vertices[3]; //!< The 3 vertices of a tri
  156. unsigned short texture; //!< Object-texture index
  157. unsigned short lighting; //!< Transparency flag & strength of the highlight
  158. } __attribute__ ((packed)) tr4_tri_t;
  159. /*!
  160. * \brief An 8-bit texture tile (65536 bytes).
  161. *
  162. * Each byte represents a pixel whose colour
  163. * is in the 8-bit palette.
  164. */
  165. typedef struct {
  166. unsigned char tile[256 * 256];
  167. } __attribute__ ((packed)) tr2_textile8_t;
  168. /*!
  169. * \brief A 16-bit texture tile (131072 bytes).
  170. *
  171. * Each word represents a pixel
  172. * whose colour is of the form ARGB, MSB-to-LSB:
  173. *
  174. * * 1-bit transparency (0: transparent, 1: opaque)
  175. * * 5-bit red channel
  176. * * 5-bit green channel
  177. * * 5-bit blue channel
  178. */
  179. typedef struct {
  180. unsigned short tile[256 * 256];
  181. } __attribute__ ((packed)) tr2_textile16_t;
  182. /*!
  183. * \brief A 32-bit texture tile (262144 bytes).
  184. *
  185. * BGRA with 4bytes each channel.
  186. */
  187. typedef struct {
  188. unsigned int tile[256 * 256];
  189. } __attribute__ ((packed)) tr2_textile32_t;
  190. /*!
  191. * \brief The "header" of a room.
  192. *
  193. * X/Z indicate the base position of the room mesh in world coordinates.
  194. *
  195. * yLowest and yHighest indicate the lowest and highest points in this room
  196. * (even though their actual values appear to be reversed, since a "high"
  197. * point will have a smaller value than a "low" point).
  198. *
  199. * When positioning objects/items, as well as the room meshes
  200. * themselves, y is always 0-relative (not room-relative).
  201. */
  202. typedef struct {
  203. int x; //!< X-offset of room (world coordinates)
  204. int z; //!< Z-offset of room (world coordinates)
  205. int y_bottom; //!< Y-offset of lowest point in room (world coordinates, actually highest value)
  206. int y_top; //!< Y-offset of highest point in room (world coordinates, actually lowest value)
  207. } __attribute__ ((packed)) tr2_room_info_t;
  208. /*!
  209. * \brief Portal structure.
  210. *
  211. * This defines every viable exit from a given "room".
  212. *
  213. * Note that "rooms" are really just areas. They aren't
  214. * necessarily enclosed. The door structure below defines
  215. * areas of egress, not the actual moveable mesh,
  216. * texture, and action (if any).
  217. */
  218. typedef struct {
  219. unsigned short adjoining_room; //!< Which room this "door" leads to
  220. tr2_vertex_t normal; //!< Which way the "door" faces
  221. tr2_vertex_t vertices[4]; //!< The corners of the "door"
  222. } __attribute__ ((packed)) tr2_room_portal_t;
  223. /*!
  224. * \brief Room sector structure.
  225. *
  226. * Sectors are 1024 * 1024 (world coordinates). Floor and
  227. * Ceiling are signed number of 256 units of height
  228. * (relative to 0), e.g. Floor 0x04 corresponds to
  229. * Y = 1024 in world coordinates.
  230. *
  231. * Note: this implies that, while X and Z can be quite large,
  232. * Y is constrained to -32768..32512. Floor/Ceiling value of
  233. * 0x81 indicates impenetrable wall.
  234. *
  235. * Floor values are used by the game engine to determine what
  236. * objects Lara can traverse and how.
  237. *
  238. * Relative steps of 1 (-256) can be walked up;
  239. * steps of 2..7 (-512..-1792) can/must be climbed;
  240. * steps larger than 7 (-2048..-32768) cannot be climbed (too tall)
  241. *
  242. * In TR3, BoxIndex is more complicated. Only bits 4-14 are the
  243. * "real" index; bits 0-3 are most likely some kind of flag,
  244. * such as what kind of footstep sound to make (wood, metal, snow).
  245. * Furthermore, there is a special value of the "real" index,
  246. * 2047, or 0x7ff.
  247. *
  248. * RoomAbove and RoomBelow indicate what neighboring rooms are
  249. * in these directions; if RoomAbove is not "none", then the
  250. * ceiling is a collisional portal to that room, while if
  251. * RoomBelow is not "none", then the floor is a collisional
  252. * portal to that room.
  253. */
  254. typedef struct {
  255. unsigned short fd_index; //!< Index into FloorData[]
  256. unsigned short box_index; //!< Index into Boxes[]/Zones[] (-1 if none)
  257. unsigned char room_below; //!< The number of the room below this one (-1 or 255 if none)
  258. char floor; //!< Absolute height of floor (Multiply by 256 for world coordinates)
  259. unsigned char room_above; //!< The number of the room above this one (-1 or 255 if none)
  260. char ceiling; //!< Absolute height of ceiling (multiply by 256 for world coordinates)
  261. } __attribute__ ((packed)) tr2_room_sector_t;
  262. /*!
  263. * \brief Room lighting structure.
  264. *
  265. * X/Y/Z are in world coordinates.
  266. *
  267. * Lighting values seem to range from 0..8192.
  268. */
  269. typedef struct {
  270. int x;
  271. int y;
  272. int z;
  273. unsigned short intensity1;
  274. unsigned short intensity2;
  275. unsigned int fade1;
  276. unsigned int fade2;
  277. } __attribute__ ((packed)) tr2_room_light_t;
  278. typedef struct {
  279. int xPosition; //!< World coords
  280. int yPosition; //!< World coords
  281. int zPosition; //!< World coords
  282. tr2_colour_t color; //!< Three bytes rgb values
  283. unsigned char lightType; //!< Same as D3D (i.e. 2 is for spotlight)
  284. unsigned char unknown; //!< Always 0xff?
  285. unsigned char intensity;
  286. float in;
  287. float out;
  288. float length;
  289. float cutoff;
  290. float xDir, yDir, zDir; //!< Direction?
  291. } __attribute__ ((packed)) tr4_room_light_t;
  292. /*!
  293. * \brief Room vertex structure.
  294. *
  295. * This defines the vertices within a room.
  296. */
  297. typedef struct {
  298. tr2_vertex_t vertex;
  299. short lighting1; //!< Values range from 0 to 32767 in TR3, 0=dark.
  300. /*!< I think the values ranged from 0 to 8192
  301. * in TR1/2, 0=bright. */
  302. unsigned short attributes; /*!<
  303. * * 0x8000 Something to do with water surface
  304. * * 0x4000 Under water lighting modulation
  305. * and movement if viewed from
  306. * above water surface
  307. * * 0x2000 Water/quicksand surface movement
  308. * * 0x1fef Nothing?
  309. * * 0x0010 Everything?
  310. */
  311. short lighting2; //!< Seems to be the same as lighting1
  312. } __attribute__ ((packed)) tr2_vertex_room_t;
  313. /*!
  314. * \brief Sprite structure
  315. */
  316. typedef struct {
  317. short vertex; //!< Offset into vertex list
  318. short texture; //!< Offset into texture list
  319. } __attribute__ ((packed)) tr2_room_sprite_t;
  320. /*!
  321. * \brief Room mesh structure.
  322. *
  323. * This is the geometry of the "room," including
  324. * walls, floors, rocks, water, etc. It does _not_ include
  325. * objects that Lara can interact with (keyboxes,
  326. * moveable blocks, moveable doors, etc.)
  327. */
  328. typedef struct tr2_room_data_s {
  329. short num_vertices; //!< Number of vertices in the following list
  330. tr2_vertex_room_t *vertices; //!< List of vertices (relative coordinates)
  331. short num_rectangles; //!< Number of textured rectangles
  332. tr2_quad_t *rectangles; //!< List of textured rectangles
  333. short num_triangles; //!< Number of textured triangles
  334. tr2_tri_t *triangles; //!< List of textured triangles
  335. short num_sprites; //!< Number of sprites
  336. tr2_room_sprite_t *sprites; //!< List of sprites
  337. } __attribute__ ((packed)) tr2_room_data_t;
  338. /*!
  339. * \brief Room static mesh data.
  340. *
  341. * Positions and IDs of static meshes
  342. * (e.g. skeletons, spiderwebs, furniture)
  343. */
  344. typedef struct {
  345. int x; //!< Absolute position in world coordinates
  346. int y;
  347. int z;
  348. unsigned short rotation; //!< High two bits (0xc000) indicate steps of 90 degrees
  349. unsigned short intensity1;
  350. unsigned short intensity2;
  351. unsigned short object_id; //!< Which StaticMesh item to draw
  352. } __attribute__ ((packed)) tr2_room_staticmesh_t;
  353. /*!
  354. * \brief Room structure.
  355. *
  356. * Here's where all the room data comes together.
  357. */
  358. typedef struct {
  359. tr2_room_info_t info; //!< where the room exists, in world coordinates
  360. unsigned int num_data_words; //!< number of data words (bitu16)
  361. unsigned char *data; //!< the raw data from which the rest of this is derived
  362. tr2_room_data_t room_data; //!< the room mesh
  363. unsigned short num_portals; //!< number of visibility portals that leave this room
  364. tr2_room_portal_t *portals; //!< list of visibility portals
  365. unsigned short num_zsectors; //!< width of sector list
  366. unsigned short num_xsectors; //!< height of sector list
  367. tr2_room_sector_t *sector_list; //!< list of sectors in this room
  368. short intensity1;
  369. short intensity2;
  370. short light_mode;
  371. unsigned short num_lights; //!< number of lights in this room
  372. tr2_room_light_t *lights; //!< list of lights
  373. unsigned short num_static_meshes; //!< number of static meshes
  374. tr2_room_staticmesh_t *static_meshes; //!< static meshes
  375. short alternate_room;
  376. short flags; /*!< * 0x0001 - room is filled with water
  377. * * 0x0020 - Lara's ponytail gets blown by the wind */
  378. tr2_colour_t room_light_colour; //!< TR3 ONLY!
  379. tr4_room_light_t *tr4Lights; //!< TR4 ONLY!
  380. } __attribute__ ((packed)) tr2_room_t;
  381. /*!
  382. * \brief Animation structure up to TR3.
  383. */
  384. typedef struct {
  385. unsigned int frame_offset; //!< byte offset into Frames[] (divide by 2 for Frames[i])
  386. unsigned char frame_rate; //!< "ticks" per frame
  387. unsigned char frame_size; //!< number of words in Frames[] used by this animation
  388. short state_id;
  389. short unknown1;
  390. short unknown2;
  391. short unknown3;
  392. short unknown4;
  393. unsigned short frame_start; //!< first frame in this animation
  394. unsigned short frame_end; //!< last frame in this animation (numframes = (End - Start) + 1)
  395. unsigned short next_animation;
  396. unsigned short next_frame;
  397. unsigned short num_state_changes;
  398. unsigned short state_change_offset; //!< offset into StateChanges[]
  399. unsigned short num_anim_commands;
  400. unsigned short anim_command; //!< offset into AnimCommands[]
  401. } __attribute__ ((packed)) tr2_animation_t;
  402. /*!
  403. * \brief Data for an animation structure (40 bytes in TR4 vice 32 in TR1/2/3)
  404. */
  405. typedef struct {
  406. unsigned int frame_offset; //!< same meaning as in TR3
  407. unsigned char frame_rate; //!< same meaning as in TR3
  408. unsigned char frame_size; //!< same meaning as in TR3
  409. unsigned short state_id; //!< same meaning as in TR3
  410. short unknown; //!< same meaning as in TR3
  411. short speed; //!< same meaning as in TR3
  412. unsigned short accel_lo; //!< same meaning as in TR3
  413. short accel_hi; //!< same meaning as in TR3
  414. unsigned char unknown2[8]; //!< new in TR4
  415. unsigned short frame_start; //!< same meaning as in TR3
  416. unsigned short frame_end; //!< same meaning as in TR3
  417. unsigned short next_animation; //!< same meaning as in TR3
  418. unsigned short next_frame; //!< same meaning as in TR3
  419. unsigned short num_state_changes; //!< same meaning as in TR3
  420. unsigned short state_change_offset; //!< same meaning as in TR3
  421. unsigned short num_anim_commands; //!< same meaning as in TR3
  422. unsigned short anim_command; //!< same meaning as in TR3
  423. } __attribute__ ((packed)) tr4_animation_t;
  424. /*!
  425. * \brief State Change structure
  426. */
  427. typedef struct {
  428. unsigned short state_id;
  429. unsigned short num_anim_dispatches; //!< Number of dispatches (seems to always be 1..5)
  430. unsigned short anim_dispatch; //!< Offset into AnimDispatches[]
  431. } __attribute__ ((packed)) tr2_state_change_t;
  432. /*!
  433. * \brief Animation Dispatch structure
  434. */
  435. typedef struct {
  436. short low;
  437. short high;
  438. short next_animation;
  439. short next_frame;
  440. } __attribute__ ((packed)) tr2_anim_dispatch_t;
  441. /*!
  442. * \brief AnimCommand structure
  443. */
  444. typedef struct {
  445. short value;
  446. } __attribute__ ((packed)) tr2_anim_command_t;
  447. /*!
  448. * \brief MeshTree structure.
  449. *
  450. * MeshTree[] is actually groups of four ints. The first one is a
  451. * "flags" word; bit 1 (0x0002) indicates "make previous mesh an
  452. * anchor (e.g. PUSH)"; bit 0 (0x0001) indicates "return to previous
  453. * anchor (e.g. POP)".
  454. * The next three ints are X, Y, Z offsets from the last mesh position.
  455. */
  456. typedef struct {
  457. int flags; //!< 0x0001 = POP, 0x0002 = PUSH
  458. int x;
  459. int y;
  460. int z;
  461. } __attribute__ ((packed)) tr2_meshtree_t;
  462. /*!
  463. * \brief Moveable structure.
  464. *
  465. * This defines a list of contiguous meshes that
  466. * comprise one object, e.g. in WALL.TR2,
  467. *
  468. * moveable[0] = Lara (StartingMesh 0, NumMeshes 15),
  469. * moveable[13] = Tiger (StartingMesh 215, NumMeshes 27)
  470. * moveable[15] = Spikes (StartingMesh 249, NumMeshes 1)
  471. * moveable[16] = Boulder (StartingMesh 250, NumMeshes 1)
  472. * moveable[20] = Rolling Blade (StartingMesh 254, NumMeshes 1)
  473. */
  474. typedef struct {
  475. unsigned int object_id; //!< Item Identifier
  476. unsigned short num_meshes; //!< number of meshes in this object
  477. unsigned short starting_mesh; //!< first mesh
  478. unsigned int mesh_tree; //!< offset into MeshTree[]
  479. unsigned int frame_offset; //!< byte offset into Frames[] (divide by 2 for Frames[i])
  480. unsigned short animation; //!< offset into Animations[]
  481. } __attribute__ ((packed)) tr2_moveable_t;
  482. /*!
  483. * \brief StaticMesh structure.
  484. *
  485. * This defines meshes that don't move (e.g. skeletons
  486. * lying on the floor, spiderwebs, etc.)
  487. */
  488. typedef struct {
  489. unsigned int object_id; //!< Item Identifier
  490. unsigned short starting_mesh; //!< first mesh
  491. tr2_vertex_t bounding_box[2][2];
  492. unsigned short flags;
  493. } __attribute__ ((packed)) tr2_staticmesh_t;
  494. /*!
  495. * \brief Object texture vertex structure.
  496. *
  497. * Maps coordinates into texture tiles.
  498. */
  499. typedef struct {
  500. unsigned char xcoordinate;
  501. unsigned char xpixel;
  502. unsigned char ycoordinate;
  503. unsigned char ypixel;
  504. } __attribute__ ((packed)) tr2_object_texture_vert_t;
  505. /*!
  506. * \brief Object texture structure.
  507. */
  508. typedef struct {
  509. unsigned short transparency_flags; /*!< * 0: Opaque
  510. * * 1: Use transparency
  511. * * 2: Use partial transparency
  512. * [grayscale intensity :: transparency]
  513. */
  514. unsigned short tile; //!< index into textile list
  515. tr2_object_texture_vert_t vertices[4]; //!< the four corners of the texture
  516. } __attribute__ ((packed)) tr2_object_texture_t;
  517. /*!
  518. * \brief Sprite texture structure.
  519. */
  520. typedef struct {
  521. unsigned short tile;
  522. unsigned char x;
  523. unsigned char y;
  524. unsigned short width; //!< Actually, (width * 256) + 255
  525. unsigned short height; //!< Actually, (height * 256) + 255
  526. short left_side;
  527. short top_side;
  528. short right_side;
  529. short bottom_side;
  530. } __attribute__ ((packed)) tr2_sprite_texture_t;
  531. /*!
  532. * \brief Sprite Sequence structure
  533. */
  534. typedef struct {
  535. int object_id; //!< Item identifier (same numbering as in tr2_moveable)
  536. short negative_length; //!< Negative of "how many sprites are in this sequence"
  537. short offset; //!< Where (in sprite texture list) this sequence starts
  538. } __attribute__ ((packed)) tr2_sprite_sequence_t;
  539. /*!
  540. * \brief Mesh structure.
  541. *
  542. * The mesh list contains the mesh info for Lara (in all her
  543. * various incarnations), blocks, enemies (tigers, birds, bad guys),
  544. * moveable blocks, zip line handles, boulders, spinning blades,
  545. * you name it.
  546. *
  547. * If NumNormals is negative, Normals[] represent vertex
  548. * lighting values (one per vertex).
  549. */
  550. typedef struct {
  551. tr2_vertex_t centre; /*!< \brief This seems to describe the
  552. * approximate geometric centre
  553. * of the mesh (possibly the centre of gravity?)
  554. * (relative coordinates, just like the vertices) */
  555. int collision_size; //!< radius of collisional sphere
  556. short num_vertices; //!< number of vertices in this mesh
  557. tr2_vertex_t *vertices; //!< list of vertices (relative coordinates)
  558. short num_normals; //!< number of normals in this mesh (should always equal NumVertices)
  559. tr2_vertex_t *normals; //!< list of normals (NULL if NumNormals < 0)
  560. short *mesh_lights; //!< if NumNormals < 0
  561. short num_textured_rectangles; //!< number of textured rectangles
  562. tr2_quad_t *textured_rectangles; //!< list of textured rectangles
  563. short num_textured_triangles; //!< number of textured triangles in this mesh
  564. tr2_tri_t *textured_triangles; //!< list of textured triangles
  565. short num_coloured_rectangles; //!< number of coloured rectangles
  566. tr2_quad_t *coloured_rectangles; //!< list of coloured rectangles
  567. short num_coloured_triangles; //!< number of coloured triangles in this mesh
  568. tr2_tri_t *coloured_triangles; //!< list of coloured triangles
  569. } __attribute__ ((packed)) tr2_mesh_t;
  570. /*!
  571. * \brief Frame structure.
  572. *
  573. * Frames indicates how composite meshes are positioned and rotated.
  574. * They work in conjunction with Animations[] and Bone2[].
  575. *
  576. * A given frame has the following format:
  577. *
  578. * short BB1x, BB1y, BB1z // bounding box (low)
  579. * short BB2x, BB2y, BB2z // bounding box (high)
  580. * short OffsetX, OffsetY, OffsetZ // starting offset for this moveable
  581. * (TR1 ONLY: short NumValues // number of angle sets to follow)
  582. * (TR2/3: NumValues is implicitly NumMeshes (from moveable))
  583. *
  584. * What follows next is a list of angle sets. In TR2/3, an angle set can
  585. * specify either one or three axes of rotation. If either of the high two
  586. * bits (0xc000) of the first angle unsigned short are set, it's one axis:
  587. *
  588. * only one unsigned short,
  589. * low 10 bits (0x03ff),
  590. * scale is 0x100 == 90 degrees;
  591. *
  592. * the high two bits are interpreted as follows:
  593. *
  594. * 0x4000 == X only, 0x8000 == Y only,
  595. * 0xC000 == Z only.
  596. *
  597. * If neither of the high bits are set, it's a three-axis rotation. The next
  598. * 10 bits (0x3ff0) are the X rotation, the next 10 (including the following
  599. * unsigned short) (0x000f, 0xfc00) are the Y rotation,
  600. * the next 10 (0x03ff) are the Z rotation, same scale as
  601. * before (0x100 == 90 degrees).
  602. *
  603. * Rotations are performed in Y, X, Z order.
  604. * TR1 ONLY: All angle sets are two words and interpreted like the two-word
  605. * sets in TR2/3, EXCEPT that the word order is reversed.
  606. */
  607. typedef struct {
  608. tr2_vertex_t vector[3];
  609. int num_words;
  610. unsigned short *words;
  611. } __attribute__ ((packed)) tr2_frame_t;
  612. /*!
  613. * \brief Item structure
  614. */
  615. typedef struct {
  616. short object_id;
  617. short room;
  618. int x;
  619. int y;
  620. int z;
  621. short angle;
  622. short intensity1;
  623. short intensity2;
  624. short flags; //!< 0x0100 indicates "inactive" or "invisible"
  625. } __attribute__ ((packed)) tr2_item_t;
  626. /*!
  627. * \brief SoundSource structure
  628. */
  629. typedef struct {
  630. int x; //!< position of sound source
  631. int y;
  632. int z;
  633. unsigned short sound_id; //!< internal sound index
  634. unsigned short flags; //!< 0x40, 0x80, or 0xc0
  635. } __attribute__ ((packed)) tr2_sound_source_t;
  636. /*!
  637. * \brief Boxes structure
  638. */
  639. typedef struct {
  640. unsigned char zmin; //!< sectors (* 1024 units)
  641. unsigned char zmax;
  642. unsigned char xmin;
  643. unsigned char xmax;
  644. short true_floor; //!< Y value (no scaling)
  645. short overlap_index; //!< index into Overlaps[]
  646. } __attribute__ ((packed)) tr2_box_t;
  647. /*!
  648. * \brief AnimatedTexture structure.
  649. *
  650. * - really should be simple short[], since it's variable length
  651. */
  652. typedef struct {
  653. short num_texture_ids; //!< Number of Texture IDs - 1
  654. short *texture_list; //!< list of textures to cycle through
  655. } __attribute__ ((packed)) tr2_animated_texture_t;
  656. /*!
  657. * \brief Camera structure
  658. */
  659. typedef struct {
  660. int x;
  661. int y;
  662. int z;
  663. short room;
  664. unsigned short unknown1; //!< correlates to Boxes[]?
  665. } __attribute__ ((packed)) tr2_camera_t;
  666. /*
  667. * \brief Data for a flyby camera (40 bytes)
  668. */
  669. typedef struct {
  670. int pos[6]; //!< Positions ? (x1,y1,z1,x2,y2,z2) roatations?
  671. unsigned char index[2]; //!< A pair of indices
  672. unsigned short unknown[5]; //!< ??
  673. int id; //!< Index of something
  674. } __attribute__ ((packed)) tr4_extra_camera_t;
  675. /*!
  676. * \brief Sound sample structure
  677. */
  678. typedef struct {
  679. short sample;
  680. short volume;
  681. short sound_range;
  682. short flags; /*!< \ brief bits 8-15: priority?, 2-7: number of sound samples
  683. * in this group, bits 0-1: channel number */
  684. } __attribute__ ((packed)) tr2_sound_details_t;
  685. /*!
  686. * \brief Cutscene Camera structure
  687. */
  688. typedef struct {
  689. short roty; //!< Rotation about Y axis, +/-32767 ::= +/- 180 degrees
  690. short rotz; //!< Rotation about Z axis, +/-32767 ::= +/- 180 degrees
  691. short rotz2; //!< Rotation about Z axis (why two?), +/-32767 ::= +/- 180 degrees
  692. short posz; //!< Z position of camera, relative to something
  693. short posy; //!< Y position of camera, relative to something
  694. short posx; //!< X position of camera, relative to something
  695. short unknown1;
  696. short rotx; //!< Rotation about X axis, +/-32767 ::= +/- 180 degrees
  697. } __attribute__ ((packed)) tr2_cinematic_frame_t;
  698. /*!
  699. * \brief Data for a AI object (24 bytes).
  700. *
  701. * this field replaces the bitu16 NumCinematicFrames of TR1/2/3 levels
  702. *
  703. * Used to read TR4 AI data
  704. */
  705. typedef struct {
  706. unsigned short int object_id; //!< the objectID from the AI object
  707. //!< (AI_FOLLOW is 402)
  708. unsigned short int room;
  709. int x, y, a;
  710. unsigned short int ocb;
  711. unsigned short int flags; //!< The trigger flags
  712. //!< (button 1-5, first button has value 2)
  713. int angle; //!< rotation
  714. } __attribute__ ((packed)) tr4_ai_object_t;
  715. /*!
  716. * \brief Used to read packed TR4 texels
  717. */
  718. typedef struct {
  719. unsigned short attribute; //!< same meaning as in TR3
  720. unsigned short tile; //!< same meaning as in TR3
  721. unsigned short flags; //!< new in TR4
  722. tr2_object_texture_vert_t vertices[4]; //!< same meaning as in TR3
  723. unsigned int unknown1, unknown2; //!< new in TR4: x & y offset in something
  724. unsigned int xsize, ysize; //!< new in TR4: width-1 & height-1 of the object texture
  725. } __attribute__ ((packed)) tr4_object_texture_t;
  726. /*!
  727. * \brief TR5 Room Layer (56 bytes)
  728. */
  729. typedef struct {
  730. uint32_t numLayerVertices; //!< number of vertices in this layer (4 bytes)
  731. uint16_t unknownL1; //!< unknown (2 bytes)
  732. uint16_t numLayerRectangles; //!< number of rectangles in this layer (2 bytes)
  733. uint16_t numLayerTriangles; //!< number of triangles in this layer (2 bytes)
  734. uint16_t unknownL2; //!< appears to be the number of 2 sided textures
  735. //!< in this layer, however is sometimes 1 off (2 bytes)
  736. uint16_t filler; //!< always 0 (2 bytes)
  737. uint16_t filler2; //!< always 0 (2 bytes)
  738. float layerBoundingBoxX1; //!< These 6 floats (4 bytes each) define the bounding box for the layer
  739. float layerBoundingBoxY1;
  740. float layerBoundingBoxZ1;
  741. float layerBoundingBoxX2;
  742. float layerBoundingBoxY2;
  743. float layerBoundingBoxZ2;
  744. uint32_t filler3; //!< always 0 (4 bytes)
  745. uint32_t unknownL6; //!< unknown (4 bytes)
  746. uint32_t unknownL7; //!< unknown (4 bytes)
  747. uint32_t unknownL8; //!< unknown. Always the same throughout the level. (4 bytes)
  748. } tr5_room_layer_t;
  749. /*!
  750. * \brief TR5 Quad (12 bytes)
  751. */
  752. typedef struct {
  753. uint16_t vertices[4]; //!< the values are the indices into the
  754. //!< appropriate layer vertice list. (2 bytes each)
  755. uint16_t texture; //!< the texture number for this face. Needs to be masked
  756. //!< with 0xFFF as the high 4 bits are flags (2 bytes)
  757. uint16_t unknownF4; //!< unknown (2 bytes)
  758. } tr5_face4_t;
  759. /*!
  760. * \brief TR5 triangular face (10 bytes)
  761. */
  762. typedef struct {
  763. uint16_t vertices[3]; //!< the values are the indices into the
  764. //!< appropriate layer vertice list (2 bytes each)
  765. uint16_t texture; //!< the texture number for this face. Needs to be masked
  766. //!< with 0xFFF as the high 4 bits are flags (2 bytes)
  767. uint16_t unknownF3; //!< unknown (2 bytes)
  768. } tr5_face3_t;
  769. /*!
  770. * \brief TR5 Vertex (28 bytes)
  771. */
  772. typedef struct {
  773. float x; //!< x of vertex (4 bytes)
  774. float y; //!< y of vertex (4 bytes)
  775. float z; //!< z of vertex (4 bytes)
  776. float nx; //!< x of vertex normal (4 bytes)
  777. float ny; //!< y of vertex normal (4 bytes)
  778. float nz; //!< z of vertex normal (4 bytes)
  779. uint32_t vColor; //!< vertex color ARGB format (4 bytes)
  780. } tr5_vertex_t;
  781. /*!
  782. * \brief This is to help store and manage TR5 layer based polgons for rooms
  783. */
  784. typedef struct {
  785. tr5_face4_t *quads;
  786. tr5_face3_t *tris;
  787. tr5_vertex_t *verts;
  788. } tr5_room_geometry_t;
  789. /*!
  790. * \brief TR5 light (88 bytes)
  791. */
  792. typedef struct {
  793. float x; //!< x position of light (4 bytes)
  794. float y; //!< y position of light (4 bytes)
  795. float z; //!< z position of light (4 bytes)
  796. /*!< Maybe wrong: The (x, y, z) floats specify the position of the light
  797. * in world coordinates.
  798. *
  799. * The sun type light should not use these but seems to have a
  800. * large x value (9 million, give or take)
  801. * a zero y value, and a small z value (4 - 20) in the original TR5 levels
  802. */
  803. float red; //!< color of red spectrum (4 bytes)
  804. float green; //!< color of green spectrum (4 bytes)
  805. float blue; //!< color of blue spectrum (4 bytes)
  806. uint32_t seperator; //!< not used 0xCDCDCDCD (4 bytes)
  807. float input; //!< cosine of the IN value for light / size of IN value (4 bytes)
  808. float output; //!< cosine of the OUT value for light / size of OUT value (4 bytes)
  809. /*!< At this point the info diverges dependant
  810. * on which type of light being used:
  811. *
  812. * 0 = sun, 1 = light, 2 = spot, 3 = shadow
  813. *
  814. * The sun type doesn't use input and output.
  815. *
  816. * For the spot type these are the hotspot and falloff angle cosines.
  817. *
  818. * For the light and shadow types these are the TR units
  819. * for the hotspot/falloff (1024=1sector).
  820. */
  821. float radInput; //!< (IN radians) * 2 (4 bytes)
  822. float radOutput; //!< (OUT radians) * 2 (4 bytes)
  823. //!< radInput and radOutput are only used by the spot type light
  824. float range; //!< Range of light (4 bytes), only used by the spot type light
  825. float directionVectorX; //!< light direction (4 bytes)
  826. float directionVectorY; //!< light direction (4 bytes)
  827. float directionVectorZ; //!< light direction (4 bytes)
  828. /*!< The 3 directionVector floats are used only by the 'sun' and 'spot' type lights.
  829. * They describe the directional vector of the light.
  830. * This can be obtained by:
  831. *
  832. * if both x and y LightDirectionVectorX = cosX * sinY
  833. *
  834. * LightDirectionVectorY = sinX
  835. * LightDirectionVectorZ = cosX * cosY
  836. */
  837. int32_t x2; //!< x position of light (4 bytes)
  838. int32_t y2; //!< y position of light (4 bytes)
  839. int32_t z2; //!< z position of light (4 bytes)
  840. /*!<
  841. * x2, y2, z2 and the directionVectors-2 repeat some of the
  842. * previous information in long data types vice floats
  843. */
  844. int32_t directionVectorX2; //!< light direction (4 bytes)
  845. int32_t directionVectorY2; //!< light direction (4 bytes)
  846. int32_t directionVectorZ2; //!< light direction (4 bytes)
  847. //!< 16384 = 1.0 for the rotations (1/16384)
  848. uint8_t lightType; //!< type of light as specified above (1 byte)
  849. uint8_t seperator2[3]; //!< 0xCDCDCD (3 bytes)
  850. } tr5_light_t;
  851. /*!
  852. * \brief TR5 Room.
  853. *
  854. * First number is offset in bytes from start of room structure.
  855. */
  856. typedef struct {
  857. uint32_t checkXELA; //!< "XELA" (4 bytes)
  858. uint32_t roomDataSize; /*!< size of the following data ( use this vice
  859. * 'walking thru' to get next room) (4 bytes) */
  860. uint32_t seperator; //!< 0xCDCDCDCD (4 bytes)
  861. uint32_t endSDOffset; /*!< usually this number + 216 will give you the
  862. * offset from the start of the room data to the end
  863. * of the Sector Data. HOWEVER have seen where this
  864. * bitu32 is equal to -1 so it is better to use the
  865. * following bitu32 and + 216 +
  866. * ((NumXSectors * NumZSectors)*8) if you need
  867. * to obtain this information. (4 bytes) */
  868. uint32_t startSDOffset; /*!< this number + 216 will give you the offset from
  869. * the start of the room to the start of the
  870. * sector data. (4 bytes) */
  871. uint32_t seperator2; //!< will either be 0x00000000 or 0xCDCDCDCD (4 bytes)
  872. uint32_t endPortalOffset; /*!< this number + 216 will give you the offset
  873. * from the start of the room to the end of the
  874. * portal data. (4 bytes) */
  875. int32_t x; //!< X position of room ( world coordinates) (4 bytes)
  876. int32_t seperator3; //!< 0x00000000 (4 bytes)
  877. int32_t z; //!< Z position of room (world coordinates) (4 bytes)
  878. int32_t yBottom; //!< lowest point in room (4 bytes)
  879. int32_t yTop; //!< highest point in room (4 bytes)
  880. uint16_t numZSectors; //!< sector table width (2 bytes)
  881. uint16_t numXSectors; //!< sector table height (2 bytes)
  882. uint32_t roomAmbientColor; //!< ARGB format (blue is least significant byte) (4 bytes)
  883. uint16_t numRoomLights; //!< number of lights in this room (2 bytes)
  884. uint16_t numStaticMeshes; //!< number of static meshes in this room (2 bytes)
  885. uint16_t unknownR1; //!< usually 0x0001 however high byte is sometimes non zero (2 bytes)
  886. uint16_t unknownR2; //!< usually 0x0000 however low byte is sometimes non zero (2 bytes)
  887. uint32_t filler; //!< always 0x00007FFF (4 bytes)
  888. uint32_t filler2; //!< always 0x00007FFF (4 bytes)
  889. uint32_t seperator4; //!< 0xCDCDCDCD (4 bytes)
  890. uint32_t seperator5; //!< 0xCDCDCDCD (4 bytes)
  891. unsigned char seperator6[6]; //!< 6 bytes 0xFF
  892. uint16_t roomFlag; //!< 0x01 = water, 0x20 = wind, others unknown (2 bytes)
  893. uint16_t unknownR5; //!< unknown (2 bytes)
  894. unsigned char seperator7[10]; //!< 10 bytes 0x00
  895. uint32_t seperator8; //!< 0xCDCDCDCD (4 bytes)
  896. uint32_t unknownR6; //!< unknown (4 bytes)
  897. float roomX; //!< X position of room in world coordinates
  898. //!< If null room then this data will be 0xCDCDCDCD (4 bytes)
  899. uint32_t seperator9; //!< 0x00000000 or 0xCDCDCDCD if null room. (4 bytes)
  900. float roomZ; //!< Z position of room in world coordinates
  901. //!< If null room then will be bitu32 0xCDCDCDCD (4 bytes)
  902. uint32_t seperator10; //!< 0xCDCDCDCD (4 bytes)
  903. uint32_t seperator11; //!< 0xCDCDCDCD (4 bytes)
  904. uint32_t seperator12; //!< 0xCDCDCDCD (4 bytes)
  905. uint32_t seperator13; //!< 0xCDCDCDCD (4 bytes)
  906. uint32_t seperator14; //!< 0x00000000 unless null room then 0xCDCDCDCD (4 bytes)
  907. uint32_t seperator15; //!< 0xCDCDCDCD (4 bytes)
  908. uint32_t numRoomTriangles; //!< total number of triangles this room (4 bytes)
  909. uint32_t numRoomRectangles; //!< total number of rectangles this room (4 bytes)
  910. uint32_t seperator16; //!< 0x00000000 (4 bytes)
  911. uint32_t lightSize; //!< size of light data (number of lights * 88) (4 bytes)
  912. uint32_t numTotalRoomLights; //!< total number of lights this room (4 bytes)
  913. uint32_t unknownR7; //!< unknown, usually equals 0, 1, 2, or 3 (4 bytes)
  914. int32_t unknownR8; //!< usually equals room yTop. Sometimes a few blocks off.
  915. //!< If null room then 0xCDCDCDCD
  916. int32_t lyBottom; //!< equals room yBottom. If null room then 0xCDCDCDCD (4 bytes)
  917. uint32_t numLayers; //!< number of layers (pieces) this room (4 bytes)
  918. uint32_t layerOffset; //!< this number + 216 will give you an offset from the start
  919. //!< of the room data to the start of the layer data (4 bytes)
  920. uint32_t verticesOffset; //!< this number + 216 will give you an offset from the start
  921. //!< of the room data to the start of the verex data (4 bytes)
  922. uint32_t polyOffset; //!< this number + 216 will give you an offset from the start
  923. //!< of the room data to the start of the rectangle/triangle data (4 bytes)
  924. uint32_t polyOffset2; //!< same as above ? (4 bytes)
  925. uint32_t verticesSize; //!< size of vertices data block (4 bytes)
  926. uint32_t seperator17; //!< 0xCDCDCDCD (4 bytes)
  927. uint32_t seperator18; //!< 0xCDCDCDCD (4 bytes)
  928. uint32_t seperator19; //!< 0xCDCDCDCD (4 bytes)
  929. uint32_t seperator20; //!< 0xCDCDCDCD (4 bytes)
  930. tr5_light_t *lights; //!< [LightSize];
  931. //!< data for the lights (88 bytes * NumRoomLights)
  932. tr2_room_sector_t *sectors; //!< Data[(NumXSectors * NumZSectors) * 8];
  933. //!< normal sector data structure
  934. uint16_t numDoors; //!< number of portals (2 bytes)
  935. tr2_room_portal_t *doors; //!< [NumDoors];
  936. //!< normal portal structure (32 bytes * NumDoors)
  937. uint16_t seperator21; //!< 0xCDCD (2 bytes)
  938. tr2_room_staticmesh_t *meshes; //!< [NumStaticMeshes];
  939. //!< normal room static mesh structure (20 bytes * NumRoomStaticMeshes)
  940. tr5_room_layer_t *layers; //!< [NumLayers];
  941. //!< data for the room layers (pieces) (56 bytes * NumLayers)
  942. tr5_room_geometry_t *faces; //!< [NumRoomRectangles + NumRoomTriangles];
  943. /* Data for the room polys (face4 and face3).
  944. * Structured as first layers rectangles
  945. * then triangles, followed by the
  946. * next layers rectangles and triangles, etc.,
  947. * until all layers are done.
  948. * (12 bytes each rectangle. 10 bytes each triangle)
  949. */
  950. tr5_vertex_t *vertices; //!< [VerticesSize];
  951. /*!< Data for the room vertices.
  952. * Structured as vertices for the first layer,
  953. * then vertices for the second layer, etc.,
  954. * until all layers are done.
  955. * (28 bytes each vertex.
  956. */
  957. } tr5_room_t;
  958. /*!
  959. * \brief TR5 Object Texture Vertex (4 bytes)
  960. */
  961. typedef struct {
  962. uint8_t xCoordinate; //!< 0 if Xpixel is the low value,
  963. //!< 255 if Xpixel is the high value in the object texture (1 byte)
  964. uint8_t xPixel; //!< (1 byte)
  965. uint8_t yCoordinate; //!< 0 if Ypixel is the low value,
  966. //!< 255 if Ypixel is the high value in the object texture (1 byte)
  967. uint8_t yPixel; //!< (1 byte)
  968. } tr5_object_texture_vertex_t;
  969. /*!
  970. * \brief TR5 Object Texture (40 bytes)
  971. */
  972. typedef struct {
  973. uint16_t attribute; //!< 0, 1, or 2 (2 means 2 sided) (2 bytes)
  974. uint32_t tile; //!< need to mask with 0xFF as other bits are flags.
  975. //!< ie int15_t seems to indicate triangle (4 bytes)
  976. tr5_object_texture_vertex_t vertices[4]; //!< Vertices[4] (16 bytes)
  977. uint32_t uv1; //!< unknown how used (4 bytes)
  978. uint32_t uv2; //!< unknown how used (4 bytes)
  979. uint32_t xSize; //!< unknown how used, x size (4 bytes)
  980. uint32_t ySize; //!< unknown how used, y size (4 bytes)
  981. uint16_t seperator; //!< always 0x0000 (2 bytes)
  982. } tr5_object_texture_t;
  983. /*!
  984. * \brief TR5 Flyby camera (40 bytes)
  985. */
  986. typedef struct {
  987. int32_t cameraX; //!< x position of camera in world coordinates (4 bytes)
  988. int32_t cameraY; //!< y position of camera in world coordinates (4 bytes)
  989. int32_t cameraZ; //!< z position of camera in world coordinates (4 bytes)
  990. int32_t targetX; //!< x position of aiming point in world coords (4 bytes)
  991. int32_t targetY; //!< y position of aiming point in world coords (4 bytes)
  992. int32_t targetZ; //!< z position of aiming point in world coords (4 bytes)
  993. int8_t sequence; //!< sequence # of camera (1 byte)
  994. int8_t cameraNumber; //!< camera # (1 byte)
  995. uint16_t fov; //!< fov of camera ( .0054945 for each degree ) (2 bytes)
  996. uint16_t roll; //!< roll of camera ( .0054945 for each degree ) (2 bytes)
  997. uint16_t timer; //!< timer number (2 bytes)
  998. uint16_t speed; //!< ( .000015259 each ) (2 bytes)
  999. uint16_t flags; //!< ( see your handy TRLE manual for the specs ) (2 bytes)
  1000. uint32_t room; //!< room number (4 bytes)
  1001. } tr5_flyby_camera_t;
  1002. /*!
  1003. * \brief TR5 Moveable (20 bytes).
  1004. *
  1005. * Same as old structure but has uint16_t filler at the end
  1006. */
  1007. typedef struct {
  1008. uint32_t objectId; //!< object identifier ( matched in Items[] )
  1009. uint16_t numMeshes; //!< number of meshes in this object
  1010. uint16_t startingMesh; //!< starting mesh ( offset into MeshPointers[] )
  1011. uint32_t meshTree; //!< offset into MeshTree[] )
  1012. uint32_t frameOffset; //!< byte offset into Frames[] ( divide by 2 for Frames[i] )
  1013. uint16_t animation; //!< offset into Animations[]
  1014. uint16_t filler; //!< always equal to 65519 ( 0xFFEF )
  1015. } tr5_moveable_t;
  1016. typedef struct {
  1017. tr2_vertex_t center; //!< relative coordinates of mesh centre (6 bytes)
  1018. uint8_t unknown1[4]; //!< unknown (4 bytes)
  1019. int16_t numVertices; //!< number of vertices to follow (2 bytes)
  1020. tr2_vertex_t *vertices; //!< list of vertices (NumVertices * 6 bytes)
  1021. int16_t numNormals; //!< number of normals to follow (2 bytes)
  1022. tr2_vertex_t *normals; //!< list of normals (NumNormals * 6 bytes)
  1023. //!< (becomes Lights if NumNormals < 0; 2 bytes)
  1024. int16_t numTexturedRectangles; //!< number of textured rectangles to follow (2 bytes)
  1025. tr5_face4_t *texturedRectangles; //!< list of textured rectangles (NumTexturedRectangles * 12 bytes)
  1026. int16_t numTexturedTriangles; //!< number of textured triangles to follow (2 bytes)
  1027. tr5_face3_t *texturedTriangles; //!< list of textured triangles (NumTexturedTriangles * 10 bytes)
  1028. } tr5_mesh_t;
  1029. /*!
  1030. * \brief TR5 Animation (40 bytes).
  1031. *
  1032. * Same as old structure but has 8 bytes before FrameStart.
  1033. */
  1034. typedef struct {
  1035. uint32_t FrameOffset; //!< byte offset into Frames[] ( divide by 2 for Frames[i] )
  1036. uint8_t FrameRate; //!< Engine ticks per frame
  1037. uint8_t FrameSize; //!< number of int16_t's in Frames[] used by this animation
  1038. uint16_t StateId;
  1039. int16_t Unknown;
  1040. int16_t Speed; //!< Evengi Popov found this but I never seen what he said it was for
  1041. uint16_t AccelLo; //!< same as above
  1042. int16_t AccelHi; //!< same as above
  1043. uint8_t AUnknown[8]; //!< Unknown
  1044. uint16_t FrameStart; //!< first frame in this animation
  1045. uint16_t FrameEnd; //!< last frame in this animation ( numframes = ( End - Start) + 1 )
  1046. uint16_t NextAnimation;
  1047. uint16_t NextFrame;
  1048. uint16_t NumStateChanges;
  1049. uint16_t StateChangeOffset; //!< offset into StateChanges[]
  1050. uint16_t NumAnimCommands; //!< how many of them to use
  1051. uint16_t AnimCommand; //!< offset into AnimCommand[]
  1052. } tr5_animation_t;
  1053. typedef struct {
  1054. unsigned int unknown[24];
  1055. } tr5_cinematic_frame_t;
  1056. #ifdef WIN32
  1057. #pragma pack(pop, tr2_h, 1)
  1058. #endif
  1059. /*!
  1060. * \brief Loads maps, meshes, textures...
  1061. */
  1062. class TombRaider {
  1063. public:
  1064. /*!
  1065. * \brief Constructs an object of TombRaider
  1066. */
  1067. TombRaider();
  1068. /*!
  1069. * \brief Deconstructs an object of TombRaider
  1070. */
  1071. ~TombRaider();
  1072. ////////////////////////////////////////
  1073. // Wash me -- not part of cleaned API //
  1074. ////////////////////////////////////////
  1075. int NumRooms();
  1076. int NumMoveables();
  1077. int NumTextures();
  1078. /*!
  1079. * \brief Get number of _special_ textures/images
  1080. * \returns number of special textures/images
  1081. */
  1082. int NumSpecialTextures();
  1083. int NumAnimations();
  1084. unsigned int NumFrames();
  1085. int NumStaticMeshes();
  1086. int NumSprites();
  1087. int NumSpriteSequences();
  1088. int NumItems();
  1089. tr2_version_type Engine();
  1090. unsigned short *Frame();
  1091. tr2_animation_t *Animation();
  1092. tr2_item_t *Item();
  1093. tr2_object_texture_t *ObjectTextures();
  1094. /*!
  1095. * \brief Get number of boxes
  1096. * \returns number of boxes
  1097. */
  1098. unsigned int getNumBoxes();
  1099. tr2_box_t *Box();
  1100. tr2_mesh_t *Mesh();
  1101. /*!
  1102. * \brief Get number of animations for a moveable
  1103. * \param moveable_index valid moveable id
  1104. * \returns number of animations for specified moveable
  1105. */
  1106. int getNumAnimsForMoveable(int moveable_index);
  1107. tr2_staticmesh_t *StaticMesh();
  1108. tr2_moveable_t *Moveable();
  1109. tr2_meshtree_t *MeshTree();
  1110. /*!
  1111. * \brief Get the sprites
  1112. * \returns the sprite array
  1113. */
  1114. tr2_sprite_texture_t *Sprite();
  1115. tr2_sprite_sequence_t *SpriteSequence();
  1116. /*!
  1117. * \brief Makes a 32bit RGBA image from a stexture/bmap
  1118. * \param texture valid index into tex_special list
  1119. * \returns 32bit RGBA image or NULL on error
  1120. */
  1121. unsigned char *SpecialTexTile(int texture);
  1122. /*!
  1123. * \brief Get copies of texture and it's bumpmap
  1124. * \param texture valid textile index
  1125. * \param image will be set to texture if found, or NULL
  1126. * \param bumpmap will be set to bumpmap if found, or NULL
  1127. */
  1128. void Texture(int texture, unsigned char **image, unsigned char **bumpmap);
  1129. unsigned int *Palette16();
  1130. unsigned char *Palette8();
  1131. tr2_room_t *Room();
  1132. /*!
  1133. * \brief Check if a file is a TombRaider pak
  1134. * \param filename file to check
  1135. * \returns 0 if it is a TombRaider pak
  1136. */
  1137. int checkMime(char *filename);
  1138. /*!
  1139. * \brief Loads TombRaider 1-5 pak into memory
  1140. * and does some processing.
  1141. *
  1142. * At 10% all textures are loaded. The exact figure
  1143. * '10' will always be passed to allow for texture
  1144. * caching while meshes load for TR4.
  1145. * \param filename points to valid TombRaider pak
  1146. * \param percent load progress callback
  1147. * \returns 0 on success, < 0 on error
  1148. * \sa TombRaider::loadTR5()
  1149. */
  1150. int Load(char *filename, void (*percent)(int, void *), void *obj);
  1151. /*!
  1152. * \brief Makes a clamped 0.0 to 1.0 texel from coord pair
  1153. * \param texel texel value, is modified, divided by 255.0 and returned
  1154. * \param offset if offset is negative, texel is decreased by one, else increased
  1155. * \returns modified texel divided by 255.0
  1156. */
  1157. float adjustTexel(unsigned char texel, char offset);
  1158. /*!
  1159. * \brief Compute rotation angles from moveable animation data
  1160. * \param frame moveable animation data
  1161. * \param frame_offset moveable animation data
  1162. * \param angle_offset moveable animation data
  1163. * \param x will be set to computed angle
  1164. * \param y will be set to computed angle
  1165. * \param z will be set to computed angle
  1166. */
  1167. void computeRotationAngles(unsigned short **frame,
  1168. unsigned int *frame_offset,
  1169. unsigned int *angle_offset,
  1170. float *x, float *y, float *z);
  1171. /*!
  1172. * \brief Returns computed UV in u and v
  1173. * \param st object texture vert, its coordinates are added to the pixels and divided by 255.0
  1174. * \param u will contain calculated x value
  1175. * \param v will contain calculated y value
  1176. */
  1177. void computeUV(tr2_object_texture_vert_t *st, float *u, float *v);
  1178. /*!
  1179. * \brief Get number of bump maps in loaded pak
  1180. * \returns number of bump maps
  1181. */
  1182. int getBumpMapCount();
  1183. void getColor(int index, float color[4]);
  1184. tr2_version_type getEngine();
  1185. /*!
  1186. * \brief Get the collision sphere for a mesh
  1187. * \param meshIndex mesh index
  1188. * \param center will be filled with center coordinates, not NULL
  1189. * \param radius will be filled with radius, not NULL
  1190. */
  1191. void getMeshCollisionInfo(unsigned int meshIndex,
  1192. float center[3], float *radius);
  1193. /*!
  1194. * \brief Get SIGNED mesh count (TR encoded < 0 errors)
  1195. * \returns signed mesh count
  1196. */
  1197. int getMeshCount();
  1198. /*!
  1199. * \brief This method is made to let you fill arrays or
  1200. * create single faces. There may be an allocatin version that
  1201. * passes back arrays later.
  1202. * Returns Quads/Rects as 2 triangles,
  1203. * because returning quads would be too trivial :)
  1204. * \param meshIndex mesh index
  1205. * \param faceIndex face index
  1206. * \param index allocated RGBA
  1207. * \param color allocated RGBA
  1208. * \fixme This method interface may change later
  1209. */
  1210. void getMeshColoredRectangle(unsigned int meshIndex,
  1211. unsigned int faceIndex,
  1212. int index[6], float color[4]);
  1213. /*!
  1214. * \brief This method is made to let you fill arrays or
  1215. * create single faces. There may be an allocating version that
  1216. * passes back arrays later.
  1217. * \param meshIndex mesh index
  1218. * \param faceIndex face index
  1219. * \param index allocated RGBA
  1220. * \param color allocated RGBA
  1221. * \fixme This method interface may change later
  1222. */
  1223. void getMeshColoredTriangle(unsigned int meshIndex,
  1224. unsigned int faceIndex,
  1225. int index[3], float color[4]);
  1226. /*!
  1227. * \brief This method is made to let you fill arrays or
  1228. * create single faces. There may be an allocatin version that
  1229. * passes back arrays later.
  1230. * Returns Quads/Rects as 2 triangles,
  1231. * because returning quads would be too trivial :)
  1232. * \param meshIndex mesh index
  1233. * \param faceIndex face index
  1234. * \param index allocated
  1235. * \param st allocated
  1236. * \param texture allocated
  1237. * \param transparency allocated
  1238. * \fixme This method interface may change later
  1239. */
  1240. void getMeshTexturedRectangle(unsigned int meshIndex,
  1241. unsigned int faceIndex,
  1242. int index[6], float st[12], int *texture,
  1243. unsigned short *transparency);
  1244. /*!
  1245. * \brief This method is made to let you fill arrays or
  1246. * create single faces. There may be an allocatin version that
  1247. * passes back arrays later.
  1248. * \param meshIndex mesh index
  1249. * \param faceIndex face index
  1250. * \param index allocated
  1251. * \param st allocated
  1252. * \param texture allocated
  1253. * \param transparency allocated
  1254. * \fixme This method interface may change later
  1255. */
  1256. void getMeshTexturedTriangle(unsigned int meshIndex,
  1257. unsigned int faceIndex,
  1258. int index[3], float st[6], int *texture,
  1259. unsigned short *transparency);
  1260. /*!
  1261. * \brief Get face counts for a given mesh.
  1262. *
  1263. * \todo This method interface may change later...
  1264. * \param meshIndex mesh index
  1265. * \returns number of textured triangles in mesh
  1266. */
  1267. int getMeshTexturedTriangleCount(unsigned int meshIndex);
  1268. /*!
  1269. * \brief Get face counts for a given mesh.
  1270. * \param meshIndex mesh index
  1271. * \returns number of colored triangles in mesh
  1272. */
  1273. int getMeshColoredTriangleCount(unsigned int meshIndex);
  1274. /*!
  1275. * \brief Get face counts for a given mesh.
  1276. * \param meshIndex mesh index
  1277. * \returns number of textured rectangles in mesh
  1278. */
  1279. int getMeshTexturedRectangleCount(unsigned int meshIndex);
  1280. /*!
  1281. * \brief Get face counts for a given mesh.
  1282. * \returns number if colored rectangles in mesh
  1283. */
  1284. int getMeshColoredRectangleCount(unsigned int meshIndex);
  1285. /*!
  1286. * \brief Get vertex, normal and color arrays for a mesh
  1287. * \param meshIndex mesh index
  1288. * \param vertexCount will be set to length of vertex array
  1289. * \param verts will be set to allocated vertex array (XYX)
  1290. * \param normalCount will be set to length of normal array
  1291. * \param norms will be set to allocated normal array (IJK)
  1292. * \param colorCount will be set to length of color array
  1293. * \param colors will be set to allocated color array (I)
  1294. */
  1295. void getMeshVertexArrays(unsigned int meshIndex,
  1296. unsigned int *vertexCount, float **verts,
  1297. unsigned int *normalCount, float **norms,
  1298. unsigned int *colorCount, float **colors);
  1299. /*!
  1300. * \brief Get a single collision box from room (unified)
  1301. * \param roomIndex room index
  1302. * \param index index of box in room
  1303. * \param xyzA will contain first corner of box
  1304. * \param xyzB will contain second corner of box
  1305. * \param xyzC will contain third corner of box
  1306. * \param xyzD will contain fourth corner of box
  1307. * \returns 0 on success, < 0 on error
  1308. */
  1309. int getRoomBox(unsigned int roomIndex, unsigned int index,
  1310. float *xyzA, float *xyzB, float *xyzC, float *xyzD);
  1311. /*!
  1312. * \brief Get number of collision boxes in room (unified)
  1313. * \param roomIndex room index
  1314. * \returns number of collision boxes in room
  1315. */
  1316. unsigned int getRoomBoxCount(unsigned int roomIndex);
  1317. void getRoomInfo(unsigned int index,
  1318. unsigned int *flags, float pos[3],
  1319. float bboxMin[3], float bboxMax[3]);
  1320. /*!
  1321. * \brief Get a single light from a room (unified)
  1322. * \param roomIndex valid room index
  1323. * \param index valid light index in room
  1324. * \param pos allocated, will contain position
  1325. * \param color allocated, will contain color
  1326. * \param dir allocated, will contain direction
  1327. * \param attenuation will contain attenuation
  1328. * \param cutoffAngle will contain cutoff angle
  1329. * \param type will contain type
  1330. * \param flags will contain flags
  1331. * \returns 0 on success, < 0 on error
  1332. */
  1333. int getRoomLight(unsigned int roomIndex, unsigned int index,
  1334. float pos[4], float color[4], float dir[3],
  1335. float *attenuation, float *cutoffAngle,
  1336. unsigned int *type, unsigned int *flags);
  1337. /*!
  1338. * \brief Get number of lights in room (unified)
  1339. * \param roomIndex room index
  1340. * \returns number of lights in room
  1341. */
  1342. unsigned int getRoomLightCount(unsigned int roomIndex);
  1343. /*!
  1344. * \brief Get a single model info from a room
  1345. * \param roomIndex valid room index
  1346. * \param index valid model index in room
  1347. * \param modelIndex will contain starting mesh
  1348. * \param pos will contain pos
  1349. * \param yaw will contain yaw angle
  1350. * \returns 0 on success, < 0 on error
  1351. */
  1352. int getRoomModel(unsigned int roomIndex, unsigned int index,
  1353. int *modelIndex, float pos[3], float *yaw);
  1354. /*!
  1355. * \brief Get number of room models in room (unified)
  1356. * \param roomIndex room index
  1357. * \returns number of room models in room
  1358. */
  1359. unsigned int getRoomModelCount(unsigned int roomIndex);
  1360. /*!
  1361. * \brief Get a single portal from room (unified)
  1362. * \param roomIndex valid room index
  1363. * \param index valid portal index in room
  1364. * \param adjoiningRoom will contain adjoining room index
  1365. * \param normal allocated, will contain normal vector
  1366. * \param vertices allocated, will contain vertices
  1367. * \returns 0 on success, < 0 on error
  1368. */
  1369. int getRoomPortal(unsigned int roomIndex, unsigned int index,
  1370. int *adjoiningRoom, float normal[3], float vertices[12]);
  1371. /*!
  1372. * \brief Get number of portals from room (unified)
  1373. * \param roomIndex room index
  1374. * \returns number of portals from room
  1375. */
  1376. unsigned int getRoomPortalCount(unsigned int roomIndex);
  1377. /*!
  1378. * \brief Get rectangle data with texCoords for non-matching
  1379. * vertex/uv for each vertex in TombRaider room (unified)
  1380. * \param roomIndex valid room index
  1381. * \param rectangleIndex rectangle index in room
  1382. * \param indices will contain indices
  1383. * \param texCoords will contain texCoords
  1384. * \param texture will contain texture
  1385. * \param flags will contain flags
  1386. */
  1387. void getRoomRectangle(unsigned int roomIndex, unsigned int rectangleIndex,
  1388. unsigned int *indices, float *texCoords, int *texture,
  1389. unsigned int *flags);
  1390. /*!
  1391. * \brief Get number of rectangles from room (unified)
  1392. * \param roomIndex room index
  1393. * \returns number of rectangles from room
  1394. */
  1395. unsigned int getRoomRectangleCount(unsigned int roomIndex);
  1396. /*!
  1397. * \brief Get a single sector from room (unified)
  1398. * \param roomIndex room index
  1399. * \param index sector index
  1400. * \param flags will contain flags
  1401. * \param ceiling will contain ceiling
  1402. * \param floor will contain floor
  1403. * \param floorDataIndex will contain floor data index
  1404. * \param boxIndex will contain boxIndex
  1405. * \param roomBelow will contain roomBelow
  1406. * \param roomAbove will contain roomAbove
  1407. * \return 0 on success, < 0 on error
  1408. */
  1409. int getRoomSector(unsigned int roomIndex, unsigned int index,
  1410. unsigned int *flags, float *ceiling, float *floor,
  1411. int *floorDataIndex, int *boxIndex,
  1412. int *roomBelow, int *roomAbove);
  1413. /*!
  1414. * \brief Get number of sectors in room (unified)
  1415. * \param roomIndex room index
  1416. * \param zSectorsCount will contain width of sector list
  1417. * \param xSectorsCount will contain height of sector list
  1418. * \returns number of sectors in room
  1419. */
  1420. unsigned int getRoomSectorCount(unsigned int roomIndex,
  1421. unsigned int *zSectorsCount,
  1422. unsigned int *xSectorsCount);
  1423. void getRoomSprite(unsigned int roomIndex, unsigned int index,
  1424. float scale, int *texture,
  1425. float *pos, float *vertices, float *texcoords);
  1426. /*!
  1427. * \brief Get number of sprites in room (unified)
  1428. * \param roomIndex room index
  1429. * \returns number of sprites in room
  1430. */
  1431. unsigned int getRoomSpriteCount(unsigned int roomIndex);
  1432. /*!
  1433. * \brief Gets triangle data with texCoords for non-matching
  1434. * vertex/uv for each vertex in TombRaider room (unified)
  1435. * \param roomIndex room index
  1436. * \param triangleIndex triangle index
  1437. * \param indices will contain indices
  1438. * \param texCoords will contain texCoords
  1439. * \param texture will contain texture
  1440. * \param flags will contain flags
  1441. */
  1442. void getRoomTriangle(unsigned int roomIndex, unsigned int triangleIndex,
  1443. unsigned int *indices, float *texCoords, int *texture,
  1444. unsigned int *flags);
  1445. /*!
  1446. * \brief Gets triangle data with texCoords for non-matching
  1447. * vertex/uv for each vertex in TombRaider room.
  1448. *
  1449. * This is used with vertices, colors, etc. to do partial array
  1450. * rendering, since the texcoords will never match vertives
  1451. * (Tomb Raider is textile based).
  1452. * \param index room index
  1453. * \param textureOffset texture offset
  1454. * \param count will contain count
  1455. * \param indices will contain indices
  1456. * \param texCoords will contain texCoords
  1457. * \param textures will contain textures
  1458. * \param flags will contain flags
  1459. */
  1460. void getRoomTriangles(unsigned int index, int textureOffset,
  1461. unsigned int *count, unsigned int **indices,
  1462. float **texCoords, int **textures,
  1463. unsigned int **flags);
  1464. /*!
  1465. * \brief Gets triangle data with duplicated vertex/color/normal
  1466. * data for each face vertex to match the textile based texcoords.
  1467. *
  1468. * This uses more memory, but lets you do direct array rendering
  1469. * with OpenGL, D3D, etc.
  1470. * \param roomIndex room index
  1471. * \param textureOffset texture offset
  1472. * \param count will contain count
  1473. * \param indices will contain indices
  1474. * \param vertices will contain vertices
  1475. * \param texCoords will contain texCoords
  1476. * \param colors will contain colors
  1477. * \param textures will contain textures
  1478. * \param flags will contain flags
  1479. */
  1480. void getRoomTriangles(unsigned int roomIndex, int textureOffset,
  1481. unsigned int *count,
  1482. unsigned int **indices, float **vertices,
  1483. float **texCoords, float **colors,
  1484. int **textures, unsigned int **flags);
  1485. /*!
  1486. * \brief Get number of triangles from room (unified)
  1487. * \param roomIndex room index
  1488. * \returns number of triangles from room
  1489. */
  1490. unsigned int getRoomTriangleCount(unsigned int roomIndex);
  1491. /*!
  1492. * \brief Gets vertex position and color
  1493. * \param roomIndex room index
  1494. * \param vertexIndex vertex index
  1495. * \param xyz will contain vertex position, has to be allocated
  1496. * \param rgba will contain vertex color, has to be allocated
  1497. */
  1498. void getRoomVertex(unsigned int roomIndex, unsigned int vertexIndex,
  1499. float *xyz, float *rgba);
  1500. /*!
  1501. * \brief Get allocated vertex and color arrays and their element counts (unified)
  1502. * \param roomIndex valid room index
  1503. * \param vertexCount will contain vertex array length
  1504. * \param vertices will contain vertex array
  1505. * \param normalCount will contain normal array length
  1506. * \param normals will contain normal array
  1507. * \param colorCount will contain color array length
  1508. * \param colors will contain color array
  1509. */
  1510. void getRoomVertexArrays(unsigned int roomIndex,
  1511. unsigned int *vertexCount, float **vertices,
  1512. unsigned int *normalCount, float **normals,
  1513. unsigned int *colorCount, float **colors);
  1514. /*!
  1515. * \brief Get number of lights in room (unified)
  1516. * \param roomIndex room index
  1517. * \returns number of lights in room
  1518. */
  1519. unsigned int getRoomVertexCount(unsigned int roomIndex);
  1520. /*!
  1521. * \brief Get sky mesh ID
  1522. * \returns moveable id of sky mesh or -1 if none
  1523. */
  1524. int getSkyModelId();
  1525. void getSprites();
  1526. /*!
  1527. * \brief Get a copy of a sound sample and its byte size
  1528. * \param index sound sample index
  1529. * \param bytes will contain byte size of sound sample
  1530. * \param data will contain sound sample
  1531. */
  1532. void getSoundSample(unsigned int index,
  1533. unsigned int *bytes, unsigned char **data);
  1534. /*!
  1535. * \brief Get number of loaded sound samples
  1536. * \returns number of sound samples loaded
  1537. */
  1538. unsigned int getSoundSamplesCount();
  1539. /*!
  1540. * \brief Check if a mesh is valid
  1541. * \param index mesh index (?)
  1542. * \returns true if mesh is valid
  1543. */
  1544. bool isMeshValid(int index);
  1545. /*!
  1546. * \brief Check if a room is valid (TRC support)
  1547. * \param index room index
  1548. * \returns true if room is valid
  1549. */
  1550. bool isRoomValid(int index);
  1551. /*!
  1552. * \brief Load an external sound pak for TR2 and TR3
  1553. * \param filename pak to load
  1554. * \returns < 0 on error
  1555. */
  1556. int loadSFX(char *filename);
  1557. void reset();
  1558. void setDebug(bool toggle);
  1559. /*!
  1560. * \brief Sets lighting factor for each vertex color per room in TR3 paks
  1561. * \param f new lighting factor
  1562. */
  1563. void setRoomVertexLightingFactor(float f);
  1564. /*!
  1565. * \brief Set scaling for sprite texel alignment, etc.
  1566. * \param f new scaling factor
  1567. */
  1568. void setTexelScalingFactor(float f);
  1569. private:
  1570. void extractMeshes(unsigned char *mesh_data,
  1571. unsigned int num_mesh_pointers,
  1572. unsigned int *mesh_pointers);
  1573. int Fread(void *buffer, size_t size, size_t count, FILE *f);
  1574. /*!
  1575. * \brief Get a copy of the sound samples
  1576. * \param bytes will contain size of sound samples
  1577. * \param data will contain sound samples themselves
  1578. */
  1579. void getRiffData(unsigned int *bytes, unsigned char **data);
  1580. /*!
  1581. * \brief Get a copy of a TR4 sound sample
  1582. * \param index sound sample index
  1583. * \param bytes will contain length of sound sample
  1584. * \param data will contain sound sample itself
  1585. */
  1586. void getRiffDataTR4(unsigned int index,
  1587. unsigned int *bytes, unsigned char **data);
  1588. /*!
  1589. * \brief Get an array of offsets for a contiguous RIFF data stream in chunks.
  1590. *
  1591. * Offsets will be allocated with enough space to hold expected
  1592. * number of offsets. (Should be known number, otherwise not all RIFFs
  1593. * will be parsed.)
  1594. * \param riffData riff data
  1595. * \param riffDataBytes length of riff data
  1596. * \param offsets will contain offsets
  1597. * \param numOffsets known number
  1598. * \returns number of RIFFs found
  1599. */
  1600. int getRiffOffsets(unsigned char *riffData, unsigned int riffDataBytes,
  1601. unsigned int **offsets, unsigned int numOffsets);
  1602. /*!
  1603. * \brief Makes a 32bit RGBA image from a textile.
  1604. *
  1605. * This handles all selection and conversion, including
  1606. * alpha layering flags, now.
  1607. * \param texture valid index into textile list
  1608. * \returns 32bit RGBA image or NULL on error
  1609. */
  1610. unsigned char *getTexTile(int texture);
  1611. /*!
  1612. * \brief Loads a TR5 pak into memory.
  1613. *
  1614. * At 10% all textures are loaded
  1615. * the exact figure '10' will always be passed to
  1616. * allow for texture caching while meshes load.
  1617. * \param f valid FILE
  1618. * \param percent callback for loading progress
  1619. * \returns 0 on success, < 0 on error
  1620. */
  1621. int loadTR5(FILE *f, void (*percent)(int, void *), void *obj);
  1622. void print(const char *methodName, const char *s, ...) __attribute__((format(printf, 3, 4)));
  1623. void printDebug(const char *methodName, const char *s, ...) __attribute__((format(printf, 3, 4)));
  1624. bool mReset; //!< Guard multiple calls to reset()
  1625. bool mDebug; //!< Debug output toggle
  1626. unsigned int mPakVersion; //!< TombRaider pak file header version
  1627. tr2_version_type mEngineVersion; //!< TombRaider engine version
  1628. tr2_colour_t _palette8[256]; //!< 8-bit palette
  1629. unsigned int _palette16[256]; //!< 16-bit palette
  1630. unsigned int _num_textiles; //!< Total number of texture tiles
  1631. unsigned short _num_room_textures; //!< Num textures only for room use?
  1632. unsigned short _num_misc_textures; //!< Num of textures for misc use?
  1633. unsigned short _num_bump_map_textures; //!< Num of textures that are bump map, texture pairs
  1634. tr2_textile8_t *_textile8; //!< 8-bit (palettised) textiles
  1635. tr2_textile16_t *_textile16; //!< 16-bit (ARGB) textiles
  1636. tr2_textile32_t *_textile32; //!< 32-bit (BGRA) textiles
  1637. unsigned int _num_tex_special; //!< Special textures and bump maps count
  1638. unsigned char *_tex_special; //!< Special textures and bump maps
  1639. unsigned int _unknown_t; //!< 32-bit unknown (always 0 in real TR2 levels)
  1640. unsigned short _num_rooms; //!< Number of rooms in this level
  1641. tr2_room_t *_rooms; //!< List of rooms (TR1,TR2,TR3,TR4)
  1642. tr5_room_t *mRoomsTR5; //!< Rooms ( TR5 / TRC ) Only
  1643. unsigned int _num_floor_data; //!< Num of words of floor data this level
  1644. unsigned short *_floor_data; //!< Floor data
  1645. int mMeshCount; //!< Number of meshes this level
  1646. tr2_mesh_t *mMeshes; //!< list of meshes
  1647. unsigned int _num_animations; //!< number of animations this level
  1648. tr2_animation_t *_animations; //!< list of animations
  1649. unsigned int _num_state_changes; //!< number of structures(?) this level
  1650. tr2_state_change_t *_state_changes; //!< list of structures
  1651. unsigned int _num_anim_dispatches; //!< number of ranges(?) this level
  1652. tr2_anim_dispatch_t *_anim_dispatches; //!< list of ranges
  1653. unsigned int _num_anim_commands; //!< number of Bone1s this level
  1654. tr2_anim_command_t *_anim_commands; //!< list of Bone1s
  1655. unsigned int _num_mesh_trees; //!< number of Bone2s this level
  1656. tr2_meshtree_t *_mesh_trees; //!< list of Bone2s
  1657. unsigned int _num_frames; //!< num of words of frame data this level
  1658. unsigned short *_frames; //!< frame data
  1659. unsigned int _num_moveables; //!< number of moveables this level
  1660. tr2_moveable_t *_moveables; //!< list of moveables
  1661. uint32_t numMoveablesTR5;
  1662. tr5_moveable_t *moveablesTR5;
  1663. uint32_t numAnimationsTR5;
  1664. tr5_animation_t *animationsTR5;
  1665. uint32_t numObjectTexturesTR5;
  1666. tr5_object_texture_t *objectTexturesTR5;
  1667. uint32_t numCinematicFramesTR5;
  1668. tr5_cinematic_frame_t *cinematicFramesTR5;
  1669. uint32_t numFlyByCamerasTR5;
  1670. tr5_flyby_camera_t *flyByCamerasTR5;
  1671. unsigned int _num_static_meshes; //!< number of static meshes this level
  1672. tr2_staticmesh_t *_static_meshes; //!< static meshes
  1673. unsigned int _num_object_textures; //!< number of object textures this level
  1674. tr2_object_texture_t *_object_textures; //!< list of object textures
  1675. unsigned int _num_sprite_textures; //!< num of sprite textures this level
  1676. tr2_sprite_texture_t *_sprite_textures; //!< list of sprite textures
  1677. unsigned int _num_sprite_sequences; //!< num of sprite sequences this level
  1678. tr2_sprite_sequence_t *_sprite_sequences; //!< sprite sequence data
  1679. int _num_cameras; //!< Number of Cameras
  1680. tr2_camera_t *_cameras; //!< cameras
  1681. int _num_sound_sources; //!< Number of Sounds
  1682. tr2_sound_source_t *_sound_sources; //!< sounds
  1683. int _num_boxes; //!< Number of Boxes
  1684. tr2_box_t *_boxes; /*!< boxes - looks like
  1685. * struct { unsigned short value[4]; }
  1686. * - value[0..2] might be a vector;
  1687. * value[3] seems to be index into
  1688. * Overlaps[] */
  1689. int _num_overlaps; //!< Number of Overlaps
  1690. short *_overlaps; /*!< Overlaps -
  1691. * looks like ushort; 0x8000 is flag
  1692. * of some sort appears to be an
  1693. * offset into Boxes[] and/or
  1694. * Boxes2[] */
  1695. short *_zones; //!< Boxes2
  1696. int _num_animated_textures; //!< Number of AnimTextures
  1697. short *_animated_textures; //!< Animtextures
  1698. int _num_items; //!< Number of Items
  1699. tr2_item_t *_items; //!< Items
  1700. unsigned char *_light_map; //!< Colour-light maps
  1701. unsigned int _num_cinematic_frames; //!< Number of cut-scene frames
  1702. tr2_cinematic_frame_t *_cinematic_frames; //!< Cut-scene frames
  1703. short _num_demo_data; //!< Number of Demo Data
  1704. unsigned char *_demo_data; //!< Demo data
  1705. float mRoomVertexLightingFactor;
  1706. float mTexelScale;
  1707. // Sound data
  1708. short *mSoundMap; //!< Sound map
  1709. int mNumSoundDetails; //!< Number of SampleModifiers
  1710. tr2_sound_details_t *mSoundDetails; //!< Sample modifiers
  1711. int mNumSampleIndices; //!< Number of Sample Indices
  1712. int *mSampleIndices; //!< Sample indices
  1713. unsigned int *mSampleIndicesTR5;
  1714. bool mRiffAlternateLoaded; //!< Is a TR2,TR3 SFX loaded?
  1715. unsigned int *mRiffAlternateOffsets; //!< After parsing this will
  1716. //!< hold byte offsets for TR2,TR3
  1717. //!< RIFFs in the buffered SFX
  1718. int mRiffDataSz; //!< Byte size of a loaded SFX
  1719. unsigned char *mRiffData; //!< SFX RIFF data in chunks
  1720. unsigned int mNumTR4Samples;
  1721. unsigned char **mTR4Samples;
  1722. unsigned int *mTR4SamplesSz;
  1723. // For packed Fread emu/wrapper
  1724. unsigned char *mCompressedLevelData; //!< Buffer used to emulate fread with uncompressed libz data
  1725. unsigned int mCompressedLevelDataOffset; //!< Offset into buffer
  1726. unsigned int mCompressedLevelSize; //!< Size of buffer
  1727. tr_fread_mode_t mFreadMode; //!< Fread mode file|buffer
  1728. };
  1729. #endif