From: terencehill Date: Wed, 16 Dec 2020 14:43:28 +0000 (+0100) Subject: Share (and compact) some duplicated code in the radar code X-Git-Tag: xonotic-v0.8.5~638 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=40511af700f0ad0254054a3f524de4df4fac1783;p=xonotic%2Fxonotic-data.pk3dir.git Share (and compact) some duplicated code in the radar code --- diff --git a/qcsrc/client/hud/panel/radar.qc b/qcsrc/client/hud/panel/radar.qc index b87ab9776..f73d5fa23 100644 --- a/qcsrc/client/hud/panel/radar.qc +++ b/qcsrc/client/hud/panel/radar.qc @@ -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); diff --git a/qcsrc/client/teamradar.qh b/qcsrc/client/teamradar.qh index 41c7d46c5..8bf54db1b 100644 --- a/qcsrc/client/teamradar.qh +++ b/qcsrc/client/teamradar.qh @@ -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);