PlayerView.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition 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 BFG Edition 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. #ifndef __GAME_PLAYERVIEW_H__
  21. #define __GAME_PLAYERVIEW_H__
  22. class idMenuHandler_HUD;
  23. /*
  24. ===============================================================================
  25. Player view.
  26. ===============================================================================
  27. */
  28. // screenBlob_t are for the on-screen damage claw marks, etc
  29. typedef struct {
  30. const idMaterial * material;
  31. float x, y, w, h;
  32. float s1, t1, s2, t2;
  33. int finishTime;
  34. int startFadeTime;
  35. float driftAmount;
  36. } screenBlob_t;
  37. #define MAX_SCREEN_BLOBS 8
  38. class WarpPolygon_t {
  39. public:
  40. idVec4 outer1;
  41. idVec4 outer2;
  42. idVec4 center;
  43. };
  44. class Warp_t {
  45. public:
  46. int id;
  47. bool active;
  48. int startTime;
  49. float initialRadius;
  50. idVec3 worldOrigin;
  51. idVec2 screenOrigin;
  52. int durationMsec;
  53. idList<WarpPolygon_t, TAG_IDLIB_LIST_PLAYER> polys;
  54. };
  55. class idPlayerView;
  56. class FullscreenFXManager;
  57. /*
  58. ==================
  59. FxFader
  60. ==================
  61. */
  62. class FxFader {
  63. enum {
  64. FX_STATE_OFF,
  65. FX_STATE_RAMPUP,
  66. FX_STATE_RAMPDOWN,
  67. FX_STATE_ON
  68. };
  69. int time;
  70. int state;
  71. float alpha;
  72. int msec;
  73. public:
  74. FxFader();
  75. // primary functions
  76. bool SetTriggerState( bool active );
  77. virtual void Save( idSaveGame *savefile );
  78. virtual void Restore( idRestoreGame *savefile );
  79. // fader functions
  80. void SetFadeTime( int t ) { msec = t; };
  81. int GetFadeTime() { return msec; };
  82. // misc functions
  83. float GetAlpha() { return alpha; };
  84. };
  85. /*
  86. ==================
  87. FullscreenFX
  88. ==================
  89. */
  90. class FullscreenFX {
  91. protected:
  92. idStr name;
  93. FxFader fader;
  94. FullscreenFXManager *fxman;
  95. public:
  96. FullscreenFX() { fxman = NULL; };
  97. virtual ~FullscreenFX() { };
  98. virtual void Initialize() = 0;
  99. virtual bool Active() = 0;
  100. virtual void HighQuality() = 0;
  101. virtual void LowQuality() { };
  102. virtual void AccumPass( const renderView_t *view ) { };
  103. virtual bool HasAccum() { return false; };
  104. void SetName( idStr n ) { name = n; };
  105. idStr GetName() { return name; };
  106. void SetFXManager( FullscreenFXManager *fx ) { fxman = fx; };
  107. bool SetTriggerState( bool state ) { return fader.SetTriggerState( state ); };
  108. void SetFadeSpeed( int msec ) { fader.SetFadeTime( msec ); };
  109. float GetFadeAlpha() { return fader.GetAlpha(); };
  110. virtual void Save( idSaveGame *savefile );
  111. virtual void Restore( idRestoreGame *savefile );
  112. };
  113. /*
  114. ==================
  115. FullscreenFX_Helltime
  116. ==================
  117. */
  118. class FullscreenFX_Helltime : public FullscreenFX {
  119. const idMaterial * initMaterial;
  120. const idMaterial * captureMaterials[3];
  121. const idMaterial * drawMaterial;
  122. bool clearAccumBuffer;
  123. int DetermineLevel();
  124. public:
  125. virtual void Initialize();
  126. virtual bool Active();
  127. virtual void HighQuality();
  128. virtual void AccumPass( const renderView_t *view );
  129. virtual bool HasAccum() { return true; };
  130. virtual void Restore( idRestoreGame *savefile );
  131. };
  132. /*
  133. ==================
  134. FullscreenFX_Multiplayer
  135. ==================
  136. */
  137. class FullscreenFX_Multiplayer : public FullscreenFX {
  138. const idMaterial * initMaterial;
  139. const idMaterial * captureMaterial;
  140. const idMaterial * drawMaterial;
  141. bool clearAccumBuffer;
  142. int DetermineLevel();
  143. public:
  144. virtual void Initialize();
  145. virtual bool Active();
  146. virtual void HighQuality();
  147. virtual void AccumPass( const renderView_t *view );
  148. virtual bool HasAccum() { return true; };
  149. virtual void Restore( idRestoreGame *savefile );
  150. };
  151. /*
  152. ==================
  153. FullscreenFX_Warp
  154. ==================
  155. */
  156. class FullscreenFX_Warp : public FullscreenFX {
  157. const idMaterial* material;
  158. bool grabberEnabled;
  159. int startWarpTime;
  160. void DrawWarp( WarpPolygon_t wp, float interp );
  161. public:
  162. virtual void Initialize();
  163. virtual bool Active();
  164. virtual void HighQuality();
  165. void EnableGrabber( bool active ) { grabberEnabled = active; startWarpTime = gameLocal.slow.time; };
  166. virtual void Save( idSaveGame *savefile );
  167. virtual void Restore( idRestoreGame *savefile );
  168. };
  169. /*
  170. ==================
  171. FullscreenFX_EnviroSuit
  172. ==================
  173. */
  174. class FullscreenFX_EnviroSuit : public FullscreenFX {
  175. const idMaterial* material;
  176. public:
  177. virtual void Initialize();
  178. virtual bool Active();
  179. virtual void HighQuality();
  180. };
  181. /*
  182. ==================
  183. FullscreenFX_DoubleVision
  184. ==================
  185. */
  186. class FullscreenFX_DoubleVision : public FullscreenFX {
  187. const idMaterial* material;
  188. public:
  189. virtual void Initialize();
  190. virtual bool Active();
  191. virtual void HighQuality();
  192. };
  193. /*
  194. ==================
  195. FullscreenFX_InfluenceVision
  196. ==================
  197. */
  198. class FullscreenFX_InfluenceVision : public FullscreenFX {
  199. public:
  200. virtual void Initialize();
  201. virtual bool Active();
  202. virtual void HighQuality();
  203. };
  204. /*
  205. ==================
  206. FullscreenFX_Bloom
  207. ==================
  208. */
  209. class FullscreenFX_Bloom : public FullscreenFX {
  210. const idMaterial* drawMaterial;
  211. const idMaterial* initMaterial;
  212. float currentIntensity;
  213. float targetIntensity;
  214. public:
  215. virtual void Initialize();
  216. virtual bool Active();
  217. virtual void HighQuality();
  218. virtual void Save( idSaveGame *savefile );
  219. virtual void Restore( idRestoreGame *savefile );
  220. };
  221. /*
  222. ==================
  223. FullscreenFXManager
  224. ==================
  225. */
  226. class FullscreenFXManager {
  227. idList<FullscreenFX*, TAG_FX> fx;
  228. idPlayerView * playerView;
  229. const idMaterial* blendBackMaterial;
  230. void CreateFX( idStr name, idStr fxtype, int fade );
  231. public:
  232. FullscreenFXManager();
  233. virtual ~FullscreenFXManager();
  234. void Initialize( idPlayerView *pv );
  235. void Process( const renderView_t *view );
  236. void Blendback( float alpha );
  237. idPlayerView* GetPlayerView() { return playerView; };
  238. idPlayer* GetPlayer() { return gameLocal.GetLocalPlayer(); };
  239. int GetNum() { return fx.Num(); };
  240. FullscreenFX* GetFX( int index ) { return fx[index]; };
  241. FullscreenFX* FindFX( idStr name );
  242. void Save( idSaveGame *savefile );
  243. void Restore( idRestoreGame *savefile );
  244. };
  245. class idPlayerView {
  246. public:
  247. idPlayerView();
  248. ~idPlayerView();
  249. void Save( idSaveGame *savefile ) const;
  250. void Restore( idRestoreGame *savefile );
  251. void SetPlayerEntity( class idPlayer *playerEnt );
  252. void ClearEffects();
  253. void DamageImpulse( idVec3 localKickDir, const idDict *damageDef );
  254. void WeaponFireFeedback( const idDict *weaponDef );
  255. idAngles AngleOffset() const; // returns the current kick angle
  256. idMat3 ShakeAxis() const; // returns the current shake angle
  257. void CalculateShake();
  258. // this may involve rendering to a texture and displaying
  259. // that with a warp model or in double vision mode
  260. void RenderPlayerView( idMenuHandler_HUD * hudManager );
  261. void EmitStereoEyeView( const int eye, idMenuHandler_HUD * hudManager );
  262. void Fade( idVec4 color, int time );
  263. void Flash( idVec4 color, int time );
  264. // temp for view testing
  265. void EnableBFGVision( bool b ) { bfgVision = b; };
  266. private:
  267. void SingleView( const renderView_t *view, idMenuHandler_HUD * hudManager );
  268. void ScreenFade();
  269. screenBlob_t * GetScreenBlob();
  270. screenBlob_t screenBlobs[MAX_SCREEN_BLOBS];
  271. public:
  272. int dvFinishTime; // double vision will be stopped at this time
  273. int kickFinishTime; // view kick will be stopped at this time
  274. idAngles kickAngles;
  275. bool bfgVision; //
  276. const idMaterial * tunnelMaterial; // health tunnel vision
  277. const idMaterial * armorMaterial; // armor damage view effect
  278. const idMaterial * berserkMaterial; // berserk effect
  279. const idMaterial * irGogglesMaterial; // ir effect
  280. const idMaterial * bloodSprayMaterial; // blood spray
  281. const idMaterial * bfgMaterial; // when targeted with BFG
  282. float lastDamageTime; // accentuate the tunnel effect for a while
  283. idVec4 fadeColor; // fade color
  284. idVec4 fadeToColor; // color to fade to
  285. idVec4 fadeFromColor; // color to fade from
  286. float fadeRate; // fade rate
  287. int fadeTime; // fade time
  288. idAngles shakeAng; // from the sound sources
  289. idPlayer * player;
  290. renderView_t view;
  291. FullscreenFXManager *fxManager;
  292. public:
  293. int AddWarp( idVec3 worldOrigin, float centerx, float centery, float initialRadius, float durationMsec );
  294. void FreeWarp( int id );
  295. };
  296. // the crosshair is swapped for a laser sight in stereo rendering
  297. bool IsGameStereoRendered();
  298. #endif /* !__GAME_PLAYERVIEW_H__ */