Open Source Tomb Raider Engine
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

OpenRaider.cpp 76KB

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