mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-16 09:04:38 +00:00
Signed values now set/get from the float value. Also add a bool helper.
This commit is contained in:
parent
8a15133a61
commit
98b92360f9
2 changed files with 59 additions and 8 deletions
|
|
@ -1589,6 +1589,10 @@ ConsoleValueRef::ConsoleValueRef(const String &newValue) : value(NULL)
|
||||||
*this = (const char*)(newValue.utf8());
|
*this = (const char*)(newValue.utf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConsoleValueRef::ConsoleValueRef(U32 newValue) : value(NULL)
|
||||||
|
{
|
||||||
|
*this = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
ConsoleValueRef::ConsoleValueRef(S32 newValue) : value(NULL)
|
ConsoleValueRef::ConsoleValueRef(S32 newValue) : value(NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -1645,7 +1649,13 @@ StringStackConsoleWrapper::~StringStackConsoleWrapper()
|
||||||
delete[] argv;
|
delete[] argv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
S32 ConsoleValue::getSignedIntValue()
|
||||||
|
{
|
||||||
|
if(type <= TypeInternalString)
|
||||||
|
return (S32)fval;
|
||||||
|
else
|
||||||
|
return dAtoi(Con::getData(type, dataPtr, 0, enumTable));
|
||||||
|
}
|
||||||
|
|
||||||
U32 ConsoleValue::getIntValue()
|
U32 ConsoleValue::getIntValue()
|
||||||
{
|
{
|
||||||
|
|
@ -1675,6 +1685,25 @@ const char *ConsoleValue::getStringValue()
|
||||||
return Con::getData(type, dataPtr, 0, enumTable);
|
return Con::getData(type, dataPtr, 0, enumTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ConsoleValue::getBoolValue()
|
||||||
|
{
|
||||||
|
if(type == TypeInternalString || type == TypeInternalStackString)
|
||||||
|
return dAtob(sval);
|
||||||
|
if(type == TypeInternalFloat)
|
||||||
|
return fval > 0;
|
||||||
|
else if(type == TypeInternalInt)
|
||||||
|
return ival > 0;
|
||||||
|
else {
|
||||||
|
const char *value = Con::getData(type, dataPtr, 0, enumTable);
|
||||||
|
return dAtob(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleValue::setIntValue(S32 val)
|
||||||
|
{
|
||||||
|
setFloatValue(val);
|
||||||
|
}
|
||||||
|
|
||||||
void ConsoleValue::setIntValue(U32 val)
|
void ConsoleValue::setIntValue(U32 val)
|
||||||
{
|
{
|
||||||
if(type <= TypeInternalString)
|
if(type <= TypeInternalString)
|
||||||
|
|
@ -1695,6 +1724,11 @@ void ConsoleValue::setIntValue(U32 val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConsoleValue::setBoolValue(bool val)
|
||||||
|
{
|
||||||
|
return setIntValue(val ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
void ConsoleValue::setFloatValue(F32 val)
|
void ConsoleValue::setFloatValue(F32 val)
|
||||||
{
|
{
|
||||||
if(type <= TypeInternalString)
|
if(type <= TypeInternalString)
|
||||||
|
|
@ -1748,6 +1782,13 @@ ConsoleValueRef& ConsoleValueRef::operator=(const char *newValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsoleValueRef& ConsoleValueRef::operator=(S32 newValue)
|
ConsoleValueRef& ConsoleValueRef::operator=(S32 newValue)
|
||||||
|
{
|
||||||
|
value = CSTK.pushFLT(newValue);
|
||||||
|
stringStackValue = NULL;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleValueRef& ConsoleValueRef::operator=(U32 newValue)
|
||||||
{
|
{
|
||||||
value = CSTK.pushUINT(newValue);
|
value = CSTK.pushUINT(newValue);
|
||||||
stringStackValue = NULL;
|
stringStackValue = NULL;
|
||||||
|
|
|
||||||
|
|
@ -163,17 +163,17 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
U32 getIntValue();
|
U32 getIntValue();
|
||||||
|
S32 getSignedIntValue();
|
||||||
F32 getFloatValue();
|
F32 getFloatValue();
|
||||||
|
|
||||||
const char *getStringValue();
|
const char *getStringValue();
|
||||||
|
bool getBoolValue();
|
||||||
|
|
||||||
void setIntValue(U32 val);
|
void setIntValue(U32 val);
|
||||||
|
void setIntValue(S32 val);
|
||||||
void setFloatValue(F32 val);
|
void setFloatValue(F32 val);
|
||||||
|
|
||||||
void setStringValue(const char *value);
|
void setStringValue(const char *value);
|
||||||
void setStackStringValue(const char *value);
|
void setStackStringValue(const char *value);
|
||||||
|
void setBoolValue(bool val);
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
|
|
@ -211,6 +211,7 @@ public:
|
||||||
ConsoleValueRef(const ConsoleValueRef &ref);
|
ConsoleValueRef(const ConsoleValueRef &ref);
|
||||||
ConsoleValueRef(const char *value);
|
ConsoleValueRef(const char *value);
|
||||||
ConsoleValueRef(const String &ref);
|
ConsoleValueRef(const String &ref);
|
||||||
|
ConsoleValueRef(U32 value);
|
||||||
ConsoleValueRef(S32 value);
|
ConsoleValueRef(S32 value);
|
||||||
ConsoleValueRef(F32 value);
|
ConsoleValueRef(F32 value);
|
||||||
ConsoleValueRef(F64 value);
|
ConsoleValueRef(F64 value);
|
||||||
|
|
@ -218,12 +219,15 @@ public:
|
||||||
const char *getStringValue() { return value ? value->getStringValue() : ""; }
|
const char *getStringValue() { return value ? value->getStringValue() : ""; }
|
||||||
const char *getStringArgValue();
|
const char *getStringArgValue();
|
||||||
|
|
||||||
inline S32 getIntValue() { return value ? value->getIntValue() : 0; }
|
inline U32 getIntValue() { return value ? value->getIntValue() : 0; }
|
||||||
|
inline S32 getSignedIntValue() { return value ? value->getSignedIntValue() : 0; }
|
||||||
inline F32 getFloatValue() { return value ? value->getFloatValue() : 0.0f; }
|
inline F32 getFloatValue() { return value ? value->getFloatValue() : 0.0f; }
|
||||||
|
inline bool getBoolValue() { return value ? value->getBoolValue() : false; }
|
||||||
|
|
||||||
inline operator const char*() { return getStringValue(); }
|
inline operator const char*() { return getStringValue(); }
|
||||||
inline operator String() { return String(getStringValue()); }
|
inline operator String() { return String(getStringValue()); }
|
||||||
inline operator S32() { return getIntValue(); }
|
inline operator U32() { return getIntValue(); }
|
||||||
|
inline operator S32() { return getSignedIntValue(); }
|
||||||
inline operator F32() { return getFloatValue(); }
|
inline operator F32() { return getFloatValue(); }
|
||||||
|
|
||||||
inline bool isString() { return value ? value->type >= ConsoleValue::TypeInternalStackString : true; }
|
inline bool isString() { return value ? value->type >= ConsoleValue::TypeInternalStackString : true; }
|
||||||
|
|
@ -233,6 +237,7 @@ public:
|
||||||
// Note: operators replace value
|
// Note: operators replace value
|
||||||
ConsoleValueRef& operator=(const ConsoleValueRef &other);
|
ConsoleValueRef& operator=(const ConsoleValueRef &other);
|
||||||
ConsoleValueRef& operator=(const char *newValue);
|
ConsoleValueRef& operator=(const char *newValue);
|
||||||
|
ConsoleValueRef& operator=(U32 newValue);
|
||||||
ConsoleValueRef& operator=(S32 newValue);
|
ConsoleValueRef& operator=(S32 newValue);
|
||||||
ConsoleValueRef& operator=(F32 newValue);
|
ConsoleValueRef& operator=(F32 newValue);
|
||||||
ConsoleValueRef& operator=(F64 newValue);
|
ConsoleValueRef& operator=(F64 newValue);
|
||||||
|
|
@ -242,7 +247,7 @@ public:
|
||||||
|
|
||||||
inline S32 dAtoi(ConsoleValueRef &ref)
|
inline S32 dAtoi(ConsoleValueRef &ref)
|
||||||
{
|
{
|
||||||
return ref.getIntValue();
|
return ref.getSignedIntValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline F32 dAtof(ConsoleValueRef &ref)
|
inline F32 dAtof(ConsoleValueRef &ref)
|
||||||
|
|
@ -250,6 +255,11 @@ inline F32 dAtof(ConsoleValueRef &ref)
|
||||||
return ref.getFloatValue();
|
return ref.getFloatValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool dAtob(ConsoleValue &ref)
|
||||||
|
{
|
||||||
|
return ref.getBoolValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Transparently converts ConsoleValue[] to const char**
|
// Transparently converts ConsoleValue[] to const char**
|
||||||
class StringStackWrapper
|
class StringStackWrapper
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue