Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OpenRaider.cpp 98KB

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