Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TombRaider.h 81KB

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