diff --git a/source/src/command.cpp b/source/src/command.cpp index e14efcd9..812c6424 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -491,19 +491,20 @@ void intret(int v) commandret = newstring(t); } -const char *floatstr(float v) +const char *floatstr(float v, bool neat) { - static int n = 0; - static string t[3]; - n = (n + 1)%3; - ftoa(t[n], v); - return t[n]; + static string s; + static int i = 0; + if(i > MAXSTRLEN - 100) i = 0; + char *t = s + i; + snprintf(t, 90, !neat && (v) == int(v) ? "%.1f" : "%.7g", v); // was ftoa() + i += strlen(t) + 1; + return t; } - -void floatret(float v) +void floatret(float v, bool neat) { - commandret = newstring(floatstr(v)); + commandret = newstring(floatstr(v, neat)); } void result(const char *s) { commandret = newstring(s); } diff --git a/source/src/protos.h b/source/src/protos.h index 97db2201..cadcb7c0 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -841,8 +841,8 @@ extern bool exechook(int context, const char *ident, const char *body,...); // extern char *executeret(const char *p); extern char *conc(const char **w, int n, bool space); extern void intret(int v); -extern const char *floatstr(float v); -extern void floatret(float v); +extern const char *floatstr(float v, bool neat = false); +extern void floatret(float v, bool neat = false); extern void result(const char *s); extern void exec(const char *cfgfile); extern bool execfile(const char *cfgfile); diff --git a/source/src/texture.cpp b/source/src/texture.cpp index 420697e2..97deef60 100644 --- a/source/src/texture.cpp +++ b/source/src/texture.cpp @@ -542,8 +542,7 @@ const char *gettextureslot(int i) if(slots.inrange(i)) { Slot &s = slots[i]; - defformatstring(d)("%d", int(s.orgscale)); - formatstring(res)("texture %s \"%s\"", s.orgscale == int(s.orgscale) ? d : floatstr(s.orgscale), s.name); + formatstring(res)("texture %s \"%s\"", floatstr(s.orgscale, true), s.name); return res; } else return NULL; @@ -1071,8 +1070,7 @@ void edittextureslot(int *n, char *scale, char *name) // edit slot parameters != unsavededits++; hdr.flags |= MHF_AUTOMAPCONFIG; // requires automapcfg } - defformatstring(d)("%d", int(s.orgscale)); - formatstring(res)("%s \"%s\"", s.orgscale == int(s.orgscale) ? d : floatstr(s.orgscale), s.name); + formatstring(res)("%s \"%s\"", floatstr(s.orgscale, true), s.name); } result(res); }