option to write floats as ints when possible
omit the ".0" in values like "3.0"
This commit is contained in:
+10
-9
@@ -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); }
|
||||
|
||||
+2
-2
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user