3 #include <client/announcer.qh>
4 #include <client/csqcmodel_hooks.qh>
5 #include <client/draw.qh>
6 #include <client/hud/_mod.qh>
7 #include <client/hud/panel/quickmenu.qh>
8 #include <client/hud/panel/scoreboard.qh>
9 #include <client/mapvoting.qh>
10 #include <client/mutators/_mod.qh>
11 #include <client/shownames.qh>
12 #include <common/anim.qh>
13 #include <common/animdecide.qh>
14 #include <common/constants.qh>
15 #include <common/deathtypes/all.qh>
16 #include <common/debug.qh>
17 #include <common/ent_cs.qh>
18 #include <common/gamemodes/_mod.qh>
19 #include <common/mapinfo.qh>
20 #include <common/mapobjects/target/music.qh>
21 #include <common/mapobjects/trigger/viewloc.qh>
22 #include <common/minigames/cl_minigames.qh>
23 #include <common/minigames/cl_minigames_hud.qh>
24 #include <common/mutators/mutator/powerups/_mod.qh>
25 #include <common/mutators/mutator/status_effects/_mod.qh>
26 #include <common/mutators/mutator/waypoints/all.qh>
27 #include <common/net_linked.qh>
28 #include <common/net_notice.qh>
29 #include <common/physics/player.qh>
30 #include <common/stats.qh>
31 #include <common/teams.qh>
32 #include <common/vehicles/all.qh>
33 #include <common/viewloc.qh>
34 #include <common/weapons/_all.qh>
35 #include <common/weapons/weapon/tuba.qh>
36 #include <common/wepent.qh>
37 #include <lib/csqcmodel/cl_model.qh>
38 #include <lib/csqcmodel/cl_player.qh>
39 #include <lib/warpzone/client.qh>
40 #include <lib/warpzone/common.qh>
42 float autocvar_cl_viewmodel_scale;
43 float autocvar_cl_viewmodel_alpha = 1;
45 bool autocvar_cl_bobmodel;
46 float autocvar_cl_bobmodel_speed;
47 float autocvar_cl_bobmodel_side;
48 float autocvar_cl_bobmodel_up;
50 float autocvar_cl_followmodel;
51 float autocvar_cl_followmodel_speed = 0.3;
52 float autocvar_cl_followmodel_limit = 135;
53 float autocvar_cl_followmodel_velocity_lowpass = 0.05;
54 float autocvar_cl_followmodel_highpass = 0.05;
55 float autocvar_cl_followmodel_lowpass = 0.03;
56 bool autocvar_cl_followmodel_velocity_absolute;
58 float autocvar_cl_leanmodel;
59 float autocvar_cl_leanmodel_speed = 0.3;
60 float autocvar_cl_leanmodel_limit = 30;
61 float autocvar_cl_leanmodel_highpass1 = 0.2;
62 float autocvar_cl_leanmodel_highpass = 0.2;
63 float autocvar_cl_leanmodel_lowpass = 0.05;
65 #define avg_factor(avg_time) (1 - exp(-frametime / max(0.001, avg_time)))
67 #define lowpass(value, frac, ref_store, ret) \
68 ret = ref_store = ref_store * (1 - frac) + (value) * frac;
70 #define lowpass_limited(value, frac, limit, ref_store, ret) MACRO_BEGIN \
71 float __ignore; lowpass(value, frac, ref_store, __ignore); \
72 ret = ref_store = bound((value) - (limit), ref_store, (value) + (limit)); \
75 #define highpass(value, frac, ref_store, ret) MACRO_BEGIN \
76 float __f = 0; lowpass(value, frac, ref_store, __f); \
77 ret = (value) - __f; \
80 #define highpass_limited(value, frac, limit, ref_store, ret) MACRO_BEGIN \
81 float __f = 0; lowpass_limited(value, frac, limit, ref_store, __f); \
82 ret = (value) - __f; \
85 #define lowpass2(value, frac, ref_store, ref_out) MACRO_BEGIN \
86 lowpass(value.x, frac, ref_store.x, ref_out.x); \
87 lowpass(value.y, frac, ref_store.y, ref_out.y); \
90 #define highpass2(value, frac, ref_store, ref_out) MACRO_BEGIN \
91 highpass(value.x, frac, ref_store.x, ref_out.x); \
92 highpass(value.y, frac, ref_store.y, ref_out.y); \
95 #define highpass2_limited(value, frac, limit, ref_store, ref_out) MACRO_BEGIN \
96 highpass_limited(value.x, frac, limit, ref_store.x, ref_out.x); \
97 highpass_limited(value.y, frac, limit, ref_store.y, ref_out.y); \
100 #define lowpass3(value, frac, ref_store, ref_out) MACRO_BEGIN \
101 lowpass(value.x, frac, ref_store.x, ref_out.x); \
102 lowpass(value.y, frac, ref_store.y, ref_out.y); \
103 lowpass(value.z, frac, ref_store.z, ref_out.z); \
106 #define highpass3(value, frac, ref_store, ref_out) MACRO_BEGIN \
107 highpass(value.x, frac, ref_store.x, ref_out.x); \
108 highpass(value.y, frac, ref_store.y, ref_out.y); \
109 highpass(value.z, frac, ref_store.z, ref_out.z); \
112 void calc_followmodel_ofs(entity view)
114 if(cl_followmodel_time == time)
115 return; // cl_followmodel_ofs already calculated for this frame
118 vector gunorg = '0 0 0';
119 static vector vel_average;
120 static vector gunorg_adjustment_highpass;
121 static vector gunorg_adjustment_lowpass;
124 if (autocvar_cl_followmodel_velocity_absolute)
128 vector forward, right, up;
129 MAKE_VECTORS(view_angles, forward, right, up);
130 vel.x = view.velocity * forward;
131 vel.y = view.velocity * right * -1;
132 vel.z = view.velocity * up;
135 vel.x = bound(vel_average.x - autocvar_cl_followmodel_limit, vel.x, vel_average.x + autocvar_cl_followmodel_limit);
136 vel.y = bound(vel_average.y - autocvar_cl_followmodel_limit, vel.y, vel_average.y + autocvar_cl_followmodel_limit);
137 vel.z = bound(vel_average.z - autocvar_cl_followmodel_limit, vel.z, vel_average.z + autocvar_cl_followmodel_limit);
139 frac = avg_factor(autocvar_cl_followmodel_velocity_lowpass);
140 lowpass3(vel, frac, vel_average, gunorg);
142 gunorg *= -autocvar_cl_followmodel_speed * 0.042;
144 // perform highpass/lowpass on the adjustment vectors (turning velocity into acceleration!)
145 // trick: we must do the lowpass LAST, so the lowpass vector IS the final vector!
146 frac = avg_factor(autocvar_cl_followmodel_highpass);
147 highpass3(gunorg, frac, gunorg_adjustment_highpass, gunorg);
148 frac = avg_factor(autocvar_cl_followmodel_lowpass);
149 lowpass3(gunorg, frac, gunorg_adjustment_lowpass, gunorg);
151 if (autocvar_cl_followmodel_velocity_absolute)
154 vector forward, right, up;
155 MAKE_VECTORS(view_angles, forward, right, up);
156 fixed_gunorg.x = gunorg * forward;
157 fixed_gunorg.y = gunorg * right * -1;
158 fixed_gunorg.z = gunorg * up;
159 gunorg = fixed_gunorg;
162 cl_followmodel_ofs = gunorg;
163 cl_followmodel_time = time;
166 vector leanmodel_ofs(entity view)
169 vector gunangles = '0 0 0';
170 static vector gunangles_prev = '0 0 0';
171 static vector gunangles_highpass = '0 0 0';
172 static vector gunangles_adjustment_highpass;
173 static vector gunangles_adjustment_lowpass;
175 if (view.csqcmodel_teleported)
176 gunangles_prev = view_angles;
178 // in the highpass, we _store_ the DIFFERENCE to the actual view angles...
179 gunangles_highpass += gunangles_prev;
180 PITCH(gunangles_highpass) += 360 * floor((PITCH(view_angles) - PITCH(gunangles_highpass)) / 360 + 0.5);
181 YAW(gunangles_highpass) += 360 * floor((YAW(view_angles) - YAW(gunangles_highpass)) / 360 + 0.5);
182 ROLL(gunangles_highpass) += 360 * floor((ROLL(view_angles) - ROLL(gunangles_highpass)) / 360 + 0.5);
183 frac = avg_factor(autocvar_cl_leanmodel_highpass1);
184 highpass2_limited(view_angles, frac, autocvar_cl_leanmodel_limit, gunangles_highpass, gunangles);
185 gunangles_prev = view_angles;
186 gunangles_highpass -= gunangles_prev;
188 PITCH(gunangles) *= -autocvar_cl_leanmodel_speed;
189 YAW(gunangles) *= -autocvar_cl_leanmodel_speed;
191 // we assume here: PITCH = 0, YAW = 1, ROLL = 2
192 frac = avg_factor(autocvar_cl_leanmodel_highpass);
193 highpass2(gunangles, frac, gunangles_adjustment_highpass, gunangles);
194 frac = avg_factor(autocvar_cl_leanmodel_lowpass);
195 lowpass2(gunangles, frac, gunangles_adjustment_lowpass, gunangles);
197 gunangles.x = -gunangles.x; // pitch was inverted, now that actually matters
202 vector bobmodel_ofs(entity view)
204 bool clonground = !(view.anim_implicit_state & ANIMIMPLICITSTATE_INAIR);
205 static bool oldonground;
206 static float hitgroundtime;
209 float f = time; // cl.movecmd[0].time
213 oldonground = clonground;
215 // calculate for swinging gun model
216 // the gun bobs when running on the ground, but doesn't bob when you're in the air.
217 vector gunorg = '0 0 0';
218 static float bobmodel_scale = 0;
219 static float time_ofs = 0; // makes the effect always restart in the same way
222 if (time - hitgroundtime > 0.05)
223 bobmodel_scale = min(1, bobmodel_scale + frametime * 5);
226 bobmodel_scale = max(0, bobmodel_scale - frametime * 5);
228 float xyspeed = bound(0, vlen(vec2(view.velocity)), 400);
229 if (bobmodel_scale && xyspeed)
231 float bspeed = xyspeed * 0.01 * autocvar_cl_viewmodel_scale * bobmodel_scale;
232 float s = (time - time_ofs) * autocvar_cl_bobmodel_speed;
233 gunorg.y = bspeed * autocvar_cl_bobmodel_side * sin(s);
234 gunorg.z = bspeed * autocvar_cl_bobmodel_up * cos(s * 2);
242 void viewmodel_animate(entity this)
244 if (autocvar_chase_active) return;
245 if (STAT(HEALTH) <= 0) return;
247 entity view = CSQCModel_server2csqc(player_localentnum - 1);
249 if (autocvar_cl_followmodel)
251 calc_followmodel_ofs(view);
252 this.origin += cl_followmodel_ofs;
255 if (autocvar_cl_leanmodel)
256 this.angles += leanmodel_ofs(view);
258 // vertical view bobbing code
261 // horizontal view bobbing code
265 // causes the view to swing down and back up when touching the ground
268 // gun model bobbing code
269 if (autocvar_cl_bobmodel)
270 this.origin += bobmodel_ofs(view);
273 .vector viewmodel_origin, viewmodel_angles;
274 .float weapon_nextthink;
275 .float weapon_eta_last;
276 .float weapon_switchdelay;
280 void viewmodel_draw(entity this)
282 if(!this.activeweapon || !autocvar_r_drawviewmodel)
284 int mask = (intermission || (STAT(HEALTH) <= 0) || autocvar_chase_active) ? 0 : MASK_NORMAL;
285 float a = ((autocvar_cl_viewmodel_alpha) ? bound(-1, autocvar_cl_viewmodel_alpha, this.m_alpha) : this.m_alpha);
286 int wepskin = this.m_skin;
287 bool invehicle = player_localentnum > maxclients;
288 if (invehicle) a = -1;
289 Weapon wep = this.activeweapon;
290 int c = entcs_GetClientColors(current_player);
291 vector g = weaponentity_glowmod(wep, NULL, c, this);
292 entity me = CSQCModel_server2csqc(player_localentnum - 1);
293 int fx = ((me.csqcmodel_effects & EFMASK_CHEAP)
295 &~ (EF_FULLBRIGHT); // can mask team color, so get rid of it
296 for (entity e = this; e; e = e.weaponchild)
301 e.colormap = 256 + c; // colormap == 0 is black, c == 0 is white
303 e.csqcmodel_effects = fx;
304 CSQCModel_Effects_Apply(e);
308 string name = wep.mdl;
309 string newname = wep.wr_viewmodel(wep, this);
312 bool swap = name != this.name_last;
315 this.name_last = name;
316 CL_WeaponEntity_SetModel(this, name, swap);
317 this.viewmodel_origin = this.origin;
318 this.viewmodel_angles = this.angles;
321 if ((!this.animstate_override && !this.animstate_looping) || time > this.animstate_endtime)
322 anim_set(this, this.anim_idle, true, false, false);
324 float f = 0; // 0..1; 0: fully active
325 float rate = STAT(WEAPONRATEFACTOR);
326 float eta = rate ? ((this.weapon_nextthink - time) / rate) : 0;
327 if (eta <= 0) f = this.weapon_eta_last;
328 else switch (this.state)
332 f = eta / max(eta, this.weapon_switchdelay);
337 f = 1 - eta / max(eta, this.weapon_switchdelay);
346 this.weapon_eta_last = f;
347 this.origin = this.viewmodel_origin;
348 this.angles = this.viewmodel_angles;
349 this.angles_x = (-90 * f * f);
350 viewmodel_animate(this);
351 MUTATOR_CALLHOOK(DrawViewModel, this);
352 setorigin(this, this.origin);
355 STATIC_INIT(viewmodel) {
356 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
357 viewmodels[slot] = new(viewmodel);
360 vector project_3d_to_2d(vector vec)
362 vec = cs_project(vec);
363 if(cs_project_is_b0rked > 0)
365 vec.x *= vid_conwidth / vid_width;
366 vec.y *= vid_conheight / vid_height;
371 bool projected_on_screen(vector screen_pos)
373 return screen_pos.z >= 0
376 && screen_pos.x < vid_conwidth
377 && screen_pos.y < vid_conheight;
380 void update_mousepos()
382 mousepos += getmousepos() * autocvar_menu_mouse_speed;
383 mousepos.x = bound(0, mousepos.x, vid_conwidth);
384 mousepos.y = bound(0, mousepos.y, vid_conheight);
387 float showfps_prevfps_time;
388 int showfps_framecounter;
390 void fpscounter_update()
395 float currentTime = gettime(GETTIME_FRAMESTART);
397 showfps_framecounter += 1;
398 if(currentTime - showfps_prevfps_time > STAT(SHOWFPS))
400 float fps = showfps_framecounter / (currentTime - showfps_prevfps_time);
401 showfps_framecounter = 0;
402 showfps_prevfps_time = currentTime;
404 int channel = MSG_C2S;
405 WriteHeader(channel, fpsreport);
406 WriteShort(channel, bound(0, rint(fps), 32767)); // prevent insane fps values
410 STATIC_INIT(fpscounter_init)
412 float currentTime = gettime(GETTIME_FRAMESTART);
413 showfps_prevfps_time = currentTime; // we must initialize it to avoid an instant low frame sending
417 vector GetCurrentFov(float fov)
419 float zoomsensitivity, zoomspeed, zoomfactor, zoomdir;
420 float velocityzoom, curspeed;
423 zoomsensitivity = autocvar_cl_zoomsensitivity;
424 zoomfactor = autocvar_cl_zoomfactor;
425 if(zoomfactor < 1 || zoomfactor > 30)
427 zoomspeed = autocvar_cl_zoomspeed;
428 if (zoomspeed >= 0 && (zoomspeed < 0.5 || zoomspeed > 16))
431 zoomdir = button_zoom;
433 if(hud == HUD_NORMAL && !spectatee_status)
435 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
437 entity wepent = viewmodels[slot];
438 if(wepent.switchweapon != wepent.activeweapon)
440 Weapon wep = wepent.activeweapon;
441 if(wep != WEP_Null && wep.wr_zoomdir)
443 bool do_zoom = wep.wr_zoomdir(wep); // TODO: merge this with wr_zoom?
448 if(spectatee_status > 0 || isdemo())
450 if(spectatorbutton_zoom)
457 // fteqcc failed twice here already, don't optimize this
460 if(zoomdir) { zoomin_effect = 0; }
462 if (spectatee_status > 0 && STAT(CAMERA_SPECTATOR) == 2)
464 current_viewzoom = 1;
466 else if (camera_active)
468 current_viewzoom = min(1, current_viewzoom + drawframetime);
470 else if(autocvar_cl_spawnzoom && zoomin_effect)
472 float spawnzoomfactor = bound(1, autocvar_cl_spawnzoom_factor, 30);
474 current_viewzoom += (autocvar_cl_spawnzoom_speed * (spawnzoomfactor - current_viewzoom) * drawframetime);
475 current_viewzoom = bound(1 / spawnzoomfactor, current_viewzoom, 1);
476 if(current_viewzoom == 1) { zoomin_effect = 0; }
480 if(zoomspeed < 0) // instant zoom
483 current_viewzoom = 1 / zoomfactor;
485 current_viewzoom = 1;
490 current_viewzoom = 1 / bound(1, 1 / current_viewzoom + drawframetime * zoomspeed * (zoomfactor - 1), zoomfactor);
492 current_viewzoom = bound(1 / zoomfactor, current_viewzoom + drawframetime * zoomspeed * (1 - 1 / zoomfactor), 1);
496 if(almost_equals(current_viewzoom, 1))
497 current_zoomfraction = 0;
498 else if(almost_equals(current_viewzoom, 1/zoomfactor))
499 current_zoomfraction = 1;
501 current_zoomfraction = (current_viewzoom - 1) / (1/zoomfactor - 1);
503 if(zoomsensitivity < 1)
504 setsensitivityscale(current_viewzoom ** (1 - zoomsensitivity));
506 setsensitivityscale(1);
508 if(autocvar_cl_velocityzoom_enabled && autocvar_cl_velocityzoom_type && !autocvar_cl_lockview) // _type = 0 disables velocity zoom too
510 if (intermission || (spectatee_status > 0 && STAT(CAMERA_SPECTATOR) == 2))
514 vector forward, right, up;
515 MAKE_VECTORS(view_angles, forward, right, up);
518 v = csqcplayer.velocity;
520 switch(autocvar_cl_velocityzoom_type)
522 case 3: curspeed = max(0, forward * v); break;
523 case 2: curspeed = (forward * v); break;
524 case 1: default: curspeed = vlen(v); break;
528 velocityzoom = bound(0, drawframetime / max(0.000000001, autocvar_cl_velocityzoom_time), 1); // speed at which the zoom adapts to player velocity
529 avgspeed = avgspeed * (1 - velocityzoom) + (curspeed / autocvar_cl_velocityzoom_speed) * velocityzoom;
530 velocityzoom = exp(float2range11(avgspeed * -autocvar_cl_velocityzoom_factor / 1) * 1);
532 //print(ftos(avgspeed), " avgspeed, ", ftos(curspeed), " curspeed, ", ftos(velocityzoom), " return\n"); // for debugging
537 float frustumx, frustumy, fovx, fovy;
538 frustumy = tan(fov * M_PI / 360.0) * 0.75 * current_viewzoom * velocityzoom;
539 frustumx = frustumy * vid_width / vid_height / vid_pixelheight;
540 fovx = atan2(frustumx, 1) / M_PI * 360.0;
541 fovy = atan2(frustumy, 1) / M_PI * 360.0;
543 return '1 0 0' * fovx + '0 1 0' * fovy;
546 vector GetViewLocationFOV(float fov)
548 float frustumy = tan(fov * M_PI / 360.0) * 0.75;
549 float frustumx = frustumy * vid_width / vid_height / vid_pixelheight;
550 float fovx = atan2(frustumx, 1) / M_PI * 360.0;
551 float fovy = atan2(frustumy, 1) / M_PI * 360.0;
552 return '1 0 0' * fovx + '0 1 0' * fovy;
555 vector GetOrthoviewFOV(vector ov_worldmin, vector ov_worldmax, vector ov_mid, vector ov_org)
558 float width = (ov_worldmax.x - ov_worldmin.x);
559 float height = (ov_worldmax.y - ov_worldmin.y);
560 float distance_to_middle_of_world = vlen(ov_mid - ov_org);
561 fovx = atan2(width/2, distance_to_middle_of_world) / M_PI * 360.0;
562 fovy = atan2(height/2, distance_to_middle_of_world) / M_PI * 360.0;
563 return '1 0 0' * fovx + '0 1 0' * fovy;
566 // this function must match W_SetupShot!
568 bool minigame_wasactive;
571 const float CAMERA_FREE = 1;
572 const float CAMERA_CHASE = 2;
573 string NextFrameCommand;
575 vector freeze_org, freeze_ang;
576 entity nightvision_noise, nightvision_noise2;
578 float myhealth, myhealth_prev;
579 float myhealth_flash;
581 float old_blurradius, old_bluralpha;
582 float old_sharpen_intensity;
584 vector myhealth_gentlergb;
586 float contentavgalpha, liquidalpha_prev;
587 vector liquidcolor_prev;
589 float eventchase_current_distance;
590 float eventchase_running;
591 int WantEventchase(entity this, bool want_vehiclechase)
593 if(autocvar_cl_orthoview)
595 if(STAT(GAME_STOPPED) || intermission)
599 if(spectatee_status >= 0)
601 if(want_vehiclechase)
603 if(MUTATOR_CALLHOOK(WantEventchase, this))
605 if(autocvar_cl_eventchase_frozen && STAT(FROZEN))
607 if(autocvar_cl_eventchase_death && (STAT(HEALTH) <= 0))
609 if(autocvar_cl_eventchase_death == 2)
611 // don't stop eventchase once it's started (even if velocity changes afterwards)
612 if(this.velocity == '0 0 0' || eventchase_running)
617 if (spectatee_status > 0 && autocvar_cl_eventchase_spectated_change)
619 if (time <= spectatee_status_changed_time + min(3, autocvar_cl_eventchase_spectated_change_time))
621 else if (eventchase_running)
622 return -1; // disable chase_active while eventchase is still enabled so to avoid a glicth
628 void View_EventChase(entity this)
630 // event chase camera
631 if(autocvar_chase_active <= 0) // greater than 0 means it's enabled manually, and this code is skipped
633 if(STAT(CAMERA_SPECTATOR))
635 if(spectatee_status > 0)
637 if(!autocvar_chase_active)
639 cvar_set("chase_active", "-2");
643 else if(autocvar_chase_active == -2)
644 cvar_set("chase_active", "0");
646 if(autocvar_chase_active == -2)
649 else if(autocvar_chase_active == -2)
650 cvar_set("chase_active", "0");
652 bool vehicle_chase = (hud != HUD_NORMAL && (autocvar_cl_eventchase_vehicle || spectatee_status > 0));
654 float vehicle_viewdist = 0;
655 vector vehicle_viewofs = '0 0 0';
659 if(hud != HUD_BUMBLEBEE_GUN)
661 Vehicle info = REGISTRY_GET(Vehicles, hud);
662 vehicle_viewdist = info.height;
663 vehicle_viewofs = info.view_ofs;
664 if(vehicle_viewdist < 0) // when set below 0, this vehicle doesn't use third person view (gunner slots)
665 vehicle_chase = false;
668 vehicle_chase = false;
671 int eventchase = WantEventchase(this, vehicle_chase);
674 vector current_view_origin_override = '0 0 0';
675 vector view_offset_override = '0 0 0';
676 float chase_distance_override = 0;
677 bool custom_eventchase = MUTATOR_CALLHOOK(CustomizeEventchase, this);
678 if(custom_eventchase)
680 current_view_origin_override = M_ARGV(0, vector);
681 view_offset_override = M_ARGV(1, vector);
682 chase_distance_override = M_ARGV(0, float);
684 eventchase_running = true;
686 // make special vector since we can't use view_origin (It is one frame old as of this code, it gets set later with the results this code makes.)
687 vector current_view_origin = (csqcplayer ? csqcplayer.origin : pmove_org);
688 if (custom_eventchase)
689 current_view_origin = current_view_origin_override;
691 // detect maximum viewoffset and use it
692 vector view_offset = autocvar_cl_eventchase_viewoffset;
696 view_offset = vehicle_viewofs;
698 view_offset = autocvar_cl_eventchase_vehicle_viewoffset;
700 if (custom_eventchase)
701 view_offset = view_offset_override;
705 WarpZone_TraceLine(current_view_origin, current_view_origin + view_offset + ('0 0 1' * autocvar_cl_eventchase_maxs.z), MOVE_WORLDONLY, this);
706 if(trace_fraction == 1) { current_view_origin += view_offset; }
707 else { current_view_origin.z += max(0, (trace_endpos.z - current_view_origin.z) - autocvar_cl_eventchase_maxs.z); }
710 // We must enable chase_active to get a third person view (weapon viewmodel hidden and own player model showing).
711 // Ideally, there should be another way to enable third person cameras, such as through setproperty()
712 // -1 enables chase_active while marking it as set by this code, and not by the user (which would be 1)
713 if(!autocvar_chase_active) { cvar_set("chase_active", "-1"); }
715 // make the camera smooth back
716 float chase_distance = autocvar_cl_eventchase_distance;
720 chase_distance = vehicle_viewdist;
722 chase_distance = autocvar_cl_eventchase_vehicle_distance;
724 if (custom_eventchase)
725 chase_distance = chase_distance_override;
727 if(autocvar_cl_eventchase_speed && eventchase_current_distance < chase_distance)
728 eventchase_current_distance += autocvar_cl_eventchase_speed * (chase_distance - eventchase_current_distance) * frametime; // slow down the further we get
729 else if(eventchase_current_distance != chase_distance)
730 eventchase_current_distance = chase_distance;
732 vector forward, right, up;
733 MAKE_VECTORS(view_angles, forward, right, up);
735 vector eventchase_target_origin = (current_view_origin - (forward * eventchase_current_distance));
736 WarpZone_TraceBox(current_view_origin, autocvar_cl_eventchase_mins, autocvar_cl_eventchase_maxs, eventchase_target_origin, MOVE_WORLDONLY, this);
738 // If the boxtrace fails, revert back to line tracing.
742 eventchase_target_origin = (current_view_origin - (forward * eventchase_current_distance));
743 WarpZone_TraceLine(current_view_origin, eventchase_target_origin, MOVE_WORLDONLY, this);
744 setproperty(VF_ORIGIN, (trace_endpos - (forward * autocvar_cl_eventchase_mins.z)));
746 else { setproperty(VF_ORIGIN, trace_endpos); }
749 setproperty(VF_ANGLES, WarpZone_TransformVAngles(WarpZone_trace_transform, view_angles));
752 if (eventchase <= 0 && autocvar_chase_active < 0) // time to disable chase_active if it was set by this code
754 eventchase_running = false;
755 cvar_set("chase_active", "0");
756 eventchase_current_distance = 0; // start from 0 next time
759 // workaround for camera stuck between player's legs when using chase_active 1
760 // because the engine stops updating the chase_active camera when the game ends
761 else if(intermission)
763 cvar_settemp("chase_active", "-1");
764 eventchase_current_distance = 0;
768 vector damage_blurpostprocess, content_blurpostprocess;
772 // accumulate damage with each stat update
773 static float damage_total_prev = 0;
774 float damage_total = STAT(DAMAGE_DEALT_TOTAL);
775 float unaccounted_damage_new = COMPARE_INCREASING(damage_total, damage_total_prev);
776 damage_total_prev = damage_total;
778 static float damage_dealt_time_prev = 0;
779 float damage_dealt_time = STAT(HIT_TIME);
780 if (damage_dealt_time != damage_dealt_time_prev)
782 unaccounted_damage += unaccounted_damage_new;
783 //LOG_TRACE("dmg total: ", ftos(unaccounted_damage), " (+", ftos(unaccounted_damage_new), ")");
785 damage_dealt_time_prev = damage_dealt_time;
787 // prevent hitsound when switching spectatee
788 static float spectatee_status_prev = 0;
789 if (spectatee_status != spectatee_status_prev)
790 unaccounted_damage = 0;
791 spectatee_status_prev = spectatee_status;
796 // varying sound pitch
798 bool have_arc = false;
799 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
801 entity wepent = viewmodels[slot];
803 if(wepent.activeweapon == WEP_ARC)
807 static float hitsound_time_prev = 0;
808 // HACK: the only way to get the arc to sound consistent with pitch shift is to ignore cl_hitsound_antispam_time
809 bool arc_hack = have_arc && autocvar_cl_hitsound >= 2;
810 if (arc_hack || COMPARE_INCREASING(time, hitsound_time_prev) > autocvar_cl_hitsound_antispam_time)
812 if (autocvar_cl_hitsound && unaccounted_damage)
814 float pitch_shift = 1;
815 if (autocvar_cl_hitsound == 2 || autocvar_cl_hitsound == 3)
817 // customizable gradient function that crosses (0,a), (c,1) and asymptotically approaches b
818 float a = autocvar_cl_hitsound_max_pitch;
819 float b = autocvar_cl_hitsound_min_pitch;
820 float c = autocvar_cl_hitsound_nom_damage;
821 float d = unaccounted_damage;
822 pitch_shift = (b*d*(a-1) + a*c*(1-b)) / (d*(a-1) + c*(1-b));
824 // if pitch shift is reversed, mirror in (max-min)/2 + min
825 if (autocvar_cl_hitsound == 3)
827 float mirror_value = (a-b)/2 + b;
828 pitch_shift = mirror_value + (mirror_value - pitch_shift);
832 //LOG_TRACE("dmg total (dmg): ", ftos(unaccounted_damage), " , pitch shift: ", ftos(pitch_shift));
834 // todo: avoid very long and very short sounds from wave stretching using different sound files? seems unnecessary
835 // todo: normalize sound pressure levels? seems unnecessary
837 sound7(NULL, CH_INFO, SND(HIT), VOL_BASE, ATTN_NONE, pitch_shift * 100, 0);
839 unaccounted_damage = 0;
840 hitsound_time_prev = time;
843 static float typehit_time_prev = 0;
844 float typehit_time = STAT(TYPEHIT_TIME);
845 if (COMPARE_INCREASING(typehit_time, typehit_time_prev) > autocvar_cl_hitsound_antispam_time)
847 sound(NULL, CH_INFO, SND_TYPEHIT, VOL_BASE, ATTN_NONE);
848 typehit_time_prev = typehit_time;
851 static float kill_time_prev = 0;
852 float kill_time = STAT(KILL_TIME);
853 if (COMPARE_INCREASING(kill_time, kill_time_prev) > autocvar_cl_hitsound_antispam_time)
855 sound(NULL, CH_INFO, SND_KILL, VOL_BASE, ATTN_NONE);
856 kill_time_prev = kill_time;
860 void HUD_Draw(entity this)
862 // if we don't know gametype and scores yet avoid drawing the scoreboard
863 // also in the very first frames, player state may be inconsistent so avoid drawing the hud at all
864 // e.g. since initial player's health is 0 hud would display the hud_damage effect,
865 // cl_deathscoreboard would show the scoreboard and so on
872 if (MUTATOR_CALLHOOK(HUD_Draw_overlay))
874 drawfill('0 0 0', vec2(vid_conwidth, vid_conheight), M_ARGV(0, vector), autocvar_hud_colorflash_alpha * M_ARGV(1, float), DRAWFLAG_ADDITIVE);
876 else if(STAT(FROZEN))
878 vector col = '0.25 0.90 1';
879 float col_fade = max(0, STAT(REVIVE_PROGRESS) * 2 - 1);
880 float alpha_fade = 0.3 + 0.7 * (1 - max(0, STAT(REVIVE_PROGRESS) * 4 - 3));
882 col += vec3(col_fade, -col_fade, -col_fade);
883 drawfill('0 0 0', vec2(vid_conwidth, vid_conheight), col, autocvar_hud_colorflash_alpha * alpha_fade, DRAWFLAG_ADDITIVE);
888 if(STAT(NADE_TIMER) && autocvar_cl_nade_timer) // give nade top priority, as it's a matter of life and death
890 vector col = '0.25 0.90 1' + vec3(STAT(NADE_TIMER), -STAT(NADE_TIMER), -STAT(NADE_TIMER));
891 DrawCircleClippedPic(vec2(0.5 * vid_conwidth, 0.6 * vid_conheight), 0.1 * vid_conheight, "gfx/crosshair_ring", STAT(NADE_TIMER), col, autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
892 drawstring_aspect(eY * 0.64 * vid_conheight, ((autocvar_cl_nade_timer == 2) ? _("Nade timer") : ""), vec2(vid_conwidth, 0.025 * vid_conheight), '1 1 1', 1, DRAWFLAG_NORMAL);
894 else if(STAT(CAPTURE_PROGRESS))
896 DrawCircleClippedPic(vec2(0.5 * vid_conwidth, 0.6 * vid_conheight), 0.1 * vid_conheight, "gfx/crosshair_ring", STAT(CAPTURE_PROGRESS), '0.25 0.90 1', autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
897 drawstring_aspect(eY * 0.64 * vid_conheight, _("Capture progress"), vec2(vid_conwidth, 0.025 * vid_conheight), '1 1 1', 1, DRAWFLAG_NORMAL);
899 else if(STAT(REVIVE_PROGRESS))
901 DrawCircleClippedPic(vec2(0.5 * vid_conwidth, 0.6 * vid_conheight), 0.1 * vid_conheight, "gfx/crosshair_ring", STAT(REVIVE_PROGRESS), '0.25 0.90 1', autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
902 drawstring_aspect(eY * 0.64 * vid_conheight, _("Revival progress"), vec2(vid_conwidth, 0.025 * vid_conheight), '1 1 1', 1, DRAWFLAG_NORMAL);
906 if(autocvar_r_letterbox == 0)
907 if(autocvar_viewsize < 120)
909 if(!MUTATOR_CALLHOOK(DrawScoreboardAccuracy))
910 Accuracy_LoadLevels();
916 // crosshair goes VERY LAST
922 void ViewLocation_Mouse()
925 return; // don't draw it as spectator!
927 viewloc_mousepos += getmousepos() * autocvar_menu_mouse_speed;
928 viewloc_mousepos.x = bound(0, viewloc_mousepos.x, vid_conwidth);
929 viewloc_mousepos.y = bound(0, viewloc_mousepos.y, vid_conheight);
931 //float cursor_alpha = 1 - autocvar__menu_alpha;
932 //cursor_type = CURSOR_NORMAL;
933 //draw_cursor(viewloc_mousepos, '0.5 0.5 0', "/cursor_move", '1 1 1', cursor_alpha);
936 void HUD_Cursor_Show()
938 float cursor_alpha = 1 - autocvar__menu_alpha;
939 if(cursor_type == CURSOR_NORMAL)
940 draw_cursor_normal(mousepos, '1 1 1', cursor_alpha);
941 else if(cursor_type == CURSOR_MOVE)
942 draw_cursor(mousepos, '0.5 0.5 0', "/cursor_move", '1 1 1', cursor_alpha);
943 else if(cursor_type == CURSOR_RESIZE)
944 draw_cursor(mousepos, '0.5 0.5 0', "/cursor_resize", '1 1 1', cursor_alpha);
945 else if(cursor_type == CURSOR_RESIZE2)
946 draw_cursor(mousepos, '0.5 0.5 0', "/cursor_resize2", '1 1 1', cursor_alpha);
949 void HUD_Mouse(entity player)
951 if(autocvar__menu_alpha == 1)
956 if(player.viewloc && (player.viewloc.spawnflags & VIEWLOC_FREEAIM))
957 ViewLocation_Mouse(); // NOTE: doesn't use cursormode
961 if (cursor_active == -1) // starting to display the cursor
963 // since HUD_Mouse is called by CSQC_UpdateView before CSQC_InputEvent,
964 // in the first frame mousepos is the mouse position of the last time
965 // the cursor was displayed, thus we ignore it to avoid a glictch
970 if(!autocvar_hud_cursormode)
973 cursor_type = CURSOR_NORMAL;
974 if(autocvar__hud_configure)
978 if (HUD_MinigameMenu_IsOpened())
979 HUD_Minigame_Mouse();
980 if (QuickMenu_IsOpened())
982 if (HUD_Radar_Clickable())
986 prevMouseClicked = mouseClicked;
991 void View_NightVision()
993 if(!(autocvar_r_fakelight >= 2 || autocvar_r_fullbright) || (serverflags & SERVERFLAG_ALLOW_FULLBRIGHT))
996 // apply night vision effect
997 vector tc_00, tc_01, tc_10, tc_11;
998 vector rgb = '0 0 0';
1001 if(!nightvision_noise)
1003 nightvision_noise = new(nightvision_noise);
1005 if(!nightvision_noise2)
1007 nightvision_noise2 = new(nightvision_noise2);
1010 // color tint in yellow
1011 drawfill('0 0 0', autocvar_vid_conwidth * '1 0 0' + autocvar_vid_conheight * '0 1 0', '0.5 1 0.3', 1, DRAWFLAG_MODULATE);
1014 a = Noise_Pink(nightvision_noise, frametime * 1.5) * 0.05 + 0.15;
1016 tc_00 = '0 0 0' + '0.2 0 0' * sin(time * 0.3) + '0 0.3 0' * cos(time * 0.7);
1017 tc_01 = '0 2.25 0' + '0.6 0 0' * cos(time * 1.2) - '0 0.3 0' * sin(time * 2.2);
1018 tc_10 = '1.5 0 0' - '0.2 0 0' * sin(time * 0.5) + '0 0.5 0' * cos(time * 1.7);
1019 //tc_11 = '1 1 0' + '0.6 0 0' * sin(time * 0.6) + '0 0.3 0' * cos(time * 0.1);
1020 tc_11 = tc_01 + tc_10 - tc_00;
1021 R_BeginPolygon("gfx/nightvision-bg", DRAWFLAG_ADDITIVE, true);
1022 R_PolygonVertex('0 0 0', tc_00, rgb, a);
1023 R_PolygonVertex(autocvar_vid_conwidth * '1 0 0', tc_10, rgb, a);
1024 R_PolygonVertex(autocvar_vid_conwidth * '1 0 0' + autocvar_vid_conheight * '0 1 0', tc_11, rgb, a);
1025 R_PolygonVertex(autocvar_vid_conheight * '0 1 0', tc_01, rgb, a);
1029 a = Noise_Pink(nightvision_noise2, frametime * 0.1) * 0.05 + 0.12;
1030 rgb = '0.3 0.6 0.4' + '0.1 0.4 0.2' * Noise_White(nightvision_noise2, frametime);
1031 tc_00 = '0 0 0' + '1 0 0' * Noise_White(nightvision_noise2, frametime) + '0 1 0' * Noise_White(nightvision_noise2, frametime);
1032 tc_01 = tc_00 + '0 3 0' * (1 + Noise_White(nightvision_noise2, frametime) * 0.2);
1033 tc_10 = tc_00 + '2 0 0' * (1 + Noise_White(nightvision_noise2, frametime) * 0.3);
1034 tc_11 = tc_01 + tc_10 - tc_00;
1035 R_BeginPolygon("gfx/nightvision-fg", DRAWFLAG_ADDITIVE, true);
1036 R_PolygonVertex('0 0 0', tc_00, rgb, a);
1037 R_PolygonVertex(autocvar_vid_conwidth * '1 0 0', tc_10, rgb, a);
1038 R_PolygonVertex(autocvar_vid_conwidth * '1 0 0' + autocvar_vid_conheight * '0 1 0', tc_11, rgb, a);
1039 R_PolygonVertex(autocvar_vid_conheight * '0 1 0', tc_01, rgb, a);
1043 // visual overlay while in liquids
1044 // provides some effects to the postprocessing function
1047 if(!autocvar_hud_contents || MUTATOR_CALLHOOK(HUD_Contents))
1050 // improved polyblend
1051 float contentalpha_temp, incontent, liquidalpha, contentfadetime;
1054 switch(pointcontents(view_origin))
1057 liquidalpha = autocvar_hud_contents_water_alpha;
1058 liquidcolor = stov(autocvar_hud_contents_water_color);
1063 liquidalpha = autocvar_hud_contents_lava_alpha;
1064 liquidcolor = stov(autocvar_hud_contents_lava_color);
1069 liquidalpha = autocvar_hud_contents_slime_alpha;
1070 liquidcolor = stov(autocvar_hud_contents_slime_color);
1076 liquidcolor = '0 0 0';
1081 if(incontent) // fade in/out at different speeds so you can do e.g. instant fade when entering water and slow when leaving it.
1082 { // also lets delcare previous values for blending properties, this way it isn't reset until after you have entered a different content
1083 contentfadetime = autocvar_hud_contents_fadeintime;
1084 liquidalpha_prev = liquidalpha;
1085 liquidcolor_prev = liquidcolor;
1088 contentfadetime = autocvar_hud_contents_fadeouttime;
1090 contentalpha_temp = bound(0, drawframetime / max(0.0001, contentfadetime), 1);
1091 contentavgalpha = contentavgalpha * (1 - contentalpha_temp) + incontent * contentalpha_temp;
1094 drawfill('0 0 0', vec2(vid_conwidth, vid_conheight), liquidcolor_prev, contentavgalpha * liquidalpha_prev, DRAWFLAG_NORMAL);
1096 if(autocvar_hud_postprocessing)
1098 if(autocvar_hud_contents_blur && contentavgalpha)
1100 content_blurpostprocess.x = 1;
1101 content_blurpostprocess.y = contentavgalpha * autocvar_hud_contents_blur;
1102 content_blurpostprocess.z = contentavgalpha * autocvar_hud_contents_blur_alpha;
1106 content_blurpostprocess.x = 0;
1107 content_blurpostprocess.y = 0;
1108 content_blurpostprocess.z = 0;
1113 // visual pain effects on the screen
1114 // provides some effects to the postprocessing function
1117 if(!autocvar_hud_damage || STAT(FROZEN))
1120 vector splash_pos = '0 0 0', splash_size = '0 0 0';
1121 splash_size.x = max(vid_conwidth, vid_conheight);
1122 splash_size.y = max(vid_conwidth, vid_conheight);
1123 splash_pos.x = (vid_conwidth - splash_size.x) / 2;
1124 splash_pos.y = (vid_conheight - splash_size.y) / 2;
1126 float myhealth_flash_temp;
1127 myhealth = STAT(HEALTH);
1130 myhealth_flash = max(0, myhealth_flash - autocvar_hud_damage_fade_rate * frametime);
1132 myhealth_flash = bound(0, myhealth_flash + dmg_take * autocvar_hud_damage_factor, autocvar_hud_damage_maxalpha);
1134 float pain_threshold, pain_threshold_lower, pain_threshold_lower_health;
1135 pain_threshold = autocvar_hud_damage_pain_threshold;
1136 pain_threshold_lower = autocvar_hud_damage_pain_threshold_lower;
1137 pain_threshold_lower_health = autocvar_hud_damage_pain_threshold_lower_health;
1139 if(pain_threshold_lower && myhealth < pain_threshold_lower_health)
1141 pain_threshold = pain_threshold - max(autocvar_hud_damage_pain_threshold_pulsating_min, fabs(sin(M_PI * time / autocvar_hud_damage_pain_threshold_pulsating_period))) * pain_threshold_lower * (1 - max(0, myhealth)/pain_threshold_lower_health);
1144 myhealth_flash_temp = bound(0, myhealth_flash - pain_threshold, 1);
1146 if(myhealth_prev < 1)
1150 myhealth_flash = 0; // just spawned, clear the flash immediately
1151 myhealth_flash_temp = 0;
1155 myhealth_flash += autocvar_hud_damage_fade_rate * frametime; // dead
1159 if(spectatee_status == -1 || intermission)
1161 myhealth_flash = 0; // observing, or match ended
1162 myhealth_flash_temp = 0;
1165 myhealth_prev = myhealth;
1167 // IDEA: change damage color/picture based on player model for robot/alien species?
1168 // pro: matches model better
1169 // contra: it's not red because blood is red, but because red is an alarming color, so red should stay
1170 // maybe different reddish pics?
1171 if(autocvar_cl_gentle_damage || autocvar_cl_gentle)
1173 if(autocvar_cl_gentle_damage == 2)
1175 if(myhealth_flash < pain_threshold) // only randomize when the flash is gone
1176 myhealth_gentlergb = randomvec();
1179 myhealth_gentlergb = stov(autocvar_hud_damage_gentle_color);
1181 if(myhealth_flash_temp > 0)
1182 drawfill('0 0 0', vec2(vid_conwidth, vid_conheight), myhealth_gentlergb, autocvar_hud_damage_gentle_alpha_multiplier * bound(0, myhealth_flash_temp, 1) * autocvar_hud_damage, DRAWFLAG_NORMAL);
1184 else if(myhealth_flash_temp > 0)
1185 drawpic(splash_pos, "gfx/blood", splash_size, stov(autocvar_hud_damage_color), bound(0, myhealth_flash_temp, 1) * autocvar_hud_damage, DRAWFLAG_NORMAL);
1187 if(autocvar_hud_postprocessing) // we still need to set this anyway even when chase_active is set, this way it doesn't get stuck on.
1189 if(autocvar_hud_damage_blur && myhealth_flash_temp)
1191 damage_blurpostprocess.x = 1;
1192 damage_blurpostprocess.y = bound(0, myhealth_flash_temp, 1) * autocvar_hud_damage_blur;
1193 damage_blurpostprocess.z = bound(0, myhealth_flash_temp, 1) * autocvar_hud_damage_blur_alpha;
1197 damage_blurpostprocess.x = 0;
1198 damage_blurpostprocess.y = 0;
1199 damage_blurpostprocess.z = 0;
1204 void View_PostProcessing()
1206 float e1 = (autocvar_hud_postprocessing_maxbluralpha != 0);
1207 float e2 = (autocvar_hud_powerup != 0);
1208 if(autocvar_hud_postprocessing && (e1 || e2)) // TODO: Remove this code and re-do the postprocess handling in the engine, where it properly belongs.
1210 // enable or disable rendering types if they are used or not
1211 if(cvar("r_glsl_postprocess_uservec1_enable") != e1) { cvar_set("r_glsl_postprocess_uservec1_enable", ftos(e1)); }
1212 if(cvar("r_glsl_postprocess_uservec2_enable") != e2) { cvar_set("r_glsl_postprocess_uservec2_enable", ftos(e2)); }
1214 // blur postprocess handling done first (used by hud_damage and hud_contents)
1215 if((damage_blurpostprocess.x || content_blurpostprocess.x))
1217 float blurradius = bound(0, damage_blurpostprocess.y + content_blurpostprocess.y, autocvar_hud_postprocessing_maxblurradius);
1218 float bluralpha = bound(0, damage_blurpostprocess.z + content_blurpostprocess.z, autocvar_hud_postprocessing_maxbluralpha);
1219 if(blurradius != old_blurradius || bluralpha != old_bluralpha) // reduce cvar_set spam as much as possible
1221 cvar_set("r_glsl_postprocess_uservec1", strcat(ftos(blurradius), " ", ftos(bluralpha), " 0 0"));
1222 old_blurradius = blurradius;
1223 old_bluralpha = bluralpha;
1226 else if(cvar_string("r_glsl_postprocess_uservec1") != "0 0 0 0") // reduce cvar_set spam as much as possible
1228 cvar_set("r_glsl_postprocess_uservec1", "0 0 0 0");
1233 // edge detection postprocess handling done second (used by hud_powerup)
1234 float sharpen_intensity = 0;
1235 FOREACH(StatusEffect, it.instanceOfPowerups,
1237 float powerup_finished = StatusEffects_gettime(it, g_statuseffects) - time;
1238 if(powerup_finished > 0)
1239 sharpen_intensity += powerup_finished;
1242 sharpen_intensity = bound(0, ((STAT(HEALTH) > 0) ? sharpen_intensity : 0), 5); // Check to see if player is alive (if not, set 0) - also bound to fade out starting at 5 seconds.
1244 if(autocvar_hud_powerup && sharpen_intensity > 0)
1246 if(sharpen_intensity != old_sharpen_intensity) // reduce cvar_set spam as much as possible
1248 cvar_set("r_glsl_postprocess_uservec2", strcat(ftos((sharpen_intensity / 5) * autocvar_hud_powerup), " ", ftos(-sharpen_intensity * autocvar_hud_powerup), " 0 0"));
1249 old_sharpen_intensity = sharpen_intensity;
1252 else if(cvar_string("r_glsl_postprocess_uservec2") != "0 0 0 0") // reduce cvar_set spam as much as possible
1254 cvar_set("r_glsl_postprocess_uservec2", "0 0 0 0");
1255 old_sharpen_intensity = 0;
1258 if(cvar("r_glsl_postprocess") == 0)
1259 cvar_set("r_glsl_postprocess", "2");
1261 else if(cvar("r_glsl_postprocess") == 2)
1262 cvar_set("r_glsl_postprocess", "0");
1267 int lock_type = autocvar_cl_lockview;
1269 if (!autocvar_hud_cursormode
1270 && ((autocvar__hud_configure && spectatee_status <= 0)
1272 || HUD_Radar_Clickable()
1273 || HUD_MinigameMenu_IsOpened()
1274 || QuickMenu_IsOpened()
1279 // lock_type 1: lock origin and angles
1280 // lock_type 2: lock only origin
1282 setproperty(VF_ORIGIN, freeze_org);
1284 freeze_org = getpropertyvec(VF_ORIGIN);
1286 setproperty(VF_ANGLES, freeze_ang);
1288 freeze_ang = getpropertyvec(VF_ANGLES);
1291 void View_DemoCamera()
1293 if(camera_active) // Camera for demo playback
1295 if(autocvar_camera_enable)
1299 cvar_set("chase_active", ftos(chase_active_backup));
1300 cvar_set("cl_demo_mousegrab", "0");
1301 camera_active = false;
1307 if(autocvar_camera_enable)
1309 if(autocvar_camera_enable && isdemo())
1312 // Enable required Darkplaces cvars
1313 chase_active_backup = autocvar_chase_active;
1314 cvar_set("chase_active", "2");
1315 cvar_set("cl_demo_mousegrab", "1");
1316 camera_active = true;
1317 camera_mode = false;
1323 void View_BlurTest()
1325 if(time > blurtest_time0 && time < blurtest_time1)
1327 float t = (time - blurtest_time0) / (blurtest_time1 - blurtest_time0);
1328 float r = t * blurtest_radius;
1329 float f = 1 / (t ** blurtest_power) - 1;
1331 cvar_set("r_glsl_postprocess", "1");
1332 cvar_set("r_glsl_postprocess_uservec1", strcat(ftos(r), " ", ftos(f), " 0 0"));
1336 cvar_set("r_glsl_postprocess", "0");
1337 cvar_set("r_glsl_postprocess_uservec1", "0 0 0 0");
1342 void View_CheckButtonStatus()
1344 float is_dead = (STAT(HEALTH) <= 0);
1346 // FIXME do we need this hack?
1349 // in demos, input_buttons do not work
1350 button_zoom = (autocvar__togglezoom == "-");
1353 && autocvar_cl_unpress_zoom_on_death
1354 && (spectatee_status >= 0)
1355 && (is_dead || intermission))
1357 // no zoom while dead or in intermission please
1358 localcmd("-zoom\n");
1359 button_zoom = false;
1362 if(autocvar_fov <= 59.5)
1364 if(!zoomscript_caught)
1366 localcmd("+button9\n");
1367 zoomscript_caught = 1;
1372 if(zoomscript_caught)
1374 localcmd("-button9\n");
1375 zoomscript_caught = 0;
1379 if(active_minigame && HUD_MinigameMenu_IsOpened())
1381 if(!minigame_wasactive)
1383 localcmd("+button12\n");
1384 minigame_wasactive = true;
1387 else if(minigame_wasactive)
1389 localcmd("-button12\n");
1390 minigame_wasactive = false;
1393 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1395 entity wepent = viewmodels[slot];
1397 if(wepent.last_switchweapon != wepent.switchweapon)
1400 wepent.last_switchweapon = wepent.switchweapon;
1401 if(slot == 0 && button_zoom && autocvar_cl_unpress_zoom_on_weapon_switch)
1403 localcmd("-zoom\n");
1404 button_zoom = false;
1406 if(slot == 0 && autocvar_cl_unpress_attack_on_weapon_switch)
1408 localcmd("-fire\n");
1409 localcmd("-fire2\n");
1410 button_attack2 = false;
1413 if(wepent.last_activeweapon != wepent.activeweapon)
1415 wepent.last_activeweapon = wepent.activeweapon;
1417 entity e = wepent.activeweapon;
1419 localcmd(strcat("\ncl_hook_activeweapon ", e.netname), "\n");
1421 localcmd("\ncl_hook_activeweapon none\n");
1427 float oldr_nearclip;
1428 float oldr_farclip_base;
1429 float oldr_farclip_world;
1431 float oldr_useportalculling;
1432 float oldr_useinfinitefarclip;
1433 vector ov_org = '0 0 0';
1434 vector ov_mid = '0 0 0';
1435 vector ov_worldmin = '0 0 0';
1436 vector ov_worldmax = '0 0 0';
1442 ov_worldmin = '0 0 0';
1443 ov_worldmax = '0 0 0';
1444 if(autocvar_cl_orthoview)
1446 ov_worldmin = mi_picmin;
1447 ov_worldmax = mi_picmax;
1449 float ov_width = (ov_worldmax.x - ov_worldmin.x);
1450 float ov_height = (ov_worldmax.y - ov_worldmin.y);
1451 float ov_distance = (max(vid_width, vid_height) * max(ov_width, ov_height));
1453 ov_mid = ((ov_worldmax + ov_worldmin) * 0.5);
1454 ov_org = vec3(ov_mid.x, ov_mid.y, (ov_mid.z + ov_distance));
1456 float ov_nearest = vlen(ov_org - vec3(
1457 bound(ov_worldmin.x, ov_org.x, ov_worldmax.x),
1458 bound(ov_worldmin.y, ov_org.y, ov_worldmax.y),
1459 bound(ov_worldmin.z, ov_org.z, ov_worldmax.z)
1462 float ov_furthest = 0;
1465 if((dist = vdist((vec3(ov_worldmin.x, ov_worldmin.y, ov_worldmin.z) - ov_org), >, ov_furthest))) { ov_furthest = dist; }
1466 if((dist = vdist((vec3(ov_worldmax.x, ov_worldmin.y, ov_worldmin.z) - ov_org), >, ov_furthest))) { ov_furthest = dist; }
1467 if((dist = vdist((vec3(ov_worldmin.x, ov_worldmax.y, ov_worldmin.z) - ov_org), >, ov_furthest))) { ov_furthest = dist; }
1468 if((dist = vdist((vec3(ov_worldmin.x, ov_worldmin.y, ov_worldmax.z) - ov_org), >, ov_furthest))) { ov_furthest = dist; }
1469 if((dist = vdist((vec3(ov_worldmax.x, ov_worldmax.y, ov_worldmin.z) - ov_org), >, ov_furthest))) { ov_furthest = dist; }
1470 if((dist = vdist((vec3(ov_worldmin.x, ov_worldmax.y, ov_worldmax.z) - ov_org), >, ov_furthest))) { ov_furthest = dist; }
1471 if((dist = vdist((vec3(ov_worldmax.x, ov_worldmin.y, ov_worldmax.z) - ov_org), >, ov_furthest))) { ov_furthest = dist; }
1472 if((dist = vdist((vec3(ov_worldmax.x, ov_worldmax.y, ov_worldmax.z) - ov_org), >, ov_furthest))) { ov_furthest = dist; }
1476 oldr_nearclip = cvar("r_nearclip");
1477 oldr_farclip_base = cvar("r_farclip_base");
1478 oldr_farclip_world = cvar("r_farclip_world");
1479 oldr_novis = cvar("r_novis");
1480 oldr_useportalculling = cvar("r_useportalculling");
1481 oldr_useinfinitefarclip = cvar("r_useinfinitefarclip");
1484 cvar_settemp("r_nearclip", ftos(ov_nearest));
1485 cvar_settemp("r_farclip_base", ftos(ov_furthest));
1486 cvar_settemp("r_farclip_world", "0");
1487 cvar_settemp("r_novis", "1");
1488 cvar_settemp("r_useportalculling", "0");
1489 cvar_settemp("r_useinfinitefarclip", "0");
1491 setproperty(VF_ORIGIN, ov_org);
1492 setproperty(VF_ANGLES, '90 0 0');
1497 LOG_INFOF("OrthoView: org = %s, angles = %s, distance = %f, nearest = %f, furthest = %f",
1499 vtos(getpropertyvec(VF_ANGLES)),
1509 cvar_set("r_nearclip", ftos(oldr_nearclip));
1510 cvar_set("r_farclip_base", ftos(oldr_farclip_base));
1511 cvar_set("r_farclip_world", ftos(oldr_farclip_world));
1512 cvar_set("r_novis", ftos(oldr_novis));
1513 cvar_set("r_useportalculling", ftos(oldr_useportalculling));
1514 cvar_set("r_useinfinitefarclip", ftos(oldr_useinfinitefarclip));
1520 void View_UpdateFov()
1523 if(autocvar_cl_orthoview)
1524 fov = GetOrthoviewFOV(ov_worldmin, ov_worldmax, ov_mid, ov_org);
1525 else if(csqcplayer.viewloc)
1526 fov = GetViewLocationFOV(110); // enforce 110 fov, so things don't look odd
1528 fov = GetCurrentFov(autocvar_fov);
1530 setproperty(VF_FOV, fov);
1533 void CSQC_UpdateView(entity this, float w, float h)
1535 TC(int, w); TC(int, h);
1537 execute_next_frame();
1544 ReplicateVars(false);
1545 if (ReplicateVars_NOT_SENDING())
1546 ReplicateVars_DELAY(0.8 + random() * 0.4); // no need to check cvars every frame
1548 HUD_Scale_Disable();
1550 if(autocvar__hud_showbinds_reload) // menu can set this one
1553 binddb = db_create();
1554 cvar_set("_hud_showbinds_reload", "0");
1557 if(checkextension("DP_CSQC_MINFPS_QUALITY"))
1558 view_quality = getproperty(VF_MINFPS_QUALITY);
1562 button_attack2 = PHYS_INPUT_BUTTON_ATCK2(this);
1563 button_zoom = PHYS_INPUT_BUTTON_ZOOM(this);
1565 vector vf_size = getpropertyvec(VF_SIZE);
1566 vector vf_min = getpropertyvec(VF_MIN);
1567 vid_width = vf_size.x;
1568 vid_height = vf_size.y;
1570 ticrate = STAT(MOVEVARS_TICRATE) * STAT(MOVEVARS_TIMESCALE);
1572 if (autocvar_chase_active)
1574 // in first person view if r_drawviewmodel is off weapon isn't visible
1575 // and server doesn't throw any casing
1576 // switching to 3rd person view r_drawviewmodel is set to -1 to let know the server casings
1577 // can be thrown for self since own weapon model is visible
1578 if (autocvar_r_drawviewmodel == 0 && STAT(HEALTH) > 0)
1579 cvar_set("r_drawviewmodel", "-1");
1583 if (autocvar_r_drawviewmodel < 0)
1584 cvar_set("r_drawviewmodel", "0");
1587 WaypointSprite_Load();
1589 CSQCPlayer_SetCamera();
1591 if(player_localentnum <= maxclients) // is it a client?
1592 current_player = player_localentnum - 1;
1593 else // then player_localentnum is the vehicle I'm driving
1594 current_player = player_localnum;
1595 myteam = entcs_GetTeam(current_player);
1597 // abused multiple places below
1598 entity local_player = ((csqcplayer) ? csqcplayer : CSQCModel_server2csqc(player_localentnum - 1));
1600 local_player = this; // fall back!
1602 View_EventChase(local_player);
1604 // do lockview after event chase camera so that it still applies whenever necessary.
1608 //WarpZone_FixPMove();
1612 // run viewmodel_draw before updating view_angles to the angles calculated by WarpZone_FixView
1613 // viewmodel_draw needs to use the view_angles set by the engine on every CSQC_UpdateView call
1614 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1615 viewmodel_draw(viewmodels[slot]);
1618 view_origin = getpropertyvec(VF_ORIGIN);
1619 view_angles = getpropertyvec(VF_ANGLES);
1620 MAKE_VECTORS(view_angles, view_forward, view_right, view_up);
1626 TargetMusic_Advance();
1628 fpscounter_update();
1631 drawframetime = 0.01666667; // when we don't know fps yet, we assume 60fps
1633 drawframetime = bound(0.000001, time - drawtime, 1);
1636 // watch for gametype changes here...
1637 // in ParseStuffCMD the cmd isn't executed yet :/
1638 // might even be better to add the gametype to TE_CSQC_INIT...?
1642 if(intermission && !intermission_time)
1643 intermission_time = time;
1645 if(intermission && !isdemo() && !(calledhooks & HOOK_END))
1647 if(calledhooks & HOOK_START)
1649 localcmd("\ncl_hook_gameend\n");
1650 calledhooks |= HOOK_END;
1656 View_CheckButtonStatus();
1658 ColorTranslateMode = autocvar_cl_stripcolorcodes;
1660 // ALWAYS Clear Current Scene First
1663 setproperty(VF_ORIGIN, view_origin);
1664 setproperty(VF_ANGLES, view_angles);
1666 // FIXME engine bug? VF_SIZE and VF_MIN are not restored to sensible values by this
1667 setproperty(VF_SIZE, vf_size);
1668 setproperty(VF_MIN, vf_min);
1670 // Assign Standard Viewflags
1671 // Draw the World (and sky)
1672 setproperty(VF_DRAWWORLD, 1);
1674 // Set the console size vars
1675 vid_conwidth = autocvar_vid_conwidth;
1676 vid_conheight = autocvar_vid_conheight;
1677 vid_pixelheight = autocvar_vid_pixelheight;
1683 // Draw the Crosshair
1684 setproperty(VF_DRAWCROSSHAIR, 0); //Make sure engine crosshairs are always hidden
1686 // Draw the Engine Status Bar (the default Quake HUD)
1687 setproperty(VF_DRAWENGINESBAR, 0);
1689 // Update the mouse position
1691 mousepos_x = vid_conwidth;
1692 mousepos_y = vid_conheight;
1693 mousepos = mousepos*0.5 + getmousepos();
1696 IL_EACH(g_drawables, it.draw, it.draw(it));
1698 addentities(MASK_NORMAL | MASK_ENGINE | MASK_ENGINEVIEWMODELS); // TODO: .health is used in cl_deathfade (a feature we have turned off currently)
1701 // Now the the scene has been rendered, begin with the 2D drawing functions
1704 DrawReticle(local_player);
1707 View_PostProcessing();
1710 IL_EACH(g_drawables_2d, it.draw2d, it.draw2d(it));
1711 Draw_ShowNames_All();
1712 #if ENABLE_DEBUGDRAW
1716 scoreboard_active = Scoreboard_WouldDraw();
1718 HUD_Draw(this); // this parameter for deep vehicle function
1720 if(NextFrameCommand)
1722 localcmd("\n", NextFrameCommand, "\n");
1723 NextFrameCommand = string_null;
1726 // we must do this check AFTER a frame was rendered, or it won't work
1727 if(cs_project_is_b0rked == 0)
1730 w0 = ftos(autocvar_vid_conwidth);
1731 h0 = ftos(autocvar_vid_conheight);
1732 //setproperty(VF_VIEWPORT, '0 0 0', '640 480 0');
1733 //setproperty(VF_FOV, '90 90 0');
1734 setproperty(VF_ORIGIN, '0 0 0');
1735 setproperty(VF_ANGLES, '0 0 0');
1736 setproperty(VF_PERSPECTIVE, 1);
1737 vector forward, right, up;
1738 MAKE_VECTORS('0 0 0', forward, right, up);
1740 cvar_set("vid_conwidth", "800");
1741 cvar_set("vid_conheight", "600");
1742 v1 = cs_project(forward);
1743 cvar_set("vid_conwidth", "640");
1744 cvar_set("vid_conheight", "480");
1745 v2 = cs_project(forward);
1747 cs_project_is_b0rked = 1;
1749 cs_project_is_b0rked = -1;
1750 cvar_set("vid_conwidth", w0);
1751 cvar_set("vid_conheight", h0);
1754 HUD_Mouse(local_player);
1760 // let's reset the view back to normal for the end
1761 setproperty(VF_MIN, '0 0 0');
1762 setproperty(VF_SIZE, '1 0 0' * w + '0 1 0' * h);
1768 // following vectors must be global to allow seamless switching between camera modes
1769 vector camera_offset, current_camera_offset, mouse_angles, current_angles, current_origin, current_position;
1770 void CSQC_Demo_Camera()
1772 float speed, attenuation, dimensions;
1775 if( autocvar_camera_reset || !camera_mode )
1777 camera_offset = '0 0 0';
1778 current_angles = '0 0 0';
1779 camera_direction = '0 0 0';
1780 camera_offset.z += 30;
1781 camera_offset.x += 30 * -cos(current_angles.y * DEG2RAD);
1782 camera_offset.y += 30 * -sin(current_angles.y * DEG2RAD);
1783 current_origin = view_origin;
1784 current_camera_offset = camera_offset;
1785 cvar_set("camera_reset", "0");
1786 camera_mode = CAMERA_CHASE;
1791 mouse_angles.z += camera_roll * autocvar_camera_speed_roll;
1793 if(autocvar_camera_look_player)
1798 dir = normalize(view_origin - current_position);
1800 mouse_angles = vectoangles(dir);
1801 mouse_angles.x = mouse_angles.x * -1;
1806 tmp = getmousepos() * 0.1;
1807 if(vdist(tmp, >, autocvar_camera_mouse_threshold))
1809 mouse_angles.x += tmp.y * cos(mouse_angles.z * DEG2RAD) + (tmp.x * sin(mouse_angles.z * DEG2RAD));
1810 mouse_angles.y -= tmp.x * cos(mouse_angles.z * DEG2RAD) + (tmp.y * -sin(mouse_angles.z * DEG2RAD));
1814 while (mouse_angles.x < -180) mouse_angles.x = mouse_angles.x + 360;
1815 while (mouse_angles.x > 180) mouse_angles.x = mouse_angles.x - 360;
1816 while (mouse_angles.y < -180) mouse_angles.y = mouse_angles.y + 360;
1817 while (mouse_angles.y > 180) mouse_angles.y = mouse_angles.y - 360;
1819 // Fix difference when angles don't have the same sign
1821 if(mouse_angles.y < -60 && current_angles.y > 60)
1823 if(mouse_angles.y > 60 && current_angles.y < -60)
1826 if(autocvar_camera_look_player)
1827 attenuation = autocvar_camera_look_attenuation;
1829 attenuation = autocvar_camera_speed_attenuation;
1831 attenuation = 1 / max(1, attenuation);
1832 current_angles += (mouse_angles - current_angles + delta) * attenuation;
1834 while (current_angles.x < -180) current_angles.x = current_angles.x + 360;
1835 while (current_angles.x > 180) current_angles.x = current_angles.x - 360;
1836 while (current_angles.y < -180) current_angles.y = current_angles.y + 360;
1837 while (current_angles.y > 180) current_angles.y = current_angles.y - 360;
1843 if( camera_direction.x )
1845 tmp.x = camera_direction.x * cos(current_angles.y * DEG2RAD);
1846 tmp.y = camera_direction.x * sin(current_angles.y * DEG2RAD);
1847 if( autocvar_camera_forward_follows && !autocvar_camera_look_player )
1848 tmp.z = camera_direction.x * -sin(current_angles.x * DEG2RAD);
1852 if( camera_direction.y )
1854 tmp.x += camera_direction.y * -sin(current_angles.y * DEG2RAD);
1855 tmp.y += camera_direction.y * cos(current_angles.y * DEG2RAD) * cos(current_angles.z * DEG2RAD);
1856 tmp.z += camera_direction.y * sin(current_angles.z * DEG2RAD);
1860 if( camera_direction.z )
1862 tmp.z += camera_direction.z * cos(current_angles.z * DEG2RAD);
1866 if(autocvar_camera_free)
1867 speed = autocvar_camera_speed_free;
1869 speed = autocvar_camera_speed_chase;
1873 speed = speed * sqrt(1 / dimensions);
1874 camera_offset += tmp * speed;
1877 current_camera_offset += (camera_offset - current_camera_offset) * attenuation;
1880 if( autocvar_camera_free )
1882 if ( camera_mode == CAMERA_CHASE )
1884 current_camera_offset = current_origin + current_camera_offset;
1885 camera_offset = current_origin + camera_offset;
1888 camera_mode = CAMERA_FREE;
1889 current_position = current_camera_offset;
1893 if ( camera_mode == CAMERA_FREE )
1895 current_origin = view_origin;
1896 camera_offset = camera_offset - current_origin;
1897 current_camera_offset = current_camera_offset - current_origin;
1900 camera_mode = CAMERA_CHASE;
1902 if(autocvar_camera_chase_smoothly)
1903 current_origin += (view_origin - current_origin) * attenuation;
1905 current_origin = view_origin;
1907 current_position = current_origin + current_camera_offset;
1910 setproperty(VF_ANGLES, current_angles);
1911 setproperty(VF_ORIGIN, current_position);