diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-04-12 10:41:01 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-04-12 10:41:01 +0400 |
commit | 33170295c8a2f3eb815b6086f47147113fd3de13 (patch) | |
tree | 4d0b1bcf15da67209c2b3c0f1834f7f63838c9f3 /source/gameengine/Expressions/IntValue.cpp | |
parent | 4cd088b1059afa2e7b998c184b2c9deecd4be4a9 (diff) |
use long long rather then int for storing game logic properties.
There were also some problems with int to python conversion
- assigning a PyLong to a KX_GameObject from python would raise an error
- PyLong were coerced into floats when used with internal CValue arithmetic
Changes...
- PyLong is converted into CIntValue for coercing and assigning from python
- CValue's generic GetNumber() function returns a double rather then a float.
- Print an error when a PyType cant be coerced into a CValue
Tested with python, expressions and property sensor.
Diffstat (limited to 'source/gameengine/Expressions/IntValue.cpp')
-rw-r--r-- | source/gameengine/Expressions/IntValue.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/source/gameengine/Expressions/IntValue.cpp b/source/gameengine/Expressions/IntValue.cpp index fb586cb4979..4e86f7bf789 100644 --- a/source/gameengine/Expressions/IntValue.cpp +++ b/source/gameengine/Expressions/IntValue.cpp @@ -42,10 +42,10 @@ effect: constructs a new CIntValue -CIntValue::CIntValue(int innie) +CIntValue::CIntValue(cInt innie) /* pre: -effect: constructs a new CIntValue containing int innie +effect: constructs a new CIntValue containing cInt innie */ { m_int = innie; @@ -54,7 +54,7 @@ effect: constructs a new CIntValue containing int innie -CIntValue::CIntValue(int innie,STR_String name,AllocationTYPE alloctype) +CIntValue::CIntValue(cInt innie,STR_String name,AllocationTYPE alloctype) { m_int = innie; SetName(name); @@ -280,10 +280,10 @@ this object -int CIntValue::GetInt() +cInt CIntValue::GetInt() /* pre: -ret: the int stored in the object +ret: the cInt stored in the object */ { return m_int; @@ -291,7 +291,7 @@ ret: the int stored in the object -float CIntValue::GetNumber() +double CIntValue::GetNumber() { return (float) m_int; } @@ -302,7 +302,7 @@ const STR_String & CIntValue::GetText() { if (!m_pstrRep) m_pstrRep=new STR_String(); - m_pstrRep->Format("%d",m_int); + m_pstrRep->Format("%lld",m_int); return *m_pstrRep; } @@ -321,7 +321,7 @@ CValue* CIntValue::GetReplica() { void CIntValue::SetValue(CValue* newval) { - m_int = (int)newval->GetNumber(); + m_int = (cInt)newval->GetNumber(); SetModified(true); } @@ -329,5 +329,8 @@ void CIntValue::SetValue(CValue* newval) PyObject* CIntValue::ConvertValueToPython() { - return PyInt_FromLong(m_int); + if((m_int > INT_MIN) && (m_int < INT_MAX)) + return PyInt_FromLong(m_int); + else + return PyLong_FromLongLong(m_int); } |