From 4aee746efa3e074730d490ce63a3dcb60aa54cb3 Mon Sep 17 00:00:00 2001 From: Shpoike Date: Wed, 2 Sep 2020 11:51:44 +0100 Subject: [PATCH] Reduce duplicate code a little. --- Quake/common.h | 2 ++ Quake/gl_mesh.c | 2 -- Quake/pr_ext.c | 41 +++++++++++++++-------------------------- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/Quake/common.h b/Quake/common.h index 4b4731df..88c7e75e 100644 --- a/Quake/common.h +++ b/Quake/common.h @@ -47,6 +47,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ((x) < (_minval) ? (_minval) : \ (x) > (_maxval) ? (_maxval) : (x)) +#define countof(x) (sizeof(x)/sizeof((x)[0])) + typedef struct sizebuf_s { qboolean allowoverflow; // if false, do a Sys_Error diff --git a/Quake/gl_mesh.c b/Quake/gl_mesh.c index 06ea77b7..dadb4aa3 100644 --- a/Quake/gl_mesh.c +++ b/Quake/gl_mesh.c @@ -32,8 +32,6 @@ ALIAS MODEL DISPLAY LIST GENERATION ================================================================= */ -#define countof(x) (sizeof(x)/sizeof((x)[0])) - /* ================ GL_MakeAliasModelDisplayLists diff --git a/Quake/pr_ext.c b/Quake/pr_ext.c index ebceaddf..de01e363 100644 --- a/Quake/pr_ext.c +++ b/Quake/pr_ext.c @@ -27,7 +27,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "q_ctype.h" -#define countof(x) (sizeof(x)/sizeof((x)[0])) +static float PR_GetVMScale(void) +{ //sigh, this is horrible (divides glwidth) + float s; + if (qcvm == &cls.menu_qcvm) + { + s = q_min((float)glwidth / 320.0, (float)glheight / 200.0); + s = CLAMP (1.0, scr_menuscale.value, s); + } + else + s = CLAMP (1.0, scr_sbarscale.value, (float)glwidth / 320.0); + return s; +} //there's a few different aproaches to tempstrings... //the lame way is to just have a single one (vanilla). @@ -4856,14 +4867,7 @@ static void PF_cl_stringwidth(void) static void PF_cl_drawsetclip(void) { - float s; - if (qcvm == &cls.menu_qcvm) - { - s = q_min((float)glwidth / 320.0, (float)glheight / 200.0); - s = CLAMP (1.0, scr_menuscale.value, s); - } - else - s = CLAMP (1.0, scr_sbarscale.value, (float)glwidth / 320.0); + float s = PR_GetVMScale(); float x = G_FLOAT(OFS_PARM0)*s; float y = G_FLOAT(OFS_PARM1)*s; @@ -5430,15 +5434,7 @@ static void PF_m_getkeydest(void) } static void PF_m_getmousepos(void) { - float s; - if (qcvm == &cls.menu_qcvm) - { - s = q_min((float)glwidth / 320.0, (float)glheight / 200.0); - s = CLAMP (1.0, scr_menuscale.value, s); - } - else - s = CLAMP (1.0, scr_sbarscale.value, (float)glwidth / 320.0); - + float s = PR_GetVMScale(); G_FLOAT(OFS_RETURN+0) = vid.cursorpos[0]/s; G_FLOAT(OFS_RETURN+1) = vid.cursorpos[1]/s; G_FLOAT(OFS_RETURN+2) = 0; @@ -5947,14 +5943,7 @@ void R_RenderScene (void); float CalcFovy (float fov_x, float width, float height); static void PF_m_renderscene(void) { - float s; - if (qcvm == &cls.menu_qcvm) - { - s = q_min((float)glwidth / 320.0, (float)glheight / 200.0); - s = CLAMP (1.0, scr_menuscale.value, s); - } - else - s = CLAMP (1.0, scr_sbarscale.value, (float)glwidth / 320.0); + float s = PR_GetVMScale(); VectorCopy(viewprops.origin, r_refdef.vieworg); VectorCopy(viewprops.angles, r_refdef.viewangles);