Add FBaseCVar::GetHumanString()

- For most cvars, this is equivalent to calling GetGenericRep() to get a
  string.
- For float cvars, it uses %g instead of %H, because %H is generally more
  information than is needed.
This commit is contained in:
Randy Heit 2016-04-23 22:30:08 -05:00
commit e96ed6bf8d
5 changed files with 24 additions and 9 deletions

View file

@ -132,6 +132,11 @@ FBaseCVar::~FBaseCVar ()
}
}
const char *FBaseCVar::GetHumanString(int precision) const
{
return GetGenericRep(CVAR_String).String;
}
void FBaseCVar::ForceSet (UCVarValue value, ECVarType type, bool nouserinfosend)
{
DoSet (value, type);
@ -750,6 +755,16 @@ ECVarType FFloatCVar::GetRealType () const
return CVAR_Float;
}
const char *FFloatCVar::GetHumanString(int precision) const
{
if (precision < 0)
{
precision = 6;
}
mysnprintf(cstrbuf, countof(cstrbuf), "%.*g", precision, Value);
return cstrbuf;
}
UCVarValue FFloatCVar::GetGenericRep (ECVarType type) const
{
return FromFloat (Value, type);
@ -1675,7 +1690,7 @@ void FBaseCVar::ListVars (const char *filter, bool plain)
if (!(flags & CVAR_UNSETTABLE))
{
++count;
Printf ("%s : %s\n", var->GetName(), var->GetGenericRep(CVAR_String).String);
Printf ("%s : %s\n", var->GetName(), var->GetHumanString());
}
}
else
@ -1692,7 +1707,7 @@ void FBaseCVar::ListVars (const char *filter, bool plain)
flags & CVAR_MOD ? 'M' : ' ',
flags & CVAR_IGNORE ? 'X' : ' ',
var->GetName(),
var->GetGenericRep(CVAR_String).String);
var->GetHumanString());
}
}
var = var->m_Next;