if(!cvar)
{
const char *value;
- char buf[64];
+ char buf[128];
+ int prec[3];
+ float f;
Con_DPrintf("PRVM_LoadProgs: no cvar for autocvar global %s in %s, creating...\n", name, prog->name);
switch(prog->globaldefs[i].type & ~DEF_SAVEGLOBAL)
{
if((float)((int)(val->_float)) == val->_float)
dpsnprintf(buf, sizeof(buf), "%i", (int)(val->_float));
else
- dpsnprintf(buf, sizeof(buf), "%.9g", val->_float);
+ {
+ // ftos_slow
+ f = val->_float;
+ for (int precision = 7; precision <= 9; ++precision) {
+ dpsnprintf(buf, sizeof(buf), "%.*g", precision, f);
+ if ((float)atof(buf) == f) {
+ break;
+ }
+ }
+ }
value = buf;
break;
case ev_vector:
- dpsnprintf(buf, sizeof(buf), "%.9g %.9g %.9g", val->vector[0], val->vector[1], val->vector[2]); value = buf;
+ for (i = 0; i < 3; ++i)
+ {
+ prec[i] = 9;
+ f = val->vector[i];
+ for (int precision = 7; precision <= 9; ++precision) {
+ dpsnprintf(buf, sizeof(buf), "%.*g", precision, f);
+ if ((float)atof(buf) == f) {
+ prec[i] = precision;
+ break;
+ }
+ }
+ }
+ dpsnprintf(buf, sizeof(buf), "%.*g %.*g %.*g", prec[0], val->vector[0], prec[1], val->vector[1], prec[2], val->vector[2]);
+ value = buf;
break;
case ev_string:
value = PRVM_GetString(prog, val->string);