Debian Codegraph @

code/cgame/cg_view.c

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