]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/view.qc
cl_lockview 2 allows to control camera angles
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / view.qc
index 66f80ad2c45b878fdafc3a9ea070fde4ef29c2ec..99549a575566077d8d95dc2fccba972ffee49ca3 100644 (file)
@@ -48,7 +48,7 @@
 #define EFMASK_CHEAP (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NODRAW | EF_NOSHADOW | EF_SELECTABLE | EF_TELEPORT_BIT)
 
 float autocvar_cl_viewmodel_scale;
-float autocvar_cl_viewmodel_alpha;
+float autocvar_cl_viewmodel_alpha = 1;
 
 bool autocvar_cl_bobmodel;
 float autocvar_cl_bobmodel_speed;
@@ -486,7 +486,7 @@ vector GetCurrentFov(float fov)
        else
                setsensitivityscale(1);
 
-       if(autocvar_cl_velocityzoom_enabled && autocvar_cl_velocityzoom_type) // _type = 0 disables velocity zoom too
+       if(autocvar_cl_velocityzoom_enabled && autocvar_cl_velocityzoom_type && !autocvar_cl_lockview) // _type = 0 disables velocity zoom too
        {
                if (intermission || (spectatee_status > 0 && STAT(CAMERA_SPECTATOR) == 2))
                        curspeed = 0;
@@ -787,7 +787,7 @@ void View_EventChase(entity this)
                {
                        if(hud != HUD_BUMBLEBEE_GUN)
                        {
-                               Vehicle info = Vehicles_from(hud);
+                               Vehicle info = REGISTRY_GET(Vehicles, hud);
                                vehicle_viewdist = info.height;
                                vehicle_viewofs = info.view_ofs;
                                if(vehicle_viewdist < 0) // when set below 0, this vehicle doesn't use third person view (gunner slots)
@@ -898,7 +898,7 @@ void HUD_Crosshair_Vehicle(entity this)
 {
        if(hud != HUD_BUMBLEBEE_GUN)
        {
-               Vehicle info = Vehicles_from(hud);
+               Vehicle info = REGISTRY_GET(Vehicles, hud);
                info.vr_crosshair(info, this);
        }
 }
@@ -1079,11 +1079,15 @@ LABEL(normalcolor)
 
 void HUD_Crosshair(entity this)
 {
+       // reset player's alpha here upon death since forced scoreboard prevents running the crosshair_chase code
+       if(autocvar_chase_active > 0 && autocvar_crosshair_chase && STAT(HEALTH) <= 0 && csqcplayer)
+               csqcplayer.alpha = csqcplayer.m_alpha;
+
        float f, i, j;
        vector v;
-       if(!scoreboard_active && !camera_active && intermission != 2 && !STAT(GAME_STOPPED) &&
-               spectatee_status != -1 && (!csqcplayer.viewloc || (!spectatee_status && (csqcplayer.viewloc.spawnflags & VIEWLOC_FREEAIM))) && !MUTATOR_CALLHOOK(DrawCrosshair) &&
-               !HUD_MinigameMenu_IsOpened() )
+       if(!scoreboard_active && !camera_active && intermission != 2 && !STAT(GAME_STOPPED) && !autocvar_cl_lockview
+               && spectatee_status != -1 && (!csqcplayer.viewloc || (!spectatee_status && (csqcplayer.viewloc.spawnflags & VIEWLOC_FREEAIM))) && !MUTATOR_CALLHOOK(DrawCrosshair)
+               && !HUD_MinigameMenu_IsOpened())
        {
                if (!autocvar_crosshair_enabled) // main toggle for crosshair rendering
                        return;
@@ -1120,12 +1124,12 @@ void HUD_Crosshair(entity this)
                else if(autocvar_chase_active > 0 && autocvar_crosshair_chase)
                {
                        vector player_org = ((csqcplayer) ? csqcplayer.origin + csqcplayer.view_ofs : view_origin);
-                       if(csqcplayer && crosshair_chase_playeralpha && crosshair_chase_playeralpha < 1)
+                       if(csqcplayer && autocvar_crosshair_chase_playeralpha && autocvar_crosshair_chase_playeralpha < 1)
                        {
                                traceline(view_origin, view_origin + max_shot_distance * view_forward, MOVE_NORMAL, NULL);
                                float myalpha = (!csqcplayer.m_alpha) ? 1 : csqcplayer.m_alpha;
-                               if(trace_ent == csqcplayer && STAT(HEALTH) > 0)
-                                       csqcplayer.alpha = min(crosshair_chase_playeralpha, myalpha);
+                               if(trace_ent == csqcplayer)
+                                       csqcplayer.alpha = min(autocvar_crosshair_chase_playeralpha, myalpha);
                                else
                                        csqcplayer.alpha = csqcplayer.m_alpha;
                        }
@@ -1159,7 +1163,7 @@ void HUD_Crosshair(entity this)
                string wcross_name = "";
                float wcross_scale, wcross_blur;
 
-        entity e = WEP_Null;
+               entity e = WEP_Null;
                if(autocvar_crosshair_per_weapon || (autocvar_crosshair_color_special == 1))
                {
                        entity wepent = viewmodels[0]; // TODO: unhardcode
@@ -1420,10 +1424,10 @@ void HUD_Crosshair(entity this)
                                }
 
                                if (autocvar_crosshair_ring_inner && ring_inner_value) // lets draw a ring inside a ring so you can ring while you ring
-                                       DrawCircleClippedPic(wcross_origin, wcross_size.x * ring_scale, ring_inner_image, ring_inner_value, ring_inner_rgb, wcross_alpha * ring_inner_alpha, DRAWFLAG_ADDITIVE);
+                                       DrawCircleClippedPic(wcross_origin, wcross_size.x * wcross_resolution * ring_scale, ring_inner_image, ring_inner_value, ring_inner_rgb, wcross_alpha * ring_inner_alpha, DRAWFLAG_ADDITIVE);
 
                                if (ring_value)
-                                       DrawCircleClippedPic(wcross_origin, wcross_size.x * ring_scale, ring_image, ring_value, ring_rgb, wcross_alpha * ring_alpha, DRAWFLAG_ADDITIVE);
+                                       DrawCircleClippedPic(wcross_origin, wcross_size.x * wcross_resolution * ring_scale, ring_image, ring_value, ring_rgb, wcross_alpha * ring_alpha, DRAWFLAG_ADDITIVE);
                        }
 
 #define CROSSHAIR_DO_BLUR(M,sz,wcross_name,wcross_alpha) \
@@ -1538,7 +1542,7 @@ void SpecialCommand()
                        {
                                slot.x = bound(0, (random() * vid_conwidth + 1), vid_conwidth);
                                slot.y = 1; // start it off 0 so we can use it
-                               slot.z = floor(random() * Weapons_MAX);
+                               slot.z = floor(random() * REGISTRY_MAX(Weapons));
                                sc_spawntime = time + bound(0.4, random(), 0.75); // prevent spawning another one for this amount of time!
                                vector newcolor = randomvec() * 2;
                                newcolor.x = bound(0.4, newcolor.x, 1);
@@ -1552,7 +1556,7 @@ void SpecialCommand()
                        vector splash_size = '0 0 0';
                        splash_size.x = max(vid_conwidth, vid_conheight) * SPECIALCOMMAND_SIZE;
                        splash_size.y = max(vid_conwidth, vid_conheight) * SPECIALCOMMAND_SIZE;
-                       entity wep = Weapons_from(slot.z);
+                       entity wep = REGISTRY_GET(Weapons, slot.z);
                        if(wep == WEP_Null)
                                drawpic(vec2(slot), "gfx/smile", vec2(splash_size), specialcommand_colors[j], 0.95, DRAWFLAG_NORMAL);
                        else
@@ -1635,6 +1639,7 @@ void ViewLocation_Mouse()
        viewloc_mousepos.y = bound(0, viewloc_mousepos.y, vid_conheight);
 
        //float cursor_alpha = 1 - autocvar__menu_alpha;
+       //cursor_type = CURSOR_NORMAL;
        //draw_cursor(viewloc_mousepos, '0.5 0.5 0', "/cursor_move", '1 1 1', cursor_alpha);
 }
 
@@ -1675,6 +1680,7 @@ void HUD_Mouse(entity player)
        if(!autocvar_hud_cursormode)
                update_mousepos();
 
+       cursor_type = CURSOR_NORMAL;
        if(autocvar__hud_configure)
                HUD_Panel_Mouse();
        else
@@ -1722,7 +1728,7 @@ void View_NightVision()
        tc_10 = '1.5 0 0' - '0.2 0 0' * sin(time * 0.5) + '0 0.5 0' * cos(time * 1.7);
        //tc_11 = '1 1 0' + '0.6 0 0' * sin(time * 0.6) + '0 0.3 0' * cos(time * 0.1);
        tc_11 = tc_01 + tc_10 - tc_00;
-       R_BeginPolygon("gfx/nightvision-bg.tga", DRAWFLAG_ADDITIVE);
+       R_BeginPolygon("gfx/nightvision-bg.tga", DRAWFLAG_ADDITIVE, true);
        R_PolygonVertex('0 0 0', tc_00, rgb, a);
        R_PolygonVertex(autocvar_vid_conwidth * '1 0 0', tc_10, rgb, a);
        R_PolygonVertex(autocvar_vid_conwidth * '1 0 0' + autocvar_vid_conheight * '0 1 0', tc_11, rgb, a);
@@ -1736,7 +1742,7 @@ void View_NightVision()
        tc_01 = tc_00 + '0 3 0' * (1 + Noise_White(nightvision_noise2, frametime) * 0.2);
        tc_10 = tc_00 + '2 0 0' * (1 + Noise_White(nightvision_noise2, frametime) * 0.3);
        tc_11 = tc_01 + tc_10 - tc_00;
-       R_BeginPolygon("gfx/nightvision-fg.tga", DRAWFLAG_ADDITIVE);
+       R_BeginPolygon("gfx/nightvision-fg.tga", DRAWFLAG_ADDITIVE, true);
        R_PolygonVertex('0 0 0', tc_00, rgb, a);
        R_PolygonVertex(autocvar_vid_conwidth * '1 0 0', tc_10, rgb, a);
        R_PolygonVertex(autocvar_vid_conwidth * '1 0 0' + autocvar_vid_conheight * '0 1 0', tc_11, rgb, a);
@@ -2038,16 +2044,20 @@ void View_PostProcessing()
 
 void View_Lock()
 {
-       if(autocvar_cl_lockview || (!autocvar_hud_cursormode && (autocvar__hud_configure && spectatee_status <= 0 || intermission > 1 || QuickMenu_IsOpened())))
-       {
+       int lock_type = (!autocvar_hud_cursormode && (autocvar__hud_configure && spectatee_status <= 0 || intermission > 1 || QuickMenu_IsOpened()));
+       if (lock_type == 0)
+               lock_type = autocvar_cl_lockview;
+
+       // lock_type 1: lock origin and angles
+       // lock_type 2: lock only origin
+       if(lock_type >= 1)
                setproperty(VF_ORIGIN, freeze_org);
-               setproperty(VF_ANGLES, freeze_ang);
-       }
        else
-       {
                freeze_org = getpropertyvec(VF_ORIGIN);
+       if(lock_type == 1)
+               setproperty(VF_ANGLES, freeze_ang);
+       else
                freeze_ang = getpropertyvec(VF_ANGLES);
-       }
 }
 
 void View_DemoCamera()
@@ -2329,6 +2339,8 @@ void CSQC_UpdateView(entity this, float w, float h)
        vid_width = vf_size.x;
        vid_height = vf_size.y;
 
+       ticrate = STAT(MOVEVARS_TICRATE) * STAT(MOVEVARS_TIMESCALE);
+
        WaypointSprite_Load();
 
        CSQCPlayer_SetCamera();
@@ -2339,8 +2351,6 @@ void CSQC_UpdateView(entity this, float w, float h)
                current_player = player_localnum;
        myteam = entcs_GetTeam(current_player);
 
-       ticrate = STAT(MOVEVARS_TICRATE) * STAT(MOVEVARS_TIMESCALE);
-
        // abused multiple places below
        entity local_player = ((csqcplayer) ? csqcplayer : CSQCModel_server2csqc(player_localentnum - 1));
        if(!local_player)
@@ -2445,10 +2455,7 @@ void CSQC_UpdateView(entity this, float w, float h)
        addentities(MASK_NORMAL | MASK_ENGINE | MASK_ENGINEVIEWMODELS); // TODO: .health is used in cl_deathfade (a feature we have turned off currently)
        renderscene();
 
-       // now switch to 2D drawing mode by calling a 2D drawing function
-       // then polygon drawing will draw as 2D stuff, and NOT get queued until the
-       // next R_RenderScene call
-       drawstring('0 0 0', "", '1 1 0', '1 1 1', 0, 0);
+       // Now the the scene has been rendered, begin with the 2D drawing functions
 
        View_NightVision();
        DrawReticle(local_player);