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.

Game.cpp 60KB

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