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