Open Source Tomb Raider Engine
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

OpenRaider.cpp 77KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599
  1. /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
  2. /*================================================================
  3. *
  4. * Project : OpenRaider
  5. * Author : Mongoose
  6. * Website : http://www.westga.edu/~stu7440/
  7. * Email : stu7440@westga.edu
  8. * Object : OpenRaider
  9. * License : No use w/o permission (C) 2001 Mongoose
  10. * Comments: This is the main class for OpenRaider
  11. *
  12. *
  13. * This file was generated using Mongoose's C++
  14. * template generator script. <stu7440@westga.edu>
  15. *
  16. *-- History -------------------------------------------------
  17. *
  18. * 2001.05.21:
  19. * Mongoose - Created
  20. =================================================================*/
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <stdio.h>
  24. #include <stdarg.h>
  25. #include <unistd.h>
  26. #include <math.h>
  27. #include <sys/types.h>
  28. #ifdef DEBUG_MEMEORY
  29. # include "memeory_test.h"
  30. #endif
  31. #ifdef USING_MD3
  32. # include "Md3AnimModel.h"
  33. Md3AnimModel gMd3;
  34. #endif
  35. #include "World.h"
  36. #include "SkeletalModel.h"
  37. #include "TombRaider1.h" // tmp stop-gap
  38. #include "OpenRaider.h"
  39. enum OpenRaiderText { textConsole = 2, textMenu = 3, textOutput = 4 };
  40. const unsigned int TextureLimit = 24;
  41. const float TexelScale = 256.0f;
  42. World gWorld;
  43. Map<int, int> gMapTex2Bump;
  44. Vector <unsigned int> gColorTextureHACK;
  45. int gTextureOffset;
  46. entity_t *LARA = 0x0;
  47. entity_t *gClientPlayer[32];
  48. unsigned int gNetTicks = 0;
  49. unsigned int gNetLastTicks = 0;
  50. bool gStartServer = false;
  51. skeletal_model_t *gLaraModel = 0x0;
  52. char *gFontFilename = 0x0;
  53. unsigned int getTicks()
  54. {
  55. OpenRaider *game = OpenRaider::Instance();
  56. return game->getTicks();
  57. }
  58. ////////////////////////////////////////////////////////////
  59. // Constructors
  60. ////////////////////////////////////////////////////////////
  61. OpenRaider *OpenRaider::mInstance = 0x0;
  62. OpenRaider *OpenRaider::Instance()
  63. {
  64. if (mInstance == 0x0)
  65. {
  66. mInstance = new OpenRaider();
  67. }
  68. return mInstance;
  69. }
  70. void killOpenRaiderSingleton()
  71. {
  72. killNetworkSingleton();
  73. printf("Shutting down Game...\n");
  74. // Requires public deconstructor
  75. // Causes pointer-being-freed-not-allocated error!
  76. //delete OpenRaider::Instance();
  77. #warning "Can't delete OpenRaider::Instance() without a not-allocated-free error. Something is fishy here..."
  78. #ifdef DEBUG_MEMEORY
  79. printf("\n[Mongoose MEMEORY_DEBUG]\nMemory leak table:\n");
  80. dump_memory_report();
  81. #endif
  82. printf("\nThanks for testing %s\n", VERSION);
  83. printf("Please file bug reports\n\n");
  84. printf("Build date: %s @ %s\n", __DATE__, __TIME__);
  85. printf("Build host: %s\n", BUILD_HOST);
  86. printf("Web site : http://github.com/xythobuz/OpenRaider\n");
  87. }
  88. OpenRaider::OpenRaider() : SDLSystem()
  89. {
  90. Network::Instance();
  91. for (unsigned int i = 0; i < 32; ++i)
  92. {
  93. gClientPlayer[i] = 0x0;
  94. }
  95. m_pakDir = 0x0;
  96. m_audioDir = 0x0;
  97. m_homeDir = 0x0;
  98. m_mouseX = 2.5;
  99. m_mouseY = 0.5;
  100. m_texOffset = 0;
  101. mLevelTextureOffset = 0;
  102. m_testSFX = -1;
  103. mNoClipping = 0;
  104. // TODO, Replace numbers with enum modes
  105. // Only do this when you know the amount of commands + 1 ( 0 reserved )
  106. mMode[addCommandMode("[OpenRaider.Engine]")] = 2;
  107. mMode[addCommandMode("[Network.Server]")] = 5;
  108. mMode[addCommandMode("[Video.OpenGL]")] = 0;
  109. mMode[addCommandMode("[Audio.OpenAL]")] = 1;
  110. mMode[addCommandMode("[OpenRaider.Console]")] = 4;
  111. mMode[addCommandMode("[Input.Mouse]")] = 3;
  112. }
  113. OpenRaider::~OpenRaider()
  114. {
  115. // Mongoose 2002.01.02, FIXME GL call to critical section,
  116. // needs mutex really
  117. m_render.setMode(Render::modeDisabled);
  118. //sleep(1); // Why should we sleep here? -- xythobuz
  119. printf("Removing World...\n");
  120. gWorld.destroy();
  121. printf("Cleaning up...\n");
  122. for (mMapList.start(); mMapList.forward(); mMapList.next())
  123. {
  124. if (mMapList.current())
  125. {
  126. delete [] mMapList.current();
  127. }
  128. }
  129. for (mMusicList.start(); mMusicList.forward(); mMusicList.next())
  130. {
  131. if (mMusicList.current())
  132. {
  133. delete [] mMusicList.current();
  134. }
  135. }
  136. if (m_pakDir)
  137. delete [] m_pakDir;
  138. if (m_audioDir)
  139. delete [] m_audioDir;
  140. if (m_homeDir)
  141. delete [] m_homeDir;
  142. if (gFontFilename)
  143. delete [] gFontFilename;
  144. }
  145. ////////////////////////////////////////////////////////////
  146. // Public Accessors
  147. ////////////////////////////////////////////////////////////
  148. ////////////////////////////////////////////////////////////
  149. // Public Mutators
  150. ////////////////////////////////////////////////////////////
  151. void eventAnimTest(int anim)
  152. {
  153. #ifdef USING_MD3
  154. switch (anim)
  155. {
  156. case TR_ANIAMTION_TURN_R:
  157. case TR_ANIAMTION_TURN_L:
  158. //gMd3.setAnimLower(LEGS_TURN);
  159. break;
  160. case TR_ANIAMTION_RUN:
  161. gMd3.setAnimLower(LEGS_RUN);
  162. break;
  163. default:
  164. gMd3.setAnimLower(LEGS_IDLE);
  165. }
  166. #endif
  167. if (LARA)
  168. {
  169. SkeletalModel *mdl = (SkeletalModel *)LARA->tmpHook;
  170. if (mdl)
  171. {
  172. mdl->setAnimation(anim);
  173. }
  174. }
  175. }
  176. void percent_callback(int p)
  177. {
  178. OpenRaider &game = *OpenRaider::Instance();
  179. switch (p)
  180. {
  181. case 10:
  182. game.print(true, "Level textures loaded");
  183. break;
  184. default:
  185. // %% has problems with OpenRaider::print it seems
  186. game.print(false, "Level pak %i/100 loaded", p);
  187. }
  188. }
  189. void openraider_warning(const char *func_name, const char *warning,
  190. const char *filename, int line)
  191. {
  192. printf("%s> WARNING %s %s:%i\n", func_name, warning, filename, line);
  193. }
  194. void openraider_error(const char *func_name, const char *error,
  195. const char *filename, int line)
  196. {
  197. printf("%s> ERROR %s %s:%i\n", func_name, error, filename, line);
  198. }
  199. void from_network_layer(network_packet_t *p, unsigned int *last_id)
  200. {
  201. static unsigned int i = 0;
  202. *last_id = i++;
  203. if (gNetTicks > gNetLastTicks + 200) // 200ms
  204. {
  205. gNetLastTicks = gNetTicks;
  206. p->send = 1;
  207. }
  208. if (LARA)
  209. {
  210. p->pos[0] = LARA->pos[0];
  211. p->pos[1] = LARA->pos[1];
  212. p->pos[2] = LARA->pos[2];
  213. p->yaw = LARA->angles[1];
  214. p->pitch = LARA->angles[1];
  215. p->view_model = LARA->modelId;
  216. SkeletalModel *mdl = (SkeletalModel *)LARA->tmpHook;
  217. if (mdl)
  218. {
  219. p->aframe = mdl->getAnimation();
  220. p->bframe = mdl->getFrame();
  221. }
  222. }
  223. #ifdef DEBUG_NETWORK
  224. printf("<> Sending data\n");
  225. #endif
  226. }
  227. void to_network_layer(network_packet_t p)
  228. {
  229. OpenRaider &game = *OpenRaider::Instance();
  230. #ifdef DEBUG_NETWORK
  231. printf("<> Recieved data\n");
  232. #endif
  233. if (gClientPlayer[p.cid])
  234. {
  235. gClientPlayer[p.cid]->pos[0] = p.pos[0];
  236. gClientPlayer[p.cid]->pos[1] = p.pos[1];
  237. gClientPlayer[p.cid]->pos[2] = p.pos[2];
  238. gClientPlayer[p.cid]->angles[1] = p.yaw;
  239. gClientPlayer[p.cid]->angles[2] = p.pitch;
  240. }
  241. else if (LARA)
  242. {
  243. gClientPlayer[p.cid] = new entity_t;
  244. gClientPlayer[p.cid]->pos[0] = p.pos[0];
  245. gClientPlayer[p.cid]->pos[1] = p.pos[1];
  246. gClientPlayer[p.cid]->pos[2] = p.pos[2];
  247. gClientPlayer[p.cid]->angles[1] = p.yaw;
  248. gClientPlayer[p.cid]->angles[2] = p.pitch;
  249. gClientPlayer[p.cid]->moving = true;
  250. gClientPlayer[p.cid]->objectId = 0;
  251. gClientPlayer[p.cid]->id = LARA->id+1000+p.cid;
  252. gClientPlayer[p.cid]->type = 0x02;
  253. SkeletalModel *mdl = new SkeletalModel();
  254. gClientPlayer[p.cid]->tmpHook = mdl;
  255. mdl->setAnimation(p.aframe);
  256. mdl->setFrame(p.bframe);
  257. mdl->setIdleAnimation(TR_ANIAMTION_STAND);
  258. gClientPlayer[p.cid]->modelId = LARA->modelId; //p.view_model;
  259. gClientPlayer[p.cid]->animate = true;
  260. gWorld.addEntity(gClientPlayer[p.cid]);
  261. game.print(true, "A new player (%u) connected", p.cid);
  262. }
  263. if (LARA)
  264. {
  265. Network &network = *Network::Instance();
  266. network_frame_t &gPiggyBack = network.getPiggyBack();
  267. if (gNetTicks > gNetLastTicks + 200)
  268. {
  269. gNetLastTicks = gNetTicks;
  270. gPiggyBack.data.send = 1;
  271. }
  272. gPiggyBack.data.pos[0] = LARA->pos[0];
  273. gPiggyBack.data.pos[1] = LARA->pos[1];
  274. gPiggyBack.data.pos[2] = LARA->pos[2];
  275. gPiggyBack.data.yaw = LARA->angles[1];
  276. gPiggyBack.data.pitch = LARA->angles[2];
  277. gPiggyBack.data.view_model = LARA->modelId;
  278. SkeletalModel *mdl = (SkeletalModel *)LARA->tmpHook;
  279. if (mdl)
  280. {
  281. gPiggyBack.data.aframe = mdl->getAnimation();
  282. gPiggyBack.data.bframe = mdl->getFrame();
  283. }
  284. }
  285. }
  286. void OpenRaider::handleMouseMotionEvent(float x, float y)
  287. {
  288. if (x > 0)
  289. {
  290. while (x-- > 0) // Tried to fix very slow camera movements
  291. m_camera.command(CAMERA_ROTATE_RIGHT);
  292. if (LARA)
  293. {
  294. switch (LARA->moveType)
  295. {
  296. case worldMoveType_swim:
  297. case worldMoveType_fly:
  298. case worldMoveType_noClipping:
  299. eventAnimTest(TR_ANIAMTION_SWIM_R);
  300. break;
  301. default:
  302. eventAnimTest(TR_ANIAMTION_TURN_L); // TURN left always for now
  303. }
  304. LARA->moving = true;
  305. }
  306. }
  307. else if (x < 0)
  308. {
  309. while (x++ < 0) // Tried to fix very slow camera movements
  310. m_camera.command(CAMERA_ROTATE_LEFT);
  311. if (LARA)
  312. {
  313. switch (LARA->moveType)
  314. {
  315. case worldMoveType_swim:
  316. case worldMoveType_fly:
  317. case worldMoveType_noClipping:
  318. eventAnimTest(TR_ANIAMTION_SWIM_L);
  319. break;
  320. default:
  321. eventAnimTest(TR_ANIAMTION_TURN_L);
  322. }
  323. LARA->moving = true;
  324. }
  325. }
  326. if (y > 0)
  327. while (y-- > 0) // Tried to fix very slow camera movements
  328. m_camera.command(CAMERA_ROTATE_UP);
  329. else if (y < 0)
  330. while (y++ < 0) // Tried to fix very slow camera movements
  331. m_camera.command(CAMERA_ROTATE_DOWN);
  332. if (LARA)
  333. {
  334. LARA->angles[1] = m_camera.getRadianYaw();
  335. LARA->angles[2] = m_camera.getRadianPitch();
  336. }
  337. }
  338. void OpenRaider::handleKeyReleaseEvent(unsigned int key, unsigned int mod)
  339. {
  340. }
  341. void OpenRaider::handleBoundKeyPressEvent(unsigned int key)
  342. {
  343. switch (key)
  344. {
  345. case OpenRaiderKey_jump:
  346. m_camera.command(CAMERA_MOVE_UP);
  347. if (LARA)
  348. {
  349. LARA->moving = true;
  350. }
  351. break;
  352. case OpenRaiderKey_crouch:
  353. m_camera.command(CAMERA_MOVE_DOWN);
  354. if (LARA)
  355. {
  356. LARA->moving = true;
  357. }
  358. break;
  359. case OpenRaiderKey_forward:
  360. gWorld.moveEntity(LARA, 'f');
  361. if (LARA && LARA->moving)
  362. {
  363. switch (LARA->moveType)
  364. {
  365. case worldMoveType_swim:
  366. case worldMoveType_fly:
  367. case worldMoveType_noClipping:
  368. eventAnimTest(TR_ANIAMTION_SWIM);
  369. break;
  370. default:
  371. eventAnimTest(TR_ANIAMTION_RUN);
  372. }
  373. }
  374. else if (LARA)
  375. {
  376. switch (LARA->moveType)
  377. {
  378. case worldMoveType_swim:
  379. case worldMoveType_fly:
  380. case worldMoveType_noClipping:
  381. eventAnimTest(TR_ANIAMTION_SWIM_IDLE);
  382. break;
  383. default:
  384. eventAnimTest(TR_ANIAMTION_HIT_WALL_FRONT);
  385. }
  386. }
  387. else
  388. {
  389. m_camera.command(CAMERA_MOVE_FORWARD);
  390. }
  391. break;
  392. case OpenRaiderKey_backward:
  393. gWorld.moveEntity(LARA, 'b');
  394. if (LARA && LARA->moving)
  395. {
  396. switch (LARA->moveType)
  397. {
  398. case worldMoveType_swim:
  399. case worldMoveType_fly:
  400. case worldMoveType_noClipping:
  401. eventAnimTest(TR_ANIAMTION_SWIM);
  402. break;
  403. default:
  404. eventAnimTest(TR_ANIAMTION_RUN);
  405. }
  406. }
  407. break;
  408. case OpenRaiderKey_left:
  409. gWorld.moveEntity(LARA, 'l');
  410. if (LARA && LARA->moving)
  411. {
  412. switch (LARA->moveType)
  413. {
  414. case worldMoveType_swim:
  415. case worldMoveType_fly:
  416. case worldMoveType_noClipping:
  417. eventAnimTest(TR_ANIAMTION_SWIM);
  418. break;
  419. default:
  420. eventAnimTest(TR_ANIAMTION_RUN);
  421. }
  422. }
  423. else if (!LARA)
  424. {
  425. m_camera.command(CAMERA_MOVE_LEFT);
  426. }
  427. break;
  428. case OpenRaiderKey_right:
  429. gWorld.moveEntity(LARA, 'r');
  430. if (LARA && LARA->moving)
  431. {
  432. switch (LARA->moveType)
  433. {
  434. case worldMoveType_swim:
  435. case worldMoveType_fly:
  436. case worldMoveType_noClipping:
  437. eventAnimTest(TR_ANIAMTION_SWIM);
  438. break;
  439. default:
  440. eventAnimTest(TR_ANIAMTION_RUN);
  441. }
  442. }
  443. else if (!LARA)
  444. {
  445. m_camera.command(CAMERA_MOVE_RIGHT);
  446. }
  447. break;
  448. case OpenRaiderKey_panRight:
  449. m_camera.command(CAMERA_ROTATE_RIGHT);
  450. break;
  451. case OpenRaiderKey_panLeft:
  452. m_camera.command(CAMERA_ROTATE_LEFT);
  453. break;
  454. case OpenRaiderKey_tiltDown:
  455. m_camera.command(CAMERA_ROTATE_DOWN);
  456. break;
  457. case OpenRaiderKey_tiltUp:
  458. m_camera.command(CAMERA_ROTATE_UP);
  459. break;
  460. }
  461. }
  462. void OpenRaider::handleBoundKeyReleaseEvent(unsigned int key)
  463. {
  464. switch (key)
  465. {
  466. case '`': // Temp hack also until console is rolled back
  467. //i = 2;
  468. if (mConsoleMode)
  469. {
  470. //buffer[0] = '>';
  471. //buffer[1] = ' ';
  472. //buffer[2] = 0;
  473. mText->setActive(textConsole, true);
  474. }
  475. else
  476. {
  477. mText->setActive(textConsole, false);
  478. //buffer[0] = 0;
  479. }
  480. break;
  481. case OpenRaiderKey_forward:
  482. case OpenRaiderKey_backward:
  483. case OpenRaiderKey_right:
  484. case OpenRaiderKey_left:
  485. if (LARA)
  486. {
  487. LARA->moving = false;
  488. }
  489. }
  490. }
  491. void OpenRaider::handleConsoleKeyPressEvent(unsigned int key,unsigned int mod)
  492. {
  493. static char lastCmd[64] = "2 ";
  494. static unsigned int i = 0;
  495. char *buffer;
  496. unsigned int len;
  497. // Cheap console test
  498. len = mText->GetStringLen(textConsole);
  499. buffer = mText->GetBuffer(textConsole);
  500. //printf("- 0x%x\n", key);
  501. if (key == mConsoleKey)
  502. {
  503. i = 2;
  504. if (mConsoleMode)
  505. {
  506. buffer[0] = '>';
  507. buffer[1] = ' ';
  508. buffer[2] = 0;
  509. mText->setActive(textConsole, true);
  510. }
  511. else
  512. {
  513. mText->setActive(textConsole, false);
  514. buffer[0] = 0;
  515. }
  516. }
  517. else if (mConsoleMode && len > i+1)
  518. {
  519. switch (key)
  520. {
  521. case SYS_KEY_UP:
  522. i = lastCmd[0];
  523. lastCmd[0] = '>';
  524. mText->SetString(textConsole, lastCmd);
  525. break;
  526. case 0:
  527. break;
  528. case '\b':
  529. if (i > 2)
  530. {
  531. buffer[--i] = 0;
  532. }
  533. break;
  534. case '\r':
  535. case '\n':
  536. strncpy(lastCmd, buffer, 63);
  537. lastCmd[0] = i;
  538. command("[OpenRaider.Console]");
  539. command(buffer);
  540. i = 2;
  541. buffer[0] = '>';
  542. buffer[1] = ' ';
  543. buffer[2] = 0;
  544. break;
  545. default:
  546. if (mod & (SYS_MOD_KEY_RSHIFT | SYS_MOD_KEY_LSHIFT) &&
  547. key > 96 && key < 122)
  548. {
  549. buffer[i++] = (key - 32);
  550. }
  551. else
  552. {
  553. if (mod & (SYS_MOD_KEY_RSHIFT | SYS_MOD_KEY_LSHIFT))
  554. {
  555. if (key == '-')
  556. key = '_';
  557. }
  558. buffer[i++] = key;
  559. }
  560. buffer[i] = 0;
  561. }
  562. }
  563. }
  564. void OpenRaider::handleKeyPressEvent(unsigned int key, unsigned int mod)
  565. {
  566. static bool menu = false;
  567. // Cheap menu test
  568. if (menu)
  569. {
  570. switch (key)
  571. {
  572. case SYS_KEY_ESC:
  573. menu = false;
  574. mText->SetString(textMenu, " ");
  575. mText->setActive(textMenu, false);
  576. break;
  577. case SYS_KEY_ENTER:
  578. loadLevel(mMapList.current());
  579. mText->SetString(textMenu, " ");
  580. mText->setActive(textMenu, false);
  581. menu = false;
  582. break;
  583. case SYS_KEY_DOWN:
  584. mMapList.prev();
  585. if (!mMapList.backward())
  586. {
  587. mMapList.finish();
  588. }
  589. if (mMapList.current())
  590. {
  591. mText->SetString(textMenu, "Load %s?", mMapList.current());
  592. }
  593. else
  594. {
  595. mText->SetString(textMenu, "See README for map install");
  596. }
  597. break;
  598. case SYS_KEY_UP:
  599. mMapList.next();
  600. if (!mMapList.forward())
  601. {
  602. mMapList.start();
  603. }
  604. if (mMapList.current())
  605. {
  606. mText->SetString(textMenu, "Load %s?", mMapList.current());
  607. }
  608. else
  609. {
  610. mText->SetString(textMenu, "See README for map install");
  611. }
  612. }
  613. return;
  614. }
  615. switch (key)
  616. {
  617. case SYS_KEY_ESC:
  618. menu = true;
  619. mText->SetString(textMenu, "Select a map UP/DOWN");
  620. mText->setActive(textMenu, true);
  621. break;
  622. case SYS_KEY_ENTER:
  623. if (mod & SYS_MOD_KEY_LALT)
  624. {
  625. toggleFullscreen();
  626. }
  627. break;
  628. }
  629. ////////////////////////////////////////////////////////////
  630. switch (key)
  631. {
  632. case SYS_MOUSE_LEFT:
  633. mSound.play(m_testSFX);
  634. if (LARA)
  635. {
  636. eventAnimTest(15);
  637. }
  638. break;
  639. case '/':
  640. if (LARA)
  641. {
  642. entity_t *e = new entity_t;
  643. e->pos[0] = LARA->pos[0];
  644. e->pos[1] = LARA->pos[1] - 256.0f; // crawling H
  645. e->pos[2] = LARA->pos[2];
  646. e->type = 61;
  647. e->master = LARA->master;
  648. LARA->master = e;
  649. }
  650. break;
  651. case '[':
  652. if (LARA)
  653. {
  654. SkeletalModel *mdl = (SkeletalModel *)LARA->tmpHook;
  655. if (mdl)
  656. {
  657. mdl->setIdleAnimation(mdl->getIdleAnimation() - 1);
  658. mdl->setAnimation(mdl->getIdleAnimation());
  659. print(false, "AFRAME %i\n", mdl->getIdleAnimation());
  660. }
  661. }
  662. break;
  663. case ']':
  664. if (LARA)
  665. {
  666. SkeletalModel *mdl = (SkeletalModel *)LARA->tmpHook;
  667. if (mdl)
  668. {
  669. mdl->setIdleAnimation(mdl->getIdleAnimation() + 1);
  670. mdl->setAnimation(mdl->getIdleAnimation());
  671. print(false, "AFRAME %i\n", mdl->getIdleAnimation());
  672. }
  673. }
  674. break;
  675. case 'r':
  676. mSound.play(m_testSFX);
  677. break;
  678. }
  679. }
  680. void OpenRaider::print(bool dump_stdout, const char *format, ...)
  681. {
  682. static char buffer[128];
  683. va_list args;
  684. unsigned int l;
  685. va_start(args, format);
  686. vsnprintf(buffer, 128, format, args);
  687. l = strlen(buffer);
  688. if (!l || !buffer[0])
  689. {
  690. return;
  691. }
  692. // Strip message of an trailing carrage return
  693. if (buffer[l-1] == '\n')
  694. {
  695. buffer[l-1] = 0;
  696. }
  697. // Print to game 'console'
  698. if (mText)
  699. {
  700. mText->SetString(textOutput, buffer);
  701. }
  702. // Print to stdout
  703. if (dump_stdout)
  704. {
  705. fprintf(stdout, "> %s\n", buffer);
  706. }
  707. va_end(args);
  708. // Mongoose 2002.08.14, Currently, you must request
  709. // frame redraws in this mode
  710. if (m_flags & OpenRaider_Loading)
  711. {
  712. gameFrame();
  713. }
  714. }
  715. void OpenRaider::initGL()
  716. {
  717. // Mongoose 2002.08.13, Handled in start() actually
  718. }
  719. void OpenRaider::start()
  720. {
  721. vec3_t up;
  722. char *filename;
  723. printf("\n[Starting %s]\n\n", VERSION);
  724. filename = fullPath("~/.OpenRaider/OpenRaider.init", 0);
  725. if (loadResourceFile(filename) < 0)
  726. {
  727. printf("Could not find ~/.OpenRaider/OpenRaider.init\n");
  728. if (loadResourceFile("OpenRaider.init") < 0)
  729. {
  730. shutdown(-1);
  731. }
  732. printf("Loaded defaults...\n");
  733. }
  734. delete [] filename;
  735. m_camera.reset();
  736. m_camera.setSensitivityX(m_mouseX);
  737. m_camera.setSensitivityY(m_mouseY);
  738. m_camera.setSpeed(512);
  739. up[0] = 0.0;
  740. up[1] = -1.0;
  741. up[2] = 0.0;
  742. m_camera.setUp(up);
  743. if (mMapList.empty())
  744. {
  745. printf("No maps in map list, please edit your OpenRaider.init\n");
  746. shutdown(0);
  747. }
  748. // Mongoose 2002.08.13, System protected members abuse
  749. m_fovY = 40.0f;
  750. m_clipFar = 600000.0f;
  751. m_clipNear = 10.0f;
  752. // Mongoose 2002.08.13, This starts GL context
  753. printf("\n[Starting video subsystem...]\n");
  754. setFastCardPerformance(true);
  755. initVideo(m_width, m_height, false);
  756. // Mongoose 2002.01.02, Disable rendering to avoid GL call conflicts
  757. m_render.setMode(Render::modeDisabled);
  758. m_render.Init(m_width, m_height, m_fastCard);
  759. m_render.initTextures(m_homeDir, &m_texOffset, &mLevelTextureOffset);
  760. m_render.RegisterCamera(&m_camera);
  761. mText = m_render.GetString();
  762. // Mongoose 2002.01.03, Good idea?
  763. m_render.setMode(Render::modeLoadScreen);
  764. // Mongoose 2002.01.02, Load external audio tracks and fx
  765. // General audio init
  766. initSound();
  767. // Old room movement
  768. //gWorld.setFlag(World::fEnableHopping);
  769. resetTicks();
  770. runGame();
  771. }
  772. void OpenRaider::initSound()
  773. {
  774. //char filename[128];
  775. //unsigned int len;
  776. //int id;
  777. if (!(m_flags & OpenRaider_EnableSound) || mSound.init() < 0)
  778. {
  779. print(true, "Disabling sound...\n");
  780. m_flags |= OpenRaider_EnableSound;
  781. m_flags ^= OpenRaider_EnableSound;
  782. return;
  783. }
  784. printf("Processing external sound files: ");
  785. #ifdef OBSOLETE
  786. // Mongoose 2001.12.31, Use music list from init script
  787. if (mMusicList.Empty())
  788. {
  789. print(true, "No music in map list, please edit your OpenRaider.init\n");
  790. }
  791. else
  792. {
  793. snprintf(filename, 126, "%s%s", m_audioDir, mMusicList[0]);
  794. filename[127] = 0;
  795. if (!mSound.addFile(filename, &id, mSound.SoundFlagsLoop))
  796. {
  797. mSound.play(id);
  798. printf("m");
  799. fflush(stdout);
  800. }
  801. }
  802. //snprintf(filename, 126, "%s%s", m_homeDir, "sample.wav");
  803. //filename[127] = 0;
  804. //mSound.addFile(filename, &m_testSFX, mSound.SoundFlagsNone);
  805. printf(".");
  806. fflush(stdout);
  807. #endif
  808. printf("\n");
  809. }
  810. void OpenRaider::processPakSounds()
  811. {
  812. unsigned char *riff;
  813. unsigned int riffSz;
  814. //tr2_sound_source_t *sound;
  815. //tr2_sound_details_t *detail;
  816. //float pos[3];
  817. unsigned int i;
  818. int id;
  819. /* detail
  820. short sample;
  821. short volume;
  822. short sound_range;
  823. short flags; // bits 8-15: priority?, 2-7: number of sound samples
  824. // in this group, bits 0-1: channel number
  825. */
  826. if (m_flags & OpenRaider_EnableSound)
  827. {
  828. printf("Processing pak sound files: ");
  829. }
  830. else
  831. {
  832. return;
  833. }
  834. for (i = 0; i < m_tombraider.getSoundSamplesCount(); ++i)
  835. {
  836. print(false, "Processing pak sounds: %i / %i",
  837. i, m_tombraider.getSoundSamplesCount());
  838. m_tombraider.getSoundSample(i, &riffSz, &riff);
  839. mSound.addWave(riff, riffSz, &id, mSound.SoundFlagsNone);
  840. if (id == TR_SOUND_F_PISTOL && id > 0)
  841. {
  842. m_testSFX = id;
  843. }
  844. delete [] riff;
  845. // sound[i].sound_id; // internal sound index
  846. // sound[i].flags; // 0x40, 0x80, or 0xc0
  847. //pos[0] = sound[i].x;
  848. //pos[1] = sound[i].y;
  849. //pos[2] = sound[i].z;
  850. //mSound.SourceAt(id, pos);
  851. printf(".");
  852. fflush(stdout);
  853. }
  854. printf("\n");
  855. }
  856. void OpenRaider::loadLevel(char *mapname)
  857. {
  858. int i, j, len;
  859. char filename[256];
  860. // Mongoose 2002.03.23, Clear last loaded 'world'
  861. m_render.setMode(Render::modeDisabled);
  862. m_render.ClearWorld();
  863. gWorld.destroy();
  864. // Mongoose 2002.01.02, Now draw load screen, since external
  865. // GL textures are loaded and renderer is initialized
  866. m_render.setMode(Render::modeLoadScreen);
  867. gameFrame();
  868. /* 2003.07.05, Mongoose - No longer seeding, and looking for
  869. map to load -- load this map or fail and return */
  870. snprintf(filename, 254, "%s%s", m_pakDir, mapname);
  871. filename[255] = 0;
  872. len = strlen(filename);
  873. for (i = len, j = 0; i > 0; --i, ++j)
  874. {
  875. if (filename[i] == '/' || filename[i] == '\\')
  876. break;
  877. }
  878. j--;
  879. memset(m_mapName, 0, 32);
  880. for (i = 0; i < len - j && i < 30; ++i)
  881. {
  882. m_mapName[i] = filename[i + len - j];
  883. }
  884. m_tombraider.setDebug(m_flags & OpenRaider_DebugMap);
  885. m_flags |= OpenRaider_Loading;
  886. print(true, "Level %s loading", m_mapName);
  887. if (m_tombraider.Load(filename, percent_callback))
  888. {
  889. print(true, "ERROR: Failed to load level %s\n", m_mapName);
  890. return;
  891. }
  892. else
  893. {
  894. char altSfx[256];
  895. switch (m_tombraider.getEngine())
  896. {
  897. case TR_VERSION_2:
  898. case TR_VERSION_3:
  899. snprintf(altSfx, 255, "%s.sfx", filename);
  900. print(true, "Loading alternate SFX for TR2 or TR3 pak...\n");
  901. m_tombraider.loadSFX(altSfx);
  902. break;
  903. default:
  904. ;
  905. }
  906. }
  907. print(true, "Optimizing and translating pak data...");
  908. m_flags ^= OpenRaider_Loading;
  909. // Mongoose 2002.08.16, Used to cache TR4 textures at 10% of file load
  910. // in a callback - then with other engines process them here
  911. m_render.setMode(Render::modeDisabled);
  912. //sleep(1); // Why should we sleep here? -- xythobuz
  913. processTextures();
  914. m_render.setMode(Render::modeLoadScreen);
  915. print(true, "Level textures cached\n");
  916. // Cache/process rooms
  917. printf("Processing rooms: ");
  918. for (i = 0; i < m_tombraider.NumRooms(); ++i)
  919. {
  920. processRoom(i);
  921. print(false, "Processing rooms: %i/%i", i, m_tombraider.NumRooms());
  922. }
  923. printf("\n");
  924. // Cache/process meshes
  925. printf("Processing meshes: ");
  926. for (i = 0; i < m_tombraider.getMeshCount(); ++i)
  927. {
  928. m_render.setMode(Render::modeDisabled);
  929. processModel(i);
  930. m_render.setMode(Render::modeLoadScreen);
  931. print(false, "Processing meshes: %i/%i", i, m_tombraider.getMeshCount());
  932. }
  933. printf("\n");
  934. // Cache/process sprites
  935. processSprites();
  936. // Cache/process skeletal models
  937. processMoveables();
  938. // Cache/process sound fx
  939. processPakSounds();
  940. #ifdef DEBUG_MEMEORY
  941. // Right before pak is cleared will be highest use or memory
  942. display_memory_usage();
  943. #endif
  944. // Mongoose 2002.01.02, Go ahead and free the TR pak
  945. m_tombraider.reset();
  946. print(true, "Level pak freed from memory, Starting game...");
  947. #ifdef DEBUG_MEMEORY
  948. display_memory_usage();
  949. #endif
  950. // Mongoose 2002.01.02, FIXME GL call to critical section,
  951. // needs mutex really
  952. m_render.setMode(Render::modeDisabled);
  953. //sleep(2);
  954. // Draw game, level is loaded
  955. m_render.setMode(Render::modeVertexLight);
  956. m_flags ^= OpenRaider_Loading;
  957. }
  958. void OpenRaider::gameFrame()
  959. {
  960. SkeletalModel *mdl = 0x0;
  961. unsigned int ticks;
  962. float time;
  963. // Remember: ticks in milliseconds, time in hundredths
  964. gNetTicks = ticks = getTicks();
  965. time = gNetTicks * 0.1f;
  966. switch (m_render.getMode())
  967. {
  968. case Render::modeDisabled:
  969. break;
  970. case Render::modeLoadScreen:
  971. if ((ticks % 10000) > 1)
  972. {
  973. m_render.drawLoadScreen();
  974. swapBuffersGL();
  975. }
  976. break;
  977. default:
  978. if (LARA)
  979. {
  980. SkeletalModel *mdl = (SkeletalModel *)LARA->tmpHook;
  981. if (mdl)
  982. {
  983. float elapsed = time - mdl->lastTime;
  984. if (elapsed > mdl->rate)
  985. {
  986. if (mdl->getAnimation() == 0 &&
  987. (mdl->getFrame() == 2 || mdl->getFrame() == 10))
  988. {
  989. if (m_flags & OpenRaider_EnableSound)
  990. {
  991. mSound.play(TR_SOUND_FOOTSTEP0);
  992. }
  993. }
  994. else if (mdl->getAnimation() == 15)
  995. {
  996. eventAnimTest(TR_ANIAMTION_RUN);
  997. }
  998. mdl->setFrame(mdl->getFrame()+1);
  999. mdl->lastTime = elapsed / mdl->rate;
  1000. }
  1001. else
  1002. {
  1003. mdl->lastTime = time;
  1004. }
  1005. }
  1006. }
  1007. m_render.Display();
  1008. swapBuffersGL();
  1009. if (mdl && mdl->getAnimation() == 12)
  1010. {
  1011. switch (LARA->moveType)
  1012. {
  1013. case worldMoveType_swim:
  1014. case worldMoveType_fly:
  1015. case worldMoveType_noClipping:
  1016. eventAnimTest(TR_ANIAMTION_SWIM_IDLE);
  1017. break;
  1018. default:
  1019. eventAnimTest(TR_ANIAMTION_STAND);
  1020. }
  1021. LARA->moving = false;
  1022. }
  1023. }
  1024. if (m_flags & OpenRaider_ShowFPS)
  1025. {
  1026. static unsigned int frames = 0;
  1027. static float lastTime = 0.0f;
  1028. ++frames;
  1029. // Only update every second, so it can't be affected
  1030. // by fast/slow cards it only counts frames instead
  1031. // of estimating
  1032. if (time - lastTime > 100.0f)
  1033. {
  1034. if (mText)
  1035. mText->SetString(1, "FPS %d", frames);
  1036. lastTime = time;
  1037. frames = 0;
  1038. }
  1039. }
  1040. }
  1041. void OpenRaider::processTextures()
  1042. {
  1043. unsigned char *image;
  1044. unsigned char *bumpmap;
  1045. int i;
  1046. printf("Processing TR textures: ");
  1047. //if ( m_tombraider.getNumBumpMaps())
  1048. // gBumpMapStart = m_tombraider.NumTextures();
  1049. for (i = 0; i < m_tombraider.NumTextures(); ++i)
  1050. {
  1051. print(false, "Processing textures: %i/%i", i, m_tombraider.NumTextures());
  1052. m_tombraider.Texture(i, &image, &bumpmap);
  1053. // Overwrite any previous level textures on load
  1054. m_render.loadTexture(image, 256, 256, mLevelTextureOffset + i);
  1055. gMapTex2Bump.Add(mLevelTextureOffset + i, -1);
  1056. if (bumpmap)
  1057. {
  1058. gMapTex2Bump.Add(mLevelTextureOffset + i, mLevelTextureOffset + i +
  1059. m_tombraider.NumTextures());
  1060. m_render.loadTexture(bumpmap, 256, 256, mLevelTextureOffset + i +
  1061. m_tombraider.NumTextures());
  1062. }
  1063. if (image)
  1064. delete [] image;
  1065. if (bumpmap)
  1066. delete [] bumpmap;
  1067. printf(".");
  1068. fflush(stdout);
  1069. }
  1070. gTextureOffset = mLevelTextureOffset + m_tombraider.NumTextures();
  1071. printf("\n");
  1072. }
  1073. ////////////////////////////////////////////////////////////
  1074. // Private Accessors
  1075. ////////////////////////////////////////////////////////////
  1076. ////////////////////////////////////////////////////////////
  1077. // Private Mutators
  1078. ////////////////////////////////////////////////////////////
  1079. void OpenRaider::soundEvent(int type, int id, vec3_t pos, vec3_t angles)
  1080. {
  1081. switch (type)
  1082. {
  1083. case 0: // Reset listener position
  1084. mSound.listenAt(pos, angles);
  1085. break;
  1086. default:
  1087. mSound.sourceAt(id, pos);
  1088. mSound.play(id);
  1089. }
  1090. }
  1091. void OpenRaider::processSprites()
  1092. {
  1093. int i, j, k, l, x, y, s_index, width, height;
  1094. float scale, width2, height2;
  1095. tr2_sprite_texture_t *sprite;
  1096. tr2_sprite_texture_t *sprite_textures;
  1097. tr2_sprite_sequence_t *sprite_sequence;
  1098. sprite_seq_t *r_mesh;
  1099. tr2_item_t *item;
  1100. item = m_tombraider.Item();
  1101. sprite_textures = m_tombraider.Sprite();
  1102. sprite_sequence = m_tombraider.SpriteSequence();
  1103. scale = 4.0;
  1104. printf("Processing sprites: ");
  1105. for (i = 0; i < m_tombraider.NumItems() - 1; ++i)
  1106. {
  1107. print(false, "Processing sprites in Items: %i/%i",
  1108. i, m_tombraider.NumItems());
  1109. // It's a mesh, skip it
  1110. if (m_tombraider.Engine() == TR_VERSION_1 && item[i].intensity1 == -1)
  1111. continue;
  1112. k = item[i].object_id;
  1113. // Search the SpriteSequence list
  1114. // (if we didn't already decide that it's a mesh)
  1115. for (j = 0; j < (int)m_tombraider.NumSpriteSequences(); ++j)
  1116. {
  1117. if (sprite_sequence[j].object_id == k)
  1118. {
  1119. k = item[i].object_id;
  1120. s_index = sprite_sequence[j].offset;
  1121. r_mesh = new sprite_seq_t;
  1122. gWorld.addSprite(r_mesh);
  1123. r_mesh->num_sprites = -sprite_sequence[j].negative_length;
  1124. r_mesh->sprite = new sprite_t[r_mesh->num_sprites];
  1125. for (l = 0; l < r_mesh->num_sprites; ++l)
  1126. {
  1127. sprite = &sprite_textures[s_index];
  1128. width = sprite->width >> 8;
  1129. height = sprite->height >> 8;
  1130. x = sprite->x;
  1131. y = sprite->y;
  1132. width2 = width * scale;
  1133. height2 = height * scale;
  1134. // For vising use
  1135. r_mesh->sprite[l].pos[0] = item[i].x;
  1136. r_mesh->sprite[l].pos[1] = item[i].y;
  1137. r_mesh->sprite[l].pos[2] = item[i].z;
  1138. r_mesh->sprite[l].texture = sprite->tile + m_texOffset;
  1139. r_mesh->sprite[l].radius = width2 / 2.0;
  1140. r_mesh->sprite[l].vertex[0].pos[0] = -width2 / 2.0;
  1141. r_mesh->sprite[l].vertex[1].pos[0] = -width2 / 2.0;
  1142. r_mesh->sprite[l].vertex[2].pos[0] = width2 / 2.0;
  1143. r_mesh->sprite[l].vertex[3].pos[0] = width2 / 2.0;
  1144. r_mesh->sprite[l].vertex[0].pos[1] = 0;
  1145. r_mesh->sprite[l].vertex[1].pos[1] = -height2;
  1146. r_mesh->sprite[l].vertex[2].pos[1] = -height2;
  1147. r_mesh->sprite[l].vertex[3].pos[1] = 0;
  1148. r_mesh->sprite[l].vertex[0].pos[2] = 0;
  1149. r_mesh->sprite[l].vertex[1].pos[2] = 0;
  1150. r_mesh->sprite[l].vertex[2].pos[2] = 0;
  1151. r_mesh->sprite[l].vertex[3].pos[2] = 0;
  1152. r_mesh->sprite[l].texel[3].st[0] = (double)(x+width)/TexelScale;
  1153. r_mesh->sprite[l].texel[3].st[1] = (double)(y+height)/TexelScale;
  1154. r_mesh->sprite[l].texel[2].st[0] = (double)(x+width)/TexelScale;
  1155. r_mesh->sprite[l].texel[2].st[1] = (double)(y)/TexelScale;
  1156. r_mesh->sprite[l].texel[1].st[0] = (double)(x) /TexelScale;
  1157. r_mesh->sprite[l].texel[1].st[1] = (double)(y) /TexelScale;
  1158. r_mesh->sprite[l].texel[0].st[0] = (double)(x) / TexelScale;
  1159. r_mesh->sprite[l].texel[0].st[1] = (double)(y+height)/TexelScale;
  1160. printf(".");
  1161. fflush(stdout);
  1162. }
  1163. }
  1164. }
  1165. }
  1166. printf("\n");
  1167. }
  1168. void OpenRaider::processMoveables()
  1169. {
  1170. List <unsigned int> cache;
  1171. List <skeletal_model_t *> cache2;
  1172. tr2_mesh_t *mesh = NULL;
  1173. tr2_moveable_t *moveable = NULL;
  1174. tr2_meshtree_t *meshtree = NULL;
  1175. tr2_item_t *item = NULL;
  1176. tr2_animation_t *animation = NULL;
  1177. unsigned short *frame = NULL;
  1178. tr2_sprite_sequence_t *sprite_sequence = NULL;
  1179. tr2_object_texture_t *object_texture = NULL;
  1180. int i, j, object_id;
  1181. int ent = 0;
  1182. frame = m_tombraider.Frame();
  1183. moveable = m_tombraider.Moveable();
  1184. meshtree = m_tombraider.MeshTree();
  1185. mesh = m_tombraider.Mesh();
  1186. object_texture = m_tombraider.ObjectTextures();
  1187. item = m_tombraider.Item();
  1188. animation = m_tombraider.Animation();
  1189. sprite_sequence = m_tombraider.SpriteSequence();
  1190. printf("Processing skeletal models: ");
  1191. for (i = 0; i < m_tombraider.NumItems(); ++i)
  1192. {
  1193. object_id = item[i].object_id;
  1194. // It may not be a moveable, test for sprite
  1195. if (!(m_tombraider.Engine() == TR_VERSION_1 && item[i].intensity1 == -1))
  1196. {
  1197. for (j = 0; j < (int)m_tombraider.NumSpriteSequences(); ++j)
  1198. {
  1199. if (sprite_sequence[j].object_id == object_id)
  1200. break;
  1201. }
  1202. // It's not a moveable, skip sprite
  1203. if (j != (int)m_tombraider.NumSpriteSequences())
  1204. {
  1205. printf("s");
  1206. fflush(stdout);
  1207. continue;
  1208. }
  1209. }
  1210. for (j = 0; j < (int)m_tombraider.NumMoveables(); ++j)
  1211. {
  1212. if ((int)moveable[j].object_id == object_id)
  1213. break;
  1214. }
  1215. // It's not a moveable or even a sprite?, skip unknown
  1216. if (j == (int)m_tombraider.NumMoveables())
  1217. {
  1218. printf("?"); // what the wolf?
  1219. fflush(stdout);
  1220. continue;
  1221. }
  1222. processMoveable(j, i, &ent, cache2, cache, object_id);
  1223. }
  1224. // Get models that aren't items
  1225. for (i = 0; i < m_tombraider.NumMoveables(); ++i)
  1226. {
  1227. print(false, "Processing skeletal models: %i/%i",
  1228. i, m_tombraider.NumMoveables());
  1229. switch ((int)moveable[i].object_id)
  1230. {
  1231. case 30:
  1232. case 2: // Which tr needs this as model agian?
  1233. processMoveable(i, i, &ent, cache2, cache,
  1234. (int)moveable[i].object_id);
  1235. break;
  1236. default:
  1237. switch (m_tombraider.Engine())
  1238. {
  1239. case TR_VERSION_1:
  1240. switch ((int)moveable[i].object_id)
  1241. {
  1242. case TombRaider1::LaraMutant:
  1243. processMoveable(i, i, &ent, cache2, cache,
  1244. (int)moveable[i].object_id);
  1245. break;
  1246. }
  1247. break;
  1248. case TR_VERSION_4:
  1249. switch ((int)moveable[i].object_id)
  1250. {
  1251. case TR4_PISTOLS_ANIM:
  1252. case TR4_UZI_ANIM:
  1253. case TR4_SHOTGUN_ANIM:
  1254. case TR4_CROSSBOW_ANIM:
  1255. case TR4_GRENADE_GUN_ANIM:
  1256. case TR4_SIXSHOOTER_ANIM:
  1257. processMoveable(i, i, &ent, cache2, cache,
  1258. (int)moveable[i].object_id);
  1259. break;
  1260. }
  1261. break;
  1262. default:
  1263. ;
  1264. }
  1265. }
  1266. }
  1267. printf("\n");
  1268. }
  1269. void OpenRaider::processMoveable(int index, int i, int *ent,
  1270. List <skeletal_model_t *> &cache2,
  1271. List <unsigned int> &cache, int object_id)
  1272. {
  1273. skeletal_model_t *r_model = NULL;
  1274. skeletal_model_t *c_model = NULL;
  1275. animation_frame_t *animation_frame = NULL;
  1276. tr2_mesh_t *mesh = NULL;
  1277. tr2_moveable_t *moveable = NULL;
  1278. tr2_meshtree_t *meshtree = NULL;
  1279. tr2_item_t *item = NULL;
  1280. tr2_animation_t *animation = NULL;
  1281. tr2_meshtree_t *mesh_tree = NULL;
  1282. bone_frame_t *bone = NULL;
  1283. bone_tag_t *tag = NULL;
  1284. entity_t *thing = NULL;
  1285. SkeletalModel *sModel = 0x0;
  1286. unsigned short *frame;
  1287. int j, k, a, frame_step;
  1288. unsigned int l, frame_offset, frame_count, f;
  1289. float pos[3];
  1290. float yaw;
  1291. bool lara = false;
  1292. int skyMesh;
  1293. skyMesh = m_tombraider.getSkyModelId();
  1294. frame = m_tombraider.Frame();
  1295. moveable = m_tombraider.Moveable();
  1296. meshtree = m_tombraider.MeshTree();
  1297. mesh = m_tombraider.Mesh();
  1298. item = m_tombraider.Item();
  1299. animation = m_tombraider.Animation();
  1300. pos[0] = item[i].x;
  1301. pos[1] = item[i].y;
  1302. pos[2] = item[i].z;
  1303. yaw = ((item[i].angle >> 14) & 0x03);
  1304. yaw *= 90;
  1305. thing = new entity_t;
  1306. thing->id = (*ent)++;
  1307. thing->type = 0x00;
  1308. thing->pos[0] = item[i].x;
  1309. thing->pos[1] = item[i].y;
  1310. thing->pos[2] = item[i].z;
  1311. thing->angles[1] = yaw;
  1312. thing->objectId = moveable[index].object_id;
  1313. thing->moving = false;
  1314. thing->animate = false;
  1315. sModel = new SkeletalModel();
  1316. m_render.addSkeletalModel(sModel);
  1317. thing->tmpHook = sModel; // temp hack to keep a running version during refactoring
  1318. if (m_tombraider.Engine() == TR_VERSION_1)
  1319. {
  1320. switch (thing->objectId)
  1321. {
  1322. case TombRaider1::Wolf:
  1323. thing->state = TombRaider1::WolfState_Lying;
  1324. //thing->animate = true;
  1325. sModel->setAnimation(3);
  1326. sModel->setFrame(0);
  1327. break;
  1328. }
  1329. }
  1330. // FIXME: Check here and see if we already have one for object_id later
  1331. // if (gWorld.isCachedSkeletalModel(moveable[index].object_id))
  1332. // {
  1333. // thing->modelId = m_render.add(sModel);
  1334. // return;
  1335. // }
  1336. r_model = new skeletal_model_t;
  1337. r_model->id = moveable[index].object_id;
  1338. // Gather more info if this is lara
  1339. if (moveable[index].object_id == 0)
  1340. {
  1341. gLaraModel = r_model; // hack to avoid broken system until new event sys
  1342. lara = true;
  1343. m_camera.translate(pos[0], pos[1] - 470, pos[2]);
  1344. thing->type = 0x02;
  1345. LARA = thing; // Mongoose 2002.03.22, Cheap hack for now
  1346. LARA->master = 0x0;
  1347. switch (m_tombraider.Engine())
  1348. {
  1349. case TR_VERSION_3:
  1350. LARA->modelId = i;
  1351. sModel->setAnimation(TR_ANIAMTION_RUN);
  1352. sModel->setIdleAnimation(TR_ANIAMTION_STAND);
  1353. r_model->tr4Overlay = false;
  1354. break;
  1355. case TR_VERSION_4:
  1356. LARA->modelId = i;
  1357. sModel->setAnimation(TR_ANIAMTION_RUN);
  1358. sModel->setIdleAnimation(TR_ANIAMTION_STAND);
  1359. // Only TR4 lara has 2 layer bone tags/meshes per bone frame
  1360. r_model->tr4Overlay = true;
  1361. break;
  1362. default:
  1363. LARA->modelId = index;
  1364. sModel->setAnimation(TR_ANIAMTION_RUN);
  1365. sModel->setIdleAnimation(TR_ANIAMTION_STAND);
  1366. r_model->tr4Overlay = false;
  1367. }
  1368. r_model->ponytailId = 0;
  1369. }
  1370. else
  1371. {
  1372. lara = false;
  1373. r_model->ponytailId = -1;
  1374. }
  1375. // Animation
  1376. a = moveable[index].animation;
  1377. frame_offset = animation[a].frame_offset / 2;
  1378. frame_step = animation[a].frame_size;
  1379. int frame_cycle = 0;
  1380. if (a >= (int)m_tombraider.NumAnimations())
  1381. {
  1382. a = m_tombraider.NumFrames() - frame_offset;
  1383. }
  1384. else
  1385. {
  1386. a = (animation[a].frame_offset / 2) - frame_offset;
  1387. }
  1388. if (frame_step != 0) // prevent divide-by-zero errors
  1389. a /= frame_step;
  1390. if (a != 0) // prevent divide-by-zero errors
  1391. frame_offset += frame_step * (frame_cycle % a);
  1392. if (a < 0)
  1393. {
  1394. // continue;
  1395. return;
  1396. }
  1397. // FIXME: Might be better UID for each model, but this seems
  1398. // to work well
  1399. j = object_id;
  1400. // We only want one copy of the skeletal model in memory
  1401. if (cache.Empty() || cache.SearchKey(j) == UINT_MAX)
  1402. {
  1403. sModel->model = r_model;
  1404. gWorld.addEntity(thing);
  1405. k = gWorld.addModel(r_model);
  1406. cache.Add(j);
  1407. cache2.Add(r_model);
  1408. switch (m_tombraider.Engine())
  1409. {
  1410. case TR_VERSION_4:
  1411. if (LARA && moveable[index].object_id == 30)
  1412. {
  1413. r_model->ponytailId = k;
  1414. r_model->ponytailMeshId = moveable[index].starting_mesh;
  1415. r_model->ponytailNumMeshes = ((moveable[index].num_meshes > 0) ?
  1416. moveable[index].num_meshes : 0);
  1417. r_model->ponytailAngle = -90.0f;
  1418. r_model->ponytail[0] = -3;
  1419. r_model->ponytail[1] = -22;
  1420. r_model->ponytail[2] = -20;
  1421. r_model->ponyOff = 40;
  1422. r_model->ponyOff2 = 32;
  1423. r_model->pigtails = false;
  1424. // Try to guess pigtails by looking for certian num verts in head
  1425. if (mesh[moveable[0].starting_mesh].num_vertices > 80)
  1426. {
  1427. r_model->pigtails = true;
  1428. r_model->ponyOff -= 20;
  1429. r_model->ponytail[1] -= 32;
  1430. }
  1431. m_render.setFlags(Render::fRenderPonytail);
  1432. print(true, "Found known ponytail\n");
  1433. }
  1434. default:
  1435. if (LARA && moveable[index].object_id == 2)
  1436. {
  1437. r_model->ponytailId = k;
  1438. r_model->ponytailMeshId = moveable[index].starting_mesh;
  1439. r_model->ponytailNumMeshes = ((moveable[index].num_meshes > 0) ?
  1440. moveable[index].num_meshes : 0);
  1441. r_model->ponytailAngle = -90.0f;
  1442. r_model->ponytail[0] = 0;
  1443. r_model->ponytail[1] = -20;
  1444. r_model->ponytail[2] = -20;
  1445. r_model->ponyOff = 40;
  1446. r_model->ponyOff2 = 0;
  1447. m_render.setFlags(Render::fRenderPonytail);
  1448. print(true, "Found ponytail?\n");
  1449. }
  1450. }
  1451. }
  1452. else
  1453. {
  1454. delete r_model;
  1455. c_model = cache2[cache.SearchKey(j)];
  1456. sModel->model = c_model;
  1457. gWorld.addEntity(thing);
  1458. gWorld.addModel(c_model);
  1459. printf("c"); // it's already cached
  1460. fflush(stdout);
  1461. // continue;
  1462. return;
  1463. }
  1464. int aloop = m_tombraider.getNumAnimsForMoveable(index);
  1465. #ifdef DEBUG
  1466. if (m_flags & OpenRaider_DebugModel)
  1467. {
  1468. printf("\nanimation = %i, num_animations = %i\n",
  1469. moveable[index].animation, aloop);
  1470. printf("\nitem[%i].flags = %i\nentity[%i]\n",
  1471. i, item[i].flags, thing->id);
  1472. }
  1473. #endif
  1474. //a = moveable[index].animation;
  1475. //frame_offset = animation[a].frame_offset / 2;
  1476. //frame_step = animation[a].frame_size;
  1477. for (; a < aloop; ++a,
  1478. frame_offset = animation[a].frame_offset / 2,
  1479. frame_step = animation[a].frame_size)
  1480. {
  1481. animation_frame = new animation_frame_t;
  1482. r_model->animation.pushBack(animation_frame);
  1483. frame_count = (animation[a].frame_end - animation[a].frame_start) + 1;
  1484. animation_frame->rate = animation[a].frame_rate;
  1485. #ifdef DEBUG
  1486. if (m_flags & OpenRaider_DebugModel)
  1487. {
  1488. printf("animation[%i] state and unknowns = %i, %i, %i, %i, %i\n",
  1489. a, animation[a].state_id, animation[a].unknown1,
  1490. animation[a].unknown2, animation[a].unknown3,
  1491. animation[a].unknown4);
  1492. printf("animation[%i].frame_rate = %i\n",
  1493. a, animation[a].frame_rate);
  1494. printf("animation[%i].next_animation = %i\n",
  1495. a, animation[a].next_animation);
  1496. printf("animation[%i].frame_offset = %i\n",
  1497. a, animation[a].frame_offset);
  1498. printf("animation[%i].anim_command = %i\n",
  1499. a, animation[a].anim_command);
  1500. printf("animation[%i].num_anim_commands = %i\n",
  1501. a, animation[a].num_anim_commands);
  1502. printf("animation[%i].state_change_offset = %i\n",
  1503. a, animation[a].state_change_offset);
  1504. printf(" frame_offset = %i\n",
  1505. frame_offset);
  1506. }
  1507. #endif
  1508. // Get all the frames for aniamtion
  1509. for (f = 0; f < frame_count; ++f, frame_offset += frame_step)
  1510. {
  1511. // HACK: Lara's ObjectID is 315, but her meshes start at 0, so make a
  1512. // quick substitution (so she doesn't appear as a bunch of thighs)
  1513. if (index == 0 && m_tombraider.Engine() == TR_VERSION_3)
  1514. {
  1515. for (j = 0; j < (int)m_tombraider.NumMoveables() && !index; ++j)
  1516. {
  1517. if (moveable[j].object_id == 315)
  1518. index = j;
  1519. }
  1520. }
  1521. // Fix Lara in TR4
  1522. if (index == 0 && m_tombraider.Engine() == TR_VERSION_4)
  1523. {
  1524. for (j = 0; j < (int)m_tombraider.NumMoveables() && !index; ++j)
  1525. {
  1526. // Body is ItemID 8, joints are ItemID 9
  1527. // (TR4 demo: body is ItemID 10, joints are ItemID 11)
  1528. if (moveable[j].object_id == 8)
  1529. index = j;
  1530. }
  1531. }
  1532. else if (moveable[index].object_id == 8 &&
  1533. m_tombraider.Engine() == TR_VERSION_4)
  1534. {
  1535. // KLUDGE to do "skinning"
  1536. index = 0;
  1537. for (j = 0; j < (int)m_tombraider.NumMoveables() && !index; ++j)
  1538. {
  1539. // Body is ItemID 8, joints are ItemID 9
  1540. // (TR4 demo: body is ItemID 10, joints are ItemID 11)
  1541. if (moveable[j].object_id == 9)
  1542. index = j;
  1543. }
  1544. }
  1545. #ifdef DEBUG
  1546. if (m_flags & OpenRaider_DebugModel)
  1547. {
  1548. printf("animation[%i].boneframe[%i] = offset %i, step %i\n",
  1549. a, f, frame_offset, frame_step);
  1550. }
  1551. #endif
  1552. // Mongoose 2002.08.15, Was
  1553. // if (frame_offset + 8 > _tombraider.NumFrames())
  1554. if (frame_offset > m_tombraider.NumFrames())
  1555. {
  1556. print(true, "WARNING: Bad animation frame %i > %i\n",
  1557. frame_offset, m_tombraider.NumFrames());
  1558. // Mongoose 2002.08.15, Atempt to skip more likely bad animation data
  1559. print(true, "WARNING: Handling bad animation data...");
  1560. return; //continue;
  1561. }
  1562. // Generate bone frames and tags per frame ////////////
  1563. bone = new bone_frame_t;
  1564. animation_frame->frame.pushBack(bone);
  1565. // Init translate for bone frame
  1566. bone->pos[0] = (short)frame[frame_offset + 6];
  1567. bone->pos[1] = (short)frame[frame_offset + 7];
  1568. bone->pos[2] = (short)frame[frame_offset + 8];
  1569. bone->yaw = yaw;
  1570. //printf("%f %f %f\n", bone->pos[0], bone->pos[1], bone->pos[2]);
  1571. l = 9; // First angle offset in this Frame
  1572. // Run through the tag and calculate the rotation and offset
  1573. for (j = 0; j < (int)moveable[index].num_meshes; ++j)
  1574. {
  1575. tag = new bone_tag_t;
  1576. bone->tag.pushBack(tag);
  1577. tag->off[0] = 0.0;
  1578. tag->off[1] = 0.0;
  1579. tag->off[2] = 0.0;
  1580. tag->flag = 0x00;
  1581. tag->rot[0] = 0.0;
  1582. tag->rot[1] = 0.0;
  1583. tag->rot[2] = 0.0;
  1584. tag->mesh = moveable[index].starting_mesh + j;
  1585. // Setup offsets to produce skeletion
  1586. if (j == 0)
  1587. {
  1588. // Since we use bone's offset, these aren't used
  1589. tag->off[0] = 0.0;
  1590. tag->off[1] = 0.0;
  1591. tag->off[2] = 0.0;
  1592. // Always push tag[0], this isn't really used either
  1593. tag->flag = 0x02;
  1594. }
  1595. else // Nonprimary tag - position relative to first tag
  1596. {
  1597. int *tree;
  1598. // Hack: moveable[index].mesh_tree is a byte offset
  1599. // into mesh_tree[], so we have to convert to index
  1600. tree = (int *)meshtree;
  1601. mesh_tree = (tr2_meshtree_t *)&tree[moveable[index].mesh_tree
  1602. + ((j - 1) * 4)];
  1603. tag->off[0] = mesh_tree->x;
  1604. tag->off[1] = mesh_tree->y;
  1605. tag->off[2] = mesh_tree->z;
  1606. tag->flag = mesh_tree->flags;
  1607. }
  1608. // Setup tag rotations
  1609. m_tombraider.computeRotationAngles(&frame, &frame_offset, &l,
  1610. tag->rot, tag->rot+1, tag->rot+2);
  1611. }
  1612. }
  1613. }
  1614. if (i == skyMesh)
  1615. {
  1616. m_render.setSkyMesh(i, //moveable[i].starting_mesh,
  1617. (m_tombraider.Engine() == TR_VERSION_2));
  1618. }
  1619. printf(".");
  1620. fflush(stdout);
  1621. }
  1622. int compareFaceTextureId(const void *voidA, const void *voidB)
  1623. {
  1624. texture_tri_t *a = (texture_tri_t *)voidA, *b = (texture_tri_t *)voidB;
  1625. if (!a || !b)
  1626. return -1; // error really
  1627. // less than
  1628. if (a->texture < b->texture)
  1629. return -1;
  1630. // greater than ( no need for equal )
  1631. return 1;
  1632. }
  1633. void setupTextureColor(texture_tri_t *r_tri, Render *render, float *colorf)
  1634. {
  1635. unsigned char color[4];
  1636. unsigned int colorI;
  1637. color[0] = (unsigned char)(colorf[0]*255.0f);
  1638. color[1] = (unsigned char)(colorf[1]*255.0f);
  1639. color[2] = (unsigned char)(colorf[2]*255.0f);
  1640. color[3] = (unsigned char)(colorf[3]*255.0f);
  1641. ((unsigned char *)(&colorI))[3] = color[0];
  1642. ((unsigned char *)(&colorI))[2] = color[1];
  1643. ((unsigned char *)(&colorI))[1] = color[2];
  1644. ((unsigned char *)(&colorI))[0] = color[3];
  1645. if (!gColorTextureHACK.find(colorI))
  1646. {
  1647. gColorTextureHACK.pushBack(colorI);
  1648. r_tri->texture = gTextureOffset + gColorTextureHACK.size();
  1649. render->loadTexture(Texture::generateColorTexture(color, 32, 32),
  1650. 32, 32,
  1651. r_tri->texture);
  1652. #ifdef DEBUG_COLOR_TEXTURE_GEN
  1653. printf("Color 0x%02x%02x%02x%02x | 0x%08xto texture[%i]?\n",
  1654. color[0], color[1], color[2], color[3], colorI,
  1655. gColorTextureHACK.size());
  1656. #endif
  1657. }
  1658. else
  1659. {
  1660. //printf("Color already loaded %i -> 0x%08x\n",
  1661. // gColorTextureHACK.getCurrentIndex(),
  1662. // gColorTextureHACK.current());
  1663. r_tri->texture = gTextureOffset + gColorTextureHACK.getCurrentIndex();
  1664. }
  1665. //r_tri->texture = white; // White texture
  1666. }
  1667. void OpenRaider::processModel(int index)
  1668. {
  1669. int i, j, count, texture, white;
  1670. int vertexIndices[6];
  1671. float st[12];
  1672. float color[4];
  1673. unsigned short transparency;
  1674. texture_tri_t *r_tri;
  1675. // Assert common sense
  1676. if (index < 0 || !m_tombraider.isMeshValid(index))
  1677. {
  1678. // FIXME: allow sparse lists with matching ids instead?
  1679. gWorld.addMesh(NULL); // Filler, to make meshes array ids align
  1680. printf("x");
  1681. fflush(stdout);
  1682. return;
  1683. }
  1684. // WHITE texture id
  1685. white = 0;
  1686. model_mesh_t *mesh = new model_mesh_t;
  1687. // Mongoose 2002.08.30, Testing support for 'shootable' models ( traceable )
  1688. m_tombraider.getMeshCollisionInfo(index, mesh->center, &mesh->radius);
  1689. // FIXME: Arrays don't work either =)
  1690. // Mesh geometery, colors, etc
  1691. m_tombraider.getMeshVertexArrays(index,
  1692. &mesh->vertexCount, &mesh->vertices,
  1693. &mesh->normalCount, &mesh->normals,
  1694. &mesh->colorCount, &mesh->colors);
  1695. // Textured Triangles
  1696. count = m_tombraider.getMeshTexturedTriangleCount(index);
  1697. mesh->texturedTriangles.reserve(count); // little faster
  1698. for (i = 0; i < count; ++i)
  1699. {
  1700. r_tri = new texture_tri_t;
  1701. m_tombraider.getMeshTexturedTriangle(index, i,
  1702. r_tri->index,
  1703. r_tri->st,
  1704. &r_tri->texture,
  1705. &r_tri->transparency);
  1706. r_tri->texture += m_texOffset;
  1707. // Add to face vector
  1708. mesh->texturedTriangles.pushBack(r_tri);
  1709. }
  1710. // Coloured Triangles
  1711. count = m_tombraider.getMeshColoredTriangleCount(index);
  1712. mesh->coloredTriangles.reserve(count); // little faster
  1713. for (i = 0; i < count; i++)
  1714. {
  1715. r_tri = new texture_tri_t;
  1716. m_tombraider.getMeshColoredTriangle(index, i,
  1717. r_tri->index,
  1718. color);
  1719. r_tri->st[0] = color[0];
  1720. r_tri->st[1] = color[1];
  1721. r_tri->st[2] = color[2];
  1722. r_tri->st[3] = color[3];
  1723. r_tri->st[4] = 1.0;
  1724. r_tri->st[5] = 1.0;
  1725. #ifdef EXPERIMENTAL
  1726. setupTextureColor(r_tri, &m_render, color);
  1727. #else
  1728. r_tri->texture = white; // White texture
  1729. #endif
  1730. r_tri->transparency = 0;
  1731. // Add to face vector
  1732. mesh->coloredTriangles.pushBack(r_tri);
  1733. }
  1734. // Textured Rectangles
  1735. count = m_tombraider.getMeshTexturedRectangleCount(index);
  1736. mesh->texturedRectangles.reserve(count*2); // little faster
  1737. for (i = 0; i < count; ++i)
  1738. {
  1739. m_tombraider.getMeshTexturedRectangle(index, i,
  1740. vertexIndices,
  1741. st,
  1742. &texture,
  1743. &transparency);
  1744. r_tri = new texture_tri_t;
  1745. for (j = 0; j < 3; ++j)
  1746. r_tri->index[j] = vertexIndices[j];
  1747. for (j = 0; j < 6; ++j)
  1748. r_tri->st[j] = st[j];
  1749. r_tri->texture = texture + m_texOffset;
  1750. r_tri->transparency = transparency;
  1751. // Add to face vector
  1752. mesh->texturedRectangles.pushBack(r_tri);
  1753. r_tri = new texture_tri_t;
  1754. for (j = 3; j < 6; ++j)
  1755. r_tri->index[j-3] = vertexIndices[j];
  1756. for (j = 6; j < 12; ++j)
  1757. r_tri->st[j-6] = st[j];
  1758. r_tri->texture = texture + m_texOffset;
  1759. r_tri->transparency = transparency;
  1760. // Add to face vector
  1761. mesh->texturedRectangles.pushBack(r_tri);
  1762. }
  1763. // Coloured Rectangles
  1764. count = m_tombraider.getMeshColoredRectangleCount(index);
  1765. mesh->coloredRectangles.reserve(count*2); // little faster
  1766. for (i = 0; i < count; ++i)
  1767. {
  1768. m_tombraider.getMeshColoredRectangle(index, i,
  1769. vertexIndices,
  1770. color);
  1771. r_tri = new texture_tri_t;
  1772. for (j = 0; j < 3; ++j)
  1773. r_tri->index[j] = vertexIndices[j];
  1774. //for (j = 0; j < 6; ++j)
  1775. // r_tri->st[j] = st[j];
  1776. r_tri->st[0] = color[0];
  1777. r_tri->st[1] = color[1];
  1778. r_tri->st[2] = color[2];
  1779. r_tri->st[3] = color[3];
  1780. r_tri->st[4] = 1.0;
  1781. r_tri->st[5] = 1.0;
  1782. #ifdef EXPERIMENTAL
  1783. //for (j = 6; j < 12; ++j)
  1784. // r_tri->st[j-6] = st[j];
  1785. setupTextureColor(r_tri, &m_render, color);
  1786. #else
  1787. r_tri->texture = white; // White texture
  1788. #endif
  1789. r_tri->transparency = 0;
  1790. // Add to face vector
  1791. mesh->coloredRectangles.pushBack(r_tri);
  1792. r_tri = new texture_tri_t;
  1793. for (j = 3; j < 6; ++j)
  1794. r_tri->index[j-3] = vertexIndices[j];
  1795. //for (j = 6; j < 12; ++j)
  1796. // r_tri->st[j-6] = st[j];
  1797. r_tri->st[0] = color[0];
  1798. r_tri->st[1] = color[1];
  1799. r_tri->st[2] = color[2];
  1800. r_tri->st[3] = color[3];
  1801. r_tri->st[4] = 1.0;
  1802. r_tri->st[5] = 1.0;
  1803. #ifdef EXPERIMENTAL
  1804. setupTextureColor(r_tri, &m_render, color);
  1805. #else
  1806. r_tri->texture = white; // White texture
  1807. #endif
  1808. r_tri->transparency = 0;
  1809. // Add to face vector
  1810. mesh->coloredRectangles.pushBack(r_tri);
  1811. }
  1812. // Sort faces by texture
  1813. mesh->texturedTriangles.qSort(compareFaceTextureId);
  1814. mesh->coloredTriangles.qSort(compareFaceTextureId);
  1815. mesh->texturedRectangles.qSort(compareFaceTextureId);
  1816. mesh->coloredRectangles.qSort(compareFaceTextureId);
  1817. gWorld.addMesh(mesh);
  1818. printf(".");
  1819. fflush(stdout);
  1820. }
  1821. #define MATRIX_TRANSFORMS
  1822. void OpenRaider::processRoom(int index)
  1823. {
  1824. unsigned int i, j, count;
  1825. room_mesh_t *r_mesh = NULL;
  1826. RenderRoom *rRoom = NULL;
  1827. #ifdef MATRIX_TRANSFORMS
  1828. //matrix_t transform;
  1829. Matrix transform;
  1830. #endif
  1831. if (!m_tombraider.isRoomValid(index))
  1832. {
  1833. openraider_error("OpenRaider::RoomSetup", "Invalid room index",
  1834. __FILE__, __LINE__);
  1835. print(false, "WARNING: Handling invalid vertex array in room");
  1836. gWorld.addRoom(0x0);
  1837. m_render.addRoom(0x0);
  1838. printf("x");
  1839. fflush(stdout);
  1840. return;
  1841. }
  1842. rRoom = new RenderRoom();
  1843. r_mesh = new room_mesh_t;
  1844. r_mesh->id = index;
  1845. m_tombraider.getRoomInfo(index, &r_mesh->flags, r_mesh->pos,
  1846. r_mesh->bbox_min, r_mesh->bbox_max);
  1847. // Adjust positioning for OR world coord translation
  1848. r_mesh->bbox_min[0] += r_mesh->pos[0];
  1849. r_mesh->bbox_max[0] += r_mesh->pos[0];
  1850. r_mesh->bbox_min[2] += r_mesh->pos[2];
  1851. r_mesh->bbox_max[2] += r_mesh->pos[2];
  1852. // Mongoose 2002.04.03, Setup 3d transform
  1853. #ifdef MATRIX_TRANSFORMS
  1854. //mtkMatrixIdentity(transform);
  1855. //mtkMatrixTranslate(transform,
  1856. // r_mesh->pos[0], r_mesh->pos[1], r_mesh->pos[2]);
  1857. transform.setIdentity();
  1858. transform.translate(r_mesh->pos);
  1859. #else
  1860. #endif
  1861. // Setup portals
  1862. float portalVertices[12];
  1863. count = m_tombraider.getRoomPortalCount(index);
  1864. // FIXME: OR wrongly uses a cached adj room list for rendering vis
  1865. r_mesh->adjacentRooms.reserve(count + 1);
  1866. r_mesh->adjacentRooms.setError(-1);
  1867. // Current room is always first
  1868. r_mesh->adjacentRooms.pushBack(index);
  1869. for (i = 0; i < count; ++i)
  1870. {
  1871. portal_t *portal = new portal_t;
  1872. m_tombraider.getRoomPortal(index, i,
  1873. &portal->adjoining_room, portal->normal,
  1874. portalVertices);
  1875. for (j = 0; j < 4; ++j)
  1876. {
  1877. portal->vertices[j][0] = portalVertices[j*3];
  1878. portal->vertices[j][1] = portalVertices[j*3+1];
  1879. portal->vertices[j][2] = portalVertices[j*3+2];
  1880. // Relative coors in vis portals
  1881. #ifdef MATRIX_TRANSFORMS
  1882. //mtkMatrixTransform(transform, portal->vertices[j]);
  1883. transform.multiply3v(portal->vertices[j], portal->vertices[j]);
  1884. #else
  1885. portal->vertices[j][0] += r_mesh->pos[0];
  1886. portal->vertices[j][1] += r_mesh->pos[1];
  1887. portal->vertices[j][2] += r_mesh->pos[2];
  1888. #endif
  1889. }
  1890. r_mesh->adjacentRooms.pushBack(portal->adjoining_room);
  1891. r_mesh->portals.pushBack(portal);
  1892. }
  1893. // Physics/gameplay use /////////////////////////////
  1894. // FIXME: Use more of sector structure, boxes, and floordata
  1895. // List of sectors in this room
  1896. unsigned int sectorFlags;
  1897. int floorDataIndex, boxIndex, roomBelow, roomAbove;
  1898. count = m_tombraider.getRoomSectorCount(index, &r_mesh->numZSectors,
  1899. &r_mesh->numXSectors);
  1900. r_mesh->sectors.reserve(count);
  1901. r_mesh->sectors.setError(0x0);
  1902. for (i = 0; i < count; ++i)
  1903. {
  1904. sector_t *sector = new sector_t;
  1905. m_tombraider.getRoomSector(index, i, &sectorFlags,
  1906. &sector->ceiling, &sector->floor,
  1907. &floorDataIndex, &boxIndex, &roomBelow,
  1908. &roomAbove);
  1909. if (sectorFlags & tombraiderSector_wall)
  1910. {
  1911. sector->wall = true;
  1912. }
  1913. else
  1914. {
  1915. sector->wall = false;
  1916. }
  1917. r_mesh->sectors.pushBack(sector);
  1918. }
  1919. // Setup collision boxes ( Should use sectors, but this is a test )
  1920. count = m_tombraider.getRoomBoxCount(index);
  1921. r_mesh->boxes.reserve(count);
  1922. r_mesh->boxes.setError(0x0);
  1923. // FIXME: Only to be done only on room[0]? I don't think so...
  1924. for (i = 0; !index && i < count; ++i)
  1925. {
  1926. box_t *box = new box_t;
  1927. m_tombraider.getRoomBox(index, i,
  1928. box->a.pos, box->b.pos, box->c.pos, box->d.pos);
  1929. r_mesh->boxes.pushBack(box);
  1930. }
  1931. // Setup room lights /////////////////////////////////////
  1932. unsigned int lightFlags, lightType;
  1933. count = m_tombraider.getRoomLightCount(index);
  1934. rRoom->lights.reserve(count);
  1935. rRoom->lights.setError(0x0);
  1936. for (i = 0; i < count; ++i)
  1937. {
  1938. Light *light = new Light();
  1939. m_tombraider.getRoomLight(index, i,
  1940. light->mPos, light->mColor, light->mDir,
  1941. &light->mAtt, &light->mCutoff,
  1942. &lightType, &lightFlags);
  1943. switch (lightType)
  1944. {
  1945. case tombraiderLight_typeDirectional:
  1946. light->mType = Light::typeDirectional;
  1947. break;
  1948. case tombraiderLight_typeSpot:
  1949. light->mType = Light::typeSpot;
  1950. break;
  1951. case tombraiderLight_typePoint:
  1952. default:
  1953. light->mType = Light::typePoint;
  1954. }
  1955. rRoom->lights.pushBack(light);
  1956. }
  1957. // Room geometery //////////////////////////////////
  1958. //#define EXPERIMENTAL_UNFIFIED_ROOM_GEOMETERY
  1959. #ifdef EXPERIMENTAL_UNFIFIED_ROOM_GEOMETERY
  1960. unsigned int vertexCount, normalCount, colorCount, triCount;
  1961. vec_t *vertexArray;
  1962. vec_t *normalArray;
  1963. vec_t *colorArray;
  1964. unsigned int *indices, *flags;
  1965. float *texCoords;
  1966. int *textures;
  1967. m_tombraider.getRoomVertexArrays(index,
  1968. &vertexCount, &vertexArray,
  1969. &normalCount, &normalArray,
  1970. &colorCount, &colorArray);
  1971. rRoom->mesh.bufferVertexArray(vertexCount, (vec_t *)vertexArray);
  1972. rRoom->mesh.bufferNormalArray(normalCount, (vec_t *)normalArray);
  1973. rRoom->mesh.bufferColorArray(vertexCount, (vec_t *)colorArray, 4);
  1974. m_tombraider.getRoomTriangles(index, m_texOffset,
  1975. &triCount, &indices, &texCoords, &textures,
  1976. &flags);
  1977. rRoom->mesh.bufferTriangles(triCount, indices, texCoords, textures, flags);
  1978. #else
  1979. float rgba[4];
  1980. float xyz[3];
  1981. count = m_tombraider.getRoomVertexCount(index);
  1982. rRoom->mesh.allocateVertices(count);
  1983. rRoom->mesh.allocateNormals(0); // count
  1984. rRoom->mesh.allocateColors(count);
  1985. for (i = 0; i < count; ++i)
  1986. {
  1987. m_tombraider.getRoomVertex(index, i, xyz, rgba);
  1988. rRoom->mesh.setVertex(i, xyz[0], xyz[1], xyz[2]);
  1989. rRoom->mesh.setColor(i, rgba);
  1990. }
  1991. // Mongoose 2002.06.09, Setup allocation of meshes and polygons
  1992. // Counters ( Textured polygon lists are allocated per texture)
  1993. // ( Textures are mapped to these meshes )
  1994. int triangle_counter[TextureLimit];
  1995. int triangle_counter_alpha[TextureLimit];
  1996. int rectangle_counter[TextureLimit];
  1997. int rectangle_counter_alpha[TextureLimit];
  1998. int tris_mesh_map[TextureLimit];
  1999. int rect_mesh_map[TextureLimit];
  2000. for (i = 0; i < TextureLimit; ++i)
  2001. {
  2002. triangle_counter[i] = 0;
  2003. triangle_counter_alpha[i] = 0;
  2004. rectangle_counter[i] = 0;
  2005. rectangle_counter_alpha[i] = 0;
  2006. tris_mesh_map[i] = -1;
  2007. rect_mesh_map[i] = -1;
  2008. }
  2009. unsigned int numTris = 0;
  2010. unsigned int numQuads = 0;
  2011. int texture;
  2012. unsigned int r, t, q, v, flags;
  2013. unsigned int indices[4];
  2014. float texCoords[8];
  2015. count = m_tombraider.getRoomTriangleCount(index);
  2016. // Mongoose 2002.08.15, Presort by alpha and texture and setup mapping
  2017. for (t = 0; t < count; ++t)
  2018. {
  2019. m_tombraider.getRoomTriangle(index, t,
  2020. indices, texCoords, &texture, &flags);
  2021. texture += m_texOffset;
  2022. if (texture > (int)TextureLimit)
  2023. {
  2024. print(true, "Handling bad room[%i].tris[%i].texture = %i",
  2025. index, t, texture);
  2026. texture = TextureLimit - 1;
  2027. }
  2028. // Counters set up polygon allocation
  2029. if (flags & tombraiderFace_Alpha ||
  2030. flags & tombraiderFace_PartialAlpha)
  2031. {
  2032. triangle_counter_alpha[texture] += 1;
  2033. }
  2034. else
  2035. {
  2036. triangle_counter[texture] += 1;
  2037. }
  2038. // Counter sets up texture id to mesh id mapping
  2039. if (tris_mesh_map[texture] == -1)
  2040. {
  2041. tris_mesh_map[texture] = ++numTris;
  2042. }
  2043. }
  2044. count = m_tombraider.getRoomRectangleCount(index);
  2045. for (r = 0; r < count; ++r)
  2046. {
  2047. m_tombraider.getRoomRectangle(index, r,
  2048. indices, texCoords, &texture, &flags);
  2049. texture += m_texOffset;
  2050. if (texture > (int)TextureLimit)
  2051. {
  2052. print(true, "Handling bad room[%i].quad[%i].texture = %i",
  2053. index, r, texture);
  2054. texture = TextureLimit - 1;
  2055. }
  2056. if (flags & tombraiderFace_Alpha ||
  2057. flags & tombraiderFace_PartialAlpha)
  2058. {
  2059. rectangle_counter_alpha[texture] += 1;
  2060. }
  2061. else
  2062. {
  2063. rectangle_counter[texture] += 1;
  2064. }
  2065. if (rect_mesh_map[texture] == -1)
  2066. {
  2067. rect_mesh_map[texture] = ++numQuads;
  2068. }
  2069. }
  2070. // Allocate indexed polygon meshes
  2071. rRoom->mesh.allocateTriangles(numTris);
  2072. rRoom->mesh.allocateRectangles(numQuads);
  2073. for (i = 0, j = 0; i < TextureLimit; ++i)
  2074. {
  2075. if (tris_mesh_map[i] > 0)
  2076. {
  2077. j = tris_mesh_map[i] - 1;
  2078. t = triangle_counter[i];
  2079. rRoom->mesh.mTris[j].texture = i;
  2080. #ifdef MULTITEXTURE
  2081. rRoom->mesh.mTris[j].bumpmap = gMapTex2Bump[i];
  2082. #endif
  2083. rRoom->mesh.mTris[j].cnum_triangles = 0;
  2084. rRoom->mesh.mTris[j].num_triangles = 0;
  2085. rRoom->mesh.mTris[j].cnum_alpha_triangles = 0;
  2086. rRoom->mesh.mTris[j].num_alpha_triangles = 0;
  2087. rRoom->mesh.mTris[j].triangles = 0x0;
  2088. rRoom->mesh.mTris[j].alpha_triangles = 0x0;
  2089. rRoom->mesh.mTris[j].texcoors = 0x0;
  2090. rRoom->mesh.mTris[j].texcoors2 = 0x0;
  2091. if (t > 0)
  2092. {
  2093. rRoom->mesh.mTris[j].num_triangles = t;
  2094. rRoom->mesh.mTris[j].triangles = new unsigned int[t*3];
  2095. rRoom->mesh.mTris[j].num_texcoors = t * 3;
  2096. rRoom->mesh.mTris[j].texcoors = new vec2_t[t * 3];
  2097. }
  2098. t = triangle_counter_alpha[i];
  2099. if (t > 0)
  2100. {
  2101. rRoom->mesh.mTris[j].num_alpha_triangles = t;
  2102. rRoom->mesh.mTris[j].alpha_triangles = new unsigned int[t*3];
  2103. rRoom->mesh.mTris[j].num_texcoors2 = t * 3;
  2104. rRoom->mesh.mTris[j].texcoors2 = new vec2_t[t * 3];
  2105. }
  2106. }
  2107. ///////////////////////////////////////////
  2108. if (rect_mesh_map[i] > 0)
  2109. {
  2110. j = rect_mesh_map[i] - 1;
  2111. r = rectangle_counter[i];
  2112. rRoom->mesh.mQuads[j].texture = i;
  2113. #ifdef MULTITEXTURE
  2114. rRoom->mesh.mQuads[j].bumpmap = gMapTex2Bump[i];
  2115. #endif
  2116. rRoom->mesh.mQuads[j].cnum_quads = 0;
  2117. rRoom->mesh.mQuads[j].num_quads = 0;
  2118. rRoom->mesh.mQuads[j].cnum_alpha_quads = 0;
  2119. rRoom->mesh.mQuads[j].num_alpha_quads = 0;
  2120. rRoom->mesh.mQuads[j].quads = 0x0;
  2121. rRoom->mesh.mQuads[j].alpha_quads = 0x0;
  2122. rRoom->mesh.mQuads[j].texcoors = 0x0;
  2123. rRoom->mesh.mQuads[j].texcoors2 = 0x0;
  2124. if (r > 0)
  2125. {
  2126. rRoom->mesh.mQuads[j].num_quads = r;
  2127. rRoom->mesh.mQuads[j].quads = new unsigned int[r*4];
  2128. rRoom->mesh.mQuads[j].num_texcoors = r * 4;
  2129. rRoom->mesh.mQuads[j].texcoors = new vec2_t[r * 4];
  2130. }
  2131. r = rectangle_counter_alpha[i];
  2132. if (r > 0)
  2133. {
  2134. rRoom->mesh.mQuads[j].num_alpha_quads = r;
  2135. rRoom->mesh.mQuads[j].alpha_quads = new unsigned int[r*4];
  2136. rRoom->mesh.mQuads[j].num_texcoors2 = r * 4;
  2137. rRoom->mesh.mQuads[j].texcoors2 = new vec2_t[r * 4];
  2138. }
  2139. }
  2140. }
  2141. // Generate textured triangles
  2142. count = m_tombraider.getRoomTriangleCount(index);
  2143. for (t = 0; t < count; ++t)
  2144. {
  2145. m_tombraider.getRoomTriangle(index, t,
  2146. indices, texCoords, &texture, &flags);
  2147. // Adjust texture id using m_texOffset to map into
  2148. // correct textures
  2149. texture += m_texOffset;
  2150. j = tris_mesh_map[texture] - 1;
  2151. // Setup per vertex
  2152. for (i = 0; i < 3; ++i)
  2153. {
  2154. // Get vertex index {(0, a), (1, b), (2, c)}
  2155. v = indices[i];
  2156. if ((flags & tombraiderFace_Alpha ||
  2157. flags & tombraiderFace_PartialAlpha) &&
  2158. rRoom->mesh.mTris[j].num_alpha_triangles > 0)
  2159. {
  2160. q = rRoom->mesh.mTris[j].cnum_alpha_triangles*3+i;
  2161. rRoom->mesh.mTris[j].alpha_triangles[q] = v;
  2162. rRoom->mesh.mTris[j].texcoors2[q][0] = texCoords[i*2];
  2163. rRoom->mesh.mTris[j].texcoors2[q][1] = texCoords[i*2+1];
  2164. }
  2165. else if (rRoom->mesh.mTris[j].num_triangles > 0)
  2166. {
  2167. q = rRoom->mesh.mTris[j].cnum_triangles*3+i;
  2168. rRoom->mesh.mTris[j].triangles[q] = v;
  2169. rRoom->mesh.mTris[j].texcoors[q][0] = texCoords[i*2];
  2170. rRoom->mesh.mTris[j].texcoors[q][1] = texCoords[i*2+1];
  2171. }
  2172. // Partial alpha hack
  2173. if (flags & tombraiderFace_PartialAlpha)
  2174. {
  2175. //rRoom->mesh.colors[v].rgba[3] = 0.45;
  2176. }
  2177. }
  2178. if (flags & tombraiderFace_Alpha ||
  2179. flags & tombraiderFace_PartialAlpha)
  2180. {
  2181. rRoom->mesh.mTris[j].cnum_alpha_triangles++;
  2182. }
  2183. else
  2184. {
  2185. rRoom->mesh.mTris[j].cnum_triangles++;
  2186. }
  2187. }
  2188. // Generate textured quads
  2189. count = m_tombraider.getRoomRectangleCount(index);
  2190. for (r = 0; r < count; ++r)
  2191. {
  2192. m_tombraider.getRoomRectangle(index, r,
  2193. indices, texCoords, &texture, &flags);
  2194. // Adjust texture id using m_texOffset to map into
  2195. // correct textures
  2196. texture += m_texOffset;
  2197. if (texture > (int)TextureLimit)
  2198. {
  2199. texture = TextureLimit - 1;
  2200. }
  2201. j = rect_mesh_map[texture] - 1;
  2202. if (rRoom->mesh.mQuads[j].num_quads <= 0 &&
  2203. rRoom->mesh.mQuads[j].num_alpha_quads <= 0)
  2204. continue;
  2205. // Setup per vertex
  2206. for (i = 0; i < 4; ++i)
  2207. {
  2208. // Get vertex index {(0, a), (1, b), (2, c), (3, d)}
  2209. v = indices[i];
  2210. if ((flags & tombraiderFace_Alpha ||
  2211. flags & tombraiderFace_PartialAlpha) &&
  2212. rRoom->mesh.mQuads[j].num_alpha_quads > 0)
  2213. {
  2214. q = rRoom->mesh.mQuads[j].cnum_alpha_quads*4+i;
  2215. rRoom->mesh.mQuads[j].alpha_quads[q] = v;
  2216. rRoom->mesh.mQuads[j].texcoors2[q][0] = texCoords[i*2];
  2217. rRoom->mesh.mQuads[j].texcoors2[q][1] = texCoords[i*2+1];
  2218. }
  2219. else if (rRoom->mesh.mQuads[j].num_quads > 0)
  2220. {
  2221. q = rRoom->mesh.mQuads[j].cnum_quads*4+i;
  2222. rRoom->mesh.mQuads[j].quads[q] = v;
  2223. rRoom->mesh.mQuads[j].texcoors[q][0] = texCoords[i*2];
  2224. rRoom->mesh.mQuads[j].texcoors[q][1] = texCoords[i*2+1];
  2225. }
  2226. // Partial alpha hack
  2227. if (flags & tombraiderFace_PartialAlpha)
  2228. {
  2229. //rRoom->mesh.colors[v].rgba[3] = 0.45;
  2230. }
  2231. }
  2232. if (flags & tombraiderFace_Alpha ||
  2233. flags & tombraiderFace_PartialAlpha)
  2234. {
  2235. rRoom->mesh.mQuads[j].cnum_alpha_quads++;
  2236. }
  2237. else
  2238. {
  2239. rRoom->mesh.mQuads[j].cnum_quads++;
  2240. }
  2241. }
  2242. #endif
  2243. // Room models
  2244. count = m_tombraider.getRoomModelCount(index);
  2245. r_mesh->models.reserve(count);
  2246. r_mesh->models.setError(0x0);
  2247. for (i = 0; i < count; ++i)
  2248. {
  2249. static_model_t *model = new static_model_t;
  2250. m_tombraider.getRoomModel(index, i,
  2251. &model->index, model->pos, &model->yaw);
  2252. r_mesh->models.pushBack(model);
  2253. }
  2254. // Room sprites
  2255. float spriteVertices[12];
  2256. float spriteTexCoords[8];
  2257. count = m_tombraider.getRoomSpriteCount(index);
  2258. r_mesh->sprites.reserve(count);
  2259. r_mesh->sprites.setError(0x0);
  2260. for (i = 0; i < count; ++i)
  2261. {
  2262. sprite_t *sprite = new sprite_t;
  2263. m_tombraider.getRoomSprite(index, i,
  2264. 10.0f, &sprite->texture, sprite->pos,
  2265. spriteVertices, spriteTexCoords);
  2266. sprite->texture += m_texOffset; // OpenRaider preloads some textures
  2267. sprite->vertex[0].pos[0] = spriteVertices[0];
  2268. sprite->vertex[0].pos[1] = spriteVertices[1];
  2269. sprite->vertex[0].pos[2] = spriteVertices[2];
  2270. sprite->vertex[1].pos[0] = spriteVertices[3];
  2271. sprite->vertex[1].pos[1] = spriteVertices[4];
  2272. sprite->vertex[1].pos[2] = spriteVertices[5];
  2273. sprite->vertex[2].pos[0] = spriteVertices[6];
  2274. sprite->vertex[2].pos[1] = spriteVertices[7];
  2275. sprite->vertex[2].pos[2] = spriteVertices[8];
  2276. sprite->vertex[3].pos[0] = spriteVertices[9];
  2277. sprite->vertex[3].pos[1] = spriteVertices[10];
  2278. sprite->vertex[3].pos[2] = spriteVertices[11];
  2279. sprite->texel[0].st[0] = spriteTexCoords[0];
  2280. sprite->texel[0].st[1] = spriteTexCoords[1];
  2281. sprite->texel[1].st[0] = spriteTexCoords[2];
  2282. sprite->texel[1].st[1] = spriteTexCoords[3];
  2283. sprite->texel[2].st[0] = spriteTexCoords[4];
  2284. sprite->texel[2].st[1] = spriteTexCoords[5];
  2285. sprite->texel[3].st[0] = spriteTexCoords[6];
  2286. sprite->texel[3].st[1] = spriteTexCoords[7];
  2287. r_mesh->sprites.pushBack(sprite);
  2288. }
  2289. gWorld.addRoom(r_mesh);
  2290. rRoom->room = r_mesh;
  2291. m_render.addRoom(rRoom);
  2292. printf(".");
  2293. fflush(stdout);
  2294. }
  2295. void OpenRaider::consoleCommand(char *cmd)
  2296. {
  2297. if (!cmd || !cmd[0])
  2298. return;
  2299. // Mongoose 2003.05.31, Strip off decp console prefix
  2300. if (cmd[0] == '>')
  2301. {
  2302. rc_command(">", cmd);
  2303. }
  2304. if (rc_command("quit", cmd))
  2305. {
  2306. shutdown(0);
  2307. }
  2308. else if (rc_command("md3", cmd))
  2309. {
  2310. #ifdef USING_MD3
  2311. m_render.loadMd3(cmd, "default");
  2312. print(true, "\nYou've found an Easter Egg!\n");
  2313. #else
  2314. print(true, "\nThis build isn't MD3 Easter Egg enabled\n");
  2315. #endif
  2316. }
  2317. else if (rc_command("port", cmd))
  2318. {
  2319. Network &net = *Network::Instance();
  2320. net.setPort(atoi(cmd));
  2321. }
  2322. else if (rc_command("killserver", cmd))
  2323. {
  2324. Network &net = *Network::Instance();
  2325. print(true, "Stopping network server...");
  2326. net.killServerThread();
  2327. }
  2328. else if (rc_command("server", cmd))
  2329. {
  2330. Network &net = *Network::Instance();
  2331. print(true, "Starting network server...");
  2332. net.spawnServerThread();
  2333. }
  2334. else if (rc_command("disconnect", cmd))
  2335. {
  2336. Network &net = *Network::Instance();
  2337. print(true, "Diconnecting...");
  2338. net.killClientThread();
  2339. }
  2340. else if (rc_command("connect", cmd))
  2341. {
  2342. Network &net = *Network::Instance();
  2343. print(true, "Connecting to %s...", cmd);
  2344. net.setRemoteHost(cmd);
  2345. net.spawnClientThread();
  2346. }
  2347. else if (rc_command("fly", cmd))
  2348. {
  2349. mNoClipping = worldMoveType_fly;
  2350. if (LARA)
  2351. {
  2352. LARA->moveType = worldMoveType_fly;
  2353. }
  2354. print(false, "World clipping is [SPACEY]");
  2355. }
  2356. else if (rc_command("walk", cmd))
  2357. {
  2358. mNoClipping = worldMoveType_walk;
  2359. if (LARA)
  2360. {
  2361. LARA->moveType = worldMoveType_walk;
  2362. }
  2363. print(false, "World clipping is [ON]");
  2364. }
  2365. else if (rc_command("ghost", cmd))
  2366. {
  2367. mNoClipping = worldMoveType_noClipping;
  2368. if (LARA)
  2369. {
  2370. LARA->moveType = worldMoveType_noClipping;
  2371. }
  2372. print(false, "World clipping is [OFF]");
  2373. }
  2374. else if (rc_command("mem", cmd))
  2375. {
  2376. #ifdef DEBUG_MEMEORY
  2377. if (rc_command("usage", cmd))
  2378. {
  2379. display_memory_usage();
  2380. }
  2381. else if (rc_command("report", cmd))
  2382. {
  2383. dump_memory_report();
  2384. }
  2385. #else
  2386. printf("This build isn't DEBUG_MEMEORY enabled\n");
  2387. #endif
  2388. }
  2389. else if (rc_command("loadlevel", cmd))
  2390. {
  2391. loadLevel(cmd);
  2392. }
  2393. else if (rc_command("play", cmd))
  2394. {
  2395. if (m_flags & OpenRaider_EnableSound)
  2396. {
  2397. mSound.play(atoi(cmd));
  2398. }
  2399. }
  2400. else if (rc_command("sensitivity.x", cmd))
  2401. {
  2402. m_mouseX = atof(cmd);
  2403. }
  2404. else if (rc_command("sensitivity.y", cmd))
  2405. {
  2406. m_mouseY = atof(cmd);
  2407. }
  2408. else if (rc_command("r_pigtails", cmd))
  2409. {
  2410. if (gLaraModel)
  2411. {
  2412. gLaraModel->pigtails = atoi(cmd);
  2413. if (gLaraModel->pigtails)
  2414. {
  2415. gLaraModel->ponyOff -= 20;
  2416. gLaraModel->ponytail[1] -= 32;
  2417. }
  2418. else
  2419. {
  2420. gLaraModel->ponyOff += 20;
  2421. gLaraModel->ponytail[1] += 32;
  2422. }
  2423. }
  2424. }
  2425. else if (rc_command("r_ponyangle", cmd))
  2426. {
  2427. if (gLaraModel)
  2428. {
  2429. gLaraModel->ponytailAngle = atoi(cmd);
  2430. }
  2431. }
  2432. else if (rc_command("r_ponyx", cmd))
  2433. {
  2434. if (gLaraModel)
  2435. {
  2436. gLaraModel->ponytail[0] = atoi(cmd);
  2437. }
  2438. }
  2439. else if (rc_command("r_ponyy", cmd))
  2440. {
  2441. if (gLaraModel)
  2442. {
  2443. gLaraModel->ponytail[1] = atoi(cmd);
  2444. }
  2445. }
  2446. else if (rc_command("r_ponyz", cmd))
  2447. {
  2448. if (gLaraModel)
  2449. {
  2450. gLaraModel->ponytail[2] = atoi(cmd);
  2451. }
  2452. }
  2453. else if (rc_command("r_animate", cmd))
  2454. {
  2455. if (atoi(cmd))
  2456. {
  2457. m_render.setFlags(Render::fAnimateAllModels);
  2458. print(false, "Animating all models");
  2459. }
  2460. else
  2461. {
  2462. m_render.clearFlags(Render::fAnimateAllModels);
  2463. print(false, "No longer animating all models");
  2464. }
  2465. }
  2466. else if (rc_command("r_ponytail", cmd))
  2467. {
  2468. if (atoi(cmd))
  2469. {
  2470. m_render.setFlags(Render::fRenderPonytail);
  2471. print(false, "Rendering ponytail");
  2472. }
  2473. else
  2474. {
  2475. m_render.clearFlags(Render::fRenderPonytail);
  2476. print(false, "No longer rendering ponytail");
  2477. }
  2478. }
  2479. else if (rc_command("r_light", cmd))
  2480. {
  2481. if (atoi(cmd))
  2482. {
  2483. m_render.setFlags(Render::fGL_Lights);
  2484. }
  2485. else
  2486. {
  2487. m_render.clearFlags(Render::fGL_Lights);
  2488. }
  2489. }
  2490. else if (rc_command("hop", cmd))
  2491. {
  2492. if (atoi(cmd))
  2493. {
  2494. gWorld.setFlag(World::fEnableHopping);
  2495. print(true, "Room hopping is on");
  2496. }
  2497. else
  2498. {
  2499. gWorld.clearFlag(World::fEnableHopping);
  2500. print(true, "Room hopping is off");
  2501. }
  2502. }
  2503. else if (rc_command("r_fog", cmd))
  2504. {
  2505. if (atoi(cmd))
  2506. {
  2507. m_render.setFlags(Render::fFog);
  2508. }
  2509. else
  2510. {
  2511. m_render.clearFlags(Render::fFog);
  2512. }
  2513. }
  2514. else if (rc_command("wireframe", cmd))
  2515. {
  2516. m_render.setMode(Render::modeWireframe);
  2517. print(false, "wireframe mode");
  2518. }
  2519. else if (rc_command("solid", cmd))
  2520. {
  2521. m_render.setMode(Render::modeSolid);
  2522. print(false, "solid mode");
  2523. }
  2524. else if (rc_command("texture", cmd))
  2525. {
  2526. m_render.setMode(Render::modeTexture);
  2527. print(false, "texture mode");
  2528. }
  2529. else if (rc_command("vertexlight", cmd))
  2530. {
  2531. m_render.setMode(Render::modeVertexLight);
  2532. print(false, "vertexlight mode");
  2533. }
  2534. else if (rc_command("titlescreen", cmd))
  2535. {
  2536. m_render.setMode(Render::modeLoadScreen);
  2537. print(false, "titlescreen mode");
  2538. }
  2539. else if (rc_command("r_viewmodel", cmd))
  2540. {
  2541. if (LARA)
  2542. {
  2543. SkeletalModel *smdl = (SkeletalModel *)LARA->tmpHook;
  2544. skeletal_model_t *mdl = gWorld.getModel(atoi(cmd));
  2545. if (smdl)
  2546. {
  2547. smdl->setModel(mdl);
  2548. }
  2549. }
  2550. //m_render.ViewModel(LARA, atoi(cmd));
  2551. }
  2552. else if (rc_command("r_oneroom", cmd))
  2553. {
  2554. if (atoi(cmd))
  2555. {
  2556. m_render.setFlags(Render::fOneRoom);
  2557. }
  2558. else
  2559. {
  2560. m_render.clearFlags(Render::fOneRoom);
  2561. }
  2562. }
  2563. else if (rc_command("r_allrooms", cmd))
  2564. {
  2565. if (atoi(cmd))
  2566. {
  2567. m_render.setFlags(Render::fAllRooms);
  2568. }
  2569. else
  2570. {
  2571. m_render.clearFlags(Render::fAllRooms);
  2572. }
  2573. print(true, "Rendering all rooms [%s]", (atoi(cmd) == 0) ? "off" : "on");
  2574. }
  2575. else if (rc_command("r_sprite", cmd))
  2576. {
  2577. if (atoi(cmd))
  2578. {
  2579. m_render.setFlags(Render::fSprites);
  2580. }
  2581. else
  2582. {
  2583. m_render.clearFlags(Render::fSprites);
  2584. }
  2585. }
  2586. else if (rc_command("r_roommodel", cmd))
  2587. {
  2588. if (atoi(cmd))
  2589. {
  2590. m_render.setFlags(Render::fRoomModels);
  2591. }
  2592. else
  2593. {
  2594. m_render.clearFlags(Render::fRoomModels);
  2595. }
  2596. }
  2597. else if (rc_command("r_entmodel", cmd))
  2598. {
  2599. if (atoi(cmd))
  2600. {
  2601. m_render.setFlags(Render::fEntityModels);
  2602. }
  2603. else
  2604. {
  2605. m_render.clearFlags(Render::fEntityModels);
  2606. }
  2607. }
  2608. else if (rc_command("r_particle", cmd))
  2609. {
  2610. if (atoi(cmd))
  2611. {
  2612. m_render.setFlags(Render::fParticles);
  2613. }
  2614. else
  2615. {
  2616. m_render.clearFlags(Render::fParticles);
  2617. }
  2618. }
  2619. else if (rc_command("r_vis", cmd))
  2620. {
  2621. if (atoi(cmd))
  2622. {
  2623. m_render.clearFlags(Render::fUsePortals);
  2624. }
  2625. else
  2626. {
  2627. m_render.clearFlags(Render::fUsePortals);
  2628. }
  2629. }
  2630. else if (rc_command("r_upf", cmd))
  2631. {
  2632. if (atoi(cmd))
  2633. {
  2634. m_render.setFlags(Render::fUpdateRoomListPerFrame);
  2635. }
  2636. else
  2637. {
  2638. m_render.clearFlags(Render::fUpdateRoomListPerFrame);
  2639. }
  2640. }
  2641. else if (rc_command("r_portal", cmd))
  2642. {
  2643. if (atoi(cmd))
  2644. {
  2645. m_render.setFlags(Render::fPortals);
  2646. }
  2647. else
  2648. {
  2649. m_render.clearFlags(Render::fPortals);
  2650. }
  2651. }
  2652. else if (rc_command("r_vmodel", cmd))
  2653. {
  2654. if (atoi(cmd))
  2655. {
  2656. m_render.setFlags(Render::fViewModel);
  2657. }
  2658. else
  2659. {
  2660. m_render.clearFlags(Render::fViewModel);
  2661. }
  2662. }
  2663. else if (rc_command("r_ralpha", cmd))
  2664. {
  2665. if (atoi(cmd))
  2666. {
  2667. m_render.setFlags(Render::fRoomAlpha);
  2668. }
  2669. else
  2670. {
  2671. m_render.clearFlags(Render::fRoomAlpha);
  2672. }
  2673. }
  2674. else if (rc_command("resize", cmd))
  2675. {
  2676. if (rc_command("xga", cmd))
  2677. {
  2678. resize(1024, 768);
  2679. m_render.Update(1024, 768);
  2680. }
  2681. else if (rc_command("svga", cmd))
  2682. {
  2683. resize(800, 600);
  2684. m_render.Update(800, 600);
  2685. }
  2686. else if (rc_command("vga", cmd))
  2687. {
  2688. resize(640, 460);
  2689. m_render.Update(640, 460);
  2690. }
  2691. }
  2692. else if (rc_command("sshot", cmd))
  2693. {
  2694. char sfilename[1024];
  2695. char *tmp = fullPath("~/.OpenRaider/sshots/", '/');
  2696. /* Not very pretty, but gets it done */
  2697. snprintf(sfilename, 1024, "%s%s", tmp, VERSION);
  2698. delete [] tmp;
  2699. m_render.screenShot(sfilename);
  2700. print(false, "Took screenshot");
  2701. }
  2702. else if (rc_command("fullscreen", cmd))
  2703. {
  2704. toggleFullscreen();
  2705. }
  2706. else if (rc_command("showfps", cmd))
  2707. {
  2708. m_flags |= OpenRaider_ShowFPS;
  2709. if (!atoi(cmd))
  2710. {
  2711. m_flags ^= OpenRaider_ShowFPS;
  2712. }
  2713. }
  2714. else if (rc_command("bind", cmd))
  2715. {
  2716. if (rc_command("+forward", cmd))
  2717. {
  2718. bindKeyCommand("+forward", atoi(cmd), OpenRaiderKey_forward);
  2719. }
  2720. else if (rc_command("+console", cmd))
  2721. {
  2722. bindKeyCommand("+console", atoi(cmd), OpenRaiderKey_console);
  2723. }
  2724. else if (rc_command("+backward", cmd))
  2725. {
  2726. bindKeyCommand("+backward", atoi(cmd), OpenRaiderKey_backward);
  2727. }
  2728. else if (rc_command("+jump", cmd))
  2729. {
  2730. bindKeyCommand("+jump", atoi(cmd), OpenRaiderKey_jump);
  2731. }
  2732. else if (rc_command("+crouch", cmd))
  2733. {
  2734. bindKeyCommand("+crouch", atoi(cmd), OpenRaiderKey_crouch);
  2735. }
  2736. else if (rc_command("+right", cmd))
  2737. {
  2738. bindKeyCommand("+right", atoi(cmd), OpenRaiderKey_right);
  2739. }
  2740. else if (rc_command("+left", cmd))
  2741. {
  2742. bindKeyCommand("+left", atoi(cmd), OpenRaiderKey_left);
  2743. }
  2744. else if (rc_command("+attack", cmd))
  2745. {
  2746. bindKeyCommand("+attack", atoi(cmd), OpenRaiderKey_attack);
  2747. }
  2748. }
  2749. else if (rc_command("set", cmd))
  2750. {
  2751. if (rc_command("mousegrab", cmd))
  2752. {
  2753. setGrabMouse(atoi(cmd));
  2754. print(true, "Mouse grabbing [%s]", atoi(cmd) ? "on" : "off");
  2755. }
  2756. }
  2757. else if (rc_command("stat", cmd))
  2758. {
  2759. if (rc_command("fps", cmd))
  2760. {
  2761. m_flags ^= OpenRaider_ShowFPS;
  2762. }
  2763. else if (rc_command("pos", cmd))
  2764. {
  2765. if (LARA)
  2766. {
  2767. print(true, "Room %2i Pos %.0f %.0f %.0f Yaw %.0f Pitch %.0f",
  2768. LARA->room,
  2769. LARA->pos[0], LARA->pos[1], LARA->pos[2],
  2770. helRadToDeg(LARA->angles[1]),
  2771. helRadToDeg(LARA->angles[2]));
  2772. }
  2773. }
  2774. else if (rc_command("room", cmd))
  2775. {
  2776. if (rc_command("flags", cmd))
  2777. {
  2778. if (LARA)
  2779. {
  2780. print(true, "Room[%i] flags: 0x%x",
  2781. LARA->room,
  2782. gWorld.getRoomInfo(LARA->room));
  2783. }
  2784. }
  2785. }
  2786. }
  2787. }
  2788. void OpenRaider::handleCommand(char *cmd, unsigned int mode)
  2789. {
  2790. bool b;
  2791. int i;
  2792. // So we can use switch stmt, translate the Ids
  2793. mode = mMode[mode];
  2794. switch (mode)
  2795. {
  2796. case 0: // [Video.OpenGL]
  2797. if (rc_command("Width", cmd))
  2798. {
  2799. m_width = atoi(cmd);
  2800. }
  2801. else if (rc_command("Height", cmd))
  2802. {
  2803. m_height = atoi(cmd);
  2804. }
  2805. else if (rc_command("FastCard", cmd))
  2806. {
  2807. rc_get_bool(cmd, &m_fastCard);
  2808. }
  2809. else if (rc_command("FullScreen", cmd))
  2810. {
  2811. rc_get_bool(cmd, &b);
  2812. m_flags |= OpenRaider_FullScreen;
  2813. if (!b)
  2814. {
  2815. m_flags ^= OpenRaider_FullScreen;
  2816. }
  2817. }
  2818. else if (rc_command("Font", cmd))
  2819. {
  2820. gFontFilename = fullPath(cmd, '/');
  2821. }
  2822. else if (rc_command("Driver", cmd))
  2823. {
  2824. if (cmd[0])
  2825. {
  2826. setDriverGL(cmd);
  2827. }
  2828. }
  2829. else
  2830. {
  2831. printf("Command> [Video.OpenGL] Unknown command '%s'\n", cmd);
  2832. }
  2833. break;
  2834. case 1: // [Audio.OpenAL]
  2835. if (rc_command("Enable", cmd))
  2836. {
  2837. rc_get_bool(cmd, &b);
  2838. m_flags |= OpenRaider_EnableSound;
  2839. if (!b)
  2840. {
  2841. m_flags ^= OpenRaider_EnableSound;
  2842. }
  2843. }
  2844. else
  2845. {
  2846. printf("Command> [Audio.OpenAL] Unknown command '%s'\n", cmd);
  2847. }
  2848. break;
  2849. case 2: // [OpenRaider.Engine]
  2850. if (rc_command("PakDir", cmd))
  2851. {
  2852. if (m_pakDir)
  2853. {
  2854. delete [] m_pakDir;
  2855. }
  2856. m_pakDir = fullPath(cmd, '/');
  2857. }
  2858. else if (rc_command("HomeDir", cmd))
  2859. {
  2860. if (m_homeDir)
  2861. {
  2862. delete [] m_homeDir;
  2863. }
  2864. i = strlen(cmd);
  2865. m_homeDir = fullPath(cmd, '/');
  2866. }
  2867. else if (rc_command("AudioDir", cmd))
  2868. {
  2869. if (m_audioDir)
  2870. {
  2871. delete [] m_audioDir;
  2872. }
  2873. m_audioDir = fullPath(cmd, '/');
  2874. }
  2875. else if (rc_command("MapDebug", cmd))
  2876. {
  2877. rc_get_bool(cmd, &b);
  2878. m_flags |= OpenRaider_DebugMap;
  2879. if (!b)
  2880. {
  2881. m_flags ^= OpenRaider_DebugMap;
  2882. }
  2883. }
  2884. else if (rc_command("Map", cmd))
  2885. {
  2886. if (cmd[0])
  2887. {
  2888. char *fullPathMap;
  2889. fullPathMap = bufferString("%s%s", m_pakDir, cmd);
  2890. if (m_tombraider.checkMime(fullPathMap) == 0)
  2891. {
  2892. printf("Validated pak: '%s'\n",
  2893. fullPathMap);
  2894. delete [] fullPathMap;
  2895. /* Just load relative filename */
  2896. mMapList.pushBack(bufferString("%s", cmd));
  2897. }
  2898. else
  2899. {
  2900. printf("ERROR: pak file '%s' not found or invalid\n",
  2901. fullPathMap);
  2902. delete [] fullPathMap;
  2903. }
  2904. }
  2905. }
  2906. // Mongoose 2001.12.31, Added music list back
  2907. else if (rc_command("Music", cmd))
  2908. {
  2909. if (cmd[0])
  2910. {
  2911. char *music;
  2912. i = strlen(cmd);
  2913. music = new char[i+1];
  2914. strncpy(music, cmd, i);
  2915. music[i] = 0;
  2916. mMusicList.pushBack(music);
  2917. }
  2918. }
  2919. else if (rc_command("DisplayFPS", cmd))
  2920. {
  2921. rc_get_bool(cmd, &b);
  2922. m_flags |= OpenRaider_ShowFPS;
  2923. if (!b)
  2924. {
  2925. m_flags ^= OpenRaider_ShowFPS;
  2926. }
  2927. }
  2928. else if (rc_command("ModelDebug", cmd))
  2929. {
  2930. rc_get_bool(cmd, &b);
  2931. m_flags |= OpenRaider_DebugModel;
  2932. if (!b)
  2933. {
  2934. m_flags ^= OpenRaider_DebugModel;
  2935. }
  2936. }
  2937. else if (rc_command("DumpTexture", cmd))
  2938. {
  2939. rc_get_bool(cmd, &b);
  2940. m_flags |= OpenRaider_DumpTexture;
  2941. if (!b)
  2942. {
  2943. m_flags ^= OpenRaider_DumpTexture;
  2944. }
  2945. }
  2946. else
  2947. {
  2948. printf("Command> [OpenRaider.Engine] Unknown command '%s'\n", cmd);
  2949. }
  2950. break;
  2951. case 3: // [Input.Mouse]
  2952. if (rc_command("SensitivityX", cmd))
  2953. {
  2954. m_mouseX = atof(cmd);
  2955. }
  2956. else if (rc_command("SensitivityY", cmd))
  2957. {
  2958. m_mouseY = atof(cmd);
  2959. }
  2960. else
  2961. {
  2962. printf("Command> [Input.Mouse] Unknown command '%s'\n", cmd);
  2963. }
  2964. break;
  2965. case 4:
  2966. if (cmd[1] == '.')
  2967. {
  2968. cmd[0] = '>';
  2969. cmd[1] = ' ';
  2970. for (i = strlen(cmd) - 1; i >= 0; --i)
  2971. {
  2972. if (cmd[i] == '.' || cmd[i] == '=')
  2973. {
  2974. cmd[i] = ' ';
  2975. }
  2976. }
  2977. }
  2978. consoleCommand(cmd);
  2979. break;
  2980. case 5:
  2981. if (rc_command("Enable", cmd))
  2982. {
  2983. rc_get_bool(cmd, &gStartServer);
  2984. }
  2985. else if (rc_command("Port", cmd))
  2986. {
  2987. if (gStartServer)
  2988. {
  2989. Network &net = *Network::Instance();
  2990. int port = atoi(cmd);
  2991. net.setPort(port);
  2992. print(true, "Starting network server on port %i...", port);
  2993. net.spawnServerThread();
  2994. }
  2995. }
  2996. else
  2997. {
  2998. printf("Command> [Network.Server] '%s' not implemented\n", cmd);
  2999. }
  3000. break;
  3001. }
  3002. }
  3003. int main(int argc, char *argv[])
  3004. {
  3005. OpenRaider *game = OpenRaider::Instance();
  3006. atexit(killOpenRaiderSingleton);
  3007. game->start();
  3008. return 0;
  3009. }