From 98b92360f9a27262a4d0f234d1a730f7f348a740 Mon Sep 17 00:00:00 2001 From: jamesu Date: Fri, 9 Nov 2012 23:00:46 +0000 Subject: [PATCH] Signed values now set/get from the float value. Also add a bool helper. --- Engine/source/console/console.cpp | 43 ++++++++++++++++++++++++++++++- Engine/source/console/console.h | 24 ++++++++++++----- 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/Engine/source/console/console.cpp b/Engine/source/console/console.cpp index 8ef659891..b292fc315 100644 --- a/Engine/source/console/console.cpp +++ b/Engine/source/console/console.cpp @@ -1589,6 +1589,10 @@ ConsoleValueRef::ConsoleValueRef(const String &newValue) : value(NULL) *this = (const char*)(newValue.utf8()); } +ConsoleValueRef::ConsoleValueRef(U32 newValue) : value(NULL) +{ + *this = newValue; +} ConsoleValueRef::ConsoleValueRef(S32 newValue) : value(NULL) { @@ -1645,7 +1649,13 @@ StringStackConsoleWrapper::~StringStackConsoleWrapper() delete[] argv; } - +S32 ConsoleValue::getSignedIntValue() +{ + if(type <= TypeInternalString) + return (S32)fval; + else + return dAtoi(Con::getData(type, dataPtr, 0, enumTable)); +} U32 ConsoleValue::getIntValue() { @@ -1675,6 +1685,25 @@ const char *ConsoleValue::getStringValue() 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) { 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) { if(type <= TypeInternalString) @@ -1748,6 +1782,13 @@ ConsoleValueRef& ConsoleValueRef::operator=(const char *newValue) } ConsoleValueRef& ConsoleValueRef::operator=(S32 newValue) +{ + value = CSTK.pushFLT(newValue); + stringStackValue = NULL; + return *this; +} + +ConsoleValueRef& ConsoleValueRef::operator=(U32 newValue) { value = CSTK.pushUINT(newValue); stringStackValue = NULL; diff --git a/Engine/source/console/console.h b/Engine/source/console/console.h index 2783a048f..edba83ea7 100644 --- a/Engine/source/console/console.h +++ b/Engine/source/console/console.h @@ -163,17 +163,17 @@ public: }; U32 getIntValue(); - + S32 getSignedIntValue(); F32 getFloatValue(); - const char *getStringValue(); + bool getBoolValue(); void setIntValue(U32 val); - + void setIntValue(S32 val); void setFloatValue(F32 val); - void setStringValue(const char *value); void setStackStringValue(const char *value); + void setBoolValue(bool val); void init() { @@ -211,6 +211,7 @@ public: ConsoleValueRef(const ConsoleValueRef &ref); ConsoleValueRef(const char *value); ConsoleValueRef(const String &ref); + ConsoleValueRef(U32 value); ConsoleValueRef(S32 value); ConsoleValueRef(F32 value); ConsoleValueRef(F64 value); @@ -218,12 +219,15 @@ public: const char *getStringValue() { return value ? value->getStringValue() : ""; } 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 bool getBoolValue() { return value ? value->getBoolValue() : false; } inline operator const char*() { return 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 bool isString() { return value ? value->type >= ConsoleValue::TypeInternalStackString : true; } @@ -233,6 +237,7 @@ public: // Note: operators replace value ConsoleValueRef& operator=(const ConsoleValueRef &other); ConsoleValueRef& operator=(const char *newValue); + ConsoleValueRef& operator=(U32 newValue); ConsoleValueRef& operator=(S32 newValue); ConsoleValueRef& operator=(F32 newValue); ConsoleValueRef& operator=(F64 newValue); @@ -242,7 +247,7 @@ public: inline S32 dAtoi(ConsoleValueRef &ref) { - return ref.getIntValue(); + return ref.getSignedIntValue(); } inline F32 dAtof(ConsoleValueRef &ref) @@ -250,6 +255,11 @@ inline F32 dAtof(ConsoleValueRef &ref) return ref.getFloatValue(); } +inline bool dAtob(ConsoleValue &ref) +{ + return ref.getBoolValue(); +} + // Transparently converts ConsoleValue[] to const char** class StringStackWrapper