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 82KB

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