Open Source Tomb Raider Engine
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TombRaider.h 75KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947
  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. float adjustTexel(unsigned char texel, char offset);
  1153. /*------------------------------------------------------
  1154. * Pre : Passed the correct coor/pixel pair from
  1155. * object texture
  1156. *
  1157. * Post : Makes a clamped 0.0 to 1.0 texel from coord pair
  1158. *
  1159. *-- History ------------------------------------------
  1160. *
  1161. * 2001.06.21:
  1162. * Mongoose - Created
  1163. ------------------------------------------------------*/
  1164. /*!
  1165. * \brief Compute rotation angles from moveable animation data
  1166. * \param frame moveable animation data
  1167. * \param frame_offset moveable animation data
  1168. * \param angle_offset moveable animation data
  1169. * \param x will be set to computed angle
  1170. * \param y will be set to computed angle
  1171. * \param z will be set to computed angle
  1172. */
  1173. void computeRotationAngles(unsigned short **frame,
  1174. unsigned int *frame_offset,
  1175. unsigned int *angle_offset,
  1176. float *x, float *y, float *z);
  1177. void computeUV(tr2_object_texture_vert_t *st, float *u, float *v);
  1178. /*------------------------------------------------------
  1179. * Pre : Args are valid pointers
  1180. * Post : Returns computed UV in u and v
  1181. *
  1182. *-- History ------------------------------------------
  1183. *
  1184. * 2002.04.05:
  1185. * Mongoose - Created
  1186. ------------------------------------------------------*/
  1187. /*!
  1188. * \brief Get number of bump maps in loaded pak
  1189. * \returns number of bump maps
  1190. */
  1191. int getBumpMapCount();
  1192. void getColor(int index, float color[4]);
  1193. tr2_version_type getEngine();
  1194. /*!
  1195. * \brief Get the collision sphere for a mesh
  1196. * \param meshIndex mesh index
  1197. * \param center will be filled with center coordinates, not NULL
  1198. * \param radius will be filled with radius, not NULL
  1199. */
  1200. void getMeshCollisionInfo(unsigned int meshIndex,
  1201. float center[3], float *radius);
  1202. /*!
  1203. * \brief Get SIGNED mesh count (TR encoded < 0 errors)
  1204. * \returns signed mesh count
  1205. */
  1206. int getMeshCount();
  1207. void getMeshColoredRectangle(unsigned int meshIndex,
  1208. unsigned int faceIndex,
  1209. int index[6], float color[4]);
  1210. /*------------------------------------------------------
  1211. * Pre : This method interface may change later
  1212. *
  1213. * Pass allocated index[6], color[4] ( RGBA )
  1214. *
  1215. * Post : This method is made to let you fill arrays or
  1216. * create single faces, their may be an allocating
  1217. * version that passes back arrays later
  1218. *
  1219. * Returns Quads/Rects as 2 triangles, because
  1220. * returning quads would be too trival =)
  1221. *
  1222. *-- History ------------------------------------------
  1223. *
  1224. * 2000.05.16:
  1225. * Mongoose - Created, based on method from OpenRaider
  1226. ------------------------------------------------------*/
  1227. void getMeshColoredTriangle(unsigned int meshIndex,
  1228. unsigned int faceIndex,
  1229. int index[3], float color[4]);
  1230. /*------------------------------------------------------
  1231. * Pre : This method interface may change later
  1232. *
  1233. * Pass allocated index[3], color[4] ( RGBA )
  1234. *
  1235. * Post : This method is made to let you fill arrays or
  1236. * create single faces, their may be an allocating
  1237. * version that passes back arrays later
  1238. *
  1239. *-- History ------------------------------------------
  1240. *
  1241. * 2000.05.16:
  1242. * Mongoose - Created, based on method from OpenRaider
  1243. ------------------------------------------------------*/
  1244. void getMeshTexturedRectangle(unsigned int meshIndex,
  1245. unsigned int faceIndex,
  1246. int index[6], float st[12], int *texture,
  1247. unsigned short *transparency);
  1248. /*------------------------------------------------------
  1249. * Pre : This method interface may change later
  1250. *
  1251. * Pass allocated index[6], st[12], texture,
  1252. * and transparency
  1253. *
  1254. * Post : This method is made to let you fill arrays or
  1255. * create single faces, their may be an allocating
  1256. * version that passes back arrays later
  1257. *
  1258. * Returns Quads/Rects as 2 triangles, because
  1259. * returning quads would be too trival =)
  1260. *
  1261. *-- History ------------------------------------------
  1262. *
  1263. * 2000.05.16:
  1264. * Mongoose - Created, based on method from OpenRaider
  1265. ------------------------------------------------------*/
  1266. void getMeshTexturedTriangle(unsigned int meshIndex,
  1267. unsigned int faceIndex,
  1268. int index[3], float st[6], int *texture,
  1269. unsigned short *transparency);
  1270. /*------------------------------------------------------
  1271. * Pre : This method interface may change later
  1272. *
  1273. * Pass allocated index[3], st[6], texture,
  1274. * and transparency
  1275. *
  1276. * Post : This method is made to let you fill arrays or
  1277. * create single faces, their may be an allocating
  1278. * version that passes back arrays later
  1279. *
  1280. *-- History ------------------------------------------
  1281. *
  1282. * 2000.05.16:
  1283. * Mongoose - Created, based on method from OpenRaider
  1284. ------------------------------------------------------*/
  1285. /*!
  1286. * \brief Get face counts for a given mesh.
  1287. *
  1288. * \todo This method interface may change later...
  1289. * \param meshIndex mesh index
  1290. * \returns number of textured triangles in mesh
  1291. */
  1292. int getMeshTexturedTriangleCount(unsigned int meshIndex);
  1293. /*!
  1294. * \brief Get face counts for a given mesh.
  1295. * \param meshIndex mesh index
  1296. * \returns number of colored triangles in mesh
  1297. */
  1298. int getMeshColoredTriangleCount(unsigned int meshIndex);
  1299. /*!
  1300. * \brief Get face counts for a given mesh.
  1301. * \param meshIndex mesh index
  1302. * \returns number of textured rectangles in mesh
  1303. */
  1304. int getMeshTexturedRectangleCount(unsigned int meshIndex);
  1305. /*!
  1306. * \brief Get face counts for a given mesh.
  1307. * \returns number if colored rectangles in mesh
  1308. */
  1309. int getMeshColoredRectangleCount(unsigned int meshIndex);
  1310. /*!
  1311. * \brief Get vertex, normal and color arrays for a mesh
  1312. * \param meshIndex mesh index
  1313. * \param vertexCount will be set to length of vertex array
  1314. * \param verts will be set to allocated vertex array (XYX)
  1315. * \param normalCount will be set to length of normal array
  1316. * \param norms will be set to allocated normal array (IJK)
  1317. * \param colorCount will be set to length of color array
  1318. * \param colors will be set to allocated color array (I)
  1319. */
  1320. void getMeshVertexArrays(unsigned int meshIndex,
  1321. unsigned int *vertexCount, float **verts,
  1322. unsigned int *normalCount, float **norms,
  1323. unsigned int *colorCount, float **colors);
  1324. int getRoomBox(unsigned int roomIndex, unsigned int index,
  1325. float *xyzA, float *xyzB, float *xyzC, float *xyzD);
  1326. /*------------------------------------------------------
  1327. * Pre :
  1328. * Post : Returns a single collision box from room ( unified )
  1329. *
  1330. *-- History ------------------------------------------
  1331. *
  1332. * 2003.05.24:
  1333. * Mongoose - Created
  1334. ------------------------------------------------------*/
  1335. /*!
  1336. * \brief Get number of collision boxes in room (unified)
  1337. * \param roomIndex room index
  1338. * \returns number of collision boxes in room
  1339. */
  1340. unsigned int getRoomBoxCount(unsigned int roomIndex);
  1341. void getRoomInfo(unsigned int index,
  1342. unsigned int *flags, float pos[3],
  1343. float bboxMin[3], float bboxMax[3]);
  1344. int getRoomLight(unsigned int roomIndex, unsigned int index,
  1345. float pos[4], float color[4], float dir[3],
  1346. float *attenuation, float *cutoffAngle,
  1347. unsigned int *type, unsigned int *flags);
  1348. /*------------------------------------------------------
  1349. * Pre : All parms are allocated
  1350. * Post : Returns a single light from a room ( unified )
  1351. *
  1352. *-- History ------------------------------------------
  1353. *
  1354. * 2003.05.19:
  1355. * Mongoose - Created
  1356. ------------------------------------------------------*/
  1357. /*!
  1358. * \brief Get number of lights in room (unified)
  1359. * \param roomIndex room index
  1360. * \returns number of lights in room
  1361. */
  1362. unsigned int getRoomLightCount(unsigned int roomIndex);
  1363. int getRoomModel(unsigned int roomIndex, unsigned int index,
  1364. int *modelIndex, float pos[3], float *yaw);
  1365. /*------------------------------------------------------
  1366. * Pre : All parms are allocated
  1367. * Post : Returns a single model info from a room ( unified )
  1368. *
  1369. *-- History ------------------------------------------
  1370. *
  1371. * 2003.05.19:
  1372. * Mongoose - Created
  1373. ------------------------------------------------------*/
  1374. /*!
  1375. * \brief Get number of room models in room (unified)
  1376. * \param roomIndex room index
  1377. * \returns number of room models in room
  1378. */
  1379. unsigned int getRoomModelCount(unsigned int roomIndex);
  1380. int getRoomPortal(unsigned int roomIndex, unsigned int index,
  1381. int *adjoiningRoom, float normal[3], float vertices[12]);
  1382. /*------------------------------------------------------
  1383. * Pre :
  1384. * Post : Returns a single portal from room ( unified )
  1385. *
  1386. *-- History ------------------------------------------
  1387. *
  1388. * 2003.05.24:
  1389. * Mongoose - Created
  1390. ------------------------------------------------------*/
  1391. /*!
  1392. * \brief Get number of portals from room (unified)
  1393. * \param roomIndex room index
  1394. * \returns number of portals from room
  1395. */
  1396. unsigned int getRoomPortalCount(unsigned int roomIndex);
  1397. void getRoomRectangle(unsigned int roomIndex, unsigned int rectangleIndex,
  1398. unsigned int *indices, float *texCoords, int *texture,
  1399. unsigned int *flags);
  1400. /*------------------------------------------------------
  1401. * Pre :
  1402. * Post : Gets rectangle data with texCoords for non-matching
  1403. * vertex/uv for each vertex in TombRaider room ( unified )
  1404. *
  1405. *-- History ------------------------------------------
  1406. *
  1407. * 2003.05.24:
  1408. * Mongoose - Created
  1409. ------------------------------------------------------*/
  1410. /*!
  1411. * \brief Get number of rectangles from room (unified)
  1412. * \param roomIndex room index
  1413. * \returns number of rectangles from room
  1414. */
  1415. unsigned int getRoomRectangleCount(unsigned int roomIndex);
  1416. int getRoomSector(unsigned int roomIndex, unsigned int index,
  1417. unsigned int *flags, float *ceiling, float *floor,
  1418. int *floorDataIndex, int *boxIndex,
  1419. int *roomBelow, int *roomAbove);
  1420. /*------------------------------------------------------
  1421. * Pre :
  1422. * Post : Returns a single sector from room ( unified )
  1423. *
  1424. *-- History ------------------------------------------
  1425. *
  1426. * 2003.05.24:
  1427. * Mongoose - Created
  1428. ------------------------------------------------------*/
  1429. /*!
  1430. * \brief Get number of sectors in room (unified)
  1431. * \param roomIndex room index
  1432. * \param zSectorsCount will contain width of sector list
  1433. * \param xSectorsCount will contain height of sector list
  1434. * \returns number of sectors in room
  1435. */
  1436. unsigned int getRoomSectorCount(unsigned int roomIndex,
  1437. unsigned int *zSectorsCount,
  1438. unsigned int *xSectorsCount);
  1439. void getRoomSprite(unsigned int roomIndex, unsigned int index,
  1440. float scale, int *texture,
  1441. float *pos, float *vertices, float *texcoords);
  1442. /*!
  1443. * \brief Get number of sprites in room (unified)
  1444. * \param roomIndex room index
  1445. * \returns number of sprites in room
  1446. */
  1447. unsigned int getRoomSpriteCount(unsigned int roomIndex);
  1448. void getRoomTriangle(unsigned int roomIndex, unsigned int triangleIndex,
  1449. unsigned int *indices, float *texCoords, int *texture,
  1450. unsigned int *flags);
  1451. /*------------------------------------------------------
  1452. * Pre :
  1453. * Post : Gets triangle data with texCoords for non-matching
  1454. * vertex/uv for each vertex in TombRaider room ( unified )
  1455. *
  1456. *-- History ------------------------------------------
  1457. *
  1458. * 2003.05.24:
  1459. * Mongoose - Created
  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. * Pre :
  1467. * Post : Gets triangle data with texCoords for non-matching
  1468. * vertex/uv for each vertex in TombRaider room
  1469. *
  1470. * This is used with room vertices, colors, etc
  1471. * to do partial array rendering, since the texcoords
  1472. * will never match vertices ( Tomb Raider is textile based )
  1473. *
  1474. *-- History ------------------------------------------
  1475. *
  1476. * 2003.05.24:
  1477. * Mongoose - Created
  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. * Pre :
  1486. * Post : Gets triangle data with duplicated
  1487. * vertex/color/normal data for each face vertex
  1488. * to match the textile based texcoords
  1489. *
  1490. * This uses more memory, but lets you do direct
  1491. * array rendering with OpenGL, D3D, etc
  1492. *
  1493. *-- History ------------------------------------------
  1494. *
  1495. * 2003.05.24:
  1496. * Mongoose - Created
  1497. ------------------------------------------------------*/
  1498. /*!
  1499. * \brief Get number of triangles from room (unified)
  1500. * \param roomIndex room index
  1501. * \returns number of triangles from room
  1502. */
  1503. unsigned int getRoomTriangleCount(unsigned int roomIndex);
  1504. void getRoomVertex(unsigned int roomIndex, unsigned int vertexIndex,
  1505. float *xyz, float *rgba);
  1506. /*------------------------------------------------------
  1507. * Pre : Given room index and vertex index and
  1508. * xyz is allocated float[3]
  1509. * rbga is allocated float[4]
  1510. *
  1511. * Post : Returns vertex position xyz and color rbga
  1512. *
  1513. *-- History ------------------------------------------
  1514. *
  1515. * 2003.05.13:
  1516. * Mongoose - Created, based on method from OpenRaider
  1517. ------------------------------------------------------*/
  1518. void getRoomVertexArrays(unsigned int roomIndex,
  1519. unsigned int *vertexCount, float **vertices,
  1520. unsigned int *normalCount, float **normals,
  1521. unsigned int *colorCount, float **colors);
  1522. /*------------------------------------------------------
  1523. * Pre : Given room index
  1524. *
  1525. * Post : Returns allocated vertex and color arrays,
  1526. * and their element counts ( unified )
  1527. *
  1528. *-- History ------------------------------------------
  1529. *
  1530. * 2003.05.24:
  1531. * Mongoose - Unified API
  1532. *
  1533. * 2003.05.13:
  1534. * Mongoose - Created, based on method from OpenRaider
  1535. ------------------------------------------------------*/
  1536. /*!
  1537. * \brief Get number of lights in room (unified)
  1538. * \param roomIndex room index
  1539. * \returns number of lights in room
  1540. */
  1541. unsigned int getRoomVertexCount(unsigned int roomIndex);
  1542. /*!
  1543. * \brief Get sky mesh ID
  1544. * \returns moveable id of sky mesh or -1 if none
  1545. */
  1546. int getSkyModelId();
  1547. void getSprites();
  1548. /*!
  1549. * \brief Get a copy of a sound sample and its byte size
  1550. * \param index sound sample index
  1551. * \param bytes will contain byte size of sound sample
  1552. * \param data will contain sound sample
  1553. */
  1554. void getSoundSample(unsigned int index,
  1555. unsigned int *bytes, unsigned char **data);
  1556. /*!
  1557. * \brief Get number of loaded sound samples
  1558. * \returns number of sound samples loaded
  1559. */
  1560. unsigned int getSoundSamplesCount();
  1561. /*!
  1562. * \brief Check if a mesh is valid
  1563. * \param index mesh index (?)
  1564. * \returns true if mesh is valid
  1565. */
  1566. bool isMeshValid(int index);
  1567. /*!
  1568. * \brief Check if a room is valid (TRC support)
  1569. * \param index room index
  1570. * \returns true if room is valid
  1571. */
  1572. bool isRoomValid(int index);
  1573. /*!
  1574. * \brief Load an external sound pak for TR2 and TR3
  1575. * \param filename pak to load
  1576. * \returns < 0 on error
  1577. */
  1578. int loadSFX(char *filename);
  1579. void reset();
  1580. void setDebug(bool toggle);
  1581. /*!
  1582. * \brief Sets lighting factor for each vertex color per room in TR3 paks
  1583. * \param f new lighting factor
  1584. */
  1585. void setRoomVertexLightingFactor(float f);
  1586. /*!
  1587. * \brief Set scaling for sprite texel alignment, etc.
  1588. * \param f new scaling factor
  1589. */
  1590. void setTexelScalingFactor(float f);
  1591. private:
  1592. void extractMeshes(unsigned char *mesh_data,
  1593. unsigned int num_mesh_pointers,
  1594. unsigned int *mesh_pointers);
  1595. int Fread(void *buffer, size_t size, size_t count, FILE *f);
  1596. /*!
  1597. * \brief Get a copy of the sound samples
  1598. * \param bytes will contain size of sound samples
  1599. * \param data will contain sound samples themselves
  1600. */
  1601. void getRiffData(unsigned int *bytes, unsigned char **data);
  1602. /*!
  1603. * \brief Get a copy of a TR4 sound sample
  1604. * \param index sound sample index
  1605. * \param bytes will contain length of sound sample
  1606. * \param data will contain sound sample itself
  1607. */
  1608. void getRiffDataTR4(unsigned int index,
  1609. unsigned int *bytes, unsigned char **data);
  1610. int getRiffOffsets(unsigned char *riffData, unsigned int riffDataBytes,
  1611. unsigned int **offsets, unsigned int numOffsets);
  1612. /*------------------------------------------------------
  1613. * Pre :
  1614. * Post : Returns an array of offsets for a contigous
  1615. * RIFF data stream in chunks.
  1616. *
  1617. * Offsets will be allocated with enough space
  1618. * to hold expected number of offsets.
  1619. * ( Should be known number, otherwise not
  1620. * all RIFFs will be parsed. )
  1621. *
  1622. * Returns number of RIFFs found
  1623. *
  1624. *-- History ------------------------------------------
  1625. *
  1626. * 2003.05.12:
  1627. * Mongoose - Created
  1628. ------------------------------------------------------*/
  1629. /*!
  1630. * \brief Makes a 32bit RGBA image from a textile.
  1631. *
  1632. * This handles all selection and conversion, including
  1633. * alpha layering flags, now.
  1634. * \param texture valid index into textile list
  1635. * \returns 32bit RGBA image or NULL on error
  1636. */
  1637. unsigned char *getTexTile(int texture);
  1638. /*!
  1639. * \brief Loads a TR5 pak into memory.
  1640. *
  1641. * At 10% all textures are loaded
  1642. * the exact figure '10' will always be passed to
  1643. * allow for texture caching while meshes load.
  1644. * \param f valid FILE
  1645. * \param percent callback for loading progress
  1646. * \returns 0 on success, < 0 on error
  1647. */
  1648. int loadTR5(FILE *f, void (*percent)(int));
  1649. void print(const char *methodName, const char *s, ...) __attribute__((format(printf, 3, 4)));
  1650. void printDebug(const char *methodName, const char *s, ...) __attribute__((format(printf, 3, 4)));
  1651. bool mReset; //!< Guard multiple calls to reset()
  1652. bool mDebug; //!< Debug output toggle
  1653. unsigned int mPakVersion; //!< TombRaider pak file header version
  1654. tr2_version_type mEngineVersion; //!< TombRaider engine version
  1655. tr2_colour_t _palette8[256]; //!< 8-bit palette
  1656. unsigned int _palette16[256]; //!< 16-bit palette
  1657. unsigned int _num_textiles; //!< Total number of texture tiles
  1658. unsigned short _num_room_textures; //!< Num textures only for room use?
  1659. unsigned short _num_misc_textures; //!< Num of textures for misc use?
  1660. unsigned short _num_bump_map_textures; //!< Num of textures that are bump map, texture pairs
  1661. tr2_textile8_t *_textile8; //!< 8-bit (palettised) textiles
  1662. tr2_textile16_t *_textile16; //!< 16-bit (ARGB) textiles
  1663. tr2_textile32_t *_textile32; //!< 32-bit (BGRA) textiles
  1664. unsigned int _num_tex_special; //!< Special textures and bump maps count
  1665. unsigned char *_tex_special; //!< Special textures and bump maps
  1666. unsigned int _unknown_t; //!< 32-bit unknown (always 0 in real TR2 levels)
  1667. unsigned short _num_rooms; //!< Number of rooms in this level
  1668. tr2_room_t *_rooms; //!< List of rooms (TR1,TR2,TR3,TR4)
  1669. tr5_room_t *mRoomsTR5; //!< Rooms ( TR5 / TRC ) Only
  1670. unsigned int _num_floor_data; //!< Num of words of floor data this level
  1671. unsigned short *_floor_data; //!< Floor data
  1672. int mMeshCount; //!< Number of meshes this level
  1673. tr2_mesh_t *mMeshes; //!< list of meshes
  1674. unsigned int _num_animations; //!< number of animations this level
  1675. tr2_animation_t *_animations; //!< list of animations
  1676. unsigned int _num_state_changes; //!< number of structures(?) this level
  1677. tr2_state_change_t *_state_changes; //!< list of structures
  1678. unsigned int _num_anim_dispatches; //!< number of ranges(?) this level
  1679. tr2_anim_dispatch_t *_anim_dispatches; //!< list of ranges
  1680. unsigned int _num_anim_commands; //!< number of Bone1s this level
  1681. tr2_anim_command_t *_anim_commands; //!< list of Bone1s
  1682. unsigned int _num_mesh_trees; //!< number of Bone2s this level
  1683. tr2_meshtree_t *_mesh_trees; //!< list of Bone2s
  1684. unsigned int _num_frames; //!< num of words of frame data this level
  1685. unsigned short *_frames; //!< frame data
  1686. unsigned int _num_moveables; //!< number of moveables this level
  1687. tr2_moveable_t *_moveables; //!< list of moveables
  1688. u_int32_t numMoveablesTR5;
  1689. tr5_moveable_t *moveablesTR5;
  1690. u_int32_t numAnimationsTR5;
  1691. tr5_animation_t *animationsTR5;
  1692. u_int32_t numObjectTexturesTR5;
  1693. tr5_object_texture_t *objectTexturesTR5;
  1694. u_int32_t numCinematicFramesTR5;
  1695. tr5_cinematic_frame_t *cinematicFramesTR5;
  1696. u_int32_t numFlyByCamerasTR5;
  1697. tr5_flyby_camera_t *flyByCamerasTR5;
  1698. unsigned int _num_static_meshes; //!< number of static meshes this level
  1699. tr2_staticmesh_t *_static_meshes; //!< static meshes
  1700. unsigned int _num_object_textures; //!< number of object textures this level
  1701. tr2_object_texture_t *_object_textures; //!< list of object textures
  1702. unsigned int _num_sprite_textures; //!< num of sprite textures this level
  1703. tr2_sprite_texture_t *_sprite_textures; //!< list of sprite textures
  1704. unsigned int _num_sprite_sequences; //!< num of sprite sequences this level
  1705. tr2_sprite_sequence_t *_sprite_sequences; //!< sprite sequence data
  1706. int _num_cameras; //!< Number of Cameras
  1707. tr2_camera_t *_cameras; //!< cameras
  1708. int _num_sound_sources; //!< Number of Sounds
  1709. tr2_sound_source_t *_sound_sources; //!< sounds
  1710. int _num_boxes; //!< Number of Boxes
  1711. tr2_box_t *_boxes; /*!< boxes - looks like
  1712. * struct { unsigned short value[4]; }
  1713. * - value[0..2] might be a vector;
  1714. * value[3] seems to be index into
  1715. * Overlaps[] */
  1716. int _num_overlaps; //!< Number of Overlaps
  1717. short *_overlaps; /*!< Overlaps -
  1718. * looks like ushort; 0x8000 is flag
  1719. * of some sort appears to be an
  1720. * offset into Boxes[] and/or
  1721. * Boxes2[] */
  1722. short *_zones; //!< Boxes2
  1723. int _num_animated_textures; //!< Number of AnimTextures
  1724. short *_animated_textures; //!< Animtextures
  1725. int _num_items; //!< Number of Items
  1726. tr2_item_t *_items; //!< Items
  1727. unsigned char *_light_map; //!< Colour-light maps
  1728. unsigned int _num_cinematic_frames; //!< Number of cut-scene frames
  1729. tr2_cinematic_frame_t *_cinematic_frames; //!< Cut-scene frames
  1730. short _num_demo_data; //!< Number of Demo Data
  1731. unsigned char *_demo_data; //!< Demo data
  1732. float mRoomVertexLightingFactor;
  1733. float mTexelScale;
  1734. // Sound data
  1735. short *mSoundMap; //!< Sound map
  1736. int mNumSoundDetails; //!< Number of SampleModifiers
  1737. tr2_sound_details_t *mSoundDetails; //!< Sample modifiers
  1738. int mNumSampleIndices; //!< Number of Sample Indices
  1739. int *mSampleIndices; //!< Sample indices
  1740. unsigned int *mSampleIndicesTR5;
  1741. bool mRiffAlternateLoaded; //!< Is a TR2,TR3 SFX loaded?
  1742. unsigned int *mRiffAlternateOffsets; //!< After parsing this will
  1743. //!< hold byte offsets for TR2,TR3
  1744. //!< RIFFs in the buffered SFX
  1745. int mRiffDataSz; //!< Byte size of a loaded SFX
  1746. unsigned char *mRiffData; //!< SFX RIFF data in chunks
  1747. unsigned int mNumTR4Samples;
  1748. unsigned char **mTR4Samples;
  1749. unsigned int *mTR4SamplesSz;
  1750. // For packed Fread emu/wrapper
  1751. unsigned char *mCompressedLevelData; //!< Buffer used to emulate fread with uncompressed libz data
  1752. unsigned int mCompressedLevelDataOffset; //!< Offset into buffer
  1753. unsigned int mCompressedLevelSize; //!< Size of buffer
  1754. tr_fread_mode_t mFreadMode; //!< Fread mode file|buffer
  1755. };
  1756. #endif