Debian Codegraph @

code/cgame/cg_view.c

raw
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 //
23 // cg_view.c -- setup all the parameters (position, angle, etc)
24 // for a 3D rendering
25 #include "cg_local.h"
26
27
28 /*
29 =============================================================================
30
31 MODEL TESTING
32
33 The viewthing and gun positioning tools from Q2 have been integrated and
34 enhanced into a single model testing facility.
35
36 Model viewing can begin with either "testmodel <modelname>" or "testgun <modelname>".
37
38 The names must be the full pathname after the basedir, like
39 "models/weapons/v_launch/tris.md3" or "players/male/tris.md3"
40
41 Testmodel will create a fake entity 100 units in front of the current view
42 position, directly facing the viewer. It will remain immobile, so you can
43 move around it to view it from different angles.
44
45 Testgun will cause the model to follow the player around and supress the real
46 view weapon model. The default frame 0 of most guns is completely off screen,
47 so you will probably have to cycle a couple frames to see it.
48
49 "nextframe", "prevframe", "nextskin", and "prevskin" commands will change the
50 frame or skin of the testmodel. These are bound to F5, F6, F7, and F8 in
51 q3default.cfg.
52
53 If a gun is being tested, the "gun_x", "gun_y", and "gun_z" variables will let
54 you adjust the positioning.
55
56 Note that none of the model testing features update while the game is paused, so
57 it may be convenient to test with deathmatch set to 1 so that bringing down the
58 console doesn't pause the game.
59
60 =============================================================================
61 */
62
63 /*
64 =================
65 CG_TestModel_f
66
67 Creates an entity in front of the current position, which
68 can then be moved around
69 =================
70 */
71 void CG_TestModel_f (void) {
72 vec3_t angles;
73
74 memset( &cg.testModelEntity, 0, sizeof(cg.testModelEntity) );
75 if ( trap_Argc() < 2 ) {
76 return;
77 }
78
79 Q_strncpyz (cg.testModelName, CG_Argv( 1 ), MAX_QPATH );
80 cg.testModelEntity.hModel = trap_R_RegisterModel( cg.testModelName );
81
82 if ( trap_Argc() == 3 ) {
83 cg.testModelEntity.backlerp = atof( CG_Argv( 2 ) );
84 cg.testModelEntity.frame = 1;
85 cg.testModelEntity.oldframe = 0;
86 }
87 if (! cg.testModelEntity.hModel ) {
88 CG_Printf( "Can't register model\n" );
89 return;
90 }
91
92 VectorMA( cg.refdef.vieworg, 100, cg.refdef.viewaxis[0], cg.testModelEntity.origin );
93
94 angles[PITCH] = 0;
95 angles[YAW] = 180 + cg.refdefViewAngles[1];
96 angles[ROLL] = 0;
97
98 AnglesToAxis( angles, cg.testModelEntity.axis );
99 cg.testGun = qfalse;
100 }
101
102 /*
103 =================
104 CG_TestGun_f
105
106 Replaces the current view weapon with the given model
107 =================
108 */
109 void CG_TestGun_f (void) {
110 CG_TestModel_f();
111 cg.testGun = qtrue;
112 cg.testModelEntity.renderfx = RF_MINLIGHT | RF_DEPTHHACK | RF_FIRST_PERSON;
113 }
114
115
116 void CG_TestModelNextFrame_f (void) {
117 cg.testModelEntity.frame++;
118 CG_Printf( "frame %i\n", cg.testModelEntity.frame );
119 }
120
121 void CG_TestModelPrevFrame_f (void) {
122 cg.testModelEntity.frame--;
123 if ( cg.testModelEntity.frame < 0 ) {
124 cg.testModelEntity.frame = 0;
125 }
126 CG_Printf( "frame %i\n", cg.testModelEntity.frame );
127 }
128
129 void CG_TestModelNextSkin_f (void) {
130 cg.testModelEntity.skinNum++;
131 CG_Printf( "skin %i\n", cg.testModelEntity.skinNum );
132 }
133
134 void CG_TestModelPrevSkin_f (void) {
135 cg.testModelEntity.skinNum--;
136 if ( cg.testModelEntity.skinNum < 0 ) {
137 cg.testModelEntity.skinNum = 0;
138 }
139 CG_Printf( "skin %i\n", cg.testModelEntity.skinNum );
140 }
141
142 static void CG_AddTestModel (void) {
143 int i;
144
145 // re-register the model, because the level may have changed
146 cg.testModelEntity.hModel = trap_R_RegisterModel( cg.testModelName );
147 if (! cg.testModelEntity.hModel ) {
148 CG_Printf ("Can't register model\n");
149 return;
150 }
151
152 // if testing a gun, set the origin reletive to the view origin
153 if ( cg.testGun ) {
154 VectorCopy( cg.refdef.vieworg, cg.testModelEntity.origin );
155 VectorCopy( cg.refdef.viewaxis[0], cg.testModelEntity.axis[0] );
156 VectorCopy( cg.refdef.viewaxis[1], cg.testModelEntity.axis[1] );
157 VectorCopy( cg.refdef.viewaxis[2], cg.testModelEntity.axis[2] );
158
159 // allow the position to be adjusted
160 for (i=0 ; i<3 ; i++) {
161 cg.testModelEntity.origin[i] += cg.refdef.viewaxis[0][i] * cg_gun_x.value;
162 cg.testModelEntity.origin[i] += cg.refdef.viewaxis[1][i] * cg_gun_y.value;
163 cg.testModelEntity.origin[i] += cg.refdef.viewaxis[2][i] * cg_gun_z.value;
164 }
165 }
166
167 trap_R_AddRefEntityToScene( &cg.testModelEntity );
168 }
169
170
171
172 //============================================================================
173
174
175 /*
176 =================
177 CG_CalcVrect
178
179 Sets the coordinates of the rendered window
180 =================
181 */
182 static void CG_CalcVrect (void) {
183 int size;
184
185 // the intermission should allways be full screen
186 if ( cg.snap->ps.pm_type == PM_INTERMISSION ) {
187 size = 100;
188 } else {
189 // bound normal viewsize
190 if (cg_viewsize.integer < 30) {
191 trap_Cvar_Set ("cg_viewsize","30");
192 size = 30;
193 } else if (cg_viewsize.integer > 100) {
194 trap_Cvar_Set ("cg_viewsize","100");
195 size = 100;
196 } else {
197 size = cg_viewsize.integer;
198 }
199
200 }
201 cg.refdef.width = cgs.glconfig.vidWidth*size/100;
202 cg.refdef.width &= ~1;
203
204 cg.refdef.height = cgs.glconfig.vidHeight*size/100;
205 cg.refdef.height &= ~1;
206
207 cg.refdef.x = (cgs.glconfig.vidWidth - cg.refdef.width)/2;
208 cg.refdef.y = (cgs.glconfig.vidHeight - cg.refdef.height)/2;
209 }
210
211 //==============================================================================
212
213
214 /*
215 ===============
216 CG_OffsetThirdPersonView
217
218 ===============
219 */
220 #define FOCUS_DISTANCE 512
221 static void CG_OffsetThirdPersonView( void ) {
222 vec3_t forward, right, up;
223 vec3_t view;
224 vec3_t focusAngles;
225 trace_t trace;
226 static vec3_t mins = { -4, -4, -4 };
227 static vec3_t maxs = { 4, 4, 4 };
228 vec3_t focusPoint;
229 float focusDist;
230 float forwardScale, sideScale;
231
232 cg.refdef.vieworg[2] += cg.predictedPlayerState.viewheight;
233
234 VectorCopy( cg.refdefViewAngles, focusAngles );
235
236 // if dead, look at killer
237 if ( (cg.predictedPlayerState.stats[STAT_HEALTH] <= 0) &&
238 (cgs.gametype !=GT_ELIMINATION && cgs.gametype !=GT_CTF_ELIMINATION && cgs.gametype !=GT_LMS) ) {
239 focusAngles[YAW] = cg.predictedPlayerState.stats[STAT_DEAD_YAW];
240 cg.refdefViewAngles[YAW] = cg.predictedPlayerState.stats[STAT_DEAD_YAW];
241 }
242
243 if ( focusAngles[PITCH] > 45 ) {
244 focusAngles[PITCH] = 45; // don't go too far overhead
245 }
246 AngleVectors( focusAngles, forward, NULL, NULL );
247
248 VectorMA( cg.refdef.vieworg, FOCUS_DISTANCE, forward, focusPoint );
249
250 VectorCopy( cg.refdef.vieworg, view );
251
252 view[2] += 8;
253
254 cg.refdefViewAngles[PITCH] *= 0.5;
255
256 AngleVectors( cg.refdefViewAngles, forward, right, up );
257
258 forwardScale = cos( cg_thirdPersonAngle.value / 180 * M_PI );
259 sideScale = sin( cg_thirdPersonAngle.value / 180 * M_PI );
260 VectorMA( view, -cg_thirdPersonRange.value * forwardScale, forward, view );
261 VectorMA( view, -cg_thirdPersonRange.value * sideScale, right, view );
262
263 // trace a ray from the origin to the viewpoint to make sure the view isn't
264 // in a solid block. Use an 8 by 8 block to prevent the view from near clipping anything
265
266 if (!cg_cameraMode.integer) {
267 CG_Trace( &trace, cg.refdef.vieworg, mins, maxs, view, cg.predictedPlayerState.clientNum, MASK_SOLID );
268
269 if ( trace.fraction != 1.0 ) {
270 VectorCopy( trace.endpos, view );
271 view[2] += (1.0 - trace.fraction) * 32;
272 // try another trace to this position, because a tunnel may have the ceiling
273 // close enogh that this is poking out
274
275 CG_Trace( &trace, cg.refdef.vieworg, mins, maxs, view, cg.predictedPlayerState.clientNum, MASK_SOLID );
276 VectorCopy( trace.endpos, view );
277 }
278 }
279
280
281 VectorCopy( view, cg.refdef.vieworg );
282
283 // select pitch to look at focus point from vieword
284 VectorSubtract( focusPoint, cg.refdef.vieworg, focusPoint );
285 focusDist = sqrt( focusPoint[0] * focusPoint[0] + focusPoint[1] * focusPoint[1] );
286 if ( focusDist < 1 ) {
287 focusDist = 1; // should never happen
288 }
289 cg.refdefViewAngles[PITCH] = -180 / M_PI * atan2( focusPoint[2], focusDist );
290 cg.refdefViewAngles[YAW] -= cg_thirdPersonAngle.value;
291 }
292
293
294 // this causes a compiler bug on mac MrC compiler
295 static void CG_StepOffset( void ) {
296 int timeDelta;
297
298 // smooth out stair climbing
299 timeDelta = cg.time - cg.stepTime;
300 if ( timeDelta < STEP_TIME ) {
301 cg.refdef.vieworg[2] -= cg.stepChange
302 * (STEP_TIME - timeDelta) / STEP_TIME;
303 }
304 }
305
306 /*
307 ===============
308 CG_OffsetFirstPersonView
309
310 ===============
311 */
312 static void CG_OffsetFirstPersonView( void ) {
313 float *origin;
314 float *angles;
315 float bob;
316 float ratio;
317 float delta;
318 float speed;
319 float f;
320 vec3_t predictedVelocity;
321 int timeDelta;
322
323 if ( cg.snap->ps.pm_type == PM_INTERMISSION ) {
324 return;
325 }
326
327 origin = cg.refdef.vieworg;
328 angles = cg.refdefViewAngles;
329
330 // if dead, fix the angle and don't add any kick
331 if ( cg.snap->ps.stats[STAT_HEALTH] <= 0 ) {
332 angles[ROLL] = 40;
333 angles[PITCH] = -15;
334 angles[YAW] = cg.snap->ps.stats[STAT_DEAD_YAW];
335 origin[2] += cg.predictedPlayerState.viewheight;
336 return;
337 }
338
339 // add angles based on weapon kick
340 VectorAdd (angles, cg.kick_angles, angles);
341
342 // add angles based on damage kick
343 if ( cg.damageTime && cgs.gametype!=GT_ELIMINATION && cgs.gametype!=GT_CTF_ELIMINATION && cgs.gametype!=GT_LMS) {
344 ratio = cg.time - cg.damageTime;
345 if ( ratio < DAMAGE_DEFLECT_TIME ) {
346 ratio /= DAMAGE_DEFLECT_TIME;
347 angles[PITCH] += ratio * cg.v_dmg_pitch;
348 angles[ROLL] += ratio * cg.v_dmg_roll;
349 } else {
350 ratio = 1.0 - ( ratio - DAMAGE_DEFLECT_TIME ) / DAMAGE_RETURN_TIME;
351 if ( ratio > 0 ) {
352 angles[PITCH] += ratio * cg.v_dmg_pitch;
353 angles[ROLL] += ratio * cg.v_dmg_roll;
354 }
355 }
356 }
357
358 // add pitch based on fall kick
359 #if 0
360 ratio = ( cg.time - cg.landTime) / FALL_TIME;
361 if (ratio < 0)
362 ratio = 0;
363 angles[PITCH] += ratio * cg.fall_value;
364 #endif
365
366 // add angles based on velocity
367 VectorCopy( cg.predictedPlayerState.velocity, predictedVelocity );
368
369 delta = DotProduct ( predictedVelocity, cg.refdef.viewaxis[0]);
370 angles[PITCH] += delta * cg_runpitch.value;
371
372 delta = DotProduct ( predictedVelocity, cg.refdef.viewaxis[1]);
373 angles[ROLL] -= delta * cg_runroll.value;
374
375 // add angles based on bob
376
377 // make sure the bob is visible even at low speeds
378 speed = cg.xyspeed > 200 ? cg.xyspeed : 200;
379
380 delta = cg.bobfracsin * cg_bobpitch.value * speed;
381 if (cg.predictedPlayerState.pm_flags & PMF_DUCKED)
382 delta *= 3; // crouching
383 angles[PITCH] += delta;
384 delta = cg.bobfracsin * cg_bobroll.value * speed;
385 if (cg.predictedPlayerState.pm_flags & PMF_DUCKED)
386 delta *= 3; // crouching accentuates roll
387 if (cg.bobcycle & 1)
388 delta = -delta;
389 angles[ROLL] += delta;
390
391 //===================================
392
393 // add view height
394 origin[2] += cg.predictedPlayerState.viewheight;
395
396 // smooth out duck height changes
397 timeDelta = cg.time - cg.duckTime;
398 if ( timeDelta < DUCK_TIME) {
399 cg.refdef.vieworg[2] -= cg.duckChange
400 * (DUCK_TIME - timeDelta) / DUCK_TIME;
401 }
402
403 // add bob height
404 bob = cg.bobfracsin * cg.xyspeed * cg_bobup.value;
405 if (bob > 6) {
406 bob = 6;
407 }
408
409 origin[2] += bob;
410
411
412 // add fall height
413 delta = cg.time - cg.landTime;
414 if ( delta < LAND_DEFLECT_TIME ) {
415 f = delta / LAND_DEFLECT_TIME;
416 cg.refdef.vieworg[2] += cg.landChange * f;
417 } else if ( delta < LAND_DEFLECT_TIME + LAND_RETURN_TIME ) {
418 delta -= LAND_DEFLECT_TIME;
419 f = 1.0 - ( delta / LAND_RETURN_TIME );
420 cg.refdef.vieworg[2] += cg.landChange * f;
421 }
422
423 // add step offset
424 CG_StepOffset();
425
426 // add kick offset
427
428 VectorAdd (origin, cg.kick_origin, origin);
429
430 // pivot the eye based on a neck length
431 #if 0
432 {
433 #define NECK_LENGTH 8
434 vec3_t forward, up;
435
436 cg.refdef.vieworg[2] -= NECK_LENGTH;
437 AngleVectors( cg.refdefViewAngles, forward, NULL, up );
438 VectorMA( cg.refdef.vieworg, 3, forward, cg.refdef.vieworg );
439 VectorMA( cg.refdef.vieworg, NECK_LENGTH, up, cg.refdef.vieworg );
440 }
441 #endif
442 }
443
444 //======================================================================
445
446 void CG_ZoomDown_f( void ) {
447 if ( cg.zoomed ) {
448 return;
449 }
450 cg.zoomed = qtrue;
451 cg.zoomTime = cg.time;
452 }
453
454 void CG_ZoomUp_f( void ) {
455 if ( !cg.zoomed ) {
456 return;
457 }
458 cg.zoomed = qfalse;
459 cg.zoomTime = cg.time;
460 }
461
462
463 /*
464 ====================
465 CG_CalcFov
466
467 Fixed fov at intermissions, otherwise account for fov variable and zooms.
468 ====================
469 */
470 #define WAVE_AMPLITUDE 1
471 #define WAVE_FREQUENCY 0.4
472
473 static int CG_CalcFov( void ) {
474 float x;
475 float phase;
476 float v;
477 int contents;
478 float fov_x, fov_y;
479 float zoomFov;
480 float f;
481 int inwater;
482
483 if ( cg.predictedPlayerState.pm_type == PM_INTERMISSION ) {
484 // if in intermission, use a fixed value
485 fov_x = 90;
486 } else {
487 // user selectable
488 if ( cgs.dmflags & DF_FIXED_FOV ) {
489 // dmflag to prevent wide fov for all clients
490 fov_x = 90;
491 } else {
492 fov_x = cg_fov.value;
493 if ( fov_x < 1 ) {
494 fov_x = 1;
495 } else if ( fov_x > 160 ) {
496 fov_x = 160;
497 }
498 if( (cgs.videoflags & VF_LOCK_CVARS_BASIC) && fov_x>140 )
499 fov_x = 140;
500
501 }
502
503 if ( cgs.dmflags & DF_FIXED_FOV ) {
504 // dmflag to prevent wide fov for all clients
505 zoomFov = 22.5;
506 } else {
507 // account for zooms
508 zoomFov = cg_zoomFov.value;
509 if ( zoomFov < 1 ) {
510 zoomFov = 1;
511 } else if ( zoomFov > 160 ) {
512 zoomFov = 160;
513 }
514
515 if( (cgs.videoflags & VF_LOCK_CVARS_BASIC) && zoomFov>140 )
516 zoomFov = 140;
517 }
518
519 if ( cg.zoomed ) {
520 f = ( cg.time - cg.zoomTime ) / (float)ZOOM_TIME;
521 if ( f > 1.0 ) {
522 fov_x = zoomFov;
523 } else {
524 fov_x = fov_x + f * ( zoomFov - fov_x );
525 }
526 } else {
527 f = ( cg.time - cg.zoomTime ) / (float)ZOOM_TIME;
528 if ( f > 1.0 ) {
529 fov_x = fov_x;
530 } else {
531 fov_x = zoomFov + f * ( fov_x - zoomFov );
532 }
533 }
534 }
535
536 x = cg.refdef.width / tan( fov_x / 360 * M_PI );
537 fov_y = atan2( cg.refdef.height, x );
538 fov_y = fov_y * 360 / M_PI;
539
540 // warp if underwater
541 contents = CG_PointContents( cg.refdef.vieworg, -1 );
542 if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ){
543 phase = cg.time / 1000.0 * WAVE_FREQUENCY * M_PI * 2;
544 v = WAVE_AMPLITUDE * sin( phase );
545 fov_x += v;
546 fov_y -= v;
547 inwater = qtrue;
548 }
549 else {
550 inwater = qfalse;
551 }
552
553
554 // set it
555 cg.refdef.fov_x = fov_x;
556 cg.refdef.fov_y = fov_y;
557
558 if ( !cg.zoomed ) {
559 cg.zoomSensitivity = 1;
560 } else {
561 cg.zoomSensitivity = cg.refdef.fov_y / 75.0;
562 }
563
564 return inwater;
565 }
566
567
568
569 /*
570 ===============
571 CG_DamageBlendBlob
572
573 ===============
574 */
575 static void CG_DamageBlendBlob( void ) {
576 int t;
577 int maxTime;
578 refEntity_t ent;
579
580 if ( !cg.damageValue ) {
581 return;
582 }
583
584 //if (cg.cameraMode) {
585 // return;
586 //}
587
588 // ragePro systems can't fade blends, so don't obscure the screen
589 if ( cgs.glconfig.hardwareType == GLHW_RAGEPRO ) {
590 return;
591 }
592
593 maxTime = DAMAGE_TIME;
594 t = cg.time - cg.damageTime;
595 if ( t <= 0 || t >= maxTime ) {
596 return;
597 }
598
599
600 memset( &ent, 0, sizeof( ent ) );
601 ent.reType = RT_SPRITE;
602 ent.renderfx = RF_FIRST_PERSON;
603
604 VectorMA( cg.refdef.vieworg, 8, cg.refdef.viewaxis[0], ent.origin );
605 VectorMA( ent.origin, cg.damageX * -8, cg.refdef.viewaxis[1], ent.origin );
606 VectorMA( ent.origin, cg.damageY * 8, cg.refdef.viewaxis[2], ent.origin );
607
608 ent.radius = cg.damageValue * 3;
609 ent.customShader = cgs.media.viewBloodShader;
610 ent.shaderRGBA[0] = 255;
611 ent.shaderRGBA[1] = 255;
612 ent.shaderRGBA[2] = 255;
613 ent.shaderRGBA[3] = 200 * ( 1.0 - ((float)t / maxTime) );
614 trap_R_AddRefEntityToScene( &ent );
615 }
616
617
618 /*
619 ===============
620 CG_CalcViewValues
621
622 Sets cg.refdef view values
623 ===============
624 */
625 static int CG_CalcViewValues( void ) {
626 playerState_t *ps;
627
628 memset( &cg.refdef, 0, sizeof( cg.refdef ) );
629
630 // strings for in game rendering
631 // Q_strncpyz( cg.refdef.text[0], "Park Ranger", sizeof(cg.refdef.text[0]) );
632 // Q_strncpyz( cg.refdef.text[1], "19", sizeof(cg.refdef.text[1]) );
633
634 // calculate size of 3D view
635 CG_CalcVrect();
636
637 ps = &cg.predictedPlayerState;
638 /*
639 if (cg.cameraMode) {
640 vec3_t origin, angles;
641 if (trap_getCameraInfo(cg.time, &origin, &angles)) {
642 VectorCopy(origin, cg.refdef.vieworg);
643 angles[ROLL] = 0;
644 VectorCopy(angles, cg.refdefViewAngles);
645 AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis );
646 return CG_CalcFov();
647 } else {
648 cg.cameraMode = qfalse;
649 }
650 }
651 */
652 // intermission view
653 if ( ps->pm_type == PM_INTERMISSION ) {
654 VectorCopy( ps->origin, cg.refdef.vieworg );
655 VectorCopy( ps->viewangles, cg.refdefViewAngles );
656 AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis );
657 return CG_CalcFov();
658 }
659
660 cg.bobcycle = ( ps->bobCycle & 128 ) >> 7;
661 cg.bobfracsin = fabs( sin( ( ps->bobCycle & 127 ) / 127.0 * M_PI ) );
662
663 cg.xyspeed = sqrt( ps->velocity[0] * ps->velocity[0] +
664 ps->velocity[1] * ps->velocity[1] );
665
666
667 VectorCopy( ps->origin, cg.refdef.vieworg );
668 VectorCopy( ps->viewangles, cg.refdefViewAngles );
669
670 if (cg_cameraOrbit.integer) {
671 if (cg.time > cg.nextOrbitTime) {
672 cg.nextOrbitTime = cg.time + cg_cameraOrbitDelay.integer;
673 cg_thirdPersonAngle.value += cg_cameraOrbit.value;
674 }
675 }
676 // add error decay
677 if ( cg_errorDecay.value > 0 ) {
678 int t;
679 float f;
680
681 t = cg.time - cg.predictedErrorTime;
682 f = ( cg_errorDecay.value - t ) / cg_errorDecay.value;
683 if ( f > 0 && f < 1 ) {
684 VectorMA( cg.refdef.vieworg, f, cg.predictedError, cg.refdef.vieworg );
685 } else {
686 cg.predictedErrorTime = 0;
687 }
688 }
689
690 if ( cg.renderingThirdPerson ) {
691 // back away from character
692 CG_OffsetThirdPersonView();
693 } else {
694 // offset for local bobbing and kicks
695 CG_OffsetFirstPersonView();
696 }
697
698 // position eye reletive to origin
699 AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis );
700
701 if ( cg.hyperspace ) {
702 cg.refdef.rdflags |= RDF_NOWORLDMODEL | RDF_HYPERSPACE;
703 }
704
705 // field of view
706 return CG_CalcFov();
707 }
708
709
710 /*
711 =====================
712 CG_PowerupTimerSounds
713 =====================
714 */
715 static void CG_PowerupTimerSounds( void ) {
716 int i;
717 int t;
718
719 // powerup timers going away
720 for ( i = 0 ; i < MAX_POWERUPS ; i++ ) {
721 t = cg.snap->ps.powerups[i];
722 if ( t <= cg.time ) {
723 continue;
724 }
725 if ( t - cg.time >= POWERUP_BLINKS * POWERUP_BLINK_TIME ) {
726 continue;
727 }
728 if ( ( t - cg.time ) / POWERUP_BLINK_TIME != ( t - cg.oldTime ) / POWERUP_BLINK_TIME ) {
729 trap_S_StartSound( NULL, cg.snap->ps.clientNum, CHAN_ITEM, cgs.media.wearOffSound );
730 }
731 }
732 }
733
734 /*
735 =====================
736 CG_AddBufferedSound
737 =====================
738 */
739 void CG_AddBufferedSound( sfxHandle_t sfx ) {
740 if ( !sfx )
741 return;
742 cg.soundBuffer[cg.soundBufferIn] = sfx;
743 cg.soundBufferIn = (cg.soundBufferIn + 1) % MAX_SOUNDBUFFER;
744 if (cg.soundBufferIn == cg.soundBufferOut) {
745 cg.soundBufferOut++;
746 }
747 }
748
749 /*
750 =====================
751 CG_PlayBufferedSounds
752 =====================
753 */
754 static void CG_PlayBufferedSounds( void ) {
755 if ( cg.soundTime < cg.time ) {
756 if (cg.soundBufferOut != cg.soundBufferIn && cg.soundBuffer[cg.soundBufferOut]) {
757 trap_S_StartLocalSound(cg.soundBuffer[cg.soundBufferOut], CHAN_ANNOUNCER);
758 cg.soundBuffer[cg.soundBufferOut] = 0;
759 cg.soundBufferOut = (cg.soundBufferOut + 1) % MAX_SOUNDBUFFER;
760 cg.soundTime = cg.time + 750;
761 }
762 }
763 }
764
765 //=========================================================================
766
767 /*
768 =================
769 CG_DrawActiveFrame
770
771 Generates and draws a game scene and status information at the given time.
772 =================
773 */
774 void CG_DrawActiveFrame( int serverTime, stereoFrame_t stereoView, qboolean demoPlayback ) {
775 int inwater;
776
777 cg.time = serverTime;
778 cg.demoPlayback = demoPlayback;
779
780 // update cvars
781 CG_UpdateCvars();
782
783 // if we are only updating the screen as a loading
784 // pacifier, don't even try to read snapshots
785 if ( cg.infoScreenText[0] != 0 ) {
786 CG_DrawInformation();
787 return;
788 }
789
790 // any looped sounds will be respecified as entities
791 // are added to the render list
792 trap_S_ClearLoopingSounds(qfalse);
793
794 // clear all the render lists
795 trap_R_ClearScene();
796
797 // set up cg.snap and possibly cg.nextSnap
798 CG_ProcessSnapshots();
799
800 // if we haven't received any snapshots yet, all
801 // we can draw is the information screen
802 if ( !cg.snap || ( cg.snap->snapFlags & SNAPFLAG_NOT_ACTIVE ) ) {
803 CG_DrawInformation();
804 return;
805 }
806
807 // let the client system know what our weapon and zoom settings are
808 trap_SetUserCmdValue( cg.weaponSelect, cg.zoomSensitivity );
809
810 // this counter will be bumped for every valid scene we generate
811 cg.clientFrame++;
812
813 // update cg.predictedPlayerState
814 CG_PredictPlayerState();
815
816 // decide on third person view
817 cg.renderingThirdPerson = cg_thirdPerson.integer || (cg.snap->ps.stats[STAT_HEALTH] <= 0);
818
819 // build cg.refdef
820 inwater = CG_CalcViewValues();
821
822 // first person blend blobs, done after AnglesToAxis
823 if ( !cg.renderingThirdPerson ) {
824 CG_DamageBlendBlob();
825 }
826
827 // build the render lists
828 if ( !cg.hyperspace ) {
829 CG_AddPacketEntities(); // adter calcViewValues, so predicted player state is correct
830 CG_AddMarks();
831 CG_AddParticles ();
832 CG_AddLocalEntities();
833 }
834 CG_AddViewWeapon( &cg.predictedPlayerState );
835
836 // add buffered sounds
837 CG_PlayBufferedSounds();
838
839 // play buffered voice chats
840 CG_PlayBufferedVoiceChats();
841
842 // finish up the rest of the refdef
843 if ( cg.testModelEntity.hModel ) {
844 CG_AddTestModel();
845 }
846 cg.refdef.time = cg.time;
847 memcpy( cg.refdef.areamask, cg.snap->areamask, sizeof( cg.refdef.areamask ) );
848
849 // warning sounds when powerup is wearing off
850 CG_PowerupTimerSounds();
851
852 // update audio positions
853 trap_S_Respatialize( cg.snap->ps.clientNum, cg.refdef.vieworg, cg.refdef.viewaxis, inwater );
854
855 // make sure the lagometerSample and frame timing isn't done twice when in stereo
856 if ( stereoView != STEREO_RIGHT ) {
857 cg.frametime = cg.time - cg.oldTime;
858 if ( cg.frametime < 0 ) {
859 cg.frametime = 0;
860 }
861 cg.oldTime = cg.time;
862 CG_AddLagometerFrameInfo();
863 }
864 if (cg_timescale.value != cg_timescaleFadeEnd.value) {
865 if (cg_timescale.value < cg_timescaleFadeEnd.value) {
866 cg_timescale.value += cg_timescaleFadeSpeed.value * ((float)cg.frametime) / 1000;
867 if (cg_timescale.value > cg_timescaleFadeEnd.value)
868 cg_timescale.value = cg_timescaleFadeEnd.value;
869 }
870 else {
871 cg_timescale.value -= cg_timescaleFadeSpeed.value * ((float)cg.frametime) / 1000;
872 if (cg_timescale.value < cg_timescaleFadeEnd.value)
873 cg_timescale.value = cg_timescaleFadeEnd.value;
874 }
875 if (cg_timescaleFadeSpeed.value) {
876 trap_Cvar_Set("timescale", va("%f", cg_timescale.value));
877 }
878 }
879
880 // actually issue the rendering calls
881 CG_DrawActive( stereoView );
882
883 if ( cg_stats.integer ) {
884 CG_Printf( "cg.clientFrame:%i\n", cg.clientFrame );
885 }
886
887
888 }
889