From: terencehill Date: Sun, 27 Mar 2016 14:10:27 +0000 (+0200) Subject: Remove trailing 0s before saving float numbers into cvars in the menu. Reason: with... X-Git-Tag: xonotic-v0.8.2~970^2~4 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6b7f3c5423ede05f45ee2c8dd2352d0dc62d36f8;p=xonotic%2Fxonotic-data.pk3dir.git Remove trailing 0s before saving float numbers into cvars in the menu. Reason: with a fresh config a few cvars were considered modified because on menu start sliders rewrite the current cvar values adding trailing 0s --- diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 7bc867533..da6574c0a 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -27,8 +27,8 @@ void depthfirst(entity start, .entity up, .entity downleft, .entity right, void( float median(float a, float b, float c); // converts a number to a string with the indicated number of decimals -// works for up to 10 decimals! string ftos_decimals(float number, float decimals); +string ftos_mindecimals(float number); bool fexists(string f); diff --git a/qcsrc/lib/string.qh b/qcsrc/lib/string.qh index 47a8175ca..380afb9ee 100644 --- a/qcsrc/lib/string.qh +++ b/qcsrc/lib/string.qh @@ -281,7 +281,6 @@ void buf_save(float buf, string pFilename) /** * converts a number to a string with the indicated number of decimals - * works for up to 10 decimals! */ string ftos_decimals(float number, int decimals) { @@ -291,6 +290,20 @@ string ftos_decimals(float number, int decimals) return sprintf("%.*f", decimals, number); } +// strips trailing 0s from a float number, e.g. 1.200000 -> 1.2 +string ftos_mindecimals(float number) +{ + string s = ftos(number); + int k = strstrofs(s, ".", 0); + if(k >= 0) + { + int i = strlen(s); + while(substring(s, i - 1, 1) == "0") i--; + s = substring(s, 0, i); + } + return s; +} + int vercmp_recursive(string v1, string v2) { int dot1 = strstrofs(v1, ".", 0); diff --git a/qcsrc/menu/xonotic/checkbox.qc b/qcsrc/menu/xonotic/checkbox.qc index 21743b9a1..6015e48ba 100644 --- a/qcsrc/menu/xonotic/checkbox.qc +++ b/qcsrc/menu/xonotic/checkbox.qc @@ -77,9 +77,9 @@ void XonoticCheckBox_saveCvars(entity me) return; if(me.checked) - cvar_set(me.cvarName, ftos(me.yesValue)); + cvar_set(me.cvarName, ftos_mindecimals(me.yesValue)); else - cvar_set(me.cvarName, ftos(me.noValue)); + cvar_set(me.cvarName, ftos_mindecimals(me.noValue)); CheckSendCvars(me, me.cvarName); } diff --git a/qcsrc/menu/xonotic/slider.qc b/qcsrc/menu/xonotic/slider.qc index fc4228cf9..c8e057a64 100644 --- a/qcsrc/menu/xonotic/slider.qc +++ b/qcsrc/menu/xonotic/slider.qc @@ -58,7 +58,7 @@ void XonoticSlider_saveCvars(entity me) if (!me.cvarName) return; - cvar_set(me.cvarName, ftos(me.value)); + cvar_set(me.cvarName, ftos_mindecimals(me.value)); CheckSendCvars(me, me.cvarName); }