* Fix cv_pointlimit's weird behaviour in match mode by standardising the switching between "named" and "range" values in CV_AddValue.

* Optimise M_ChangeCvar.
This commit is contained in:
toaster 2019-10-15 12:24:31 +01:00
parent 3185a66191
commit aa9bc574da
2 changed files with 38 additions and 30 deletions

View File

@ -1525,6 +1525,9 @@ void CV_AddValue(consvar_t *var, INT32 increment)
{ {
INT32 newvalue, max; INT32 newvalue, max;
if (!increment)
return;
// count pointlimit better // count pointlimit better
if (var == &cv_pointlimit && (gametype == GT_MATCH)) if (var == &cv_pointlimit && (gametype == GT_MATCH))
increment *= 50; 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 // Special case for the nextmap variable, used only directly from the menu
INT32 oldvalue = var->value - 1, gt; INT32 oldvalue = var->value - 1, gt;
gt = cv_newgametype.value; gt = cv_newgametype.value;
if (increment != 0) // Going up!
{ {
newvalue = var->value - 1; newvalue = var->value - 1;
do do
@ -1597,21 +1599,39 @@ void CV_AddValue(consvar_t *var, INT32 increment)
{ {
INT32 currentindice = -1, newindice; INT32 currentindice = -1, newindice;
for (max = MAXVAL+1; var->PossibleValue[max].strvalue; max++) 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; if (var->PossibleValue[max].value == newvalue)
CV_SetValue(var, 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 else
CV_Set(var, var->PossibleValue[newindice].strvalue); CV_Set(var, var->PossibleValue[currentindice].strvalue);
} }
else else
CV_SetValue(var, newvalue); CV_SetValue(var, newvalue);

View File

@ -2788,31 +2788,19 @@ static void M_ChangeCvar(INT32 choice)
choice = (choice<<1) - 1; choice = (choice<<1) - 1;
if (((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_SLIDER) if (cv->flags & CV_FLOAT)
||((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_INVISSLIDER)
||((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_NOMOD))
{ {
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]; char s[20];
sprintf(s,"%f",FIXED_TO_FLOAT(cv->value)+(choice)*(1.0f/16.0f)); sprintf(s,"%f",FIXED_TO_FLOAT(cv->value)+(choice)*(1.0f/16.0f));
CV_Set(cv,s); CV_Set(cv,s);
} }
else 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)); 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 else
CV_AddValue(cv,choice); CV_AddValue(cv,choice);