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.
This commit is contained in:
parent
4cd088b105
commit
33170295c8
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -84,7 +84,7 @@ void CConstExpr::ClearModified()
|
||||
|
||||
|
||||
|
||||
float CConstExpr::GetNumber()
|
||||
double CConstExpr::GetNumber()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -76,7 +76,7 @@ this object
|
||||
|
||||
|
||||
|
||||
float CEmptyValue::GetNumber()
|
||||
double CEmptyValue::GetNumber()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
@ -561,7 +561,7 @@ void CListValue::Add(CValue* value)
|
||||
|
||||
|
||||
|
||||
float CListValue::GetNumber()
|
||||
double CListValue::GetNumber()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -113,7 +113,7 @@ this object
|
||||
|
||||
|
||||
|
||||
float CStringValue::GetNumber()
|
||||
double CStringValue::GetNumber()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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))
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -156,7 +156,7 @@ this object
|
||||
return ret;
|
||||
}
|
||||
|
||||
float CVectorValue::GetNumber()
|
||||
double CVectorValue::GetNumber()
|
||||
{
|
||||
return m_vec[KX_X];
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -109,7 +109,7 @@ void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr)
|
||||
printf(value->GetText());
|
||||
} else
|
||||
{
|
||||
float num = value->GetNumber();
|
||||
float num = (float)value->GetNumber();
|
||||
expressionresult = !MT_fuzzyZero(num);
|
||||
}
|
||||
value->Release();
|
||||
|
@ -123,7 +123,7 @@ const STR_String& SCA_ILogicBrick::GetText()
|
||||
|
||||
|
||||
|
||||
float SCA_ILogicBrick::GetNumber()
|
||||
double SCA_ILogicBrick::GetNumber()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public:
|
||||
virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
|
||||
|
||||
virtual const STR_String & GetText();
|
||||
virtual float GetNumber();
|
||||
virtual double GetNumber();
|
||||
virtual STR_String GetName();
|
||||
virtual void SetName(STR_String name);
|
||||
virtual void ReplicaSetName(STR_String name);
|
||||
|
@ -105,7 +105,7 @@ void SCA_ISensor::SetLevel(bool lvl) {
|
||||
}
|
||||
|
||||
|
||||
float SCA_ISensor::GetNumber() {
|
||||
double SCA_ISensor::GetNumber() {
|
||||
return IsPositiveTrigger();
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ public:
|
||||
virtual void RegisterToManager();
|
||||
virtual void UnregisterToManager();
|
||||
|
||||
virtual float GetNumber();
|
||||
virtual double GetNumber();
|
||||
|
||||
/** Stop sensing for a while. */
|
||||
void Suspend();
|
||||
|
@ -164,7 +164,7 @@ const STR_String & KX_GameObject::GetText()
|
||||
|
||||
|
||||
|
||||
float KX_GameObject::GetNumber()
|
||||
double KX_GameObject::GetNumber()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ public:
|
||||
/**
|
||||
* Inherited from CValue -- does nothing!
|
||||
*/
|
||||
float
|
||||
double
|
||||
GetNumber(
|
||||
);
|
||||
|
||||
|
@ -120,7 +120,7 @@ CValue* KX_MeshProxy::Calc(VALUE_OPERATOR op, CValue *val) { return NULL;}
|
||||
CValue* KX_MeshProxy::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) { return NULL;}
|
||||
|
||||
const STR_String & KX_MeshProxy::GetText() {return m_meshobj->GetName();};
|
||||
float KX_MeshProxy::GetNumber() { return -1;}
|
||||
double KX_MeshProxy::GetNumber() { return -1;}
|
||||
STR_String KX_MeshProxy::GetName() { return m_meshobj->GetName();}
|
||||
void KX_MeshProxy::SetName(STR_String name) { };
|
||||
CValue* KX_MeshProxy::GetReplica() { return NULL;}
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
virtual CValue* Calc(VALUE_OPERATOR op, CValue *val) ;
|
||||
virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
|
||||
virtual const STR_String & GetText();
|
||||
virtual float GetNumber();
|
||||
virtual double GetNumber();
|
||||
virtual RAS_MeshObject* GetMesh() { return m_meshobj; }
|
||||
virtual STR_String GetName();
|
||||
virtual void SetName(STR_String name); // Set the name of the value
|
||||
|
@ -177,7 +177,7 @@ CValue* KX_PolyProxy::Calc(VALUE_OPERATOR, CValue *) { return NULL;}
|
||||
CValue* KX_PolyProxy::CalcFinal(VALUE_DATA_TYPE, VALUE_OPERATOR, CValue *) { return NULL;}
|
||||
STR_String sPolyName="polygone";
|
||||
const STR_String & KX_PolyProxy::GetText() {return sPolyName;};
|
||||
float KX_PolyProxy::GetNumber() { return -1;}
|
||||
double KX_PolyProxy::GetNumber() { return -1;}
|
||||
STR_String KX_PolyProxy::GetName() { return sPolyName;}
|
||||
void KX_PolyProxy::SetName(STR_String) { };
|
||||
CValue* KX_PolyProxy::GetReplica() { return NULL;}
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
CValue* Calc(VALUE_OPERATOR op, CValue *val) ;
|
||||
CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
|
||||
const STR_String & GetText();
|
||||
float GetNumber();
|
||||
double GetNumber();
|
||||
STR_String GetName();
|
||||
void SetName(STR_String name); // Set the name of the value
|
||||
void ReplicaSetName(STR_String name);
|
||||
|
@ -332,7 +332,7 @@ CValue* KX_VertexProxy::Calc(VALUE_OPERATOR, CValue *) { return NULL;}
|
||||
CValue* KX_VertexProxy::CalcFinal(VALUE_DATA_TYPE, VALUE_OPERATOR, CValue *) { return NULL;}
|
||||
STR_String sVertexName="vertex";
|
||||
const STR_String & KX_VertexProxy::GetText() {return sVertexName;};
|
||||
float KX_VertexProxy::GetNumber() { return -1;}
|
||||
double KX_VertexProxy::GetNumber() { return -1;}
|
||||
STR_String KX_VertexProxy::GetName() { return sVertexName;}
|
||||
void KX_VertexProxy::SetName(STR_String) { };
|
||||
CValue* KX_VertexProxy::GetReplica() { return NULL;}
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
CValue* Calc(VALUE_OPERATOR op, CValue *val) ;
|
||||
CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
|
||||
const STR_String & GetText();
|
||||
float GetNumber();
|
||||
double GetNumber();
|
||||
STR_String GetName();
|
||||
void SetName(STR_String name); // Set the name of the value
|
||||
void ReplicaSetName(STR_String name);
|
||||
|
Loading…
Reference in New Issue
Block a user