Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

TombRaider.h 74KB

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