From aa9bc574da314d21e9f8a854698235dc9c7aab19 Mon Sep 17 00:00:00 2001 From: toaster Date: Tue, 15 Oct 2019 12:24:31 +0100 Subject: [PATCH] * Fix cv_pointlimit's weird behaviour in match mode by standardising the switching between "named" and "range" values in CV_AddValue. * Optimise M_ChangeCvar. --- src/command.c | 46 +++++++++++++++++++++++++++++++++------------- src/m_menu.c | 22 +++++----------------- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/command.c b/src/command.c index 114b37489..b3181bd05 100644 --- a/src/command.c +++ b/src/command.c @@ -1525,6 +1525,9 @@ void CV_AddValue(consvar_t *var, INT32 increment) { INT32 newvalue, max; + if (!increment) + return; + // count pointlimit better if (var == &cv_pointlimit && (gametype == GT_MATCH)) increment *= 50; @@ -1553,7 +1556,6 @@ void CV_AddValue(consvar_t *var, INT32 increment) // Special case for the nextmap variable, used only directly from the menu INT32 oldvalue = var->value - 1, gt; gt = cv_newgametype.value; - if (increment != 0) // Going up! { newvalue = var->value - 1; do @@ -1597,21 +1599,39 @@ void CV_AddValue(consvar_t *var, INT32 increment) { INT32 currentindice = -1, newindice; for (max = MAXVAL+1; var->PossibleValue[max].strvalue; max++) - if (var->PossibleValue[max].value == var->value) - currentindice = max; - - if (currentindice == -1 && max != MAXVAL+1) - newindice = ((increment > 0) ? MAXVAL : max) + increment; - else - newindice = currentindice + increment; - - if (newindice >= max || newindice <= MAXVAL) { - newvalue = var->PossibleValue[((increment > 0) ? MINVAL : MAXVAL)].value; - CV_SetValue(var, newvalue); + if (var->PossibleValue[max].value == newvalue) + { + increment = 0; + currentindice = max; + } + else if (var->PossibleValue[max].value == var->value) + currentindice = max; + } + + if (increment) + { + increment = (increment > 0) ? 1 : -1; + if (currentindice == -1 && max != MAXVAL+1) + newindice = ((increment > 0) ? MAXVAL : max) + increment; + else + newindice = currentindice + increment; + + if (newindice >= max || newindice <= MAXVAL) + { + if (var == &cv_pointlimit && (gametype == GT_MATCH) && increment > 0) + CV_SetValue(var, 50); + else + { + newvalue = var->PossibleValue[((increment > 0) ? MINVAL : MAXVAL)].value; + CV_SetValue(var, newvalue); + } + } + else + CV_Set(var, var->PossibleValue[newindice].strvalue); } else - CV_Set(var, var->PossibleValue[newindice].strvalue); + CV_Set(var, var->PossibleValue[currentindice].strvalue); } else CV_SetValue(var, newvalue); diff --git a/src/m_menu.c b/src/m_menu.c index 66f7cf3ba..1935c76c6 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2788,31 +2788,19 @@ static void M_ChangeCvar(INT32 choice) choice = (choice<<1) - 1; - if (((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_SLIDER) - ||((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_INVISSLIDER) - ||((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_NOMOD)) + if (cv->flags & CV_FLOAT) { - if (cv->flags & CV_FLOAT && (currentMenu->menuitems[itemOn].status & IT_CV_FLOATSLIDER) == IT_CV_FLOATSLIDER) + if (((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_SLIDER) + ||((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_INVISSLIDER) + ||((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_NOMOD) + || !(currentMenu->menuitems[itemOn].status & IT_CV_INTEGERSTEP)) { char s[20]; sprintf(s,"%f",FIXED_TO_FLOAT(cv->value)+(choice)*(1.0f/16.0f)); CV_Set(cv,s); } else - CV_SetValue(cv,cv->value+(choice)); - } - else if (cv->flags & CV_FLOAT) - { - if (currentMenu->menuitems[itemOn].status & IT_CV_INTEGERSTEP) - { CV_SetValue(cv,FIXED_TO_FLOAT(cv->value)+(choice)); - } - else - { - char s[20]; - sprintf(s,"%f",FIXED_TO_FLOAT(cv->value)+(choice)*(1.0f/16.0f)); - CV_Set(cv,s); - } } else CV_AddValue(cv,choice);