]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Share (and compact) some duplicated code in the radar code
authorterencehill <piuntn@gmail.com>
Wed, 16 Dec 2020 14:43:28 +0000 (15:43 +0100)
committerterencehill <piuntn@gmail.com>
Wed, 16 Dec 2020 14:59:59 +0000 (15:59 +0100)
qcsrc/client/hud/panel/radar.qc
qcsrc/client/teamradar.qh

index b87ab97762f1cf15cf103bf9e8bc2c382d60a400..f73d5fa239c4b3ff972a61456c91c1ad6368e390 100644 (file)
@@ -173,6 +173,24 @@ void HUD_Radar_Mouse()
        }
 }
 
+float HUD_Radar_GetZoomFactor(int zoommode)
+{
+       switch(zoommode)
+       {
+               case 1: return 1 - current_zoomfraction;
+               case 2: return 0;
+               case 3: return 1;
+       }
+       return current_zoomfraction;
+}
+
+float HUD_Radar_GetAngle(int rotation)
+{
+       if (rotation)
+               return 90 * rotation;
+       return view_angles.y - 90;
+}
+
 void HUD_Radar()
 {
        if (!autocvar__hud_configure)
@@ -198,7 +216,7 @@ void HUD_Radar()
 
        HUD_Panel_LoadCvars();
 
-       float f = 0;
+       float zoom_factor = 0;
 
        if (hud_panel_radar_maximized && !autocvar__hud_configure)
        {
@@ -216,61 +234,14 @@ void HUD_Radar()
                        radar_panel_modified = true;
                strcpy(panel.current_panel_bg, panel_bg);
 
-               switch(hud_panel_radar_maximized_zoommode)
-               {
-                       default:
-                       case 0:
-                               f = current_zoomfraction;
-                               break;
-                       case 1:
-                               f = 1 - current_zoomfraction;
-                               break;
-                       case 2:
-                               f = 0;
-                               break;
-                       case 3:
-                               f = 1;
-                               break;
-               }
-
-               switch(hud_panel_radar_maximized_rotation)
-               {
-                       case 0:
-                               teamradar_angle = view_angles.y - 90;
-                               break;
-                       default:
-                               teamradar_angle = 90 * hud_panel_radar_maximized_rotation;
-                               break;
-               }
+               zoom_factor = HUD_Radar_GetZoomFactor(hud_panel_radar_maximized_zoommode);
+               teamradar_angle = HUD_Radar_GetAngle(hud_panel_radar_maximized_rotation);
        }
+
        if (!hud_panel_radar_maximized && !autocvar__hud_configure)
        {
-               switch(hud_panel_radar_zoommode)
-               {
-                       default:
-                       case 0:
-                               f = current_zoomfraction;
-                               break;
-                       case 1:
-                               f = 1 - current_zoomfraction;
-                               break;
-                       case 2:
-                               f = 0;
-                               break;
-                       case 3:
-                               f = 1;
-                               break;
-               }
-
-               switch(hud_panel_radar_rotation)
-               {
-                       case 0:
-                               teamradar_angle = view_angles.y - 90;
-                               break;
-                       default:
-                               teamradar_angle = 90 * hud_panel_radar_rotation;
-                               break;
-               }
+               zoom_factor = HUD_Radar_GetZoomFactor(hud_panel_radar_zoommode);
+               teamradar_angle = HUD_Radar_GetAngle(hud_panel_radar_rotation);
        }
 
        vector pos, mySize;
@@ -332,19 +303,10 @@ void HUD_Radar()
        if(bigsize > normalsize)
                normalsize = bigsize;
 
-       teamradar_size =
-                 f * bigsize
-               + (1 - f) * normalsize;
-       teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
-                 f * mi_center
-               + (1 - f) * view_origin);
-
-       drawsetcliparea(
-               pos.x,
-               pos.y,
-               mySize.x,
-               mySize.y
-       );
+       teamradar_size = zoom_factor * bigsize + (1 - zoom_factor) * normalsize;
+       teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(zoom_factor * mi_center + (1 - zoom_factor) * view_origin);
+
+       drawsetcliparea(pos.x, pos.y, mySize.x, mySize.y);
 
        draw_teamradar_background(hud_panel_radar_foreground_alpha);
 
index 41c7d46c564465924e272e585f249db640639b23..8bf54db1bd1f0a92e0a565912c6ae4d5633e5d40 100644 (file)
@@ -19,11 +19,11 @@ float v_flipped;
 
 float hud_panel_radar_scale; // window size = ...qu
 float hud_panel_radar_foreground_alpha;
-float hud_panel_radar_rotation;
+int hud_panel_radar_rotation;
 vector hud_panel_radar_size;
-float hud_panel_radar_zoommode;
-float hud_panel_radar_maximized_zoommode;
-float hud_panel_radar_maximized_rotation;
+int hud_panel_radar_zoommode;
+int hud_panel_radar_maximized_zoommode;
+int hud_panel_radar_maximized_rotation;
 
 
 vector teamradar_2dcoord_to_texcoord(vector in);