1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592 |
- /*!
- * \file include/OpenRaider.h
- * \brief Main Game Singleton
- *
- * \author Mongoose
- */
-
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdarg.h>
- #include <unistd.h>
- #include <math.h>
- #include <sys/types.h>
- #include <dirent.h>
-
- #include "World.h"
- #include "SkeletalModel.h"
- #include "OpenRaider.h"
-
- #include "games/TombRaider1.h" // tmp stop-gap
-
- enum OpenRaiderText { textConsole = 2, textMenu = 3, textOutput = 4 };
-
- const unsigned int TextureLimit = 24;
- const float TexelScale = 256.0f;
-
- World gWorld;
- std::map<int, int> gMapTex2Bump;
- Vector <unsigned int> gColorTextureHACK;
- int gTextureOffset;
- entity_t *LARA = 0x0;
- entity_t *gClientPlayer[32];
- unsigned int gNetTicks = 0;
- unsigned int gNetLastTicks = 0;
- bool gStartServer = false;
- skeletal_model_t *gLaraModel = 0x0;
- char *gFontFilename = 0x0;
-
- unsigned int getTicks()
- {
- OpenRaider *game = OpenRaider::Instance();
-
- return game->getTicks();
- }
-
-
- ////////////////////////////////////////////////////////////
- // Constructors
- ////////////////////////////////////////////////////////////
-
- OpenRaider *OpenRaider::mInstance = 0x0;
-
-
- OpenRaider *OpenRaider::Instance()
- {
- if (mInstance == 0x0)
- {
- mInstance = new OpenRaider();
- }
-
- return mInstance;
- }
-
-
- void killOpenRaiderSingleton() {
- killNetworkSingleton();
-
- printf("Shutting down Game...\n");
-
- // Requires public deconstructor
- //! \fixme Causes pointer-being-freed-not-allocated error!
- //delete OpenRaider::Instance();
-
- printf("\nThanks for testing %s\n", VERSION);
- printf("Build date: %s @ %s\n", __DATE__, __TIME__);
- printf("Build host: %s\n", BUILD_HOST);
- printf("Web site : http://github.com/xythobuz/OpenRaider\n");
- printf("Contact : xythobuz@xythobuz.de");
- }
-
-
- OpenRaider::OpenRaider() : SDLSystem()
- {
- Network::Instance();
-
- for (unsigned int i = 0; i < 32; ++i)
- {
- gClientPlayer[i] = 0x0;
- }
-
- m_pakDir = 0x0;
- m_audioDir = 0x0;
- m_homeDir = 0x0;
-
- m_mouseX = 2.5;
- m_mouseY = 0.5;
- m_texOffset = 0;
- mLevelTextureOffset = 0;
- m_testSFX = -1;
-
- mText = NULL;
- m_flags = 0;
- m_mapName[0] = '\0';
-
- /*! \todo Replace numbers with enum modes.
- * Only do this when you know the amount of commands + 1 (0 reserved)
- */
- mMode[addCommandMode("[OpenRaider.Engine]")] = 2;
- mMode[addCommandMode("[Network.Server]")] = 5;
- mMode[addCommandMode("[Video.OpenGL]")] = 0;
- mMode[addCommandMode("[Audio.OpenAL]")] = 1;
- mMode[addCommandMode("[OpenRaider.Console]")] = 4;
- mMode[addCommandMode("[Input.Mouse]")] = 3;
- }
-
-
- OpenRaider::~OpenRaider() {
- /*! \fixme GL call to critical section,
- * needs mutex really -- Mongoose 2002.01.02
- */
- m_render.setMode(Render::modeDisabled);
- //sleep(1);
-
- printf("Removing World...\n");
- gWorld.destroy();
-
- printf("Cleaning up...\n");
-
- for (mMapList.start(); mMapList.forward(); mMapList.next()) {
- if (mMapList.current())
- delete [] mMapList.current();
- }
-
- for (mMusicList.start(); mMusicList.forward(); mMusicList.next()) {
- if (mMusicList.current())
- delete [] mMusicList.current();
- }
-
- if (m_pakDir)
- delete [] m_pakDir;
-
- if (m_audioDir)
- delete [] m_audioDir;
-
- if (m_homeDir)
- delete [] m_homeDir;
-
- if (gFontFilename)
- delete [] gFontFilename;
- }
-
-
- ////////////////////////////////////////////////////////////
- // Public Accessors
- ////////////////////////////////////////////////////////////
-
-
- ////////////////////////////////////////////////////////////
- // Public Mutators
- ////////////////////////////////////////////////////////////
-
- void eventAnimTest(int anim)
- {
- if (LARA)
- {
- SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
-
- if (mdl)
- {
- mdl->setAnimation(anim);
- }
- }
- }
-
-
- void percent_callback(int p) {
- OpenRaider &game = *OpenRaider::Instance();
-
- switch (p) {
- case 10:
- game.print(true, "Level textures loaded");
- break;
- default:
- game.print(false, "Level pak %i%% loaded", p);
- break;
- }
- }
-
-
- void openraider_warning(const char *func_name, const char *warning,
- const char *filename, int line)
- {
- printf("%s> WARNING %s %s:%i\n", func_name, warning, filename, line);
- }
-
- void openraider_error(const char *func_name, const char *error,
- const char *filename, int line)
- {
- printf("%s> ERROR %s %s:%i\n", func_name, error, filename, line);
- }
-
-
- void from_network_layer(network_packet_t *p, unsigned int *last_id)
- {
- static unsigned int i = 0;
-
-
- *last_id = i++;
-
- if (gNetTicks > gNetLastTicks + 200) // 200ms
- {
- gNetLastTicks = gNetTicks;
- p->send = 1;
- }
-
- if (LARA)
- {
- p->pos[0] = LARA->pos[0];
- p->pos[1] = LARA->pos[1];
- p->pos[2] = LARA->pos[2];
- p->yaw = LARA->angles[1];
- p->pitch = LARA->angles[1];
- p->view_model = LARA->modelId;
-
- SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
-
- if (mdl)
- {
- p->aframe = mdl->getAnimation();
- p->bframe = mdl->getFrame();
- }
- }
-
- #ifdef DEBUG_NETWORK
- printf("<> Sending data\n");
- #endif
- }
-
-
- void to_network_layer(network_packet_t p)
- {
- OpenRaider &game = *OpenRaider::Instance();
-
-
- #ifdef DEBUG_NETWORK
- printf("<> Recieved data\n");
- #endif
-
- if (gClientPlayer[p.cid])
- {
- gClientPlayer[p.cid]->pos[0] = p.pos[0];
- gClientPlayer[p.cid]->pos[1] = p.pos[1];
- gClientPlayer[p.cid]->pos[2] = p.pos[2];
- gClientPlayer[p.cid]->angles[1] = p.yaw;
- gClientPlayer[p.cid]->angles[2] = p.pitch;
- }
- else if (LARA)
- {
- gClientPlayer[p.cid] = new entity_t;
-
- gClientPlayer[p.cid]->pos[0] = p.pos[0];
- gClientPlayer[p.cid]->pos[1] = p.pos[1];
- gClientPlayer[p.cid]->pos[2] = p.pos[2];
- gClientPlayer[p.cid]->angles[1] = p.yaw;
- gClientPlayer[p.cid]->angles[2] = p.pitch;
- gClientPlayer[p.cid]->moving = true;
- gClientPlayer[p.cid]->objectId = 0;
- gClientPlayer[p.cid]->id = LARA->id+1000+p.cid;
- gClientPlayer[p.cid]->type = 0x02;
-
- SkeletalModel *mdl = new SkeletalModel();
- gClientPlayer[p.cid]->tmpHook = mdl;
- mdl->setAnimation(p.aframe);
- mdl->setFrame(p.bframe);
- mdl->setIdleAnimation(TR_ANIAMTION_STAND);
- gClientPlayer[p.cid]->modelId = LARA->modelId; //p.view_model;
- gClientPlayer[p.cid]->animate = true;
-
- gWorld.addEntity(gClientPlayer[p.cid]);
- game.print(true, "A new player (%u) connected", p.cid);
- }
-
- if (LARA)
- {
- Network &network = *Network::Instance();
- network_frame_t &gPiggyBack = network.getPiggyBack();
-
-
- if (gNetTicks > gNetLastTicks + 200)
- {
- gNetLastTicks = gNetTicks;
- gPiggyBack.data.send = 1;
- }
-
- gPiggyBack.data.pos[0] = LARA->pos[0];
- gPiggyBack.data.pos[1] = LARA->pos[1];
- gPiggyBack.data.pos[2] = LARA->pos[2];
- gPiggyBack.data.yaw = LARA->angles[1];
- gPiggyBack.data.pitch = LARA->angles[2];
- gPiggyBack.data.view_model = LARA->modelId;
-
- SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
-
- if (mdl)
- {
- gPiggyBack.data.aframe = mdl->getAnimation();
- gPiggyBack.data.bframe = mdl->getFrame();
- }
- }
- }
-
-
- void OpenRaider::handleMouseMotionEvent(float x, float y)
- {
- if (x > 0)
- {
- while (x-- > 0) // Tried to fix very slow camera movements
- m_camera.command(CAMERA_ROTATE_RIGHT);
-
- if (LARA)
- {
- switch (LARA->moveType)
- {
- case worldMoveType_swim:
- case worldMoveType_fly:
- case worldMoveType_noClipping:
- eventAnimTest(TR_ANIAMTION_SWIM_R);
- break;
- case worldMoveType_walk:
- case worldMoveType_walkNoSwim:
- eventAnimTest(TR_ANIAMTION_TURN_L); // TURN left always for now
- break;
- }
-
- LARA->moving = true;
- }
- }
- else if (x < 0)
- {
- while (x++ < 0) // Tried to fix very slow camera movements
- m_camera.command(CAMERA_ROTATE_LEFT);
-
- if (LARA)
- {
- switch (LARA->moveType)
- {
- case worldMoveType_swim:
- case worldMoveType_fly:
- case worldMoveType_noClipping:
- eventAnimTest(TR_ANIAMTION_SWIM_L);
- break;
- case worldMoveType_walk:
- case worldMoveType_walkNoSwim:
- eventAnimTest(TR_ANIAMTION_TURN_L);
- break;
- }
-
- LARA->moving = true;
- }
- }
-
- if (y > 0)
- while (y-- > 0) // Tried to fix very slow camera movements
- m_camera.command(CAMERA_ROTATE_UP);
- else if (y < 0)
- while (y++ < 0) // Tried to fix very slow camera movements
- m_camera.command(CAMERA_ROTATE_DOWN);
-
- if (LARA)
- {
- LARA->angles[1] = m_camera.getRadianYaw();
- LARA->angles[2] = m_camera.getRadianPitch();
- }
- }
-
-
- void OpenRaider::handleKeyReleaseEvent(unsigned int key, unsigned int mod)
- {
- }
-
-
- void OpenRaider::handleBoundKeyPressEvent(unsigned int key)
- {
- switch (key)
- {
- case OpenRaiderKey_jump:
- m_camera.command(CAMERA_MOVE_UP);
-
- if (LARA)
- {
- LARA->moving = true;
- }
- break;
- case OpenRaiderKey_crouch:
- m_camera.command(CAMERA_MOVE_DOWN);
-
- if (LARA)
- {
- LARA->moving = true;
- }
- break;
- case OpenRaiderKey_forward:
- gWorld.moveEntity(LARA, 'f');
-
- if (LARA && LARA->moving)
- {
- switch (LARA->moveType)
- {
- case worldMoveType_swim:
- case worldMoveType_fly:
- case worldMoveType_noClipping:
- eventAnimTest(TR_ANIAMTION_SWIM);
- break;
- case worldMoveType_walk:
- case worldMoveType_walkNoSwim:
- eventAnimTest(TR_ANIAMTION_RUN);
- break;
- }
- }
- else if (LARA)
- {
- switch (LARA->moveType)
- {
- case worldMoveType_swim:
- case worldMoveType_fly:
- case worldMoveType_noClipping:
- eventAnimTest(TR_ANIAMTION_SWIM_IDLE);
- break;
- case worldMoveType_walk:
- case worldMoveType_walkNoSwim:
- eventAnimTest(TR_ANIAMTION_HIT_WALL_FRONT);
- break;
- }
- }
- else
- {
- m_camera.command(CAMERA_MOVE_FORWARD);
- }
- break;
- case OpenRaiderKey_backward:
- gWorld.moveEntity(LARA, 'b');
-
- if (LARA && LARA->moving)
- {
- switch (LARA->moveType)
- {
- case worldMoveType_swim:
- case worldMoveType_fly:
- case worldMoveType_noClipping:
- eventAnimTest(TR_ANIAMTION_SWIM);
- break;
- case worldMoveType_walk:
- case worldMoveType_walkNoSwim:
- eventAnimTest(TR_ANIAMTION_RUN);
- break;
- }
- }
- break;
- case OpenRaiderKey_left:
- gWorld.moveEntity(LARA, 'l');
-
- if (LARA && LARA->moving)
- {
- switch (LARA->moveType)
- {
- case worldMoveType_swim:
- case worldMoveType_fly:
- case worldMoveType_noClipping:
- eventAnimTest(TR_ANIAMTION_SWIM);
- break;
- case worldMoveType_walk:
- case worldMoveType_walkNoSwim:
- eventAnimTest(TR_ANIAMTION_RUN);
- break;
- }
- }
- else if (!LARA)
- {
- m_camera.command(CAMERA_MOVE_LEFT);
- }
- break;
- case OpenRaiderKey_right:
- gWorld.moveEntity(LARA, 'r');
-
- if (LARA && LARA->moving)
- {
- switch (LARA->moveType)
- {
- case worldMoveType_swim:
- case worldMoveType_fly:
- case worldMoveType_noClipping:
- eventAnimTest(TR_ANIAMTION_SWIM);
- break;
- case worldMoveType_walk:
- case worldMoveType_walkNoSwim:
- eventAnimTest(TR_ANIAMTION_RUN);
- break;
- }
- }
- else if (!LARA)
- {
- m_camera.command(CAMERA_MOVE_RIGHT);
- }
- break;
- case OpenRaiderKey_panRight:
- m_camera.command(CAMERA_ROTATE_RIGHT);
- break;
- case OpenRaiderKey_panLeft:
- m_camera.command(CAMERA_ROTATE_LEFT);
- break;
- case OpenRaiderKey_tiltDown:
- m_camera.command(CAMERA_ROTATE_DOWN);
- break;
- case OpenRaiderKey_tiltUp:
- m_camera.command(CAMERA_ROTATE_UP);
- break;
- }
- }
-
-
- void OpenRaider::handleBoundKeyReleaseEvent(unsigned int key)
- {
- switch (key)
- {
- case '`': // Temp hack also until console is rolled back
- //i = 2;
-
- if (mConsoleMode)
- {
- //buffer[0] = '>';
- //buffer[1] = ' ';
- //buffer[2] = 0;
-
- mText->setActive(textConsole, true);
- }
- else
- {
- mText->setActive(textConsole, false);
- //buffer[0] = 0;
- }
- break;
- case OpenRaiderKey_forward:
- case OpenRaiderKey_backward:
- case OpenRaiderKey_right:
- case OpenRaiderKey_left:
- if (LARA)
- {
- LARA->moving = false;
- }
- }
- }
-
-
- void OpenRaider::handleConsoleKeyPressEvent(unsigned int key,unsigned int mod)
- {
- static char lastCmd[64] = "2 ";
- static unsigned int i = 0;
- char *buffer;
- unsigned int len;
-
-
- // Cheap console test
- len = mText->GetStringLen(textConsole);
- buffer = mText->GetBuffer(textConsole);
-
- //printf("- 0x%x\n", key);
-
- if (key == mConsoleKey)
- {
- i = 2;
-
- if (mConsoleMode)
- {
- buffer[0] = '>';
- buffer[1] = ' ';
- buffer[2] = 0;
-
- mText->setActive(textConsole, true);
- }
- else
- {
- mText->setActive(textConsole, false);
- buffer[0] = 0;
- }
- }
- else if (mConsoleMode && len > i+1)
- {
- switch (key)
- {
- case SYS_KEY_UP:
- i = lastCmd[0];
-
- lastCmd[0] = '>';
- mText->SetString(textConsole, "%s", lastCmd);
- break;
- case 0:
- break;
- case '\b':
- if (i > 2)
- {
- buffer[--i] = 0;
- }
- break;
- case '\r':
- case '\n':
- strncpy(lastCmd, buffer, 63);
- lastCmd[0] = (char)i;
-
- command("[OpenRaider.Console]");
- command(buffer);
-
- i = 2;
- buffer[0] = '>';
- buffer[1] = ' ';
- buffer[2] = 0;
- break;
- default:
- if (mod & (SYS_MOD_KEY_RSHIFT | SYS_MOD_KEY_LSHIFT) &&
- key > 96 && key < 122)
- {
- buffer[i++] = (char)(key - 32);
- }
- else
- {
- if (mod & (SYS_MOD_KEY_RSHIFT | SYS_MOD_KEY_LSHIFT))
- {
- if (key == '-')
- key = '_';
- }
-
- buffer[i++] = (char)key;
- }
-
- buffer[i] = 0;
- }
- }
- }
-
-
- void OpenRaider::menuMapListMove(char dir, bool show) {
- if (dir == 'f') {
- mMapList.next();
- if (!mMapList.forward())
- mMapList.start();
- } else if (dir == 'b') {
- mMapList.prev();
- if (!mMapList.backward())
- mMapList.finish();
- } else if (dir == 'n') {
- size_t slashPos = strcspn(mMapList.current(), "/");
- if (slashPos < strlen(mMapList.current())) {
- char *dirName = new char[slashPos + 1];
- dirName[slashPos] = '\0';
- strncpy(dirName, mMapList.current(), slashPos);
- do {
- menuMapListMove('f', false);
- } while (strstr(mMapList.current(), dirName) != NULL);
- delete []dirName;
- } else {
- do {
- menuMapListMove('f', false);
- } while (strstr(mMapList.current(), "/") == NULL);
- }
- } else if (dir == 'p') {
- size_t slashPos = strcspn(mMapList.current(), "/");
- if (slashPos < strlen(mMapList.current())) {
- char *dirName = new char[slashPos + 1];
- dirName[slashPos] = '\0';
- strncpy(dirName, mMapList.current(), slashPos);
- do {
- menuMapListMove('b', false);
- } while (strstr(mMapList.current(), dirName) != NULL);
- // Yeah, cheap...
- strncpy(dirName, mMapList.current(), slashPos);
- do {
- menuMapListMove('b', false);
- } while (strstr(mMapList.current(), dirName) != NULL);
- menuMapListMove('f', false);
- delete []dirName;
- } else {
- do {
- menuMapListMove('b', false);
- } while (strstr(mMapList.current(), "/") == NULL);
- }
- }
-
- if (show) {
- if (mMapList.current())
- mText->SetString(textMenu, "Load %s?", mMapList.current());
- else
- mText->SetString(textMenu, "See README for map install");
- }
- }
-
-
- void OpenRaider::handleKeyPressEvent(unsigned int key, unsigned int mod)
- {
- static bool menu = false;
-
- // Cheap menu test
- if (menu)
- {
- switch (key)
- {
- case SYS_KEY_ESC:
- menu = false;
- mText->SetString(textMenu, " ");
- mText->setActive(textMenu, false);
- break;
- case SYS_KEY_ENTER:
- loadLevel(mMapList.current());
- mText->SetString(textMenu, " ");
- mText->setActive(textMenu, false);
-
- menu = false;
- break;
- case SYS_KEY_DOWN:
- menuMapListMove('b', true);
- break;
- case SYS_KEY_UP:
- menuMapListMove('f', true);
- break;
- case SYS_KEY_LEFT:
- menuMapListMove('p', true);
- break;
- case SYS_KEY_RIGHT:
- menuMapListMove('n', true);
- break;
- }
-
- return;
- }
-
- switch (key)
- {
- case SYS_KEY_ESC:
- menu = true;
- mText->SetString(textMenu, "Select a map UP/DOWN");
- mText->setActive(textMenu, true);
- break;
- case SYS_KEY_ENTER:
- if (mod & SYS_MOD_KEY_LALT)
- {
- toggleFullscreen();
- }
- break;
- }
-
- ////////////////////////////////////////////////////////////
-
- switch (key)
- {
- case SYS_MOUSE_LEFT:
- mSound.play(m_testSFX);
-
- if (LARA)
- {
- eventAnimTest(15);
- }
- break;
- case '/':
- if (LARA)
- {
- entity_t *e = new entity_t;
-
- e->pos[0] = LARA->pos[0];
- e->pos[1] = LARA->pos[1] - 256.0f; // crawling H
- e->pos[2] = LARA->pos[2];
- e->type = 61;
- e->master = LARA->master;
- LARA->master = e;
- }
- break;
- case '[':
- if (LARA)
- {
- SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
-
- if (mdl)
- {
- mdl->setIdleAnimation(mdl->getIdleAnimation() - 1);
- mdl->setAnimation(mdl->getIdleAnimation());
- print(false, "AFRAME %i\n", mdl->getIdleAnimation());
- }
- }
- break;
- case ']':
- if (LARA)
- {
- SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
-
- if (mdl)
- {
- mdl->setIdleAnimation(mdl->getIdleAnimation() + 1);
- mdl->setAnimation(mdl->getIdleAnimation());
- print(false, "AFRAME %i\n", mdl->getIdleAnimation());
- }
- }
- break;
- case 'r':
- mSound.play(m_testSFX);
- break;
- }
- }
-
-
- void OpenRaider::print(bool dump_stdout, const char *format, ...)
- {
- static char buffer[128];
- va_list args;
- unsigned int l;
-
-
- va_start(args, format);
- vsnprintf(buffer, 128, format, args);
-
- l = strlen(buffer);
-
- if (!l || !buffer[0])
- {
- return;
- }
-
- // Strip message of trailing newline
- if (buffer[l-1] == '\n')
- {
- buffer[l-1] = 0;
- }
-
- // Print to game 'console'
- if (mText)
- {
- mText->SetString(textOutput, "%s", buffer);
- }
-
- // Print to stdout
- if (dump_stdout)
- {
- fprintf(stdout, "> %s\n", buffer);
- }
-
- va_end(args);
-
- // Mongoose 2002.08.14, Currently, you must request
- // frame redraws in this mode
- if (m_flags & OpenRaider_Loading)
- {
- gameFrame();
- }
- }
-
-
- void OpenRaider::start()
- {
- vec3_t up;
- char *filename;
-
-
- printf("\n[Starting %s]\n\n", VERSION);
-
-
- filename = fullPath("~/.OpenRaider/OpenRaider.init", 0);
-
- if (loadResourceFile(filename) < 0)
- {
-
- printf("Could not find ~/.OpenRaider/OpenRaider.init\n");
- if (loadResourceFile("OpenRaider.init") < 0)
- {
- shutdown(-1);
- }
- printf("Loaded defaults...\n");
- }
-
- delete [] filename;
-
- m_camera.reset();
- m_camera.setSensitivityX(m_mouseX);
- m_camera.setSensitivityY(m_mouseY);
- m_camera.setSpeed(512);
- up[0] = 0.0;
- up[1] = -1.0;
- up[2] = 0.0;
- m_camera.setUp(up);
-
- if (mMapList.empty())
- {
- printf("No maps in map list, please edit your OpenRaider.init\n");
- shutdown(0);
- }
-
- // Mongoose 2002.08.13, System protected members abuse
- m_fovY = 40.0f;
- m_clipFar = 600000.0f;
- m_clipNear = 10.0f;
-
- // Mongoose 2002.08.13, This starts GL context
- printf("\n[Starting video subsystem...]\n");
- initVideo(m_width, m_height, false);
-
- // Mongoose 2002.01.02, Disable rendering to avoid GL call conflicts
- m_render.setMode(Render::modeDisabled);
- m_render.Init(m_width, m_height);
- m_render.initTextures(m_homeDir, &m_texOffset, &mLevelTextureOffset);
-
- m_render.RegisterCamera(&m_camera);
- mText = m_render.GetString();
-
- // Mongoose 2002.01.03, Good idea?
- m_render.setMode(Render::modeLoadScreen);
-
- // Mongoose 2002.01.02, Load external audio tracks and fx
- // General audio init
- initSound();
-
- // Old room movement
- gWorld.setFlag(World::fEnableHopping);
- // reenabled, what should be the new room movement? --xythobuz
-
- resetTicks();
-
- runGame();
- }
-
-
- void OpenRaider::initSound()
- {
- if (!(m_flags & OpenRaider_EnableSound) || mSound.init() < 0)
- {
- print(true, "Disabling sound...\n");
- m_flags &= ~OpenRaider_EnableSound;
- return;
- }
-
- #ifdef OBSOLETE
- char filename[128];
- int id;
-
- printf("Processing external sound files: ");
-
- // Mongoose 2001.12.31, Use music list from init script
- if (mMusicList.Empty())
- {
- print(true, "No music in map list, please edit your OpenRaider.init\n");
- }
- else
- {
- snprintf(filename, 126, "%s%s", m_audioDir, mMusicList[0]);
- filename[127] = 0;
-
- if (!mSound.addFile(filename, &id, mSound.SoundFlagsLoop))
- {
- mSound.play(id);
-
- printf("m");
- fflush(stdout);
- }
- }
-
- //snprintf(filename, 126, "%s%s", m_homeDir, "sample.wav");
- //filename[127] = 0;
- //mSound.addFile(filename, &m_testSFX, mSound.SoundFlagsNone);
-
- printf(".");
- fflush(stdout);
-
- printf("\n");
- #endif
- }
-
-
- void OpenRaider::processPakSounds()
- {
- unsigned char *riff;
- unsigned int riffSz;
- //tr2_sound_source_t *sound;
- //tr2_sound_details_t *detail;
- //float pos[3];
- unsigned int i;
- int id;
-
- /* detail
- short sample;
- short volume;
- short sound_range;
- short flags; // bits 8-15: priority?, 2-7: number of sound samples
- // in this group, bits 0-1: channel number
- */
-
- if (m_flags & OpenRaider_EnableSound)
- {
- printf("Processing pak sound files: ");
- }
- else
- {
- return;
- }
-
- for (i = 0; i < m_tombraider.getSoundSamplesCount(); ++i)
- {
- print(false, "Processing pak sounds: %i / %i",
- i, m_tombraider.getSoundSamplesCount());
-
- m_tombraider.getSoundSample(i, &riffSz, &riff);
-
- mSound.addWave(riff, riffSz, &id, mSound.SoundFlagsNone);
-
- if (((i + 1) == TR_SOUND_F_PISTOL) && (id > 0))
- {
- m_testSFX = id;
- }
-
- delete [] riff;
-
- // sound[i].sound_id; // internal sound index
- // sound[i].flags; // 0x40, 0x80, or 0xc0
- //pos[0] = sound[i].x;
- //pos[1] = sound[i].y;
- //pos[2] = sound[i].z;
- //mSound.SourceAt(id, pos);
-
- printf(".");
- fflush(stdout);
- }
-
- printf("\n");
- }
-
-
- void OpenRaider::loadLevel(char *mapname)
- {
- int i, j, len;
- char filename[256];
-
-
- // Mongoose 2002.03.23, Clear last loaded 'world'
- m_render.setMode(Render::modeDisabled);
- m_render.ClearWorld();
- gWorld.destroy();
-
- // Mongoose 2002.01.02, Now draw load screen, since external
- // GL textures are loaded and renderer is initialized
- m_render.setMode(Render::modeLoadScreen);
- gameFrame();
-
- /* 2003.07.05, Mongoose - No longer seeding, and looking for
- map to load -- load this map or fail and return */
- snprintf(filename, 254, "%s%s", m_pakDir, mapname);
- filename[255] = 0;
- len = strlen(filename);
-
- for (i = len, j = 0; i > 0; --i, ++j)
- {
- if (filename[i] == '/' || filename[i] == '\\')
- break;
- }
-
- j--;
-
- memset(m_mapName, 0, 32);
-
- for (i = 0; i < len - j && i < 30; ++i)
- {
- m_mapName[i] = filename[i + len - j];
- }
-
- m_tombraider.setDebug(m_flags & OpenRaider_DebugMap);
-
- m_flags |= OpenRaider_Loading;
- print(true, "Level %s loading", m_mapName);
-
- if (m_tombraider.Load(filename, percent_callback))
- {
- print(true, "ERROR: Failed to load level %s\n", m_mapName);
- return;
- }
- else
- {
- char altSfx[256];
-
- switch (m_tombraider.getEngine())
- {
- case TR_VERSION_2:
- case TR_VERSION_3:
- // Now loads eg. "tr3/MAIN.SFX" instead of "tr3/SHORE.TR2.sfx"
- filename[len - j] = '\0';
- snprintf(altSfx, 255, "%sMAIN.SFX", filename);
- print(true, "Loading alternate SFX for TR2 or TR3 pak at %sMAIN.SFX\n", filename);
-
- m_tombraider.loadSFX(altSfx);
- break;
- case TR_VERSION_1:
- case TR_VERSION_4:
- case TR_VERSION_5:
- case TR_VERSION_UNKNOWN:
- break;
- }
- }
-
- print(true, "Optimizing and translating pak data...");
- m_flags ^= OpenRaider_Loading;
-
- // Mongoose 2002.08.16, Used to cache TR4 textures at 10% of file load
- // in a callback - then with other engines process them here
- m_render.setMode(Render::modeDisabled);
- //sleep(1); // Why should we sleep here? -- xythobuz
- processTextures();
- m_render.setMode(Render::modeLoadScreen);
- print(true, "Level textures cached\n");
-
- // Cache/process rooms
- printf("Processing rooms: ");
-
- for (i = 0; i < m_tombraider.NumRooms(); ++i)
- {
- processRoom(i);
- print(false, "Processing rooms: %i/%i", i, m_tombraider.NumRooms());
- }
-
- printf("\n");
-
- // Cache/process meshes
- printf("Processing meshes: ");
-
- for (i = 0; i < m_tombraider.getMeshCount(); ++i)
- {
- m_render.setMode(Render::modeDisabled);
- processModel(i);
- m_render.setMode(Render::modeLoadScreen);
- print(false, "Processing meshes: %i/%i", i, m_tombraider.getMeshCount());
- }
-
- printf("\n");
-
- // Cache/process sprites
- processSprites();
-
- // Cache/process skeletal models
- processMoveables();
-
- // Cache/process sound fx
- processPakSounds();
-
- // Mongoose 2002.01.02, Go ahead and free the TR pak
- m_tombraider.reset();
-
- print(true, "Level pak freed from memory, Starting game...");
-
- /*! \fixme GL call to critical section,
- * needs mutex really -- Mongoose 2002.01.02
- */
- m_render.setMode(Render::modeDisabled);
- sleep(1);
-
- // Draw game, level is loaded
- m_render.setMode(Render::modeVertexLight);
-
- m_flags ^= OpenRaider_Loading;
- }
-
-
- void OpenRaider::gameFrame()
- {
- SkeletalModel *mdl = 0x0;
- unsigned int ticks;
- float time;
-
-
- // Remember: ticks in milliseconds, time in hundredths
- gNetTicks = ticks = getTicks();
- time = gNetTicks * 0.1f;
-
- switch (m_render.getMode())
- {
- case Render::modeDisabled:
- break;
- case Render::modeLoadScreen:
- if ((ticks % 10000) > 1)
- {
- m_render.drawLoadScreen();
- swapBuffersGL();
- }
- break;
- default:
- if (LARA)
- {
- mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
-
- if (mdl)
- {
- float elapsed = time - mdl->lastTime;
-
-
- if (elapsed > mdl->rate)
- {
- if (mdl->getAnimation() == 0 &&
- (mdl->getFrame() == 2 || mdl->getFrame() == 10))
- {
- if (m_flags & OpenRaider_EnableSound)
- {
- mSound.play(TR_SOUND_FOOTSTEP0);
- }
- }
- else if (mdl->getAnimation() == 15)
- {
- eventAnimTest(TR_ANIAMTION_RUN);
- }
-
- mdl->setFrame(mdl->getFrame()+1);
- mdl->lastTime = elapsed / mdl->rate;
- }
- else
- {
- mdl->lastTime = time;
- }
- }
- }
-
- m_render.Display();
- swapBuffersGL();
-
- if (mdl && mdl->getAnimation() == 12)
- {
- switch (LARA->moveType)
- {
- case worldMoveType_swim:
- case worldMoveType_fly:
- case worldMoveType_noClipping:
- eventAnimTest(TR_ANIAMTION_SWIM_IDLE);
- break;
- case worldMoveType_walk:
- case worldMoveType_walkNoSwim:
- eventAnimTest(TR_ANIAMTION_STAND);
- break;
- }
-
- LARA->moving = false;
- }
- }
-
- if (m_flags & OpenRaider_ShowFPS)
- {
- static unsigned int frames = 0;
- static float lastTime = 0.0f;
-
-
- ++frames;
-
- // Only update every second, so it can't be affected
- // by fast/slow cards it only counts frames instead
- // of estimating
- if (time - lastTime > 100.0f)
- {
- if (mText)
- mText->SetString(1, "%dFPS", frames);
-
- lastTime = time;
- frames = 0;
- }
- }
- }
-
-
- void OpenRaider::processTextures()
- {
- unsigned char *image;
- unsigned char *bumpmap;
- int i;
-
-
- printf("Processing TR textures: ");
-
- //if ( m_tombraider.getNumBumpMaps())
- // gBumpMapStart = m_tombraider.NumTextures();
-
- for (i = 0; i < m_tombraider.NumTextures(); ++i)
- {
- print(false, "Processing textures: %i/%i", i, m_tombraider.NumTextures());
-
- m_tombraider.Texture(i, &image, &bumpmap);
-
- // Overwrite any previous level textures on load
- m_render.loadTexture(image, 256, 256, mLevelTextureOffset + i);
-
- gMapTex2Bump[mLevelTextureOffset + i] = -1;
-
- if (bumpmap)
- {
- gMapTex2Bump[mLevelTextureOffset + i] = mLevelTextureOffset + i +
- m_tombraider.NumTextures();
- m_render.loadTexture(bumpmap, 256, 256, mLevelTextureOffset + i +
- m_tombraider.NumTextures());
- }
-
- if (image)
- delete [] image;
-
- if (bumpmap)
- delete [] bumpmap;
-
- printf(".");
- fflush(stdout);
- }
-
- gTextureOffset = mLevelTextureOffset + m_tombraider.NumTextures();
-
- printf("\n");
- }
-
-
- ////////////////////////////////////////////////////////////
- // Private Accessors
- ////////////////////////////////////////////////////////////
-
-
- ////////////////////////////////////////////////////////////
- // Private Mutators
- ////////////////////////////////////////////////////////////
-
- void OpenRaider::soundEvent(int type, int id, vec3_t pos, vec3_t angles)
- {
- switch (type)
- {
- case 0: // Reset listener position
- mSound.listenAt(pos, angles);
- break;
- default:
- mSound.sourceAt(id, pos);
- mSound.play(id);
- }
- }
-
-
- void OpenRaider::processSprites()
- {
- int i, j, k, l, x, y, s_index, width, height;
- float scale, width2, height2;
- tr2_sprite_texture_t *sprite;
- tr2_sprite_texture_t *sprite_textures;
- tr2_sprite_sequence_t *sprite_sequence;
- sprite_seq_t *r_mesh;
- tr2_item_t *item;
-
-
- item = m_tombraider.Item();
- sprite_textures = m_tombraider.Sprite();
- sprite_sequence = m_tombraider.SpriteSequence();
- scale = 4.0;
-
- printf("Processing sprites: ");
-
- for (i = 0; i < m_tombraider.NumItems() - 1; ++i)
- {
- print(false, "Processing sprites in Items: %i/%i",
- i, m_tombraider.NumItems());
-
- // It's a mesh, skip it
- if (m_tombraider.Engine() == TR_VERSION_1 && item[i].intensity1 == -1)
- continue;
-
- k = item[i].object_id;
-
- // Search the SpriteSequence list
- // (if we didn't already decide that it's a mesh)
- for (j = 0; j < (int)m_tombraider.NumSpriteSequences(); ++j)
- {
- if (sprite_sequence[j].object_id == k)
- {
- k = item[i].object_id;
-
- s_index = sprite_sequence[j].offset;
-
- r_mesh = new sprite_seq_t;
- gWorld.addSprite(r_mesh);
- r_mesh->num_sprites = -sprite_sequence[j].negative_length;
- r_mesh->sprite = new sprite_t[r_mesh->num_sprites];
-
- for (l = 0; l < r_mesh->num_sprites; ++l)
- {
- sprite = &sprite_textures[s_index];
-
- width = sprite->width >> 8;
- height = sprite->height >> 8;
- x = sprite->x;
- y = sprite->y;
- width2 = width * scale;
- height2 = height * scale;
-
- // For vising use
- r_mesh->sprite[l].pos[0] = item[i].x;
- r_mesh->sprite[l].pos[1] = item[i].y;
- r_mesh->sprite[l].pos[2] = item[i].z;
- r_mesh->sprite[l].texture = sprite->tile + m_texOffset;
-
- r_mesh->sprite[l].radius = width2 / 2.0f;
-
- r_mesh->sprite[l].vertex[0].pos[0] = -width2 / 2.0f;
- r_mesh->sprite[l].vertex[1].pos[0] = -width2 / 2.0f;
- r_mesh->sprite[l].vertex[2].pos[0] = width2 / 2.0f;
- r_mesh->sprite[l].vertex[3].pos[0] = width2 / 2.0f;
-
- r_mesh->sprite[l].vertex[0].pos[1] = 0;
- r_mesh->sprite[l].vertex[1].pos[1] = -height2;
- r_mesh->sprite[l].vertex[2].pos[1] = -height2;
- r_mesh->sprite[l].vertex[3].pos[1] = 0;
-
- r_mesh->sprite[l].vertex[0].pos[2] = 0;
- r_mesh->sprite[l].vertex[1].pos[2] = 0;
- r_mesh->sprite[l].vertex[2].pos[2] = 0;
- r_mesh->sprite[l].vertex[3].pos[2] = 0;
-
- r_mesh->sprite[l].texel[3].st[0] = (vec_t)(x+width)/TexelScale;
- r_mesh->sprite[l].texel[3].st[1] = (vec_t)(y+height)/TexelScale;
-
- r_mesh->sprite[l].texel[2].st[0] = (vec_t)(x+width)/TexelScale;
- r_mesh->sprite[l].texel[2].st[1] = (vec_t)(y)/TexelScale;
-
- r_mesh->sprite[l].texel[1].st[0] = (vec_t)(x) /TexelScale;
- r_mesh->sprite[l].texel[1].st[1] = (vec_t)(y) /TexelScale;
-
- r_mesh->sprite[l].texel[0].st[0] = (vec_t)(x) / TexelScale;
- r_mesh->sprite[l].texel[0].st[1] = (vec_t)(y+height)/TexelScale;
-
- printf(".");
- fflush(stdout);
- }
- }
- }
- }
-
- printf("\n");
- }
-
-
- void OpenRaider::processMoveables()
- {
- List<unsigned int> cache;
- List<skeletal_model_t *> cache2;
- tr2_mesh_t *mesh = NULL;
- tr2_moveable_t *moveable = NULL;
- tr2_meshtree_t *meshtree = NULL;
- tr2_item_t *item = NULL;
- tr2_animation_t *animation = NULL;
- unsigned short *frame = NULL;
- tr2_sprite_sequence_t *sprite_sequence = NULL;
- tr2_object_texture_t *object_texture = NULL;
- int i, j, object_id;
- int ent = 0;
-
-
- frame = m_tombraider.Frame();
- moveable = m_tombraider.Moveable();
- meshtree = m_tombraider.MeshTree();
- mesh = m_tombraider.Mesh();
- object_texture = m_tombraider.ObjectTextures();
- item = m_tombraider.Item();
- animation = m_tombraider.Animation();
- sprite_sequence = m_tombraider.SpriteSequence();
-
- printf("Processing skeletal models: ");
-
- for (i = 0; i < m_tombraider.NumItems(); ++i)
- {
- object_id = item[i].object_id;
-
- // It may not be a moveable, test for sprite
- if (!(m_tombraider.Engine() == TR_VERSION_1 && item[i].intensity1 == -1))
- {
- for (j = 0; j < (int)m_tombraider.NumSpriteSequences(); ++j)
- {
- if (sprite_sequence[j].object_id == object_id)
- break;
- }
-
- // It's not a moveable, skip sprite
- if (j != (int)m_tombraider.NumSpriteSequences())
- {
- printf("s");
- fflush(stdout);
- continue;
- }
- }
-
- for (j = 0; j < (int)m_tombraider.NumMoveables(); ++j)
- {
- if ((int)moveable[j].object_id == object_id)
- break;
- }
-
- // It's not a moveable or even a sprite?, skip unknown
- if (j == (int)m_tombraider.NumMoveables())
- {
- printf("?"); // what the wolf?
- fflush(stdout);
- continue;
- }
-
- processMoveable(j, i, &ent, cache2, cache, object_id);
- }
-
- // Get models that aren't items
- for (i = 0; i < m_tombraider.NumMoveables(); ++i)
- {
- print(false, "Processing skeletal models: %i/%i",
- i, m_tombraider.NumMoveables());
-
- switch ((int)moveable[i].object_id)
- {
- case 30:
- case 2: // Which tr needs this as model again?
- processMoveable(i, i, &ent, cache2, cache,
- (int)moveable[i].object_id);
- break;
- default:
- switch (m_tombraider.Engine())
- {
- case TR_VERSION_1:
- switch ((int)moveable[i].object_id)
- {
- case TombRaider1::LaraMutant:
- processMoveable(i, i, &ent, cache2, cache,
- (int)moveable[i].object_id);
- break;
- }
- break;
- case TR_VERSION_4:
- switch ((int)moveable[i].object_id)
- {
- case TR4_PISTOLS_ANIM:
- case TR4_UZI_ANIM:
- case TR4_SHOTGUN_ANIM:
- case TR4_CROSSBOW_ANIM:
- case TR4_GRENADE_GUN_ANIM:
- case TR4_SIXSHOOTER_ANIM:
- processMoveable(i, i, &ent, cache2, cache,
- (int)moveable[i].object_id);
- break;
- }
- break;
- case TR_VERSION_2:
- case TR_VERSION_3:
- case TR_VERSION_5:
- case TR_VERSION_UNKNOWN:
- break;
- }
- }
- }
-
- printf("\n");
- }
-
-
- void OpenRaider::processMoveable(int index, int i, int *ent,
- List<skeletal_model_t *> &cache2,
- List<unsigned int> &cache, int object_id)
- {
- skeletal_model_t *r_model = NULL;
- skeletal_model_t *c_model = NULL;
- animation_frame_t *animation_frame = NULL;
- tr2_mesh_t *mesh = NULL;
- tr2_moveable_t *moveable = NULL;
- tr2_meshtree_t *meshtree = NULL;
- tr2_item_t *item = NULL;
- tr2_animation_t *animation = NULL;
- tr2_meshtree_t *mesh_tree = NULL;
- bone_frame_t *bone = NULL;
- bone_tag_t *tag = NULL;
- entity_t *thing = NULL;
- SkeletalModel *sModel = 0x0;
- unsigned short *frame;
- int j, k, a, frame_step;
- unsigned int l, frame_offset, frame_count, f;
- float pos[3];
- float yaw;
- bool lara = false;
- int skyMesh;
-
-
- skyMesh = m_tombraider.getSkyModelId();
- frame = m_tombraider.Frame();
- moveable = m_tombraider.Moveable();
- meshtree = m_tombraider.MeshTree();
- mesh = m_tombraider.Mesh();
- item = m_tombraider.Item();
- animation = m_tombraider.Animation();
-
- pos[0] = item[i].x;
- pos[1] = item[i].y;
- pos[2] = item[i].z;
-
- yaw = ((item[i].angle >> 14) & 0x03);
- yaw *= 90;
-
- thing = new entity_t;
- thing->id = (*ent)++;
- thing->type = 0x00;
- thing->pos[0] = item[i].x;
- thing->pos[1] = item[i].y;
- thing->pos[2] = item[i].z;
- thing->angles[1] = yaw;
- thing->objectId = moveable[index].object_id;
- thing->moving = false;
- thing->animate = false;
-
- sModel = new SkeletalModel();
- m_render.addSkeletalModel(sModel);
- thing->tmpHook = sModel; // temp hack to keep a running version during refactoring
-
- if (m_tombraider.Engine() == TR_VERSION_1)
- {
- switch (thing->objectId)
- {
- case TombRaider1::Wolf:
- thing->state = TombRaider1::WolfState_Lying;
- //thing->animate = true;
- sModel->setAnimation(3);
- sModel->setFrame(0);
- break;
- }
- }
-
- //! \fixme Check here and see if we already have one for object_id later
- // if (gWorld.isCachedSkeletalModel(moveable[index].object_id))
- // {
- // thing->modelId = m_render.add(sModel);
- // return;
- // }
-
- r_model = new skeletal_model_t;
- r_model->id = moveable[index].object_id;
-
- // Gather more info if this is lara
- if (moveable[index].object_id == 0)
- {
- gLaraModel = r_model; // hack to avoid broken system until new event sys
-
- lara = true;
- m_camera.translate(pos[0], pos[1] - 470, pos[2]);
- thing->type = 0x02;
- LARA = thing; // Mongoose 2002.03.22, Cheap hack for now
- LARA->master = 0x0;
-
- switch (m_tombraider.Engine())
- {
- case TR_VERSION_3:
- LARA->modelId = i;
- sModel->setAnimation(TR_ANIAMTION_RUN);
- sModel->setIdleAnimation(TR_ANIAMTION_STAND);
- r_model->tr4Overlay = false;
- break;
- case TR_VERSION_4:
- LARA->modelId = i;
- sModel->setAnimation(TR_ANIAMTION_RUN);
- sModel->setIdleAnimation(TR_ANIAMTION_STAND);
- // Only TR4 lara has 2 layer bone tags/meshes per bone frame
- r_model->tr4Overlay = true;
- break;
- case TR_VERSION_1:
- case TR_VERSION_2:
- case TR_VERSION_5:
- case TR_VERSION_UNKNOWN:
- LARA->modelId = index;
- sModel->setAnimation(TR_ANIAMTION_RUN);
- sModel->setIdleAnimation(TR_ANIAMTION_STAND);
- r_model->tr4Overlay = false;
- break;
- }
-
- r_model->ponytailId = 0;
- }
- else
- {
- lara = false;
- r_model->ponytailId = -1;
- }
-
- // Animation
- a = moveable[index].animation;
-
- frame_offset = animation[a].frame_offset / 2;
- frame_step = animation[a].frame_size;
-
- int frame_cycle = 0;
-
- if (a >= (int)m_tombraider.NumAnimations())
- {
- a = m_tombraider.NumFrames() - frame_offset;
- }
- else
- {
- a = (animation[a].frame_offset / 2) - frame_offset;
- }
-
- if (frame_step != 0) // prevent divide-by-zero errors
- a /= frame_step;
-
- if (a != 0) // prevent divide-by-zero errors
- frame_offset += frame_step * (frame_cycle % a);
-
- if (a < 0)
- {
- //continue;
- return;
- }
-
- //! \fixme Might be better UID for each model, but this seems to work well
- j = object_id;
-
- // We only want one copy of the skeletal model in memory
- if (cache.Empty() || cache.SearchKey(j) == UINT_MAX)
- {
- sModel->model = r_model;
- gWorld.addEntity(thing);
-
- k = gWorld.addModel(r_model);
-
- cache.Add(j);
- cache2.Add(r_model);
-
- switch (m_tombraider.Engine())
- {
- case TR_VERSION_4:
- if (LARA && moveable[index].object_id == 30)
- {
- r_model->ponytailId = k;
- r_model->ponytailMeshId = moveable[index].starting_mesh;
- r_model->ponytailNumMeshes = ((moveable[index].num_meshes > 0) ?
- moveable[index].num_meshes : 0);
- r_model->ponytailAngle = -90.0f;
- r_model->ponytail[0] = -3;
- r_model->ponytail[1] = -22;
- r_model->ponytail[2] = -20;
- r_model->ponyOff = 40;
- r_model->ponyOff2 = 32;
- r_model->pigtails = false;
-
- // Try to guess pigtails by looking for certian num verts in head
- if (mesh[moveable[0].starting_mesh].num_vertices > 80)
- {
- r_model->pigtails = true;
- r_model->ponyOff -= 20;
- r_model->ponytail[1] -= 32;
- }
-
- m_render.setFlags(Render::fRenderPonytail);
- print(true, "Found known ponytail\n");
- }
- break; // ?
- case TR_VERSION_1:
- case TR_VERSION_2:
- case TR_VERSION_3:
- case TR_VERSION_5:
- case TR_VERSION_UNKNOWN:
- if (LARA && moveable[index].object_id == 2)
- {
- r_model->ponytailId = k;
- r_model->ponytailMeshId = moveable[index].starting_mesh;
- r_model->ponytailNumMeshes = ((moveable[index].num_meshes > 0) ?
- moveable[index].num_meshes : 0);
- r_model->ponytailAngle = -90.0f;
- r_model->ponytail[0] = 0;
- r_model->ponytail[1] = -20;
- r_model->ponytail[2] = -20;
- r_model->ponyOff = 40;
- r_model->ponyOff2 = 0;
-
- m_render.setFlags(Render::fRenderPonytail);
- print(true, "Found ponytail?\n");
- }
- break;
- }
- }
- else
- {
- delete r_model;
-
- c_model = cache2[cache.SearchKey(j)];
- sModel->model = c_model;
- gWorld.addEntity(thing);
- gWorld.addModel(c_model);
- printf("c"); // it's already cached
- fflush(stdout);
-
- //continue;
- return;
- }
-
-
- int aloop = m_tombraider.getNumAnimsForMoveable(index);
-
- #ifdef DEBUG
- if (m_flags & OpenRaider_DebugModel)
- {
- printf("\nanimation = %i, num_animations = %i\n",
- moveable[index].animation, aloop);
- printf("\nitem[%i].flags = %i\nentity[%i]\n",
- i, item[i].flags, thing->id);
- }
- #endif
-
- //a = moveable[index].animation;
- //frame_offset = animation[a].frame_offset / 2;
- //frame_step = animation[a].frame_size;
-
- for (; a < aloop; ++a,
- frame_offset = animation[a].frame_offset / 2,
- frame_step = animation[a].frame_size)
- {
- animation_frame = new animation_frame_t;
- r_model->animation.pushBack(animation_frame);
-
- frame_count = (animation[a].frame_end - animation[a].frame_start) + 1;
- animation_frame->rate = animation[a].frame_rate;
-
- #ifdef DEBUG
- if (m_flags & OpenRaider_DebugModel)
- {
- printf("animation[%i] state and unknowns = %i, %i, %i, %i, %i\n",
- a, animation[a].state_id, animation[a].unknown1,
- animation[a].unknown2, animation[a].unknown3,
- animation[a].unknown4);
- printf("animation[%i].frame_rate = %i\n",
- a, animation[a].frame_rate);
- printf("animation[%i].next_animation = %i\n",
- a, animation[a].next_animation);
- printf("animation[%i].frame_offset = %u\n",
- a, animation[a].frame_offset);
- printf("animation[%i].anim_command = %i\n",
- a, animation[a].anim_command);
- printf("animation[%i].num_anim_commands = %i\n",
- a, animation[a].num_anim_commands);
- printf("animation[%i].state_change_offset = %i\n",
- a, animation[a].state_change_offset);
- printf(" frame_offset = %u\n",
- frame_offset);
- }
- #endif
-
- // Get all the frames for aniamtion
- for (f = 0; f < frame_count; ++f, frame_offset += frame_step)
- {
- // HACK: Lara's ObjectID is 315, but her meshes start at 0, so make a
- // quick substitution (so she doesn't appear as a bunch of thighs)
- if (index == 0 && m_tombraider.Engine() == TR_VERSION_3)
- {
- for (j = 0; j < (int)m_tombraider.NumMoveables() && !index; ++j)
- {
- if (moveable[j].object_id == 315)
- index = j;
- }
- }
-
- // Fix Lara in TR4
- if (index == 0 && m_tombraider.Engine() == TR_VERSION_4)
- {
- for (j = 0; j < (int)m_tombraider.NumMoveables() && !index; ++j)
- {
- // Body is ItemID 8, joints are ItemID 9
- // (TR4 demo: body is ItemID 10, joints are ItemID 11)
- if (moveable[j].object_id == 8)
- index = j;
- }
- }
- else if (moveable[index].object_id == 8 &&
- m_tombraider.Engine() == TR_VERSION_4)
- {
- // KLUDGE to do "skinning"
- index = 0;
-
- for (j = 0; j < (int)m_tombraider.NumMoveables() && !index; ++j)
- {
- // Body is ItemID 8, joints are ItemID 9
- // (TR4 demo: body is ItemID 10, joints are ItemID 11)
- if (moveable[j].object_id == 9)
- index = j;
- }
- }
-
- #ifdef DEBUG
- if (m_flags & OpenRaider_DebugModel)
- {
- printf("animation[%i].boneframe[%u] = offset %u, step %i\n",
- a, f, frame_offset, frame_step);
- }
- #endif
-
- // Mongoose 2002.08.15, Was
- // if (frame_offset + 8 > _tombraider.NumFrames())
- if (frame_offset > m_tombraider.NumFrames())
- {
- print(true, "WARNING: Bad animation frame %i > %i\n",
- frame_offset, m_tombraider.NumFrames());
-
- // Mongoose 2002.08.15, Attempt to skip more likely bad animation data
- print(true, "WARNING: Handling bad animation data...");
- return; //continue;
- }
-
- // Generate bone frames and tags per frame ////////////
- bone = new bone_frame_t;
- animation_frame->frame.pushBack(bone);
-
- // Init translate for bone frame
- bone->pos[0] = (short)frame[frame_offset + 6];
- bone->pos[1] = (short)frame[frame_offset + 7];
- bone->pos[2] = (short)frame[frame_offset + 8];
- bone->yaw = yaw;
-
- //printf("%f %f %f\n", bone->pos[0], bone->pos[1], bone->pos[2]);
-
- l = 9; // First angle offset in this Frame
-
- // Run through the tag and calculate the rotation and offset
- for (j = 0; j < (int)moveable[index].num_meshes; ++j)
- {
- tag = new bone_tag_t;
- bone->tag.pushBack(tag);
- tag->off[0] = 0.0;
- tag->off[1] = 0.0;
- tag->off[2] = 0.0;
- tag->flag = 0x00;
- tag->rot[0] = 0.0;
- tag->rot[1] = 0.0;
- tag->rot[2] = 0.0;
- tag->mesh = moveable[index].starting_mesh + j;
-
-
- // Setup offsets to produce skeletion
- if (j == 0)
- {
- // Since we use bone's offset, these aren't used
- tag->off[0] = 0.0;
- tag->off[1] = 0.0;
- tag->off[2] = 0.0;
-
- // Always push tag[0], this isn't really used either
- tag->flag = 0x02;
- }
- else // Nonprimary tag - position relative to first tag
- {
- int *tree;
- // Hack: moveable[index].mesh_tree is a byte offset
- // into mesh_tree[], so we have to convert to index
- tree = (int *)(void *)meshtree;
- mesh_tree = (tr2_meshtree_t *)&tree[moveable[index].mesh_tree
- + ((j - 1) * 4)];
-
- tag->off[0] = mesh_tree->x;
- tag->off[1] = mesh_tree->y;
- tag->off[2] = mesh_tree->z;
- tag->flag = (char)mesh_tree->flags;
- }
-
- // Setup tag rotations
- m_tombraider.computeRotationAngles(&frame, &frame_offset, &l,
- tag->rot, tag->rot+1, tag->rot+2);
- }
- }
- }
-
- if (i == skyMesh)
- {
- m_render.setSkyMesh(i, //moveable[i].starting_mesh,
- (m_tombraider.Engine() == TR_VERSION_2));
- }
-
- printf(".");
- fflush(stdout);
- }
-
-
- int compareFaceTextureId(const void *voidA, const void *voidB)
- {
- texture_tri_t *a = (texture_tri_t *)voidA, *b = (texture_tri_t *)voidB;
-
-
- if (!a || !b)
- return -1; // error really
-
- // less than
- if (a->texture < b->texture)
- return -1;
-
- // greater than ( no need for equal )
- return 1;
- }
-
-
- void setupTextureColor(texture_tri_t *r_tri, Render *render, float *colorf)
- {
- unsigned char color[4];
- unsigned int colorI;
-
-
- color[0] = (unsigned char)(colorf[0]*255.0f);
- color[1] = (unsigned char)(colorf[1]*255.0f);
- color[2] = (unsigned char)(colorf[2]*255.0f);
- color[3] = (unsigned char)(colorf[3]*255.0f);
-
- ((unsigned char *)(&colorI))[3] = color[0];
- ((unsigned char *)(&colorI))[2] = color[1];
- ((unsigned char *)(&colorI))[1] = color[2];
- ((unsigned char *)(&colorI))[0] = color[3];
-
- if (!gColorTextureHACK.find(colorI))
- {
- gColorTextureHACK.pushBack(colorI);
- r_tri->texture = gTextureOffset + gColorTextureHACK.size();
-
- render->loadTexture(Texture::generateColorTexture(color, 32, 32),
- 32, 32,
- r_tri->texture);
-
- #ifdef DEBUG_COLOR_TEXTURE_GEN
- printf("Color 0x%02x%02x%02x%02x | 0x%08xto texture[%u]?\n",
- color[0], color[1], color[2], color[3], colorI,
- gColorTextureHACK.size());
- #endif
- }
- else
- {
- //printf("Color already loaded %i -> 0x%08x\n",
- // gColorTextureHACK.getCurrentIndex(),
- // gColorTextureHACK.current());
-
- r_tri->texture = gTextureOffset + gColorTextureHACK.getCurrentIndex();
- }
-
- //r_tri->texture = white; // White texture
- }
-
-
- void OpenRaider::processModel(int index)
- {
- int i, j, count, texture;
- int vertexIndices[6];
- float st[12];
- float color[4];
- unsigned short transparency;
- texture_tri_t *r_tri;
-
-
- // Assert common sense
- if (index < 0 || !m_tombraider.isMeshValid(index))
- {
- //! \fixme allow sparse lists with matching ids instead?
- gWorld.addMesh(NULL); // Filler, to make meshes array ids align
- printf("x");
- fflush(stdout);
- return;
- }
-
- #ifndef EXPERIMENTAL
- // WHITE texture id
- int white = 0;
- #endif
-
- model_mesh_t *mesh = new model_mesh_t;
-
- // Mongoose 2002.08.30, Testing support for 'shootable' models ( traceable )
- m_tombraider.getMeshCollisionInfo(index, mesh->center, &mesh->radius);
-
- //! \fixme Arrays don't work either =)
- // Mesh geometery, colors, etc
- m_tombraider.getMeshVertexArrays(index,
- &mesh->vertexCount, &mesh->vertices,
- &mesh->normalCount, &mesh->normals,
- &mesh->colorCount, &mesh->colors);
-
-
- // Textured Triangles
- count = m_tombraider.getMeshTexturedTriangleCount(index);
- mesh->texturedTriangles.reserve(count); // little faster
-
- for (i = 0; i < count; ++i)
- {
- r_tri = new texture_tri_t;
-
- m_tombraider.getMeshTexturedTriangle(index, i,
- r_tri->index,
- r_tri->st,
- &r_tri->texture,
- &r_tri->transparency);
-
- r_tri->texture += m_texOffset;
-
- // Add to face vector
- mesh->texturedTriangles.pushBack(r_tri);
- }
-
-
- // Coloured Triangles
- count = m_tombraider.getMeshColoredTriangleCount(index);
- mesh->coloredTriangles.reserve(count); // little faster
-
- for (i = 0; i < count; i++)
- {
- r_tri = new texture_tri_t;
-
- m_tombraider.getMeshColoredTriangle(index, i,
- r_tri->index,
- color);
- r_tri->st[0] = color[0];
- r_tri->st[1] = color[1];
- r_tri->st[2] = color[2];
- r_tri->st[3] = color[3];
- r_tri->st[4] = 1.0;
- r_tri->st[5] = 1.0;
-
- #ifdef EXPERIMENTAL
- setupTextureColor(r_tri, &m_render, color);
- #else
- r_tri->texture = white; // White texture
- #endif
- r_tri->transparency = 0;
-
- // Add to face vector
- mesh->coloredTriangles.pushBack(r_tri);
- }
-
- // Textured Rectangles
- count = m_tombraider.getMeshTexturedRectangleCount(index);
- mesh->texturedRectangles.reserve(count*2); // little faster
-
- for (i = 0; i < count; ++i)
- {
- m_tombraider.getMeshTexturedRectangle(index, i,
- vertexIndices,
- st,
- &texture,
- &transparency);
-
- r_tri = new texture_tri_t;
-
- for (j = 0; j < 3; ++j)
- r_tri->index[j] = vertexIndices[j];
-
- for (j = 0; j < 6; ++j)
- r_tri->st[j] = st[j];
-
- r_tri->texture = texture + m_texOffset;
- r_tri->transparency = transparency;
-
- // Add to face vector
- mesh->texturedRectangles.pushBack(r_tri);
-
- r_tri = new texture_tri_t;
-
- for (j = 3; j < 6; ++j)
- r_tri->index[j-3] = vertexIndices[j];
-
- for (j = 6; j < 12; ++j)
- r_tri->st[j-6] = st[j];
-
- r_tri->texture = texture + m_texOffset;
- r_tri->transparency = transparency;
-
- // Add to face vector
- mesh->texturedRectangles.pushBack(r_tri);
- }
-
-
- // Coloured Rectangles
- count = m_tombraider.getMeshColoredRectangleCount(index);
- mesh->coloredRectangles.reserve(count*2); // little faster
-
- for (i = 0; i < count; ++i)
- {
- m_tombraider.getMeshColoredRectangle(index, i,
- vertexIndices,
- color);
-
- r_tri = new texture_tri_t;
-
- for (j = 0; j < 3; ++j)
- r_tri->index[j] = vertexIndices[j];
-
- //for (j = 0; j < 6; ++j)
- // r_tri->st[j] = st[j];
-
- r_tri->st[0] = color[0];
- r_tri->st[1] = color[1];
- r_tri->st[2] = color[2];
- r_tri->st[3] = color[3];
- r_tri->st[4] = 1.0;
- r_tri->st[5] = 1.0;
-
- #ifdef EXPERIMENTAL
- //for (j = 6; j < 12; ++j)
- // r_tri->st[j-6] = st[j];
- setupTextureColor(r_tri, &m_render, color);
- #else
- r_tri->texture = white; // White texture
- #endif
- r_tri->transparency = 0;
-
- // Add to face vector
- mesh->coloredRectangles.pushBack(r_tri);
-
- r_tri = new texture_tri_t;
-
- for (j = 3; j < 6; ++j)
- r_tri->index[j-3] = vertexIndices[j];
-
- //for (j = 6; j < 12; ++j)
- // r_tri->st[j-6] = st[j];
-
- r_tri->st[0] = color[0];
- r_tri->st[1] = color[1];
- r_tri->st[2] = color[2];
- r_tri->st[3] = color[3];
- r_tri->st[4] = 1.0;
- r_tri->st[5] = 1.0;
-
- #ifdef EXPERIMENTAL
- setupTextureColor(r_tri, &m_render, color);
- #else
- r_tri->texture = white; // White texture
- #endif
- r_tri->transparency = 0;
-
- // Add to face vector
- mesh->coloredRectangles.pushBack(r_tri);
- }
-
- // Sort faces by texture
- mesh->texturedTriangles.qSort(compareFaceTextureId);
- mesh->coloredTriangles.qSort(compareFaceTextureId);
- mesh->texturedRectangles.qSort(compareFaceTextureId);
- mesh->coloredRectangles.qSort(compareFaceTextureId);
-
- gWorld.addMesh(mesh);
- printf(".");
- fflush(stdout);
- }
-
-
- #define MATRIX_TRANSFORMS
- void OpenRaider::processRoom(int index)
- {
- unsigned int i, j, count;
- room_mesh_t *r_mesh = NULL;
- RenderRoom *rRoom = NULL;
- #ifdef MATRIX_TRANSFORMS
- Matrix transform;
- #endif
-
-
- if (!m_tombraider.isRoomValid(index))
- {
- openraider_error("OpenRaider::RoomSetup", "Invalid room index",
- __FILE__, __LINE__);
-
- print(false, "WARNING: Handling invalid vertex array in room");
- gWorld.addRoom(0x0);
- m_render.addRoom(0x0);
-
- printf("x");
- fflush(stdout);
- return;
- }
-
- rRoom = new RenderRoom();
- r_mesh = new room_mesh_t;
- r_mesh->id = index;
-
- m_tombraider.getRoomInfo(index, &r_mesh->flags, r_mesh->pos,
- r_mesh->bbox_min, r_mesh->bbox_max);
-
- // Adjust positioning for OR world coord translation
- r_mesh->bbox_min[0] += r_mesh->pos[0];
- r_mesh->bbox_max[0] += r_mesh->pos[0];
- r_mesh->bbox_min[2] += r_mesh->pos[2];
- r_mesh->bbox_max[2] += r_mesh->pos[2];
-
- // Mongoose 2002.04.03, Setup 3d transform
- #ifdef MATRIX_TRANSFORMS
- transform.setIdentity();
- transform.translate(r_mesh->pos);
- #endif
-
- // Setup portals
- float portalVertices[12];
- count = m_tombraider.getRoomPortalCount(index);
-
- //! \fixme OR wrongly uses a cached adj room list for rendering vis
- r_mesh->adjacentRooms.reserve(count + 1);
- r_mesh->adjacentRooms.setError(-1);
-
- // Current room is always first
- r_mesh->adjacentRooms.pushBack(index);
-
- for (i = 0; i < count; ++i)
- {
- portal_t *portal = new portal_t;
-
- m_tombraider.getRoomPortal(index, i,
- &portal->adjoining_room, portal->normal,
- portalVertices);
-
- for (j = 0; j < 4; ++j)
- {
- portal->vertices[j][0] = portalVertices[j*3];
- portal->vertices[j][1] = portalVertices[j*3+1];
- portal->vertices[j][2] = portalVertices[j*3+2];
-
- // Relative coors in vis portals
- #ifdef MATRIX_TRANSFORMS
- transform.multiply3v(portal->vertices[j], portal->vertices[j]);
- #else
- portal->vertices[j][0] += r_mesh->pos[0];
- portal->vertices[j][1] += r_mesh->pos[1];
- portal->vertices[j][2] += r_mesh->pos[2];
- #endif
- }
-
- r_mesh->adjacentRooms.pushBack(portal->adjoining_room);
- r_mesh->portals.pushBack(portal);
- }
-
- // Physics/gameplay use /////////////////////////////
-
- //! \fixme Use more of sector structure, boxes, and floordata
-
- // List of sectors in this room
- unsigned int sectorFlags;
- int floorDataIndex, boxIndex, roomBelow, roomAbove;
- count = m_tombraider.getRoomSectorCount(index, &r_mesh->numZSectors,
- &r_mesh->numXSectors);
- r_mesh->sectors.reserve(count);
- r_mesh->sectors.setError(0x0);
-
- for (i = 0; i < count; ++i)
- {
- sector_t *sector = new sector_t;
-
- m_tombraider.getRoomSector(index, i, §orFlags,
- §or->ceiling, §or->floor,
- &floorDataIndex, &boxIndex, &roomBelow,
- &roomAbove);
-
- if (sectorFlags & tombraiderSector_wall)
- {
- sector->wall = true;
- }
- else
- {
- sector->wall = false;
- }
-
- r_mesh->sectors.pushBack(sector);
- }
-
- // Setup collision boxes ( Should use sectors, but this is a test )
- count = m_tombraider.getRoomBoxCount(index);
- r_mesh->boxes.reserve(count);
- r_mesh->boxes.setError(0x0);
-
- //! fixme Only to be done only on room[0]? I don't think so...
- for (i = 0; !index && i < count; ++i)
- {
- box_t *box = new box_t;
-
- m_tombraider.getRoomBox(index, i,
- box->a.pos, box->b.pos, box->c.pos, box->d.pos);
-
- r_mesh->boxes.pushBack(box);
- }
-
-
- // Setup room lights /////////////////////////////////////
- unsigned int lightFlags, lightType;
- count = m_tombraider.getRoomLightCount(index);
- rRoom->lights.reserve(count);
- rRoom->lights.setError(0x0);
-
- for (i = 0; i < count; ++i)
- {
- Light *light = new Light();
-
- m_tombraider.getRoomLight(index, i,
- light->mPos, light->mColor, light->mDir,
- &light->mAtt, &light->mCutoff,
- &lightType, &lightFlags);
-
- switch (lightType)
- {
- case tombraiderLight_typeDirectional:
- light->mType = Light::typeDirectional;
- break;
- case tombraiderLight_typeSpot:
- light->mType = Light::typeSpot;
- break;
- case tombraiderLight_typePoint:
- default:
- light->mType = Light::typePoint;
- }
-
- rRoom->lights.pushBack(light);
- }
-
-
- // Room geometery //////////////////////////////////
-
- //#define EXPERIMENTAL_UNFIFIED_ROOM_GEOMETERY
- #ifdef EXPERIMENTAL_UNFIFIED_ROOM_GEOMETERY
- unsigned int vertexCount, normalCount, colorCount, triCount;
- vec_t *vertexArray;
- vec_t *normalArray;
- vec_t *colorArray;
- unsigned int *indices, *flags;
- float *texCoords;
- int *textures;
-
-
- m_tombraider.getRoomVertexArrays(index,
- &vertexCount, &vertexArray,
- &normalCount, &normalArray,
- &colorCount, &colorArray);
-
- rRoom->mesh.bufferVertexArray(vertexCount, (vec_t *)vertexArray);
- rRoom->mesh.bufferNormalArray(normalCount, (vec_t *)normalArray);
- rRoom->mesh.bufferColorArray(vertexCount, (vec_t *)colorArray);
-
- m_tombraider.getRoomTriangles(index, m_texOffset,
- &triCount, &indices, &texCoords, &textures,
- &flags);
-
- rRoom->mesh.bufferTriangles(triCount, indices, texCoords, textures, flags);
- #else
- float rgba[4];
- float xyz[3];
-
- count = m_tombraider.getRoomVertexCount(index);
- rRoom->mesh.allocateVertices(count);
- rRoom->mesh.allocateNormals(0); // count
- rRoom->mesh.allocateColors(count);
-
- for (i = 0; i < count; ++i)
- {
- m_tombraider.getRoomVertex(index, i, xyz, rgba);
-
- rRoom->mesh.setVertex(i, xyz[0], xyz[1], xyz[2]);
- rRoom->mesh.setColor(i, rgba);
- }
-
- // Mongoose 2002.06.09, Setup allocation of meshes and polygons
- // Counters ( Textured polygon lists are allocated per texture)
- // ( Textures are mapped to these meshes )
- int triangle_counter[TextureLimit];
- int triangle_counter_alpha[TextureLimit];
- int rectangle_counter[TextureLimit];
- int rectangle_counter_alpha[TextureLimit];
- int tris_mesh_map[TextureLimit];
- int rect_mesh_map[TextureLimit];
-
-
- for (i = 0; i < TextureLimit; ++i)
- {
- triangle_counter[i] = 0;
- triangle_counter_alpha[i] = 0;
- rectangle_counter[i] = 0;
- rectangle_counter_alpha[i] = 0;
-
- tris_mesh_map[i] = -1;
- rect_mesh_map[i] = -1;
- }
-
- unsigned int numTris = 0;
- unsigned int numQuads = 0;
-
- int texture;
- unsigned int r, t, q, v, flags;
- unsigned int indices[4];
- float texCoords[8];
-
- count = m_tombraider.getRoomTriangleCount(index);
-
- // Mongoose 2002.08.15, Presort by alpha and texture and setup mapping
- for (t = 0; t < count; ++t)
- {
- m_tombraider.getRoomTriangle(index, t,
- indices, texCoords, &texture, &flags);
-
- texture += m_texOffset;
-
- if (texture > (int)TextureLimit)
- {
- print(true, "Handling bad room[%i].tris[%i].texture = %i",
- index, t, texture);
- texture = TextureLimit - 1;
- }
-
- // Counters set up polygon allocation
- if (flags & tombraiderFace_Alpha ||
- flags & tombraiderFace_PartialAlpha)
- {
- triangle_counter_alpha[texture] += 1;
- }
- else
- {
- triangle_counter[texture] += 1;
- }
-
- // Counter sets up texture id to mesh id mapping
- if (tris_mesh_map[texture] == -1)
- {
- tris_mesh_map[texture] = ++numTris;
- }
- }
-
- count = m_tombraider.getRoomRectangleCount(index);
-
- for (r = 0; r < count; ++r)
- {
- m_tombraider.getRoomRectangle(index, r,
- indices, texCoords, &texture, &flags);
-
- texture += m_texOffset;
-
- if (texture > (int)TextureLimit)
- {
- print(true, "Handling bad room[%i].quad[%i].texture = %i",
- index, r, texture);
- texture = TextureLimit - 1;
- }
-
- if (flags & tombraiderFace_Alpha ||
- flags & tombraiderFace_PartialAlpha)
- {
- rectangle_counter_alpha[texture] += 1;
- }
- else
- {
- rectangle_counter[texture] += 1;
- }
-
- if (rect_mesh_map[texture] == -1)
- {
- rect_mesh_map[texture] = ++numQuads;
- }
- }
-
- // Allocate indexed polygon meshes
- rRoom->mesh.allocateTriangles(numTris);
- rRoom->mesh.allocateRectangles(numQuads);
-
- for (i = 0, j = 0; i < TextureLimit; ++i)
- {
- if (tris_mesh_map[i] > 0)
- {
- j = tris_mesh_map[i] - 1;
-
- t = triangle_counter[i];
-
- rRoom->mesh.mTris[j].texture = i;
- #ifdef MULTITEXTURE
- rRoom->mesh.mTris[j].bumpmap = gMapTex2Bump[i];
- #endif
- rRoom->mesh.mTris[j].cnum_triangles = 0;
- rRoom->mesh.mTris[j].num_triangles = 0;
- rRoom->mesh.mTris[j].cnum_alpha_triangles = 0;
- rRoom->mesh.mTris[j].num_alpha_triangles = 0;
- rRoom->mesh.mTris[j].triangles = 0x0;
- rRoom->mesh.mTris[j].alpha_triangles = 0x0;
- rRoom->mesh.mTris[j].texcoors = 0x0;
- rRoom->mesh.mTris[j].texcoors2 = 0x0;
-
- if (t > 0)
- {
- rRoom->mesh.mTris[j].num_triangles = t;
- rRoom->mesh.mTris[j].triangles = new unsigned int[t*3];
- rRoom->mesh.mTris[j].num_texcoors = t * 3;
- rRoom->mesh.mTris[j].texcoors = new vec2_t[t * 3];
- }
-
- t = triangle_counter_alpha[i];
-
- if (t > 0)
- {
- rRoom->mesh.mTris[j].num_alpha_triangles = t;
- rRoom->mesh.mTris[j].alpha_triangles = new unsigned int[t*3];
- rRoom->mesh.mTris[j].num_texcoors2 = t * 3;
- rRoom->mesh.mTris[j].texcoors2 = new vec2_t[t * 3];
- }
- }
-
- ///////////////////////////////////////////
-
- if (rect_mesh_map[i] > 0)
- {
- j = rect_mesh_map[i] - 1;
-
- r = rectangle_counter[i];
-
- rRoom->mesh.mQuads[j].texture = i;
- #ifdef MULTITEXTURE
- rRoom->mesh.mQuads[j].bumpmap = gMapTex2Bump[i];
- #endif
- rRoom->mesh.mQuads[j].cnum_quads = 0;
- rRoom->mesh.mQuads[j].num_quads = 0;
- rRoom->mesh.mQuads[j].cnum_alpha_quads = 0;
- rRoom->mesh.mQuads[j].num_alpha_quads = 0;
- rRoom->mesh.mQuads[j].quads = 0x0;
- rRoom->mesh.mQuads[j].alpha_quads = 0x0;
- rRoom->mesh.mQuads[j].texcoors = 0x0;
- rRoom->mesh.mQuads[j].texcoors2 = 0x0;
-
- if (r > 0)
- {
- rRoom->mesh.mQuads[j].num_quads = r;
- rRoom->mesh.mQuads[j].quads = new unsigned int[r*4];
- rRoom->mesh.mQuads[j].num_texcoors = r * 4;
- rRoom->mesh.mQuads[j].texcoors = new vec2_t[r * 4];
- }
-
- r = rectangle_counter_alpha[i];
-
- if (r > 0)
- {
- rRoom->mesh.mQuads[j].num_alpha_quads = r;
- rRoom->mesh.mQuads[j].alpha_quads = new unsigned int[r*4];
- rRoom->mesh.mQuads[j].num_texcoors2 = r * 4;
- rRoom->mesh.mQuads[j].texcoors2 = new vec2_t[r * 4];
- }
- }
- }
-
- // Generate textured triangles
- count = m_tombraider.getRoomTriangleCount(index);
-
- for (t = 0; t < count; ++t)
- {
- m_tombraider.getRoomTriangle(index, t,
- indices, texCoords, &texture, &flags);
-
- // Adjust texture id using m_texOffset to map into
- // correct textures
- texture += m_texOffset;
-
- j = tris_mesh_map[texture] - 1;
-
- // Setup per vertex
- for (i = 0; i < 3; ++i)
- {
- // Get vertex index {(0, a), (1, b), (2, c)}
- v = indices[i];
-
- if ((flags & tombraiderFace_Alpha ||
- flags & tombraiderFace_PartialAlpha) &&
- rRoom->mesh.mTris[j].num_alpha_triangles > 0)
- {
- q = rRoom->mesh.mTris[j].cnum_alpha_triangles*3+i;
-
- rRoom->mesh.mTris[j].alpha_triangles[q] = v;
-
- rRoom->mesh.mTris[j].texcoors2[q][0] = texCoords[i*2];
- rRoom->mesh.mTris[j].texcoors2[q][1] = texCoords[i*2+1];
- }
- else if (rRoom->mesh.mTris[j].num_triangles > 0)
- {
- q = rRoom->mesh.mTris[j].cnum_triangles*3+i;
-
- rRoom->mesh.mTris[j].triangles[q] = v;
-
- rRoom->mesh.mTris[j].texcoors[q][0] = texCoords[i*2];
- rRoom->mesh.mTris[j].texcoors[q][1] = texCoords[i*2+1];
- }
-
- // Partial alpha hack
- if (flags & tombraiderFace_PartialAlpha)
- {
- //rRoom->mesh.colors[v].rgba[3] = 0.45;
- }
- }
-
- if (flags & tombraiderFace_Alpha ||
- flags & tombraiderFace_PartialAlpha)
- {
- rRoom->mesh.mTris[j].cnum_alpha_triangles++;
- }
- else
- {
- rRoom->mesh.mTris[j].cnum_triangles++;
- }
- }
-
-
- // Generate textured quads
- count = m_tombraider.getRoomRectangleCount(index);
-
- for (r = 0; r < count; ++r)
- {
- m_tombraider.getRoomRectangle(index, r,
- indices, texCoords, &texture, &flags);
-
- // Adjust texture id using m_texOffset to map into
- // correct textures
- texture += m_texOffset;
-
- if (texture > (int)TextureLimit)
- {
- texture = TextureLimit - 1;
- }
-
- j = rect_mesh_map[texture] - 1;
-
- if (rRoom->mesh.mQuads[j].num_quads <= 0 &&
- rRoom->mesh.mQuads[j].num_alpha_quads <= 0)
- continue;
-
- // Setup per vertex
- for (i = 0; i < 4; ++i)
- {
- // Get vertex index {(0, a), (1, b), (2, c), (3, d)}
- v = indices[i];
-
- if ((flags & tombraiderFace_Alpha ||
- flags & tombraiderFace_PartialAlpha) &&
- rRoom->mesh.mQuads[j].num_alpha_quads > 0)
- {
- q = rRoom->mesh.mQuads[j].cnum_alpha_quads*4+i;
-
- rRoom->mesh.mQuads[j].alpha_quads[q] = v;
-
- rRoom->mesh.mQuads[j].texcoors2[q][0] = texCoords[i*2];
- rRoom->mesh.mQuads[j].texcoors2[q][1] = texCoords[i*2+1];
- }
- else if (rRoom->mesh.mQuads[j].num_quads > 0)
- {
- q = rRoom->mesh.mQuads[j].cnum_quads*4+i;
-
- rRoom->mesh.mQuads[j].quads[q] = v;
-
- rRoom->mesh.mQuads[j].texcoors[q][0] = texCoords[i*2];
- rRoom->mesh.mQuads[j].texcoors[q][1] = texCoords[i*2+1];
- }
-
- // Partial alpha hack
- if (flags & tombraiderFace_PartialAlpha)
- {
- //rRoom->mesh.colors[v].rgba[3] = 0.45;
- }
- }
-
- if (flags & tombraiderFace_Alpha ||
- flags & tombraiderFace_PartialAlpha)
- {
- rRoom->mesh.mQuads[j].cnum_alpha_quads++;
- }
- else
- {
- rRoom->mesh.mQuads[j].cnum_quads++;
- }
- }
- #endif
-
- // Room models
- count = m_tombraider.getRoomModelCount(index);
- r_mesh->models.reserve(count);
- r_mesh->models.setError(0x0);
-
- for (i = 0; i < count; ++i)
- {
- static_model_t *model = new static_model_t;
-
- m_tombraider.getRoomModel(index, i,
- &model->index, model->pos, &model->yaw);
-
- r_mesh->models.pushBack(model);
- }
-
- // Room sprites
- float spriteVertices[12];
- float spriteTexCoords[8];
- count = m_tombraider.getRoomSpriteCount(index);
- r_mesh->sprites.reserve(count);
- r_mesh->sprites.setError(0x0);
-
- for (i = 0; i < count; ++i)
- {
- sprite_t *sprite = new sprite_t;
-
- m_tombraider.getRoomSprite(index, i,
- 10.0f, &sprite->texture, sprite->pos,
- spriteVertices, spriteTexCoords);
-
- sprite->texture += m_texOffset; // OpenRaider preloads some textures
-
- sprite->vertex[0].pos[0] = spriteVertices[0];
- sprite->vertex[0].pos[1] = spriteVertices[1];
- sprite->vertex[0].pos[2] = spriteVertices[2];
- sprite->vertex[1].pos[0] = spriteVertices[3];
- sprite->vertex[1].pos[1] = spriteVertices[4];
- sprite->vertex[1].pos[2] = spriteVertices[5];
- sprite->vertex[2].pos[0] = spriteVertices[6];
- sprite->vertex[2].pos[1] = spriteVertices[7];
- sprite->vertex[2].pos[2] = spriteVertices[8];
- sprite->vertex[3].pos[0] = spriteVertices[9];
- sprite->vertex[3].pos[1] = spriteVertices[10];
- sprite->vertex[3].pos[2] = spriteVertices[11];
-
- sprite->texel[0].st[0] = spriteTexCoords[0];
- sprite->texel[0].st[1] = spriteTexCoords[1];
- sprite->texel[1].st[0] = spriteTexCoords[2];
- sprite->texel[1].st[1] = spriteTexCoords[3];
- sprite->texel[2].st[0] = spriteTexCoords[4];
- sprite->texel[2].st[1] = spriteTexCoords[5];
- sprite->texel[3].st[0] = spriteTexCoords[6];
- sprite->texel[3].st[1] = spriteTexCoords[7];
-
- r_mesh->sprites.pushBack(sprite);
- }
-
- gWorld.addRoom(r_mesh);
-
- rRoom->room = r_mesh;
- m_render.addRoom(rRoom);
-
- printf(".");
- fflush(stdout);
- }
-
- //! \fixme Use rc_get_bool consistently!
- void OpenRaider::consoleCommand(char *cmd)
- {
- if (!cmd || !cmd[0])
- return;
-
- // Mongoose 2003.05.31, Strip off decp console prefix
- if (cmd[0] == '>')
- {
- rc_command(">", cmd);
- }
-
- if (rc_command("quit", cmd))
- {
- shutdown(0);
- }
- else if (rc_command("port", cmd))
- {
- Network &net = *Network::Instance();
- net.setPort(atoi(cmd));
- }
- else if (rc_command("killserver", cmd))
- {
- Network &net = *Network::Instance();
-
-
- print(true, "Stopping network server...");
- net.killServerThread();
- }
- else if (rc_command("server", cmd))
- {
- Network &net = *Network::Instance();
-
-
- print(true, "Starting network server...");
- net.spawnServerThread();
- }
- else if (rc_command("disconnect", cmd))
- {
- Network &net = *Network::Instance();
-
-
- print(true, "Diconnecting...");
- net.killClientThread();
- }
- else if (rc_command("connect", cmd))
- {
- Network &net = *Network::Instance();
-
-
- print(true, "Connecting to %s...", cmd);
-
- net.setRemoteHost(cmd);
- net.spawnClientThread();
- }
- else if (rc_command("fly", cmd))
- {
- if (LARA)
- {
- LARA->moveType = worldMoveType_fly;
- }
-
- print(false, "World clipping is [SPACEY]");
- }
- else if (rc_command("walk", cmd))
- {
- if (LARA)
- {
- LARA->moveType = worldMoveType_walk;
- }
-
- print(false, "World clipping is [ON]");
- }
- else if (rc_command("ghost", cmd))
- {
- if (LARA)
- {
- LARA->moveType = worldMoveType_noClipping;
- }
-
- print(false, "World clipping is [OFF]");
- }
- else if (rc_command("loadlevel", cmd))
- {
- loadLevel(cmd);
- }
- else if (rc_command("play", cmd))
- {
- if (m_flags & OpenRaider_EnableSound)
- {
- mSound.play(atoi(cmd));
- }
- }
- else if (rc_command("sensitivity.x", cmd))
- {
- m_mouseX = static_cast<float>(atof(cmd));
- }
- else if (rc_command("sensitivity.y", cmd))
- {
- m_mouseY = static_cast<float>(atof(cmd));
- }
- else if (rc_command("r_pigtails", cmd))
- {
- if (gLaraModel)
- {
- gLaraModel->pigtails = atoi(cmd);
-
- if (gLaraModel->pigtails)
- {
- gLaraModel->ponyOff -= 20;
- gLaraModel->ponytail[1] -= 32;
- }
- else
- {
- gLaraModel->ponyOff += 20;
- gLaraModel->ponytail[1] += 32;
- }
- }
- }
- else if (rc_command("r_ponyangle", cmd))
- {
- if (gLaraModel)
- {
- gLaraModel->ponytailAngle = atoi(cmd);
- }
- }
- else if (rc_command("r_ponyx", cmd))
- {
- if (gLaraModel)
- {
- gLaraModel->ponytail[0] = atoi(cmd);
- }
- }
- else if (rc_command("r_ponyy", cmd))
- {
- if (gLaraModel)
- {
- gLaraModel->ponytail[1] = atoi(cmd);
- }
- }
- else if (rc_command("r_ponyz", cmd))
- {
- if (gLaraModel)
- {
- gLaraModel->ponytail[2] = atoi(cmd);
- }
- }
- else if (rc_command("r_animate", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fAnimateAllModels);
- print(false, "Animating all models");
- }
- else
- {
- m_render.clearFlags(Render::fAnimateAllModels);
- print(false, "No longer animating all models");
- }
- }
- else if (rc_command("r_ponytail", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fRenderPonytail);
- print(false, "Rendering ponytail");
- }
- else
- {
- m_render.clearFlags(Render::fRenderPonytail);
- print(false, "No longer rendering ponytail");
- }
- }
- else if (rc_command("r_light", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fGL_Lights);
- }
- else
- {
- m_render.clearFlags(Render::fGL_Lights);
- }
- }
- else if (rc_command("hop", cmd))
- {
- if (atoi(cmd))
- {
- gWorld.setFlag(World::fEnableHopping);
- print(true, "Room hopping is on");
- }
- else
- {
- gWorld.clearFlag(World::fEnableHopping);
- print(true, "Room hopping is off");
- }
- }
- else if (rc_command("r_fog", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fFog);
- }
- else
- {
- m_render.clearFlags(Render::fFog);
- }
- }
- else if (rc_command("wireframe", cmd))
- {
- m_render.setMode(Render::modeWireframe);
- print(false, "wireframe mode");
- }
- else if (rc_command("solid", cmd))
- {
- m_render.setMode(Render::modeSolid);
- print(false, "solid mode");
- }
- else if (rc_command("texture", cmd))
- {
- m_render.setMode(Render::modeTexture);
- print(false, "texture mode");
- }
- else if (rc_command("vertexlight", cmd))
- {
- m_render.setMode(Render::modeVertexLight);
- print(false, "vertexlight mode");
- }
- else if (rc_command("titlescreen", cmd))
- {
- m_render.setMode(Render::modeLoadScreen);
- print(false, "titlescreen mode");
- }
- else if (rc_command("r_viewmodel", cmd))
- {
- if (LARA)
- {
- SkeletalModel *smdl = static_cast<SkeletalModel *>(LARA->tmpHook);
- skeletal_model_t *mdl = gWorld.getModel(atoi(cmd));
-
- if (smdl)
- {
- smdl->setModel(mdl);
- }
- }
-
- //m_render.ViewModel(LARA, atoi(cmd));
- }
- else if (rc_command("r_oneroom", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fOneRoom);
- }
- else
- {
- m_render.clearFlags(Render::fOneRoom);
- }
- }
- else if (rc_command("r_allrooms", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fAllRooms);
- }
- else
- {
- m_render.clearFlags(Render::fAllRooms);
- }
-
- print(true, "Rendering all rooms [%s]", (atoi(cmd) == 0) ? "off" : "on");
- }
- else if (rc_command("r_sprite", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fSprites);
- }
- else
- {
- m_render.clearFlags(Render::fSprites);
- }
- }
- else if (rc_command("r_roommodel", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fRoomModels);
- }
- else
- {
- m_render.clearFlags(Render::fRoomModels);
- }
- }
- else if (rc_command("r_entmodel", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fEntityModels);
- }
- else
- {
- m_render.clearFlags(Render::fEntityModels);
- }
- }
- else if (rc_command("r_particle", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fParticles);
- }
- else
- {
- m_render.clearFlags(Render::fParticles);
- }
- }
- else if (rc_command("r_vis", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fUsePortals);
- }
- else
- {
- m_render.clearFlags(Render::fUsePortals);
- }
- }
- else if (rc_command("r_upf", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fUpdateRoomListPerFrame);
- }
- else
- {
- m_render.clearFlags(Render::fUpdateRoomListPerFrame);
- }
- }
- else if (rc_command("r_portal", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fPortals);
- }
- else
- {
- m_render.clearFlags(Render::fPortals);
- }
- }
- else if (rc_command("r_vmodel", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fViewModel);
- }
- else
- {
- m_render.clearFlags(Render::fViewModel);
- }
- }
- else if (rc_command("r_ralpha", cmd))
- {
- if (atoi(cmd))
- {
- m_render.setFlags(Render::fRoomAlpha);
- }
- else
- {
- m_render.clearFlags(Render::fRoomAlpha);
- }
- }
- else if (rc_command("resize", cmd))
- {
- if (rc_command("xga", cmd))
- {
- resize(1024, 768);
- m_render.Update(1024, 768);
- }
- else if (rc_command("svga", cmd))
- {
- resize(800, 600);
- m_render.Update(800, 600);
- }
- else if (rc_command("vga", cmd))
- {
- resize(640, 460);
- m_render.Update(640, 460);
- }
- }
- else if (rc_command("sshot", cmd))
- {
- char *tmp = fullPath("~/.OpenRaider/sshots/", '/');
- char *sfilename = bufferString("%s%s", tmp, VERSION);
- m_render.screenShot(sfilename);
- delete [] tmp;
- delete [] sfilename;
- print(false, "Took screenshot");
- }
- else if (rc_command("fullscreen", cmd))
- {
- toggleFullscreen();
- }
- else if (rc_command("showfps", cmd))
- {
- m_flags |= OpenRaider_ShowFPS;
-
- if (!atoi(cmd))
- {
- m_flags ^= OpenRaider_ShowFPS;
- }
- }
- else if (rc_command("bind", cmd))
- {
- if (rc_command("+forward", cmd))
- {
- bindKeyCommand("+forward", atoi(cmd), OpenRaiderKey_forward);
- }
- else if (rc_command("+console", cmd))
- {
- bindKeyCommand("+console", atoi(cmd), OpenRaiderKey_console);
- }
- else if (rc_command("+backward", cmd))
- {
- bindKeyCommand("+backward", atoi(cmd), OpenRaiderKey_backward);
- }
- else if (rc_command("+jump", cmd))
- {
- bindKeyCommand("+jump", atoi(cmd), OpenRaiderKey_jump);
- }
- else if (rc_command("+crouch", cmd))
- {
- bindKeyCommand("+crouch", atoi(cmd), OpenRaiderKey_crouch);
- }
- else if (rc_command("+right", cmd))
- {
- bindKeyCommand("+right", atoi(cmd), OpenRaiderKey_right);
- }
- else if (rc_command("+left", cmd))
- {
- bindKeyCommand("+left", atoi(cmd), OpenRaiderKey_left);
- }
- else if (rc_command("+attack", cmd))
- {
- bindKeyCommand("+attack", atoi(cmd), OpenRaiderKey_attack);
- }
- }
- else if (rc_command("set", cmd))
- {
- if (rc_command("mousegrab", cmd))
- {
- setGrabMouse(atoi(cmd));
- print(true, "Mouse grabbing [%s]", atoi(cmd) ? "on" : "off");
- }
- }
- else if (rc_command("stat", cmd))
- {
- if (rc_command("fps", cmd))
- {
- m_flags ^= OpenRaider_ShowFPS;
- }
- else if (rc_command("pos", cmd))
- {
- if (LARA)
- {
- print(true, "Room %2i Pos %.0f %.0f %.0f Yaw %.0f Pitch %.0f",
- LARA->room,
- LARA->pos[0], LARA->pos[1], LARA->pos[2],
- HEL_RAD_TO_DEG(LARA->angles[1]),
- HEL_RAD_TO_DEG(LARA->angles[2]));
- }
- }
- else if (rc_command("room", cmd))
- {
- if (rc_command("flags", cmd))
- {
- if (LARA)
- {
- print(true, "Room[%i] flags: 0x%x",
- LARA->room,
- gWorld.getRoomInfo(LARA->room));
- }
- }
- }
- }
- }
-
-
- void OpenRaider::loadPakFolderRecursive(const char *dir) {
- struct dirent *ep;
- DIR *pakDir;
-
- pakDir = opendir(dir);
- if (pakDir != NULL) {
- while ((ep = readdir(pakDir)) != NULL) {
- if (ep->d_type == DT_DIR) {
- if ((strcmp(".", ep->d_name) != 0)
- && (strcmp("..", ep->d_name) != 0)) {
- char *tmp = bufferString("%s%s", dir, ep->d_name);
- char *next = fullPath(tmp, '/');
- loadPakFolderRecursive(next);
- delete next;
- delete tmp;
- }
- } else {
- char *fullPathMap = bufferString("%s%s", dir, ep->d_name);
-
- char *lowerPath = bufferString("%s", fullPathMap);
- for (char *p = lowerPath; *p; ++p) *p = (char)tolower(*p);
-
- // Check for valid extension
- if (stringEndsWith(lowerPath, ".phd")
- || stringEndsWith(lowerPath, ".tr2")
- || stringEndsWith(lowerPath, ".tr4")
- || stringEndsWith(lowerPath, ".trc")) {
- if (m_tombraider.checkMime(fullPathMap) == 0) {
- // printf("Validated pak: '%s'\n", fullPathMap);
-
- // Just load relative filename
- mMapList.pushBack(bufferString("%s", (fullPathMap + strlen(m_pakDir))));
- } else {
- printf("ERROR: pak file '%s' not found or invalid\n", fullPathMap);
-
- delete [] fullPathMap;
- }
- }
-
- delete [] lowerPath;
- }
- }
- closedir(pakDir);
- } else {
- printf("Could not open PAK dir %s!\n", dir);
- }
- }
-
-
- void OpenRaider::handleCommand(char *cmd, unsigned int mode)
- {
- bool b;
- int i;
-
-
- // So we can use switch stmt, translate the Ids
- mode = mMode[mode];
-
- switch (mode)
- {
- case 0: // [Video.OpenGL]
- if (rc_command("Width", cmd))
- {
- m_width = atoi(cmd);
- }
- else if (rc_command("Height", cmd))
- {
- m_height = atoi(cmd);
- }
- else if (rc_command("FullScreen", cmd))
- {
- rc_get_bool(cmd, &b);
-
- m_flags |= OpenRaider_FullScreen;
-
- if (!b)
- {
- m_flags ^= OpenRaider_FullScreen;
- }
- }
- else if (rc_command("Font", cmd))
- {
- gFontFilename = fullPath(cmd, 0);
- }
- else if (rc_command("Driver", cmd))
- {
- if (cmd[0])
- {
- setDriverGL(cmd);
- }
- }
- else
- {
- printf("Command> [Video.OpenGL] Unknown command '%s'\n", cmd);
- }
- break;
- case 1: // [Audio.OpenAL]
- if (rc_command("Enable", cmd))
- {
- rc_get_bool(cmd, &b);
-
- m_flags |= OpenRaider_EnableSound;
-
- if (!b)
- {
- m_flags ^= OpenRaider_EnableSound;
- }
- }
- else
- {
- printf("Command> [Audio.OpenAL] Unknown command '%s'\n", cmd);
- }
- break;
- case 2: // [OpenRaider.Engine]
- if (rc_command("PakDir", cmd))
- {
- if (m_pakDir)
- {
- delete [] m_pakDir;
- }
-
- m_pakDir = fullPath(cmd, '/');
-
- // Recursively search for level paks instead of
- // naming individual levels 2014-02-21 xythobuz
-
- loadPakFolderRecursive(m_pakDir);
- }
- else if (rc_command("HomeDir", cmd))
- {
- if (m_homeDir)
- {
- delete [] m_homeDir;
- }
-
- i = strlen(cmd);
-
- m_homeDir = fullPath(cmd, '/');
- }
- else if (rc_command("AudioDir", cmd))
- {
- if (m_audioDir)
- {
- delete [] m_audioDir;
- }
-
- m_audioDir = fullPath(cmd, '/');
- }
- else if (rc_command("MapDebug", cmd))
- {
- rc_get_bool(cmd, &b);
-
- m_flags |= OpenRaider_DebugMap;
-
- if (!b)
- {
- m_flags ^= OpenRaider_DebugMap;
- }
- }
- // Mongoose 2001.12.31, Added music list back
- else if (rc_command("Music", cmd))
- {
- if (cmd[0])
- {
- char *music;
-
- i = strlen(cmd);
- music = new char[i+1];
- strncpy(music, cmd, i);
- music[i] = 0;
-
- mMusicList.pushBack(music);
- }
- }
- else if (rc_command("DisplayFPS", cmd))
- {
- rc_get_bool(cmd, &b);
-
- m_flags |= OpenRaider_ShowFPS;
-
- if (!b)
- {
- m_flags ^= OpenRaider_ShowFPS;
- }
- }
- else if (rc_command("ModelDebug", cmd))
- {
- rc_get_bool(cmd, &b);
-
- m_flags |= OpenRaider_DebugModel;
-
- if (!b)
- {
- m_flags ^= OpenRaider_DebugModel;
- }
- }
- else if (rc_command("DumpTexture", cmd))
- {
- rc_get_bool(cmd, &b);
-
- m_flags |= OpenRaider_DumpTexture;
-
- if (!b)
- {
- m_flags ^= OpenRaider_DumpTexture;
- }
- }
- else
- {
- printf("Command> [OpenRaider.Engine] Unknown command '%s'\n", cmd);
- }
- break;
- case 3: // [Input.Mouse]
- if (rc_command("SensitivityX", cmd))
- {
- m_mouseX = static_cast<float>(atof(cmd));
- }
- else if (rc_command("SensitivityY", cmd))
- {
- m_mouseY = static_cast<float>(atof(cmd));
- }
- else
- {
- printf("Command> [Input.Mouse] Unknown command '%s'\n", cmd);
- }
- break;
- case 4:
- if (cmd[1] == '.')
- {
- cmd[0] = '>';
- cmd[1] = ' ';
-
- for (i = strlen(cmd) - 1; i >= 0; --i)
- {
- if (cmd[i] == '.' || cmd[i] == '=')
- {
- cmd[i] = ' ';
- }
- }
- }
-
- consoleCommand(cmd);
- break;
- case 5:
- if (rc_command("Enable", cmd))
- {
- rc_get_bool(cmd, &gStartServer);
- }
- else if (rc_command("Port", cmd))
- {
- if (gStartServer)
- {
- Network &net = *Network::Instance();
- int port = atoi(cmd);
-
- net.setPort(port);
- print(true, "Starting network server on port %i...", port);
- net.spawnServerThread();
- }
- }
- else
- {
- printf("Command> [Network.Server] '%s' not implemented\n", cmd);
- }
- break;
- }
- }
-
-
- int main(int argc, char *argv[]) {
- if (argc != 1) {
- printf("Usage:\n\t%s\n", argv[0]);
- return 1;
- }
-
- OpenRaider *game = OpenRaider::Instance();
- atexit(killOpenRaiderSingleton);
- game->start();
-
- return 0;
- }
|