12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964 |
- /*
- ===========================================================================
- Doom 3 GPL Source Code
- Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
- This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
- Doom 3 Source Code is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- Doom 3 Source Code is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
- In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
- If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
- ===========================================================================
- */
- #include "../idlib/precompiled.h"
- #pragma hdrstop
- #include "Game_local.h"
- // _D3XP : rename all gameLocal.time to gameLocal.slow.time for merge!
- #ifdef _D3XP
- static int MakePowerOfTwo( int num ) {
- int pot;
- for (pot = 1 ; pot < num ; pot<<=1) {
- }
- return pot;
- }
- #endif
- const int IMPULSE_DELAY = 150;
- /*
- ==============
- idPlayerView::idPlayerView
- ==============
- */
- idPlayerView::idPlayerView() {
- memset( screenBlobs, 0, sizeof( screenBlobs ) );
- memset( &view, 0, sizeof( view ) );
- player = NULL;
- dvMaterial = declManager->FindMaterial( "_scratch" );
-
-
-
-
-
-
- lagoMaterial = declManager->FindMaterial( LAGO_MATERIAL, false );
- bfgVision = false;
- dvFinishTime = 0;
- kickFinishTime = 0;
- kickAngles.Zero();
- lastDamageTime = 0.0f;
- fadeTime = 0;
- fadeRate = 0.0;
- fadeFromColor.Zero();
- fadeToColor.Zero();
- fadeColor.Zero();
- shakeAng.Zero();
- #ifdef _D3XP
- fxManager = NULL;
- if ( !fxManager ) {
- fxManager = new FullscreenFXManager;
- fxManager->Initialize( this );
- }
- #endif
- ClearEffects();
- }
- /*
- ==============
- idPlayerView::Save
- ==============
- */
- void idPlayerView::Save( idSaveGame *savefile ) const {
- int i;
- const screenBlob_t *blob;
- blob = &screenBlobs[ 0 ];
- for( i = 0; i < MAX_SCREEN_BLOBS; i++, blob++ ) {
- savefile->WriteMaterial( blob->material );
- savefile->WriteFloat( blob->x );
- savefile->WriteFloat( blob->y );
- savefile->WriteFloat( blob->w );
- savefile->WriteFloat( blob->h );
- savefile->WriteFloat( blob->s1 );
- savefile->WriteFloat( blob->t1 );
- savefile->WriteFloat( blob->s2 );
- savefile->WriteFloat( blob->t2 );
- savefile->WriteInt( blob->finishTime );
- savefile->WriteInt( blob->startFadeTime );
- savefile->WriteFloat( blob->driftAmount );
- }
- savefile->WriteInt( dvFinishTime );
- savefile->WriteMaterial( dvMaterial );
- savefile->WriteInt( kickFinishTime );
- savefile->WriteAngles( kickAngles );
- savefile->WriteBool( bfgVision );
-
-
-
-
-
-
- savefile->WriteFloat( lastDamageTime );
- savefile->WriteVec4( fadeColor );
- savefile->WriteVec4( fadeToColor );
- savefile->WriteVec4( fadeFromColor );
- savefile->WriteFloat( fadeRate );
- savefile->WriteInt( fadeTime );
- savefile->WriteAngles( shakeAng );
- savefile->WriteObject( player );
- savefile->WriteRenderView( view );
- #ifdef _D3XP
- if ( fxManager ) {
- fxManager->Save( savefile );
- }
- #endif
- }
- /*
- ==============
- idPlayerView::Restore
- ==============
- */
- void idPlayerView::Restore( idRestoreGame *savefile ) {
- int i;
- screenBlob_t *blob;
- blob = &screenBlobs[ 0 ];
- for( i = 0; i < MAX_SCREEN_BLOBS; i++, blob++ ) {
- savefile->ReadMaterial( blob->material );
- savefile->ReadFloat( blob->x );
- savefile->ReadFloat( blob->y );
- savefile->ReadFloat( blob->w );
- savefile->ReadFloat( blob->h );
- savefile->ReadFloat( blob->s1 );
- savefile->ReadFloat( blob->t1 );
- savefile->ReadFloat( blob->s2 );
- savefile->ReadFloat( blob->t2 );
- savefile->ReadInt( blob->finishTime );
- savefile->ReadInt( blob->startFadeTime );
- savefile->ReadFloat( blob->driftAmount );
- }
- savefile->ReadInt( dvFinishTime );
- savefile->ReadMaterial( dvMaterial );
- savefile->ReadInt( kickFinishTime );
- savefile->ReadAngles( kickAngles );
- savefile->ReadBool( bfgVision );
-
-
-
-
-
-
- savefile->ReadFloat( lastDamageTime );
- savefile->ReadVec4( fadeColor );
- savefile->ReadVec4( fadeToColor );
- savefile->ReadVec4( fadeFromColor );
- savefile->ReadFloat( fadeRate );
- savefile->ReadInt( fadeTime );
- savefile->ReadAngles( shakeAng );
- savefile->ReadObject( reinterpret_cast<idClass *&>( player ) );
- savefile->ReadRenderView( view );
- #ifdef _D3XP
- if ( fxManager ) {
- fxManager->Restore( savefile );
- }
- #endif
- }
- /*
- ==============
- idPlayerView::SetPlayerEntity
- ==============
- */
- void idPlayerView::SetPlayerEntity( idPlayer *playerEnt ) {
- player = playerEnt;
- }
- /*
- ==============
- idPlayerView::ClearEffects
- ==============
- */
- void idPlayerView::ClearEffects() {
- lastDamageTime = MS2SEC( gameLocal.slow.time - 99999 );
- dvFinishTime = ( gameLocal.fast.time - 99999 );
- kickFinishTime = ( gameLocal.slow.time - 99999 );
- for ( int i = 0 ; i < MAX_SCREEN_BLOBS ; i++ ) {
- screenBlobs[i].finishTime = gameLocal.slow.time;
- }
- fadeTime = 0;
- bfgVision = false;
- }
- /*
- ==============
- idPlayerView::GetScreenBlob
- ==============
- */
- screenBlob_t *idPlayerView::GetScreenBlob() {
- screenBlob_t *oldest = &screenBlobs[0];
- for ( int i = 1 ; i < MAX_SCREEN_BLOBS ; i++ ) {
- if ( screenBlobs[i].finishTime < oldest->finishTime ) {
- oldest = &screenBlobs[i];
- }
- }
- return oldest;
- }
- /*
- ==============
- idPlayerView::DamageImpulse
- LocalKickDir is the direction of force in the player's coordinate system,
- which will determine the head kick direction
- ==============
- */
- void idPlayerView::DamageImpulse( idVec3 localKickDir, const idDict *damageDef ) {
- //
- // double vision effect
- //
- if ( lastDamageTime > 0.0f && SEC2MS( lastDamageTime ) + IMPULSE_DELAY > gameLocal.slow.time ) {
- // keep shotgun from obliterating the view
- return;
- }
- float dvTime = damageDef->GetFloat( "dv_time" );
- if ( dvTime ) {
- if ( dvFinishTime < gameLocal.fast.time ) {
- dvFinishTime = gameLocal.fast.time;
- }
- dvFinishTime += g_dvTime.GetFloat() * dvTime;
- // don't let it add up too much in god mode
- if ( dvFinishTime > gameLocal.fast.time + 5000 ) {
- dvFinishTime = gameLocal.fast.time + 5000;
- }
- }
- //
- // head angle kick
- //
- float kickTime = damageDef->GetFloat( "kick_time" );
- if ( kickTime ) {
- kickFinishTime = gameLocal.slow.time + g_kickTime.GetFloat() * kickTime;
- // forward / back kick will pitch view
- kickAngles[0] = localKickDir[0];
- // side kick will yaw view
- kickAngles[1] = localKickDir[1]*0.5f;
- // up / down kick will pitch view
- kickAngles[0] += localKickDir[2];
- // roll will come from side
- kickAngles[2] = localKickDir[1];
- float kickAmplitude = damageDef->GetFloat( "kick_amplitude" );
- if ( kickAmplitude ) {
- kickAngles *= kickAmplitude;
- }
- }
- //
- // screen blob
- //
- float blobTime = damageDef->GetFloat( "blob_time" );
- if ( blobTime ) {
- screenBlob_t *blob = GetScreenBlob();
- blob->startFadeTime = gameLocal.slow.time;
- blob->finishTime = gameLocal.slow.time + blobTime * g_blobTime.GetFloat() * ((float)gameLocal.msec / USERCMD_MSEC);
- const char *materialName = damageDef->GetString( "mtr_blob" );
- blob->material = declManager->FindMaterial( materialName );
- blob->x = damageDef->GetFloat( "blob_x" );
- blob->x += ( gameLocal.random.RandomInt()&63 ) - 32;
- blob->y = damageDef->GetFloat( "blob_y" );
- blob->y += ( gameLocal.random.RandomInt()&63 ) - 32;
-
- float scale = ( 256 + ( ( gameLocal.random.RandomInt()&63 ) - 32 ) ) / 256.0f;
- blob->w = damageDef->GetFloat( "blob_width" ) * g_blobSize.GetFloat() * scale;
- blob->h = damageDef->GetFloat( "blob_height" ) * g_blobSize.GetFloat() * scale;
- blob->s1 = 0;
- blob->t1 = 0;
- blob->s2 = 1;
- blob->t2 = 1;
- blob->driftAmount = 0.5f + gameLocal.random.CRandomFloat() * 0.5;
- }
- //
- // save lastDamageTime for tunnel vision accentuation
- //
- lastDamageTime = MS2SEC( gameLocal.slow.time );
- }
- /*
- ==================
- idPlayerView::AddBloodSpray
- If we need a more generic way to add blobs then we can do that
- but having it localized here lets the material be pre-looked up etc.
- ==================
- */
- void idPlayerView::AddBloodSpray( float duration ) {
- /*
- if ( duration <= 0 || bloodSprayMaterial == NULL || g_skipViewEffects.GetBool() ) {
- return;
- }
- // visit this for chainsaw
- screenBlob_t *blob = GetScreenBlob();
- blob->startFadeTime = gameLocal.slow.time;
- blob->finishTime = gameLocal.slow.time + ( duration * 1000 );
- blob->material = bloodSprayMaterial;
- blob->x = ( gameLocal.random.RandomInt() & 63 ) - 32;
- blob->y = ( gameLocal.random.RandomInt() & 63 ) - 32;
- blob->driftAmount = 0.5f + gameLocal.random.CRandomFloat() * 0.5;
- float scale = ( 256 + ( ( gameLocal.random.RandomInt()&63 ) - 32 ) ) / 256.0f;
- blob->w = 600 * g_blobSize.GetFloat() * scale;
- blob->h = 480 * g_blobSize.GetFloat() * scale;
- float s1 = 0.0f;
- float t1 = 0.0f;
- float s2 = 1.0f;
- float t2 = 1.0f;
- if ( blob->driftAmount < 0.6 ) {
- s1 = 1.0f;
- s2 = 0.0f;
- } else if ( blob->driftAmount < 0.75 ) {
- t1 = 1.0f;
- t2 = 0.0f;
- } else if ( blob->driftAmount < 0.85 ) {
- s1 = 1.0f;
- s2 = 0.0f;
- t1 = 1.0f;
- t2 = 0.0f;
- }
- blob->s1 = s1;
- blob->t1 = t1;
- blob->s2 = s2;
- blob->t2 = t2;
- */
- }
- /*
- ==================
- idPlayerView::WeaponFireFeedback
- Called when a weapon fires, generates head twitches, etc
- ==================
- */
- void idPlayerView::WeaponFireFeedback( const idDict *weaponDef ) {
- int recoilTime;
- recoilTime = weaponDef->GetInt( "recoilTime" );
- // don't shorten a damage kick in progress
- if ( recoilTime && kickFinishTime < gameLocal.slow.time ) {
- idAngles angles;
- weaponDef->GetAngles( "recoilAngles", "5 0 0", angles );
- kickAngles = angles;
- int finish = gameLocal.slow.time + g_kickTime.GetFloat() * recoilTime;
- kickFinishTime = finish;
- }
- }
- /*
- ===================
- idPlayerView::CalculateShake
- ===================
- */
- void idPlayerView::CalculateShake() {
- idVec3 origin, matrix;
- float shakeVolume = gameSoundWorld->CurrentShakeAmplitudeForPosition( gameLocal.slow.time, player->firstPersonViewOrigin );
- //
- // shakeVolume should somehow be molded into an angle here
- // it should be thought of as being in the range 0.0 -> 1.0, although
- // since CurrentShakeAmplitudeForPosition() returns all the shake sounds
- // the player can hear, it can go over 1.0 too.
- //
- shakeAng[0] = gameLocal.random.CRandomFloat() * shakeVolume;
- shakeAng[1] = gameLocal.random.CRandomFloat() * shakeVolume;
- shakeAng[2] = gameLocal.random.CRandomFloat() * shakeVolume;
- }
- /*
- ===================
- idPlayerView::ShakeAxis
- ===================
- */
- idMat3 idPlayerView::ShakeAxis() const {
- return shakeAng.ToMat3();
- }
- /*
- ===================
- idPlayerView::AngleOffset
- kickVector, a world space direction that the attack should
- ===================
- */
- idAngles idPlayerView::AngleOffset() const {
- idAngles ang;
- ang.Zero();
- if ( gameLocal.slow.time < kickFinishTime ) {
- float offset = kickFinishTime - gameLocal.slow.time;
- ang = kickAngles * offset * offset * g_kickAmplitude.GetFloat();
- for ( int i = 0 ; i < 3 ; i++ ) {
- if ( ang[i] > 70.0f ) {
- ang[i] = 70.0f;
- } else if ( ang[i] < -70.0f ) {
- ang[i] = -70.0f;
- }
- }
- }
- return ang;
- }
- /*
- ==================
- idPlayerView::SingleView
- ==================
- */
- void idPlayerView::SingleView( idUserInterface *hud, const renderView_t *view ) {
- // normal rendering
- if ( !view ) {
- return;
- }
- // place the sound origin for the player
- gameSoundWorld->PlaceListener( view->vieworg, view->viewaxis, player->entityNumber + 1, gameLocal.slow.time, hud ? hud->State().GetString( "location" ) : "Undefined" );
- // if the objective system is up, don't do normal drawing
- if ( player->objectiveSystemOpen ) {
- player->objectiveSystem->Redraw( gameLocal.fast.time );
- return;
- }
- // hack the shake in at the very last moment, so it can't cause any consistency problems
- renderView_t hackedView = *view;
- hackedView.viewaxis = hackedView.viewaxis * ShakeAxis();
- #ifdef _D3XP
- if ( gameLocal.portalSkyEnt.GetEntity() && gameLocal.IsPortalSkyAcive() && g_enablePortalSky.GetBool() ) {
- renderView_t portalView = hackedView;
- portalView.vieworg = gameLocal.portalSkyEnt.GetEntity()->GetPhysics()->GetOrigin();
- // setup global fixup projection vars
- if ( 1 ) {
- int vidWidth, vidHeight;
- idVec2 shiftScale;
- renderSystem->GetGLSettings( vidWidth, vidHeight );
- float pot;
- int w = vidWidth;
- pot = MakePowerOfTwo( w );
- shiftScale.x = (float)w / pot;
- int h = vidHeight;
- pot = MakePowerOfTwo( h );
- shiftScale.y = (float)h / pot;
- hackedView.shaderParms[4] = shiftScale.x;
- hackedView.shaderParms[5] = shiftScale.y;
- }
- gameRenderWorld->RenderScene( &portalView );
- renderSystem->CaptureRenderToImage( "_currentRender" );
- hackedView.forceUpdate = true; // FIX: for smoke particles not drawing when portalSky present
- }
- // process the frame
- if (!cvarSystem->GetCVarBool("com_skipRenderer"))
- fxManager->Process( &hackedView );
- if (player->commentaryActive)
- {
- player->commentaryScreen->Redraw(gameLocal.time);
- return;
- }
- #endif
- if ( player->spectating ) {
- return;
- }
- #ifdef _D3XP
- if ( !hud ) {
- return;
- }
- #endif
- // draw screen blobs
- if ( !pm_thirdPerson.GetBool() && !g_skipViewEffects.GetBool() ) {
- for ( int i = 0 ; i < MAX_SCREEN_BLOBS ; i++ ) {
- screenBlob_t *blob = &screenBlobs[i];
- if ( blob->finishTime <= gameLocal.slow.time ) {
- continue;
- }
-
- blob->y += blob->driftAmount;
- float fade = (float)( blob->finishTime - gameLocal.slow.time ) / ( blob->finishTime - blob->startFadeTime );
- if ( fade > 1.0f ) {
- fade = 1.0f;
- }
- if ( fade ) {
- renderSystem->SetColor4( 1,1,1,fade );
- renderSystem->DrawStretchPic( blob->x, blob->y, blob->w, blob->h,blob->s1, blob->t1, blob->s2, blob->t2, blob->material );
- }
- }
- player->DrawHUD( hud );
- // armor impulse feedback
- float armorPulse = ( gameLocal.fast.time - player->lastArmorPulse ) / 250.0f;
- // tunnel vision
- float health = 0.0f;
- if ( g_testHealthVision.GetFloat() != 0.0f ) {
- health = g_testHealthVision.GetFloat();
- } else {
- health = player->health;
- }
- float alpha = health / 100.0f;
- if ( alpha < 0.0f ) {
- alpha = 0.0f;
- }
- if ( alpha > 1.0f ) {
- alpha = 1.0f;
- }
-
- }
- // test a single material drawn over everything
- if ( g_testPostProcess.GetString()[0] ) {
- const idMaterial *mtr = declManager->FindMaterial( g_testPostProcess.GetString(), false );
-
- if ( !mtr )
- {
- common->Printf( "Material not found.\n" );
- g_testPostProcess.SetString( "" );
- }
- else
- {
- //xpac
- renderSystem->CaptureRenderToImage( "_currentRender" );
- renderSystem->SetColor4( 1.0f, 1.0f, 1.0f, 1.0f );
- renderSystem->DrawStretchPic( 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 1.0f, 1.0f, mtr );
- }
- }
- }
- /*
- =================
- idPlayerView::Flash
- flashes the player view with the given color
- =================
- */
- void idPlayerView::Flash(idVec4 color, int time ) {
- Fade(idVec4(0, 0, 0, 0), time);
- fadeFromColor = colorWhite;
- }
- /*
- =================
- idPlayerView::Fade
- used for level transition fades
- assumes: color.w is 0 or 1
- =================
- */
- void idPlayerView::Fade( idVec4 color, int time ) {
- #ifdef _D3XP
- SetTimeState ts( player->timeGroup );
- #endif
- if ( !fadeTime ) {
- fadeFromColor.Set( 0.0f, 0.0f, 0.0f, 1.0f - color[ 3 ] );
- } else {
- fadeFromColor = fadeColor;
- }
- fadeToColor = color;
- if ( time <= 0 ) {
- fadeRate = 0;
- time = 0;
- fadeColor = fadeToColor;
- } else {
- fadeRate = 1.0f / ( float )time;
- }
- if ( gameLocal.realClientTime == 0 && time == 0 ) {
- fadeTime = 1;
- } else {
- fadeTime = gameLocal.realClientTime + time;
- }
- }
- /*
- =================
- idPlayerView::ScreenFade
- =================
- */
- void idPlayerView::ScreenFade() {
- int msec;
- float t;
- if ( !fadeTime ) {
- return;
- }
- #ifdef _D3XP
- SetTimeState ts( player->timeGroup );
- #endif
- msec = fadeTime - gameLocal.realClientTime;
- if ( msec <= 0 ) {
- fadeColor = fadeToColor;
- if ( fadeColor[ 3 ] == 0.0f ) {
- fadeTime = 0;
- }
- } else {
- t = ( float )msec * fadeRate;
- fadeColor = fadeFromColor * t + fadeToColor * ( 1.0f - t );
- }
- if ( fadeColor[ 3 ] != 0.0f ) {
- renderSystem->SetColor4( fadeColor[ 0 ], fadeColor[ 1 ], fadeColor[ 2 ], fadeColor[ 3 ] );
- renderSystem->DrawStretchPic( 0, 0, 640, 480, 0, 0, 1, 1, declManager->FindMaterial( "_white" ) );
- }
- }
- /*
- ===================
- idPlayerView::RenderPlayerView
- ===================
- */
- void idPlayerView::RenderPlayerView( idUserInterface *hud ) {
- const renderView_t *view = player->GetRenderView();
- SingleView( hud, view );
- ScreenFade();
- if ( net_clientLagOMeter.GetBool() && lagoMaterial && gameLocal.isClient ) {
- renderSystem->SetColor4( 1.0f, 1.0f, 1.0f, 1.0f );
- renderSystem->DrawStretchPic( 10.0f, 380.0f, 64.0f, 64.0f, 0.0f, 0.0f, 1.0f, 1.0f, lagoMaterial );
- }
- }
- #ifdef _D3XP
- /*
- ===================
- idPlayerView::WarpVision
- ===================
- */
- int idPlayerView::AddWarp( idVec3 worldOrigin, float centerx, float centery, float initialRadius, float durationMsec ) {
- FullscreenFX_Warp *fx = (FullscreenFX_Warp*)( fxManager->FindFX( "warp" ) );
- if ( fx ) {
- fx->EnableGrabber( true );
- return 1;
- }
- return 1;
- }
- void idPlayerView::FreeWarp( int id ) {
- FullscreenFX_Warp *fx = (FullscreenFX_Warp*)( fxManager->FindFX( "warp" ) );
- if ( fx ) {
- fx->EnableGrabber( false );
- return;
- }
- }
- /*
- ==================
- FxFader::FxFader
- ==================
- */
- FxFader::FxFader() {
- time = 0;
- state = FX_STATE_OFF;
- alpha = 0;
- msec = 1000;
- }
- /*
- ==================
- FxFader::SetTriggerState
- ==================
- */
- bool FxFader::SetTriggerState( bool active ) {
- // handle on/off states
- if ( active && state == FX_STATE_OFF ) {
- state = FX_STATE_RAMPUP;
- time = gameLocal.slow.time + msec;
- }
- else if ( !active && state == FX_STATE_ON ) {
- state = FX_STATE_RAMPDOWN;
- time = gameLocal.slow.time + msec;
- }
- // handle rampup/rampdown states
- if ( state == FX_STATE_RAMPUP ) {
- if ( gameLocal.slow.time >= time ) {
- state = FX_STATE_ON;
- }
- }
- else if ( state == FX_STATE_RAMPDOWN ) {
- if ( gameLocal.slow.time >= time ) {
- state = FX_STATE_OFF;
- }
- }
- // compute alpha
- switch ( state ) {
- case FX_STATE_ON: alpha = 1; break;
- case FX_STATE_OFF: alpha = 0; break;
- case FX_STATE_RAMPUP: alpha = 1 - (float)( time - gameLocal.slow.time ) / msec; break;
- case FX_STATE_RAMPDOWN: alpha = (float)( time - gameLocal.slow.time ) / msec; break;
- }
- if ( alpha > 0 ) {
- return true;
- }
- else {
- return false;
- }
- }
- /*
- ==================
- FxFader::Save
- ==================
- */
- void FxFader::Save( idSaveGame *savefile ) {
- savefile->WriteInt( time );
- savefile->WriteInt( state );
- savefile->WriteFloat( alpha );
- savefile->WriteInt( msec );
- }
- /*
- ==================
- FxFader::Restore
- ==================
- */
- void FxFader::Restore( idRestoreGame *savefile ) {
- savefile->ReadInt( time );
- savefile->ReadInt( state );
- savefile->ReadFloat( alpha );
- savefile->ReadInt( msec );
- }
- /*
- ==================
- FullscreenFX_Helltime::Save
- ==================
- */
- void FullscreenFX::Save( idSaveGame *savefile ) {
- fader.Save( savefile );
- }
- /*
- ==================
- FullscreenFX_Helltime::Restore
- ==================
- */
- void FullscreenFX::Restore( idRestoreGame *savefile ) {
- fader.Restore( savefile );
- }
- /*
- ==================
- FullscreenFX_Helltime::Initialize
- ==================
- */
- void FullscreenFX_Helltime::Initialize() {
- /*
- acInitMaterials[0] = declManager->FindMaterial( "textures/smf/bloodorb1/ac_init" );
- acInitMaterials[1] = declManager->FindMaterial( "textures/smf/bloodorb2/ac_init" );
- acInitMaterials[2] = declManager->FindMaterial( "textures/smf/bloodorb3/ac_init" );
- acCaptureMaterials[0] = declManager->FindMaterial( "textures/smf/bloodorb1/ac_capture" );
- acCaptureMaterials[1] = declManager->FindMaterial( "textures/smf/bloodorb2/ac_capture" );
- acCaptureMaterials[2] = declManager->FindMaterial( "textures/smf/bloodorb3/ac_capture" );
- acDrawMaterials[0] = declManager->FindMaterial( "textures/smf/bloodorb1/ac_draw" );
- acDrawMaterials[1] = declManager->FindMaterial( "textures/smf/bloodorb2/ac_draw" );
- acDrawMaterials[2] = declManager->FindMaterial( "textures/smf/bloodorb3/ac_draw" );
- crCaptureMaterials[0] = declManager->FindMaterial( "textures/smf/bloodorb1/cr_capture" );
- crCaptureMaterials[1] = declManager->FindMaterial( "textures/smf/bloodorb2/cr_capture" );
- crCaptureMaterials[2] = declManager->FindMaterial( "textures/smf/bloodorb3/cr_capture" );
- crDrawMaterials[0] = declManager->FindMaterial( "textures/smf/bloodorb1/cr_draw" );
- crDrawMaterials[1] = declManager->FindMaterial( "textures/smf/bloodorb2/cr_draw" );
- crDrawMaterials[2] = declManager->FindMaterial( "textures/smf/bloodorb3/cr_draw" );
- */
- clearAccumBuffer = true;
- }
- /*
- ==================
- FullscreenFX_Helltime::DetermineLevel
- ==================
- */
- int FullscreenFX_Helltime::DetermineLevel() {
- idPlayer *player;
- int testfx = g_testHelltimeFX.GetInteger();
- // for testing purposes
- if ( testfx >= 0 && testfx < 3 ) {
- return testfx;
- }
- player = fxman->GetPlayer();
- if ( player->PowerUpActive( INVULNERABILITY ) ) {
- return 2;
- }
- else if ( player->PowerUpActive( BERSERK ) ) {
- return 1;
- }
- else if ( player->PowerUpActive( HELLTIME ) ) {
- return 0;
- }
- return -1;
- }
- /*
- ==================
- FullscreenFX_Helltime::Active
- ==================
- */
- bool FullscreenFX_Helltime::Active() {
- if ( gameLocal.inCinematic || gameLocal.isMultiplayer ) {
- return false;
- }
- if ( DetermineLevel() >= 0 ) {
- return true;
- }
- else {
- // latch the clear flag
- if ( fader.GetAlpha() == 0 ) {
- clearAccumBuffer = true;
- }
- }
- return false;
- }
- /*
- ==================
- FullscreenFX_Helltime::AccumPass
- ==================
- */
- void FullscreenFX_Helltime::AccumPass( const renderView_t *view ) {
- idVec2 shiftScale;
- int level = DetermineLevel();
- // for testing
- if ( level < 0 || level > 2 ) {
- level = 0;
- }
- shiftScale = fxman->GetShiftScale();
- renderSystem->SetColor4( 1, 1, 1, 1 );
- // capture pass
- /*
- if ( clearAccumBuffer ) {
- clearAccumBuffer = false;
- renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1, 1, 0, acInitMaterials[level] );
- }
- else {
- renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1, 1, 0, acCaptureMaterials[level] );
- renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, shiftScale.y, shiftScale.x, 0, crCaptureMaterials[level] );
- }
- renderSystem->CaptureRenderToImage( "_accum" );
- */
- }
- /*
- ==================
- FullscreenFX_Helltime::HighQuality
- ==================
- */
- void FullscreenFX_Helltime::HighQuality() {
- idVec2 shiftScale;
- int level = DetermineLevel();
- // for testing
- if ( level < 0 || level > 2 ) {
- level = 0;
- }
- shiftScale = fxman->GetShiftScale();
- renderSystem->SetColor4( 1, 1, 1, 1 );
- /*
- // draw pass
- renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1, 1, 0, acDrawMaterials[level] );
- renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, shiftScale.y, shiftScale.x, 0, crDrawMaterials[level] );
- */
- }
- /*
- ==================
- FullscreenFX_Helltime::Restore
- ==================
- */
- void FullscreenFX_Helltime::Restore( idRestoreGame *savefile ) {
- FullscreenFX::Restore( savefile );
- // latch the clear flag
- clearAccumBuffer = true;
- }
- /*
- ==================
- FullscreenFX_Multiplayer::Initialize
- ==================
- */
- void FullscreenFX_Multiplayer::Initialize() {
- /*
- acInitMaterials = declManager->FindMaterial( "textures/smf/multiplayer1/ac_init" );
- acCaptureMaterials = declManager->FindMaterial( "textures/smf/multiplayer1/ac_capture" );
- acDrawMaterials = declManager->FindMaterial( "textures/smf/multiplayer1/ac_draw" );
- crCaptureMaterials = declManager->FindMaterial( "textures/smf/multiplayer1/cr_capture" );
- crDrawMaterials = declManager->FindMaterial( "textures/smf/multiplayer1/cr_draw" );
- */
- clearAccumBuffer = true;
- }
- /*
- ==================
- FullscreenFX_Multiplayer::DetermineLevel
- ==================
- */
- int FullscreenFX_Multiplayer::DetermineLevel() {
- idPlayer *player;
- int testfx = g_testMultiplayerFX.GetInteger();
- // for testing purposes
- if ( testfx >= 0 && testfx < 3 ) {
- return testfx;
- }
- player = fxman->GetPlayer();
- if ( player->PowerUpActive( INVULNERABILITY ) ) {
- return 2;
- }
- //else if ( player->PowerUpActive( HASTE ) ) {
- // return 1;
- //}
- else if ( player->PowerUpActive( BERSERK ) ) {
- return 0;
- }
- return -1;
- }
- /*
- ==================
- FullscreenFX_Multiplayer::Active
- ==================
- */
- bool FullscreenFX_Multiplayer::Active() {
- if ( !gameLocal.isMultiplayer && g_testMultiplayerFX.GetInteger() == -1 ) {
- return false;
- }
- if ( DetermineLevel() >= 0 ) {
- return true;
- }
- else {
- // latch the clear flag
- if ( fader.GetAlpha() == 0 ) {
- clearAccumBuffer = true;
- }
- }
- return false;
- }
- /*
- ==================
- FullscreenFX_Multiplayer::AccumPass
- ==================
- */
- void FullscreenFX_Multiplayer::AccumPass( const renderView_t *view ) {
- idVec2 shiftScale;
- int level = DetermineLevel();
- // for testing
- if ( level < 0 || level > 2 ) {
- level = 0;
- }
- shiftScale = fxman->GetShiftScale();
- renderSystem->SetColor4( 1, 1, 1, 1 );
- /*
- // capture pass
- if ( clearAccumBuffer ) {
- clearAccumBuffer = false;
- renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1, 1, 0, acInitMaterials );
- }
- else {
- renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1, 1, 0, acCaptureMaterials );
- renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, shiftScale.y, shiftScale.x, 0, crCaptureMaterials );
- }
- renderSystem->CaptureRenderToImage( "_accum" );
- */
- }
- /*
- ==================
- FullscreenFX_Multiplayer::HighQuality
- ==================
- */
- void FullscreenFX_Multiplayer::HighQuality() {
- idVec2 shiftScale;
- int level = DetermineLevel();
- // for testing
- if ( level < 0 || level > 2 ) {
- level = 0;
- }
- shiftScale = fxman->GetShiftScale();
- renderSystem->SetColor4( 1, 1, 1, 1 );
- /*
- // draw pass
- renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1, 1, 0, acDrawMaterials );
- renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, shiftScale.y, shiftScale.x, 0, crDrawMaterials );
- */
- }
- /*
- ==================
- FullscreenFX_Multiplayer::Restore
- ==================
- */
- void FullscreenFX_Multiplayer::Restore( idRestoreGame *savefile ) {
- FullscreenFX::Restore( savefile );
- // latch the clear flag
- clearAccumBuffer = true;
- }
- /*
- ==================
- FullscreenFX_Warp::Initialize
- ==================
- */
- void FullscreenFX_Warp::Initialize() {
-
- grabberEnabled = false;
- startWarpTime = 0;
- }
- /*
- ==================
- FullscreenFX_Warp::Active
- ==================
- */
- bool FullscreenFX_Warp::Active() {
- if ( grabberEnabled ) {
- return true;
- }
- return false;
- }
- /*
- ==================
- FullscreenFX_Warp::Save
- ==================
- */
- void FullscreenFX_Warp::Save( idSaveGame *savefile ) {
- FullscreenFX::Save( savefile );
- savefile->WriteBool( grabberEnabled );
- savefile->WriteInt( startWarpTime );
- }
- /*
- ==================
- FullscreenFX_Warp::Restore
- ==================
- */
- void FullscreenFX_Warp::Restore( idRestoreGame *savefile ) {
- FullscreenFX::Restore( savefile );
- savefile->ReadBool( grabberEnabled );
- savefile->ReadInt( startWarpTime );
- }
- /*
- ==================
- FullscreenFX_Warp::DrawWarp
- ==================
- */
- void FullscreenFX_Warp::DrawWarp( WarpPolygon_t wp, float interp ) {
- idVec4 mid1_uv, mid2_uv;
- idVec4 mid1, mid2;
- idVec2 drawPts[6], shiftScale;
- WarpPolygon_t trans;
- trans = wp;
- shiftScale = fxman->GetShiftScale();
- // compute mid points
- mid1 = trans.outer1 * ( interp ) + trans.center * ( 1 - interp );
- mid2 = trans.outer2 * ( interp ) + trans.center * ( 1 - interp );
- mid1_uv = trans.outer1 * ( 0.5 ) + trans.center * ( 1 - 0.5 );
- mid2_uv = trans.outer2 * ( 0.5 ) + trans.center * ( 1 - 0.5 );
- // draw [outer1, mid2, mid1]
- drawPts[0].Set( trans.outer1.x, trans.outer1.y );
- drawPts[1].Set( mid2.x, mid2.y );
- drawPts[2].Set( mid1.x, mid1.y );
- drawPts[3].Set( trans.outer1.z, trans.outer1.w );
- drawPts[4].Set( mid2_uv.z, mid2_uv.w );
- drawPts[5].Set( mid1_uv.z, mid1_uv.w );
- for ( int j = 0; j < 3; j++ ) {
- drawPts[j+3].x *= shiftScale.x;
- drawPts[j+3].y *= shiftScale.y;
- }
- renderSystem->DrawStretchTri( drawPts[0], drawPts[1], drawPts[2], drawPts[3], drawPts[4], drawPts[5], material );
- // draw [outer1, outer2, mid2]
- drawPts[0].Set( trans.outer1.x, trans.outer1.y );
- drawPts[1].Set( trans.outer2.x, trans.outer2.y );
- drawPts[2].Set( mid2.x, mid2.y );
- drawPts[3].Set( trans.outer1.z, trans.outer1.w );
- drawPts[4].Set( trans.outer2.z, trans.outer2.w );
- drawPts[5].Set( mid2_uv.z, mid2_uv.w );
- for ( int j = 0; j < 3; j++ ) {
- drawPts[j+3].x *= shiftScale.x;
- drawPts[j+3].y *= shiftScale.y;
- }
- renderSystem->DrawStretchTri( drawPts[0], drawPts[1], drawPts[2], drawPts[3], drawPts[4], drawPts[5], material );
- // draw [mid1, mid2, center]
- drawPts[0].Set( mid1.x, mid1.y );
- drawPts[1].Set( mid2.x, mid2.y );
- drawPts[2].Set( trans.center.x, trans.center.y );
- drawPts[3].Set( mid1_uv.z, mid1_uv.w );
- drawPts[4].Set( mid2_uv.z, mid2_uv.w );
- drawPts[5].Set( trans.center.z, trans.center.w );
- for ( int j = 0; j < 3; j++ ) {
- drawPts[j+3].x *= shiftScale.x;
- drawPts[j+3].y *= shiftScale.y;
- }
- renderSystem->DrawStretchTri( drawPts[0], drawPts[1], drawPts[2], drawPts[3], drawPts[4], drawPts[5], material );
- }
- /*
- ==================
- FullscreenFX_Warp::HighQuality
- ==================
- */
- void FullscreenFX_Warp::HighQuality() {
- float x1, y1, x2, y2, radius, interp;
- idVec2 center;
- int STEP = 9;
- interp = ( idMath::Sin( (float)( gameLocal.slow.time - startWarpTime ) / 1000 ) + 1 ) / 2.f;
- interp = 0.7 * ( 1 - interp ) + 0.3 * ( interp );
- // draw the warps
- center.x = 320;
- center.y = 240;
- radius = 200;
- for ( float i = 0; i < 360; i += STEP ) {
- // compute the values
- x1 = idMath::Sin( DEG2RAD( i ) );
- y1 = idMath::Cos( DEG2RAD( i ) );
- x2 = idMath::Sin( DEG2RAD( i + STEP ) );
- y2 = idMath::Cos( DEG2RAD( i + STEP ) );
- // add warp polygon
- WarpPolygon_t p;
- p.outer1.x = center.x + x1 * radius;
- p.outer1.y = center.y + y1 * radius;
- p.outer1.z = p.outer1.x / 640.f;
- p.outer1.w = 1 - ( p.outer1.y / 480.f );
- p.outer2.x = center.x + x2 * radius;
- p.outer2.y = center.y + y2 * radius;
- p.outer2.z = p.outer2.x / 640.f;
- p.outer2.w = 1 - ( p.outer2.y / 480.f );
- p.center.x = center.x;
- p.center.y = center.y;
- p.center.z = p.center.x / 640.f;
- p.center.w = 1 - ( p.center.y / 480.f );
-
- // draw it
- DrawWarp( p, interp );
- }
- }
- /*
- ==================
- FullscreenFX_EnviroSuit::Initialize
- ==================
- */
- void FullscreenFX_EnviroSuit::Initialize() {
- material = declManager->FindMaterial( "textures/fx/enviro_suit" );
- }
- /*
- ==================
- FullscreenFX_EnviroSuit::Active
- ==================
- */
- bool FullscreenFX_EnviroSuit::Active() {
- idPlayer *player;
- player = fxman->GetPlayer();
- if ( player->PowerUpActive( ENVIROSUIT ) ) {
- return true;
- }
- return false;
- }
- /*
- ==================
- FullscreenFX_EnviroSuit::HighQuality
- ==================
- */
- void FullscreenFX_EnviroSuit::HighQuality() {
-
- renderSystem->SetColor4( 1, 1, 1, 1 );
- renderSystem->DrawStretchPic( 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 1.0f, 1.0f, material );
- }
- /*
- ==================
- FullscreenFX_DoubleVision::Initialize
- ==================
- */
- void FullscreenFX_DoubleVision::Initialize() {
- material = declManager->FindMaterial( "textures/smf/doubleVision" );
- }
- /*
- ==================
- FullscreenFX_DoubleVision::Active
- ==================
- */
- bool FullscreenFX_DoubleVision::Active() {
- if ( gameLocal.fast.time < fxman->GetPlayerView()->dvFinishTime ) {
- return true;
- }
- return false;
- }
- /*
- ==================
- FullscreenFX_DoubleVision::HighQuality
- ==================
- */
- void FullscreenFX_DoubleVision::HighQuality() {
- int offset = fxman->GetPlayerView()->dvFinishTime - gameLocal.fast.time;
- float scale = offset * g_dvAmplitude.GetFloat();
- idPlayer *player;
- idVec2 shiftScale;
- // for testing purposes
- if ( !Active() ) {
- static int test = 0;
- if ( test > 312 ) {
- test = 0;
- }
- offset = test++;
- scale = offset * g_dvAmplitude.GetFloat();
- }
- player = fxman->GetPlayer();
- shiftScale = fxman->GetShiftScale();
- offset *= 2; // crutch up for higher res
- // set the scale and shift
- if ( scale > 0.5f ) {
- scale = 0.5f;
- }
- float shift = scale * sin( sqrtf( (float)offset ) * g_dvFrequency.GetFloat() );
- shift = fabs( shift );
- // carry red tint if in berserk mode
- idVec4 color(1, 1, 1, 1);
- if ( gameLocal.fast.time < player->inventory.powerupEndTime[ BERSERK ] ) {
- color.y = 0;
- color.z = 0;
- }
- if ( !gameLocal.isMultiplayer && gameLocal.fast.time < player->inventory.powerupEndTime[ HELLTIME ] || gameLocal.fast.time < player->inventory.powerupEndTime[ INVULNERABILITY ]) {
- color.y = 0;
- color.z = 0;
- }
- renderSystem->SetColor4( color.x, color.y, color.z, 1.0f );
- renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, shift, shiftScale.y, shiftScale.x, 0, material );
- renderSystem->SetColor4( color.x, color.y, color.z, 0.5f );
- renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, shiftScale.y, (1-shift) * shiftScale.x, 0, material );
- }
- /*
- ==================
- FullscreenFX_InfluenceVision::Initialize
- ==================
- */
- void FullscreenFX_InfluenceVision::Initialize() {
- }
- /*
- ==================
- FullscreenFX_InfluenceVision::Active
- ==================
- */
- bool FullscreenFX_InfluenceVision::Active() {
- idPlayer *player;
- player = fxman->GetPlayer();
- if ( player->GetInfluenceMaterial() || player->GetInfluenceEntity() ) {
- return true;
- }
- return false;
- }
- /*
- ==================
- FullscreenFX_InfluenceVision::HighQuality
- ==================
- */
- void FullscreenFX_InfluenceVision::HighQuality() {
- float distance = 0.0f;
- float pct = 1.0f;
- idPlayer *player;
- idVec2 shiftScale;
- shiftScale = fxman->GetShiftScale();
- player = fxman->GetPlayer();
- if ( player->GetInfluenceEntity() ) {
- distance = ( player->GetInfluenceEntity()->GetPhysics()->GetOrigin() - player->GetPhysics()->GetOrigin() ).Length();
- if ( player->GetInfluenceRadius() != 0.0f && distance < player->GetInfluenceRadius() ) {
- pct = distance / player->GetInfluenceRadius();
- pct = 1.0f - idMath::ClampFloat( 0.0f, 1.0f, pct );
- }
- }
- if ( player->GetInfluenceMaterial() ) {
- renderSystem->SetColor4( 1.0f, 1.0f, 1.0f, pct );
- renderSystem->DrawStretchPic( 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 1.0f, 1.0f, player->GetInfluenceMaterial() );
- } else if ( player->GetInfluenceEntity() == NULL ) {
- return;
- } else {
- // int offset = 25 + sinf( gameLocal.slow.time );
- // DoubleVision( hud, view, pct * offset );
- }
- }
- void FullscreenFX_Haze::Initialize() {
- material = declManager->FindMaterial( "textures/fx/heathaze" );
- hazeActive = false;
- hazeStartTime = 0;
- hazeEndTime = 0;
- hazeAmount = 0;
- }
- bool FullscreenFX_Haze::Active()
- {
- idPlayer *player;
- player = fxman->GetPlayer();
- float lerp;
- float currentTime = gameLocal.time;
- float lookTimeMax = this->hazeEndTime - this->hazeStartTime;
- float lookTimeMin = this->hazeStartTime;
- currentTime -= this->hazeStartTime;
- lerp = lookTimeMax != 0 ? currentTime / lookTimeMax : 1.01f;
- if (lerp > 1)
- hazeActive = false;
- hazeAmount = idMath::Lerp(hazeValue, 0, lerp);
- if ( hazeActive )
- {
- return true;
- }
- return false;
- }
- void FullscreenFX_Haze::HighQuality()
- {
- renderSystem->SetColor4( 1, 1, 1, hazeAmount );
- renderSystem->DrawStretchPic( 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 1.0f, 1.0f, material );
- }
- void FullscreenFX_Haze::ActivateHaze(int time, float value)
- {
- hazeActive = true;
- hazeStartTime = gameLocal.time;
- hazeEndTime = gameLocal.time + time;
- hazeValue = value;
- }
- void idPlayerView::AddHaze(int time, float value)
- {
- FullscreenFX_Haze *fx = (FullscreenFX_Haze*)( fxManager->FindFX( "haze" ) );
- if ( fx )
- {
- fx->ActivateHaze(time, value);
- }
- }
- /*
- ==================
- FullscreenFX_Bloom::Initialize
- ==================
- */
- void FullscreenFX_Bloom::Initialize() {
- drawMaterial = declManager->FindMaterial( "textures/smf/bloom2/draw" );
- initMaterial = declManager->FindMaterial( "textures/smf/bloom2/init" );
- //currentMaterial = declManager->FindMaterial( "textures/smf/bloom2/currentMaterial" );
- currentIntensity = 0;
- targetIntensity = 0;
- }
- /*
- ==================
- FullscreenFX_Bloom::Active
- ==================
- */
- bool FullscreenFX_Bloom::Active() {
- idPlayer *player;
- player = fxman->GetPlayer();
- if ( player && player->bloomEnabled ) {
- return true;
- }
- currentIntensity = 0;
- return false;
- }
- /*
- ==================
- FullscreenFX_Bloom::HighQuality
- ==================
- */
- void FullscreenFX_Bloom::HighQuality() {
- float shift, delta;
- idVec2 shiftScale;
- idPlayer *player;
- int num;
- shift = 1;
- player = fxman->GetPlayer();
- shiftScale = fxman->GetShiftScale();
- renderSystem->SetColor4( 1, 1, 1, 1 );
- // if intensity value is different, start the blend
- targetIntensity = g_testBloomIntensity.GetFloat();
- if ( player && player->bloomEnabled ) {
- targetIntensity = player->bloomIntensity;
- }
- delta = targetIntensity - currentIntensity;
- float step = 0.001f;
- if ( step < fabs( delta ) ) {
- if ( delta < 0 ) {
- step = -step;
- }
- currentIntensity += step;
- }
- // draw the blends
- num = g_testBloomNumPasses.GetInteger();
- for ( int i = 0; i < num; i++ ) {
- float s1 = 0, t1 = 0, s2 = 1, t2 = 1;
- float alpha;
- // do the center scale
- s1 -= 0.5;
- s1 *= shift;
- s1 += 0.5;
- s1 *= shiftScale.x;
- t1 -= 0.5;
- t1 *= shift;
- t1 += 0.5;
- t1 *= shiftScale.y;
- s2 -= 0.5;
- s2 *= shift;
- s2 += 0.5;
- s2 *= shiftScale.x;
- t2 -= 0.5;
- t2 *= shift;
- t2 += 0.5;
- t2 *= shiftScale.y;
- // draw it
- if ( num == 1 ) {
- alpha = 1;
- }
- else {
- alpha = 1 - (float)i / ( num - 1 );
- }
- renderSystem->SetColor4( alpha, alpha, alpha, 1 );
- renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, s1, t2, s2, t1, drawMaterial );
- shift += currentIntensity;
- }
- }
- /*
- ==================
- FullscreenFX_Bloom::Save
- ==================
- */
- void FullscreenFX_Bloom::Save( idSaveGame *savefile ) {
- FullscreenFX::Save( savefile );
- savefile->WriteFloat( currentIntensity );
- savefile->WriteFloat( targetIntensity );
- }
- /*
- ==================
- FullscreenFX_Bloom::Restore
- ==================
- */
- void FullscreenFX_Bloom::Restore( idRestoreGame *savefile ) {
- FullscreenFX::Restore( savefile );
- savefile->ReadFloat( currentIntensity );
- savefile->ReadFloat( targetIntensity );
- }
- /*
- ==================
- FullscreenFXManager::FullscreenFXManager
- ==================
- */
- FullscreenFXManager::FullscreenFXManager() {
- highQualityMode = false;
- playerView = NULL;
-
- shiftScale.Set( 0, 0 );
- }
- /*
- ==================
- FullscreenFXManager::~FullscreenFXManager
- ==================
- */
- FullscreenFXManager::~FullscreenFXManager() {
- }
- /*
- ==================
- FullscreenFXManager::FindFX
- ==================
- */
- FullscreenFX* FullscreenFXManager::FindFX( idStr name ) {
- for ( int i = 0; i < fx.Num(); i++ ) {
- if ( fx[i]->GetName() == name ) {
- return fx[i];
- }
- }
- return NULL;
- }
- /*
- ==================
- FullscreenFXManager::CreateFX
- ==================
- */
- void FullscreenFXManager::CreateFX( idStr name, idStr fxtype, int fade ) {
- FullscreenFX *pfx = NULL;
- if ( fxtype == "helltime" ) {
- pfx = new FullscreenFX_Helltime;
- }
- else if ( fxtype == "warp" ) {
- pfx = new FullscreenFX_Warp;
- }
- else if ( fxtype == "envirosuit" ) {
- pfx = new FullscreenFX_EnviroSuit;
- }
- else if ( fxtype == "doublevision" ) {
- pfx = new FullscreenFX_DoubleVision;
- }
- else if ( fxtype == "multiplayer" ) {
- pfx = new FullscreenFX_Multiplayer;
- }
- else if ( fxtype == "influencevision" ) {
- pfx = new FullscreenFX_InfluenceVision;
- }
- else if ( fxtype == "bloom" ) {
- pfx = new FullscreenFX_Bloom;
- }
- else if ( fxtype == "haze" )
- {
- pfx = new FullscreenFX_Haze;
- }
- else {
- assert( 0 );
- }
- if ( pfx ) {
- pfx->Initialize();
- pfx->SetFXManager( this );
- pfx->SetName( name );
- pfx->SetFadeSpeed( fade );
- fx.Append( pfx );
- }
- }
- /*
- ==================
- FullscreenFXManager::Initialize
- ==================
- */
- void FullscreenFXManager::Initialize( idPlayerView *pv ) {
- // set the playerview
- playerView = pv;
-
- // allocate the fx
- CreateFX( "helltime", "helltime", 1000 );
- CreateFX( "warp", "warp", 0 );
- CreateFX( "envirosuit", "envirosuit", 1 ); //bc how long to fade out hte enviro suit
- CreateFX( "doublevision", "doublevision", 0 );
- CreateFX( "multiplayer", "multiplayer", 1000 );
- CreateFX( "influencevision", "influencevision", 1000 );
- CreateFX( "bloom", "bloom", 0 );
- CreateFX( "haze", "haze", 0);
- // pre-cache the texture grab so we dont hitch
- renderSystem->CropRenderSize( 512, 512, true );
- renderSystem->CaptureRenderToImage( "_accum" );
- renderSystem->UnCrop();
- renderSystem->CropRenderSize( 512, 256, true );
- renderSystem->CaptureRenderToImage( "_scratch" );
- renderSystem->UnCrop();
- renderSystem->CaptureRenderToImage( "_currentRender" );
- }
- /*
- ==================
- FullscreenFXManager::Blendback
- ==================
- */
- void FullscreenFXManager::Blendback( float alpha ) {
- // alpha fade
- }
- /*
- ==================
- FullscreenFXManager::Save
- ==================
- */
- void FullscreenFXManager::Save( idSaveGame *savefile ) {
- savefile->WriteBool( highQualityMode );
- savefile->WriteVec2( shiftScale );
- for ( int i = 0; i < fx.Num(); i++ ) {
- FullscreenFX *pfx = fx[i];
- pfx->Save( savefile );
- }
- }
- /*
- ==================
- FullscreenFXManager::Restore
- ==================
- */
- void FullscreenFXManager::Restore( idRestoreGame *savefile ) {
- savefile->ReadBool( highQualityMode );
- savefile->ReadVec2( shiftScale );
- for ( int i = 0; i < fx.Num(); i++ ) {
- FullscreenFX *pfx = fx[i];
- pfx->Restore( savefile );
- }
- }
- /*
- ==================
- FullscreenFXManager::CaptureCurrentRender
- ==================
- */
- void FullscreenFXManager::CaptureCurrentRender() {
- renderSystem->CaptureRenderToImage( "_currentRender" );
- }
- /*
- ==================
- FullscreenFXManager::Process
- ==================
- */
- void FullscreenFXManager::Process( const renderView_t *view ) {
- bool allpass = false;
- bool atLeastOneFX = false;
- if ( g_testFullscreenFX.GetInteger() == -2 ) {
- allpass = true;
- }
- if ( g_lowresFullscreenFX.GetBool() ) {
- highQualityMode = false;
- }
- else {
- highQualityMode = true;
- }
- // compute the shift scale
- if ( highQualityMode ) {
- int vidWidth, vidHeight;
- renderSystem->GetGLSettings( vidWidth, vidHeight );
- float pot;
- int w = vidWidth;
- pot = MakePowerOfTwo( w );
- shiftScale.x = (float)w / pot;
- int h = vidHeight;
- pot = MakePowerOfTwo( h );
- shiftScale.y = (float)h / pot;
- }
- else {
- // if we're in low-res mode, shrink view down
- shiftScale.x = 1;
- shiftScale.y = 1;
- renderSystem->CropRenderSize( 512, 512, true );
- }
- // do the first render
- gameRenderWorld->RenderScene( view );
- // do the process
- for ( int i = 0; i < fx.Num(); i++ ) {
- FullscreenFX *pfx = fx[i];
- bool drawIt = false;
- // determine if we need to draw
- if ( pfx->Active() || g_testFullscreenFX.GetInteger() == i || allpass ) {
- drawIt = pfx->SetTriggerState( true );
- }
- else {
- drawIt = pfx->SetTriggerState( false );
- }
- // do the actual drawing
- if ( drawIt ) {
- atLeastOneFX = true;
- // we need to dump to _currentRender
- CaptureCurrentRender();
- // handle the accum pass if we have one
- if ( pfx->HasAccum() ) {
- // if we're in high quality mode, we need to crop the accum pass
- if ( highQualityMode ) {
- renderSystem->CropRenderSize( 512, 512, true );
- pfx->AccumPass( view );
- renderSystem->UnCrop();
- }
- else {
- pfx->AccumPass( view );
- }
- }
- // do the high quality pass
- pfx->HighQuality();
- // do the blendback
- Blendback( pfx->GetFadeAlpha() );
- }
- }
- if ( !highQualityMode ) {
- // we need to dump to _currentRender
- CaptureCurrentRender();
- // uncrop view
- renderSystem->UnCrop();
- }
- }
- #endif
|