Open Source Tomb Raider Engine
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900
  1. /*!
  2. * \file src/Game.cpp
  3. * \brief Game abstraction
  4. *
  5. * \author xythobuz
  6. */
  7. #ifdef __APPLE__
  8. #include <OpenGL/gl.h>
  9. #else
  10. #include <GL/gl.h>
  11. #endif
  12. #include <algorithm>
  13. #include <map>
  14. #include <cstdlib>
  15. #include "main.h"
  16. #include "Console.h"
  17. #include "Game.h"
  18. #include "utils/strings.h"
  19. #include "games/TombRaider1.h"
  20. // Old Code compatibility
  21. #define TexelScale 256.0f
  22. #define TextureLimit 24
  23. std::map<int, int> gMapTex2Bump;
  24. skeletal_model_t *gLaraModel;
  25. std::vector<unsigned int> gColorTextureHACK;
  26. Game::Game() {
  27. mLoaded = false;
  28. mName = NULL;
  29. mLara = NULL;
  30. mTextureStart = 0;
  31. mTextureLevelOffset = 0;
  32. mTextureOffset = 0;
  33. mRender = NULL;
  34. }
  35. Game::~Game() {
  36. destroy();
  37. if (mRender)
  38. delete mRender;
  39. }
  40. int Game::initialize() {
  41. // Set up Renderer
  42. mRender = new Render();
  43. mRender->initTextures(getOpenRaider().mDataDir, &mTextureStart, &mTextureLevelOffset);
  44. // Enable Renderer
  45. mRender->setMode(Render::modeLoadScreen);
  46. // Enable World Hopping
  47. getWorld().setFlag(World::fEnableHopping);
  48. return 0;
  49. }
  50. void Game::destroy() {
  51. if (mName)
  52. delete [] mName;
  53. mLoaded = false;
  54. mRender->setMode(Render::modeDisabled);
  55. getWorld().destroy();
  56. mRender->ClearWorld();
  57. getSound().clear(); // Remove all previously loaded sounds
  58. }
  59. int Game::loadLevel(const char *level) {
  60. if (mLoaded)
  61. destroy();
  62. mName = bufferString("%s", level);
  63. // Load the level pak into TombRaider
  64. getConsole().print("Loading %s", mName);
  65. int error = mTombRaider.Load(mName);
  66. if (error != 0) {
  67. return error;
  68. }
  69. // If required, load the external sound effect file MAIN.SFX into TombRaider
  70. if ((mTombRaider.getEngine() == TR_VERSION_2) || (mTombRaider.getEngine() == TR_VERSION_3)) {
  71. char *tmp = bufferString("%sMAIN.SFX", level); // Ensure theres enough space
  72. size_t length = strlen(tmp);
  73. size_t dir = 0;
  74. for (int i = length - 1; i >= 0; i--) {
  75. if ((tmp[i] == '/') || (tmp[i] == '\\')) {
  76. dir = i + 1; // Find where the filename (bla.tr2) starts
  77. break;
  78. }
  79. }
  80. strcpy(tmp + dir, "MAIN.SFX"); // overwrite the name itself with MAIN.SFX
  81. tmp[dir + 8] = '\0';
  82. error = mTombRaider.loadSFX(tmp);
  83. if (error != 0) {
  84. getConsole().print("Could not load %s", tmp);
  85. }
  86. delete [] tmp;
  87. }
  88. // Process data
  89. processTextures();
  90. processRooms();
  91. processModels();
  92. processSprites();
  93. processMoveables();
  94. processPakSounds();
  95. // Free pak file
  96. mTombRaider.reset();
  97. // Check if the level contains Lara
  98. if (mLara == NULL) {
  99. getConsole().print("Can't find Lara entity in level pak!");
  100. return -1;
  101. }
  102. mLoaded = true;
  103. mRender->setMode(Render::modeVertexLight);
  104. return 0;
  105. }
  106. void Game::handleAction(ActionEvents action, bool isFinished) {
  107. if (mLoaded) {
  108. if (action == forwardAction) {
  109. getWorld().moveEntity(mLara, 'f');
  110. } else if (action == backwardAction) {
  111. getWorld().moveEntity(mLara, 'b');
  112. } else if (action == leftAction) {
  113. getWorld().moveEntity(mLara, 'l');
  114. } else if (action == rightAction) {
  115. getWorld().moveEntity(mLara, 'r');
  116. }
  117. }
  118. }
  119. void Game::handleMouseMotion(int xrel, int yrel) {
  120. if (mLoaded) {
  121. // Move Camera on X Axis
  122. if (xrel > 0)
  123. while (xrel-- > 0)
  124. getCamera().command(CAMERA_ROTATE_RIGHT);
  125. else if (xrel < 0)
  126. while (xrel++ < 0)
  127. getCamera().command(CAMERA_ROTATE_LEFT);
  128. // Move Camera on Y Axis
  129. if (yrel > 0)
  130. while (yrel-- > 0)
  131. getCamera().command(CAMERA_ROTATE_UP);
  132. else if (yrel < 0)
  133. while (yrel++ < 0)
  134. getCamera().command(CAMERA_ROTATE_DOWN);
  135. // Fix Laras rotation
  136. mLara->angles[1] = getCamera().getRadianYaw();
  137. mLara->angles[2] = getCamera().getRadianPitch();
  138. }
  139. }
  140. void Game::display() {
  141. mRender->Display();
  142. }
  143. int Game::command(std::vector<char *> *args) {
  144. if (args->size() < 1) {
  145. getConsole().print("Invalid use of game-command!");
  146. return -1;
  147. }
  148. char *cmd = args->at(0);
  149. if (strcmp(cmd, "mode") == 0) {
  150. if (args->size() > 1) {
  151. char *mode = args->at(1);
  152. if (strcmp(mode, "wireframe") == 0) {
  153. if (mLoaded) {
  154. mRender->setMode(Render::modeWireframe);
  155. getConsole().print("Wireframe mode");
  156. } else {
  157. getConsole().print("Load a level to set this mode!");
  158. return -2;
  159. }
  160. } else if (strcmp(mode, "solid") == 0) {
  161. if (mLoaded) {
  162. mRender->setMode(Render::modeSolid);
  163. getConsole().print("Solid mode");
  164. } else {
  165. getConsole().print("Load a level to set this mode!");
  166. return -3;
  167. }
  168. } else if (strcmp(mode, "texture") == 0) {
  169. if (mLoaded) {
  170. mRender->setMode(Render::modeTexture);
  171. getConsole().print("Texture mode");
  172. } else {
  173. getConsole().print("Load a level to set this mode!");
  174. return -4;
  175. }
  176. } else if (strcmp(mode, "vertexlight") == 0) {
  177. if (mLoaded) {
  178. mRender->setMode(Render::modeVertexLight);
  179. getConsole().print("Vertexlight mode");
  180. } else {
  181. getConsole().print("Load a level to set this mode!");
  182. return -5;
  183. }
  184. } else if (strcmp(mode, "titlescreen") == 0) {
  185. mRender->setMode(Render::modeLoadScreen);
  186. getConsole().print("Titlescreen mode");
  187. } else {
  188. getConsole().print("Invalid use of mode command (%s)!", mode);
  189. return -6;
  190. }
  191. } else {
  192. getConsole().print("Invalid use of mode command!");
  193. return -7;
  194. }
  195. } else if (strcmp(cmd, "move") == 0) {
  196. if (args->size() > 1) {
  197. if (mLoaded) {
  198. char *move = args->at(1);
  199. if (strcmp(move, "walk") == 0) {
  200. mLara->moveType = worldMoveType_walk;
  201. getConsole().print("Lara is walking...");
  202. } else if (strcmp(move, "fly") == 0) {
  203. mLara->moveType = worldMoveType_fly;
  204. getConsole().print("Lara is flying...");
  205. } else if (strcmp(move, "noclip") == 0) {
  206. mLara->moveType = worldMoveType_noClipping;
  207. getConsole().print("Lara is noclipping...");
  208. } else {
  209. getConsole().print("Invalid use of move command (%s)!", move);
  210. return -8;
  211. }
  212. } else {
  213. getConsole().print("Load a level to change the movement type!");
  214. return -9;
  215. }
  216. } else {
  217. getConsole().print("Invalid use of move command!");
  218. return -10;
  219. }
  220. } else if (strcmp(cmd, "sound") == 0) {
  221. if (args->size() > 1) {
  222. getSound().play(atoi(args->at(1)));
  223. } else {
  224. getConsole().print("Invalid use of sound command!");
  225. return -11;
  226. }
  227. } else if (strcmp(cmd, "animate") == 0) {
  228. if (args->size() > 1) {
  229. char c = args->at(1)[0];
  230. if (c == 'n') {
  231. // Step all skeletal models to their next animation
  232. if (mRender->getFlags() & Render::fAnimateAllModels) {
  233. for (unsigned int i = 0; i < mRender->mModels.size(); i++) {
  234. SkeletalModel *m = mRender->mModels[i];
  235. if (m->getAnimation() < ((int)m->model->animation.size() - 1))
  236. m->setAnimation(m->getAnimation() + 1);
  237. else
  238. if (m->getAnimation() != 0)
  239. m->setAnimation(0);
  240. }
  241. } else {
  242. getConsole().print("Animations need to be enabled!");
  243. }
  244. } else if (c == 'p') {
  245. // Step all skeletal models to their previous animation
  246. if (mRender->getFlags() & Render::fAnimateAllModels) {
  247. for (unsigned int i = 0; i < mRender->mModels.size(); i++) {
  248. SkeletalModel *m = mRender->mModels[i];
  249. if (m->getAnimation() > 0)
  250. m->setAnimation(m->getAnimation() - 1);
  251. else
  252. if (m->model->animation.size() > 0)
  253. m->setAnimation(m->model->animation.size() - 1);
  254. }
  255. } else {
  256. getConsole().print("Animations need to be enabled!");
  257. }
  258. } else {
  259. // Enable or disable animating all skeletal models
  260. bool b;
  261. if (readBool(args->at(1), &b) < 0) {
  262. getConsole().print("Pass BOOL to animate command!");
  263. return -12;
  264. }
  265. if (b)
  266. mRender->setFlags(Render::fAnimateAllModels);
  267. else
  268. mRender->clearFlags(Render::fAnimateAllModels);
  269. getConsole().print(b ? "Animating all models" : "No longer animating all models");
  270. }
  271. } else {
  272. getConsole().print("Invalid use of animate command!");
  273. return -13;
  274. }
  275. } else if (strcmp(cmd, "help") == 0) {
  276. if (args->size() < 2) {
  277. getConsole().print("game-command Usage:");
  278. getConsole().print(" game COMMAND");
  279. getConsole().print("Available commands:");
  280. getConsole().print(" move [walk|fly|noclip]");
  281. getConsole().print(" sound INT");
  282. getConsole().print(" mode MODE");
  283. getConsole().print(" animate [BOOL|n|p]");
  284. } else if (strcmp(args->at(1), "sound") == 0) {
  285. getConsole().print("game-sound-command Usage:");
  286. getConsole().print(" game sound INT");
  287. getConsole().print("Where INT is a valid sound ID integer");
  288. } else if (strcmp(args->at(1), "move") == 0) {
  289. getConsole().print("game-move-command Usage:");
  290. getConsole().print(" game move COMMAND");
  291. getConsole().print("Where COMMAND is one of the following:");
  292. getConsole().print(" walk");
  293. getConsole().print(" fly");
  294. getConsole().print(" noclip");
  295. } else if (strcmp(args->at(1), "mode") == 0) {
  296. getConsole().print("game-mode-command Usage:");
  297. getConsole().print(" game mode MODE");
  298. getConsole().print("Where MODE is one of the following:");
  299. getConsole().print(" wireframe");
  300. getConsole().print(" solid");
  301. getConsole().print(" texture");
  302. getConsole().print(" vertexlight");
  303. getConsole().print(" titlescreen");
  304. } else if (strcmp(args->at(1), "animate") == 0) {
  305. getConsole().print("game-animate-command Usage:");
  306. getConsole().print(" game animate [n|p|BOOL]");
  307. getConsole().print("Where the commands have the following meaning:");
  308. getConsole().print(" BOOL to (de)activate animating all models");
  309. getConsole().print(" n to step all models to their next animation");
  310. getConsole().print(" p to step all models to their previous animation");
  311. } else {
  312. getConsole().print("No help available for game %s.", args->at(1));
  313. return -14;
  314. }
  315. } else {
  316. getConsole().print("Invalid use of game-command (%s)!", cmd);
  317. return -15;
  318. }
  319. return 0;
  320. }
  321. void Game::processPakSounds()
  322. {
  323. unsigned char *riff;
  324. unsigned int riffSz;
  325. //tr2_sound_source_t *sound;
  326. //tr2_sound_details_t *detail;
  327. //float pos[3];
  328. unsigned int i;
  329. int id;
  330. /* detail
  331. short sample;
  332. short volume;
  333. short sound_range;
  334. short flags; // bits 8-15: priority?, 2-7: number of sound samples
  335. // in this group, bits 0-1: channel number
  336. */
  337. printf("Processing pak sound files: ");
  338. for (i = 0; i < mTombRaider.getSoundSamplesCount(); ++i)
  339. {
  340. mTombRaider.getSoundSample(i, &riffSz, &riff);
  341. getSound().addWave(riff, riffSz, &id, getSound().SoundFlagsNone);
  342. //if (((i + 1) == TR_SOUND_F_PISTOL) && (id > 0))
  343. //{
  344. //m_testSFX = id;
  345. //}
  346. delete [] riff;
  347. // sound[i].sound_id; // internal sound index
  348. // sound[i].flags; // 0x40, 0x80, or 0xc0
  349. //pos[0] = sound[i].x;
  350. //pos[1] = sound[i].y;
  351. //pos[2] = sound[i].z;
  352. //getSound().SourceAt(id, pos);
  353. //printf(".");
  354. //fflush(stdout);
  355. }
  356. printf("Done! Found %u files.\n", mTombRaider.getSoundSamplesCount());
  357. }
  358. void Game::processTextures()
  359. {
  360. unsigned char *image;
  361. unsigned char *bumpmap;
  362. int i;
  363. printf("Processing TR textures: ");
  364. //if ( mTombRaider.getNumBumpMaps())
  365. // gBumpMapStart = mTombRaider.NumTextures();
  366. for (i = 0; i < mTombRaider.NumTextures(); ++i)
  367. {
  368. mTombRaider.Texture(i, &image, &bumpmap);
  369. // Overwrite any previous level textures on load
  370. mRender->loadTexture(image, 256, 256, mTextureLevelOffset + i);
  371. gMapTex2Bump[mTextureLevelOffset + i] = -1;
  372. if (bumpmap)
  373. {
  374. gMapTex2Bump[mTextureLevelOffset + i] = mTextureLevelOffset + i +
  375. mTombRaider.NumTextures();
  376. mRender->loadTexture(bumpmap, 256, 256, mTextureLevelOffset + i +
  377. mTombRaider.NumTextures());
  378. }
  379. if (image)
  380. delete [] image;
  381. if (bumpmap)
  382. delete [] bumpmap;
  383. //printf(".");
  384. //fflush(stdout);
  385. }
  386. mTextureOffset = mTextureLevelOffset + mTombRaider.NumTextures();
  387. printf("Done! Found %d textures.\n", mTombRaider.NumTextures());
  388. }
  389. void Game::processSprites()
  390. {
  391. int i, j, k, l, x, y, s_index, width, height;
  392. float scale, width2, height2;
  393. tr2_sprite_texture_t *sprite;
  394. tr2_sprite_texture_t *sprite_textures;
  395. tr2_sprite_sequence_t *sprite_sequence;
  396. sprite_seq_t *r_mesh;
  397. tr2_item_t *item;
  398. item = mTombRaider.Item();
  399. sprite_textures = mTombRaider.Sprite();
  400. sprite_sequence = mTombRaider.SpriteSequence();
  401. scale = 4.0;
  402. printf("Processing sprites: ");
  403. for (i = 0; i < mTombRaider.NumItems() - 1; ++i)
  404. {
  405. // It's a mesh, skip it
  406. if (mTombRaider.Engine() == TR_VERSION_1 && item[i].intensity1 == -1)
  407. continue;
  408. k = item[i].object_id;
  409. // Search the SpriteSequence list
  410. // (if we didn't already decide that it's a mesh)
  411. for (j = 0; j < (int)mTombRaider.NumSpriteSequences(); ++j)
  412. {
  413. if (sprite_sequence[j].object_id == k)
  414. {
  415. k = item[i].object_id;
  416. s_index = sprite_sequence[j].offset;
  417. r_mesh = new sprite_seq_t;
  418. getWorld().addSprite(r_mesh);
  419. r_mesh->num_sprites = -sprite_sequence[j].negative_length;
  420. r_mesh->sprite = new sprite_t[r_mesh->num_sprites];
  421. for (l = 0; l < r_mesh->num_sprites; ++l)
  422. {
  423. sprite = &sprite_textures[s_index];
  424. width = sprite->width >> 8;
  425. height = sprite->height >> 8;
  426. x = sprite->x;
  427. y = sprite->y;
  428. width2 = width * scale;
  429. height2 = height * scale;
  430. // For vising use
  431. r_mesh->sprite[l].pos[0] = item[i].x;
  432. r_mesh->sprite[l].pos[1] = item[i].y;
  433. r_mesh->sprite[l].pos[2] = item[i].z;
  434. r_mesh->sprite[l].texture = sprite->tile + mTextureStart;
  435. r_mesh->sprite[l].radius = width2 / 2.0f;
  436. r_mesh->sprite[l].vertex[0].pos[0] = -width2 / 2.0f;
  437. r_mesh->sprite[l].vertex[1].pos[0] = -width2 / 2.0f;
  438. r_mesh->sprite[l].vertex[2].pos[0] = width2 / 2.0f;
  439. r_mesh->sprite[l].vertex[3].pos[0] = width2 / 2.0f;
  440. r_mesh->sprite[l].vertex[0].pos[1] = 0;
  441. r_mesh->sprite[l].vertex[1].pos[1] = -height2;
  442. r_mesh->sprite[l].vertex[2].pos[1] = -height2;
  443. r_mesh->sprite[l].vertex[3].pos[1] = 0;
  444. r_mesh->sprite[l].vertex[0].pos[2] = 0;
  445. r_mesh->sprite[l].vertex[1].pos[2] = 0;
  446. r_mesh->sprite[l].vertex[2].pos[2] = 0;
  447. r_mesh->sprite[l].vertex[3].pos[2] = 0;
  448. r_mesh->sprite[l].texel[3].st[0] = (vec_t)(x+width)/TexelScale;
  449. r_mesh->sprite[l].texel[3].st[1] = (vec_t)(y+height)/TexelScale;
  450. r_mesh->sprite[l].texel[2].st[0] = (vec_t)(x+width)/TexelScale;
  451. r_mesh->sprite[l].texel[2].st[1] = (vec_t)(y)/TexelScale;
  452. r_mesh->sprite[l].texel[1].st[0] = (vec_t)(x) /TexelScale;
  453. r_mesh->sprite[l].texel[1].st[1] = (vec_t)(y) /TexelScale;
  454. r_mesh->sprite[l].texel[0].st[0] = (vec_t)(x) / TexelScale;
  455. r_mesh->sprite[l].texel[0].st[1] = (vec_t)(y+height)/TexelScale;
  456. //printf(".");
  457. //fflush(stdout);
  458. }
  459. }
  460. }
  461. }
  462. printf("Done! Found %d sprites.\n", mTombRaider.NumSpriteSequences());
  463. }
  464. void Game::processMoveables()
  465. {
  466. std::vector<unsigned int> cache;
  467. std::vector<skeletal_model_t *> cache2;
  468. tr2_mesh_t *mesh = NULL;
  469. tr2_moveable_t *moveable = NULL;
  470. tr2_meshtree_t *meshtree = NULL;
  471. tr2_item_t *item = NULL;
  472. tr2_animation_t *animation = NULL;
  473. unsigned short *frame = NULL;
  474. tr2_sprite_sequence_t *sprite_sequence = NULL;
  475. tr2_object_texture_t *object_texture = NULL;
  476. int i, j, object_id;
  477. int ent = 0;
  478. unsigned int statCount = 0;
  479. frame = mTombRaider.Frame();
  480. moveable = mTombRaider.Moveable();
  481. meshtree = mTombRaider.MeshTree();
  482. mesh = mTombRaider.Mesh();
  483. object_texture = mTombRaider.ObjectTextures();
  484. item = mTombRaider.Item();
  485. animation = mTombRaider.Animation();
  486. sprite_sequence = mTombRaider.SpriteSequence();
  487. printf("Processing skeletal models: ");
  488. for (i = 0; i < mTombRaider.NumItems(); ++i)
  489. {
  490. object_id = item[i].object_id;
  491. // It may not be a moveable, test for sprite
  492. if (!(mTombRaider.Engine() == TR_VERSION_1 && item[i].intensity1 == -1))
  493. {
  494. for (j = 0; j < (int)mTombRaider.NumSpriteSequences(); ++j)
  495. {
  496. if (sprite_sequence[j].object_id == object_id)
  497. break;
  498. }
  499. // It's not a moveable, skip sprite
  500. if (j != (int)mTombRaider.NumSpriteSequences())
  501. {
  502. //printf("s");
  503. //fflush(stdout);
  504. continue;
  505. }
  506. }
  507. for (j = 0; j < (int)mTombRaider.NumMoveables(); ++j)
  508. {
  509. if ((int)moveable[j].object_id == object_id)
  510. break;
  511. }
  512. // It's not a moveable or even a sprite?, skip unknown
  513. if (j == (int)mTombRaider.NumMoveables())
  514. {
  515. //printf("?"); // what the wolf?
  516. //fflush(stdout);
  517. continue;
  518. }
  519. processMoveable(j, i, &ent, cache2, cache, object_id);
  520. statCount++;
  521. }
  522. // Get models that aren't items
  523. for (i = 0; i < mTombRaider.NumMoveables(); ++i)
  524. {
  525. switch ((int)moveable[i].object_id)
  526. {
  527. case 30:
  528. case 2: // Which tr needs this as model again?
  529. processMoveable(i, i, &ent, cache2, cache,
  530. (int)moveable[i].object_id);
  531. break;
  532. default:
  533. switch (mTombRaider.Engine())
  534. {
  535. case TR_VERSION_1:
  536. switch ((int)moveable[i].object_id)
  537. {
  538. case TombRaider1::LaraMutant:
  539. processMoveable(i, i, &ent, cache2, cache,
  540. (int)moveable[i].object_id);
  541. break;
  542. }
  543. break;
  544. case TR_VERSION_4:
  545. switch ((int)moveable[i].object_id)
  546. {
  547. case TR4_PISTOLS_ANIM:
  548. case TR4_UZI_ANIM:
  549. case TR4_SHOTGUN_ANIM:
  550. case TR4_CROSSBOW_ANIM:
  551. case TR4_GRENADE_GUN_ANIM:
  552. case TR4_SIXSHOOTER_ANIM:
  553. processMoveable(i, i, &ent, cache2, cache,
  554. (int)moveable[i].object_id);
  555. break;
  556. }
  557. break;
  558. case TR_VERSION_2:
  559. case TR_VERSION_3:
  560. case TR_VERSION_5:
  561. case TR_VERSION_UNKNOWN:
  562. break;
  563. }
  564. }
  565. }
  566. printf("Done! Found %d models.\n", mTombRaider.NumMoveables() + statCount);
  567. }
  568. void Game::processMoveable(int index, int i, int *ent,
  569. std::vector<skeletal_model_t *> &cache2,
  570. std::vector<unsigned int> &cache, int object_id)
  571. {
  572. skeletal_model_t *r_model = NULL;
  573. skeletal_model_t *c_model = NULL;
  574. animation_frame_t *animation_frame = NULL;
  575. tr2_mesh_t *mesh = NULL;
  576. tr2_moveable_t *moveable = NULL;
  577. tr2_meshtree_t *meshtree = NULL;
  578. tr2_item_t *item = NULL;
  579. tr2_animation_t *animation = NULL;
  580. tr2_meshtree_t *mesh_tree = NULL;
  581. bone_frame_t *bone = NULL;
  582. bone_tag_t *tag = NULL;
  583. entity_t *thing = NULL;
  584. SkeletalModel *sModel = 0x0;
  585. unsigned short *frame;
  586. int j, k, a, frame_step;
  587. unsigned int l, frame_offset, frame_count, f;
  588. float pos[3];
  589. float yaw;
  590. bool lara = false;
  591. int skyMesh;
  592. skyMesh = mTombRaider.getSkyModelId();
  593. frame = mTombRaider.Frame();
  594. moveable = mTombRaider.Moveable();
  595. meshtree = mTombRaider.MeshTree();
  596. mesh = mTombRaider.Mesh();
  597. item = mTombRaider.Item();
  598. animation = mTombRaider.Animation();
  599. pos[0] = item[i].x;
  600. pos[1] = item[i].y;
  601. pos[2] = item[i].z;
  602. yaw = ((item[i].angle >> 14) & 0x03);
  603. yaw *= 90;
  604. thing = new entity_t;
  605. thing->id = (*ent)++;
  606. thing->type = 0x00;
  607. thing->pos[0] = item[i].x;
  608. thing->pos[1] = item[i].y;
  609. thing->pos[2] = item[i].z;
  610. thing->angles[1] = yaw;
  611. thing->objectId = moveable[index].object_id;
  612. thing->moving = false;
  613. thing->animate = false;
  614. sModel = new SkeletalModel();
  615. mRender->addSkeletalModel(sModel);
  616. thing->tmpHook = sModel; // temp hack to keep a running version during refactoring
  617. if (mTombRaider.Engine() == TR_VERSION_1)
  618. {
  619. switch (thing->objectId)
  620. {
  621. case TombRaider1::Wolf:
  622. thing->state = TombRaider1::WolfState_Lying;
  623. //thing->animate = true;
  624. sModel->setAnimation(3);
  625. sModel->setFrame(0);
  626. break;
  627. }
  628. }
  629. //! \fixme Check here and see if we already have one for object_id later
  630. // if (getWorld().isCachedSkeletalModel(moveable[index].object_id))
  631. // {
  632. // thing->modelId = mRender->add(sModel);
  633. // return;
  634. // }
  635. r_model = new skeletal_model_t;
  636. r_model->id = moveable[index].object_id;
  637. // Gather more info if this is lara
  638. if (moveable[index].object_id == 0)
  639. {
  640. gLaraModel = r_model; // hack to avoid broken system until new event sys
  641. lara = true;
  642. getCamera().translate(pos[0], pos[1] - 470, pos[2]);
  643. thing->type = 0x02;
  644. mLara = thing; // Mongoose 2002.03.22, Cheap hack for now
  645. mLara->master = 0x0;
  646. switch (mTombRaider.Engine())
  647. {
  648. case TR_VERSION_3:
  649. mLara->modelId = i;
  650. sModel->setAnimation(TR_ANIAMTION_RUN);
  651. sModel->setIdleAnimation(TR_ANIAMTION_STAND);
  652. r_model->tr4Overlay = false;
  653. break;
  654. case TR_VERSION_4:
  655. mLara->modelId = i;
  656. sModel->setAnimation(TR_ANIAMTION_RUN);
  657. sModel->setIdleAnimation(TR_ANIAMTION_STAND);
  658. // Only TR4 lara has 2 layer bone tags/meshes per bone frame
  659. r_model->tr4Overlay = true;
  660. break;
  661. case TR_VERSION_1:
  662. case TR_VERSION_2:
  663. case TR_VERSION_5:
  664. case TR_VERSION_UNKNOWN:
  665. mLara->modelId = index;
  666. sModel->setAnimation(TR_ANIAMTION_RUN);
  667. sModel->setIdleAnimation(TR_ANIAMTION_STAND);
  668. r_model->tr4Overlay = false;
  669. break;
  670. }
  671. r_model->ponytailId = 0;
  672. }
  673. else
  674. {
  675. lara = false;
  676. r_model->ponytailId = -1;
  677. }
  678. // Animation
  679. a = moveable[index].animation;
  680. frame_offset = animation[a].frame_offset / 2;
  681. frame_step = animation[a].frame_size;
  682. int frame_cycle = 0;
  683. if (a >= (int)mTombRaider.NumAnimations())
  684. {
  685. a = mTombRaider.NumFrames() - frame_offset;
  686. }
  687. else
  688. {
  689. a = (animation[a].frame_offset / 2) - frame_offset;
  690. }
  691. if (frame_step != 0) // prevent divide-by-zero errors
  692. a /= frame_step;
  693. if (a != 0) // prevent divide-by-zero errors
  694. frame_offset += frame_step * (frame_cycle % a);
  695. if (a < 0)
  696. {
  697. //continue;
  698. return;
  699. }
  700. //! \fixme Might be better UID for each model, but this seems to work well
  701. j = object_id;
  702. // We only want one copy of the skeletal model in memory
  703. unsigned int foundIndex;
  704. bool found = false;
  705. for (foundIndex = 0; foundIndex < cache.size(); foundIndex++) {
  706. if ((int)cache[foundIndex] == j) {
  707. found = true;
  708. break;
  709. }
  710. }
  711. if (!found)
  712. {
  713. sModel->model = r_model;
  714. getWorld().addEntity(thing);
  715. k = getWorld().addModel(r_model);
  716. cache.push_back(j);
  717. cache2.push_back(r_model);
  718. switch (mTombRaider.Engine())
  719. {
  720. case TR_VERSION_4:
  721. if (mLara && moveable[index].object_id == 30)
  722. {
  723. r_model->ponytailId = k;
  724. r_model->ponytailMeshId = moveable[index].starting_mesh;
  725. r_model->ponytailNumMeshes = ((moveable[index].num_meshes > 0) ?
  726. moveable[index].num_meshes : 0);
  727. r_model->ponytailAngle = -90.0f;
  728. r_model->ponytail[0] = -3;
  729. r_model->ponytail[1] = -22;
  730. r_model->ponytail[2] = -20;
  731. r_model->ponyOff = 40;
  732. r_model->ponyOff2 = 32;
  733. r_model->pigtails = false;
  734. // Try to guess pigtails by looking for certian num verts in head
  735. if (mesh[moveable[0].starting_mesh].num_vertices > 80)
  736. {
  737. r_model->pigtails = true;
  738. r_model->ponyOff -= 20;
  739. r_model->ponytail[1] -= 32;
  740. }
  741. mRender->setFlags(Render::fRenderPonytail);
  742. getConsole().print("Found known ponytail");
  743. }
  744. break; // ?
  745. case TR_VERSION_1:
  746. case TR_VERSION_2:
  747. case TR_VERSION_3:
  748. case TR_VERSION_5:
  749. case TR_VERSION_UNKNOWN:
  750. if (mLara && moveable[index].object_id == 2)
  751. {
  752. r_model->ponytailId = k;
  753. r_model->ponytailMeshId = moveable[index].starting_mesh;
  754. r_model->ponytailNumMeshes = ((moveable[index].num_meshes > 0) ?
  755. moveable[index].num_meshes : 0);
  756. r_model->ponytailAngle = -90.0f;
  757. r_model->ponytail[0] = 0;
  758. r_model->ponytail[1] = -20;
  759. r_model->ponytail[2] = -20;
  760. r_model->ponyOff = 40;
  761. r_model->ponyOff2 = 0;
  762. mRender->setFlags(Render::fRenderPonytail);
  763. getConsole().print("Found ponytail?");
  764. }
  765. break;
  766. }
  767. }
  768. else
  769. {
  770. // Already cached
  771. delete r_model;
  772. c_model = cache2[foundIndex];
  773. sModel->model = c_model;
  774. getWorld().addEntity(thing);
  775. getWorld().addModel(c_model);
  776. printf("c");
  777. return;
  778. }
  779. int aloop = mTombRaider.getNumAnimsForMoveable(index);
  780. #ifdef DEBUG_MOVEABLE
  781. printf("\nanimation = %i, num_animations = %i\n",
  782. moveable[index].animation, aloop);
  783. printf("\nitem[%i].flags = %i\nentity[%i]\n",
  784. i, item[i].flags, thing->id);
  785. #endif
  786. //a = moveable[index].animation;
  787. //frame_offset = animation[a].frame_offset / 2;
  788. //frame_step = animation[a].frame_size;
  789. for (; a < aloop; ++a,
  790. frame_offset = animation[a].frame_offset / 2,
  791. frame_step = animation[a].frame_size)
  792. {
  793. animation_frame = new animation_frame_t;
  794. r_model->animation.push_back(animation_frame);
  795. frame_count = (animation[a].frame_end - animation[a].frame_start) + 1;
  796. animation_frame->rate = animation[a].frame_rate;
  797. #ifdef DEBUG_MOVEABLE
  798. printf("animation[%i] state and unknowns = %i, %i, %i, %i, %i\n",
  799. a, animation[a].state_id, animation[a].unknown1,
  800. animation[a].unknown2, animation[a].unknown3,
  801. animation[a].unknown4);
  802. printf("animation[%i].frame_rate = %i\n",
  803. a, animation[a].frame_rate);
  804. printf("animation[%i].next_animation = %i\n",
  805. a, animation[a].next_animation);
  806. printf("animation[%i].frame_offset = %u\n",
  807. a, animation[a].frame_offset);
  808. printf("animation[%i].anim_command = %i\n",
  809. a, animation[a].anim_command);
  810. printf("animation[%i].num_anim_commands = %i\n",
  811. a, animation[a].num_anim_commands);
  812. printf("animation[%i].state_change_offset = %i\n",
  813. a, animation[a].state_change_offset);
  814. printf(" frame_offset = %u\n",
  815. frame_offset);
  816. #endif
  817. // Get all the frames for aniamtion
  818. for (f = 0; f < frame_count; ++f, frame_offset += frame_step)
  819. {
  820. // HACK: Lara's ObjectID is 315, but her meshes start at 0, so make a
  821. // quick substitution (so she doesn't appear as a bunch of thighs)
  822. if (index == 0 && mTombRaider.Engine() == TR_VERSION_3)
  823. {
  824. for (j = 0; j < (int)mTombRaider.NumMoveables() && !index; ++j)
  825. {
  826. if (moveable[j].object_id == 315)
  827. index = j;
  828. }
  829. }
  830. // Fix Lara in TR4
  831. if (index == 0 && mTombRaider.Engine() == TR_VERSION_4)
  832. {
  833. for (j = 0; j < (int)mTombRaider.NumMoveables() && !index; ++j)
  834. {
  835. // Body is ItemID 8, joints are ItemID 9
  836. // (TR4 demo: body is ItemID 10, joints are ItemID 11)
  837. if (moveable[j].object_id == 8)
  838. index = j;
  839. }
  840. }
  841. else if (moveable[index].object_id == 8 &&
  842. mTombRaider.Engine() == TR_VERSION_4)
  843. {
  844. // KLUDGE to do "skinning"
  845. index = 0;
  846. for (j = 0; j < (int)mTombRaider.NumMoveables() && !index; ++j)
  847. {
  848. // Body is ItemID 8, joints are ItemID 9
  849. // (TR4 demo: body is ItemID 10, joints are ItemID 11)
  850. if (moveable[j].object_id == 9)
  851. index = j;
  852. }
  853. }
  854. #ifdef DEBUG_MOVEABLE
  855. printf("animation[%i].boneframe[%u] = offset %u, step %i\n",
  856. a, f, frame_offset, frame_step);
  857. #endif
  858. // Mongoose 2002.08.15, Was
  859. // if (frame_offset + 8 > _tombraider.NumFrames())
  860. if (frame_offset > mTombRaider.NumFrames())
  861. {
  862. getConsole().print("WARNING: Bad animation frame %i > %i",
  863. frame_offset, mTombRaider.NumFrames());
  864. // Mongoose 2002.08.15, Attempt to skip more likely bad animation data
  865. getConsole().print("WARNING: Handling bad animation data...");
  866. return; //continue;
  867. }
  868. // Generate bone frames and tags per frame ////////////
  869. bone = new bone_frame_t;
  870. animation_frame->frame.push_back(bone);
  871. // Init translate for bone frame
  872. bone->pos[0] = (short)frame[frame_offset + 6];
  873. bone->pos[1] = (short)frame[frame_offset + 7];
  874. bone->pos[2] = (short)frame[frame_offset + 8];
  875. bone->yaw = yaw;
  876. //printf("%f %f %f\n", bone->pos[0], bone->pos[1], bone->pos[2]);
  877. l = 9; // First angle offset in this Frame
  878. // Run through the tag and calculate the rotation and offset
  879. for (j = 0; j < (int)moveable[index].num_meshes; ++j)
  880. {
  881. tag = new bone_tag_t;
  882. bone->tag.push_back(tag);
  883. tag->off[0] = 0.0;
  884. tag->off[1] = 0.0;
  885. tag->off[2] = 0.0;
  886. tag->flag = 0x00;
  887. tag->rot[0] = 0.0;
  888. tag->rot[1] = 0.0;
  889. tag->rot[2] = 0.0;
  890. tag->mesh = moveable[index].starting_mesh + j;
  891. // Setup offsets to produce skeletion
  892. if (j == 0)
  893. {
  894. // Since we use bone's offset, these aren't used
  895. tag->off[0] = 0.0;
  896. tag->off[1] = 0.0;
  897. tag->off[2] = 0.0;
  898. // Always push tag[0], this isn't really used either
  899. tag->flag = 0x02;
  900. }
  901. else // Nonprimary tag - position relative to first tag
  902. {
  903. int *tree;
  904. // Hack: moveable[index].mesh_tree is a byte offset
  905. // into mesh_tree[], so we have to convert to index
  906. tree = (int *)(void *)meshtree;
  907. mesh_tree = (tr2_meshtree_t *)&tree[moveable[index].mesh_tree
  908. + ((j - 1) * 4)];
  909. tag->off[0] = mesh_tree->x;
  910. tag->off[1] = mesh_tree->y;
  911. tag->off[2] = mesh_tree->z;
  912. tag->flag = (char)mesh_tree->flags;
  913. }
  914. // Setup tag rotations
  915. mTombRaider.computeRotationAngles(&frame, &frame_offset, &l,
  916. tag->rot, tag->rot+1, tag->rot+2);
  917. }
  918. }
  919. }
  920. if (i == skyMesh)
  921. {
  922. mRender->setSkyMesh(i, //moveable[i].starting_mesh,
  923. (mTombRaider.Engine() == TR_VERSION_2));
  924. }
  925. //printf(".");
  926. //fflush(stdout);
  927. }
  928. bool compareFaceTextureId(const void *voidA, const void *voidB)
  929. {
  930. texture_tri_t *a = (texture_tri_t *)voidA, *b = (texture_tri_t *)voidB;
  931. if (!a || !b)
  932. return false; // error really
  933. return (a->texture < b->texture);
  934. }
  935. #ifdef EXPERIMENTAL
  936. void Game::setupTextureColor(texture_tri_t *r_tri, float *colorf)
  937. {
  938. unsigned char color[4];
  939. unsigned int colorI;
  940. color[0] = (unsigned char)(colorf[0]*255.0f);
  941. color[1] = (unsigned char)(colorf[1]*255.0f);
  942. color[2] = (unsigned char)(colorf[2]*255.0f);
  943. color[3] = (unsigned char)(colorf[3]*255.0f);
  944. ((unsigned char *)(&colorI))[3] = color[0];
  945. ((unsigned char *)(&colorI))[2] = color[1];
  946. ((unsigned char *)(&colorI))[1] = color[2];
  947. ((unsigned char *)(&colorI))[0] = color[3];
  948. bool found = false;
  949. unsigned int foundIndex = 0;
  950. for (foundIndex = 0; foundIndex < gColorTextureHACK.size(); foundIndex++) {
  951. if (gColorTextureHACK[foundIndex] == colorI) {
  952. found = true;
  953. break;
  954. }
  955. }
  956. if (!found)
  957. {
  958. gColorTextureHACK.push_back(colorI);
  959. r_tri->texture = mTextureOffset + gColorTextureHACK.size();
  960. mRender->loadTexture(Texture::generateColorTexture(color, 32, 32),
  961. 32, 32,
  962. r_tri->texture);
  963. #ifdef DEBUG_COLOR_TEXTURE_GEN
  964. printf("Color 0x%02x%02x%02x%02x | 0x%08xto texture[%u]?\n",
  965. color[0], color[1], color[2], color[3], colorI,
  966. gColorTextureHACK.size());
  967. #endif
  968. }
  969. else
  970. {
  971. //printf("Color already loaded %i -> 0x%08x\n",
  972. // gColorTextureHACK.getCurrentIndex(),
  973. // gColorTextureHACK.current());
  974. r_tri->texture = mTextureOffset + foundIndex;
  975. }
  976. //r_tri->texture = white; // White texture
  977. }
  978. #endif
  979. void Game::processModels()
  980. {
  981. printf("Processing meshes: ");
  982. for (int index = 0; index < mTombRaider.getMeshCount(); index++) {
  983. int i, j, count, texture;
  984. int vertexIndices[6];
  985. float st[12];
  986. float color[4];
  987. unsigned short transparency;
  988. texture_tri_t *r_tri;
  989. // Assert common sense
  990. if (index < 0 || !mTombRaider.isMeshValid(index))
  991. {
  992. //! \fixme allow sparse lists with matching ids instead?
  993. getWorld().addMesh(NULL); // Filler, to make meshes array ids align
  994. //printf("x");
  995. //fflush(stdout);
  996. return;
  997. }
  998. #ifndef EXPERIMENTAL
  999. // WHITE texture id
  1000. int white = 0;
  1001. #endif
  1002. model_mesh_t *mesh = new model_mesh_t;
  1003. // Mongoose 2002.08.30, Testing support for 'shootable' models ( traceable )
  1004. mTombRaider.getMeshCollisionInfo(index, mesh->center, &mesh->radius);
  1005. //! \fixme Arrays don't work either =)
  1006. // Mesh geometery, colors, etc
  1007. mTombRaider.getMeshVertexArrays(index,
  1008. &mesh->vertexCount, &mesh->vertices,
  1009. &mesh->normalCount, &mesh->normals,
  1010. &mesh->colorCount, &mesh->colors);
  1011. // Textured Triangles
  1012. count = mTombRaider.getMeshTexturedTriangleCount(index);
  1013. mesh->texturedTriangles.reserve(count); // little faster
  1014. for (i = 0; i < count; ++i)
  1015. {
  1016. r_tri = new texture_tri_t;
  1017. mTombRaider.getMeshTexturedTriangle(index, i,
  1018. r_tri->index,
  1019. r_tri->st,
  1020. &r_tri->texture,
  1021. &r_tri->transparency);
  1022. r_tri->texture += mTextureStart;
  1023. // Add to face vector
  1024. mesh->texturedTriangles.push_back(r_tri);
  1025. }
  1026. // Coloured Triangles
  1027. count = mTombRaider.getMeshColoredTriangleCount(index);
  1028. mesh->coloredTriangles.reserve(count); // little faster
  1029. for (i = 0; i < count; i++)
  1030. {
  1031. r_tri = new texture_tri_t;
  1032. mTombRaider.getMeshColoredTriangle(index, i,
  1033. r_tri->index,
  1034. color);
  1035. r_tri->st[0] = color[0];
  1036. r_tri->st[1] = color[1];
  1037. r_tri->st[2] = color[2];
  1038. r_tri->st[3] = color[3];
  1039. r_tri->st[4] = 1.0;
  1040. r_tri->st[5] = 1.0;
  1041. #ifdef EXPERIMENTAL
  1042. setupTextureColor(r_tri, color);
  1043. #else
  1044. r_tri->texture = white; // White texture
  1045. #endif
  1046. r_tri->transparency = 0;
  1047. // Add to face vector
  1048. mesh->coloredTriangles.push_back(r_tri);
  1049. }
  1050. // Textured Rectangles
  1051. count = mTombRaider.getMeshTexturedRectangleCount(index);
  1052. mesh->texturedRectangles.reserve(count*2); // little faster
  1053. for (i = 0; i < count; ++i)
  1054. {
  1055. mTombRaider.getMeshTexturedRectangle(index, i,
  1056. vertexIndices,
  1057. st,
  1058. &texture,
  1059. &transparency);
  1060. r_tri = new texture_tri_t;
  1061. for (j = 0; j < 3; ++j)
  1062. r_tri->index[j] = vertexIndices[j];
  1063. for (j = 0; j < 6; ++j)
  1064. r_tri->st[j] = st[j];
  1065. r_tri->texture = texture + mTextureStart;
  1066. r_tri->transparency = transparency;
  1067. // Add to face vector
  1068. mesh->texturedRectangles.push_back(r_tri);
  1069. r_tri = new texture_tri_t;
  1070. for (j = 3; j < 6; ++j)
  1071. r_tri->index[j-3] = vertexIndices[j];
  1072. for (j = 6; j < 12; ++j)
  1073. r_tri->st[j-6] = st[j];
  1074. r_tri->texture = texture + mTextureStart;
  1075. r_tri->transparency = transparency;
  1076. // Add to face vector
  1077. mesh->texturedRectangles.push_back(r_tri);
  1078. }
  1079. // Coloured Rectangles
  1080. count = mTombRaider.getMeshColoredRectangleCount(index);
  1081. mesh->coloredRectangles.reserve(count*2); // little faster
  1082. for (i = 0; i < count; ++i)
  1083. {
  1084. mTombRaider.getMeshColoredRectangle(index, i,
  1085. vertexIndices,
  1086. color);
  1087. r_tri = new texture_tri_t;
  1088. for (j = 0; j < 3; ++j)
  1089. r_tri->index[j] = vertexIndices[j];
  1090. //for (j = 0; j < 6; ++j)
  1091. // r_tri->st[j] = st[j];
  1092. r_tri->st[0] = color[0];
  1093. r_tri->st[1] = color[1];
  1094. r_tri->st[2] = color[2];
  1095. r_tri->st[3] = color[3];
  1096. r_tri->st[4] = 1.0;
  1097. r_tri->st[5] = 1.0;
  1098. #ifdef EXPERIMENTAL
  1099. //for (j = 6; j < 12; ++j)
  1100. // r_tri->st[j-6] = st[j];
  1101. setupTextureColor(r_tri, color);
  1102. #else
  1103. r_tri->texture = white; // White texture
  1104. #endif
  1105. r_tri->transparency = 0;
  1106. // Add to face vector
  1107. mesh->coloredRectangles.push_back(r_tri);
  1108. r_tri = new texture_tri_t;
  1109. for (j = 3; j < 6; ++j)
  1110. r_tri->index[j-3] = vertexIndices[j];
  1111. //for (j = 6; j < 12; ++j)
  1112. // r_tri->st[j-6] = st[j];
  1113. r_tri->st[0] = color[0];
  1114. r_tri->st[1] = color[1];
  1115. r_tri->st[2] = color[2];
  1116. r_tri->st[3] = color[3];
  1117. r_tri->st[4] = 1.0;
  1118. r_tri->st[5] = 1.0;
  1119. #ifdef EXPERIMENTAL
  1120. setupTextureColor(r_tri, color);
  1121. #else
  1122. r_tri->texture = white; // White texture
  1123. #endif
  1124. r_tri->transparency = 0;
  1125. // Add to face vector
  1126. mesh->coloredRectangles.push_back(r_tri);
  1127. }
  1128. // Sort faces by texture
  1129. std::sort(mesh->texturedTriangles.begin(), mesh->texturedTriangles.end(), compareFaceTextureId);
  1130. std::sort(mesh->coloredTriangles.begin(), mesh->coloredTriangles.end(), compareFaceTextureId);
  1131. std::sort(mesh->texturedRectangles.begin(), mesh->texturedRectangles.end(), compareFaceTextureId);
  1132. std::sort(mesh->coloredRectangles.begin(), mesh->coloredRectangles.end(), compareFaceTextureId);
  1133. getWorld().addMesh(mesh);
  1134. //printf(".");
  1135. //fflush(stdout);
  1136. }
  1137. printf("Done! Found %d meshes.\n", mTombRaider.getMeshCount());
  1138. }
  1139. void Game::processRooms()
  1140. {
  1141. printf("Processing rooms: ");
  1142. for (int index = 0; index < mTombRaider.NumRooms(); index++) {
  1143. unsigned int i, j, count;
  1144. room_mesh_t *r_mesh = NULL;
  1145. RenderRoom *rRoom = NULL;
  1146. Matrix transform;
  1147. if (!mTombRaider.isRoomValid(index))
  1148. {
  1149. getConsole().print("WARNING: Handling invalid vertex array in room");
  1150. getWorld().addRoom(0x0);
  1151. mRender->addRoom(0x0);
  1152. //printf("x");
  1153. //fflush(stdout);
  1154. return;
  1155. }
  1156. rRoom = new RenderRoom();
  1157. r_mesh = new room_mesh_t;
  1158. r_mesh->id = index;
  1159. mTombRaider.getRoomInfo(index, &r_mesh->flags, r_mesh->pos,
  1160. r_mesh->bbox_min, r_mesh->bbox_max);
  1161. // Adjust positioning for OR world coord translation
  1162. r_mesh->bbox_min[0] += r_mesh->pos[0];
  1163. r_mesh->bbox_max[0] += r_mesh->pos[0];
  1164. r_mesh->bbox_min[2] += r_mesh->pos[2];
  1165. r_mesh->bbox_max[2] += r_mesh->pos[2];
  1166. // Mongoose 2002.04.03, Setup 3d transform
  1167. transform.setIdentity();
  1168. transform.translate(r_mesh->pos);
  1169. // Setup portals
  1170. float portalVertices[12];
  1171. count = mTombRaider.getRoomPortalCount(index);
  1172. //! \fixme OR wrongly uses a cached adj room list for rendering vis
  1173. r_mesh->adjacentRooms.reserve(count + 1);
  1174. // Current room is always first
  1175. r_mesh->adjacentRooms.push_back(index);
  1176. for (i = 0; i < count; ++i)
  1177. {
  1178. portal_t *portal = new portal_t;
  1179. mTombRaider.getRoomPortal(index, i,
  1180. &portal->adjoining_room, portal->normal,
  1181. portalVertices);
  1182. for (j = 0; j < 4; ++j)
  1183. {
  1184. portal->vertices[j][0] = portalVertices[j*3];
  1185. portal->vertices[j][1] = portalVertices[j*3+1];
  1186. portal->vertices[j][2] = portalVertices[j*3+2];
  1187. // Relative coors in vis portals
  1188. transform.multiply3v(portal->vertices[j], portal->vertices[j]);
  1189. }
  1190. r_mesh->adjacentRooms.push_back(portal->adjoining_room);
  1191. r_mesh->portals.push_back(portal);
  1192. }
  1193. // Physics/gameplay use /////////////////////////////
  1194. //! \fixme Use more of sector structure, boxes, and floordata
  1195. // List of sectors in this room
  1196. unsigned int sectorFlags;
  1197. int floorDataIndex, boxIndex, roomBelow, roomAbove;
  1198. count = mTombRaider.getRoomSectorCount(index, &r_mesh->numZSectors,
  1199. &r_mesh->numXSectors);
  1200. r_mesh->sectors.reserve(count);
  1201. for (i = 0; i < count; ++i)
  1202. {
  1203. sector_t *sector = new sector_t;
  1204. mTombRaider.getRoomSector(index, i, &sectorFlags,
  1205. &sector->ceiling, &sector->floor,
  1206. &floorDataIndex, &boxIndex, &roomBelow,
  1207. &roomAbove);
  1208. if (sectorFlags & tombraiderSector_wall)
  1209. {
  1210. sector->wall = true;
  1211. }
  1212. else
  1213. {
  1214. sector->wall = false;
  1215. }
  1216. r_mesh->sectors.push_back(sector);
  1217. }
  1218. // Setup collision boxes ( Should use sectors, but this is a test )
  1219. count = mTombRaider.getRoomBoxCount(index);
  1220. r_mesh->boxes.reserve(count);
  1221. //! fixme Only to be done only on room[0]? I don't think so...
  1222. for (i = 0; !index && i < count; ++i)
  1223. {
  1224. box_t *box = new box_t;
  1225. mTombRaider.getRoomBox(index, i,
  1226. box->a.pos, box->b.pos, box->c.pos, box->d.pos);
  1227. r_mesh->boxes.push_back(box);
  1228. }
  1229. // Setup room lights /////////////////////////////////////
  1230. unsigned int lightFlags, lightType;
  1231. count = mTombRaider.getRoomLightCount(index);
  1232. rRoom->lights.reserve(count);
  1233. for (i = 0; i < count; ++i)
  1234. {
  1235. Light *light = new Light();
  1236. mTombRaider.getRoomLight(index, i,
  1237. light->mPos, light->mColor, light->mDir,
  1238. &light->mAtt, &light->mCutoff,
  1239. &lightType, &lightFlags);
  1240. switch (lightType)
  1241. {
  1242. case tombraiderLight_typeDirectional:
  1243. light->mType = Light::typeDirectional;
  1244. break;
  1245. case tombraiderLight_typeSpot:
  1246. light->mType = Light::typeSpot;
  1247. break;
  1248. case tombraiderLight_typePoint:
  1249. default:
  1250. light->mType = Light::typePoint;
  1251. }
  1252. rRoom->lights.push_back(light);
  1253. }
  1254. // Room geometery //////////////////////////////////
  1255. //#define EXPERIMENTAL_UNFIFIED_ROOM_GEOMETERY
  1256. #ifdef EXPERIMENTAL_UNFIFIED_ROOM_GEOMETERY
  1257. unsigned int vertexCount, normalCount, colorCount, triCount;
  1258. vec_t *vertexArray;
  1259. vec_t *normalArray;
  1260. vec_t *colorArray;
  1261. unsigned int *indices, *flags;
  1262. float *texCoords;
  1263. int *textures;
  1264. mTombRaider.getRoomVertexArrays(index,
  1265. &vertexCount, &vertexArray,
  1266. &normalCount, &normalArray,
  1267. &colorCount, &colorArray);
  1268. rRoom->mesh.bufferVertexArray(vertexCount, (vec_t *)vertexArray);
  1269. rRoom->mesh.bufferNormalArray(normalCount, (vec_t *)normalArray);
  1270. rRoom->mesh.bufferColorArray(vertexCount, (vec_t *)colorArray);
  1271. mTombRaider.getRoomTriangles(index, mTextureStart,
  1272. &triCount, &indices, &texCoords, &textures,
  1273. &flags);
  1274. rRoom->mesh.bufferTriangles(triCount, indices, texCoords, textures, flags);
  1275. #else
  1276. float rgba[4];
  1277. float xyz[3];
  1278. count = mTombRaider.getRoomVertexCount(index);
  1279. rRoom->mesh.allocateVertices(count);
  1280. rRoom->mesh.allocateNormals(0); // count
  1281. rRoom->mesh.allocateColors(count);
  1282. for (i = 0; i < count; ++i)
  1283. {
  1284. mTombRaider.getRoomVertex(index, i, xyz, rgba);
  1285. rRoom->mesh.setVertex(i, xyz[0], xyz[1], xyz[2]);
  1286. rRoom->mesh.setColor(i, rgba);
  1287. }
  1288. // Mongoose 2002.06.09, Setup allocation of meshes and polygons
  1289. // Counters ( Textured polygon lists are allocated per texture)
  1290. // ( Textures are mapped to these meshes )
  1291. int triangle_counter[TextureLimit];
  1292. int triangle_counter_alpha[TextureLimit];
  1293. int rectangle_counter[TextureLimit];
  1294. int rectangle_counter_alpha[TextureLimit];
  1295. int tris_mesh_map[TextureLimit];
  1296. int rect_mesh_map[TextureLimit];
  1297. for (i = 0; i < TextureLimit; ++i)
  1298. {
  1299. triangle_counter[i] = 0;
  1300. triangle_counter_alpha[i] = 0;
  1301. rectangle_counter[i] = 0;
  1302. rectangle_counter_alpha[i] = 0;
  1303. tris_mesh_map[i] = -1;
  1304. rect_mesh_map[i] = -1;
  1305. }
  1306. unsigned int numTris = 0;
  1307. unsigned int numQuads = 0;
  1308. int texture;
  1309. unsigned int r, t, q, v, flags;
  1310. unsigned int indices[4];
  1311. float texCoords[8];
  1312. count = mTombRaider.getRoomTriangleCount(index);
  1313. // Mongoose 2002.08.15, Presort by alpha and texture and setup mapping
  1314. for (t = 0; t < count; ++t)
  1315. {
  1316. mTombRaider.getRoomTriangle(index, t,
  1317. indices, texCoords, &texture, &flags);
  1318. texture += mTextureStart;
  1319. if (texture > (int)TextureLimit)
  1320. {
  1321. getConsole().print("Handling bad room[%i].tris[%i].texture = %i",
  1322. index, t, texture);
  1323. texture = TextureLimit - 1;
  1324. }
  1325. // Counters set up polygon allocation
  1326. if (flags & tombraiderFace_Alpha ||
  1327. flags & tombraiderFace_PartialAlpha)
  1328. {
  1329. triangle_counter_alpha[texture] += 1;
  1330. }
  1331. else
  1332. {
  1333. triangle_counter[texture] += 1;
  1334. }
  1335. // Counter sets up texture id to mesh id mapping
  1336. if (tris_mesh_map[texture] == -1)
  1337. {
  1338. tris_mesh_map[texture] = ++numTris;
  1339. }
  1340. }
  1341. count = mTombRaider.getRoomRectangleCount(index);
  1342. for (r = 0; r < count; ++r)
  1343. {
  1344. mTombRaider.getRoomRectangle(index, r,
  1345. indices, texCoords, &texture, &flags);
  1346. texture += mTextureStart;
  1347. if (texture > (int)TextureLimit)
  1348. {
  1349. getConsole().print("Handling bad room[%i].quad[%i].texture = %i",
  1350. index, r, texture);
  1351. texture = TextureLimit - 1;
  1352. }
  1353. if (flags & tombraiderFace_Alpha ||
  1354. flags & tombraiderFace_PartialAlpha)
  1355. {
  1356. rectangle_counter_alpha[texture] += 1;
  1357. }
  1358. else
  1359. {
  1360. rectangle_counter[texture] += 1;
  1361. }
  1362. if (rect_mesh_map[texture] == -1)
  1363. {
  1364. rect_mesh_map[texture] = ++numQuads;
  1365. }
  1366. }
  1367. // Allocate indexed polygon meshes
  1368. rRoom->mesh.allocateTriangles(numTris);
  1369. rRoom->mesh.allocateRectangles(numQuads);
  1370. for (i = 0, j = 0; i < TextureLimit; ++i)
  1371. {
  1372. if (tris_mesh_map[i] > 0)
  1373. {
  1374. j = tris_mesh_map[i] - 1;
  1375. t = triangle_counter[i];
  1376. rRoom->mesh.mTris[j].texture = i;
  1377. #ifdef MULTITEXTURE
  1378. rRoom->mesh.mTris[j].bumpmap = gMapTex2Bump[i];
  1379. #endif
  1380. rRoom->mesh.mTris[j].cnum_triangles = 0;
  1381. rRoom->mesh.mTris[j].num_triangles = 0;
  1382. rRoom->mesh.mTris[j].cnum_alpha_triangles = 0;
  1383. rRoom->mesh.mTris[j].num_alpha_triangles = 0;
  1384. rRoom->mesh.mTris[j].triangles = 0x0;
  1385. rRoom->mesh.mTris[j].alpha_triangles = 0x0;
  1386. rRoom->mesh.mTris[j].texcoors = 0x0;
  1387. rRoom->mesh.mTris[j].texcoors2 = 0x0;
  1388. if (t > 0)
  1389. {
  1390. rRoom->mesh.mTris[j].num_triangles = t;
  1391. rRoom->mesh.mTris[j].triangles = new unsigned int[t*3];
  1392. rRoom->mesh.mTris[j].num_texcoors = t * 3;
  1393. rRoom->mesh.mTris[j].texcoors = new vec2_t[t * 3];
  1394. }
  1395. t = triangle_counter_alpha[i];
  1396. if (t > 0)
  1397. {
  1398. rRoom->mesh.mTris[j].num_alpha_triangles = t;
  1399. rRoom->mesh.mTris[j].alpha_triangles = new unsigned int[t*3];
  1400. rRoom->mesh.mTris[j].num_texcoors2 = t * 3;
  1401. rRoom->mesh.mTris[j].texcoors2 = new vec2_t[t * 3];
  1402. }
  1403. }
  1404. ///////////////////////////////////////////
  1405. if (rect_mesh_map[i] > 0)
  1406. {
  1407. j = rect_mesh_map[i] - 1;
  1408. r = rectangle_counter[i];
  1409. rRoom->mesh.mQuads[j].texture = i;
  1410. #ifdef MULTITEXTURE
  1411. rRoom->mesh.mQuads[j].bumpmap = gMapTex2Bump[i];
  1412. #endif
  1413. rRoom->mesh.mQuads[j].cnum_quads = 0;
  1414. rRoom->mesh.mQuads[j].num_quads = 0;
  1415. rRoom->mesh.mQuads[j].cnum_alpha_quads = 0;
  1416. rRoom->mesh.mQuads[j].num_alpha_quads = 0;
  1417. rRoom->mesh.mQuads[j].quads = 0x0;
  1418. rRoom->mesh.mQuads[j].alpha_quads = 0x0;
  1419. rRoom->mesh.mQuads[j].texcoors = 0x0;
  1420. rRoom->mesh.mQuads[j].texcoors2 = 0x0;
  1421. if (r > 0)
  1422. {
  1423. rRoom->mesh.mQuads[j].num_quads = r;
  1424. rRoom->mesh.mQuads[j].quads = new unsigned int[r*4];
  1425. rRoom->mesh.mQuads[j].num_texcoors = r * 4;
  1426. rRoom->mesh.mQuads[j].texcoors = new vec2_t[r * 4];
  1427. }
  1428. r = rectangle_counter_alpha[i];
  1429. if (r > 0)
  1430. {
  1431. rRoom->mesh.mQuads[j].num_alpha_quads = r;
  1432. rRoom->mesh.mQuads[j].alpha_quads = new unsigned int[r*4];
  1433. rRoom->mesh.mQuads[j].num_texcoors2 = r * 4;
  1434. rRoom->mesh.mQuads[j].texcoors2 = new vec2_t[r * 4];
  1435. }
  1436. }
  1437. }
  1438. // Generate textured triangles
  1439. count = mTombRaider.getRoomTriangleCount(index);
  1440. for (t = 0; t < count; ++t)
  1441. {
  1442. mTombRaider.getRoomTriangle(index, t,
  1443. indices, texCoords, &texture, &flags);
  1444. // Adjust texture id using mTextureStart to map into
  1445. // correct textures
  1446. texture += mTextureStart;
  1447. j = tris_mesh_map[texture] - 1;
  1448. // Setup per vertex
  1449. for (i = 0; i < 3; ++i)
  1450. {
  1451. // Get vertex index {(0, a), (1, b), (2, c)}
  1452. v = indices[i];
  1453. if ((flags & tombraiderFace_Alpha ||
  1454. flags & tombraiderFace_PartialAlpha) &&
  1455. rRoom->mesh.mTris[j].num_alpha_triangles > 0)
  1456. {
  1457. q = rRoom->mesh.mTris[j].cnum_alpha_triangles*3+i;
  1458. rRoom->mesh.mTris[j].alpha_triangles[q] = v;
  1459. rRoom->mesh.mTris[j].texcoors2[q][0] = texCoords[i*2];
  1460. rRoom->mesh.mTris[j].texcoors2[q][1] = texCoords[i*2+1];
  1461. }
  1462. else if (rRoom->mesh.mTris[j].num_triangles > 0)
  1463. {
  1464. q = rRoom->mesh.mTris[j].cnum_triangles*3+i;
  1465. rRoom->mesh.mTris[j].triangles[q] = v;
  1466. rRoom->mesh.mTris[j].texcoors[q][0] = texCoords[i*2];
  1467. rRoom->mesh.mTris[j].texcoors[q][1] = texCoords[i*2+1];
  1468. }
  1469. // Partial alpha hack
  1470. if (flags & tombraiderFace_PartialAlpha)
  1471. {
  1472. //rRoom->mesh.colors[v].rgba[3] = 0.45;
  1473. }
  1474. }
  1475. if (flags & tombraiderFace_Alpha ||
  1476. flags & tombraiderFace_PartialAlpha)
  1477. {
  1478. rRoom->mesh.mTris[j].cnum_alpha_triangles++;
  1479. }
  1480. else
  1481. {
  1482. rRoom->mesh.mTris[j].cnum_triangles++;
  1483. }
  1484. }
  1485. // Generate textured quads
  1486. count = mTombRaider.getRoomRectangleCount(index);
  1487. for (r = 0; r < count; ++r)
  1488. {
  1489. mTombRaider.getRoomRectangle(index, r,
  1490. indices, texCoords, &texture, &flags);
  1491. // Adjust texture id using mTextureStart to map into
  1492. // correct textures
  1493. texture += mTextureStart;
  1494. if (texture > (int)TextureLimit)
  1495. {
  1496. texture = TextureLimit - 1;
  1497. }
  1498. j = rect_mesh_map[texture] - 1;
  1499. if (rRoom->mesh.mQuads[j].num_quads <= 0 &&
  1500. rRoom->mesh.mQuads[j].num_alpha_quads <= 0)
  1501. continue;
  1502. // Setup per vertex
  1503. for (i = 0; i < 4; ++i)
  1504. {
  1505. // Get vertex index {(0, a), (1, b), (2, c), (3, d)}
  1506. v = indices[i];
  1507. if ((flags & tombraiderFace_Alpha ||
  1508. flags & tombraiderFace_PartialAlpha) &&
  1509. rRoom->mesh.mQuads[j].num_alpha_quads > 0)
  1510. {
  1511. q = rRoom->mesh.mQuads[j].cnum_alpha_quads*4+i;
  1512. rRoom->mesh.mQuads[j].alpha_quads[q] = v;
  1513. rRoom->mesh.mQuads[j].texcoors2[q][0] = texCoords[i*2];
  1514. rRoom->mesh.mQuads[j].texcoors2[q][1] = texCoords[i*2+1];
  1515. }
  1516. else if (rRoom->mesh.mQuads[j].num_quads > 0)
  1517. {
  1518. q = rRoom->mesh.mQuads[j].cnum_quads*4+i;
  1519. rRoom->mesh.mQuads[j].quads[q] = v;
  1520. rRoom->mesh.mQuads[j].texcoors[q][0] = texCoords[i*2];
  1521. rRoom->mesh.mQuads[j].texcoors[q][1] = texCoords[i*2+1];
  1522. }
  1523. // Partial alpha hack
  1524. if (flags & tombraiderFace_PartialAlpha)
  1525. {
  1526. //rRoom->mesh.colors[v].rgba[3] = 0.45;
  1527. }
  1528. }
  1529. if (flags & tombraiderFace_Alpha ||
  1530. flags & tombraiderFace_PartialAlpha)
  1531. {
  1532. rRoom->mesh.mQuads[j].cnum_alpha_quads++;
  1533. }
  1534. else
  1535. {
  1536. rRoom->mesh.mQuads[j].cnum_quads++;
  1537. }
  1538. }
  1539. #endif
  1540. // Room models
  1541. count = mTombRaider.getRoomModelCount(index);
  1542. r_mesh->models.reserve(count);
  1543. for (i = 0; i < count; ++i)
  1544. {
  1545. static_model_t *model = new static_model_t;
  1546. mTombRaider.getRoomModel(index, i,
  1547. &model->index, model->pos, &model->yaw);
  1548. r_mesh->models.push_back(model);
  1549. }
  1550. // Room sprites
  1551. float spriteVertices[12];
  1552. float spriteTexCoords[8];
  1553. count = mTombRaider.getRoomSpriteCount(index);
  1554. r_mesh->sprites.reserve(count);
  1555. for (i = 0; i < count; ++i)
  1556. {
  1557. sprite_t *sprite = new sprite_t;
  1558. mTombRaider.getRoomSprite(index, i,
  1559. 10.0f, &sprite->texture, sprite->pos,
  1560. spriteVertices, spriteTexCoords);
  1561. sprite->texture += mTextureStart; // OpenRaider preloads some textures
  1562. sprite->vertex[0].pos[0] = spriteVertices[0];
  1563. sprite->vertex[0].pos[1] = spriteVertices[1];
  1564. sprite->vertex[0].pos[2] = spriteVertices[2];
  1565. sprite->vertex[1].pos[0] = spriteVertices[3];
  1566. sprite->vertex[1].pos[1] = spriteVertices[4];
  1567. sprite->vertex[1].pos[2] = spriteVertices[5];
  1568. sprite->vertex[2].pos[0] = spriteVertices[6];
  1569. sprite->vertex[2].pos[1] = spriteVertices[7];
  1570. sprite->vertex[2].pos[2] = spriteVertices[8];
  1571. sprite->vertex[3].pos[0] = spriteVertices[9];
  1572. sprite->vertex[3].pos[1] = spriteVertices[10];
  1573. sprite->vertex[3].pos[2] = spriteVertices[11];
  1574. sprite->texel[0].st[0] = spriteTexCoords[0];
  1575. sprite->texel[0].st[1] = spriteTexCoords[1];
  1576. sprite->texel[1].st[0] = spriteTexCoords[2];
  1577. sprite->texel[1].st[1] = spriteTexCoords[3];
  1578. sprite->texel[2].st[0] = spriteTexCoords[4];
  1579. sprite->texel[2].st[1] = spriteTexCoords[5];
  1580. sprite->texel[3].st[0] = spriteTexCoords[6];
  1581. sprite->texel[3].st[1] = spriteTexCoords[7];
  1582. r_mesh->sprites.push_back(sprite);
  1583. }
  1584. getWorld().addRoom(r_mesh);
  1585. rRoom->room = r_mesh;
  1586. mRender->addRoom(rRoom);
  1587. //printf(".");
  1588. //fflush(stdout);
  1589. }
  1590. printf("Done! Found %d rooms.\n", mTombRaider.NumRooms());
  1591. }