PlayerView.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. #include "../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "Game_local.h"
  23. const int IMPULSE_DELAY = 150;
  24. /*
  25. ==============
  26. idPlayerView::idPlayerView
  27. ==============
  28. */
  29. idPlayerView::idPlayerView() {
  30. memset( screenBlobs, 0, sizeof( screenBlobs ) );
  31. memset( &view, 0, sizeof( view ) );
  32. player = NULL;
  33. dvMaterial = declManager->FindMaterial( "_scratch" );
  34. tunnelMaterial = declManager->FindMaterial( "textures/decals/tunnel" );
  35. armorMaterial = declManager->FindMaterial( "armorViewEffect" );
  36. berserkMaterial = declManager->FindMaterial( "textures/decals/berserk" );
  37. irGogglesMaterial = declManager->FindMaterial( "textures/decals/irblend" );
  38. bloodSprayMaterial = declManager->FindMaterial( "textures/decals/bloodspray" );
  39. bfgMaterial = declManager->FindMaterial( "textures/decals/bfgvision" );
  40. lagoMaterial = declManager->FindMaterial( LAGO_MATERIAL, false );
  41. bfgVision = false;
  42. dvFinishTime = 0;
  43. kickFinishTime = 0;
  44. kickAngles.Zero();
  45. lastDamageTime = 0.0f;
  46. fadeTime = 0;
  47. fadeRate = 0.0;
  48. fadeFromColor.Zero();
  49. fadeToColor.Zero();
  50. fadeColor.Zero();
  51. shakeAng.Zero();
  52. ClearEffects();
  53. }
  54. /*
  55. ==============
  56. idPlayerView::Save
  57. ==============
  58. */
  59. void idPlayerView::Save( idSaveGame *savefile ) const {
  60. int i;
  61. const screenBlob_t *blob;
  62. blob = &screenBlobs[ 0 ];
  63. for( i = 0; i < MAX_SCREEN_BLOBS; i++, blob++ ) {
  64. savefile->WriteMaterial( blob->material );
  65. savefile->WriteFloat( blob->x );
  66. savefile->WriteFloat( blob->y );
  67. savefile->WriteFloat( blob->w );
  68. savefile->WriteFloat( blob->h );
  69. savefile->WriteFloat( blob->s1 );
  70. savefile->WriteFloat( blob->t1 );
  71. savefile->WriteFloat( blob->s2 );
  72. savefile->WriteFloat( blob->t2 );
  73. savefile->WriteInt( blob->finishTime );
  74. savefile->WriteInt( blob->startFadeTime );
  75. savefile->WriteFloat( blob->driftAmount );
  76. }
  77. savefile->WriteInt( dvFinishTime );
  78. savefile->WriteMaterial( dvMaterial );
  79. savefile->WriteInt( kickFinishTime );
  80. savefile->WriteAngles( kickAngles );
  81. savefile->WriteBool( bfgVision );
  82. savefile->WriteMaterial( tunnelMaterial );
  83. savefile->WriteMaterial( armorMaterial );
  84. savefile->WriteMaterial( berserkMaterial );
  85. savefile->WriteMaterial( irGogglesMaterial );
  86. savefile->WriteMaterial( bloodSprayMaterial );
  87. savefile->WriteMaterial( bfgMaterial );
  88. savefile->WriteFloat( lastDamageTime );
  89. savefile->WriteVec4( fadeColor );
  90. savefile->WriteVec4( fadeToColor );
  91. savefile->WriteVec4( fadeFromColor );
  92. savefile->WriteFloat( fadeRate );
  93. savefile->WriteInt( fadeTime );
  94. savefile->WriteAngles( shakeAng );
  95. savefile->WriteObject( player );
  96. savefile->WriteRenderView( view );
  97. }
  98. /*
  99. ==============
  100. idPlayerView::Restore
  101. ==============
  102. */
  103. void idPlayerView::Restore( idRestoreGame *savefile ) {
  104. int i;
  105. screenBlob_t *blob;
  106. blob = &screenBlobs[ 0 ];
  107. for( i = 0; i < MAX_SCREEN_BLOBS; i++, blob++ ) {
  108. savefile->ReadMaterial( blob->material );
  109. savefile->ReadFloat( blob->x );
  110. savefile->ReadFloat( blob->y );
  111. savefile->ReadFloat( blob->w );
  112. savefile->ReadFloat( blob->h );
  113. savefile->ReadFloat( blob->s1 );
  114. savefile->ReadFloat( blob->t1 );
  115. savefile->ReadFloat( blob->s2 );
  116. savefile->ReadFloat( blob->t2 );
  117. savefile->ReadInt( blob->finishTime );
  118. savefile->ReadInt( blob->startFadeTime );
  119. savefile->ReadFloat( blob->driftAmount );
  120. }
  121. savefile->ReadInt( dvFinishTime );
  122. savefile->ReadMaterial( dvMaterial );
  123. savefile->ReadInt( kickFinishTime );
  124. savefile->ReadAngles( kickAngles );
  125. savefile->ReadBool( bfgVision );
  126. savefile->ReadMaterial( tunnelMaterial );
  127. savefile->ReadMaterial( armorMaterial );
  128. savefile->ReadMaterial( berserkMaterial );
  129. savefile->ReadMaterial( irGogglesMaterial );
  130. savefile->ReadMaterial( bloodSprayMaterial );
  131. savefile->ReadMaterial( bfgMaterial );
  132. savefile->ReadFloat( lastDamageTime );
  133. savefile->ReadVec4( fadeColor );
  134. savefile->ReadVec4( fadeToColor );
  135. savefile->ReadVec4( fadeFromColor );
  136. savefile->ReadFloat( fadeRate );
  137. savefile->ReadInt( fadeTime );
  138. savefile->ReadAngles( shakeAng );
  139. savefile->ReadObject( reinterpret_cast<idClass *&>( player ) );
  140. savefile->ReadRenderView( view );
  141. }
  142. /*
  143. ==============
  144. idPlayerView::SetPlayerEntity
  145. ==============
  146. */
  147. void idPlayerView::SetPlayerEntity( idPlayer *playerEnt ) {
  148. player = playerEnt;
  149. }
  150. /*
  151. ==============
  152. idPlayerView::ClearEffects
  153. ==============
  154. */
  155. void idPlayerView::ClearEffects() {
  156. lastDamageTime = MS2SEC( gameLocal.time - 99999 );
  157. dvFinishTime = ( gameLocal.time - 99999 );
  158. kickFinishTime = ( gameLocal.time - 99999 );
  159. for ( int i = 0 ; i < MAX_SCREEN_BLOBS ; i++ ) {
  160. screenBlobs[i].finishTime = gameLocal.time;
  161. }
  162. fadeTime = 0;
  163. bfgVision = false;
  164. }
  165. /*
  166. ==============
  167. idPlayerView::GetScreenBlob
  168. ==============
  169. */
  170. screenBlob_t *idPlayerView::GetScreenBlob() {
  171. screenBlob_t *oldest = &screenBlobs[0];
  172. for ( int i = 1 ; i < MAX_SCREEN_BLOBS ; i++ ) {
  173. if ( screenBlobs[i].finishTime < oldest->finishTime ) {
  174. oldest = &screenBlobs[i];
  175. }
  176. }
  177. return oldest;
  178. }
  179. /*
  180. ==============
  181. idPlayerView::DamageImpulse
  182. LocalKickDir is the direction of force in the player's coordinate system,
  183. which will determine the head kick direction
  184. ==============
  185. */
  186. void idPlayerView::DamageImpulse( idVec3 localKickDir, const idDict *damageDef ) {
  187. //
  188. // double vision effect
  189. //
  190. if ( lastDamageTime > 0.0f && SEC2MS( lastDamageTime ) + IMPULSE_DELAY > gameLocal.time ) {
  191. // keep shotgun from obliterating the view
  192. return;
  193. }
  194. float dvTime = damageDef->GetFloat( "dv_time" );
  195. if ( dvTime ) {
  196. if ( dvFinishTime < gameLocal.time ) {
  197. dvFinishTime = gameLocal.time;
  198. }
  199. dvFinishTime += g_dvTime.GetFloat() * dvTime;
  200. // don't let it add up too much in god mode
  201. if ( dvFinishTime > gameLocal.time + 5000 ) {
  202. dvFinishTime = gameLocal.time + 5000;
  203. }
  204. }
  205. //
  206. // head angle kick
  207. //
  208. float kickTime = damageDef->GetFloat( "kick_time" );
  209. if ( kickTime ) {
  210. kickFinishTime = gameLocal.time + g_kickTime.GetFloat() * kickTime;
  211. // forward / back kick will pitch view
  212. kickAngles[0] = localKickDir[0];
  213. // side kick will yaw view
  214. kickAngles[1] = localKickDir[1]*0.5f;
  215. // up / down kick will pitch view
  216. kickAngles[0] += localKickDir[2];
  217. // roll will come from side
  218. kickAngles[2] = localKickDir[1];
  219. float kickAmplitude = damageDef->GetFloat( "kick_amplitude" );
  220. if ( kickAmplitude ) {
  221. kickAngles *= kickAmplitude;
  222. }
  223. }
  224. //
  225. // screen blob
  226. //
  227. float blobTime = damageDef->GetFloat( "blob_time" );
  228. if ( blobTime ) {
  229. screenBlob_t *blob = GetScreenBlob();
  230. blob->startFadeTime = gameLocal.time;
  231. blob->finishTime = gameLocal.time + blobTime * g_blobTime.GetFloat();
  232. const char *materialName = damageDef->GetString( "mtr_blob" );
  233. blob->material = declManager->FindMaterial( materialName );
  234. blob->x = damageDef->GetFloat( "blob_x" );
  235. blob->x += ( gameLocal.random.RandomInt()&63 ) - 32;
  236. blob->y = damageDef->GetFloat( "blob_y" );
  237. blob->y += ( gameLocal.random.RandomInt()&63 ) - 32;
  238. float scale = ( 256 + ( ( gameLocal.random.RandomInt()&63 ) - 32 ) ) / 256.0f;
  239. blob->w = damageDef->GetFloat( "blob_width" ) * g_blobSize.GetFloat() * scale;
  240. blob->h = damageDef->GetFloat( "blob_height" ) * g_blobSize.GetFloat() * scale;
  241. blob->s1 = 0;
  242. blob->t1 = 0;
  243. blob->s2 = 1;
  244. blob->t2 = 1;
  245. }
  246. //
  247. // save lastDamageTime for tunnel vision accentuation
  248. //
  249. lastDamageTime = MS2SEC( gameLocal.time );
  250. }
  251. /*
  252. ==================
  253. idPlayerView::AddBloodSpray
  254. If we need a more generic way to add blobs then we can do that
  255. but having it localized here lets the material be pre-looked up etc.
  256. ==================
  257. */
  258. void idPlayerView::AddBloodSpray( float duration ) {
  259. /*
  260. if ( duration <= 0 || bloodSprayMaterial == NULL || g_skipViewEffects.GetBool() ) {
  261. return;
  262. }
  263. // visit this for chainsaw
  264. screenBlob_t *blob = GetScreenBlob();
  265. blob->startFadeTime = gameLocal.time;
  266. blob->finishTime = gameLocal.time + ( duration * 1000 );
  267. blob->material = bloodSprayMaterial;
  268. blob->x = ( gameLocal.random.RandomInt() & 63 ) - 32;
  269. blob->y = ( gameLocal.random.RandomInt() & 63 ) - 32;
  270. blob->driftAmount = 0.5f + gameLocal.random.CRandomFloat() * 0.5;
  271. float scale = ( 256 + ( ( gameLocal.random.RandomInt()&63 ) - 32 ) ) / 256.0f;
  272. blob->w = 600 * g_blobSize.GetFloat() * scale;
  273. blob->h = 480 * g_blobSize.GetFloat() * scale;
  274. float s1 = 0.0f;
  275. float t1 = 0.0f;
  276. float s2 = 1.0f;
  277. float t2 = 1.0f;
  278. if ( blob->driftAmount < 0.6 ) {
  279. s1 = 1.0f;
  280. s2 = 0.0f;
  281. } else if ( blob->driftAmount < 0.75 ) {
  282. t1 = 1.0f;
  283. t2 = 0.0f;
  284. } else if ( blob->driftAmount < 0.85 ) {
  285. s1 = 1.0f;
  286. s2 = 0.0f;
  287. t1 = 1.0f;
  288. t2 = 0.0f;
  289. }
  290. blob->s1 = s1;
  291. blob->t1 = t1;
  292. blob->s2 = s2;
  293. blob->t2 = t2;
  294. */
  295. }
  296. /*
  297. ==================
  298. idPlayerView::WeaponFireFeedback
  299. Called when a weapon fires, generates head twitches, etc
  300. ==================
  301. */
  302. void idPlayerView::WeaponFireFeedback( const idDict *weaponDef ) {
  303. int recoilTime;
  304. recoilTime = weaponDef->GetInt( "recoilTime" );
  305. // don't shorten a damage kick in progress
  306. if ( recoilTime && kickFinishTime < gameLocal.time ) {
  307. idAngles angles;
  308. weaponDef->GetAngles( "recoilAngles", "5 0 0", angles );
  309. kickAngles = angles;
  310. int finish = gameLocal.time + g_kickTime.GetFloat() * recoilTime;
  311. kickFinishTime = finish;
  312. }
  313. }
  314. /*
  315. ===================
  316. idPlayerView::CalculateShake
  317. ===================
  318. */
  319. void idPlayerView::CalculateShake() {
  320. idVec3 origin, matrix;
  321. float shakeVolume = gameSoundWorld->CurrentShakeAmplitudeForPosition( gameLocal.time, player->firstPersonViewOrigin );
  322. //
  323. // shakeVolume should somehow be molded into an angle here
  324. // it should be thought of as being in the range 0.0 -> 1.0, although
  325. // since CurrentShakeAmplitudeForPosition() returns all the shake sounds
  326. // the player can hear, it can go over 1.0 too.
  327. //
  328. shakeAng[0] = gameLocal.random.CRandomFloat() * shakeVolume;
  329. shakeAng[1] = gameLocal.random.CRandomFloat() * shakeVolume;
  330. shakeAng[2] = gameLocal.random.CRandomFloat() * shakeVolume;
  331. }
  332. /*
  333. ===================
  334. idPlayerView::ShakeAxis
  335. ===================
  336. */
  337. idMat3 idPlayerView::ShakeAxis() const {
  338. return shakeAng.ToMat3();
  339. }
  340. /*
  341. ===================
  342. idPlayerView::AngleOffset
  343. kickVector, a world space direction that the attack should
  344. ===================
  345. */
  346. idAngles idPlayerView::AngleOffset() const {
  347. idAngles ang;
  348. ang.Zero();
  349. if ( gameLocal.time < kickFinishTime ) {
  350. float offset = kickFinishTime - gameLocal.time;
  351. ang = kickAngles * offset * offset * g_kickAmplitude.GetFloat();
  352. for ( int i = 0 ; i < 3 ; i++ ) {
  353. if ( ang[i] > 70.0f ) {
  354. ang[i] = 70.0f;
  355. } else if ( ang[i] < -70.0f ) {
  356. ang[i] = -70.0f;
  357. }
  358. }
  359. }
  360. return ang;
  361. }
  362. /*
  363. ==================
  364. idPlayerView::SingleView
  365. ==================
  366. */
  367. void idPlayerView::SingleView( idUserInterface *hud, const renderView_t *view ) {
  368. // normal rendering
  369. if ( !view ) {
  370. return;
  371. }
  372. // place the sound origin for the player
  373. gameSoundWorld->PlaceListener( view->vieworg, view->viewaxis, player->entityNumber + 1, gameLocal.time, hud ? hud->State().GetString( "location" ) : "Undefined" );
  374. // if the objective system is up, don't do normal drawing
  375. if ( player->objectiveSystemOpen ) {
  376. player->objectiveSystem->Redraw( gameLocal.time );
  377. return;
  378. }
  379. // hack the shake in at the very last moment, so it can't cause any consistency problems
  380. renderView_t hackedView = *view;
  381. hackedView.viewaxis = hackedView.viewaxis * ShakeAxis();
  382. gameRenderWorld->RenderScene( &hackedView );
  383. if ( player->spectating ) {
  384. return;
  385. }
  386. // draw screen blobs
  387. if ( !pm_thirdPerson.GetBool() && !g_skipViewEffects.GetBool() ) {
  388. for ( int i = 0 ; i < MAX_SCREEN_BLOBS ; i++ ) {
  389. screenBlob_t *blob = &screenBlobs[i];
  390. if ( blob->finishTime <= gameLocal.time ) {
  391. continue;
  392. }
  393. blob->y += blob->driftAmount;
  394. float fade = (float)( blob->finishTime - gameLocal.time ) / ( blob->finishTime - blob->startFadeTime );
  395. if ( fade > 1.0f ) {
  396. fade = 1.0f;
  397. }
  398. if ( fade ) {
  399. renderSystem->SetColor4( 1,1,1,fade );
  400. renderSystem->DrawStretchPic( blob->x, blob->y, blob->w, blob->h,blob->s1, blob->t1, blob->s2, blob->t2, blob->material );
  401. }
  402. }
  403. player->DrawHUD( hud );
  404. // armor impulse feedback
  405. float armorPulse = ( gameLocal.time - player->lastArmorPulse ) / 250.0f;
  406. if ( armorPulse > 0.0f && armorPulse < 1.0f ) {
  407. renderSystem->SetColor4( 1, 1, 1, 1.0 - armorPulse );
  408. renderSystem->DrawStretchPic( 0, 0, 640, 480, 0, 0, 1, 1, armorMaterial );
  409. }
  410. // tunnel vision
  411. float health = 0.0f;
  412. if ( g_testHealthVision.GetFloat() != 0.0f ) {
  413. health = g_testHealthVision.GetFloat();
  414. } else {
  415. health = player->health;
  416. }
  417. float alpha = health / 100.0f;
  418. if ( alpha < 0.0f ) {
  419. alpha = 0.0f;
  420. }
  421. if ( alpha > 1.0f ) {
  422. alpha = 1.0f;
  423. }
  424. if ( alpha < 1.0f ) {
  425. renderSystem->SetColor4( ( player->health <= 0.0f ) ? MS2SEC( gameLocal.time ) : lastDamageTime, 1.0f, 1.0f, ( player->health <= 0.0f ) ? 0.0f : alpha );
  426. renderSystem->DrawStretchPic( 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 1.0f, 1.0f, tunnelMaterial );
  427. }
  428. if ( player->PowerUpActive(BERSERK) ) {
  429. int berserkTime = player->inventory.powerupEndTime[ BERSERK ] - gameLocal.time;
  430. if ( berserkTime > 0 ) {
  431. // start fading if within 10 seconds of going away
  432. alpha = (berserkTime < 10000) ? (float)berserkTime / 10000 : 1.0f;
  433. renderSystem->SetColor4( 1.0f, 1.0f, 1.0f, alpha );
  434. renderSystem->DrawStretchPic( 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 1.0f, 1.0f, berserkMaterial );
  435. }
  436. }
  437. if ( bfgVision ) {
  438. renderSystem->SetColor4( 1.0f, 1.0f, 1.0f, 1.0f );
  439. renderSystem->DrawStretchPic( 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 1.0f, 1.0f, bfgMaterial );
  440. }
  441. }
  442. // test a single material drawn over everything
  443. if ( g_testPostProcess.GetString()[0] ) {
  444. const idMaterial *mtr = declManager->FindMaterial( g_testPostProcess.GetString(), false );
  445. if ( !mtr ) {
  446. common->Printf( "Material not found.\n" );
  447. g_testPostProcess.SetString( "" );
  448. } else {
  449. renderSystem->SetColor4( 1.0f, 1.0f, 1.0f, 1.0f );
  450. renderSystem->DrawStretchPic( 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 1.0f, 1.0f, mtr );
  451. }
  452. }
  453. }
  454. /*
  455. ===================
  456. idPlayerView::DoubleVision
  457. ===================
  458. */
  459. void idPlayerView::DoubleVision( idUserInterface *hud, const renderView_t *view, int offset ) {
  460. if ( !g_doubleVision.GetBool() ) {
  461. SingleView( hud, view );
  462. return;
  463. }
  464. float scale = offset * g_dvAmplitude.GetFloat();
  465. if ( scale > 0.5f ) {
  466. scale = 0.5f;
  467. }
  468. float shift = scale * sin( sqrtf( offset ) * g_dvFrequency.GetFloat() );
  469. shift = fabs( shift );
  470. // if double vision, render to a texture
  471. renderSystem->CropRenderSize( 512, 256, true );
  472. SingleView( hud, view );
  473. renderSystem->CaptureRenderToImage( "_scratch" );
  474. renderSystem->UnCrop();
  475. // carry red tint if in berserk mode
  476. idVec4 color(1, 1, 1, 1);
  477. if ( gameLocal.time < player->inventory.powerupEndTime[ BERSERK ] ) {
  478. color.y = 0;
  479. color.z = 0;
  480. }
  481. renderSystem->SetColor4( color.x, color.y, color.z, 1.0f );
  482. renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, shift, 1, 1, 0, dvMaterial );
  483. renderSystem->SetColor4( color.x, color.y, color.z, 0.5f );
  484. renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1, 1-shift, 0, dvMaterial );
  485. }
  486. /*
  487. ===================
  488. idPlayerView::BerserkVision
  489. ===================
  490. */
  491. void idPlayerView::BerserkVision( idUserInterface *hud, const renderView_t *view ) {
  492. renderSystem->CropRenderSize( 512, 256, true );
  493. SingleView( hud, view );
  494. renderSystem->CaptureRenderToImage( "_scratch" );
  495. renderSystem->UnCrop();
  496. renderSystem->SetColor4( 1.0f, 1.0f, 1.0f, 1.0f );
  497. renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1, 1, 0, dvMaterial );
  498. }
  499. /*
  500. =================
  501. idPlayerView::Flash
  502. flashes the player view with the given color
  503. =================
  504. */
  505. void idPlayerView::Flash(idVec4 color, int time ) {
  506. Fade(idVec4(0, 0, 0, 0), time);
  507. fadeFromColor = colorWhite;
  508. }
  509. /*
  510. =================
  511. idPlayerView::Fade
  512. used for level transition fades
  513. assumes: color.w is 0 or 1
  514. =================
  515. */
  516. void idPlayerView::Fade( idVec4 color, int time ) {
  517. if ( !fadeTime ) {
  518. fadeFromColor.Set( 0.0f, 0.0f, 0.0f, 1.0f - color[ 3 ] );
  519. } else {
  520. fadeFromColor = fadeColor;
  521. }
  522. fadeToColor = color;
  523. if ( time <= 0 ) {
  524. fadeRate = 0;
  525. time = 0;
  526. fadeColor = fadeToColor;
  527. } else {
  528. fadeRate = 1.0f / ( float )time;
  529. }
  530. if ( gameLocal.realClientTime == 0 && time == 0 ) {
  531. fadeTime = 1;
  532. } else {
  533. fadeTime = gameLocal.realClientTime + time;
  534. }
  535. }
  536. /*
  537. =================
  538. idPlayerView::ScreenFade
  539. =================
  540. */
  541. void idPlayerView::ScreenFade() {
  542. int msec;
  543. float t;
  544. if ( !fadeTime ) {
  545. return;
  546. }
  547. msec = fadeTime - gameLocal.realClientTime;
  548. if ( msec <= 0 ) {
  549. fadeColor = fadeToColor;
  550. if ( fadeColor[ 3 ] == 0.0f ) {
  551. fadeTime = 0;
  552. }
  553. } else {
  554. t = ( float )msec * fadeRate;
  555. fadeColor = fadeFromColor * t + fadeToColor * ( 1.0f - t );
  556. }
  557. if ( fadeColor[ 3 ] != 0.0f ) {
  558. renderSystem->SetColor4( fadeColor[ 0 ], fadeColor[ 1 ], fadeColor[ 2 ], fadeColor[ 3 ] );
  559. renderSystem->DrawStretchPic( 0, 0, 640, 480, 0, 0, 1, 1, declManager->FindMaterial( "_white" ) );
  560. }
  561. }
  562. /*
  563. ===================
  564. idPlayerView::InfluenceVision
  565. ===================
  566. */
  567. void idPlayerView::InfluenceVision( idUserInterface *hud, const renderView_t *view ) {
  568. float distance = 0.0f;
  569. float pct = 1.0f;
  570. if ( player->GetInfluenceEntity() ) {
  571. distance = ( player->GetInfluenceEntity()->GetPhysics()->GetOrigin() - player->GetPhysics()->GetOrigin() ).Length();
  572. if ( player->GetInfluenceRadius() != 0.0f && distance < player->GetInfluenceRadius() ) {
  573. pct = distance / player->GetInfluenceRadius();
  574. pct = 1.0f - idMath::ClampFloat( 0.0f, 1.0f, pct );
  575. }
  576. }
  577. if ( player->GetInfluenceMaterial() ) {
  578. SingleView( hud, view );
  579. renderSystem->CaptureRenderToImage( "_currentRender" );
  580. renderSystem->SetColor4( 1.0f, 1.0f, 1.0f, pct );
  581. renderSystem->DrawStretchPic( 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 1.0f, 1.0f, player->GetInfluenceMaterial() );
  582. } else if ( player->GetInfluenceEntity() == NULL ) {
  583. SingleView( hud, view );
  584. return;
  585. } else {
  586. int offset = 25 + sinf( gameLocal.time );
  587. DoubleVision( hud, view, pct * offset );
  588. }
  589. }
  590. /*
  591. ===================
  592. idPlayerView::RenderPlayerView
  593. ===================
  594. */
  595. void idPlayerView::RenderPlayerView( idUserInterface *hud ) {
  596. const renderView_t *view = player->GetRenderView();
  597. if ( g_skipViewEffects.GetBool() ) {
  598. SingleView( hud, view );
  599. } else {
  600. if ( player->GetInfluenceMaterial() || player->GetInfluenceEntity() ) {
  601. InfluenceVision( hud, view );
  602. } else if ( gameLocal.time < dvFinishTime ) {
  603. DoubleVision( hud, view, dvFinishTime - gameLocal.time );
  604. } else if ( player->PowerUpActive( BERSERK ) ) {
  605. BerserkVision( hud, view );
  606. } else {
  607. SingleView( hud, view );
  608. }
  609. ScreenFade();
  610. }
  611. if ( net_clientLagOMeter.GetBool() && lagoMaterial && gameLocal.isClient ) {
  612. renderSystem->SetColor4( 1.0f, 1.0f, 1.0f, 1.0f );
  613. renderSystem->DrawStretchPic( 10.0f, 380.0f, 64.0f, 64.0f, 0.0f, 0.0f, 1.0f, 1.0f, lagoMaterial );
  614. }
  615. }