Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-04-12 10:41:01 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-12 10:41:01 +0400
commit33170295c8a2f3eb815b6086f47147113fd3de13 (patch)
tree4d0b1bcf15da67209c2b3c0f1834f7f63838c9f3 /source/gameengine/Expressions
parent4cd088b1059afa2e7b998c184b2c9deecd4be4a9 (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')
-rw-r--r--source/gameengine/Expressions/BoolValue.cpp4
-rw-r--r--source/gameengine/Expressions/BoolValue.h2
-rw-r--r--source/gameengine/Expressions/ConstExpr.cpp2
-rw-r--r--source/gameengine/Expressions/ConstExpr.h2
-rw-r--r--source/gameengine/Expressions/EmptyValue.cpp2
-rw-r--r--source/gameengine/Expressions/EmptyValue.h2
-rw-r--r--source/gameengine/Expressions/ErrorValue.cpp2
-rw-r--r--source/gameengine/Expressions/ErrorValue.h2
-rw-r--r--source/gameengine/Expressions/FloatValue.cpp4
-rw-r--r--source/gameengine/Expressions/FloatValue.h2
-rw-r--r--source/gameengine/Expressions/InputParser.cpp8
-rw-r--r--source/gameengine/Expressions/InputParser.h2
-rw-r--r--source/gameengine/Expressions/IntValue.cpp21
-rw-r--r--source/gameengine/Expressions/IntValue.h12
-rw-r--r--source/gameengine/Expressions/ListValue.cpp2
-rw-r--r--source/gameengine/Expressions/ListValue.h2
-rw-r--r--source/gameengine/Expressions/StringValue.cpp2
-rw-r--r--source/gameengine/Expressions/StringValue.h2
-rw-r--r--source/gameengine/Expressions/Value.cpp19
-rw-r--r--source/gameengine/Expressions/Value.h2
-rw-r--r--source/gameengine/Expressions/VectorValue.cpp2
-rw-r--r--source/gameengine/Expressions/VectorValue.h2
-rw-r--r--source/gameengine/Expressions/VoidValue.h2
23 files changed, 57 insertions, 45 deletions
diff --git a/source/gameengine/Expressions/BoolValue.cpp b/source/gameengine/Expressions/BoolValue.cpp
index cadb34d7e8f..13c870b68e5 100644
--- a/source/gameengine/Expressions/BoolValue.cpp
+++ b/source/gameengine/Expressions/BoolValue.cpp
@@ -181,9 +181,9 @@ ret: the bool stored in the object
-float CBoolValue::GetNumber()
+double CBoolValue::GetNumber()
{
- return (float)m_bool;
+ return (double)m_bool;
}
diff --git a/source/gameengine/Expressions/BoolValue.h b/source/gameengine/Expressions/BoolValue.h
index 6c4d964249f..9352b9d4b92 100644
--- a/source/gameengine/Expressions/BoolValue.h
+++ b/source/gameengine/Expressions/BoolValue.h
@@ -33,7 +33,7 @@ public:
CBoolValue(bool innie, STR_String name, AllocationTYPE alloctype = CValue::HEAPVALUE);
virtual const STR_String& GetText();
- virtual float GetNumber();
+ virtual double GetNumber();
bool GetBool();
virtual void SetValue(CValue* newval);
diff --git a/source/gameengine/Expressions/ConstExpr.cpp b/source/gameengine/Expressions/ConstExpr.cpp
index e33ba091ac4..6b64be9c9a9 100644
--- a/source/gameengine/Expressions/ConstExpr.cpp
+++ b/source/gameengine/Expressions/ConstExpr.cpp
@@ -84,7 +84,7 @@ void CConstExpr::ClearModified()
-float CConstExpr::GetNumber()
+double CConstExpr::GetNumber()
{
return -1;
}
diff --git a/source/gameengine/Expressions/ConstExpr.h b/source/gameengine/Expressions/ConstExpr.h
index e27ece52a83..b117140fe70 100644
--- a/source/gameengine/Expressions/ConstExpr.h
+++ b/source/gameengine/Expressions/ConstExpr.h
@@ -32,7 +32,7 @@ public:
//bool IsInside(float x,float y,float z,bool bBorderInclude=true);
bool NeedsRecalculated();
void ClearModified();
- virtual float GetNumber();
+ virtual double GetNumber();
virtual CValue* Calculate();
CConstExpr(CValue* constval);
CConstExpr();
diff --git a/source/gameengine/Expressions/EmptyValue.cpp b/source/gameengine/Expressions/EmptyValue.cpp
index c2b60e590a4..f72ddc47096 100644
--- a/source/gameengine/Expressions/EmptyValue.cpp
+++ b/source/gameengine/Expressions/EmptyValue.cpp
@@ -76,7 +76,7 @@ this object
-float CEmptyValue::GetNumber()
+double CEmptyValue::GetNumber()
{
return 0;
}
diff --git a/source/gameengine/Expressions/EmptyValue.h b/source/gameengine/Expressions/EmptyValue.h
index b9cca0e57e5..fb6b4a477a6 100644
--- a/source/gameengine/Expressions/EmptyValue.h
+++ b/source/gameengine/Expressions/EmptyValue.h
@@ -27,7 +27,7 @@ public:
virtual ~CEmptyValue();
virtual const STR_String & GetText();
- virtual float GetNumber();
+ virtual double GetNumber();
CListValue* GetPolySoup();
virtual double* GetVector3(bool bGetTransformedVec=false);
bool IsInside(CValue* testpoint,bool bBorderInclude=true);
diff --git a/source/gameengine/Expressions/ErrorValue.cpp b/source/gameengine/Expressions/ErrorValue.cpp
index e52be4c8021..651a772db19 100644
--- a/source/gameengine/Expressions/ErrorValue.cpp
+++ b/source/gameengine/Expressions/ErrorValue.cpp
@@ -99,7 +99,7 @@ ret: a new object containing the result of applying operator op to val and
-float CErrorValue::GetNumber()
+double CErrorValue::GetNumber()
{
return -1;
}
diff --git a/source/gameengine/Expressions/ErrorValue.h b/source/gameengine/Expressions/ErrorValue.h
index 16e608ca01a..5b5795196ba 100644
--- a/source/gameengine/Expressions/ErrorValue.h
+++ b/source/gameengine/Expressions/ErrorValue.h
@@ -23,7 +23,7 @@ class CErrorValue : public CPropValue
public:
virtual const STR_String & GetText();
- virtual float GetNumber();
+ virtual double GetNumber();
CErrorValue();
CErrorValue(STR_String errmsg);
virtual ~CErrorValue();
diff --git a/source/gameengine/Expressions/FloatValue.cpp b/source/gameengine/Expressions/FloatValue.cpp
index 460eaa73f35..212a55fe457 100644
--- a/source/gameengine/Expressions/FloatValue.cpp
+++ b/source/gameengine/Expressions/FloatValue.cpp
@@ -278,7 +278,7 @@ ret: the float stored in the object
-float CFloatValue::GetNumber()
+double CFloatValue::GetNumber()
{
return m_float;
}
@@ -287,7 +287,7 @@ float CFloatValue::GetNumber()
void CFloatValue::SetValue(CValue* newval)
{
- m_float = newval->GetNumber();
+ m_float = (float)newval->GetNumber();
SetModified(true);
}
diff --git a/source/gameengine/Expressions/FloatValue.h b/source/gameengine/Expressions/FloatValue.h
index 33f05f1d7f2..41f70b5c54c 100644
--- a/source/gameengine/Expressions/FloatValue.h
+++ b/source/gameengine/Expressions/FloatValue.h
@@ -28,7 +28,7 @@ public:
virtual const STR_String & GetText();
void Configure(CValue* menuvalue);
- virtual float GetNumber();
+ virtual double GetNumber();
virtual void SetValue(CValue* newval);
float GetFloat();
void SetFloat(float fl);
diff --git a/source/gameengine/Expressions/InputParser.cpp b/source/gameengine/Expressions/InputParser.cpp
index 94663c4a365..677bbb36d70 100644
--- a/source/gameengine/Expressions/InputParser.cpp
+++ b/source/gameengine/Expressions/InputParser.cpp
@@ -319,12 +319,14 @@ void CParser::NextSym()
}
}
+#if 0
int CParser::MakeInt() {
// returns the integer representation of the value in the global
// variable const_as_string
// pre: const_as_string contains only numercal chars
return atoi(const_as_string);
}
+#endif
STR_String CParser::Symbol2Str(int s) {
// returns a string representation of of symbol s,
@@ -436,8 +438,8 @@ CExpression *CParser::Ex(int i) {
break;
case inttype:
{
- int temp;
- temp = atoi(const_as_string);
+ cInt temp;
+ temp = strtoll(const_as_string, NULL, 10); /* atoi is for int only */
e1 = new CConstExpr(new CIntValue(temp));
break;
}
@@ -580,7 +582,7 @@ float CParser::GetFloat(STR_String txt)
CExpression* expr = ProcessText(txt);
if (expr) {
val = expr->Calculate();
- result=val->GetNumber();
+ result=(float)val->GetNumber();
diff --git a/source/gameengine/Expressions/InputParser.h b/source/gameengine/Expressions/InputParser.h
index f51c473ba18..3d517222639 100644
--- a/source/gameengine/Expressions/InputParser.h
+++ b/source/gameengine/Expressions/InputParser.h
@@ -94,7 +94,9 @@ private:
void CharRep();
void GrabString(int start);
void NextSym();
+#if 0 /* not used yet */
int MakeInt();
+#endif
STR_String Symbol2Str(int s);
void Term(int s);
int Priority(int optor);
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);
}
diff --git a/source/gameengine/Expressions/IntValue.h b/source/gameengine/Expressions/IntValue.h
index 4fdc1089857..0f3a38b274b 100644
--- a/source/gameengine/Expressions/IntValue.h
+++ b/source/gameengine/Expressions/IntValue.h
@@ -18,18 +18,20 @@
#include "Value.h"
+typedef long long cInt;
+
class CIntValue : public CPropValue
{
//PLUGIN_DECLARE_SERIAL (CIntValue,CValue)
public:
virtual const STR_String& GetText();
- virtual float GetNumber();
+ virtual double GetNumber();
- int GetInt();
+ cInt GetInt();
CIntValue();
- CIntValue(int innie);
- CIntValue(int innie,
+ CIntValue(cInt innie);
+ CIntValue(cInt innie,
STR_String name,
AllocationTYPE alloctype=CValue::HEAPVALUE);
@@ -51,7 +53,7 @@ protected:
virtual ~CIntValue();
private:
- int m_int;
+ cInt m_int;
STR_String* m_pstrRep;
};
diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp
index 16b4fbef6b7..0f163ad07c1 100644
--- a/source/gameengine/Expressions/ListValue.cpp
+++ b/source/gameengine/Expressions/ListValue.cpp
@@ -561,7 +561,7 @@ void CListValue::Add(CValue* value)
-float CListValue::GetNumber()
+double CListValue::GetNumber()
{
return -1;
}
diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/ListValue.h
index 6f70acb9367..cf2976c2bbb 100644
--- a/source/gameengine/Expressions/ListValue.h
+++ b/source/gameengine/Expressions/ListValue.h
@@ -36,7 +36,7 @@ public:
virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype,
VALUE_OPERATOR op,
CValue* val);
- virtual float GetNumber();
+ virtual double GetNumber();
virtual CValue* GetReplica();
public:
diff --git a/source/gameengine/Expressions/StringValue.cpp b/source/gameengine/Expressions/StringValue.cpp
index 1ef8c5629a0..2b3c62c411e 100644
--- a/source/gameengine/Expressions/StringValue.cpp
+++ b/source/gameengine/Expressions/StringValue.cpp
@@ -113,7 +113,7 @@ this object
-float CStringValue::GetNumber()
+double CStringValue::GetNumber()
{
return -1;
}
diff --git a/source/gameengine/Expressions/StringValue.h b/source/gameengine/Expressions/StringValue.h
index b824d4ef86d..16575ed7ffa 100644
--- a/source/gameengine/Expressions/StringValue.h
+++ b/source/gameengine/Expressions/StringValue.h
@@ -33,7 +33,7 @@ public:
/// CValue implementation
virtual bool IsEqual(const STR_String & other);
virtual const STR_String & GetText();
- virtual float GetNumber();
+ virtual double GetNumber();
virtual CValue* Calc(VALUE_OPERATOR op, CValue *val);
virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
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))
{
diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h
index 7a2816a9778..4cdc80dc9bd 100644
--- a/source/gameengine/Expressions/Value.h
+++ b/source/gameengine/Expressions/Value.h
@@ -306,7 +306,7 @@ public:
virtual void SetColorOperator(VALUE_OPERATOR op);
virtual const STR_String & GetText() = 0;
- virtual float GetNumber() = 0;
+ virtual double GetNumber() = 0;
double* ZeroVector() { return m_sZeroVec; };
virtual double* GetVector3(bool bGetTransformedVec = false);
diff --git a/source/gameengine/Expressions/VectorValue.cpp b/source/gameengine/Expressions/VectorValue.cpp
index bea6902eba8..497a50b90e7 100644
--- a/source/gameengine/Expressions/VectorValue.cpp
+++ b/source/gameengine/Expressions/VectorValue.cpp
@@ -156,7 +156,7 @@ this object
return ret;
}
-float CVectorValue::GetNumber()
+double CVectorValue::GetNumber()
{
return m_vec[KX_X];
}
diff --git a/source/gameengine/Expressions/VectorValue.h b/source/gameengine/Expressions/VectorValue.h
index 5d9b2a98891..99bf0abb11b 100644
--- a/source/gameengine/Expressions/VectorValue.h
+++ b/source/gameengine/Expressions/VectorValue.h
@@ -32,7 +32,7 @@ public:
void SetVector(double newvec[]);
void Configure(CValue* menuvalue);
virtual double* GetVector3(bool bGetTransformedVec=false);
- virtual float GetNumber();
+ virtual double GetNumber();
CValue* Calc(VALUE_OPERATOR op, CValue *val) {
return val->CalcFinal(VALUE_VECTOR_TYPE, op, this);
diff --git a/source/gameengine/Expressions/VoidValue.h b/source/gameengine/Expressions/VoidValue.h
index 4bde0254787..10a6ff9ad3d 100644
--- a/source/gameengine/Expressions/VoidValue.h
+++ b/source/gameengine/Expressions/VoidValue.h
@@ -47,7 +47,7 @@ public:
/// Value -> String or number
virtual const STR_String & GetText(); // Get string description of void value (unimplemented)
- virtual float GetNumber() { return -1; }
+ virtual double GetNumber() { return -1; }
/// Value calculation
virtual CValue* Calc(VALUE_OPERATOR op, CValue *val);