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

OpenRaider.cpp 94KB

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