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 76KB

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