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/Value.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/Value.cpp')
-rw-r--r-- | source/gameengine/Expressions/Value.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index a631d58d21a..47f0686c4c3 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -86,20 +86,17 @@ int MyPyCompare (PyObject* v,PyObject* w) int cvalue_coerce(PyObject** pv,PyObject** pw) { if (PyInt_Check(*pw)) { - double db = (double)PyInt_AsLong(*pw); - *pw = new CIntValue((int) db); + *pw = new CIntValue((cInt)PyInt_AsLong(*pw)); Py_INCREF(*pv); return 0; } else if (PyLong_Check(*pw)) { - double db = PyLong_AsDouble(*pw); - *pw = new CFloatValue(db); + *pw = new CIntValue((cInt)PyLong_AsLongLong(*pw)); Py_INCREF(*pv); return 0; } else if (PyFloat_Check(*pw)) { - double db = PyFloat_AsDouble(*pw); - *pw = new CFloatValue(db); + *pw = new CFloatValue((float)PyFloat_AsDouble(*pw)); Py_INCREF(*pv); return 0; } else if (PyString_Check(*pw)) { @@ -108,6 +105,8 @@ int cvalue_coerce(PyObject** pv,PyObject** pw) Py_INCREF(*pv); return 0; } + + PyErr_SetString(PyExc_TypeError, "unable to coerce python type to cvalue"); return 1; /* Can't do it */ } @@ -402,7 +401,7 @@ float CValue::GetPropertyNumber(const STR_String& inName,float defnumber) { CValue *property = GetProperty(inName); if (property) - return property->GetNumber(); + return property->GetNumber(); else return defnumber; } @@ -757,7 +756,11 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj) } else if (PyInt_Check(pyobj)) { - vallie = new CIntValue( (int)PyInt_AS_LONG(pyobj) ); + vallie = new CIntValue( (cInt)PyInt_AS_LONG(pyobj) ); + } else + if (PyLong_Check(pyobj)) + { + vallie = new CIntValue( (cInt)PyLong_AsLongLong(pyobj) ); } else if (PyString_Check(pyobj)) { |