123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334 |
- #ifdef _d3d
- #include "Hunt.h"
- #include "stdio.h"
- #define d3debvcG 400
- #define d3debvc 1024
- #undef TCMAX
- #undef TCMIN
- #define TCMAX (((128<<16)-62024) / 128.f / 65535.f)
- #define TCMIN (((000<<16)+62024) / 128.f / 65535.f)
- #define _ZSCALE - 16.f
- #define _AZSCALE (1.f / 16.f);
- Vector2di ORList[2048];
- int ORLCount = 0;
- LPDIRECTDRAWSURFACE lpddPrimary = NULL;
- LPDIRECTDRAWSURFACE lpddBack = NULL;
- LPDIRECTDRAWSURFACE lpddZBuffer = NULL;
- LPDIRECTDRAWSURFACE lpddTexture = NULL;
- DDSURFACEDESC ddsd;
- LPDIRECT3D lpd3d = NULL;
- LPDIRECT3DDEVICE lpd3dDevice = NULL;
- LPDIRECT3DVIEWPORT lpd3dViewport = NULL;
- LPDIRECT3DEXECUTEBUFFER lpd3dExecuteBuffer = NULL;
- LPDIRECT3DEXECUTEBUFFER lpd3dExecuteBufferG = NULL;
- LPD3DTLVERTEX lpVertex, lpVertexG;
- WORD *lpwTriCount;
- HRESULT hRes;
- D3DEXECUTEBUFFERDESC d3dExeBufDesc;
- D3DEXECUTEBUFFERDESC d3dExeBufDescG;
- LPD3DINSTRUCTION lpInstruction, lpInstructionG;
- LPD3DPROCESSVERTICES lpProcessVertices;
- LPD3DTRIANGLE lpTriangle;
- LPD3DLINE lpLine;
- LPD3DSTATE lpState;
- BOOL fDeviceFound = FALSE;
- DWORD dwDeviceBitDepth = 0UL;
- GUID guidDevice;
- char szDeviceName[256];
- char szDeviceDesc[256];
- D3DDEVICEDESC d3dHWDeviceDesc;
- D3DTEXTUREHANDLE hTexture, hGTexture;
- HDC ddBackDC;
- BOOL D3DACTIVE;
- BOOL VMFORMAT565;
- BOOL STARTCONV555;
- BOOL HANDLECHANGED;
- #define NUM_INSTRUCTIONS 5UL
- #define NUM_STATES 20UL
- #define NUM_PROCESSVERTICES 1UL
- void RenderFSRect(DWORD Color);
- void d3dDownLoadTexture(int i, int w, int h, LPVOID tptr);
- BOOL d3dAllocTexture(int i, int w, int h);
- void d3dSetTexture(LPVOID tptr, int w, int h);
- void RenderShadowClip (TModel*, float, float, float, float, float, float, int, float, float);
- void ResetTextureMap();
- int WaterAlphaL = 255;
- int d3dTexturesMem;
- int d3dLastTexture;
- int d3dMemUsageCount;
- int d3dMemLoaded;
- int GVCnt;
- BOOL LINEARFILTER = TRUE;
- int zs;
- float SunLight;
- float TraceK,SkyTraceK,FogYGrad,FogYBase;;
- int SunScrX, SunScrY;
- int SkySumR, SkySumG, SkySumB;
- int LowHardMemory;
- int lsw;
- int vFogT[1024];
- BOOL SmallFont;
- typedef struct _d3dmemmap {
- int cpuaddr, size, lastused;
- LPDIRECTDRAWSURFACE lpddTexture;
- D3DTEXTUREHANDLE hTexture;
- } Td3dmemmap;
- #define d3dmemmapsize 128
- Td3dmemmap d3dMemMap[d3dmemmapsize+2];
- WORD conv_555(WORD c)
- {
- return (c & 31) + ( (c & 0xFFE0) >> 1 );
- }
- void conv_pic555(TPicture &pic)
- {
- if (!HARD3D) return;
- for (int y=0; y<pic.H; y++)
- for (int x=0; x<pic.W; x++)
- *(pic.lpImage + x + y*pic.W) = conv_555(*(pic.lpImage + x + y*pic.W));
- }
- void CalcFogLevel_Gradient(Vector3d v)
- {
- FogYBase = CalcFogLevel(v);
- if (FogYBase>0) {
- v.y+=800;
- FogYGrad = (CalcFogLevel(v) - FogYBase) / 800.f;
- } else FogYGrad=0;
- }
- void Hardware_ZBuffer(BOOL bl)
- {
- if (!bl) {
- DDBLTFX ddbltfx;
- ddbltfx.dwSize = sizeof( DDBLTFX );
- ddbltfx.dwFillDepth = 0x0000;
- lpddZBuffer->Blt( NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &ddbltfx );
- }
- }
- void d3dClearBuffers()
- {
- DDBLTFX ddbltfx;
- ddbltfx.dwSize = sizeof( DDBLTFX );
-
- if (VMFORMAT565) ddbltfx.dwFillColor = (SkyR>>3)*32*32*2 + (SkyG>>2)*32 + (SkyB>>3);
- else ddbltfx.dwFillColor = (SkyR>>3)*32*32 + (SkyG>>3)*32 + (SkyB>>3);
- lpddBack->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx );
-
- ddbltfx.dwSize = sizeof( DDBLTFX );
- ddbltfx.dwFillDepth = 0x0000;
- lpddZBuffer->Blt( NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &ddbltfx );
- }
- void d3dStartBuffer()
- {
- ZeroMemory(&d3dExeBufDesc, sizeof(d3dExeBufDesc));
- d3dExeBufDesc.dwSize = sizeof(d3dExeBufDesc);
- hRes = lpd3dExecuteBuffer->Lock( &d3dExeBufDesc );
- if (FAILED(hRes)) DoHalt("Error locking execute buffer");
- lpVertex = (LPD3DTLVERTEX)d3dExeBufDesc.lpData;
- }
- void d3dStartBufferG()
- {
- ZeroMemory(&d3dExeBufDescG, sizeof(d3dExeBufDescG));
- d3dExeBufDescG.dwSize = sizeof(d3dExeBufDescG);
- hRes = lpd3dExecuteBufferG->Lock( &d3dExeBufDescG );
- if (FAILED(hRes)) DoHalt("Error locking execute buffer");
- GVCnt = 0;
- hGTexture = -1;
- lpVertexG = (LPD3DTLVERTEX)d3dExeBufDescG.lpData;
- lpInstructionG = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDescG.lpData + d3debvcG*3);
- lpInstructionG->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstructionG->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstructionG->wCount = 1U;
- lpInstructionG++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstructionG;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = d3debvcG*3;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstructionG = (LPD3DINSTRUCTION)lpProcessVertices;
- if (!LINEARFILTER) {
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 2;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- }
-
- if (FOGENABLE) {
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 1;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_FOGCOLOR;
- lpState->dwArg[0] = CurFogColor;
-
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- }
-
- }
- void d3dStartBufferGBMP()
- {
- ZeroMemory(&d3dExeBufDescG, sizeof(d3dExeBufDescG));
- d3dExeBufDescG.dwSize = sizeof(d3dExeBufDescG);
- hRes = lpd3dExecuteBufferG->Lock( &d3dExeBufDescG );
- if (FAILED(hRes)) DoHalt("Error locking execute buffer");
- GVCnt = 0;
- hGTexture = -1;
- lpVertexG = (LPD3DTLVERTEX)d3dExeBufDescG.lpData;
- lpInstructionG = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDescG.lpData + d3debvcG*3);
- lpInstructionG->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstructionG->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstructionG->wCount = 1U;
- lpInstructionG++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstructionG;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = d3debvcG*3;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstructionG = (LPD3DINSTRUCTION)lpProcessVertices;
-
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- if (FOGENABLE) lpInstructionG->wCount = 6;
- else lpInstructionG->wCount = 5;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHAFUNC;
- lpState->dwArg[0] = D3DCMP_GREATER;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_NEAREST;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_NEAREST;
- lpState++;
- if (FOGENABLE) {
- lpState->drstRenderStateType = D3DRENDERSTATE_FOGCOLOR;
- lpState->dwArg[0] = CurFogColor;
- /*if (UNDERWATER) lpState->dwArg[0] = 0x00004560;
- else lpState->dwArg[0] = 0x00606065;*/
- lpState++;
- }
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- LINEARFILTER = FALSE;
- }
- void d3dEndBufferG(BOOL ColorKey)
- {
- if (!lpVertexG) return;
- if (ColorKey) {
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 5;
- lpInstructionG++;
-
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHAFUNC;
- lpState->dwArg[0] = D3DCMP_GREATEREQUAL;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- }
-
- lpInstructionG->bOpcode = D3DOP_EXIT;
- lpInstructionG->bSize = 0UL;
- lpInstructionG->wCount = 0U;
- lpInstructionG = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDescG.lpData + d3debvcG*3);
- lpInstructionG->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstructionG->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstructionG->wCount = 1U;
- lpInstructionG++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstructionG;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = GVCnt;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
- lpd3dExecuteBufferG->Unlock( );
- dFacesCount+=GVCnt/3;
- lpInstructionG = NULL;
- lpVertexG = NULL;
- GVCnt = 0;
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBufferG, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- LINEARFILTER = TRUE;
-
- }
- void d3dFlushBuffer(int fproc1, int fproc2)
- {
-
- BOOL ColorKey = (fproc2>0);
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + d3debvc*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
-
- lpInstruction->wCount = 3;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstruction->wCount = 1U;
- lpInstruction++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = (fproc1+fproc2)*3;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
- lpInstruction->bOpcode = D3DOP_TRIANGLE;
- lpInstruction->bSize = sizeof(D3DTRIANGLE);
- lpInstruction->wCount = fproc1;
- lpInstruction++;
- lpTriangle = (LPD3DTRIANGLE)lpInstruction;
-
- int ii = 0;
- for (int i=0; i<fproc1; i++) {
- lpTriangle->wV1 = ii++;
- lpTriangle->wV2 = ii++;
- lpTriangle->wV3 = ii++;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- }
- lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
- if (ColorKey) {
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 5;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHAFUNC;
- lpState->dwArg[0] = D3DCMP_GREATER;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_NEAREST;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_NEAREST;
- lpState++;
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_TRIANGLE;
- lpInstruction->bSize = sizeof(D3DTRIANGLE);
- lpInstruction->wCount = fproc2;
- lpInstruction++;
- lpTriangle = (LPD3DTRIANGLE)lpInstruction;
- for (i=0; i<fproc2; i++) {
- lpTriangle->wV1 = ii++;
- lpTriangle->wV2 = ii++;
- lpTriangle->wV3 = ii++;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- }
- lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 5;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHAFUNC;
- lpState->dwArg[0] = D3DCMP_GREATEREQUAL;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- }
-
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
- LINEARFILTER = TRUE;
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- //if (FAILED(hRes)) DoHalt("Error execute buffer");
- dFacesCount+=fproc1+fproc2;
- }
- DWORD BitDepthToFlags( DWORD dwBitDepth )
- {
- switch( dwBitDepth ) {
- case 1UL: return DDBD_1;
- case 2UL: return DDBD_2;
- case 4UL: return DDBD_4;
- case 8UL: return DDBD_8;
- case 16UL: return DDBD_16;
- case 24UL: return DDBD_24;
- case 32UL: return DDBD_32;
- default : return 0UL;
- }
- }
- DWORD FlagsToBitDepth( DWORD dwFlags )
- {
- if (dwFlags & DDBD_1) return 1UL;
- else if (dwFlags & DDBD_2) return 2UL;
- else if (dwFlags & DDBD_4) return 4UL;
- else if (dwFlags & DDBD_8) return 8UL;
- else if (dwFlags & DDBD_16) return 16UL;
- else if (dwFlags & DDBD_24) return 24UL;
- else if (dwFlags & DDBD_32) return 32UL;
- else return 0UL;
- }
- HRESULT FillExecuteBuffer_State( LPDIRECT3DEXECUTEBUFFER lpd3dExecuteBuffer)
- {
- HRESULT hRes;
- D3DEXECUTEBUFFERDESC d3dExeBufDesc;
- LPD3DINSTRUCTION lpInstruction;
- LPD3DSTATE lpState;
-
- ZeroMemory(&d3dExeBufDesc, sizeof(d3dExeBufDesc));
- d3dExeBufDesc.dwSize = sizeof(d3dExeBufDesc);
- hRes = lpd3dExecuteBuffer->Lock( &d3dExeBufDesc );
- if (FAILED(hRes)) {
- PrintLog( "Error locking execute buffer");
- return hRes;
- }
-
-
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + d3debvc*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 24;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_ZENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ZWRITEENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
-
- lpState->drstRenderStateType = D3DRENDERSTATE_ZFUNC;
- lpState->dwArg[0] = D3DCMP_GREATEREQUAL;
- lpState++;
-
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREPERSPECTIVE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAPBLEND;
- if (OPT_ALPHA_COLORKEY) lpState->dwArg[0] = D3DTBLEND_MODULATEALPHA;
- else lpState->dwArg[0] = D3DTBLEND_MODULATE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_SHADEMODE;
- lpState->dwArg[0] = D3DSHADE_GOURAUD;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_DITHERENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_CULLMODE;
- lpState->dwArg[0] = D3DCULL_NONE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_BLENDENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
-
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHABLENDENABLE;
- lpState->dwArg[0] = TRUE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHATESTENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHAREF;
- lpState->dwArg[0] = 0;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_ALPHAFUNC;
- lpState->dwArg[0] = D3DCMP_GREATEREQUAL;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_SPECULARENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_FOGENABLE;
- lpState->dwArg[0] = FOGENABLE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_FOGCOLOR;
- lpState->dwArg[0] = 0x00606070;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_SRCBLEND;
- lpState->dwArg[0] = D3DBLEND_SRCALPHA;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_DESTBLEND;
- lpState->dwArg[0] = D3DBLEND_INVSRCALPHA;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_STIPPLEDALPHA;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_WRAPU;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_WRAPV;
- lpState->dwArg[0] = FALSE;
- lpState++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
- //PrintLog( "Execute buffer filled successfully\n" );
- return DD_OK;
- }
- void SetRenderStates(BOOL ZWRITE, int DST_BLEND)
- {
- HRESULT hRes;
- D3DEXECUTEBUFFERDESC d3dExeBufDesc;
- LPD3DINSTRUCTION lpInstruction;
- LPD3DSTATE lpState;
-
- ZeroMemory(&d3dExeBufDesc, sizeof(d3dExeBufDesc));
- d3dExeBufDesc.dwSize = sizeof(d3dExeBufDesc);
- hRes = lpd3dExecuteBuffer->Lock( &d3dExeBufDesc );
- if (FAILED(hRes)) {
- PrintLog( "Error locking execute buffer");
- return;
- }
-
-
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + d3debvc*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 2;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
-
- lpState->drstRenderStateType = D3DRENDERSTATE_ZWRITEENABLE;
- lpState->dwArg[0] = ZWRITE;
- lpState++;
-
- lpState->drstRenderStateType = D3DRENDERSTATE_DESTBLEND;
- lpState->dwArg[0] = DST_BLEND;
- lpState++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
- lpd3dDevice->Execute( lpd3dExecuteBuffer,
- lpd3dViewport,
- D3DEXECUTE_UNCLIPPED );
- }
- HRESULT WINAPI EnumDeviceCallback(
- LPGUID lpGUID,
- LPSTR lpszDeviceDesc,
- LPSTR lpszDeviceName,
- LPD3DDEVICEDESC lpd3dHWDeviceDesc,
- LPD3DDEVICEDESC lpd3dSWDeviceDesc,
- LPVOID lpUserArg )
- {
- LPD3DDEVICEDESC lpd3dDeviceDesc;
- wsprintf(logt,"ENUMERATE: DDesc: %s DName: %s\n", lpszDeviceDesc, lpszDeviceName);
- //PrintLog(logt);
- if( !lpd3dHWDeviceDesc->dcmColorModel )
- return D3DENUMRET_OK; // we don't need SW rasterizer
- lpd3dDeviceDesc = lpd3dHWDeviceDesc;
- if( (lpd3dDeviceDesc->dwDeviceRenderBitDepth & dwDeviceBitDepth) == 0UL )
- return D3DENUMRET_OK;
- if( !(lpd3dDeviceDesc->dpcTriCaps.dwShadeCaps & D3DPSHADECAPS_COLORGOURAUDRGB) )
- return D3DENUMRET_OK;
- fDeviceFound = TRUE;
- CopyMemory( &guidDevice, lpGUID, sizeof(GUID) );
- strcpy( szDeviceDesc, lpszDeviceDesc );
- strcpy( szDeviceName, lpszDeviceName );
- CopyMemory( &d3dHWDeviceDesc, lpd3dHWDeviceDesc, sizeof(D3DDEVICEDESC) );
- return D3DENUMRET_CANCEL;
- }
- HRESULT CreateDirect3D( HWND hwnd )
- {
- HRESULT hRes;
- PrintLog("\n");
- PrintLog("=== Init Direct3D ===\n" );
- hRes = lpDD->SetCooperativeLevel( hwnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN );
- if (FAILED(hRes)) DoHalt("Error setting cooperative level\n");
- hRes = lpDD->SetDisplayMode( WinW, WinH, 16 );
- if (FAILED(hRes)) {
- PrintLog("DDraw: can't set selected video mode\n");
- WinW = 640;
- WinH = 480;
- OptRes = 3;
- hRes = lpDD->SetDisplayMode( WinW, WinH, 16 );
- }
- if (FAILED(hRes)) DoHalt("Error setting display mode\n");
- wsprintf(logt, "Set Display mode %dx%d, 16bpp\n", WinW, WinH);
- PrintLog(logt);
-
- hRes = lpDD->QueryInterface( IID_IDirect3D, (LPVOID*) &lpd3d);
- if (FAILED(hRes)) DoHalt("Error quering Direct3D interface\n");
- PrintLog("QueryInterface: Ok. (IID_IDirect3D)\n");
-
- DDSURFACEDESC ddsd;
- ZeroMemory(&ddsd, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- ddsd.dwFlags = DDSD_CAPS;
- ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
- hRes = lpDD->CreateSurface( &ddsd, &lpddPrimary, NULL );
- if (FAILED(hRes)) DoHalt( "Error creating primary surface\n");
-
- ZeroMemory(&ddsd, sizeof(ddsd) );
- ddsd.dwSize = sizeof(ddsd);
- hRes = lpddPrimary->GetSurfaceDesc( &ddsd);
- if (FAILED(hRes)) DoHalt("Error getting surface description\n");
- PrintLog("CreateSurface: Ok. (Primary)\n");
- dwDeviceBitDepth = BitDepthToFlags(ddsd.ddpfPixelFormat.dwRGBBitCount);
- fDeviceFound = FALSE;
- hRes = lpd3d->EnumDevices( EnumDeviceCallback, &fDeviceFound);
- if (FAILED(hRes) ) DoHalt("EnumDevices failed.\n");
- if (!fDeviceFound ) DoHalt("No devices found.\n");
- PrintLog("EnumDevices: Ok.\n");
-
- return DD_OK;
- }
- HRESULT CreateDevice(DWORD dwWidth, DWORD dwHeight)
- {
- DDSURFACEDESC ddsd;
- HRESULT hRes;
- DWORD dwZBufferBitDepth;
-
- ZeroMemory(&ddsd, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
- ddsd.dwWidth = dwWidth;
- ddsd.dwHeight = dwHeight;
- ddsd.ddsCaps.dwCaps = DDSCAPS_3DDEVICE | DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
- hRes = lpDD->CreateSurface( &ddsd, &lpddBack, NULL);
- if (FAILED(hRes)) DoHalt("Error creating back buffer surface\n");
- PrintLog("CreateSurface: Ok. (BackBuffer)\n");
-
- if( d3dHWDeviceDesc.dwDeviceZBufferBitDepth != 0UL ) {
- dwZBufferBitDepth = FlagsToBitDepth( d3dHWDeviceDesc.dwDeviceZBufferBitDepth );
- ZeroMemory(&ddsd, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_ZBUFFERBITDEPTH;
- ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
- ddsd.dwWidth = dwWidth;
- ddsd.dwHeight = dwHeight;
- ddsd.dwZBufferBitDepth = 16;//dwZBufferBitDepth;
- hRes = lpDD->CreateSurface( &ddsd, &lpddZBuffer, NULL);
- /*
- if (FAILED(hRes)) {
- ddsd.dwZBufferBitDepth = 16;//dwZBufferBitDepth;
- hRes = lpDD->CreateSurface( &ddsd, &lpddZBuffer, NULL);
- PrintLog("Z-Buffer: 16 bit\n");
- } else
- PrintLog("Z-Buffer: 32 bit\n");
- */
- if (FAILED(hRes)) DoHalt("Error creating z-buffer\n");
-
- hRes = lpddBack->AddAttachedSurface( lpddZBuffer );
- if (FAILED(hRes)) DoHalt("Error attaching z-buffer\n");
- PrintLog("CreateSurface: Ok. (Z-buffer)\n");
- }
-
- hRes = lpddBack->QueryInterface( guidDevice, (LPVOID*) &lpd3dDevice);
- if (FAILED(hRes)) DoHalt("Error quering device interface\n");
- PrintLog("QueryInterface: Ok. (lpd3dDevice)\n");
- return DD_OK;
- }
- HRESULT CreateScene(void)
- {
- HRESULT hRes;
- DWORD dwVertexSize;
- DWORD dwInstructionSize;
- DWORD dwExecuteBufferSize;
- D3DEXECUTEBUFFERDESC d3dExecuteBufferDesc;
- D3DEXECUTEDATA d3dExecuteData;
- hRes = lpd3d->CreateViewport( &lpd3dViewport, NULL );
- if (FAILED(hRes)) DoHalt("Error creating viewport\n");
- PrintLog("CreateViewport: Ok.\n");
- hRes = lpd3dDevice->AddViewport( lpd3dViewport );
- if (FAILED(hRes)) DoHalt("Error adding viewport\n");
- //PrintLog("AddViewport: Ok.\n");
-
- D3DVIEWPORT d3dViewport;
- ZeroMemory(&d3dViewport, sizeof(d3dViewport));
- d3dViewport.dwSize = sizeof(d3dViewport);
- d3dViewport.dwX = 0UL;
- d3dViewport.dwY = 0UL;
- d3dViewport.dwWidth = (DWORD)WinW;
- d3dViewport.dwHeight = (DWORD)WinH;
- d3dViewport.dvScaleX = D3DVAL((float)d3dViewport.dwWidth / 2.0);
- d3dViewport.dvScaleY = D3DVAL((float)d3dViewport.dwHeight / 2.0);
- d3dViewport.dvMaxX = D3DVAL(1.0);
- d3dViewport.dvMaxY = D3DVAL(1.0);
-
- lpd3dViewport->SetViewport( &d3dViewport);
-
- //=========== CREATING EXECUTE BUFFER ======================//
- dwVertexSize = ((d3debvc*3) * sizeof(D3DVERTEX));
- dwInstructionSize = (NUM_INSTRUCTIONS * sizeof(D3DINSTRUCTION)) +
- (NUM_STATES * sizeof(D3DSTATE)) +
- (NUM_PROCESSVERTICES * sizeof(D3DPROCESSVERTICES)) +
- ((d3debvc) * sizeof(D3DTRIANGLE));
- dwExecuteBufferSize = dwVertexSize + dwInstructionSize;
- ZeroMemory(&d3dExecuteBufferDesc, sizeof(d3dExecuteBufferDesc));
- d3dExecuteBufferDesc.dwSize = sizeof(d3dExecuteBufferDesc);
- d3dExecuteBufferDesc.dwFlags = D3DDEB_BUFSIZE;
- d3dExecuteBufferDesc.dwBufferSize = dwExecuteBufferSize;
- hRes = lpd3dDevice->CreateExecuteBuffer( &d3dExecuteBufferDesc, &lpd3dExecuteBuffer, NULL);
- if (FAILED(hRes)) DoHalt( "Error creating execute buffer\n");
- PrintLog("CreateExecuteBuffer: Ok.\n");
- ZeroMemory(&d3dExecuteData, sizeof(d3dExecuteData));
- d3dExecuteData.dwSize = sizeof(d3dExecuteData);
- d3dExecuteData.dwVertexCount = d3debvc;
- d3dExecuteData.dwInstructionOffset = dwVertexSize;
- d3dExecuteData.dwInstructionLength = dwInstructionSize;
- hRes = lpd3dExecuteBuffer->SetExecuteData( &d3dExecuteData );
- if (FAILED(hRes)) DoHalt("Error setting execute data\n");
- //=========== CREATING EXECUTE BUFFER ======================//
- dwVertexSize = ((d3debvcG*3) * sizeof(D3DVERTEX));
- dwInstructionSize = (300 * sizeof(D3DINSTRUCTION)) +
- (300 * sizeof(D3DSTATE)) +
- (10 * sizeof(D3DPROCESSVERTICES)) +
- ((d3debvcG) * sizeof(D3DTRIANGLE));
- dwExecuteBufferSize = dwVertexSize + dwInstructionSize;
- ZeroMemory(&d3dExecuteBufferDesc, sizeof(d3dExecuteBufferDesc));
- d3dExecuteBufferDesc.dwSize = sizeof(d3dExecuteBufferDesc);
- d3dExecuteBufferDesc.dwFlags = D3DDEB_BUFSIZE;
- d3dExecuteBufferDesc.dwBufferSize = dwExecuteBufferSize;
- hRes = lpd3dDevice->CreateExecuteBuffer( &d3dExecuteBufferDesc, &lpd3dExecuteBufferG, NULL);
- if (FAILED(hRes)) DoHalt( "Error creating execute buffer\n");
- PrintLog("CreateExecuteBuffer: Ok.\n");
- ZeroMemory(&d3dExecuteData, sizeof(d3dExecuteData));
- d3dExecuteData.dwSize = sizeof(d3dExecuteData);
- d3dExecuteData.dwVertexCount = d3debvcG;
- d3dExecuteData.dwInstructionOffset = dwVertexSize;
- d3dExecuteData.dwInstructionLength = dwInstructionSize;
- hRes = lpd3dExecuteBufferG->SetExecuteData( &d3dExecuteData );
- if (FAILED(hRes)) DoHalt("Error setting execute data\n");
-
- FillExecuteBuffer_State(lpd3dExecuteBuffer);
- hRes = lpd3dDevice->Execute( lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
-
- return DD_OK;
- }
- void Init3DHardware()
- {
- HARD3D = TRUE;
- PrintLog("\n");
- PrintLog("==Init Direct Draw==\n");
- HRESULT hres;
- hres = DirectDrawCreate( NULL, &lpDD, NULL );
- if( hres != DD_OK ) {
- wsprintf(logt, "DirectDrawCreate Error: %Xh\n", hres);
- DoHalt(logt); }
- PrintLog("DirectDrawCreate: Ok\n");
-
- DirectActive = TRUE;
- }
- void d3dDetectCaps()
- {
- for (int t=0; t<d3dmemmapsize; t++) {
- if (!d3dAllocTexture(t, 256, 256)) break;
- }
- d3dTexturesMem = t*256*256*2;
- d3dDownLoadTexture(0, 256, 256, SkyPic);
- DWORD T;
- T = timeGetTime();
- for (t=0; t<10; t++) d3dDownLoadTexture(0, 256, 256, SkyPic);
- T = timeGetTime() - T;
-
- wsprintf(logt, "DETECTED: Texture memory : %dK.\n", d3dTexturesMem>>10);
- PrintLog(logt);
- ResetTextureMap();
- wsprintf(logt, "DETECTED: Texture transfer speed: %dK/sec.\n", 128*10000 / T);
- PrintLog(logt);
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
- lpddBack->Unlock(ddsd.lpSurface);
- if (ddsd.ddpfPixelFormat.dwGBitMask == 0x3E0) VMFORMAT565=FALSE; else VMFORMAT565=TRUE;
- if (VMFORMAT565)
- PrintLog("DETECTED: PixelFormat RGB565\n");
- else {
- PrintLog("DETECTED: PixelFormat RGB555\n");
- if (!STARTCONV555) {
- STARTCONV555 = TRUE;
- conv_pic555(PausePic);
- conv_pic555(ExitPic);
- conv_pic555(TrophyExit);
- conv_pic555(MapPic);
- conv_pic555(TrophyPic);
- for (int c=0; c<20; c++)
- if (DinoInfo[c].CallIcon.W)
- conv_pic555(DinoInfo[c].CallIcon);
- for (int w=0; w<TotalW; w++)
- if (Weapon.BulletPic[w].W)
- conv_pic555(Weapon.BulletPic[w]);
- }
- }
-
-
- }
- void d3dTestDrawTri(DWORD color, float tx)
- {
- d3dStartBuffer();
-
- lpVertex->sx = 0;
- lpVertex->sy = 0;
- lpVertex->sz = _ZSCALE / 10;
- lpVertex->rhw = 1.f;
- lpVertex->color = color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = tx;
- lpVertex->tv = tx;
- lpVertex++;
- lpVertex->sx = 100;
- lpVertex->sy = 0;
- lpVertex->sz = _ZSCALE / 10;
- lpVertex->rhw = 1.f;
- lpVertex->color = color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = tx;
- lpVertex->tv = tx;
- lpVertex++;
- lpVertex->sx = 0;
- lpVertex->sy = 100;
- lpVertex->sz = _ZSCALE / 10;
- lpVertex->rhw = 1.f;
- lpVertex->color = color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = tx;
- lpVertex->tv = tx;
- lpVertex++;
-
- d3dFlushBuffer(0, 1);
-
- }
- int d3dTestAlpha()
- {
- int RF = 0;
-
- lpd3dDevice->BeginScene( );
- // RenderSkyPlane();
- d3dSetTexture(TFX_SPECULAR.lpImage, TFX_SPECULAR.W, TFX_SPECULAR.W);
-
- DDBLTFX ddbltfx;
- ddbltfx.dwSize = sizeof( DDBLTFX );
- ddbltfx.dwFillColor = 0xFFFF;
- lpddBack->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx );
- FillExecuteBuffer_State(lpd3dExecuteBuffer);
- hRes = lpd3dDevice->Execute( lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- //========= test opacity ==========//
-
- //d3dSetTexture(TFX_SPECULAR.lpImage, TFX_SPECULAR.W, TFX_SPECULAR.W);
- SetRenderStates(FALSE, D3DBLEND_INVSRCALPHA);
- d3dTestDrawTri(0xFFFFFFFF, 0.0);
-
-
- CopyBackToDIB();
- if (*((WORD*)lpVideoBuf)==0) PrintLog("[OPACITY: Failed] ");
- else { PrintLog("[OPACITY: Ok.] "); RF+=4; }
- lpd3dDevice->EndScene( );
- lpd3dDevice->BeginScene( );
- /*
- ShowVideo();
- lpd3dDevice->BeginScene( );
- Sleep(1000);
- */
- //=========== test transparent mode =============//
- lpd3dDevice->BeginScene( );
- ddbltfx.dwSize = sizeof( DDBLTFX );
- ddbltfx.dwFillColor = 0x0000;
- lpddBack->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx );
- d3dTestDrawTri(0x00FFFFFF, 0.5);
-
- CopyBackToDIB();
- if (*((WORD*)lpVideoBuf)!=0) PrintLog("[TRANSPARENT: Failed] ");
- else { PrintLog("[TRANSPARENT: Ok.] "); RF+=2; }
- lpd3dDevice->EndScene( );
- lpd3dDevice->BeginScene( );
- /*
- ShowVideo();
- lpd3dDevice->BeginScene( );
- Sleep(1000);
- */
- //=========== test env map ==================//
- SetRenderStates(FALSE, D3DBLEND_ONE);
- lpd3dDevice->BeginScene( );
- ddbltfx.dwSize = sizeof( DDBLTFX );
- ddbltfx.dwFillColor = 0x0000;
- lpddBack->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx );
- d3dTestDrawTri(0x00FFFFFF, 0.5);
- CopyBackToDIB();
- if (*((WORD*)lpVideoBuf)!=0) PrintLog("[ENV.BLEND : Failed]\n");
- else { PrintLog("[ENV.BLEND : Ok.]\n"); RF+=1; }
- lpd3dDevice->EndScene( );
- lpd3dDevice->BeginScene( );
- /*
- ShowVideo();
- lpd3dDevice->BeginScene( );
- Sleep(1000);
- */
- SetRenderStates(TRUE, D3DBLEND_INVSRCALPHA);
- lpd3dDevice->EndScene( );
- return RF;
- }
- void Activate3DHardware()
- {
- SetVideoMode(WinW,WinH);
- HRESULT hRes = CreateDirect3D(hwndMain);
- if (FAILED(hRes)) DoHalt("CreateDirect3D Failed.\n");
- hRes = CreateDevice((DWORD)WinW, (DWORD)WinH);
- if (FAILED(hRes)) DoHalt("Create Device Failed.\n");
- d3dClearBuffers();
- hRes = CreateScene();
- if (FAILED(hRes)) DoHalt("CreateScene Failed.\n");
- d3dDetectCaps();
- OPT_ALPHA_COLORKEY=FALSE;
- PrintLog("TEST COLOR KEY: ");
- int r1 = d3dTestAlpha();
-
- OPT_ALPHA_COLORKEY=TRUE;
- PrintLog("TEST ALPHA KEY: ");
- int r2 = d3dTestAlpha();
- OPT_ALPHA_COLORKEY = (r2>=r1);
- if (OPT_ALPHA_COLORKEY) PrintLog("ALPHA KEY mode selected.\n");
- else PrintLog("COLOR KEY mode selected.\n");
-
- hRes = lpd3dDevice->BeginScene( );
- if (OptText==0) LOWRESTX = TRUE;
- if (OptText==1) LOWRESTX = FALSE;
- if (OptText==2) LOWRESTX = FALSE;
- d3dMemLoaded = 0;
-
- D3DACTIVE = TRUE;
-
- d3dLastTexture = d3dmemmapsize+1;
- PrintLog("=== Direct3D started === \n");
- PrintLog("\n");
- }
- void ResetTextureMap()
- {
- d3dEndBufferG(FALSE);
- d3dMemUsageCount = 0;
- //d3dMemLoaded = 0;
- d3dLastTexture = d3dmemmapsize+1;
- for (int m=0; m<d3dmemmapsize+2; m++) {
- d3dMemMap[m].lastused = 0;
- d3dMemMap[m].cpuaddr = 0;
- if (d3dMemMap[m].lpddTexture) {
- d3dMemMap[m].lpddTexture->Release();
- d3dMemMap[m].lpddTexture = NULL;
- }
- }
- }
- void ShutDown3DHardware()
- {
- D3DACTIVE = FALSE;
-
- if (lpd3dDevice)
- hRes = lpd3dDevice->EndScene();
-
- ResetTextureMap();
- lpInstructionG = NULL;
- lpVertexG = NULL;
- if (NULL != lpd3dExecuteBuffer) {
- lpd3dExecuteBuffer->Release( );
- lpd3dExecuteBufferG->Release( );
- lpd3dExecuteBuffer = NULL;
- }
- if (NULL != lpd3dViewport) {
- lpd3dViewport->Release( );
- lpd3dViewport = NULL;
- }
- if (NULL != lpd3dDevice) {
- lpd3dDevice->Release( );
- lpd3dDevice = NULL;
- }
- if (NULL != lpddZBuffer) {
- lpddZBuffer->Release( );
- lpddZBuffer = NULL;
- }
-
- if (NULL != lpddBack) {
- lpddBack->Release();
- lpddBack = NULL;
- }
- if (NULL != lpddPrimary) {
- lpddPrimary->Release( );
- lpddPrimary = NULL;
- }
- if (NULL != lpd3d) {
- lpd3d->Release( );
- lpd3d = NULL;
- }
- lpDD->SetCooperativeLevel( hwndMain, DDSCL_NORMAL);
- }
- void InsertFxMM(int m)
- {
- for (int mm=d3dmemmapsize-1; mm>m; mm--)
- d3dMemMap[m] = d3dMemMap[m-1];
- }
- BOOL d3dAllocTexture(int i, int w, int h)
- {
- DDSURFACEDESC ddsd;
- DDPIXELFORMAT ddpf;
- ZeroMemory( &ddpf, sizeof(DDPIXELFORMAT) );
- ddpf.dwSize = sizeof(DDPIXELFORMAT);
- ddpf.dwFlags = DDPF_RGB;
- if (OPT_ALPHA_COLORKEY) {
- ddpf.dwFlags |= DDPF_ALPHAPIXELS;
- ddpf.dwRGBAlphaBitMask = 0x8000;
- }
- ddpf.dwRGBBitCount = 16;
- ddpf.dwRBitMask = 0x7c00;
- ddpf.dwGBitMask = 0x3e0;
- ddpf.dwBBitMask = 0x1f;
- ZeroMemory(&ddsd, sizeof(ddsd));
- ddsd.dwSize = sizeof(ddsd);
- ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
- ddsd.dwWidth = w;
- ddsd.dwHeight = h;
- CopyMemory( &ddsd.ddpfPixelFormat, &ddpf, sizeof(DDPIXELFORMAT) );
- ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
- hRes = lpDD->CreateSurface( &ddsd, &d3dMemMap[i].lpddTexture, NULL);
- if (FAILED(hRes)) {
- d3dMemMap[i].lpddTexture = NULL;
- return FALSE; }
-
- DDCOLORKEY ddck;
- ddck.dwColorSpaceLowValue = ddck.dwColorSpaceHighValue = 0x0000;
- d3dMemMap[i].lpddTexture->SetColorKey(DDCKEY_SRCBLT, &ddck);
-
- return TRUE;
- }
- void d3dDownLoadTexture(int i, int w, int h, LPVOID tptr)
- {
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
-
- if( d3dMemMap[i].lpddTexture->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
- CopyMemory( ddsd.lpSurface, tptr, w*h*2 );
- d3dMemMap[i].lpddTexture->Unlock( ddsd.lpSurface );
- IDirect3DTexture* Texture;
- if( d3dMemMap[i].lpddTexture->QueryInterface( IID_IDirect3DTexture, (LPVOID*)&Texture ) != S_OK ) return;
- if( Texture->GetHandle( lpd3dDevice, &d3dMemMap[i].hTexture ) != D3D_OK ) return;
- Texture->Release( );
- d3dMemMap[i].cpuaddr = (int) tptr;
- d3dMemMap[i].size = w*h*2;
- d3dMemLoaded+=w*h*2;
- //---------------------------------------------------------------------------
- }
- int DownLoadTexture(LPVOID tptr, int w, int h)
- {
- int textureSize = w*w*2;
- int fxm = 0;
- int m;
- //========== if no memory used ==========//
- if (!d3dMemMap[0].cpuaddr) {
- d3dAllocTexture(0, w, h);
- d3dDownLoadTexture(0, w, h, tptr);
- return 0;
- }
- //====== search for last used block and try to alloc next ============//
- for (m = 0; m < d3dmemmapsize; m++)
- if (!d3dMemMap[m].cpuaddr)
- if (d3dAllocTexture(m, w, h)) {
- d3dDownLoadTexture(m, w, h, tptr);
- return m;
- } else break;
-
-
- //====== search for unused texture and replace it with new ============//
- int unusedtime = 2;
- int rt = -1;
- for (m = 0; m < d3dmemmapsize; m++) {
- if (!d3dMemMap[m].cpuaddr) break;
- if (d3dMemMap[m].size != w*h*2) continue;
- int ut = d3dMemUsageCount - d3dMemMap[m].lastused;
-
- if (ut >= unusedtime) {
- unusedtime = ut;
- rt = m; }
- }
- if (rt!=-1) {
- d3dDownLoadTexture(rt, w, h, tptr);
- return rt;
- }
-
- ResetTextureMap();
- d3dAllocTexture(0, w, h);
- d3dDownLoadTexture(0, w, h, tptr);
- return 0;
- }
- void d3dSetTexture(LPVOID tptr, int w, int h)
- {
-
- if (d3dMemMap[d3dLastTexture].cpuaddr == (int)tptr) return;
- int fxm = -1;
- for (int m=0; m<d3dmemmapsize; m++) {
- if (d3dMemMap[m].cpuaddr == (int)tptr) { fxm = m; break; }
- if (!d3dMemMap[m].cpuaddr) break;
- }
- if (fxm==-1) fxm = DownLoadTexture(tptr, w, h);
- d3dMemMap[fxm].lastused = d3dMemUsageCount;
- hTexture = d3dMemMap[fxm].hTexture;
- d3dLastTexture = fxm;
-
- }
- float GetTraceK(int x, int y)
- {
-
- if (x<8 || y<8 || x>WinW-8 || y>WinH-8) return 0.f;
-
- float k = 0;
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddZBuffer->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) {
- return 0;
- }
- WORD CC = 200;
- int bw = (ddsd.lPitch>>1);
- if ( *((WORD*)ddsd.lpSurface + (y+0)*bw + x+0) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y+10)*bw + x+0) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y-10)*bw + x+0) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y+0)*bw + x+10) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y+0)*bw + x-10) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y+8)*bw + x+8) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y+8)*bw + x-8) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y-8)*bw + x+8) < CC ) k+=1.f;
- if ( *((WORD*)ddsd.lpSurface + (y-8)*bw + x-8) < CC ) k+=1.f;
-
- lpddZBuffer->Unlock(ddsd.lpSurface);
- k/=9.f;
-
- DeltaFunc(TraceK, k, TimeDt / 1024.f);
- return TraceK;
- }
- void AddSkySum(WORD C)
- {
- int R,G,B;
- if (VMFORMAT565) {
- R = C>>11; G = (C>>5) & 63; B = C & 31;
- } else {
- R = C>>10; G = (C>>5) & 31; B = C & 31; C=C*2;
- }
-
- SkySumR += R*8;
- SkySumG += G*4;
- SkySumB += B*8;
- }
- float GetSkyK(int x, int y)
- {
- if (x<10 || y<10 || x>WinW-10 || y>WinH-10) return 0.5;
- SkySumR = 0;
- SkySumG = 0;
- SkySumB = 0;
- float k = 0;
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) {
- return 0;
- }
-
- int bw = (ddsd.lPitch>>1);
- AddSkySum(*((WORD*)ddsd.lpSurface + (y+0)*bw + x+0));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y+6)*bw + x+0));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y-6)*bw + x+0));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y+0)*bw + x+6));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y+0)*bw + x-6));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y+4)*bw + x+4));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y+4)*bw + x-4));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y-4)*bw + x+4));
- AddSkySum(*((WORD*)ddsd.lpSurface + (y-4)*bw + x-4));
-
- lpddBack->Unlock(ddsd.lpSurface);
-
- SkySumR-=SkyTR*9;
- SkySumG-=SkyTG*9;
- SkySumB-=SkyTB*9;
- k = (float)sqrt(SkySumR*SkySumR + SkySumG*SkySumG + SkySumB*SkySumB) / 9;
- if (k>80) k = 80;
- if (k< 0) k = 0;
- k = 1.0f - k/80.f;
- if (k<0.2) k=0.2f;
- if (OptDayNight==2) k=0.3 + k/2.75;
- DeltaFunc(SkyTraceK, k, (0.07f + (float)fabs(k-SkyTraceK)) * (TimeDt / 512.f) );
- return SkyTraceK;
- }
- void TryHiResTx()
- {
- int UsedMem = 0;
- for (int m=0; m<d3dmemmapsize; m++) {
- if (!d3dMemMap[m].cpuaddr) break;
- if (d3dMemMap[m].lastused+2>=d3dMemUsageCount)
- UsedMem+= d3dMemMap[m].size;
- }
- /*
- wsprintf(logt, "TOTALL: %d USED: %d", d3dTexturesMem, UsedMem);
- AddMessage(logt);
- */
- if (UsedMem*4 < (int)d3dTexturesMem)
- LOWRESTX = FALSE;
- }
- void ShowVideo()
- {
- /*
- char t[128];
- wsprintf(t, "T-mem loaded: %dK", d3dMemLoaded >> 10);
- if (d3dMemLoaded) AddMessage(t);
- */
- if (d3dMemLoaded > 200*1024) LowHardMemory++;
- else LowHardMemory=0;
- if (LowHardMemory>2) {
- LOWRESTX = TRUE;
- LowHardMemory = 0; }
- if (OptText==0) LOWRESTX = TRUE;
- if (OptText==1) LOWRESTX = FALSE;
- if (OptText==2)
- if (LOWRESTX && (Takt & 63)==0) TryHiResTx();
- if (UNDERWATER)
- RenderFSRect(CurFogColor+0x70000000);
-
- if (OptDayNight!=2)
- if (!UNDERWATER && (SunLight>1.0f) ) {
- RenderFSRect(0xFFFFC0 + ((int)SunLight<<24));
- }
-
- RenderHealthBar();
-
- d3dMemUsageCount++;
- d3dMemLoaded = 0;
- hRes = lpd3dDevice->EndScene();
- hRes = lpddPrimary->Blt( NULL, lpddBack, NULL, DDBLT_WAIT, NULL );
-
- d3dClearBuffers();
- hRes = lpd3dDevice->BeginScene( );
-
- }
- void CopyBackToDIB()
- {
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
-
- WORD *lpVMem = (WORD*) ddsd.lpSurface;
- ddsd.lPitch/=2;
- for (int y=0; y<=256; y++)
- CopyMemory( (WORD*)lpVideoBuf + y*1024,
- lpVMem + y*ddsd.lPitch,
- 256*2);
-
- lpddBack->Unlock(ddsd.lpSurface);
- }
- void CopyHARDToDIB()
- {
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddPrimary->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
-
- WORD *lpVMem = (WORD*) ddsd.lpSurface;
- ddsd.lPitch/=2;
- for (int y=0; y<=WinH; y++)
- CopyMemory( (WORD*)lpVideoBuf + y*1024,
- lpVMem + y*ddsd.lPitch,
- WinW*2);
-
- lpddPrimary->Unlock(ddsd.lpSurface);
- }
- void FXPutBitMap(int x0, int y0, int w, int h, int smw, LPVOID lpData)
- {
- DDSURFACEDESC ddsd;
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
-
- WORD *lpVMem = (WORD*) ddsd.lpSurface;
- ddsd.lPitch/=2;
- lpVMem+=x0+y0 * ddsd.lPitch;
- for (int y=0; y<h; y++)
- CopyMemory( lpVMem + y*ddsd.lPitch, ((WORD*)lpData)+y*smw, w*2);
-
- lpddBack->Unlock(ddsd.lpSurface);
- }
- void DrawPicture(int x, int y, TPicture &pic)
- {
- FXPutBitMap(x, y, pic.W, pic.H, pic.W, pic.lpImage);
- }
- void ddTextOut(int x, int y, LPSTR t, int color)
- {
- lpddBack->GetDC( &ddBackDC );
- SetBkMode( ddBackDC, TRANSPARENT );
- HFONT oldfont;
- if (SmallFont) oldfont = (HFONT)SelectObject(ddBackDC, fnt_Small);
-
- SetTextColor(ddBackDC, 0x00101010);
- TextOut(ddBackDC, x+2, y+1, t, strlen(t));
- SetTextColor(ddBackDC, color);
- TextOut(ddBackDC, x+1, y, t, strlen(t));
- if (SmallFont) SelectObject(ddBackDC, oldfont);
-
- lpddBack->ReleaseDC( ddBackDC );
- }
- void DrawTrophyText(int x0, int y0)
- {
- int x;
- SmallFont = TRUE;
- HFONT oldfont = (HFONT)SelectObject(hdcMain, fnt_Small);
- int tc = TrophyBody;
-
- int dtype = TrophyRoom.Body[tc].ctype;
- int time = TrophyRoom.Body[tc].time;
- int date = TrophyRoom.Body[tc].date;
- int wep = TrophyRoom.Body[tc].weapon;
- int score = TrophyRoom.Body[tc].score;
- float scale = TrophyRoom.Body[tc].scale;
- float range = TrophyRoom.Body[tc].range;
- char t[32];
- x0+=14; y0+=18;
- x = x0;
- ddTextOut(x, y0 , "Name: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Name: ");
- ddTextOut(x, y0 , DinoInfo[dtype].Name, 0x0000BFBF);
- x = x0;
- ddTextOut(x, y0+16, "Weight: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Weight: ");
- if (OptSys)
- sprintf(t,"%3.2ft ", DinoInfo[dtype].Mass * scale * scale / 0.907);
- else
- sprintf(t,"%3.2fT ", DinoInfo[dtype].Mass * scale * scale);
- ddTextOut(x, y0+16, t, 0x0000BFBF); x+=GetTextW(hdcMain,t);
- ddTextOut(x, y0+16, "Length: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Length: ");
-
- if (OptSys)
- sprintf(t,"%3.2fft", DinoInfo[dtype].Length * scale / 0.3);
- else
- sprintf(t,"%3.2fm", DinoInfo[dtype].Length * scale);
- ddTextOut(x, y0+16, t, 0x0000BFBF);
-
- x = x0;
- ddTextOut(x, y0+32, "Weapon: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Weapon: ");
- wsprintf(t,"%s ", WeapInfo[wep].Name);
- ddTextOut(x, y0+32, t, 0x0000BFBF); x+=GetTextW(hdcMain,t);
- ddTextOut(x, y0+32, "Score: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Score: ");
- wsprintf(t,"%d", score);
- ddTextOut(x, y0+32, t, 0x0000BFBF);
- x = x0;
- ddTextOut(x, y0+48, "Range of kill: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Range of kill: ");
- if (OptSys) sprintf(t,"%3.1fft", range / 0.3);
- else sprintf(t,"%3.1fm", range);
- ddTextOut(x, y0+48, t, 0x0000BFBF);
- x = x0;
- ddTextOut(x, y0+64, "Date: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Date: ");
- if (OptSys)
- wsprintf(t,"%d.%d.%d ", ((date>>10) & 255), (date & 255), date>>20);
- else
- wsprintf(t,"%d.%d.%d ", (date & 255), ((date>>10) & 255), date>>20);
- ddTextOut(x, y0+64, t, 0x0000BFBF); x+=GetTextW(hdcMain,t);
- ddTextOut(x, y0+64, "Time: ", 0x00BFBFBF); x+=GetTextW(hdcMain,"Time: ");
- wsprintf(t,"%d:%02d", ((time>>10) & 255), (time & 255));
- ddTextOut(x, y0+64, t, 0x0000BFBF);
- SmallFont = FALSE;
- SelectObject(hdcMain, oldfont);
-
- }
- void Render_LifeInfo(int li)
- {
- int x,y;
- SmallFont = TRUE;
- //HFONT oldfont = SelectObject(hdcMain, fnt_Small);
-
- int ctype = Characters[li].CType;
- float scale = Characters[li].scale;
- char t[32];
-
- x = VideoCX + WinW / 64;
- y = VideoCY + (int)(WinH / 6.8);
-
- ddTextOut(x, y, DinoInfo[ctype].Name, 0x0000b000);
-
- if (OptSys) sprintf(t,"Weight: %3.2ft ", DinoInfo[ctype].Mass * scale * scale / 0.907);
- else sprintf(t,"Weight: %3.2fT ", DinoInfo[ctype].Mass * scale * scale);
-
- ddTextOut(x, y+16, t, 0x0000b000);
- int R = (int)(VectorLength( SubVectors(Characters[li].pos, PlayerPos) )*3 / 64.f);
- if (OptSys) sprintf(t,"Distance: %dft ", R);
- else sprintf(t,"Distance: %dm ", R/3);
- ddTextOut(x, y+32, t, 0x0000b000);
-
- SmallFont = FALSE;
- //SelectObject(hdcMain, oldfont);
- }
- void RenderFXMMap()
- {
-
- }
- void ShowControlElements()
- {
- char buf[128];
-
- //ddTextOut(100, 100, "!", 0x0020A0A0);
- lpddBack->GetDC( &ddBackDC );
- lpddBack->ReleaseDC( ddBackDC );
-
- if (TIMER) {
- wsprintf(buf,"msc: %d", TimeDt);
- ddTextOut(WinEX-81, 11, buf, 0x0020A0A0);
- wsprintf(buf,"polys: %d", dFacesCount);
- ddTextOut(WinEX-90, 24, buf, 0x0020A0A0);
- wsprintf(buf,"%d", Env);
- ddTextOut(10, 24, buf, 0x0020A0A0);
- }
- if (MessageList.timeleft) {
- if (RealTime>MessageList.timeleft) MessageList.timeleft = 0;
- ddTextOut(10, 10, MessageList.mtext, 0x0020A0A0);
- }
- if (ExitTime) {
- int y = WinH / 3;
- wsprintf(buf,"Preparing for evacuation...");
- ddTextOut(VideoCX - GetTextW(hdcCMain, buf)/2, y, buf, 0x0060C0D0);
- wsprintf(buf,"%d seconds left.", 1 + ExitTime / 1000);
- ddTextOut(VideoCX - GetTextW(hdcCMain, buf)/2, y + 18, buf, 0x0060C0D0);
- }
- }
- void ClipVector(CLIPPLANE& C, int vn)
- {
- int ClipRes = 0;
- float s,s1,s2;
- int vleft = (vn-1); if (vleft <0) vleft=vused-1;
- int vright = (vn+1); if (vright>=vused) vright=0;
-
- MulVectorsScal(cp[vn].ev.v, C.nv, s); /*s=SGN(s-0.01f);*/
- if (s>=0) return;
- MulVectorsScal(cp[vleft ].ev.v, C.nv, s1); /* s1=SGN(s1+0.01f); */ //s1+=0.0001f;
- MulVectorsScal(cp[vright].ev.v, C.nv, s2); /* s2=SGN(s2+0.01f); */ //s2+=0.0001f;
-
- if (s1>0) {
- ClipRes+=1;
- /*
- CalcHitPoint(C,cp[vn].ev.v,
- cp[vleft].ev.v, hleft.ev.v);
- float ll = VectorLength(SubVectors(cp[vleft].ev.v, cp[vn].ev.v));
- float lc = VectorLength(SubVectors(hleft.ev.v, cp[vn].ev.v));
- lc = lc / ll;
- */
- float lc = -s / (s1-s);
- hleft.ev.v.x = cp[vn].ev.v.x + ((cp[vleft].ev.v.x - cp[vn].ev.v.x) * lc);
- hleft.ev.v.y = cp[vn].ev.v.y + ((cp[vleft].ev.v.y - cp[vn].ev.v.y) * lc);
- hleft.ev.v.z = cp[vn].ev.v.z + ((cp[vleft].ev.v.z - cp[vn].ev.v.z) * lc);
- hleft.tx = cp[vn].tx + ((cp[vleft].tx - cp[vn].tx) * lc);
- hleft.ty = cp[vn].ty + ((cp[vleft].ty - cp[vn].ty) * lc);
- hleft.ev.Light = cp[vn].ev.Light + (int)((cp[vleft].ev.Light - cp[vn].ev.Light) * lc);
- hleft.ev.ALPHA = cp[vn].ev.ALPHA + (int)((cp[vleft].ev.ALPHA - cp[vn].ev.ALPHA) * lc);
- hleft.ev.Fog = cp[vn].ev.Fog + ((cp[vleft].ev.Fog - cp[vn].ev.Fog ) * lc);
- }
- if (s2>0) {
- ClipRes+=2;
- /*
- CalcHitPoint(C,cp[vn].ev.v,
- cp[vright].ev.v, hright.ev.v);
- float ll = VectorLength(SubVectors(cp[vright].ev.v, cp[vn].ev.v));
- float lc = VectorLength(SubVectors(hright.ev.v, cp[vn].ev.v));
- lc = lc / ll;*/
- float lc = -s / (s2-s);
- hright.ev.v.x = cp[vn].ev.v.x + ((cp[vright].ev.v.x - cp[vn].ev.v.x) * lc);
- hright.ev.v.y = cp[vn].ev.v.y + ((cp[vright].ev.v.y - cp[vn].ev.v.y) * lc);
- hright.ev.v.z = cp[vn].ev.v.z + ((cp[vright].ev.v.z - cp[vn].ev.v.z) * lc);
- hright.tx = cp[vn].tx + ((cp[vright].tx - cp[vn].tx) * lc);
- hright.ty = cp[vn].ty + ((cp[vright].ty - cp[vn].ty) * lc);
- hright.ev.Light = cp[vn].ev.Light + (int)((cp[vright].ev.Light - cp[vn].ev.Light) * lc);
- hright.ev.ALPHA = cp[vn].ev.ALPHA + (int)((cp[vright].ev.ALPHA - cp[vn].ev.ALPHA) * lc);
- hright.ev.Fog = cp[vn].ev.Fog + ((cp[vright].ev.Fog - cp[vn].ev.Fog ) * lc);
- }
- if (ClipRes == 0) {
- u--; vused--;
- cp[vn] = cp[vn+1];
- cp[vn+1] = cp[vn+2];
- cp[vn+2] = cp[vn+3];
- cp[vn+3] = cp[vn+4];
- cp[vn+4] = cp[vn+5];
- cp[vn+5] = cp[vn+6];
- //memcpy(&cp[vn], &cp[vn+1], (15-vn)*sizeof(ClipPoint));
- }
- if (ClipRes == 1) {cp[vn] = hleft; }
- if (ClipRes == 2) {cp[vn] = hright;}
- if (ClipRes == 3) {
- u++; vused++;
- //memcpy(&cp[vn+1], &cp[vn], (15-vn)*sizeof(ClipPoint));
- cp[vn+6] = cp[vn+5];
- cp[vn+5] = cp[vn+4];
- cp[vn+4] = cp[vn+3];
- cp[vn+3] = cp[vn+2];
- cp[vn+2] = cp[vn+1];
- cp[vn+1] = cp[vn];
-
- cp[vn] = hleft;
- cp[vn+1] = hright;
- }
- }
- void DrawTPlaneClip(BOOL SECONT)
- {
- if (!WATERREVERSE) {
- MulVectorsVect(SubVectors(ev[1].v, ev[0].v), SubVectors(ev[2].v, ev[0].v), nv);
- if (nv.x*ev[0].v.x + nv.y*ev[0].v.y + nv.z*ev[0].v.z<0) return;
- }
- cp[0].ev = ev[0]; cp[1].ev = ev[1]; cp[2].ev = ev[2];
- if (ReverseOn)
- if (SECONT) {
- switch (TDirection) {
- case 0:
- cp[0].tx = TCMIN; cp[0].ty = TCMAX;
- cp[1].tx = TCMAX; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMAX;
- break;
- case 1:
- cp[0].tx = TCMAX; cp[0].ty = TCMAX;
- cp[1].tx = TCMIN; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMIN;
- break;
- case 2:
- cp[0].tx = TCMAX; cp[0].ty = TCMIN;
- cp[1].tx = TCMIN; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMIN;
- break;
- case 3:
- cp[0].tx = TCMIN; cp[0].ty = TCMIN;
- cp[1].tx = TCMAX; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMAX;
- break;
- }
- } else {
- switch (TDirection) {
- case 0:
- cp[0].tx = TCMIN; cp[0].ty = TCMIN;
- cp[1].tx = TCMAX; cp[1].ty = TCMIN;
- cp[2].tx = TCMIN; cp[2].ty = TCMAX;
- break;
- case 1:
- cp[0].tx = TCMIN; cp[0].ty = TCMAX;
- cp[1].tx = TCMIN; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMAX;
- break;
- case 2:
- cp[0].tx = TCMAX; cp[0].ty = TCMAX;
- cp[1].tx = TCMIN; cp[1].ty = TCMAX;
- cp[2].tx = TCMAX; cp[2].ty = TCMIN;
- break;
- case 3:
- cp[0].tx = TCMAX; cp[0].ty = TCMIN;
- cp[1].tx = TCMAX; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMIN;
- break;
- }
- }
- else
- if (SECONT) {
- switch (TDirection) {
- case 0:
- cp[0].tx = TCMIN; cp[0].ty = TCMIN;
- cp[1].tx = TCMAX; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMAX;
- break;
- case 1:
- cp[0].tx = TCMIN; cp[0].ty = TCMAX;
- cp[1].tx = TCMAX; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMAX;
- break;
- case 2:
- cp[0].tx = TCMAX; cp[0].ty = TCMAX;
- cp[1].tx = TCMIN; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMIN;
- break;
- case 3:
- cp[0].tx = TCMAX; cp[0].ty = TCMIN;
- cp[1].tx = TCMIN; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMIN;
- break;
- }
- } else {
- switch (TDirection) {
- case 0:
- cp[0].tx = TCMIN; cp[0].ty = TCMIN;
- cp[1].tx = TCMAX; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMAX;
- break;
- case 1:
- cp[0].tx = TCMIN; cp[0].ty = TCMAX;
- cp[1].tx = TCMIN; cp[1].ty = TCMIN;
- cp[2].tx = TCMAX; cp[2].ty = TCMIN;
- break;
- case 2:
- cp[0].tx = TCMAX; cp[0].ty = TCMAX;
- cp[1].tx = TCMIN; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMIN;
- break;
- case 3:
- cp[0].tx = TCMAX; cp[0].ty = TCMIN;
- cp[1].tx = TCMAX; cp[1].ty = TCMAX;
- cp[2].tx = TCMIN; cp[2].ty = TCMAX;
- break;
- }
- }
-
- vused = 3;
- for (u=0; u<vused; u++) cp[u].ev.v.z+=16.0f;
- for (u=0; u<vused; u++) ClipVector(ClipZ,u);
- for (u=0; u<vused; u++) cp[u].ev.v.z-=16.0f;
- if (vused<3) return;
- for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) return;
- for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) return;
- for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) return;
- for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) return;
-
- for (u=0; u<vused; u++) {
- cp[u].ev.scrx = VideoCXf - cp[u].ev.v.x / cp[u].ev.v.z * CameraW;
- cp[u].ev.scry = VideoCYf + cp[u].ev.v.y / cp[u].ev.v.z * CameraH;
- }
-
-
- if (!lpVertexG)
- d3dStartBufferG();
-
- if (GVCnt>380) {
- if (lpVertexG) d3dEndBufferG(FALSE);
- d3dStartBufferG();
- }
- if (hGTexture!=hTexture) {
- hGTexture=hTexture;
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 1;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- lpwTriCount = &(lpInstructionG->wCount);
- lpInstructionG->bOpcode = D3DOP_TRIANGLE;
- lpInstructionG->bSize = sizeof(D3DTRIANGLE);
- lpInstructionG->wCount = 0;
- lpInstructionG++;
-
- }
-
- lpTriangle = (LPD3DTRIANGLE)lpInstructionG;
- for (u=0; u<vused-2; u++) {
- lpVertexG->sx = (float)cp[0].ev.scrx;
- lpVertexG->sy = (float)cp[0].ev.scry;
- lpVertexG->sz = _ZSCALE / cp[0].ev.v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(cp[0].ev.Light) * 0x00010101 | ((int)cp[0].ev.ALPHA<<24);
- lpVertexG->specular = (255-(int)cp[0].ev.Fog)<<24;//0x7F000000;
- lpVertexG->tu = (float)(cp[0].tx);// / (128.f*65536.f);
- lpVertexG->tv = (float)(cp[0].ty);// / (128.f*65536.f);
- lpVertexG++;
- lpVertexG->sx = (float)cp[u+1].ev.scrx;
- lpVertexG->sy = (float)cp[u+1].ev.scry;
- lpVertexG->sz = _ZSCALE / cp[u+1].ev.v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(cp[u+1].ev.Light) * 0x00010101 | ((int)cp[u+1].ev.ALPHA<<24);
- lpVertexG->specular = (255-(int)cp[u+1].ev.Fog)<<24;//0x7F000000;
- lpVertexG->tu = (float)(cp[u+1].tx);// / (128.f*65536.f);
- lpVertexG->tv = (float)(cp[u+1].ty);// / (128.f*65536.f);
- lpVertexG++;
- lpVertexG->sx = (float)cp[u+2].ev.scrx;
- lpVertexG->sy = (float)cp[u+2].ev.scry;
- lpVertexG->sz = _ZSCALE / cp[u+2].ev.v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(cp[u+2].ev.Light) * 0x00010101 | ((int)cp[u+2].ev.ALPHA<<24);
- lpVertexG->specular = (255-(int)cp[u+2].ev.Fog)<<24;//0x7F000000;
- lpVertexG->tu = (float)(cp[u+2].tx);// / (128.f*65536.f);
- lpVertexG->tv = (float)(cp[u+2].ty);// / (128.f*65536.f);
- lpVertexG++;
-
- lpTriangle->wV1 = GVCnt;
- lpTriangle->wV2 = GVCnt+1;
- lpTriangle->wV3 = GVCnt+2;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- *lpwTriCount = (*lpwTriCount) + 1;
- GVCnt+=3;
- }
-
- lpInstructionG = (LPD3DINSTRUCTION)lpTriangle;
- }
- void DrawTPlane(BOOL SECONT)
- {
- int n;
-
- //if (!WATERREVERSE) {
- MulVectorsVect(SubVectors(ev[1].v, ev[0].v), SubVectors(ev[2].v, ev[0].v), nv);
- if (nv.x*ev[0].v.x + nv.y*ev[0].v.y + nv.z*ev[0].v.z<0) return;
- //}
- Mask1=0x007F;
- for (n=0; n<3; n++) {
- if (ev[n].DFlags & 128) return;
- Mask1=Mask1 & ev[n].DFlags; }
- if (Mask1>0) return;
- if (ReverseOn)
- if (SECONT) {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- }
- } else {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- }
- }
- else
- if (SECONT) {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- }
- } else {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- }
- }
-
- int alpha1 = 255;
- int alpha2 = 255;
- int alpha3 = 255;
- //if (!WATERREVERSE)
-
- if (zs > (ctViewR-8)<<8) {
- int zz;
- zz = (int)VectorLength(ev[0].v) - 256 * (ctViewR-4);
- if (zz > 0) alpha1 = max(0, 255 - zz / 3); else alpha1 = 255;
-
- zz = (int)VectorLength(ev[1].v) - 256 * (ctViewR-4);
- if (zz > 0) alpha2 = max(0, 255 - zz / 3); else alpha2 = 255;
- zz = (int)VectorLength(ev[2].v) - 256 * (ctViewR-4);
- if (zz > 0) alpha3 = max(0, 255 - zz / 3); else alpha3 = 255;
- }
-
- if (!lpVertexG)
- d3dStartBufferG();
-
- if (GVCnt>380) {
- if (lpVertexG) d3dEndBufferG(FALSE);
- d3dStartBufferG();
- }
- lpVertexG->sx = (float)ev[0].scrx;
- lpVertexG->sy = (float)ev[0].scry;
- lpVertexG->sz = _ZSCALE / ev[0].v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(ev[0].Light) * 0x00010101 | alpha1<<24;
- lpVertexG->specular = (255-(int)ev[0].Fog)<<24;//0x7F000000;
- lpVertexG->tu = (float)(scrp[0].tx);// / (128.f*65536.f);
- lpVertexG->tv = (float)(scrp[0].ty);// / (128.f*65536.f);
- lpVertexG++;
- lpVertexG->sx = (float)ev[1].scrx;
- lpVertexG->sy = (float)ev[1].scry;
- lpVertexG->sz = _ZSCALE / ev[1].v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(ev[1].Light) * 0x00010101 | alpha2<<24;
- lpVertexG->specular = (255-(int)ev[1].Fog)<<24;//0x7F000000;
- lpVertexG->tu = (float)(scrp[1].tx);// / (128.f*65536.f);
- lpVertexG->tv = (float)(scrp[1].ty);// / (128.f*65536.f);
- lpVertexG++;
- lpVertexG->sx = (float)ev[2].scrx;
- lpVertexG->sy = (float)ev[2].scry;
- lpVertexG->sz = _ZSCALE / ev[2].v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(ev[2].Light) * 0x00010101 | alpha3<<24;
- lpVertexG->specular = (255-(int)ev[2].Fog)<<24;//0x7F000000;
- lpVertexG->tu = (float)(scrp[2].tx);// / (128.f*65536.f);
- lpVertexG->tv = (float)(scrp[2].ty);// / (128.f*65536.f);
- lpVertexG++;
- if (hGTexture!=hTexture) {
- hGTexture=hTexture;
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 1;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- lpwTriCount = (&lpInstructionG->wCount);
- lpInstructionG->bOpcode = D3DOP_TRIANGLE;
- lpInstructionG->bSize = sizeof(D3DTRIANGLE);
- lpInstructionG->wCount = 0;
- lpInstructionG++;
- }
-
- lpTriangle = (LPD3DTRIANGLE)lpInstructionG;
- lpTriangle->wV1 = GVCnt;
- lpTriangle->wV2 = GVCnt+1;
- lpTriangle->wV3 = GVCnt+2;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- *lpwTriCount = (*lpwTriCount) + 1;
- lpInstructionG = (LPD3DINSTRUCTION)lpTriangle;
- GVCnt+=3;
- }
- void DrawTPlaneW(BOOL SECONT)
- {
- int n;
-
- Mask1=0x007F;
- for (n=0; n<3; n++) {
- if (ev[n].DFlags & 128) return;
- Mask1=Mask1 & ev[n].DFlags; }
- if (Mask1>0) return;
- /*
- for (n=0; n<3; n++) {
- scrp[n].x = (float)(VideoCX) - (ev[n].v.x / ev[n].v.z * CameraW);
- scrp[n].y = (float)(VideoCY) + (ev[n].v.y / ev[n].v.z * CameraH);
- scrp[n].Light = ev[n].Light;
- } */
- if (ReverseOn)
- if (SECONT) {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- }
- } else {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- }
- }
- else
- if (SECONT) {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- }
- } else {
- switch (TDirection) {
- case 0:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMAX;
- break;
- case 1:
- scrp[0].tx = TCMIN; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMIN;
- scrp[2].tx = TCMAX; scrp[2].ty = TCMIN;
- break;
- case 2:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMAX;
- scrp[1].tx = TCMIN; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMIN;
- break;
- case 3:
- scrp[0].tx = TCMAX; scrp[0].ty = TCMIN;
- scrp[1].tx = TCMAX; scrp[1].ty = TCMAX;
- scrp[2].tx = TCMIN; scrp[2].ty = TCMAX;
- break;
- }
- }
-
- if (!UNDERWATER)
- if (zs > (ctViewR-8)<<8) {
- float zz;
- zz = VectorLength(ev[0].v) - 256 * (ctViewR-4);
- if (zz > 0) ev[0].ALPHA = max(0.f,255.f - zz / 3.f);
-
- zz = VectorLength(ev[1].v) - 256 * (ctViewR-4);
- if (zz > 0) ev[1].ALPHA = max(0.f, 255.f - zz / 3.f);
- zz = VectorLength(ev[2].v) - 256 * (ctViewR-4);
- if (zz > 0) ev[2].ALPHA = max(0,255.f - zz / 3.f);
- }
-
- if (!lpVertexG)
- d3dStartBufferG();
-
- if (GVCnt>380) {
- if (lpVertexG) d3dEndBufferG(FALSE);
- d3dStartBufferG();
- }
- lpVertexG->sx = (float)ev[0].scrx;
- lpVertexG->sy = (float)ev[0].scry;
- lpVertexG->sz = _ZSCALE / ev[0].v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(ev[0].Light) * 0x00010101 | ev[0].ALPHA<<24;
- lpVertexG->specular = (255-(int)ev[0].Fog)<<24;
- lpVertexG->tu = (float)(scrp[0].tx);
- lpVertexG->tv = (float)(scrp[0].ty);
- lpVertexG++;
- lpVertexG->sx = (float)ev[1].scrx;
- lpVertexG->sy = (float)ev[1].scry;
- lpVertexG->sz = _ZSCALE / ev[1].v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(ev[1].Light) * 0x00010101 | ev[1].ALPHA<<24;
- lpVertexG->specular = (255-(int)ev[1].Fog)<<24;
- lpVertexG->tu = (float)(scrp[1].tx);
- lpVertexG->tv = (float)(scrp[1].ty);
- lpVertexG++;
- lpVertexG->sx = (float)ev[2].scrx;
- lpVertexG->sy = (float)ev[2].scry;
- lpVertexG->sz = _ZSCALE / ev[2].v.z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = (int)(ev[2].Light) * 0x00010101 | ev[2].ALPHA<<24;
- lpVertexG->specular = (255-(int)ev[2].Fog)<<24;
- lpVertexG->tu = (float)(scrp[2].tx);
- lpVertexG->tv = (float)(scrp[2].ty);
- lpVertexG++;
- if (hGTexture!=hTexture) {
- hGTexture=hTexture;
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 1;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- lpwTriCount = (&lpInstructionG->wCount);
- lpInstructionG->bOpcode = D3DOP_TRIANGLE;
- lpInstructionG->bSize = sizeof(D3DTRIANGLE);
- lpInstructionG->wCount = 0;
- lpInstructionG++;
- }
-
- lpTriangle = (LPD3DTRIANGLE)lpInstructionG;
- lpTriangle->wV1 = GVCnt;
- lpTriangle->wV2 = GVCnt+1;
- lpTriangle->wV3 = GVCnt+2;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- *lpwTriCount = (*lpwTriCount) + 1;
- lpInstructionG = (LPD3DINSTRUCTION)lpTriangle;
- GVCnt+=3;
- }
- void _RenderObject(int x, int y)
- {
- int ob = OMap[y][x];
- if (!MObjects[ob].model) {
- //return;
- wsprintf(logt,"Incorrect model at [%d][%d]!", x, y);
- DoHalt(logt);
- }
- //int mlight = -(RandomMap[y & 31][x & 31] >> 5) + (LMap[y][x]>>1) + 96;
- int FI = (FMap[y][x] >> 2) & 3;
- float fi = CameraAlpha + (float)(FI * 2.f*pi / 4.f);
- int mlight;
- if (MObjects[ob].info.flags & ofDEFLIGHT)
- mlight = MObjects[ob].info.DefLight; else
- if (MObjects[ob].info.flags & ofGRNDLIGHT)
- {
- mlight = 128;
- CalcModelGroundLight(MObjects[ob].model, x*256+128, y*256+128, FI);
- FI = 0;
- }
- else
- mlight = -(RandomMap[y & 31][x & 31] >> 5) + (LMap[y][x]>>1) + 96;
- if (mlight >192) mlight =192;
- if (mlight < 64) mlight = 64;
-
- v[0].x = x*256+128 - CameraX;
- v[0].z = y*256+128 - CameraZ;
- v[0].y = (float)(HMapO[y][x]) * ctHScale - CameraY;
- float zs = VectorLength(v[0]);
- //if (v[0].y + MObjects[ob].info.YHi < (int)(HMap[y][x]+HMap[y+1][x+1]) / 2 * ctHScale - CameraY) return;
-
- CalcFogLevel_Gradient(v[0]);
-
-
- v[0] = RotateVector(v[0]);
- GlassL = 0;
-
- if (zs > 256 * (ctViewR-8))
- GlassL=min(255,(int)(zs - 256 * (ctViewR-8)) / 4);
- if (GlassL==255) return;
-
- if (MObjects[ob].info.flags & ofANIMATED)
- if (MObjects[ob].info.LastAniTime!=RealTime) {
- MObjects[ob].info.LastAniTime=RealTime;
- CreateMorphedObject(MObjects[ob].model,
- MObjects[ob].vtl,
- RealTime % MObjects[ob].vtl.AniTime);
- }
-
- if (MObjects[ob].info.flags & ofNOBMP) zs = 0;
- /*
- if (!NeedWater && zs>ctViewRM*256 && zs<(ctViewRM+1)*256) {
- GlassL = 255-(int)(zs - ctViewRM*256);
- RenderBMPModel(&MObjects[ob].bmpmodel, v[0].x, v[0].y, v[0].z, mlight-32);
- GlassL=255-GlassL;
- RenderModel(MObjects[ob].model, v[0].x, v[0].y, v[0].z, mlight, FI, fi, CameraBeta);
- } else */
- if (zs>ctViewRM*256)
- RenderBMPModel(&MObjects[ob].bmpmodel, v[0].x, v[0].y, v[0].z, mlight-16);
- else
- if (v[0].z<-256*8)
- RenderModel(MObjects[ob].model, v[0].x, v[0].y, v[0].z, mlight, FI, fi, CameraBeta);
- else
- RenderModelClip(MObjects[ob].model, v[0].x, v[0].y, v[0].z, mlight, FI, fi, CameraBeta);
-
- }
- void RenderObject(int x, int y)
- {
- if (OMap[y][x]==255) return;
- if (!MODELS) return;
- if (ORLCount>2000) return;
- ORList[ORLCount].x = x;
- ORList[ORLCount].y = y;
- ORLCount++;
- }
- void RenderModelsList()
- {
- d3dEndBufferG(FALSE);
- for (int o=0; o<ORLCount; o++)
- _RenderObject(ORList[o].x, ORList[o].y);
- ORLCount=0;
- d3dEndBufferG(TRUE);
- }
- void ProcessMap(int x, int y, int r)
- {
- //WATERREVERSE = FALSE;
- if (x>=ctMapSize-1 || y>=ctMapSize-1 ||
- x<0 || y<0) return;
- float BackR = BackViewR;
- if (OMap[y][x]!=255) BackR+=MObjects[OMap[y][x]].info.BoundR;
- ev[0] = VMap[y-CCY+128][x-CCX+128];
- if (ev[0].v.z>BackR) return;
-
- int t1 = TMap1[y][x];
- ReverseOn = (FMap[y][x] & fmReverse);
- TDirection = (FMap[y][x] & 3);
-
- x = x - CCX + 128;
- y = y - CCY + 128;
- ev[1] = VMap[y][x+1];
- if (ReverseOn) ev[2] = VMap[y+1][x];
- else ev[2] = VMap[y+1][x+1];
- //Mask1=0x007F;
- //for (n=0; n<3; n++) Mask1&=ev[n].DFlags;
- //if (Mask1) return;
-
- float xx = (ev[0].v.x + VMap[y+1][x+1].v.x) / 2;
- float yy = (ev[0].v.y + VMap[y+1][x+1].v.y) / 2;
- float zz = (ev[0].v.z + VMap[y+1][x+1].v.z) / 2;
- if ( fabs(xx*FOVK) > -zz + BackR) return;
-
-
- zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
-
- /*
- if (MIPMAP && (zs > 256 * 10 && t1 || LOWRESTX)) d3dSetTexture(Textures[t1]->DataB, 64, 64);
- else d3dSetTexture(Textures[t1]->DataA, 128, 128);
- */
- if (!LOWRESTX) {
- if (zs > 256 * 20) d3dSetTexture(Textures[t1]->DataC, 32, 32); else
- if (zs > 256 * 10) d3dSetTexture(Textures[t1]->DataB, 64, 64);
- else d3dSetTexture(Textures[t1]->DataA, 128, 128);
- } else {
- if (zs > 256 * 10) d3dSetTexture(Textures[t1]->DataC, 32, 32);
- else d3dSetTexture(Textures[t1]->DataB, 64, 64);
- }
- if (r>8) DrawTPlane(FALSE);
- else DrawTPlaneClip(FALSE);
- if (ReverseOn) { ev[0] = ev[2]; ev[2] = VMap[y+1][x+1]; }
- else { ev[1] = ev[2]; ev[2] = VMap[y+1][x]; }
- if (r>8) DrawTPlane(TRUE);
- else DrawTPlaneClip(TRUE);
-
- x = x + CCX - 128;
- y = y + CCY - 128;
- if (OMap[y][x]==255) return;
-
- if (zz<BackR)
- RenderObject(x, y);
- }
- void ProcessMap2(int x, int y, int r)
- {
- //WATERREVERSE = FALSE;
- if (x>=ctMapSize-1 || y>=ctMapSize-1 ||
- x<0 || y<0) return;
- ev[0] = VMap[y-CCY+128][x-CCX+128];
- if (ev[0].v.z>BackViewR) return;
-
- int t1 = TMap2[y][x];
- TDirection = ((FMap[y][x]>>8) & 3);
- ReverseOn = FALSE;
-
- x = x - CCX + 128;
- y = y - CCY + 128;
- ev[1] = VMap[y][x+2];
- if (ReverseOn) ev[2] = VMap[y+2][x];
- else ev[2] = VMap[y+2][x+2];
-
- float xx = (ev[0].v.x + VMap[y+2][x+2].v.x) / 2;
- float yy = (ev[0].v.y + VMap[y+2][x+2].v.y) / 2;
- float zz = (ev[0].v.z + VMap[y+2][x+2].v.z) / 2;
- if ( fabs(xx*FOVK) > -zz + BackViewR) return;
-
- zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
- if (zs>ctViewR*256) return;
-
- d3dSetTexture(Textures[t1]->DataB, 64, 64);
- DrawTPlane(FALSE);
-
- if (ReverseOn) { ev[0] = ev[2]; ev[2] = VMap[y+2][x+2]; }
- else { ev[1] = ev[2]; ev[2] = VMap[y+2][x]; }
- DrawTPlane(TRUE);
-
-
- x = x + CCX - 128;
- y = y + CCY - 128;
- RenderObject(x , y);
- RenderObject(x+1, y);
- RenderObject(x , y+1);
- RenderObject(x+1, y+1);
- }
- void ProcessMapW(int x, int y, int r)
- {
- if (!( (FMap[y ][x ] & fmWaterA) &&
- (FMap[y ][x+1] & fmWaterA) &&
- (FMap[y+1][x ] & fmWaterA) &&
- (FMap[y+1][x+1] & fmWaterA) )) return;
-
- WATERREVERSE = TRUE;
- int t1 = WaterList[ WMap[y][x] ].tindex;
- ev[0] = VMap2[y-CCY+128][x-CCX+128];
- if (ev[0].v.z>BackViewR) return;
-
- ReverseOn = FALSE;
- TDirection = 0;
-
- x = x - CCX + 128;
- y = y - CCY + 128;
- ev[1] = VMap2[y][x+1];
- ev[2] = VMap2[y+1][x+1];
-
- float xx = (ev[0].v.x + VMap2[y+1][x+1].v.x) / 2;
- float yy = (ev[0].v.y + VMap2[y+1][x+1].v.y) / 2;
- float zz = (ev[0].v.z + VMap2[y+1][x+1].v.z) / 2;
-
- if ( fabs(xx*FOVK) > -zz + BackViewR) return;
-
- zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
- if (zs > ctViewR*256) return;
- /*
- if (MIPMAP && (zs > 256 * 10 && t1 || LOWRESTX)) d3dSetTexture(Textures[t1]->DataB, 64, 64);
- else d3dSetTexture(Textures[t1]->DataA, 128, 128);
- */
- if (!LOWRESTX) {
- if (zs > 256 * 20) d3dSetTexture(Textures[t1]->DataC, 32, 32); else
- if (zs > 256 * 10) d3dSetTexture(Textures[t1]->DataB, 64, 64);
- else d3dSetTexture(Textures[t1]->DataA, 128, 128);
- } else {
- if (zs > 256 * 10) d3dSetTexture(Textures[t1]->DataC, 32, 32);
- else d3dSetTexture(Textures[t1]->DataB, 64, 64);
- }
- if (r>8) DrawTPlaneW(FALSE);
- else DrawTPlaneClip(FALSE);
-
- ev[1] = ev[2]; ev[2] = VMap2[y+1][x];
-
- if (r>8) DrawTPlaneW(TRUE);
- else DrawTPlaneClip(TRUE);
- WATERREVERSE = FALSE;
- }
- void ProcessMapW2(int x, int y, int r)
- {
- if (!( (FMap[y ][x ] & fmWaterA) &&
- (FMap[y ][x+2] & fmWaterA) &&
- (FMap[y+2][x ] & fmWaterA) &&
- (FMap[y+2][x+2] & fmWaterA) )) return;
-
- int t1 = WaterList[ WMap[y][x] ].tindex;
- ev[0] = VMap2[y-CCY+128][x-CCX+128];
- if (ev[0].v.z>BackViewR) return;
-
- //WATERREVERSE = TRUE;
- ReverseOn = FALSE;
- TDirection = 0;
-
- x = x - CCX + 128;
- y = y - CCY + 128;
- ev[1] = VMap2[y][x+2];
- ev[2] = VMap2[y+2][x+2];
-
- float xx = (ev[0].v.x + VMap2[y+2][x+2].v.x) / 2;
- float yy = (ev[0].v.y + VMap2[y+2][x+2].v.y) / 2;
- float zz = (ev[0].v.z + VMap2[y+2][x+2].v.z) / 2;
-
- if ( fabs(xx*FOVK) > -zz + BackViewR) return;
-
- zs = (int)sqrt( xx*xx + zz*zz + yy*yy);
- if (zs > ctViewR*256) return;
-
-
- d3dSetTexture(Textures[t1]->DataB, 64, 64);
-
- DrawTPlaneW(FALSE);
- ev[1] = ev[2]; ev[2] = VMap2[y+2][x];
-
- DrawTPlaneW(TRUE);
- }
- void RenderGround()
- {
- for (r=ctViewR; r>=ctViewR1; r-=2) {
-
- for (int x=r; x>0; x-=2) {
- ProcessMap2(CCX-x, CCY+r, r);
- ProcessMap2(CCX+x, CCY+r, r);
- ProcessMap2(CCX-x, CCY-r, r);
- ProcessMap2(CCX+x, CCY-r, r);
- }
-
- ProcessMap2(CCX, CCY-r, r);
- ProcessMap2(CCX, CCY+r, r);
- for (int y=r-2; y>0; y-=2) {
- ProcessMap2(CCX+r, CCY-y, r);
- ProcessMap2(CCX+r, CCY+y, r);
- ProcessMap2(CCX-r, CCY+y, r);
- ProcessMap2(CCX-r, CCY-y, r);
- }
- ProcessMap2(CCX-r, CCY, r);
- ProcessMap2(CCX+r, CCY, r);
-
- }
-
- r = ctViewR1-1;
- for (int x=r; x>-r; x--) {
- ProcessMap(CCX+r, CCY+x, r);
- ProcessMap(CCX+x, CCY+r, r);
- }
- for (r=ctViewR1-2; r>0; r--) {
-
- for (int x=r; x>0; x--) {
- ProcessMap(CCX-x, CCY+r, r);
- ProcessMap(CCX+x, CCY+r, r);
- ProcessMap(CCX-x, CCY-r, r);
- ProcessMap(CCX+x, CCY-r, r);
- }
-
- ProcessMap(CCX, CCY-r, r);
- ProcessMap(CCX, CCY+r, r);
- for (int y=r-1; y>0; y--) {
- ProcessMap(CCX+r, CCY-y, r);
- ProcessMap(CCX+r, CCY+y, r);
- ProcessMap(CCX-r, CCY+y, r);
- ProcessMap(CCX-r, CCY-y, r);
- }
- ProcessMap(CCX-r, CCY, r);
- ProcessMap(CCX+r, CCY, r);
-
- }
- ProcessMap(CCX, CCY, 0);
- }
- void RenderWCircles()
- {
-
- TWCircle *wptr;
- Vector3d rpos;
- for (int c=0; c<WCCount; c++) {
-
- wptr = &WCircles[c];
- rpos.x = wptr->pos.x - CameraX;
- rpos.y = wptr->pos.y - CameraY;
- rpos.z = wptr->pos.z - CameraZ;
- float r = (float)max( fabs(rpos.x), fabs(rpos.z) );
- int ri = -1 + (int)(r / 256.f + 0.4f);
- if (ri < 0) ri = 0;
- if (ri > ctViewR) continue;
- rpos = RotateVector(rpos);
- if ( rpos.z > BackViewR) continue;
- if ( fabs(rpos.x) > -rpos.z + BackViewR ) continue;
- if ( fabs(rpos.y) > -rpos.z + BackViewR ) continue;
-
- GlassL = 255 - (2000-wptr->FTime) / 38;
- CreateMorphedModel(WCircleModel.mptr, &WCircleModel.Animation[0], (int)(wptr->FTime), wptr->scale);
- if ( fabs(rpos.z) + fabs(rpos.x) < 1000)
- RenderModelClip(WCircleModel.mptr,
- rpos.x, rpos.y, rpos.z, 250, 0, 0, CameraBeta);
- else
- RenderModel(WCircleModel.mptr,
- rpos.x, rpos.y, rpos.z, 250, 0, 0, CameraBeta);
- }
- GlassL = 0;
- }
- void RenderWater()
- {
- SetRenderStates(FALSE, D3DBLEND_INVSRCALPHA);
-
- for (int r=ctViewR; r>=ctViewR1; r-=2) {
-
- for (int x=r; x>0; x-=2) {
- ProcessMapW2(CCX-x, CCY+r, r);
- ProcessMapW2(CCX+x, CCY+r, r);
- ProcessMapW2(CCX-x, CCY-r, r);
- ProcessMapW2(CCX+x, CCY-r, r);
- }
-
- ProcessMapW2(CCX, CCY-r, r);
- ProcessMapW2(CCX, CCY+r, r);
- for (int y=r-2; y>0; y-=2) {
- ProcessMapW2(CCX+r, CCY-y, r);
- ProcessMapW2(CCX+r, CCY+y, r);
- ProcessMapW2(CCX-r, CCY+y, r);
- ProcessMapW2(CCX-r, CCY-y, r);
- }
- ProcessMapW2(CCX-r, CCY, r);
- ProcessMapW2(CCX+r, CCY, r);
- }
- for (int y=-ctViewR1+2; y<ctViewR1; y++)
- for (int x=-ctViewR1+2; x<ctViewR1; x++)
- ProcessMapW(CCX+x, CCY+y, max(abs(x), abs(y)));
-
- d3dEndBufferG(FALSE);
- FogYBase = 0;
- SetRenderStates(FALSE, D3DBLEND_ONE);
- RenderWCircles();
- SetRenderStates(TRUE, D3DBLEND_INVSRCALPHA);
- }
- void RenderPoint(float cx, float cy, float z, float _R, DWORD RGBA, DWORD RGBA2)
- {
- /*
- RGBA = (RGBA & 0xFF00FF00) + ((RGBA & 0x000000FF)<<16) + ((RGBA & 0x00FF0000)>>16);
- RGBA2= (RGBA2 & 0xFF00FF00) + ((RGBA2 & 0x000000FF)<<16) + ((RGBA2 & 0x00FF0000)>>16);
- */
- float R = (float)((int)( _R*16.f)) / 16.f;
- float R2= (float)((int)(0.6f* _R*16.f)) / 16.f;
- float sz = _ZSCALE / z;
- if (R>1) R=1;
- DWORD A = (int)(((RGBA>>25) + (RGBA2>>25)) * R);
- RGBA = (RGBA & 0x00FFFFFF) | (A<<24);
-
- lpVertex->sx = cx;
- lpVertex->sy = cy-R2;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx-R2;
- lpVertex->sy = cy+R2;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx+R2;
- lpVertex->sy = cy+R2;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 1
- }
- void RenderCircle(float cx, float cy, float z, float _R, DWORD RGBA, DWORD RGBA2)
- {
- /*
- RGBA = (RGBA & 0xFF00FF00) + ((RGBA & 0x000000FF)<<16) + ((RGBA & 0x00FF0000)>>16);
- RGBA2= (RGBA2 & 0xFF00FF00) + ((RGBA2 & 0x000000FF)<<16) + ((RGBA2 & 0x00FF0000)>>16);
- */
- float R = (float)((int)( _R*16.f)) / 16.f;
- float R2 = (float)((int)(0.65f*_R*16.f)) / 16.f;
- float sz = _ZSCALE / z;
-
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx;
- lpVertex->sy = cy-R;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx+R2;
- lpVertex->sy = cy-R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 1
-
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
-
- lpVertex->sx = cx+R2;
- lpVertex->sy = cy-R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx+R;
- lpVertex->sy = cy;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 2
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
-
- lpVertex->sx = cx+R;
- lpVertex->sy = cy;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
-
- lpVertex->sx = cx+R2;
- lpVertex->sy = cy+R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 3
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx+R2;
- lpVertex->sy = cy+R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
-
- lpVertex->sx = cx;
- lpVertex->sy = cy+R;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 4
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx;
- lpVertex->sy = cy+R;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx-R2;
- lpVertex->sy = cy+R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 5
-
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx-R2;
- lpVertex->sy = cy+R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx-R;
- lpVertex->sy = cy;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 6
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx-R;
- lpVertex->sy = cy;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx-R2;
- lpVertex->sy = cy-R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 7
- lpVertex->sx = cx;
- lpVertex->sy = cy;
- lpVertex->color = RGBA;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx-R2;
- lpVertex->sy = cy-R2;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- lpVertex->sx = cx;
- lpVertex->sy = cy-R;
- lpVertex->color = RGBA2;
- lpVertex->specular = 0xFF000000; lpVertex->sz = sz; lpVertex->rhw = 1.f; lpVertex++;
- //================ 8
- }
- void BuildTreeNoSort()
- {
- Vector2di v[3];
- Current = -1;
- int LastFace = -1;
- TFace* fptr;
- int sg;
-
- for (int f=0; f<mptr->FCount; f++)
- {
- fptr = &mptr->gFace[f];
- v[0] = gScrp[fptr->v1];
- v[1] = gScrp[fptr->v2];
- v[2] = gScrp[fptr->v3];
- if (v[0].x == 0xFFFFFF) continue;
- if (v[1].x == 0xFFFFFF) continue;
- if (v[2].x == 0xFFFFFF) continue;
- if (fptr->Flags & (sfDarkBack+sfNeedVC)) {
- sg = (v[1].x-v[0].x)*(v[2].y-v[1].y) - (v[1].y-v[0].y)*(v[2].x-v[1].x);
- if (sg<0) continue;
- }
-
- fptr->Next=-1;
- if (Current==-1) { Current=f; LastFace = f; } else
- { mptr->gFace[LastFace].Next=f; LastFace=f; }
-
- }
- }
- void BuildTreeNoSortf()
- {
- Vector2df v[3];
- Current = -1;
- int LastFace = -1;
- TFace* fptr;
- int sg;
-
- for (int f=0; f<mptr->FCount; f++)
- {
- fptr = &mptr->gFace[f];
- v[0] = gScrpf[fptr->v1];
- v[1] = gScrpf[fptr->v2];
- v[2] = gScrpf[fptr->v3];
- if (v[0].x <-102300) continue;
- if (v[1].x <-102300) continue;
- if (v[2].x <-102300) continue;
- if (fptr->Flags & (sfDarkBack+sfNeedVC)) {
- sg = (v[1].x-v[0].x)*(v[2].y-v[1].y) - (v[1].y-v[0].y)*(v[2].x-v[1].x);
- if (sg<0) continue;
- }
-
- fptr->Next=-1;
- if (Current==-1) { Current=f; LastFace = f; } else
- { mptr->gFace[LastFace].Next=f; LastFace=f; }
-
- }
- }
- int BuildTreeClipNoSort()
- {
- Current = -1;
- int fc = 0;
- int LastFace = -1;
- TFace* fptr;
- for (int f=0; f<mptr->FCount; f++)
- {
- fptr = &mptr->gFace[f];
-
- if (fptr->Flags & (sfDarkBack + sfNeedVC) ) {
- MulVectorsVect(SubVectors(rVertex[fptr->v2], rVertex[fptr->v1]), SubVectors(rVertex[fptr->v3], rVertex[fptr->v1]), nv);
- if (nv.x*rVertex[fptr->v1].x + nv.y*rVertex[fptr->v1].y + nv.z*rVertex[fptr->v1].z<0) continue;
- }
- fc++;
- fptr->Next=-1;
- if (Current==-1) { Current=f; LastFace = f; } else
- { mptr->gFace[LastFace].Next=f; LastFace=f; }
-
- }
- return fc;
- }
- void RenderBMPModel(TBMPModel* mptr, float x0, float y0, float z0, int light)
- {
- if (fabs(y0) > -(z0-256*6)) return;
-
- int minx = 10241024;
- int maxx =-10241024;
- int miny = 10241024;
- int maxy =-10241024;
-
- BOOL FOGACTIVE = (FOGON && (FogYBase>0));
- for (int s=0; s<4; s++) {
- if (FOGACTIVE) {
- vFogT[s] = 255-(int) (FogYBase + mptr->gVertex[s].y * FogYGrad);
- if (vFogT[s]<0 ) vFogT[s] = 0;
- if (vFogT[s]>255) vFogT[s]=255;
- vFogT[s]<<=24;
- } else vFogT[s]=255<<24;
-
- rVertex[s].x = mptr->gVertex[s].x + x0;
- rVertex[s].y = mptr->gVertex[s].y * cb + y0;
- rVertex[s].z = mptr->gVertex[s].y * sb + z0;
- if (rVertex[s].z<-256) {
- gScrp[s].x = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
- gScrp[s].y = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
- } else return;
- if (gScrp[s].x > maxx) maxx = gScrp[s].x;
- if (gScrp[s].x < minx) minx = gScrp[s].x;
- if (gScrp[s].y > maxy) maxy = gScrp[s].y;
- if (gScrp[s].y < miny) miny = gScrp[s].y;
- }
- if (minx == 10241024) return;
- if (minx>WinW || maxx<0 || miny>WinH || maxy<0) return;
- int argb = light * 0x00010101 + ((255-GlassL)<<24);
-
- float d = (float) sqrt(x0*x0 + y0*y0 + z0*z0);
- d3dSetTexture(mptr->lpTexture, 128, 128);
-
- //d3dStartBuffer();
-
- if (!lpVertexG)
- d3dStartBufferGBMP();
-
- if (GVCnt>380) {
- if (lpVertexG) d3dEndBufferG(TRUE);
- d3dStartBufferGBMP();
- }
- lpVertexG->sx = (float)gScrp[0].x;
- lpVertexG->sy = (float)gScrp[0].y;
- lpVertexG->sz = _ZSCALE / rVertex[0].z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = argb;
- lpVertexG->specular = vFogT[0];
- lpVertexG->tu = (float)(0.0f);
- lpVertexG->tv = (float)(0.0f);
- lpVertexG++;
- lpVertexG->sx = (float)gScrp[1].x;
- lpVertexG->sy = (float)gScrp[1].y;
- lpVertexG->sz = _ZSCALE / rVertex[1].z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = argb;
- lpVertexG->specular = vFogT[1];
- lpVertexG->tu = (float)(0.995f);
- lpVertexG->tv = (float)(0.0f);
- lpVertexG++;
- lpVertexG->sx = (float)gScrp[2].x;
- lpVertexG->sy = (float)gScrp[2].y;
- lpVertexG->sz = _ZSCALE / rVertex[2].z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = argb;
- lpVertexG->specular = vFogT[2];
- lpVertexG->tu = (float)(0.995f);
- lpVertexG->tv = (float)(0.995f);
- lpVertexG++;
- //=========//
- lpVertexG->sx = (float)gScrp[0].x;
- lpVertexG->sy = (float)gScrp[0].y;
- lpVertexG->sz = _ZSCALE / rVertex[0].z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = argb;
- lpVertexG->specular = vFogT[0];
- lpVertexG->tu = (float)(0.0f);
- lpVertexG->tv = (float)(0.0f);
- lpVertexG++;
- lpVertexG->sx = (float)gScrp[2].x;
- lpVertexG->sy = (float)gScrp[2].y;
- lpVertexG->sz = _ZSCALE / rVertex[2].z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = argb;
- lpVertexG->specular = vFogT[2];
- lpVertexG->tu = (float)(0.995f);
- lpVertexG->tv = (float)(0.995f);
- lpVertexG++;
- lpVertexG->sx = (float)gScrp[3].x;
- lpVertexG->sy = (float)gScrp[3].y;
- lpVertexG->sz = _ZSCALE / rVertex[3].z;
- lpVertexG->rhw = lpVertexG->sz * _AZSCALE;
- lpVertexG->color = argb;
- lpVertexG->specular = vFogT[3];
- lpVertexG->tu = (float)(0.0f);
- lpVertexG->tv = (float)(0.995f);
- lpVertexG++;
- //d3dFlushBuffer(0, 2);
-
- if (hGTexture!=hTexture) {
- hGTexture=hTexture;
- lpInstructionG->bOpcode = D3DOP_STATERENDER;
- lpInstructionG->bSize = sizeof(D3DSTATE);
- lpInstructionG->wCount = 1;
- lpInstructionG++;
- lpState = (LPD3DSTATE)lpInstructionG;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
- lpInstructionG = (LPD3DINSTRUCTION)lpState;
- lpwTriCount = (&lpInstructionG->wCount);
- lpInstructionG->bOpcode = D3DOP_TRIANGLE;
- lpInstructionG->bSize = sizeof(D3DTRIANGLE);
- lpInstructionG->wCount = 0;
- lpInstructionG++;
- }
-
- lpTriangle = (LPD3DTRIANGLE)lpInstructionG;
- lpTriangle->wV1 = GVCnt;
- lpTriangle->wV2 = GVCnt+1;
- lpTriangle->wV3 = GVCnt+2;
- lpTriangle->wFlags = 0;
- lpTriangle++;
-
- lpTriangle->wV1 = GVCnt+3;
- lpTriangle->wV2 = GVCnt+4;
- lpTriangle->wV3 = GVCnt+5;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- *lpwTriCount = (*lpwTriCount) + 2;
- lpInstructionG = (LPD3DINSTRUCTION)lpTriangle;
- GVCnt+=6;
- }
- void RenderModel(TModel* _mptr, float x0, float y0, float z0, int light, int VT, float al, float bt)
- {
- int f;
-
- if (fabs(y0) > -(z0-256*6)) return;
- mptr = _mptr;
-
- float ca = (float)f_cos(al);
- float sa = (float)f_sin(al);
-
- float cb = (float)f_cos(bt);
- float sb = (float)f_sin(bt);
- float minx = 10241024;
- float maxx =-10241024;
- float miny = 10241024;
- float maxy =-10241024;
- BOOL FOGACTIVE = (FOGON && (FogYBase>0));
- int alphamask = (255-GlassL)<<24;
- int ml = light;
-
- TPoint3d p;
- for (int s=0; s<mptr->VCount; s++) {
- p = mptr->gVertex[s];
- if (FOGACTIVE) {
- vFogT[s] = 255-(int)(FogYBase + p.y * FogYGrad);
- if (vFogT[s]<5 ) vFogT[s] = 5;
- if (vFogT[s]>255) vFogT[s]=255;
- vFogT[s]<<=24;
- } else vFogT[s] = 255<<24;
-
- rVertex[s].x = (p.x * ca + p.z * sa) + x0;
- float vz = p.z * ca - p.x * sa;
- rVertex[s].y = (p.y * cb - vz * sb) + y0;
- rVertex[s].z = (vz * cb + p.y * sb) + z0;
- if (rVertex[s].z<-32) {
- gScrpf[s].x = VideoCXf - (rVertex[s].x / rVertex[s].z * CameraW);
- gScrpf[s].y = VideoCYf + (rVertex[s].y / rVertex[s].z * CameraH);
- } else gScrpf[s].x=-102400;
- if (gScrpf[s].x > maxx) maxx = gScrpf[s].x;
- if (gScrpf[s].x < minx) minx = gScrpf[s].x;
- if (gScrpf[s].y > maxy) maxy = gScrpf[s].y;
- if (gScrpf[s].y < miny) miny = gScrpf[s].y;
- }
- if (minx == 10241024) return;
- if (minx>WinW || maxx<0 || miny>WinH || maxy<0) return;
-
-
- BuildTreeNoSortf();
-
- float d = (float) sqrt(x0*x0 + y0*y0 + z0*z0);
- if (LOWRESTX) d = 14*256;
- if (MIPMAP && (d > 12*256)) d3dSetTexture(mptr->lpTexture2, 128, 128);
- else d3dSetTexture(mptr->lpTexture, 256, 256);
- int PrevOpacity = 0;
- int NewOpacity = 0;
- int PrevTransparent = 0;
- int NewTransparent = 0;
-
- d3dStartBuffer();
- int fproc1 = 0;
- int fproc2 = 0;
- f = Current;
- BOOL CKEY = FALSE;
- while( f!=-1 ) {
- TFace *fptr = & mptr->gFace[f];
- f = mptr->gFace[f].Next;
- if (minx<0)
- if (gScrpf[fptr->v1].x <0 && gScrpf[fptr->v2].x<0 && gScrpf[fptr->v3].x<0) continue;
- if (maxx>WinW)
- if (gScrpf[fptr->v1].x >WinW && gScrpf[fptr->v2].x>WinW && gScrpf[fptr->v3].x>WinW) continue;
- if (fptr->Flags & (sfOpacity | sfTransparent)) fproc2++; else fproc1++;
- int _ml = ml + mptr->VLight[VT][fptr->v1];
- lpVertex->sx = (float)gScrpf[fptr->v1].x;
- lpVertex->sy = (float)gScrpf[fptr->v1].y;
- lpVertex->sz = _ZSCALE / rVertex[fptr->v1].z;
- lpVertex->rhw = 1.f;
- lpVertex->color = _ml * 0x00010101 | alphamask;
- lpVertex->specular = vFogT[fptr->v1];
- lpVertex->tu = (float)(fptr->tax);
- lpVertex->tv = (float)(fptr->tay);
- lpVertex++;
- _ml = ml + mptr->VLight[VT][fptr->v2];
- lpVertex->sx = (float)gScrpf[fptr->v2].x;
- lpVertex->sy = (float)gScrpf[fptr->v2].y;
- lpVertex->sz = _ZSCALE / rVertex[fptr->v2].z;
- lpVertex->rhw = 1.f;
- lpVertex->color = _ml * 0x00010101 | alphamask;;
- lpVertex->specular = vFogT[fptr->v2];
- lpVertex->tu = (float)(fptr->tbx);
- lpVertex->tv = (float)(fptr->tby);
- lpVertex++;
- _ml = ml + mptr->VLight[VT][fptr->v3];
- lpVertex->sx = (float)gScrpf[fptr->v3].x;
- lpVertex->sy = (float)gScrpf[fptr->v3].y;
- lpVertex->sz = _ZSCALE / rVertex[fptr->v3].z;
- lpVertex->rhw = 1.f;
- lpVertex->color = _ml * 0x00010101 | alphamask;;
- lpVertex->specular = vFogT[fptr->v3];
- lpVertex->tu = (float)(fptr->tcx);
- lpVertex->tv = (float)(fptr->tcy);
- lpVertex++;
-
-
- //f = mptr->gFace[f].Next;
- }
- d3dFlushBuffer(fproc1, fproc2);
- }
- void RenderShadowClip(TModel* _mptr,
- float xm0, float ym0, float zm0,
- float x0, float y0, float z0, float cal, float al, float bt)
- {
- int f,CMASK,j;
- mptr = _mptr;
-
- float cla = (float)f_cos(cal);
- float sla = (float)f_sin(cal);
- float ca = (float)f_cos(al);
- float sa = (float)f_sin(al);
-
- float cb = (float)f_cos(bt);
- float sb = (float)f_sin(bt);
-
-
- BOOL BL = FALSE;
- for (int s=0; s<mptr->VCount; s++) {
- float mrx = mptr->gVertex[s].x * cla + mptr->gVertex[s].z * sla;
- float mrz = mptr->gVertex[s].z * cla - mptr->gVertex[s].x * sla;
- float shx = mrx + mptr->gVertex[s].y * SunShadowK;
- float shz = mrz + mptr->gVertex[s].y * SunShadowK;
- float shy = GetLandH(shx + xm0, shz + zm0) - ym0;
- rVertex[s].x = (shx * ca + shz * sa) + x0;
- float vz = shz * ca - shx * sa;
- rVertex[s].y = (shy * cb - vz * sb) + y0;
- rVertex[s].z = (vz * cb + shy * sb) + z0;
- if (rVertex[s].z<0) BL=TRUE;
- if (rVertex[s].z>-256) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = 0xFF; }
- else {
- int f = 0;
- int sx = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
- int sy = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
-
- if (sx>=WinEX) f+=1;
- if (sx<=0 ) f+=2;
- if (sy>=WinEY) f+=4;
- if (sy<=0 ) f+=8;
- gScrp[s].y = f;
- }
- }
-
- if (!BL) return;
-
- float d = (float) sqrt(x0*x0 + y0*y0 + z0*z0);
- if (LOWRESTX) d = 14*256;
- if (MIPMAP && (d > 12*256)) d3dSetTexture(mptr->lpTexture2, 128, 128);
- else d3dSetTexture(mptr->lpTexture, 256, 256);
-
- BuildTreeClipNoSort();
- d3dStartBuffer();
- int fproc1 = 0;
- f = Current;
- while( f!=-1 ) {
-
- vused = 3;
- TFace *fptr = &mptr->gFace[f];
-
- CMASK = 0;
- CMASK|=gScrp[fptr->v1].y;
- CMASK|=gScrp[fptr->v2].y;
- CMASK|=gScrp[fptr->v3].y;
- cp[0].ev.v = rVertex[fptr->v1]; cp[0].tx = fptr->tax; cp[0].ty = fptr->tay;
- cp[1].ev.v = rVertex[fptr->v2]; cp[1].tx = fptr->tbx; cp[1].ty = fptr->tby;
- cp[2].ev.v = rVertex[fptr->v3]; cp[2].tx = fptr->tcx; cp[2].ty = fptr->tcy;
- if (CMASK == 0xFF) {
- for (u=0; u<vused; u++) cp[u].ev.v.z+=16.0f;
- for (u=0; u<vused; u++) ClipVector(ClipZ,u);
- for (u=0; u<vused; u++) cp[u].ev.v.z-=16.0f;
- if (vused<3) goto LNEXT;
- }
-
- if (CMASK & 1) for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) goto LNEXT;
- if (CMASK & 2) for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) goto LNEXT;
- if (CMASK & 4) for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) goto LNEXT;
- if (CMASK & 8) for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) goto LNEXT;
-
- for (j=0; j<vused-2; j++) {
- u = 0;
- lpVertex->sx = (float)(VideoCX - (int)(cp[u].ev.v.x / cp[u].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[u].ev.v.y / cp[u].ev.v.z * CameraH));
- lpVertex->sz = (_ZSCALE-0.5f) / cp[u].ev.v.z;
- lpVertex->rhw = 1.f;
- lpVertex->color = GlassL;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0.f;
- lpVertex->tv = 0.f;
- lpVertex++;
- u = j+1;
- lpVertex->sx = (float)(VideoCX - (int)(cp[u].ev.v.x / cp[u].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[u].ev.v.y / cp[u].ev.v.z * CameraH));
- lpVertex->sz = (_ZSCALE-0.5f) / cp[u].ev.v.z;
- lpVertex->rhw = 1.f;
- lpVertex->color = GlassL;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0.f;
- lpVertex->tv = 0.f;
- lpVertex++;
- u = j+2;
- lpVertex->sx = (float)(VideoCX - (int)(cp[u].ev.v.x / cp[u].ev.v.z * CameraW));
- lpVertex->sy = (float)(VideoCY + (int)(cp[u].ev.v.y / cp[u].ev.v.z * CameraH));
- lpVertex->sz = (_ZSCALE-0.5f) / cp[u].ev.v.z;
- lpVertex->rhw = 1.f;
- lpVertex->color = GlassL;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0.f;
- lpVertex->tv = 0.f;
- lpVertex++;
- fproc1++;
- }
-
- LNEXT:
- f = mptr->gFace[f].Next;
- }
- d3dFlushBuffer(fproc1, 0);
-
- }
- void RenderModelClip(TModel* _mptr, float x0, float y0, float z0, int light, int VT, float al, float bt)
- {
- int f,CMASK;
- //if (fabs(y0) > -(z0-256*6)) return;
- mptr = _mptr;
-
- float ca = (float)f_cos(al);
- float sa = (float)f_sin(al);
-
- float cb = (float)f_cos(bt);
- float sb = (float)f_sin(bt);
-
- int flight = (int)light;
- DWORD almask;
- DWORD alphamask = (255-GlassL)<<24;
-
-
- BOOL BL = FALSE;
- BOOL FOGACTIVE = (FOGON && (FogYBase>0));
- for (int s=0; s<mptr->VCount; s++) {
- if (FOGACTIVE) {
- vFogT[s] = 255-(int)(FogYBase + mptr->gVertex[s].y * FogYGrad);
- if (vFogT[s]<5 ) vFogT[s] = 5;
- if (vFogT[s]>255) vFogT[s]=255;
- } else vFogT[s] = 255;
-
- rVertex[s].x = (mptr->gVertex[s].x * ca + mptr->gVertex[s].z * sa) /* * mdlScale */ + x0;
- float vz = mptr->gVertex[s].z * ca - mptr->gVertex[s].x * sa;
- rVertex[s].y = (mptr->gVertex[s].y * cb - vz * sb) /* * mdlScale */ + y0;
- rVertex[s].z = (vz * cb + mptr->gVertex[s].y * sb) /* * mdlScale */ + z0;
- if (rVertex[s].z<0) BL=TRUE;
- if (rVertex[s].z>-256) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = 0xFF; }
- else {
- int f = 0;
- int sx = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
- int sy = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
-
- if (sx>=WinEX) f+=1;
- if (sx<=0 ) f+=2;
- if (sy>=WinEY) f+=4;
- if (sy<=0 ) f+=8;
- gScrp[s].y = f;
- }
- }
-
- if (!BL) return;
-
- if (LOWRESTX) d3dSetTexture(mptr->lpTexture2, 128, 128);
- else d3dSetTexture(mptr->lpTexture, 256, 256);
-
- BuildTreeClipNoSort();
-
- d3dStartBuffer();
- f = Current;
- int fproc1 = 0;
- int fproc2 = 0;
- BOOL CKEY = FALSE;
- while( f!=-1 ) {
-
- vused = 3;
- TFace *fptr = &mptr->gFace[f];
-
- CMASK = 0;
-
- CMASK|=gScrp[fptr->v1].y;
- CMASK|=gScrp[fptr->v2].y;
- CMASK|=gScrp[fptr->v3].y;
-
- cp[0].ev.v = rVertex[fptr->v1]; cp[0].tx = fptr->tax; cp[0].ty = fptr->tay; cp[0].ev.Fog = vFogT[fptr->v1]; cp[0].ev.Light = mptr->VLight[VT][fptr->v1];
- cp[1].ev.v = rVertex[fptr->v2]; cp[1].tx = fptr->tbx; cp[1].ty = fptr->tby; cp[1].ev.Fog = vFogT[fptr->v2]; cp[1].ev.Light = mptr->VLight[VT][fptr->v2];
- cp[2].ev.v = rVertex[fptr->v3]; cp[2].tx = fptr->tcx; cp[2].ty = fptr->tcy; cp[2].ev.Fog = vFogT[fptr->v3]; cp[2].ev.Light = mptr->VLight[VT][fptr->v3];
-
- {
- for (u=0; u<vused; u++) cp[u].ev.v.z+= 8.0f;
- for (u=0; u<vused; u++) ClipVector(ClipZ,u);
- for (u=0; u<vused; u++) cp[u].ev.v.z-= 8.0f;
- if (vused<3) goto LNEXT;
- }
-
- if (CMASK & 1) for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) goto LNEXT;
- if (CMASK & 2) for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) goto LNEXT;
- if (CMASK & 4) for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) goto LNEXT;
- if (CMASK & 8) for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) goto LNEXT;
- almask = 0xFF000000;
- if (fptr->Flags & sfTransparent) almask = 0x70000000;
- if (almask > alphamask)
- almask = alphamask;
-
- for (u=0; u<vused-2; u++) {
- int _flight = flight + cp[0].ev.Light;
- lpVertex->sx = VideoCXf - cp[0].ev.v.x / cp[0].ev.v.z * CameraW;
- lpVertex->sy = VideoCYf + cp[0].ev.v.y / cp[0].ev.v.z * CameraH;
- lpVertex->sz = _ZSCALE / cp[0].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = _flight * 0x00010101 | almask;
- lpVertex->specular = ((int)cp[0].ev.Fog)<<24;
- lpVertex->tu = (float)(cp[0].tx);
- lpVertex->tv = (float)(cp[0].ty);
- lpVertex++;
- _flight = flight + cp[u+1].ev.Light;
- lpVertex->sx = VideoCXf - cp[u+1].ev.v.x / cp[u+1].ev.v.z * CameraW;
- lpVertex->sy = VideoCYf + cp[u+1].ev.v.y / cp[u+1].ev.v.z * CameraH;
- lpVertex->sz = _ZSCALE / cp[u+1].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = _flight * 0x00010101 | almask;
- lpVertex->specular = ((int)cp[u+1].ev.Fog)<<24;
- lpVertex->tu = (float)(cp[u+1].tx);
- lpVertex->tv = (float)(cp[u+1].ty);
- lpVertex++;
- _flight = flight + cp[u+2].ev.Light;
- lpVertex->sx = VideoCXf - cp[u+2].ev.v.x / cp[u+2].ev.v.z * CameraW;
- lpVertex->sy = VideoCYf + cp[u+2].ev.v.y / cp[u+2].ev.v.z * CameraH;
- lpVertex->sz = _ZSCALE / cp[u+2].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = _flight * 0x00010101 | almask;
- lpVertex->specular = ((int)cp[u+2].ev.Fog)<<24;
- lpVertex->tu = (float)(cp[u+2].tx);
- lpVertex->tv = (float)(cp[u+2].ty);
- lpVertex++;
- if (fptr->Flags & (sfOpacity | sfTransparent)) fproc2++; else fproc1++;
- }
- LNEXT:
- f = mptr->gFace[f].Next;
- }
- d3dFlushBuffer(fproc1, fproc2);
- }
- void RenderModelClipEnvMap(TModel* _mptr, float x0, float y0, float z0, float al, float bt)
- {
- int f,CMASK;
- mptr = _mptr;
-
- float ca = (float)f_cos(al);
- float sa = (float)f_sin(al);
- float cb = (float)f_cos(bt);
- float sb = (float)f_sin(bt);
-
- DWORD PHCOLOR = 0xFFFFFFFF;
-
- BOOL BL = FALSE;
-
- for (int s=0; s<mptr->VCount; s++) {
-
- rVertex[s].x = (mptr->gVertex[s].x * ca + mptr->gVertex[s].z * sa) /* * mdlScale */ + x0;
- float vz = mptr->gVertex[s].z * ca - mptr->gVertex[s].x * sa;
- rVertex[s].y = (mptr->gVertex[s].y * cb - vz * sb) /* * mdlScale */ + y0;
- rVertex[s].z = (vz * cb + mptr->gVertex[s].y * sb) /* * mdlScale */ + z0;
- if (rVertex[s].z<0) BL=TRUE;
- if (rVertex[s].z>-256) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = 0xFF; }
- else {
- int f = 0;
- int sx = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
- int sy = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
-
- if (sx>=WinEX) f+=1;
- if (sx<=0 ) f+=2;
- if (sy>=WinEY) f+=4;
- if (sy<=0 ) f+=8;
- gScrp[s].y = f;
- }
- }
-
- d3dSetTexture(TFX_ENVMAP.lpImage, TFX_ENVMAP.W, TFX_ENVMAP.W);
- SetRenderStates(FALSE, D3DBLEND_ONE);
-
- BuildTreeClipNoSort();
-
- d3dStartBuffer();
- f = Current;
- int fproc1 = 0;
-
- while( f!=-1 ) {
-
- vused = 3;
- TFace *fptr = &mptr->gFace[f];
- if (!(fptr->Flags & sfEnvMap)) goto LNEXT;
-
- CMASK = 0;
-
- CMASK|=gScrp[fptr->v1].y;
- CMASK|=gScrp[fptr->v2].y;
- CMASK|=gScrp[fptr->v3].y;
-
- cp[0].ev.v = rVertex[fptr->v1]; cp[0].tx = PhongMapping[fptr->v1].x/256.f; cp[0].ty = PhongMapping[fptr->v1].y/256.f;
- cp[1].ev.v = rVertex[fptr->v2]; cp[1].tx = PhongMapping[fptr->v2].x/256.f; cp[1].ty = PhongMapping[fptr->v2].y/256.f;
- cp[2].ev.v = rVertex[fptr->v3]; cp[2].tx = PhongMapping[fptr->v3].x/256.f; cp[2].ty = PhongMapping[fptr->v3].y/256.f;
-
-
- {
- for (u=0; u<vused; u++) cp[u].ev.v.z+= 8.0f;
- for (u=0; u<vused; u++) ClipVector(ClipZ,u);
- for (u=0; u<vused; u++) cp[u].ev.v.z-= 8.0f;
- if (vused<3) goto LNEXT;
- }
-
- if (CMASK & 1) for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) goto LNEXT;
- if (CMASK & 2) for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) goto LNEXT;
- if (CMASK & 4) for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) goto LNEXT;
- if (CMASK & 8) for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) goto LNEXT;
-
- for (u=0; u<vused-2; u++) {
- lpVertex->sx = VideoCXf - cp[0].ev.v.x / cp[0].ev.v.z * CameraW;
- lpVertex->sy = VideoCYf + cp[0].ev.v.y / cp[0].ev.v.z * CameraH;
- lpVertex->sz = _ZSCALE / cp[0].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = PHCOLOR;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(cp[0].tx);
- lpVertex->tv = (float)(cp[0].ty);
- lpVertex++;
-
- lpVertex->sx = VideoCXf - cp[u+1].ev.v.x / cp[u+1].ev.v.z * CameraW;
- lpVertex->sy = VideoCYf + cp[u+1].ev.v.y / cp[u+1].ev.v.z * CameraH;
- lpVertex->sz = _ZSCALE / cp[u+1].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = PHCOLOR;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(cp[u+1].tx);
- lpVertex->tv = (float)(cp[u+1].ty);
- lpVertex++;
-
- lpVertex->sx = VideoCXf - cp[u+2].ev.v.x / cp[u+2].ev.v.z * CameraW;
- lpVertex->sy = VideoCYf + cp[u+2].ev.v.y / cp[u+2].ev.v.z * CameraH;
- lpVertex->sz = _ZSCALE / cp[u+2].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = PHCOLOR;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(cp[u+2].tx);
- lpVertex->tv = (float)(cp[u+2].ty);
- lpVertex++;
- fproc1++;
- }
- LNEXT:
- f = mptr->gFace[f].Next;
- }
- d3dFlushBuffer(fproc1, 0);
- SetRenderStates(TRUE, D3DBLEND_INVSRCALPHA);
- }
- void RenderModelClipPhongMap(TModel* _mptr, float x0, float y0, float z0, float al, float bt)
- {
- int f,CMASK;
- mptr = _mptr;
-
- float ca = (float)f_cos(al);
- float sa = (float)f_sin(al);
- float cb = (float)f_cos(bt);
- float sb = (float)f_sin(bt);
- int rv = SkyR +64; if (rv>255) rv = 255;
- int gv = SkyG +64; if (gv>255) gv = 255;
- int bv = SkyB +64; if (bv>255) bv = 255;
- DWORD PHCOLOR = 0xFF000000 + (rv<<16) + (gv<<8) + bv;
-
- BOOL BL = FALSE;
-
- for (int s=0; s<mptr->VCount; s++) {
-
- rVertex[s].x = (mptr->gVertex[s].x * ca + mptr->gVertex[s].z * sa) /* * mdlScale */ + x0;
- float vz = mptr->gVertex[s].z * ca - mptr->gVertex[s].x * sa;
- rVertex[s].y = (mptr->gVertex[s].y * cb - vz * sb) /* * mdlScale */ + y0;
- rVertex[s].z = (vz * cb + mptr->gVertex[s].y * sb) /* * mdlScale */ + z0;
- if (rVertex[s].z<0) BL=TRUE;
- if (rVertex[s].z>-256) { gScrp[s].x = 0xFFFFFF; gScrp[s].y = 0xFF; }
- else {
- int f = 0;
- int sx = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
- int sy = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH);
-
- if (sx>=WinEX) f+=1;
- if (sx<=0 ) f+=2;
- if (sy>=WinEY) f+=4;
- if (sy<=0 ) f+=8;
- gScrp[s].y = f;
- }
- }
-
- d3dSetTexture(TFX_SPECULAR.lpImage, TFX_SPECULAR.W, TFX_SPECULAR.W);
- SetRenderStates(FALSE, D3DBLEND_ONE);
-
- BuildTreeClipNoSort();
-
- d3dStartBuffer();
- f = Current;
- int fproc1 = 0;
-
- while( f!=-1 ) {
-
- vused = 3;
- TFace *fptr = &mptr->gFace[f];
- if (!(fptr->Flags & sfPhong)) goto LNEXT;
-
- CMASK = 0;
-
- CMASK|=gScrp[fptr->v1].y;
- CMASK|=gScrp[fptr->v2].y;
- CMASK|=gScrp[fptr->v3].y;
-
- cp[0].ev.v = rVertex[fptr->v1]; cp[0].tx = PhongMapping[fptr->v1].x/256.f; cp[0].ty = PhongMapping[fptr->v1].y/256.f;
- cp[1].ev.v = rVertex[fptr->v2]; cp[1].tx = PhongMapping[fptr->v2].x/256.f; cp[1].ty = PhongMapping[fptr->v2].y/256.f;
- cp[2].ev.v = rVertex[fptr->v3]; cp[2].tx = PhongMapping[fptr->v3].x/256.f; cp[2].ty = PhongMapping[fptr->v3].y/256.f;
-
- {
- for (u=0; u<vused; u++) cp[u].ev.v.z+= 8.0f;
- for (u=0; u<vused; u++) ClipVector(ClipZ,u);
- for (u=0; u<vused; u++) cp[u].ev.v.z-= 8.0f;
- if (vused<3) goto LNEXT;
- }
-
- if (CMASK & 1) for (u=0; u<vused; u++) ClipVector(ClipA,u); if (vused<3) goto LNEXT;
- if (CMASK & 2) for (u=0; u<vused; u++) ClipVector(ClipC,u); if (vused<3) goto LNEXT;
- if (CMASK & 4) for (u=0; u<vused; u++) ClipVector(ClipB,u); if (vused<3) goto LNEXT;
- if (CMASK & 8) for (u=0; u<vused; u++) ClipVector(ClipD,u); if (vused<3) goto LNEXT;
-
- for (u=0; u<vused-2; u++) {
- lpVertex->sx = VideoCXf - cp[0].ev.v.x / cp[0].ev.v.z * CameraW;
- lpVertex->sy = VideoCYf + cp[0].ev.v.y / cp[0].ev.v.z * CameraH;
- lpVertex->sz = _ZSCALE / cp[0].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = PHCOLOR;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(cp[0].tx);
- lpVertex->tv = (float)(cp[0].ty);
- lpVertex++;
-
- lpVertex->sx = VideoCXf - cp[u+1].ev.v.x / cp[u+1].ev.v.z * CameraW;
- lpVertex->sy = VideoCYf + cp[u+1].ev.v.y / cp[u+1].ev.v.z * CameraH;
- lpVertex->sz = _ZSCALE / cp[u+1].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = PHCOLOR;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(cp[u+1].tx);
- lpVertex->tv = (float)(cp[u+1].ty);
- lpVertex++;
-
- lpVertex->sx = VideoCX - cp[u+2].ev.v.x / cp[u+2].ev.v.z * CameraW;
- lpVertex->sy = VideoCY + cp[u+2].ev.v.y / cp[u+2].ev.v.z * CameraH;
- lpVertex->sz = _ZSCALE / cp[u+2].ev.v.z;
- lpVertex->rhw = lpVertex->sz * _AZSCALE;
- lpVertex->color = PHCOLOR;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(cp[u+2].tx);
- lpVertex->tv = (float)(cp[u+2].ty);
- lpVertex++;
- fproc1++;
- }
- LNEXT:
- f = mptr->gFace[f].Next;
- }
- d3dFlushBuffer(fproc1, 0);
- SetRenderStates(TRUE, D3DBLEND_INVSRCALPHA);
- }
- void RenderModelSun(TModel* _mptr, float x0, float y0, float z0, int Alpha)
- {
- int f;
- mptr = _mptr;
- int minx = 10241024;
- int maxx =-10241024;
- int miny = 10241024;
- int maxy =-10241024;
-
- for (int s=0; s<mptr->VCount; s++) {
- rVertex[s].x = mptr->gVertex[s].x + x0;
- rVertex[s].y = mptr->gVertex[s].y + y0;
- rVertex[s].z = mptr->gVertex[s].z + z0;
- if (rVertex[s].z>-64) gScrp[s].x = 0xFFFFFF; else {
- gScrp[s].x = VideoCX + (int)(rVertex[s].x / (-rVertex[s].z) * CameraW);
- gScrp[s].y = VideoCY - (int)(rVertex[s].y / (-rVertex[s].z) * CameraH); }
- if (gScrp[s].x > maxx) maxx = gScrp[s].x;
- if (gScrp[s].x < minx) minx = gScrp[s].x;
- if (gScrp[s].y > maxy) maxy = gScrp[s].y;
- if (gScrp[s].y < miny) miny = gScrp[s].y;
- }
- if (minx == 10241024) return;
- if (minx>WinW || maxx<0 || miny>WinH || maxy<0) return;
-
- BuildTreeNoSort();
-
- d3dSetTexture(mptr->lpTexture2, 128, 128);
-
- d3dStartBuffer();
- DWORD alpha = Alpha;
- alpha = (alpha<<24) | 0x00FFFFFF;
- int fproc1 = 0;
- f = Current;
- while( f!=-1 ) {
- TFace *fptr = & mptr->gFace[f];
- fproc1++;
- lpVertex->sx = (float)gScrp[fptr->v1].x;
- lpVertex->sy = (float)gScrp[fptr->v1].y;
- lpVertex->sz = 0.0002;//_ZSCALE / rVertex[fptr->v1].z;
- lpVertex->rhw = 1.f;
- lpVertex->color = alpha;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(fptr->tax);
- lpVertex->tv = (float)(fptr->tay);
- lpVertex++;
- lpVertex->sx = (float)gScrp[fptr->v2].x;
- lpVertex->sy = (float)gScrp[fptr->v2].y;
- lpVertex->sz = 0.0002;//_ZSCALE / rVertex[fptr->v2].z;
- lpVertex->rhw = 1.f;
- lpVertex->color = alpha;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(fptr->tbx);
- lpVertex->tv = (float)(fptr->tby);
- lpVertex++;
- lpVertex->sx = (float)gScrp[fptr->v3].x;
- lpVertex->sy = (float)gScrp[fptr->v3].y;
- lpVertex->sz = 0.0002;//_ZSCALE / rVertex[fptr->v3].z;
- lpVertex->rhw = 1.f;
- lpVertex->color = alpha;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = (float)(fptr->tcx);
- lpVertex->tv = (float)(fptr->tcy);
- lpVertex++;
-
- f = mptr->gFace[f].Next;
- }
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + d3debvc*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 2;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
-
- lpState->drstRenderStateType = D3DRENDERSTATE_DESTBLEND;
- lpState->dwArg[0] = D3DBLEND_ONE;
- lpState++;
-
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstruction->wCount = 1U;
- lpInstruction++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = fproc1*3;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
- lpInstruction->bOpcode = D3DOP_TRIANGLE;
- lpInstruction->bSize = sizeof(D3DTRIANGLE);
- lpInstruction->wCount = fproc1;
- lpInstruction++;
- lpTriangle = (LPD3DTRIANGLE)lpInstruction;
-
- int ii = 0;
- for (int i=0; i<fproc1; i++) {
- lpTriangle->wV1 = ii++;
- lpTriangle->wV2 = ii++;
- lpTriangle->wV3 = ii++;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- }
- lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
-
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 1;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_DESTBLEND;
- lpState->dwArg[0] = D3DBLEND_INVSRCALPHA;
- lpState++;
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 3;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_COLORKEYENABLE;
- lpState->dwArg[0] = FALSE;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpInstruction = (LPD3DINSTRUCTION)lpState;
-
-
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- //if (FAILED(hRes)) DoHalt("Error execute buffer");
- dFacesCount+=fproc1;
- }
- void RenderNearModel(TModel* _mptr, float x0, float y0, float z0, int light, float al, float bt)
- {
- BOOL b = LOWRESTX;
- Vector3d v;
- v.x = 0; v.y =-128; v.z = 0;
- CalcFogLevel_Gradient(v);
- FogYGrad = 0;
-
- LOWRESTX = FALSE;
- RenderModelClip(_mptr, x0, y0, z0, light, 0, al, bt);
- LOWRESTX = b;
- }
- void RenderModelClipWater(TModel* _mptr, float x0, float y0, float z0, int light, int VT, float al, float bt)
- {
- }
- void RenderCharacter(int index)
- {
- }
- void RenderExplosion(int index)
- {
- }
- void RenderShip()
- {
- }
- void RenderElements()
- {
- d3dLastTexture = d3dmemmapsize+1;
- hTexture = NULL;
- int fproc1 = 0;
-
- for (int eg = 0; eg<ElCount; eg++) {
- for (int e = 0; e<Elements[eg].ECount; e++) {
- Vector3d rpos;
- TElement *el = &Elements[eg].EList[e];
- rpos.x = el->pos.x - CameraX;
- rpos.y = el->pos.y - CameraY;
- rpos.z = el->pos.z - CameraZ;
- float r = el->R;
- rpos = RotateVector(rpos);
- if (rpos.z > -64) continue;
- if ( fabs(rpos.x) > -rpos.z) continue;
- if ( fabs(rpos.y) > -rpos.z) continue;
- if (!fproc1) d3dStartBuffer();
- float sx = VideoCXf - (CameraW * rpos.x / rpos.z);
- float sy = VideoCYf + (CameraH * rpos.y / rpos.z);
- RenderCircle(sx, sy, rpos.z, -r*CameraW*0.64 / rpos.z, Elements[eg].RGBA, Elements[eg].RGBA2);
- fproc1+=8;
- if (fproc1>256) {
- d3dFlushBuffer(fproc1, 0);
- fproc1 = 0;
- }
- }
-
- }
- if (fproc1) d3dFlushBuffer(fproc1, 0);
-
- fproc1 = 0;
- for (int b=0; b<BloodTrail.Count; b++) {
- Vector3d rpos = BloodTrail.Trail[b].pos;
- DWORD A1 = (0xE0 * BloodTrail.Trail[b].LTime / 20000); if (A1>0xE0) A1=0xE0;
- DWORD A2 = (0x20 * BloodTrail.Trail[b].LTime / 20000); if (A2>0x20) A2=0x20;
- rpos.x = rpos.x - CameraX;
- rpos.y = rpos.y - CameraY;
- rpos.z = rpos.z - CameraZ;
- rpos = RotateVector(rpos);
- if (rpos.z > -64) continue;
- if ( fabs(rpos.x) > -rpos.z) continue;
- if ( fabs(rpos.y) > -rpos.z) continue;
- if (!fproc1) d3dStartBuffer();
- float sx = VideoCXf - (CameraW * rpos.x / rpos.z);
- float sy = VideoCYf + (CameraH * rpos.y / rpos.z);
- RenderCircle(sx, sy, rpos.z, -12*CameraW*0.64 / rpos.z, (A1<<24)+conv_xGx(0x700000), (A2<<24)+conv_xGx(0x300000));
- fproc1+=8;
-
- if (fproc1>256) {
- d3dFlushBuffer(fproc1, 0);
- fproc1 = 0;
- }
- }
-
- if (fproc1) d3dFlushBuffer(fproc1, 0);
- if (SNOW)
- for (int s=0; s<SnCount; s++) {
- Vector3d rpos = Snow[s].pos;
-
- rpos.x = rpos.x - CameraX;
- rpos.y = rpos.y - CameraY;
- rpos.z = rpos.z - CameraZ;
- rpos = RotateVector(rpos);
- if (rpos.z > -64) continue;
- if ( fabs(rpos.x) > -rpos.z) continue;
- if ( fabs(rpos.y) > -rpos.z) continue;
- float sx = VideoCXf - CameraW * rpos.x / rpos.z;
- float sy = VideoCYf + CameraH * rpos.y / rpos.z;
-
- DWORD A1 = 0xFF;
- DWORD A2 = 0x30;
- if (Snow[s].ftime) {
- A1 = A1 * (2000-Snow[s].ftime) / 2000;
- A2 = A2 * (2000-Snow[s].ftime) / 2000;
- }
- if (!fproc1) d3dStartBuffer();
- if (rpos.z>-1624) {
- RenderCircle(sx, sy, rpos.z, -8*CameraW*0.64 / rpos.z, (A1<<24)+conv_xGx(0xF0F0F0), (A2<<24)+conv_xGx(0xB0B0B0));
- fproc1+=8;
- } else {
- RenderPoint(sx, sy, rpos.z, -8*CameraW*0.64 / rpos.z, (A1<<24)+conv_xGx(0xF0F0F0), (A2<<24)+conv_xGx(0xB0B0B0));
- fproc1++;
- }
- if (fproc1>d3debvc) {
- d3dFlushBuffer(fproc1, 0);
- fproc1 = 0;
- }
- }
- if (fproc1) d3dFlushBuffer(fproc1, 0);
-
- GlassL = 0;
- }
- void RenderCharacterPost(TCharacter *cptr)
- {
- //mdlScale = 1.0f;
-
- CreateChMorphedModel(cptr);
-
- float zs = (float)sqrt( cptr->rpos.x*cptr->rpos.x + cptr->rpos.y*cptr->rpos.y + cptr->rpos.z*cptr->rpos.z);
- if (zs > ctViewR*256) return;
- GlassL = 0;
- if (zs > 256 * (ctViewR-4))
- GlassL = min(255, (zs/4 - 64*(ctViewR-4)));
-
- waterclip = FALSE;
-
- if ( cptr->rpos.z >-256*10)
- RenderModelClip(cptr->pinfo->mptr,
- cptr->rpos.x, cptr->rpos.y, cptr->rpos.z, 210, 0,
- -cptr->alpha + pi / 2 + CameraAlpha,
- CameraBeta );
- else
- RenderModel(cptr->pinfo->mptr,
- cptr->rpos.x, cptr->rpos.y, cptr->rpos.z, 210, 0,
- -cptr->alpha + pi / 2 + CameraAlpha,
- CameraBeta );
-
- if (!SHADOWS3D) return;
- if (zs > 256 * (ctViewR-8)) return;
-
- int Al = 0x60;
-
- if (cptr->Health==0) {
- int at = cptr->pinfo->Animation[cptr->Phase].AniTime;
- if (Tranq) return;
- if (cptr->FTime==at-1) return;
- Al = Al * (at-cptr->FTime) / at; }
- if (cptr->AI==0) Al = 0x50;
- GlassL = (Al<<24) + 0x00222222;
-
- RenderShadowClip(cptr->pinfo->mptr,
- cptr->pos.x, cptr->pos.y, cptr->pos.z,
- cptr->rpos.x, cptr->rpos.y, cptr->rpos.z,
- pi/2-cptr->alpha,
- CameraAlpha,
- CameraBeta );
- }
- void RenderShipPost()
- {
- if (Ship.State==-1) return;
- GlassL = 0;
- zs = (int)VectorLength(Ship.rpos);
- if (zs > 256 * (ctViewR)) return;
-
- if (zs > 256 * (ctViewR-4))
- GlassL = min(255,(int)(zs - 256 * (ctViewR-4)) / 4);
-
-
- /*grConstantColorValue( (255-GlassL) << 24);*/
- CreateMorphedModel(ShipModel.mptr, &ShipModel.Animation[0], Ship.FTime, 1.0);
-
- if ( fabs(Ship.rpos.z) < 4000)
- RenderModelClip(ShipModel.mptr,
- Ship.rpos.x, Ship.rpos.y, Ship.rpos.z, 210, 0, -Ship.alpha -pi/2 + CameraAlpha, CameraBeta);
- else
- RenderModel(ShipModel.mptr,
- Ship.rpos.x, Ship.rpos.y, Ship.rpos.z, 210, 0, -Ship.alpha -pi/2+ CameraAlpha, CameraBeta);
-
- /*grConstantColorValue( 0xFF000000);*/
- }
- void Render3DHardwarePosts()
- {
-
-
- TCharacter *cptr;
- for (int c=0; c<ChCount; c++) {
- cptr = &Characters[c];
- cptr->rpos.x = cptr->pos.x - CameraX;
- cptr->rpos.y = cptr->pos.y - CameraY;
- cptr->rpos.z = cptr->pos.z - CameraZ;
-
- float r = (float)max( fabs(cptr->rpos.x), fabs(cptr->rpos.z) );
- int ri = -1 + (int)(r / 256.f + 0.5f);
- if (ri < 0) ri = 0;
- if (ri > ctViewR) continue;
- if (FOGON)
- CalcFogLevel_Gradient(cptr->rpos);
-
- cptr->rpos = RotateVector(cptr->rpos);
- float br = BackViewR + DinoInfo[cptr->CType].Radius;
- if (cptr->rpos.z > br) continue;
- if ( fabs(cptr->rpos.x) > -cptr->rpos.z + br ) continue;
- if ( fabs(cptr->rpos.y) > -cptr->rpos.z + br ) continue;
- RenderCharacterPost(cptr);
- }
- Ship.rpos.x = Ship.pos.x - CameraX;
- Ship.rpos.y = Ship.pos.y - CameraY;
- Ship.rpos.z = Ship.pos.z - CameraZ;
- float r = (float)max( fabs(Ship.rpos.x), fabs(Ship.rpos.z) );
- int ri = -1 + (int)(r / 256.f + 0.2f);
- if (ri < 0) ri = 0;
- if (ri < ctViewR) {
- if (FOGON)
- CalcFogLevel_Gradient(Ship.rpos);
- Ship.rpos = RotateVector(Ship.rpos);
- if (Ship.rpos.z > BackViewR) goto NOSHIP;
- if ( fabs(Ship.rpos.x) > -Ship.rpos.z + BackViewR ) goto NOSHIP;
- RenderShipPost();
- }
- NOSHIP: ;
- SunLight *= GetTraceK(SunScrX, SunScrY);
- }
- void ClearVideoBuf()
- {
- }
- int CircleCX, CircleCY;
- WORD CColor;
- void PutPixel(int x, int y)
- { *((WORD*)ddsd.lpSurface + y*lsw + x) = CColor; }
- void Put8pix(int X,int Y)
- {
- PutPixel(CircleCX + X, CircleCY + Y);
- PutPixel(CircleCX + X, CircleCY - Y);
- PutPixel(CircleCX - X, CircleCY + Y);
- PutPixel(CircleCX - X, CircleCY - Y);
- PutPixel(CircleCX + Y, CircleCY + X);
- PutPixel(CircleCX + Y, CircleCY - X);
- PutPixel(CircleCX - Y, CircleCY + X);
- PutPixel(CircleCX - Y, CircleCY - X);
- }
- void DrawCircle(int cx, int cy, int R)
- {
- int d = 3 - (2 * R);
- int x = 0;
- int y = R;
- CircleCX=cx;
- CircleCY=cy;
- do {
- Put8pix(x,y); x++;
- if (d < 0) d = d + (x<<2) + 6; else
- { d = d + (x - y) * 4 + 10; y--; }
- } while (x<y);
- Put8pix(x,y);
- }
- void DrawBox( WORD *lfbPtr, int lsw, int xx, int yy, WORD c)
- {
- yy = yy * lsw + xx;
- *(lfbPtr + yy) = c;
- *(lfbPtr + yy + 1) = c;
- yy+=lsw;
- *(lfbPtr + yy) = c;
- *(lfbPtr + yy + 1) = c;
- }
- void DrawHMap()
- {
- int c;
- DrawPicture(VideoCX-MapPic.W/2, VideoCY - MapPic.H/2-6, MapPic);
-
- ZeroMemory( &ddsd, sizeof(DDSURFACEDESC) );
- ddsd.dwSize = sizeof(DDSURFACEDESC);
- if( lpddBack->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) != DD_OK ) return;
- lsw = ddsd.lPitch / 2;
- int RShift, GShift;
- if (VMFORMAT565) {
- RShift=11; GShift=6;
- } else {
- RShift=10; GShift=5;
- }
- int xx = VideoCX - 128 + (CCX>>2);
- int yy = VideoCY - 128 + (CCY>>2);
- if (yy<0 || yy>=WinH) goto endmap;
- if (xx<0 || xx>=WinW) goto endmap;
- DrawBox((WORD*)ddsd.lpSurface, lsw, xx+1, yy+1, 8<<RShift);
- DrawBox((WORD*)ddsd.lpSurface, lsw, xx, yy, 30<<RShift);
- /*
- *((WORD*)ddsd.lpSurface + yy*lsw + xx) = 30<<RShift;
- *((WORD*)ddsd.lpSurface + yy*lsw + xx + 1) = 30<<RShift;
- yy++;
- *((WORD*)ddsd.lpSurface + yy*lsw + xx) = 30<<RShift;
- *((WORD*)ddsd.lpSurface + yy*lsw + xx + 1) = 30<<RShift;
- */
- CColor = 4<<GShift; DrawCircle(xx+1, yy+1, (ctViewR/4));
- CColor = 18<<GShift; DrawCircle(xx, yy, (ctViewR/4));
- if (RadarMode)
- for (c=0; c<ChCount; c++) {
- if (Characters[c].AI<10) continue;
- if (! (TargetDino & (1<<Characters[c].AI)) ) continue;
- if (!Characters[c].Health) continue;
- xx = VideoCX - 128 + (int)Characters[c].pos.x / 1024;
- yy = VideoCY - 128 + (int)Characters[c].pos.z / 1024;
- if (yy<=0 || yy>=WinH) goto endmap;
- if (xx<=0 || xx>=WinW) goto endmap;
- DrawBox((WORD*)ddsd.lpSurface, lsw, xx, yy, 31);
- }
-
- endmap:
- lpddBack->Unlock(ddsd.lpSurface);
- }
- void RenderSun(float x, float y, float z)
- {
- SunScrX = VideoCX + (int)(x / (-z) * CameraW);
- SunScrY = VideoCY - (int)(y / (-z) * CameraH);
- GetSkyK(SunScrX, SunScrY);
-
- float d = (float)sqrt(x*x + y*y);
- if (d<2048) {
- SunLight = (220.f- d*220.f/2048.f);
- if (SunLight>140) SunLight = 140;
- SunLight*=SkyTraceK;
- }
-
-
- if (d>812.f) d = 812.f;
- d = (2048.f + d) / 3048.f;
- d+=(1.f-SkyTraceK)/2.f;
- if (OptDayNight==2) d=1.5;
- RenderModelSun(SunModel, x*d, y*d, z*d, (int)(200.f* SkyTraceK));
- }
- void RotateVVector(Vector3d& v)
- {
- float x = v.x * ca - v.z * sa;
- float y = v.y;
- float z = v.z * ca + v.x * sa;
- float xx = x;
- float xy = y * cb + z * sb;
- float xz = z * cb - y * sb;
-
- v.x = xx; v.y = xy; v.z = xz;
- }
- void RenderSkyPlane()
- {
-
- Vector3d v,vbase;
- Vector3d tx,ty,nv;
- float p,q, qx, qy, qz, px, py, pz, rx, ry, rz, ddx, ddy;
- float lastdt = 0.f;
- d3dSetTexture(SkyPic, 256, 256);
-
- nv.x = 512; nv.y = 4024; nv.z=0;
- cb = (float)f_cos(CameraBeta);
- sb = (float)f_sin(CameraBeta);
- SKYDTime = RealTime & ((1<<17) - 1);
- float sh = - CameraY;
- if (MapMinY==10241024)
- MapMinY=0;
- sh = (float)((int)MapMinY)*ctHScale - CameraY;
- if (sh<-2024) sh=-2024;
- v.x = 0;
- v.z = ctViewR*256.f;
- v.y = sh;
-
- vbase.x = v.x;
- vbase.y = v.y * cb + v.z * sb;
- vbase.z = v.z * cb - v.y * sb;
- if (vbase.z < 128) vbase.z = 128;
- int scry = VideoCY - (int)(vbase.y / vbase.z * CameraH);
-
- if (scry<0) return;
- if (scry>WinEY+1) scry = WinEY+1;
-
- cb = (float)f_cos(CameraBeta-0.15);
- sb = (float)f_sin(CameraBeta-0.15);
- v.x = 0;
- v.z = 2*256.f*256.f;
- v.y = 512;
- vbase.x = v.x;
- vbase.y = v.y * cb + v.z * sb;
- vbase.z = v.z * cb - v.y * sb;
- if (vbase.z < 128) vbase.z = 128;
- int _scry = VideoCY - (int)(vbase.y / vbase.z * CameraH);
- if (scry > _scry) scry = _scry;
-
- tx.x=0.002f; tx.y=0; tx.z=0;
- ty.x=0.0f; ty.y=0; ty.z=0.002f;
- nv.x=0; nv.y=-1.f; nv.z=0;
-
- RotateVVector(tx);
- RotateVVector(ty);
- RotateVVector(nv);
-
- sh = 4*512*16;
- vbase.x = -CameraX;
- vbase.y = sh;
- vbase.z = +CameraZ;
- RotateVVector(vbase);
- //============= calc render params =================//
- p = nv.x * vbase.x + nv.y * vbase.y + nv.z * vbase.z;
- ddx = vbase.x * tx.x + vbase.y * tx.y + vbase.z * tx.z;
- ddy = vbase.x * ty.x + vbase.y * ty.y + vbase.z * ty.z;
- qx = CameraH * nv.x; qy = CameraW * nv.y; qz = CameraW*CameraH * nv.z;
- px = p*CameraH*tx.x; py = p*CameraW*tx.y; pz = p*CameraW*CameraH* tx.z;
- rx = p*CameraH*ty.x; ry = p*CameraW*ty.y; rz = p*CameraW*CameraH* ty.z;
- px=px - ddx*qx; py=py - ddx*qy; pz=pz - ddx*qz;
- rx=rx - ddy*qx; ry=ry - ddy*qy; rz=rz - ddy*qz;
- float za = CameraW * CameraH * p / (qy * VideoCY + qz);
- float zb = CameraW * CameraH * p / (qy * (VideoCY-scry/2.f) + qz);
- float zc = CameraW * CameraH * p / (qy * (VideoCY-scry) + qz);
- float _za = fabs(za) - 100200.f; if (_za<0) _za=0.f;
- float _zb = fabs(zb) - 100200.f; if (_zb<0) _zb=0.f;
- float _zc = fabs(zc) - 100200.f; if (_zc<0) _zc=0.f;
-
- int alpha = (int)(255*40240 / (40240+_za));
- int alphb = (int)(255*40240 / (40240+_zb));
- int alphc = (int)(255*40240 / (40240+_zc));
-
- int sx1 = - VideoCX;
- int sx2 = + VideoCX;
- float qx1 = qx * sx1 + qz;
- float qx2 = qx * sx2 + qz;
- float qyy;
- // d3dStartBuffer();
- ZeroMemory(&d3dExeBufDesc, sizeof(d3dExeBufDesc));
- d3dExeBufDesc.dwSize = sizeof(d3dExeBufDesc);
- hRes = lpd3dExecuteBufferG->Lock( &d3dExeBufDesc );
- if (FAILED(hRes)) DoHalt("Error locking execute buffer");
- lpVertex = (LPD3DTLVERTEX)d3dExeBufDesc.lpData;
- float dtt = (float)(SKYDTime) / 512.f;
- float sky=0;
- float sy = VideoCY - sky;
- qyy = qy * sy;
- q = qx1 + qyy;
- float fxa = (px * sx1 + py * sy + pz) / q;
- float fya = (rx * sx1 + ry * sy + rz) / q;
- q = qx2 + qyy;
- float fxb = (px * sx2 + py * sy + pz) / q;
- float fyb = (rx * sx2 + ry * sy + rz) / q;
-
- lpVertex->sx = 0.f;
- lpVertex->sy = (float)sky;
- lpVertex->sz = 0.0001f;//-8.f / za;
- lpVertex->rhw = 128.f / za;
- /*if (FOGENABLE) {
- lpVertex->color = 0xFFFFFFFF;
- lpVertex->specular = alpha<<24; } else */{
- lpVertex->color = 0x00FFFFFF | alpha<<24;
- lpVertex->specular = 0xFF000000; }
- lpVertex->tu = (fxa + dtt) / 256.f;
- lpVertex->tv = (fya - dtt) / 256.f;
- lpVertex++;
- lpVertex->sx = (float)WinW;
- lpVertex->sy = (float)sky;
- lpVertex->sz = 0.0001f;//-8.f / za;
- lpVertex->rhw = 128.f / za;
- /*if (FOGENABLE) {
- lpVertex->color = 0xFFFFFFFF;
- lpVertex->specular = alpha<<24; } else */{
- lpVertex->color = 0x00FFFFFF | alpha<<24;
- lpVertex->specular = 0xFF000000; }
- lpVertex->tu = (fxb + dtt) / 256.f;
- lpVertex->tv = (fyb - dtt) / 256.f;
- lpVertex++;
- sky=scry/2.f;
- sy = VideoCY - sky;
- qyy = qy * sy;
- q = qx1 + qyy;
- fxa = (px * sx1 + py * sy + pz) / q;
- fya = (rx * sx1 + ry * sy + rz) / q;
- q = qx2 + qyy;
- fxb = (px * sx2 + py * sy + pz) / q;
- fyb = (rx * sx2 + ry * sy + rz) / q;
-
- lpVertex->sx = 0.f;
- lpVertex->sy = (float)sky;
- lpVertex->sz = 0.0001f;//-8.f / zb;
- lpVertex->rhw = 128.f / zb;
- /*if (FOGENABLE) {
- lpVertex->color = 0xFFFFFFFF;
- lpVertex->specular = alphb<<24; } else */{
- lpVertex->color = 0x00FFFFFF | alphb<<24;
- lpVertex->specular = 0xFF000000; }
- lpVertex->tu = (fxa + dtt) / 256.f;
- lpVertex->tv = (fya - dtt) / 256.f;
- lpVertex++;
- lpVertex->sx = (float)WinW;
- lpVertex->sy = (float)sky;
- lpVertex->sz = 0.0001f;//-8.f / zb;
- lpVertex->rhw = 128.f / zb;
- /*if (FOGENABLE) {
- lpVertex->color = 0xFFFFFFFF;
- lpVertex->specular = alphb<<24; } else */{
- lpVertex->color = 0x00FFFFFF | alphb<<24;
- lpVertex->specular = 0xFF000000; }
- lpVertex->tu = (fxb + dtt) / 256.f;
- lpVertex->tv = (fyb - dtt) / 256.f;
- lpVertex++;
- sky=(float)scry;
- sy = VideoCY - sky;
- qyy = qy * sy;
- q = qx1 + qyy;
- fxa = (px * sx1 + py * sy + pz) / q;
- fya = (rx * sx1 + ry * sy + rz) / q;
- q = qx2 + qyy;
- fxb = (px * sx2 + py * sy + pz) / q;
- fyb = (rx * sx2 + ry * sy + rz) / q;
-
- lpVertex->sx = 0.f;
- lpVertex->sy = (float)sky;
- lpVertex->sz = 0.0001f;//-8.f / zb;
- lpVertex->rhw = 128.f / zc;
- /*if (FOGENABLE) {
- lpVertex->color = 0xFFFFFFFF;
- lpVertex->specular = alphc<<24; } else */{
- lpVertex->color = 0x00FFFFFF | alphc<<24;
- lpVertex->specular = 0xFF000000; }
- lpVertex->tu = (fxa + dtt) / 256.f;
- lpVertex->tv = (fya - dtt) / 256.f;
- lpVertex++;
- lpVertex->sx = (float)WinW;
- lpVertex->sy = (float)sky;
- lpVertex->sz = 0.0001f;//-8.f / zb;
- lpVertex->rhw = 128.f / zc;
- /*if (FOGENABLE) {
- lpVertex->color = 0xFFFFFFFF;
- lpVertex->specular = alphc<<24; } else */{
- lpVertex->color = 0x00FFFFFF | alphc<<24;
- lpVertex->specular = 0xFF000000; }
- lpVertex->tu = (fxb + dtt) / 256.f;
- lpVertex->tv = (fyb - dtt) / 256.f;
- lpVertex++;
-
-
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + d3debvcG*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 4;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = hTexture;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMAG;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREMIN;
- lpState->dwArg[0] = D3DFILTER_LINEAR;
- lpState++;
- lpState->drstRenderStateType = D3DRENDERSTATE_FOGCOLOR;
- if (UNDERWATER) lpState->dwArg[0] = CurFogColor;
- else lpState->dwArg[0] = (SkyR<<16) + (SkyG<<8) + SkyB;
- lpState++;
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstruction->wCount = 1U;
- lpInstruction++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = 6;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
- lpInstruction->bOpcode = D3DOP_TRIANGLE;
- lpInstruction->bSize = sizeof(D3DTRIANGLE);
- lpInstruction->wCount = 4;
- lpInstruction++;
- lpTriangle = (LPD3DTRIANGLE)lpInstruction;
-
- lpTriangle->wV1 = 0;
- lpTriangle->wV2 = 1;
- lpTriangle->wV3 = 2;
- lpTriangle->wFlags = 0;
- lpTriangle++;
-
- lpTriangle->wV1 = 1;
- lpTriangle->wV2 = 2;
- lpTriangle->wV3 = 3;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- lpTriangle->wV1 = 2;
- lpTriangle->wV2 = 3;
- lpTriangle->wV3 = 4;
- lpTriangle->wFlags = 0;
- lpTriangle++;
-
- lpTriangle->wV1 = 3;
- lpTriangle->wV2 = 4;
- lpTriangle->wV3 = 5;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBufferG->Unlock( );
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBufferG, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- LINEARFILTER = TRUE;
-
- nv = RotateVector(Sun3dPos);
- SunLight = 0;
- if (nv.z < -2024) RenderSun(nv.x, nv.y, nv.z);
- }
- void RenderFSRect(DWORD Color)
- {
- d3dStartBuffer();
- lpVertex->sx = 0.f;
- lpVertex->sy = 0.f;
- lpVertex->sz = 0.999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = Color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)WinW;
- lpVertex->sy = 0.f;
- lpVertex->sz = 0.999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = Color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = 0.f;
- lpVertex->sy = (float)WinH;
- lpVertex->sz = 0.999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = Color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)WinW;
- lpVertex->sy = (float)WinH;
- lpVertex->sz = (float)0.999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = Color;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + d3debvc*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 1;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = NULL;
- lpState++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstruction->wCount = 1U;
- lpInstruction++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = 4;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
- lpInstruction->bOpcode = D3DOP_TRIANGLE;
- lpInstruction->bSize = sizeof(D3DTRIANGLE);
- lpInstruction->wCount = 2;
- lpInstruction++;
- lpTriangle = (LPD3DTRIANGLE)lpInstruction;
-
- lpTriangle->wV1 = 0;
- lpTriangle->wV2 = 1;
- lpTriangle->wV3 = 2;
- lpTriangle->wFlags = 0;
- lpTriangle++;
-
- lpTriangle->wV1 = 1;
- lpTriangle->wV2 = 2;
- lpTriangle->wV3 = 3;
- lpTriangle->wFlags = 0;
- lpTriangle++;
- lpInstruction = (LPD3DINSTRUCTION)lpTriangle;
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- }
- void RenderHealthBar()
- {
- if (MyHealth >= 100000) return;
- if (MyHealth == 000000) return;
-
- int L = WinW / 4;
- int x0 = WinW - (WinW / 20) - L;
- int y0 = WinH / 40;
- int G = min( (MyHealth * 240 / 100000), 160);
- int R = min( ( (100000 - MyHealth) * 240 / 100000), 160);
-
-
- int L0 = (L * MyHealth) / 100000;
- int H = WinH / 200;
- d3dStartBuffer();
- for (int y=0; y<4; y++) {
- lpVertex->sx = (float)x0-1;
- lpVertex->sy = (float)y0+y;
- lpVertex->sz = 0.9999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0xF0000010;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)x0+L0+1;
- lpVertex->sy = (float)y0+y;
- lpVertex->sz = 0.9999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0xF0000010;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- }
- for (y=1; y<3; y++) {
- lpVertex->sx = (float)x0;
- lpVertex->sy = (float)y0+y;
- lpVertex->sz = 0.99999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0xF0000000 + (G<<8) + (R<<16);
- lpVertex->specular = 0xFF000000;// + (G<<8) + (R<<16);
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)x0+L0;
- lpVertex->sy = (float)y0+y;
- lpVertex->sz = 0.99999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0xF0000000 + (G<<8) + (R<<16);
- lpVertex->specular = 0xFF000000;// + (G<<8) + (R<<16);
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- }
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + d3debvc*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 1;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = NULL;
- lpState++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstruction->wCount = 1U;
- lpInstruction++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = 12;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
- lpInstruction->bOpcode = D3DOP_LINE;
- lpInstruction->bSize = sizeof(D3DLINE);
- lpInstruction->wCount = 6;
- lpInstruction++;
- lpLine = (LPD3DLINE)lpInstruction;
- for (y=0; y<6; y++) {
- lpLine->wV1 = y*2;
- lpLine->wV2 = y*2+1;
- lpLine++;
- }
-
- lpInstruction = (LPD3DINSTRUCTION)lpLine;
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- }
- void Render_Cross(int sx, int sy)
- {
- float w = (float) WinW / 12.f;
- d3dStartBuffer();
- lpVertex->sx = (float)sx-w;
- lpVertex->sy = (float)sy;
- lpVertex->sz = 0.99999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0x80000010;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)sx+w;
- lpVertex->sy = (float)sy;
- lpVertex->sz = 0.99999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0x80000010;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)sx;
- lpVertex->sy = (float)sy-w;
- lpVertex->sz = 0.99999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0x80000010;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpVertex->sx = (float)sx;
- lpVertex->sy = (float)sy+w;
- lpVertex->sz = 0.99999f;
- lpVertex->rhw = 1.f;
- lpVertex->color = 0x80000010;
- lpVertex->specular = 0xFF000000;
- lpVertex->tu = 0;
- lpVertex->tv = 0;
- lpVertex++;
- lpInstruction = (LPD3DINSTRUCTION) ((LPD3DTLVERTEX)d3dExeBufDesc.lpData + d3debvc*3);
- lpInstruction->bOpcode = D3DOP_STATERENDER;
- lpInstruction->bSize = sizeof(D3DSTATE);
- lpInstruction->wCount = 1;
- lpInstruction++;
- lpState = (LPD3DSTATE)lpInstruction;
- lpState->drstRenderStateType = D3DRENDERSTATE_TEXTUREHANDLE;
- lpState->dwArg[0] = NULL;
- lpState++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpState;
- lpInstruction->bOpcode = D3DOP_PROCESSVERTICES;
- lpInstruction->bSize = sizeof(D3DPROCESSVERTICES);
- lpInstruction->wCount = 1U;
- lpInstruction++;
- lpProcessVertices = (LPD3DPROCESSVERTICES)lpInstruction;
- lpProcessVertices->dwFlags = D3DPROCESSVERTICES_COPY;
- lpProcessVertices->wStart = 0U;
- lpProcessVertices->wDest = 0U;
- lpProcessVertices->dwCount = 4;
- lpProcessVertices->dwReserved = 0UL;
- lpProcessVertices++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpProcessVertices;
- lpInstruction->bOpcode = D3DOP_LINE;
- lpInstruction->bSize = sizeof(D3DLINE);
- lpInstruction->wCount = 2;
- lpInstruction++;
- lpLine = (LPD3DLINE)lpInstruction;
-
- lpLine->wV1 = 0;
- lpLine->wV2 = 1;
- lpLine++;
- lpLine->wV1 = 2;
- lpLine->wV2 = 3;
- lpLine++;
-
- lpInstruction = (LPD3DINSTRUCTION)lpLine;
- lpInstruction->bOpcode = D3DOP_EXIT;
- lpInstruction->bSize = 0UL;
- lpInstruction->wCount = 0U;
- lpd3dExecuteBuffer->Unlock( );
-
- hRes = lpd3dDevice->Execute(lpd3dExecuteBuffer, lpd3dViewport, D3DEXECUTE_UNCLIPPED);
- }
- #endif
|