Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

OpenRaider.cpp 76KB

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