1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21 
22 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.
23 
24 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.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __GAME_PLAYERVIEW_H__
30 #define __GAME_PLAYERVIEW_H__
31 
32 #include "idlib/math/Vector.h"
33 #include "idlib/Dict.h"
34 #include "renderer/Material.h"
35 #include "renderer/RenderWorld.h"
36 
37 class idSaveGame;
38 class idRestoreGame;
39 
40 /*
41 ===============================================================================
42 
43   Player view.
44 
45 ===============================================================================
46 */
47 
48 // screenBlob_t are for the on-screen damage claw marks, etc
49 typedef struct {
50 	const idMaterial *	material;
51 	float				x, y, w, h;
52 	float				s1, t1, s2, t2;
53 	int					finishTime;
54 	int					startFadeTime;
55 	float				driftAmount;
56 } screenBlob_t;
57 
58 #define	MAX_SCREEN_BLOBS	8
59 
60 
61 
62 
63 
64 #ifdef _D3XP
65 class WarpPolygon_t {
66 public:
67 	idVec4					outer1;
68 	idVec4					outer2;
69 	idVec4					center;
70 };
71 
72 class Warp_t {
73 public:
74 	int						id;
75 	bool					active;
76 
77 	int						startTime;
78 	float					initialRadius;
79 
80 	idVec3					worldOrigin;
81 	idVec2					screenOrigin;
82 
83 	int						durationMsec;
84 
85 	idList<WarpPolygon_t>	polys;
86 };
87 #endif
88 
89 
90 
91 
92 
93 
94 
95 #ifdef _D3XP
96 
97 class idPlayerView;
98 class FullscreenFXManager;
99 
100 
101 /*
102 ==================
103 FxFader
104 ==================
105 */
106 class FxFader {
107 	enum {
108 		FX_STATE_OFF,
109 		FX_STATE_RAMPUP,
110 		FX_STATE_RAMPDOWN,
111 		FX_STATE_ON
112 	};
113 
114 	int						time;
115 	int						state;
116 	float					alpha;
117 	int						msec;
118 
119 public:
120 							FxFader();
121 
122 	// primary functions
123 	bool					SetTriggerState( bool active );
124 
125 	virtual void			Save( idSaveGame *savefile );
126 	virtual void			Restore( idRestoreGame *savefile );
127 
128 	// fader functions
SetFadeTime(int t)129 	void					SetFadeTime( int t )		{ msec = t; };
GetFadeTime()130 	int						GetFadeTime()				{ return msec; };
131 
132 	// misc functions
GetAlpha()133 	float					GetAlpha()					{ return alpha; };
134 };
135 
136 
137 /*
138 ==================
139 FullscreenFX
140 ==================
141 */
142 class FullscreenFX {
143 protected:
144 	idStr					name;
145 	FxFader					fader;
146 	FullscreenFXManager		*fxman;
147 
148 public:
FullscreenFX()149 							FullscreenFX()							{ fxman = NULL; };
~FullscreenFX()150 	virtual					~FullscreenFX()							{ };
151 
152 	virtual void			Initialize()							= 0;
153 	virtual bool			Active()								= 0;
154 	virtual void			HighQuality()							= 0;
LowQuality()155 	virtual void			LowQuality()							{ };
AccumPass(const renderView_t * view)156 	virtual void			AccumPass( const renderView_t *view )	{ };
HasAccum()157 	virtual bool			HasAccum()								{ return false; };
158 
SetName(idStr n)159 	void					SetName( idStr n )						{ name = n; };
GetName()160 	idStr					GetName()								{ return name; };
161 
SetFXManager(FullscreenFXManager * fx)162 	void					SetFXManager( FullscreenFXManager *fx )	{ fxman = fx; };
163 
SetTriggerState(bool state)164 	bool					SetTriggerState( bool state )			{ return fader.SetTriggerState( state ); };
SetFadeSpeed(int msec)165 	void					SetFadeSpeed( int msec )				{ fader.SetFadeTime( msec ); };
GetFadeAlpha()166 	float					GetFadeAlpha()							{ return fader.GetAlpha(); };
167 
168 	virtual void			Save( idSaveGame *savefile );
169 	virtual void			Restore( idRestoreGame *savefile );
170 };
171 
172 /*
173 ==================
174 FullscreenFX_Helltime
175 ==================
176 */
177 class FullscreenFX_Helltime : public FullscreenFX {
178 	const idMaterial*		acInitMaterials[3];
179 	const idMaterial*		acCaptureMaterials[3];
180 	const idMaterial*		acDrawMaterials[3];
181 	const idMaterial*		crCaptureMaterials[3];
182 	const idMaterial*		crDrawMaterials[3];
183 	bool					clearAccumBuffer;
184 
185 	int						DetermineLevel();
186 
187 public:
188 	virtual void			Initialize();
189 	virtual bool			Active();
190 	virtual void			HighQuality();
191 	virtual void			AccumPass( const renderView_t *view );
HasAccum()192 	virtual bool			HasAccum()		{ return true; };
193 
194 	virtual void			Restore( idRestoreGame *savefile );
195 };
196 
197 /*
198 ==================
199 FullscreenFX_Multiplayer
200 ==================
201 */
202 class FullscreenFX_Multiplayer : public FullscreenFX {
203 	const idMaterial*		acInitMaterials;
204 	const idMaterial*		acCaptureMaterials;
205 	const idMaterial*		acDrawMaterials;
206 	const idMaterial*		crCaptureMaterials;
207 	const idMaterial*		crDrawMaterials;
208 	bool					clearAccumBuffer;
209 
210 	int						DetermineLevel();
211 
212 public:
213 	virtual void			Initialize();
214 	virtual bool			Active();
215 	virtual void			HighQuality();
216 	virtual void			AccumPass( const renderView_t *view );
HasAccum()217 	virtual bool			HasAccum()		{ return true; };
218 
219 	virtual void			Restore( idRestoreGame *savefile );
220 };
221 
222 /*
223 ==================
224 FullscreenFX_Warp
225 ==================
226 */
227 class FullscreenFX_Warp : public FullscreenFX {
228 	const idMaterial*		material;
229 	bool					grabberEnabled;
230 	int						startWarpTime;
231 
232 	void					DrawWarp( WarpPolygon_t wp, float interp );
233 
234 public:
235 	virtual void			Initialize();
236 	virtual bool			Active();
237 	virtual void			HighQuality();
238 
EnableGrabber(bool active)239 	void					EnableGrabber( bool active )			{ grabberEnabled = active; startWarpTime = gameLocal.slow.time; };
240 
241 	virtual void			Save( idSaveGame *savefile );
242 	virtual void			Restore( idRestoreGame *savefile );
243 };
244 
245 /*
246 ==================
247 FullscreenFX_EnviroSuit
248 ==================
249 */
250 class FullscreenFX_EnviroSuit : public FullscreenFX {
251 	const idMaterial*		material;
252 
253 public:
254 	virtual void			Initialize();
255 	virtual bool			Active();
256 	virtual void			HighQuality();
257 };
258 
259 /*
260 ==================
261 FullscreenFX_DoubleVision
262 ==================
263 */
264 class FullscreenFX_DoubleVision : public FullscreenFX {
265 	const idMaterial*		material;
266 
267 public:
268 	virtual void			Initialize();
269 	virtual bool			Active();
270 	virtual void			HighQuality();
271 };
272 
273 /*
274 ==================
275 FullscreenFX_InfluenceVision
276 ==================
277 */
278 class FullscreenFX_InfluenceVision : public FullscreenFX {
279 
280 public:
281 	virtual void			Initialize();
282 	virtual bool			Active();
283 	virtual void			HighQuality();
284 };
285 
286 /*
287 ==================
288 FullscreenFX_Bloom
289 ==================
290 */
291 class FullscreenFX_Bloom : public FullscreenFX {
292 	const idMaterial*		drawMaterial;
293 	const idMaterial*		initMaterial;
294 	const idMaterial*		currentMaterial;
295 
296 	float					currentIntensity;
297 	float					targetIntensity;
298 
299 public:
300 	virtual void			Initialize();
301 	virtual bool			Active();
302 	virtual void			HighQuality();
303 
304 	virtual void			Save( idSaveGame *savefile );
305 	virtual void			Restore( idRestoreGame *savefile );
306 };
307 
308 
309 
310 /*
311 ==================
312 FullscreenFXManager
313 ==================
314 */
315 class FullscreenFXManager {
316 	idList<FullscreenFX*>	fx;
317 	bool					highQualityMode;
318 	idVec2					shiftScale;
319 
320 	idPlayerView			*playerView;
321 	const idMaterial*		blendBackMaterial;
322 
323 	void					CreateFX( idStr name, idStr fxtype, int fade );
324 
325 public:
326 							FullscreenFXManager();
327 	virtual					~FullscreenFXManager();
328 
329 	void					Initialize( idPlayerView *pv );
330 
331 	void					Process( const renderView_t *view );
332 	void					CaptureCurrentRender();
333 	void					Blendback( float alpha );
334 
GetShiftScale()335 	idVec2					GetShiftScale()			{ return shiftScale; };
GetPlayerView()336 	idPlayerView*			GetPlayerView()			{ return playerView; };
GetPlayer()337 	idPlayer*				GetPlayer()				{ return gameLocal.GetLocalPlayer(); };
338 
GetNum()339 	int						GetNum()				{ return fx.Num(); };
GetFX(int index)340 	FullscreenFX*			GetFX( int index )		{ return fx[index]; };
341 	FullscreenFX*			FindFX( idStr name );
342 
343 	void					Save( idSaveGame *savefile );
344 	void					Restore( idRestoreGame *savefile );
345 };
346 
347 #endif
348 
349 
350 
351 
352 
353 
354 
355 
356 
357 class idPlayerView {
358 public:
359 						idPlayerView();
360 
361 	void				Save( idSaveGame *savefile ) const;
362 	void				Restore( idRestoreGame *savefile );
363 
364 	void				SetPlayerEntity( class idPlayer *playerEnt );
365 
366 	void				ClearEffects( void );
367 
368 	void				DamageImpulse( idVec3 localKickDir, const idDict *damageDef );
369 
370 	void				WeaponFireFeedback( const idDict *weaponDef );
371 
372 	idAngles			AngleOffset( void ) const;			// returns the current kick angle
373 
374 	idMat3				ShakeAxis( void ) const;			// returns the current shake angle
375 
376 	void				CalculateShake( void );
377 
378 	// this may involve rendering to a texture and displaying
379 	// that with a warp model or in double vision mode
380 	void				RenderPlayerView( idUserInterface *hud );
381 
382 	void				Fade( idVec4 color, int time );
383 
384 	void				Flash( idVec4 color, int time );
385 
386 	void				AddBloodSpray( float duration );
387 
388 	// temp for view testing
EnableBFGVision(bool b)389 	void				EnableBFGVision( bool b ) { bfgVision = b; };
390 
391 private:
392 	void				SingleView( idUserInterface *hud, const renderView_t *view );
393 	void				ScreenFade();
394 
395 	screenBlob_t *		GetScreenBlob();
396 
397 	screenBlob_t		screenBlobs[MAX_SCREEN_BLOBS];
398 
399 public:
400 	int					dvFinishTime;		// double vision will be stopped at this time
401 	const idMaterial *	dvMaterial;			// material to take the double vision screen shot
402 
403 	int					kickFinishTime;		// view kick will be stopped at this time
404 	idAngles			kickAngles;
405 
406 	bool				bfgVision;			//
407 
408 	const idMaterial *	tunnelMaterial;		// health tunnel vision
409 	const idMaterial *	armorMaterial;		// armor damage view effect
410 	const idMaterial *	berserkMaterial;	// berserk effect
411 	const idMaterial *	irGogglesMaterial;	// ir effect
412 	const idMaterial *	bloodSprayMaterial; // blood spray
413 	const idMaterial *	bfgMaterial;		// when targeted with BFG
414 	const idMaterial *	lagoMaterial;		// lagometer drawing
415 	float				lastDamageTime;		// accentuate the tunnel effect for a while
416 
417 	idVec4				fadeColor;			// fade color
418 	idVec4				fadeToColor;		// color to fade to
419 	idVec4				fadeFromColor;		// color to fade from
420 	float				fadeRate;			// fade rate
421 	int					fadeTime;			// fade time
422 
423 	idAngles			shakeAng;			// from the sound sources
424 
425 	idPlayer *			player;
426 	renderView_t		view;
427 
428 #ifdef _D3XP
429 	FullscreenFXManager	*fxManager;
430 
431 public:
432 	int					AddWarp( idVec3 worldOrigin, float centerx, float centery, float initialRadius, float durationMsec );
433 	void				FreeWarp( int id );
434 #endif
435 };
436 
437 #endif /* !__GAME_PLAYERVIEW_H__ */
438