Open Source Tomb Raider Engine
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

OpenRaider.cpp 95KB

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