Python BGE API

- Initialize python types with PyType_Ready, which adds methods to the type dictionary.
- use Pythons get/setattro (uses a python string for the attribute rather then char*). Using basic C strings seems nice but internally python converts them to python strings and discards them for most functions that accept char arrays.
- Method lookups use the PyTypes dictionary (should be faster then Py_FindMethod)
- Renamed __getattr -> py_base_getattro, _getattr -> py_getattro, __repr -> py_base_repr, py_delattro, py_getattro_self etc.

From here is possible to put all the parent classes methods into each python types dictionary to avoid nested lookups (api has 4 levels of lookups in some places), tested this but its not ready yet.

Simple tests for getting a method within a loop show this to be between 0.5 and 3.2x faster then using Py_FindMethod()
This commit is contained in:
2009-04-03 14:51:06 +00:00
parent e30cb79aaa
commit fd2b115678
128 changed files with 1385 additions and 906 deletions

View File

@@ -965,18 +965,21 @@ KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel,
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
PyTypeObject BL_ActionActuator::Type = { PyTypeObject BL_ActionActuator::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"BL_ActionActuator", "BL_ActionActuator",
sizeof(BL_ActionActuator), sizeof(BL_ActionActuator),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -1032,17 +1035,20 @@ PyAttributeDef BL_ActionActuator::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* BL_ActionActuator::_getattr(const char *attr) { PyObject* BL_ActionActuator::py_getattro(PyObject *attr) {
if (!strcmp(attr, "action")) char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str, "action"))
return PyString_FromString(m_action->id.name+2); return PyString_FromString(m_action->id.name+2);
PyObject* object = _getattr_self(Attributes, this, attr);
PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_IActuator); py_getattro_up(SCA_IActuator);
} }
int BL_ActionActuator::_setattr(const char *attr, PyObject* value) { int BL_ActionActuator::py_setattro(PyObject *attr, PyObject* value) {
if (!strcmp(attr, "action")) char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str, "action"))
{ {
if (!PyString_Check(value)) if (!PyString_Check(value))
{ {
@@ -1072,8 +1078,8 @@ int BL_ActionActuator::_setattr(const char *attr, PyObject* value) {
m_action = action; m_action = action;
return 0; return 0;
} }
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_IActuator::_setattr(attr, value); return SCA_IActuator::py_setattro(attr, value);
} }

View File

@@ -110,8 +110,8 @@ public:
KX_PYMETHOD_DOC(BL_ActionActuator,setChannel); KX_PYMETHOD_DOC(BL_ActionActuator,setChannel);
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject* attr);
virtual int _setattr(const char *attr, PyObject* value); virtual int py_setattro(PyObject* attr, PyObject* value);
/* attribute check */ /* attribute check */
static int CheckFrame(void *self, const PyAttributeDef*) static int CheckFrame(void *self, const PyAttributeDef*)

View File

@@ -420,18 +420,21 @@ bool BL_ShapeActionActuator::Update(double curtime, bool frame)
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject BL_ShapeActionActuator::Type = { PyTypeObject BL_ShapeActionActuator::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"BL_ShapeActionActuator", "BL_ShapeActionActuator",
sizeof(BL_ShapeActionActuator), sizeof(BL_ShapeActionActuator),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr, 0,
__setattr, 0,
0, //&MyPyCompare, 0,
__repr, py_base_repr,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -481,17 +484,19 @@ PyAttributeDef BL_ShapeActionActuator::Attributes[] = {
}; };
PyObject* BL_ShapeActionActuator::_getattr(const char *attr) { PyObject* BL_ShapeActionActuator::py_getattro(PyObject* attr) {
if (!strcmp(attr, "action")) char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str, "action"))
return PyString_FromString(m_action->id.name+2); return PyString_FromString(m_action->id.name+2);
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_IActuator); py_getattro_up(SCA_IActuator);
} }
int BL_ShapeActionActuator::_setattr(const char *attr, PyObject* value) { int BL_ShapeActionActuator::py_setattro(PyObject *attr, PyObject* value) {
if (!strcmp(attr, "action")) char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str, "action"))
{ {
if (!PyString_Check(value)) if (!PyString_Check(value))
{ {
@@ -521,10 +526,10 @@ int BL_ShapeActionActuator::_setattr(const char *attr, PyObject* value) {
m_action = action; m_action = action;
return 0; return 0;
} }
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_IActuator::_setattr(attr, value); return SCA_IActuator::py_setattro(attr, value);
} }
/* setStart */ /* setStart */

View File

@@ -103,8 +103,8 @@ public:
KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetType); KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetType);
KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetType); KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetType);
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject* attr);
virtual int _setattr(const char *attr, PyObject* value); virtual int py_setattro(PyObject* attr, PyObject* value);
static int CheckBlendTime(void *self, const PyAttributeDef*) static int CheckBlendTime(void *self, const PyAttributeDef*)
{ {

View File

@@ -193,7 +193,7 @@ static PyMappingMethods instance_as_mapping = {
PyTypeObject CListValue::Type = { PyTypeObject CListValue::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, /*ob_size*/ 0, /*ob_size*/
"CListValue", /*tp_name*/ "CListValue", /*tp_name*/
sizeof(CListValue), /*tp_basicsize*/ sizeof(CListValue), /*tp_basicsize*/
@@ -201,16 +201,19 @@ PyTypeObject CListValue::Type = {
/* methods */ /* methods */
PyDestructor, /*tp_dealloc*/ PyDestructor, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
__getattr, /*tp_getattr*/ 0, /*tp_getattr*/
__setattr, /*tp_setattr*/ 0, /*tp_setattr*/
0, /*tp_compare*/ 0, /*tp_compare*/
__repr, /*tp_repr*/ py_base_repr, /*tp_repr*/
0, /*tp_as_number*/ 0, /*tp_as_number*/
&listvalue_as_sequence, /*tp_as_sequence*/ &listvalue_as_sequence, /*tp_as_sequence*/
&instance_as_mapping, /*tp_as_mapping*/ &instance_as_mapping, /*tp_as_mapping*/
0, /*tp_hash*/ 0, /*tp_hash*/
0, /*tp_call */ 0, /*tp_call */
0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -238,8 +241,8 @@ PyAttributeDef CListValue::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* CListValue::_getattr(const char *attr) { PyObject* CListValue::py_getattro(PyObject* attr) {
_getattr_up(CValue); py_getattro_up(CValue);
} }

View File

@@ -59,7 +59,7 @@ public:
bool CheckEqual(CValue* first,CValue* second); bool CheckEqual(CValue* first,CValue* second);
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject* attr);
KX_PYMETHOD_O(CListValue,append); KX_PYMETHOD_O(CListValue,append);
KX_PYMETHOD_NOARGS(CListValue,reverse); KX_PYMETHOD_NOARGS(CListValue,reverse);

View File

@@ -55,19 +55,22 @@
------------------------------*/ ------------------------------*/
PyTypeObject PyObjectPlus::Type = { PyTypeObject PyObjectPlus::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, /*ob_size*/ 0, /*ob_size*/
"PyObjectPlus", /*tp_name*/ "PyObjectPlus", /*tp_name*/
sizeof(PyObjectPlus), /*tp_basicsize*/ sizeof(PyObjectPlus), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
/* methods */ /* methods */
PyDestructor, /*tp_dealloc*/ PyDestructor,
0, /*tp_print*/ 0,
__getattr, /*tp_getattr*/ 0,
__setattr, /*tp_setattr*/ 0,
0, /*tp_compare*/ 0,
__repr, py_base_repr,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -103,37 +106,41 @@ PyParentObject PyObjectPlus::Parents[] = {&PyObjectPlus::Type, NULL};
/*------------------------------ /*------------------------------
* PyObjectPlus attributes -- attributes * PyObjectPlus attributes -- attributes
------------------------------*/ ------------------------------*/
PyObject *PyObjectPlus::_getattr(const char *attr) PyObject *PyObjectPlus::py_getattro(PyObject* attr)
{ {
if (!strcmp(attr, "__doc__") && GetType()->tp_doc) PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \
return PyString_FromString(GetType()->tp_doc); if (descr == NULL) {
PyErr_SetString(PyExc_AttributeError, "attribute not found");
return NULL;
} else {
return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \
}
//if (streq(attr, "type")) //if (streq(attr, "type"))
// return Py_BuildValue("s", (*(GetParents()))->tp_name); // return Py_BuildValue("s", (*(GetParents()))->tp_name);
return Py_FindMethod(Methods, this, attr);
} }
int PyObjectPlus::_delattr(const char *attr) int PyObjectPlus::py_delattro(PyObject* attr)
{ {
PyErr_SetString(PyExc_AttributeError, "attribute cant be deleted"); PyErr_SetString(PyExc_AttributeError, "attribute cant be deleted");
return 1; return 1;
} }
int PyObjectPlus::_setattr(const char *attr, PyObject *value) int PyObjectPlus::py_setattro(PyObject *attr, PyObject* value)
{ {
//return PyObject::_setattr(attr,value); //return PyObject::py_setattro(attr,value);
//cerr << "Unknown attribute" << endl; //cerr << "Unknown attribute" << endl;
PyErr_SetString(PyExc_AttributeError, "attribute cant be set"); PyErr_SetString(PyExc_AttributeError, "attribute cant be set");
return 1; return 1;
} }
PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *self, const char *attr) PyObject *PyObjectPlus::py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr)
{ {
char *attr_str= PyString_AsString(attr);
const PyAttributeDef *attrdef; const PyAttributeDef *attrdef;
for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++)
{ {
if (!strcmp(attr, attrdef->m_name)) if (!strcmp(attr_str, attrdef->m_name))
{ {
if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY)
{ {
@@ -242,16 +249,17 @@ PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *sel
return NULL; return NULL;
} }
int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, const char *attr, PyObject *value) int PyObjectPlus::py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value)
{ {
const PyAttributeDef *attrdef; const PyAttributeDef *attrdef;
void *undoBuffer = NULL; void *undoBuffer = NULL;
void *sourceBuffer = NULL; void *sourceBuffer = NULL;
size_t bufferSize = 0; size_t bufferSize = 0;
char *attr_str= PyString_AsString(attr);
for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++)
{ {
if (!strcmp(attr, attrdef->m_name)) if (!strcmp(attr_str, attrdef->m_name))
{ {
if (attrdef->m_access == KX_PYATTRIBUTE_RO || if (attrdef->m_access == KX_PYATTRIBUTE_RO ||
attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY)
@@ -684,7 +692,7 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con
/*------------------------------ /*------------------------------
* PyObjectPlus repr -- representations * PyObjectPlus repr -- representations
------------------------------*/ ------------------------------*/
PyObject *PyObjectPlus::_repr(void) PyObject *PyObjectPlus::py_repr(void)
{ {
PyErr_SetString(PyExc_SystemError, "Representation not overridden by object."); PyErr_SetString(PyExc_SystemError, "Representation not overridden by object.");
return NULL; return NULL;
@@ -726,7 +734,7 @@ PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA
Py_RETURN_FALSE; Py_RETURN_FALSE;
} }
/* Utility function called by the macro _getattr_up() /* Utility function called by the macro py_getattro_up()
* for getting ob.__dict__() values from our PyObject * for getting ob.__dict__() values from our PyObject
* this is used by python for doing dir() on an object, so its good * this is used by python for doing dir() on an object, so its good
* if we return a list of attributes and methods. * if we return a list of attributes and methods.

View File

@@ -72,6 +72,8 @@ typedef int Py_ssize_t;
#define PY_METHODCHAR const char * #define PY_METHODCHAR const char *
#endif #endif
#include "descrobject.h"
static inline void Py_Fatal(const char *M) { static inline void Py_Fatal(const char *M) {
fprintf(stderr, "%s\n", M); fprintf(stderr, "%s\n", M);
exit(-1); exit(-1);
@@ -90,21 +92,27 @@ static inline void Py_Fatal(const char *M) {
// This defines the _getattr_up macro // This defines the py_getattro_up macro
// which allows attribute and method calls // which allows attribute and method calls
// to be properly passed up the hierarchy. // to be properly passed up the hierarchy.
#define _getattr_up(Parent) \
PyObject *rvalue = Py_FindMethod(Methods, this, attr); \ #define py_getattro_up(Parent) \
PyObject *rvalue; \
PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \
\ \
if (rvalue == NULL) { \ if (descr == NULL) { \
PyErr_Clear(); \ PyErr_Clear(); \
rvalue = Parent::_getattr(attr); \ rvalue = Parent::py_getattro(attr); \
} else { \
rvalue= PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \
} \ } \
if (strcmp(attr, "__dict__")==0) {\ \
if (strcmp(PyString_AsString(attr), "__dict__")==0) {\
rvalue = _getattr_dict(rvalue, Methods, Attributes); \ rvalue = _getattr_dict(rvalue, Methods, Attributes); \
} \ } \
return rvalue; \ return rvalue; \
/** /**
* These macros are helpfull when embedding Python routines. The second * These macros are helpfull when embedding Python routines. The second
* macro is one that also requires a documentation string * macro is one that also requires a documentation string
@@ -361,29 +369,29 @@ public:
// Py_DECREF(this); // Py_DECREF(this);
// }; // decref method // }; // decref method
virtual PyObject *_getattr(const char *attr); // _getattr method virtual PyObject *py_getattro(PyObject *attr); // py_getattro method
static PyObject *__getattr(PyObject * PyObj, char *attr) // This should be the entry in Type. static PyObject *py_base_getattro(PyObject * PyObj, PyObject *attr) // This should be the entry in Type.
{ {
return ((PyObjectPlus*) PyObj)->_getattr(attr); return ((PyObjectPlus*) PyObj)->py_getattro(attr);
} }
static PyObject *_getattr_self(const PyAttributeDef attrlist[], void *self, const char *attr); static PyObject *py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr);
static int _setattr_self(const PyAttributeDef attrlist[], void *self, const char *attr, PyObject *value); static int py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value);
virtual int _delattr(const char *attr); virtual int py_delattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); // _setattr method virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method
static int __setattr(PyObject *PyObj, // This should be the entry in Type. static int py_base_setattro(PyObject *PyObj, // This should be the entry in Type.
char *attr, PyObject *attr,
PyObject *value) PyObject *value)
{ {
if (!value) if (value==NULL)
return ((PyObjectPlus*) PyObj)->_delattr(attr); return ((PyObjectPlus*) PyObj)->py_delattro(attr);
return ((PyObjectPlus*) PyObj)->_setattr(attr, value); return ((PyObjectPlus*) PyObj)->py_setattro(attr, value);
} }
virtual PyObject *_repr(void); // _repr method virtual PyObject *py_repr(void); // py_repr method
static PyObject *__repr(PyObject *PyObj) // This should be the entry in Type. static PyObject *py_base_repr(PyObject *PyObj) // This should be the entry in Type.
{ {
return ((PyObjectPlus*) PyObj)->_repr(); return ((PyObjectPlus*) PyObj)->py_repr();
} }
// isA methods // isA methods

View File

@@ -139,19 +139,22 @@ static PyNumberMethods cvalue_as_number = {
PyTypeObject CValue::Type = { PyTypeObject CValue::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"CValue", "CValue",
sizeof(CValue), sizeof(CValue),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr, 0,
__setattr, 0,
&MyPyCompare, &MyPyCompare,
__repr, py_base_repr,
&cvalue_as_number, &cvalue_as_number,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -695,9 +698,10 @@ PyAttributeDef CValue::Attributes[] = {
}; };
PyObject* CValue::_getattr(const char *attr) PyObject* CValue::py_getattro(PyObject *attr)
{ {
CValue* resultattr = GetProperty(attr); char *attr_str= PyString_AsString(attr);
CValue* resultattr = GetProperty(attr_str);
if (resultattr) if (resultattr)
{ {
PyObject* pyconvert = resultattr->ConvertValueToPython(); PyObject* pyconvert = resultattr->ConvertValueToPython();
@@ -707,7 +711,7 @@ PyObject* CValue::_getattr(const char *attr)
else else
return resultattr; // also check if it's already in pythoninterpreter! return resultattr; // also check if it's already in pythoninterpreter!
} }
_getattr_up(PyObjectPlus); py_getattro_up(PyObjectPlus);
} }
CValue* CValue::ConvertPythonToValue(PyObject* pyobj) CValue* CValue::ConvertPythonToValue(PyObject* pyobj)
@@ -769,26 +773,28 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj)
} }
int CValue::_delattr(const char *attr) int CValue::py_delattro(PyObject *attr)
{ {
if (RemoveProperty(STR_String(attr))) char *attr_str= PyString_AsString(attr);
if (RemoveProperty(STR_String(attr_str)))
return 0; return 0;
PyErr_Format(PyExc_AttributeError, "attribute \"%s\" dosnt exist", attr); PyErr_Format(PyExc_AttributeError, "attribute \"%s\" dosnt exist", attr_str);
return 1; return 1;
} }
int CValue::_setattr(const char *attr, PyObject* pyobj) int CValue::py_setattro(PyObject *attr, PyObject* pyobj)
{ {
CValue* vallie = ConvertPythonToValue(pyobj); CValue* vallie = ConvertPythonToValue(pyobj);
if (vallie) if (vallie)
{ {
CValue* oldprop = GetProperty(attr); char *attr_str= PyString_AsString(attr);
CValue* oldprop = GetProperty(attr_str);
if (oldprop) if (oldprop)
oldprop->SetValue(vallie); oldprop->SetValue(vallie);
else else
SetProperty(attr, vallie); SetProperty(attr_str, vallie);
vallie->Release(); vallie->Release();
} else } else
@@ -796,7 +802,7 @@ int CValue::_setattr(const char *attr, PyObject* pyobj)
return 1; /* ConvertPythonToValue sets the error message */ return 1; /* ConvertPythonToValue sets the error message */
} }
//PyObjectPlus::_setattr(attr,value); //PyObjectPlus::py_setattro(attr,value);
return 0; return 0;
}; };

View File

@@ -217,14 +217,14 @@ public:
CValue(PyTypeObject *T = &Type); CValue(PyTypeObject *T = &Type);
//static PyObject* PyMake(PyObject*,PyObject*); //static PyObject* PyMake(PyObject*,PyObject*);
virtual PyObject *_repr(void) virtual PyObject *py_repr(void)
{ {
return Py_BuildValue("s",(const char*)GetText()); return Py_BuildValue("s",(const char*)GetText());
} }
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
void SpecialRelease() void SpecialRelease()
{ {
@@ -251,8 +251,8 @@ public:
virtual CValue* ConvertPythonToValue(PyObject* pyobj); virtual CValue* ConvertPythonToValue(PyObject* pyobj);
virtual int _delattr(const char *attr); virtual int py_delattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject* value); virtual int py_setattro(PyObject *attr, PyObject* value);
virtual PyObject* ConvertKeysToPython( void ); virtual PyObject* ConvertKeysToPython( void );

View File

@@ -80,18 +80,21 @@ bool SCA_2DFilterActuator::Update()
PyTypeObject SCA_2DFilterActuator::Type = { PyTypeObject SCA_2DFilterActuator::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_2DFilterActuator", "SCA_2DFilterActuator",
sizeof(SCA_2DFilterActuator), sizeof(SCA_2DFilterActuator),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr, 0,
__setattr, 0,
0, 0,
__repr, py_base_repr,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -114,6 +117,6 @@ PyAttributeDef SCA_2DFilterActuator::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* SCA_2DFilterActuator::_getattr(const char *attr) { PyObject* SCA_2DFilterActuator::py_getattro(PyObject *attr) {
_getattr_up(SCA_IActuator); py_getattro_up(SCA_IActuator);
} }

View File

@@ -38,7 +38,7 @@ public:
virtual bool Update(); virtual bool Update();
virtual CValue* GetReplica(); virtual CValue* GetReplica();
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
}; };
#endif #endif

View File

@@ -107,18 +107,21 @@ CValue* SCA_ANDController::GetReplica()
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_ANDController::Type = { PyTypeObject SCA_ANDController::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_ANDController", "SCA_ANDController",
sizeof(SCA_ANDController), sizeof(SCA_ANDController),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -138,8 +141,8 @@ PyAttributeDef SCA_ANDController::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* SCA_ANDController::_getattr(const char *attr) { PyObject* SCA_ANDController::py_getattro(PyObject *attr) {
_getattr_up(SCA_IController); py_getattro_up(SCA_IController);
} }
/* eof */ /* eof */

View File

@@ -48,7 +48,7 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
}; };

View File

@@ -122,18 +122,21 @@ void SCA_ActuatorSensor::Update()
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_ActuatorSensor::Type = { PyTypeObject SCA_ActuatorSensor::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_ActuatorSensor", "SCA_ActuatorSensor",
sizeof(SCA_ActuatorSensor), sizeof(SCA_ActuatorSensor),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -158,11 +161,11 @@ PyAttributeDef SCA_ActuatorSensor::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* SCA_ActuatorSensor::_getattr(const char *attr) { PyObject* SCA_ActuatorSensor::py_getattro(PyObject *attr) {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_ISensor); /* implicit return! */ py_getattro_up(SCA_ISensor); /* implicit return! */
} }
int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*) int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*)
@@ -177,11 +180,11 @@ int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*)
return 1; return 1;
} }
int SCA_ActuatorSensor::_setattr(const char *attr, PyObject *value) { int SCA_ActuatorSensor::py_setattro(PyObject *attr, PyObject *value) {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_ISensor::_setattr(attr, value); return SCA_ISensor::py_setattro(attr, value);
} }
/* 3. getActuator */ /* 3. getActuator */

View File

@@ -61,8 +61,8 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
/* 3. setProperty */ /* 3. setProperty */
KX_PYMETHOD_DOC(SCA_ActuatorSensor,SetActuator); KX_PYMETHOD_DOC(SCA_ActuatorSensor,SetActuator);

View File

@@ -105,18 +105,21 @@ bool SCA_AlwaysSensor::Evaluate(CValue* event)
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_AlwaysSensor::Type = { PyTypeObject SCA_AlwaysSensor::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_AlwaysSensor", "SCA_AlwaysSensor",
sizeof(SCA_AlwaysSensor), sizeof(SCA_AlwaysSensor),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr, 0,
__setattr, 0,
0, //&MyPyCompare, 0,
__repr, py_base_repr,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -136,8 +139,8 @@ PyAttributeDef SCA_AlwaysSensor::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* SCA_AlwaysSensor::_getattr(const char *attr) { PyObject* SCA_AlwaysSensor::py_getattro(PyObject *attr) {
_getattr_up(SCA_ISensor); py_getattro_up(SCA_ISensor);
} }
/* eof */ /* eof */

View File

@@ -52,7 +52,7 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
}; };

View File

@@ -131,18 +131,21 @@ bool SCA_DelaySensor::Evaluate(CValue* event)
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_DelaySensor::Type = { PyTypeObject SCA_DelaySensor::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_DelaySensor", "SCA_DelaySensor",
sizeof(SCA_DelaySensor), sizeof(SCA_DelaySensor),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr, 0,
__setattr, 0,
0, //&MyPyCompare, 0,
__repr, py_base_repr,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -175,18 +178,18 @@ PyAttributeDef SCA_DelaySensor::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* SCA_DelaySensor::_getattr(const char *attr) { PyObject* SCA_DelaySensor::py_getattro(PyObject *attr) {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_ISensor); py_getattro_up(SCA_ISensor);
} }
int SCA_DelaySensor::_setattr(const char *attr, PyObject *value) { int SCA_DelaySensor::py_setattro(PyObject *attr, PyObject *value) {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_ISensor::_setattr(attr, value); return SCA_ISensor::py_setattro(attr, value);
} }

View File

@@ -60,8 +60,8 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
/* setProperty */ /* setProperty */
KX_PYMETHOD_DOC(SCA_DelaySensor,SetDelay); KX_PYMETHOD_DOC(SCA_DelaySensor,SetDelay);

View File

@@ -59,7 +59,7 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
// virtual PyObject* _getattr(const char *attr); // virtual PyObject* py_getattro(PyObject *attr);
}; };

View File

@@ -217,18 +217,21 @@ CValue* SCA_ILogicBrick::GetEvent()
/* python stuff */ /* python stuff */
PyTypeObject SCA_ILogicBrick::Type = { PyTypeObject SCA_ILogicBrick::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_ILogicBrick", "SCA_ILogicBrick",
sizeof(SCA_ILogicBrick), sizeof(SCA_ILogicBrick),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr, 0,
__setattr, 0,
0, //&MyPyCompare, 0,
__repr, py_base_repr,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -275,20 +278,20 @@ int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef)
} }
PyObject* PyObject*
SCA_ILogicBrick::_getattr(const char *attr) SCA_ILogicBrick::py_getattro(PyObject *attr)
{ {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(CValue); py_getattro_up(CValue);
} }
int SCA_ILogicBrick::_setattr(const char *attr, PyObject *value) int SCA_ILogicBrick::py_setattro(PyObject *attr, PyObject *value)
{ {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return CValue::_setattr(attr, value); return CValue::py_setattro(attr, value);
} }

View File

@@ -79,8 +79,8 @@ public:
virtual bool LessComparedTo(SCA_ILogicBrick* other); virtual bool LessComparedTo(SCA_ILogicBrick* other);
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
static class SCA_LogicManager* m_sCurrentLogicManager; static class SCA_LogicManager* m_sCurrentLogicManager;

View File

@@ -375,18 +375,21 @@ void SCA_IObject::SetState(unsigned int state)
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_IObject::Type = { PyTypeObject SCA_IObject::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_IObject", "SCA_IObject",
sizeof(SCA_IObject), sizeof(SCA_IObject),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr, 0,
__setattr, 0,
0, //&MyPyCompare, 0,
__repr, py_base_repr,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -411,7 +414,7 @@ PyAttributeDef SCA_IObject::Attributes[] = {
}; };
PyObject* SCA_IObject::_getattr(const char *attr) { PyObject* SCA_IObject::py_getattro(PyObject *attr) {
_getattr_up(CValue); py_getattro_up(CValue);
} }

View File

@@ -145,7 +145,7 @@ public:
// const class MT_Point3& ConvertPythonPylist(PyObject* pylist); // const class MT_Point3& ConvertPythonPylist(PyObject* pylist);
// here come the python forwarded methods // here come the python forwarded methods
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int GetGameObjectType() {return -1;} virtual int GetGameObjectType() {return -1;}

View File

@@ -393,18 +393,21 @@ KX_PYMETHODDEF_DOC_NOARGS(SCA_ISensor, reset,
/* ----------------------------------------------- */ /* ----------------------------------------------- */
PyTypeObject SCA_ISensor::Type = { PyTypeObject SCA_ISensor::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_ISensor", "SCA_ISensor",
sizeof(SCA_ISensor), sizeof(SCA_ISensor),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -451,38 +454,40 @@ PyAttributeDef SCA_ISensor::Attributes[] = {
KX_PYATTRIBUTE_INT_RW("frequency",0,100000,true,SCA_ISensor,m_pulse_frequency), KX_PYATTRIBUTE_INT_RW("frequency",0,100000,true,SCA_ISensor,m_pulse_frequency),
KX_PYATTRIBUTE_BOOL_RW("invert",SCA_ISensor,m_invert), KX_PYATTRIBUTE_BOOL_RW("invert",SCA_ISensor,m_invert),
KX_PYATTRIBUTE_BOOL_RW("level",SCA_ISensor,m_level), KX_PYATTRIBUTE_BOOL_RW("level",SCA_ISensor,m_level),
// make these properties read-only in _setaddr, must still implement them in _getattr // make these properties read-only in _setaddr, must still implement them in py_getattro
KX_PYATTRIBUTE_DUMMY("triggered"), KX_PYATTRIBUTE_DUMMY("triggered"),
KX_PYATTRIBUTE_DUMMY("positive"), KX_PYATTRIBUTE_DUMMY("positive"),
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* PyObject*
SCA_ISensor::_getattr(const char *attr) SCA_ISensor::py_getattro(PyObject *attr)
{ {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
if (!strcmp(attr, "triggered"))
char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str, "triggered"))
{ {
int retval = 0; int retval = 0;
if (SCA_PythonController::m_sCurrentController) if (SCA_PythonController::m_sCurrentController)
retval = SCA_PythonController::m_sCurrentController->IsTriggered(this); retval = SCA_PythonController::m_sCurrentController->IsTriggered(this);
return PyInt_FromLong(retval); return PyInt_FromLong(retval);
} }
if (!strcmp(attr, "positive")) if (!strcmp(attr_str, "positive"))
{ {
int retval = IsPositiveTrigger(); int retval = IsPositiveTrigger();
return PyInt_FromLong(retval); return PyInt_FromLong(retval);
} }
_getattr_up(SCA_ILogicBrick); py_getattro_up(SCA_ILogicBrick);
} }
int SCA_ISensor::_setattr(const char *attr, PyObject *value) int SCA_ISensor::py_setattro(PyObject *attr, PyObject *value)
{ {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_ILogicBrick::_setattr(attr, value); return SCA_ILogicBrick::py_setattro(attr, value);
} }
/* eof */ /* eof */

View File

@@ -136,8 +136,8 @@ public:
/* Python functions: */ /* Python functions: */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
//Deprecated functions -----> //Deprecated functions ----->
KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,IsPositive); KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,IsPositive);

View File

@@ -275,18 +275,21 @@ bool SCA_JoystickSensor::isValid(SCA_JoystickSensor::KX_JOYSENSORMODE m)
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_JoystickSensor::Type = { PyTypeObject SCA_JoystickSensor::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_JoystickSensor", "SCA_JoystickSensor",
sizeof(SCA_JoystickSensor), sizeof(SCA_JoystickSensor),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr, 0,
__setattr, 0,
0, //&MyPyCompare, 0,
__repr, py_base_repr,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -330,8 +333,8 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = {
KX_PYATTRIBUTE_INT_RW("button",0,100,false,SCA_JoystickSensor,m_button), KX_PYATTRIBUTE_INT_RW("button",0,100,false,SCA_JoystickSensor,m_button),
KX_PYATTRIBUTE_INT_LIST_RW_CHECK("axis",0,3,true,SCA_JoystickSensor,m_axis,2,CheckAxis), KX_PYATTRIBUTE_INT_LIST_RW_CHECK("axis",0,3,true,SCA_JoystickSensor,m_axis,2,CheckAxis),
KX_PYATTRIBUTE_INT_LIST_RW_CHECK("hat",0,12,true,SCA_JoystickSensor,m_hat,2,CheckHat), KX_PYATTRIBUTE_INT_LIST_RW_CHECK("hat",0,12,true,SCA_JoystickSensor,m_hat,2,CheckHat),
// dummy attributes will just be read-only in _setattr // dummy attributes will just be read-only in py_setattro
// you still need to defined them in _getattr // you still need to defined them in py_getattro
KX_PYATTRIBUTE_DUMMY("axisPosition"), KX_PYATTRIBUTE_DUMMY("axisPosition"),
KX_PYATTRIBUTE_DUMMY("numAxis"), KX_PYATTRIBUTE_DUMMY("numAxis"),
KX_PYATTRIBUTE_DUMMY("numButtons"), KX_PYATTRIBUTE_DUMMY("numButtons"),
@@ -340,38 +343,40 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* SCA_JoystickSensor::_getattr(const char *attr) { PyObject* SCA_JoystickSensor::py_getattro(PyObject *attr) {
SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
if (!strcmp(attr, "axisPosition")) { char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str, "axisPosition")) {
if(joy) if(joy)
return Py_BuildValue("[iiii]", joy->GetAxis10(), joy->GetAxis11(), joy->GetAxis20(), joy->GetAxis21()); return Py_BuildValue("[iiii]", joy->GetAxis10(), joy->GetAxis11(), joy->GetAxis20(), joy->GetAxis21());
else else
return Py_BuildValue("[iiii]", 0, 0, 0, 0); return Py_BuildValue("[iiii]", 0, 0, 0, 0);
} }
if (!strcmp(attr, "numAxis")) { if (!strcmp(attr_str, "numAxis")) {
return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 ); return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 );
} }
if (!strcmp(attr, "numButtons")) { if (!strcmp(attr_str, "numButtons")) {
return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 );
} }
if (!strcmp(attr, "numHats")) { if (!strcmp(attr_str, "numHats")) {
return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 );
} }
if (!strcmp(attr, "connected")) { if (!strcmp(attr_str, "connected")) {
return PyBool_FromLong( joy ? joy->Connected() : 0 ); return PyBool_FromLong( joy ? joy->Connected() : 0 );
} }
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_ISensor); py_getattro_up(SCA_ISensor);
} }
int SCA_JoystickSensor::_setattr(const char *attr, PyObject *value) int SCA_JoystickSensor::py_setattro(PyObject *attr, PyObject *value)
{ {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_ISensor::_setattr(attr, value); return SCA_ISensor::py_setattro(attr, value);
} }

View File

@@ -121,8 +121,8 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
/* Joystick Index */ /* Joystick Index */
KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetIndex); KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetIndex);

View File

@@ -778,18 +778,21 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus,
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
PyTypeObject SCA_KeyboardSensor::Type = { PyTypeObject SCA_KeyboardSensor::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_KeyboardSensor", "SCA_KeyboardSensor",
sizeof(SCA_KeyboardSensor), sizeof(SCA_KeyboardSensor),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr, 0,
__setattr, 0,
0, //&MyPyCompare, 0,
__repr, py_base_repr,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -828,18 +831,18 @@ PyAttributeDef SCA_KeyboardSensor::Attributes[] = {
}; };
PyObject* PyObject*
SCA_KeyboardSensor::_getattr(const char *attr) SCA_KeyboardSensor::py_getattro(PyObject *attr)
{ {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_ISensor); py_getattro_up(SCA_ISensor);
} }
int SCA_KeyboardSensor::_setattr(const char *attr, PyObject *value) int SCA_KeyboardSensor::py_setattro(PyObject *attr, PyObject *value)
{ {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_ISensor::_setattr(attr, value); return SCA_ISensor::py_setattro(attr, value);
} }

View File

@@ -126,8 +126,8 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
//Deprecated functions -----> //Deprecated functions ----->
/** 1. GetKey : check which key this sensor looks at */ /** 1. GetKey : check which key this sensor looks at */

View File

@@ -102,7 +102,7 @@ int SCA_MouseSensor::UpdateHotkey(void *self, const PyAttributeDef*)
default: default:
; /* ignore, no hotkey */ ; /* ignore, no hotkey */
} }
// return value is used in _setattr(), // return value is used in py_setattro(),
// 0=attribute checked ok (see Attributes array definition) // 0=attribute checked ok (see Attributes array definition)
return 0; return 0;
} }
@@ -300,18 +300,21 @@ KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus,
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
PyTypeObject SCA_MouseSensor::Type = { PyTypeObject SCA_MouseSensor::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_MouseSensor", "SCA_MouseSensor",
sizeof(SCA_MouseSensor), sizeof(SCA_MouseSensor),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -338,20 +341,20 @@ PyAttributeDef SCA_MouseSensor::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* SCA_MouseSensor::_getattr(const char *attr) PyObject* SCA_MouseSensor::py_getattro(PyObject *attr)
{ {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_ISensor); py_getattro_up(SCA_ISensor);
} }
int SCA_MouseSensor::_setattr(const char *attr, PyObject *value) int SCA_MouseSensor::py_setattro(PyObject *attr, PyObject *value)
{ {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_ISensor::_setattr(attr, value); return SCA_ISensor::py_setattro(attr, value);
} }
/* eof */ /* eof */

View File

@@ -109,8 +109,8 @@ class SCA_MouseSensor : public SCA_ISensor
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
//Deprecated functions -----> //Deprecated functions ----->
/* read x-coordinate */ /* read x-coordinate */

View File

@@ -107,18 +107,21 @@ CValue* SCA_NANDController::GetReplica()
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_NANDController::Type = { PyTypeObject SCA_NANDController::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_NANDController", "SCA_NANDController",
sizeof(SCA_NANDController), sizeof(SCA_NANDController),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -138,8 +141,8 @@ PyAttributeDef SCA_NANDController::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* SCA_NANDController::_getattr(const char *attr) { PyObject* SCA_NANDController::py_getattro(PyObject *attr) {
_getattr_up(SCA_IController); py_getattro_up(SCA_IController);
} }
/* eof */ /* eof */

View File

@@ -48,7 +48,7 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
}; };

View File

@@ -107,18 +107,21 @@ CValue* SCA_NORController::GetReplica()
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_NORController::Type = { PyTypeObject SCA_NORController::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_NORController", "SCA_NORController",
sizeof(SCA_NORController), sizeof(SCA_NORController),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -138,8 +141,8 @@ PyAttributeDef SCA_NORController::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* SCA_NORController::_getattr(const char *attr) { PyObject* SCA_NORController::py_getattro(PyObject *attr) {
_getattr_up(SCA_IController); py_getattro_up(SCA_IController);
} }
/* eof */ /* eof */

View File

@@ -48,7 +48,7 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
}; };

View File

@@ -99,18 +99,21 @@ void SCA_ORController::Trigger(SCA_LogicManager* logicmgr)
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_ORController::Type = { PyTypeObject SCA_ORController::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_ORController", "SCA_ORController",
sizeof(SCA_ORController), sizeof(SCA_ORController),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr, 0,
__setattr, 0,
0, //&MyPyCompare, 0,
__repr, py_base_repr,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -131,8 +134,8 @@ PyAttributeDef SCA_ORController::Attributes[] = {
}; };
PyObject* SCA_ORController::_getattr(const char *attr) { PyObject* SCA_ORController::py_getattro(PyObject *attr) {
_getattr_up(SCA_IController); py_getattro_up(SCA_IController);
} }
/* eof */ /* eof */

View File

@@ -49,7 +49,7 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
}; };
#endif //__KX_ORCONTROLLER #endif //__KX_ORCONTROLLER

View File

@@ -218,18 +218,21 @@ void SCA_PropertyActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map)
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_PropertyActuator::Type = { PyTypeObject SCA_PropertyActuator::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_PropertyActuator", "SCA_PropertyActuator",
sizeof(SCA_PropertyActuator), sizeof(SCA_PropertyActuator),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -257,18 +260,18 @@ PyAttributeDef SCA_PropertyActuator::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* SCA_PropertyActuator::_getattr(const char *attr) { PyObject* SCA_PropertyActuator::py_getattro(PyObject *attr) {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_IActuator); py_getattro_up(SCA_IActuator);
} }
int SCA_PropertyActuator::_setattr(const char *attr, PyObject *value) { int SCA_PropertyActuator::py_setattro(PyObject *attr, PyObject *value) {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_IActuator::_setattr(attr, value); return SCA_IActuator::py_setattro(attr, value);
} }
/* 1. setProperty */ /* 1. setProperty */

View File

@@ -85,8 +85,8 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
// python wrapped methods // python wrapped methods
KX_PYMETHOD_DOC(SCA_PropertyActuator,SetProperty); KX_PYMETHOD_DOC(SCA_PropertyActuator,SetProperty);

View File

@@ -306,18 +306,21 @@ int SCA_PropertySensor::validValueForProperty(void *self, const PyAttributeDef*)
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_PropertySensor::Type = { PyTypeObject SCA_PropertySensor::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_PropertySensor", "SCA_PropertySensor",
sizeof(SCA_PropertySensor), sizeof(SCA_PropertySensor),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -349,18 +352,18 @@ PyAttributeDef SCA_PropertySensor::Attributes[] = {
}; };
PyObject* SCA_PropertySensor::_getattr(const char *attr) { PyObject* SCA_PropertySensor::py_getattro(PyObject *attr) {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_ISensor); /* implicit return! */ py_getattro_up(SCA_ISensor); /* implicit return! */
} }
int SCA_PropertySensor::_setattr(const char *attr, PyObject *value) { int SCA_PropertySensor::py_setattro(PyObject *attr, PyObject *value) {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_ISensor::_setattr(attr, value); return SCA_ISensor::py_setattro(attr, value);
} }
/* 1. getType */ /* 1. getType */

View File

@@ -89,8 +89,8 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
/* 1. getType */ /* 1. getType */
KX_PYMETHOD_DOC(SCA_PropertySensor,GetType); KX_PYMETHOD_DOC(SCA_PropertySensor,GetType);

View File

@@ -224,18 +224,21 @@ const char* SCA_PythonController::sPyAddActiveActuator__doc__= "addActiveActuato
const char SCA_PythonController::GetActuators_doc[] = "getActuator"; const char SCA_PythonController::GetActuators_doc[] = "getActuator";
PyTypeObject SCA_PythonController::Type = { PyTypeObject SCA_PythonController::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_PythonController", "SCA_PythonController",
sizeof(SCA_PythonController), sizeof(SCA_PythonController),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr, 0,
__setattr, 0,
0, //&MyPyCompare, 0,
__repr, py_base_repr,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -369,24 +372,26 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
PyObject* SCA_PythonController::_getattr(const char *attr) PyObject* SCA_PythonController::py_getattro(PyObject *attr)
{ {
if (!strcmp(attr,"state")) { char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str,"state")) {
return PyInt_FromLong(m_statemask); return PyInt_FromLong(m_statemask);
} }
if (!strcmp(attr,"script")) { if (!strcmp(attr_str,"script")) {
return PyString_FromString(m_scriptText); return PyString_FromString(m_scriptText);
} }
_getattr_up(SCA_IController); py_getattro_up(SCA_IController);
} }
int SCA_PythonController::_setattr(const char *attr, PyObject *value) int SCA_PythonController::py_setattro(PyObject *attr, PyObject *value)
{ {
if (!strcmp(attr,"state")) { char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str,"state")) {
PyErr_SetString(PyExc_AttributeError, "state is read only"); PyErr_SetString(PyExc_AttributeError, "state is read only");
return 1; return 1;
} }
if (!strcmp(attr,"script")) { if (!strcmp(attr_str,"script")) {
char *scriptArg = PyString_AsString(value); char *scriptArg = PyString_AsString(value);
if (scriptArg==NULL) { if (scriptArg==NULL) {
@@ -400,7 +405,7 @@ int SCA_PythonController::_setattr(const char *attr, PyObject *value)
return 1; return 1;
} }
return SCA_IController::_setattr(attr, value); return SCA_IController::py_setattro(attr, value);
} }
PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value) PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value)

View File

@@ -78,8 +78,8 @@ class SCA_PythonController : public SCA_IController
static PyObject* sPyAddActiveActuator(PyObject* self, static PyObject* sPyAddActiveActuator(PyObject* self,
PyObject* args); PyObject* args);
static SCA_IActuator* LinkedActuatorFromPy(PyObject *value); static SCA_IActuator* LinkedActuatorFromPy(PyObject *value);
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
KX_PYMETHOD_O(SCA_PythonController,Activate); KX_PYMETHOD_O(SCA_PythonController,Activate);

View File

@@ -312,18 +312,21 @@ void SCA_RandomActuator::enforceConstraints() {
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_RandomActuator::Type = { PyTypeObject SCA_RandomActuator::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_RandomActuator", "SCA_RandomActuator",
sizeof(SCA_RandomActuator), sizeof(SCA_RandomActuator),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -366,22 +369,25 @@ PyAttributeDef SCA_RandomActuator::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* SCA_RandomActuator::_getattr(const char *attr) { PyObject* SCA_RandomActuator::py_getattro(PyObject *attr) {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
if (!strcmp(attr, "seed")) { char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str, "seed")) {
return PyInt_FromLong(m_base->GetSeed()); return PyInt_FromLong(m_base->GetSeed());
} }
_getattr_up(SCA_IActuator); py_getattro_up(SCA_IActuator);
} }
int SCA_RandomActuator::_setattr(const char *attr, PyObject *value) int SCA_RandomActuator::py_setattro(PyObject *attr, PyObject *value)
{ {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
if (!strcmp(attr, "seed")) {
char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str, "seed")) {
if (PyInt_Check(value)) { if (PyInt_Check(value)) {
int ival = PyInt_AsLong(value); int ival = PyInt_AsLong(value);
m_base->SetSeed(ival); m_base->SetSeed(ival);
@@ -391,7 +397,7 @@ int SCA_RandomActuator::_setattr(const char *attr, PyObject *value)
return 1; return 1;
} }
} }
return SCA_IActuator::_setattr(attr, value); return SCA_IActuator::py_setattro(attr, value);
} }
/* 1. setSeed */ /* 1. setSeed */

View File

@@ -96,8 +96,8 @@ class SCA_RandomActuator : public SCA_IActuator
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
/* 1. setSeed */ /* 1. setSeed */
KX_PYMETHOD_DOC(SCA_RandomActuator,SetSeed); KX_PYMETHOD_DOC(SCA_RandomActuator,SetSeed);

View File

@@ -127,18 +127,21 @@ bool SCA_RandomSensor::Evaluate(CValue* event)
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_RandomSensor::Type = { PyTypeObject SCA_RandomSensor::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_RandomSensor", "SCA_RandomSensor",
sizeof(SCA_RandomSensor), sizeof(SCA_RandomSensor),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -162,22 +165,25 @@ PyAttributeDef SCA_RandomSensor::Attributes[] = {
{NULL} //Sentinel {NULL} //Sentinel
}; };
PyObject* SCA_RandomSensor::_getattr(const char *attr) { PyObject* SCA_RandomSensor::py_getattro(PyObject *attr) {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
if (!strcmp(attr,"seed")) {
char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str,"seed")) {
return PyInt_FromLong(m_basegenerator->GetSeed()); return PyInt_FromLong(m_basegenerator->GetSeed());
} }
_getattr_up(SCA_ISensor); py_getattro_up(SCA_ISensor);
} }
int SCA_RandomSensor::_setattr(const char *attr, PyObject *value) int SCA_RandomSensor::py_setattro(PyObject *attr, PyObject *value)
{ {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
if (!strcmp(attr,"seed")) { char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str,"seed")) {
if (PyInt_Check(value)) { if (PyInt_Check(value)) {
int ival = PyInt_AsLong(value); int ival = PyInt_AsLong(value);
m_basegenerator->SetSeed(ival); m_basegenerator->SetSeed(ival);
@@ -187,7 +193,7 @@ int SCA_RandomSensor::_setattr(const char *attr, PyObject *value)
return 1; return 1;
} }
} }
return SCA_ISensor::_setattr(attr, value); return SCA_ISensor::py_setattro(attr, value);
} }
/* 1. setSeed */ /* 1. setSeed */

View File

@@ -60,8 +60,8 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
/* 1. setSeed */ /* 1. setSeed */
KX_PYMETHOD_DOC(SCA_RandomSensor,SetSeed); KX_PYMETHOD_DOC(SCA_RandomSensor,SetSeed);

View File

@@ -111,18 +111,21 @@ CValue* SCA_XNORController::GetReplica()
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_XNORController::Type = { PyTypeObject SCA_XNORController::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_XNORController", "SCA_XNORController",
sizeof(SCA_XNORController), sizeof(SCA_XNORController),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -142,8 +145,8 @@ PyAttributeDef SCA_XNORController::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* SCA_XNORController::_getattr(const char *attr) { PyObject* SCA_XNORController::py_getattro(PyObject *attr) {
_getattr_up(SCA_IController); py_getattro_up(SCA_IController);
} }
/* eof */ /* eof */

View File

@@ -48,7 +48,7 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
}; };

View File

@@ -111,18 +111,21 @@ CValue* SCA_XORController::GetReplica()
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_XORController::Type = { PyTypeObject SCA_XORController::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"SCA_XORController", "SCA_XORController",
sizeof(SCA_XORController), sizeof(SCA_XORController),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -142,8 +145,8 @@ PyAttributeDef SCA_XORController::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* SCA_XORController::_getattr(const char *attr) { PyObject* SCA_XORController::py_getattro(PyObject *attr) {
_getattr_up(SCA_IController); py_getattro_up(SCA_IController);
} }
/* eof */ /* eof */

View File

@@ -48,7 +48,7 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
}; };

View File

@@ -729,9 +729,9 @@ void BL_Shader::SetUniform(int uniform, const int* val, int len)
} }
PyObject* BL_Shader::_getattr(const char *attr) PyObject* BL_Shader::py_getattro(PyObject *attr)
{ {
_getattr_up(PyObjectPlus); py_getattro_up(PyObjectPlus);
} }
@@ -772,25 +772,28 @@ PyAttributeDef BL_Shader::Attributes[] = {
}; };
PyTypeObject BL_Shader::Type = { PyTypeObject BL_Shader::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"BL_Shader", "BL_Shader",
sizeof(BL_Shader), sizeof(BL_Shader),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
PyParentObject BL_Shader::Parents[] = { PyParentObject BL_Shader::Parents[] = {
&PyObjectPlus::Type,
&BL_Shader::Type, &BL_Shader::Type,
&PyObjectPlus::Type,
NULL NULL
}; };

View File

@@ -202,7 +202,7 @@ public:
void SetUniform(int uniform, const int val); void SetUniform(int uniform, const int val);
// Python interface // Python interface
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
// ----------------------------------- // -----------------------------------
KX_PYMETHOD_DOC( BL_Shader, setSource ); KX_PYMETHOD_DOC( BL_Shader, setSource );

View File

@@ -105,18 +105,21 @@ CValue* KX_NetworkMessageActuator::GetReplica()
/* Integration hooks -------------------------------------------------- */ /* Integration hooks -------------------------------------------------- */
PyTypeObject KX_NetworkMessageActuator::Type = { PyTypeObject KX_NetworkMessageActuator::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_NetworkMessageActuator", "KX_NetworkMessageActuator",
sizeof(KX_NetworkMessageActuator), sizeof(KX_NetworkMessageActuator),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -150,18 +153,18 @@ PyAttributeDef KX_NetworkMessageActuator::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* KX_NetworkMessageActuator::_getattr(const char *attr) { PyObject* KX_NetworkMessageActuator::py_getattro(PyObject *attr) {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_IActuator); py_getattro_up(SCA_IActuator);
} }
int KX_NetworkMessageActuator::_setattr(const char *attr, PyObject *value) { int KX_NetworkMessageActuator::py_setattro(PyObject *attr, PyObject *value) {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_IActuator::_setattr(attr, value); return SCA_IActuator::py_setattro(attr, value);
} }
// Deprecated -----> // Deprecated ----->

View File

@@ -61,8 +61,8 @@ public:
/* Python interface ------------------------------------------- */ /* Python interface ------------------------------------------- */
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
// Deprecated -----> // Deprecated ----->
KX_PYMETHOD(KX_NetworkMessageActuator, SetToPropName); KX_PYMETHOD(KX_NetworkMessageActuator, SetToPropName);

View File

@@ -168,18 +168,21 @@ bool KX_NetworkMessageSensor::IsPositiveTrigger()
/* Integration hooks --------------------------------------------------- */ /* Integration hooks --------------------------------------------------- */
PyTypeObject KX_NetworkMessageSensor::Type = { PyTypeObject KX_NetworkMessageSensor::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_NetworkMessageSensor", "KX_NetworkMessageSensor",
sizeof(KX_NetworkMessageSensor), sizeof(KX_NetworkMessageSensor),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -220,18 +223,18 @@ PyAttributeDef KX_NetworkMessageSensor::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* KX_NetworkMessageSensor::_getattr(const char *attr) { PyObject* KX_NetworkMessageSensor::py_getattro(PyObject *attr) {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_ISensor); py_getattro_up(SCA_ISensor);
} }
int KX_NetworkMessageSensor::_setattr(const char *attr, PyObject *value) { int KX_NetworkMessageSensor::py_setattro(PyObject *attr, PyObject *value) {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_ISensor::_setattr(attr, value); return SCA_ISensor::py_setattro(attr, value);
} }
PyObject* KX_NetworkMessageSensor::pyattr_get_bodies(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) PyObject* KX_NetworkMessageSensor::pyattr_get_bodies(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)

View File

@@ -72,8 +72,8 @@ public:
/* Python interface -------------------------------------------- */ /* Python interface -------------------------------------------- */
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
// Deprecated -----> // Deprecated ----->
KX_PYMETHOD_DOC_O(KX_NetworkMessageSensor, SetSubjectFilterText); KX_PYMETHOD_DOC_O(KX_NetworkMessageSensor, SetSubjectFilterText);

View File

@@ -753,37 +753,40 @@ PyAttributeDef KX_BlenderMaterial::Attributes[] = {
}; };
PyTypeObject KX_BlenderMaterial::Type = { PyTypeObject KX_BlenderMaterial::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_BlenderMaterial", "KX_BlenderMaterial",
sizeof(KX_BlenderMaterial), sizeof(KX_BlenderMaterial),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
PyParentObject KX_BlenderMaterial::Parents[] = { PyParentObject KX_BlenderMaterial::Parents[] = {
&PyObjectPlus::Type,
&KX_BlenderMaterial::Type, &KX_BlenderMaterial::Type,
&PyObjectPlus::Type,
NULL NULL
}; };
PyObject* KX_BlenderMaterial::_getattr(const char *attr) PyObject* KX_BlenderMaterial::py_getattro(PyObject *attr)
{ {
_getattr_up(PyObjectPlus); py_getattro_up(PyObjectPlus);
} }
int KX_BlenderMaterial::_setattr(const char *attr, PyObject *pyvalue) int KX_BlenderMaterial::py_setattro(PyObject *attr, PyObject *pyvalue)
{ {
return PyObjectPlus::_setattr(attr, pyvalue); return PyObjectPlus::py_setattro(attr, pyvalue);
} }

View File

@@ -82,8 +82,8 @@ public:
); );
// -------------------------------- // --------------------------------
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *pyvalue); virtual int py_setattro(PyObject *attr, PyObject *pyvalue);
KX_PYMETHOD_DOC( KX_BlenderMaterial, getShader ); KX_PYMETHOD_DOC( KX_BlenderMaterial, getShader );
KX_PYMETHOD_DOC( KX_BlenderMaterial, getMaterialIndex ); KX_PYMETHOD_DOC( KX_BlenderMaterial, getMaterialIndex );

View File

@@ -158,18 +158,21 @@ bool KX_CDActuator::Update()
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject KX_CDActuator::Type = { PyTypeObject KX_CDActuator::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_SoundActuator", "KX_SoundActuator",
sizeof(KX_CDActuator), sizeof(KX_CDActuator),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -212,20 +215,20 @@ int KX_CDActuator::pyattr_setGain(void *self, const struct KX_PYATTRIBUTE_DEF *a
return 0; return 0;
} }
PyObject* KX_CDActuator::_getattr(const char *attr) PyObject* KX_CDActuator::py_getattro(PyObject *attr)
{ {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_IActuator); py_getattro_up(SCA_IActuator);
} }
int KX_CDActuator::_setattr(const char *attr, PyObject *value) int KX_CDActuator::py_setattro(PyObject *attr, PyObject *value)
{ {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_IActuator::_setattr(attr, value); return SCA_IActuator::py_setattro(attr, value);
} }

View File

@@ -81,8 +81,8 @@ public:
/* Python interface --------------------------------------------------- */ /* Python interface --------------------------------------------------- */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
// Deprecated -----> // Deprecated ----->
KX_PYMETHOD(KX_CDActuator,SetGain); KX_PYMETHOD(KX_CDActuator,SetGain);

View File

@@ -488,18 +488,21 @@ PyAttributeDef KX_Camera::Attributes[] = {
}; };
PyTypeObject KX_Camera::Type = { PyTypeObject KX_Camera::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_Camera", "KX_Camera",
sizeof(KX_Camera), sizeof(KX_Camera),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -511,48 +514,51 @@ PyParentObject KX_Camera::Parents[] = {
NULL NULL
}; };
PyObject* KX_Camera::_getattr(const char *attr) PyObject* KX_Camera::py_getattro(PyObject *attr)
{ {
if (!strcmp(attr, "INSIDE")) char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str, "INSIDE"))
return PyInt_FromLong(INSIDE); /* new ref */ return PyInt_FromLong(INSIDE); /* new ref */
if (!strcmp(attr, "OUTSIDE")) if (!strcmp(attr_str, "OUTSIDE"))
return PyInt_FromLong(OUTSIDE); /* new ref */ return PyInt_FromLong(OUTSIDE); /* new ref */
if (!strcmp(attr, "INTERSECT")) if (!strcmp(attr_str, "INTERSECT"))
return PyInt_FromLong(INTERSECT); /* new ref */ return PyInt_FromLong(INTERSECT); /* new ref */
if (!strcmp(attr, "lens")) if (!strcmp(attr_str, "lens"))
return PyFloat_FromDouble(GetLens()); /* new ref */ return PyFloat_FromDouble(GetLens()); /* new ref */
if (!strcmp(attr, "near")) if (!strcmp(attr_str, "near"))
return PyFloat_FromDouble(GetCameraNear()); /* new ref */ return PyFloat_FromDouble(GetCameraNear()); /* new ref */
if (!strcmp(attr, "far")) if (!strcmp(attr_str, "far"))
return PyFloat_FromDouble(GetCameraFar()); /* new ref */ return PyFloat_FromDouble(GetCameraFar()); /* new ref */
if (!strcmp(attr, "frustum_culling")) if (!strcmp(attr_str, "frustum_culling"))
return PyInt_FromLong(m_frustum_culling); /* new ref */ return PyInt_FromLong(m_frustum_culling); /* new ref */
if (!strcmp(attr, "perspective")) if (!strcmp(attr_str, "perspective"))
return PyInt_FromLong(m_camdata.m_perspective); /* new ref */ return PyInt_FromLong(m_camdata.m_perspective); /* new ref */
if (!strcmp(attr, "projection_matrix")) if (!strcmp(attr_str, "projection_matrix"))
return PyObjectFrom(GetProjectionMatrix()); /* new ref */ return PyObjectFrom(GetProjectionMatrix()); /* new ref */
if (!strcmp(attr, "modelview_matrix")) if (!strcmp(attr_str, "modelview_matrix"))
return PyObjectFrom(GetModelviewMatrix()); /* new ref */ return PyObjectFrom(GetModelviewMatrix()); /* new ref */
if (!strcmp(attr, "camera_to_world")) if (!strcmp(attr_str, "camera_to_world"))
return PyObjectFrom(GetCameraToWorld()); /* new ref */ return PyObjectFrom(GetCameraToWorld()); /* new ref */
if (!strcmp(attr, "world_to_camera")) if (!strcmp(attr_str, "world_to_camera"))
return PyObjectFrom(GetWorldToCamera()); /* new ref */ return PyObjectFrom(GetWorldToCamera()); /* new ref */
_getattr_up(KX_GameObject); py_getattro_up(KX_GameObject);
} }
int KX_Camera::_setattr(const char *attr, PyObject *pyvalue) int KX_Camera::py_setattro(PyObject *attr, PyObject *pyvalue)
{ {
char *attr_str= PyString_AsString(attr);
if (PyInt_Check(pyvalue)) if (PyInt_Check(pyvalue))
{ {
if (!strcmp(attr, "frustum_culling")) if (!strcmp(attr_str, "frustum_culling"))
{ {
m_frustum_culling = PyInt_AsLong(pyvalue); m_frustum_culling = PyInt_AsLong(pyvalue);
return 0; return 0;
} }
if (!strcmp(attr, "perspective")) if (!strcmp(attr_str, "perspective"))
{ {
m_camdata.m_perspective = PyInt_AsLong(pyvalue); m_camdata.m_perspective = PyInt_AsLong(pyvalue);
return 0; return 0;
@@ -561,19 +567,19 @@ int KX_Camera::_setattr(const char *attr, PyObject *pyvalue)
if (PyFloat_Check(pyvalue)) if (PyFloat_Check(pyvalue))
{ {
if (!strcmp(attr, "lens")) if (!strcmp(attr_str, "lens"))
{ {
m_camdata.m_lens = PyFloat_AsDouble(pyvalue); m_camdata.m_lens = PyFloat_AsDouble(pyvalue);
m_set_projection_matrix = false; m_set_projection_matrix = false;
return 0; return 0;
} }
if (!strcmp(attr, "near")) if (!strcmp(attr_str, "near"))
{ {
m_camdata.m_clipstart = PyFloat_AsDouble(pyvalue); m_camdata.m_clipstart = PyFloat_AsDouble(pyvalue);
m_set_projection_matrix = false; m_set_projection_matrix = false;
return 0; return 0;
} }
if (!strcmp(attr, "far")) if (!strcmp(attr_str, "far"))
{ {
m_camdata.m_clipend = PyFloat_AsDouble(pyvalue); m_camdata.m_clipend = PyFloat_AsDouble(pyvalue);
m_set_projection_matrix = false; m_set_projection_matrix = false;
@@ -583,7 +589,7 @@ int KX_Camera::_setattr(const char *attr, PyObject *pyvalue)
if (PyObject_IsMT_Matrix(pyvalue, 4)) if (PyObject_IsMT_Matrix(pyvalue, 4))
{ {
if (!strcmp(attr, "projection_matrix")) if (!strcmp(attr_str, "projection_matrix"))
{ {
MT_Matrix4x4 mat; MT_Matrix4x4 mat;
if (PyMatTo(pyvalue, mat)) if (PyMatTo(pyvalue, mat))
@@ -594,7 +600,7 @@ int KX_Camera::_setattr(const char *attr, PyObject *pyvalue)
return 1; return 1;
} }
} }
return KX_GameObject::_setattr(attr, pyvalue); return KX_GameObject::py_setattro(attr, pyvalue);
} }
KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, sphereInsideFrustum, KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, sphereInsideFrustum,

View File

@@ -265,8 +265,8 @@ public:
KX_PYMETHOD_DOC_VARARGS(KX_Camera, setViewport); KX_PYMETHOD_DOC_VARARGS(KX_Camera, setViewport);
KX_PYMETHOD_DOC_NOARGS(KX_Camera, setOnTop); KX_PYMETHOD_DOC_NOARGS(KX_Camera, setOnTop);
virtual PyObject* _getattr(const char *attr); /* lens, near, far, projection_matrix */ virtual PyObject* py_getattro(PyObject *attr); /* lens, near, far, projection_matrix */
virtual int _setattr(const char *attr, PyObject *pyvalue); virtual int py_setattro(PyObject *attr, PyObject *pyvalue);
}; };

View File

@@ -371,18 +371,21 @@ bool KX_CameraActuator::string2axischoice(const char *axisString)
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject KX_CameraActuator::Type = { PyTypeObject KX_CameraActuator::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_CameraActuator", "KX_CameraActuator",
sizeof(KX_CameraActuator), sizeof(KX_CameraActuator),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -414,27 +417,28 @@ PyAttributeDef KX_CameraActuator::Attributes[] = {
KX_PYATTRIBUTE_FLOAT_RW("max",-MAXFLOAT,MAXFLOAT,KX_CameraActuator,m_maxHeight), KX_PYATTRIBUTE_FLOAT_RW("max",-MAXFLOAT,MAXFLOAT,KX_CameraActuator,m_maxHeight),
KX_PYATTRIBUTE_FLOAT_RW("height",-MAXFLOAT,MAXFLOAT,KX_CameraActuator,m_height), KX_PYATTRIBUTE_FLOAT_RW("height",-MAXFLOAT,MAXFLOAT,KX_CameraActuator,m_height),
KX_PYATTRIBUTE_BOOL_RW("xy",KX_CameraActuator,m_x), KX_PYATTRIBUTE_BOOL_RW("xy",KX_CameraActuator,m_x),
KX_PYATTRIBUTE_DUMMY("object"),
{NULL} {NULL}
}; };
PyObject* KX_CameraActuator::_getattr(const char *attr) { PyObject* KX_CameraActuator::py_getattro(PyObject *attr) {
PyObject* object; PyObject* object;
char *attr_str= PyString_AsString(attr);
if (!strcmp(attr, "object")) { if (!strcmp(attr_str, "object")) {
if (!m_ob) Py_RETURN_NONE; if (!m_ob) Py_RETURN_NONE;
else return m_ob->AddRef(); else return m_ob->AddRef();
} }
object = _getattr_self(Attributes, this, attr); object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_IActuator); py_getattro_up(SCA_IActuator);
} }
int KX_CameraActuator::_setattr(const char *attr, PyObject* value) { int KX_CameraActuator::py_setattro(PyObject *attr, PyObject* value) {
int ret; int ret;
char *attr_str= PyString_AsString(attr);
if (!strcmp(attr, "object")) { if (!strcmp(attr_str, "object")) {
KX_GameObject *gameobj; KX_GameObject *gameobj;
if (!ConvertPythonToGameObject(value, &gameobj, true)) if (!ConvertPythonToGameObject(value, &gameobj, true))
@@ -451,10 +455,10 @@ int KX_CameraActuator::_setattr(const char *attr, PyObject* value) {
return 0; return 0;
} }
ret = _setattr_self(Attributes, this, attr, value); ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_IActuator::_setattr(attr, value); return SCA_IActuator::py_setattro(attr, value);
} }
/* get obj ---------------------------------------------------------- */ /* get obj ---------------------------------------------------------- */

View File

@@ -120,8 +120,8 @@ private :
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject* value); virtual int py_setattro(PyObject *attr, PyObject* value);
/* set object to look at */ /* set object to look at */
KX_PYMETHOD_DOC_O(KX_CameraActuator,SetObject); KX_PYMETHOD_DOC_O(KX_CameraActuator,SetObject);

View File

@@ -560,18 +560,21 @@ bool KX_ConstraintActuator::IsValidMode(KX_ConstraintActuator::KX_CONSTRAINTTYPE
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject KX_ConstraintActuator::Type = { PyTypeObject KX_ConstraintActuator::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_ConstraintActuator", "KX_ConstraintActuator",
sizeof(KX_ConstraintActuator), sizeof(KX_ConstraintActuator),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -613,8 +616,8 @@ PyAttributeDef KX_ConstraintActuator::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* KX_ConstraintActuator::_getattr(const char *attr) { PyObject* KX_ConstraintActuator::py_getattro(PyObject *attr) {
_getattr_up(SCA_IActuator); py_getattro_up(SCA_IActuator);
} }
/* 2. setDamp */ /* 2. setDamp */

View File

@@ -142,7 +142,7 @@ protected:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDamp); KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDamp);
KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetDamp); KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetDamp);

View File

@@ -69,18 +69,21 @@ PyObject* KX_ConstraintWrapper::PyGetConstraintId(PyObject* self,
//python specific stuff //python specific stuff
PyTypeObject KX_ConstraintWrapper::Type = { PyTypeObject KX_ConstraintWrapper::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_ConstraintWrapper", "KX_ConstraintWrapper",
sizeof(KX_ConstraintWrapper), sizeof(KX_ConstraintWrapper),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -89,13 +92,13 @@ PyParentObject KX_ConstraintWrapper::Parents[] = {
NULL NULL
}; };
PyObject* KX_ConstraintWrapper::_getattr(const char *attr) PyObject* KX_ConstraintWrapper::py_getattro(PyObject *attr)
{ {
//here you can search for existing data members (like mass,friction etc.) //here you can search for existing data members (like mass,friction etc.)
_getattr_up(PyObjectPlus); py_getattro_up(PyObjectPlus);
} }
int KX_ConstraintWrapper::_setattr(const char *attr,PyObject* pyobj) int KX_ConstraintWrapper::py_setattro(PyObject *attr,PyObject* pyobj)
{ {
int result = 1; int result = 1;
@@ -117,7 +120,7 @@ int KX_ConstraintWrapper::_setattr(const char *attr,PyObject* pyobj)
result = 0; result = 0;
} }
if (result) if (result)
result = PyObjectPlus::_setattr(attr,pyobj); result = PyObjectPlus::py_setattro(attr,pyobj);
return result; return result;
}; };

View File

@@ -35,8 +35,8 @@
class KX_ConstraintWrapper : public PyObjectPlus class KX_ConstraintWrapper : public PyObjectPlus
{ {
Py_Header; Py_Header;
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
public: public:
KX_ConstraintWrapper(PHY_ConstraintType ctype,int constraintId,class PHY_IPhysicsEnvironment* physenv,PyTypeObject *T = &Type); KX_ConstraintWrapper(PHY_ConstraintType ctype,int constraintId,class PHY_IPhysicsEnvironment* physenv,PyTypeObject *T = &Type);
virtual ~KX_ConstraintWrapper (); virtual ~KX_ConstraintWrapper ();

View File

@@ -208,18 +208,21 @@ bool KX_GameActuator::Update()
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject KX_GameActuator::Type = { PyTypeObject KX_GameActuator::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_GameActuator", "KX_GameActuator",
sizeof(KX_GameActuator), sizeof(KX_GameActuator),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -251,20 +254,20 @@ PyAttributeDef KX_GameActuator::Attributes[] = {
}; };
PyObject* PyObject*
KX_GameActuator::_getattr(const char *attr) KX_GameActuator::py_getattro(PyObject *attr)
{ {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_IActuator); py_getattro_up(SCA_IActuator);
} }
int KX_GameActuator::_setattr(const char *attr, PyObject *value) int KX_GameActuator::py_setattro(PyObject *attr, PyObject *value)
{ {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_IActuator::_setattr(attr, value); return SCA_IActuator::py_setattro(attr, value);
} }

View File

@@ -77,8 +77,8 @@ protected:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
// Deprecated functions -----> // Deprecated functions ----->
KX_PYMETHOD_DOC(KX_GameActuator,GetFile); KX_PYMETHOD_DOC(KX_GameActuator,GetFile);

View File

@@ -1180,21 +1180,21 @@ PyMappingMethods KX_GameObject::Mapping = {
PyTypeObject KX_GameObject::Type = { PyTypeObject KX_GameObject::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_GameObject", "KX_GameObject",
sizeof(KX_GameObject), sizeof(KX_GameObject),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0,
__repr,
0, 0,
0, 0,
&Mapping, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0, py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -1420,7 +1420,9 @@ int KX_GameObject::pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attr
PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{ {
KX_GameObject* self= static_cast<KX_GameObject*>(self_v); KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
PyObject *dict= _getattr_dict(self->SCA_IObject::_getattr("__dict__"), KX_GameObject::Methods, KX_GameObject::Attributes); PyObject *dict_str = PyString_FromString("__dict__");
PyObject *dict= _getattr_dict(self->SCA_IObject::py_getattro(dict_str), KX_GameObject::Methods, KX_GameObject::Attributes);
Py_DECREF(dict_str);
if(dict==NULL) if(dict==NULL)
return NULL; return NULL;
@@ -1441,22 +1443,22 @@ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_
return dict; return dict;
} }
PyObject* KX_GameObject::_getattr(const char *attr) PyObject* KX_GameObject::py_getattro(PyObject *attr)
{ {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_IObject); py_getattro_up(SCA_IObject);
} }
int KX_GameObject::_setattr(const char *attr, PyObject *value) // _setattr method int KX_GameObject::py_setattro(PyObject *attr, PyObject *value) // py_setattro method
{ {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_IObject::_setattr(attr, value); return SCA_IObject::py_setattro(attr, value);
} }
PyObject* KX_GameObject::PyApplyForce(PyObject* self, PyObject* args) PyObject* KX_GameObject::PyApplyForce(PyObject* self, PyObject* args)

View File

@@ -756,9 +756,9 @@ public:
* @section Python interface functions. * @section Python interface functions.
*/ */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); // _setattr method virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method
virtual PyObject* _repr(void) { return PyString_FromString(GetName().ReadPtr()); } virtual PyObject* py_repr(void) { return PyString_FromString(GetName().ReadPtr()); }
KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition); KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition);
KX_PYMETHOD_O(KX_GameObject,SetPosition); KX_PYMETHOD_O(KX_GameObject,SetPosition);

View File

@@ -413,18 +413,21 @@ int KX_IpoActuator::string2mode(char* modename) {
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject KX_IpoActuator::Type = { PyTypeObject KX_IpoActuator::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_IpoActuator", "KX_IpoActuator",
sizeof(KX_IpoActuator), sizeof(KX_IpoActuator),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -470,25 +473,21 @@ PyAttributeDef KX_IpoActuator::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* KX_IpoActuator::_getattr(const char *attr) { PyObject* KX_IpoActuator::py_getattro(PyObject *attr) {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
if (!strcmp(attr, "__dict__")) { /* python 3.0 uses .__dir__()*/ py_getattro_up(SCA_IActuator);
return _getattr_dict(SCA_IActuator::_getattr(attr), Methods, Attributes);
}
_getattr_up(SCA_IActuator);
} }
int KX_IpoActuator::_setattr(const char *attr, PyObject *value) // _setattr method int KX_IpoActuator::py_setattro(PyObject *attr, PyObject *value) // py_setattro method
{ {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_IActuator::_setattr(attr, value); return SCA_IActuator::py_setattro(attr, value);
} }
/* set --------------------------------------------------------------------- */ /* set --------------------------------------------------------------------- */

View File

@@ -141,8 +141,8 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
//KX_PYMETHOD_DOC //KX_PYMETHOD_DOC
KX_PYMETHOD_DOC(KX_IpoActuator,Set); KX_PYMETHOD_DOC(KX_IpoActuator,Set);

View File

@@ -173,59 +173,62 @@ void KX_LightObject::UnbindShadowBuffer(RAS_IRasterizer *ras)
GPU_lamp_shadow_buffer_unbind(lamp); GPU_lamp_shadow_buffer_unbind(lamp);
} }
PyObject* KX_LightObject::_getattr(const char *attr) PyObject* KX_LightObject::py_getattro(PyObject *attr)
{ {
if (!strcmp(attr, "layer")) char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str, "layer"))
return PyInt_FromLong(m_lightobj.m_layer); return PyInt_FromLong(m_lightobj.m_layer);
if (!strcmp(attr, "energy")) if (!strcmp(attr_str, "energy"))
return PyFloat_FromDouble(m_lightobj.m_energy); return PyFloat_FromDouble(m_lightobj.m_energy);
if (!strcmp(attr, "distance")) if (!strcmp(attr_str, "distance"))
return PyFloat_FromDouble(m_lightobj.m_distance); return PyFloat_FromDouble(m_lightobj.m_distance);
if (!strcmp(attr, "colour") || !strcmp(attr, "color")) if (!strcmp(attr_str, "colour") || !strcmp(attr_str, "color"))
return Py_BuildValue("[fff]", m_lightobj.m_red, m_lightobj.m_green, m_lightobj.m_blue); return Py_BuildValue("[fff]", m_lightobj.m_red, m_lightobj.m_green, m_lightobj.m_blue);
if (!strcmp(attr, "lin_attenuation")) if (!strcmp(attr_str, "lin_attenuation"))
return PyFloat_FromDouble(m_lightobj.m_att1); return PyFloat_FromDouble(m_lightobj.m_att1);
if (!strcmp(attr, "quad_attenuation")) if (!strcmp(attr_str, "quad_attenuation"))
return PyFloat_FromDouble(m_lightobj.m_att2); return PyFloat_FromDouble(m_lightobj.m_att2);
if (!strcmp(attr, "spotsize")) if (!strcmp(attr_str, "spotsize"))
return PyFloat_FromDouble(m_lightobj.m_spotsize); return PyFloat_FromDouble(m_lightobj.m_spotsize);
if (!strcmp(attr, "spotblend")) if (!strcmp(attr_str, "spotblend"))
return PyFloat_FromDouble(m_lightobj.m_spotblend); return PyFloat_FromDouble(m_lightobj.m_spotblend);
if (!strcmp(attr, "SPOT")) if (!strcmp(attr_str, "SPOT"))
return PyInt_FromLong(RAS_LightObject::LIGHT_SPOT); return PyInt_FromLong(RAS_LightObject::LIGHT_SPOT);
if (!strcmp(attr, "SUN")) if (!strcmp(attr_str, "SUN"))
return PyInt_FromLong(RAS_LightObject::LIGHT_SUN); return PyInt_FromLong(RAS_LightObject::LIGHT_SUN);
if (!strcmp(attr, "NORMAL")) if (!strcmp(attr_str, "NORMAL"))
return PyInt_FromLong(RAS_LightObject::LIGHT_NORMAL); return PyInt_FromLong(RAS_LightObject::LIGHT_NORMAL);
if (!strcmp(attr, "type")) if (!strcmp(attr_str, "type"))
return PyInt_FromLong(m_lightobj.m_type); return PyInt_FromLong(m_lightobj.m_type);
_getattr_up(KX_GameObject); py_getattro_up(KX_GameObject);
} }
int KX_LightObject::_setattr(const char *attr, PyObject *pyvalue) int KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue)
{ {
char *attr_str= PyString_AsString(attr);
if (PyInt_Check(pyvalue)) if (PyInt_Check(pyvalue))
{ {
int value = PyInt_AsLong(pyvalue); int value = PyInt_AsLong(pyvalue);
if (!strcmp(attr, "layer")) if (!strcmp(attr_str, "layer"))
{ {
m_lightobj.m_layer = value; m_lightobj.m_layer = value;
return 0; return 0;
} }
if (!strcmp(attr, "type")) if (!strcmp(attr_str, "type"))
{ {
if (value >= RAS_LightObject::LIGHT_SPOT && value <= RAS_LightObject::LIGHT_NORMAL) if (value >= RAS_LightObject::LIGHT_SPOT && value <= RAS_LightObject::LIGHT_NORMAL)
m_lightobj.m_type = (RAS_LightObject::LightType) value; m_lightobj.m_type = (RAS_LightObject::LightType) value;
@@ -236,37 +239,37 @@ int KX_LightObject::_setattr(const char *attr, PyObject *pyvalue)
if (PyFloat_Check(pyvalue)) if (PyFloat_Check(pyvalue))
{ {
float value = PyFloat_AsDouble(pyvalue); float value = PyFloat_AsDouble(pyvalue);
if (!strcmp(attr, "energy")) if (!strcmp(attr_str, "energy"))
{ {
m_lightobj.m_energy = value; m_lightobj.m_energy = value;
return 0; return 0;
} }
if (!strcmp(attr, "distance")) if (!strcmp(attr_str, "distance"))
{ {
m_lightobj.m_distance = value; m_lightobj.m_distance = value;
return 0; return 0;
} }
if (!strcmp(attr, "lin_attenuation")) if (!strcmp(attr_str, "lin_attenuation"))
{ {
m_lightobj.m_att1 = value; m_lightobj.m_att1 = value;
return 0; return 0;
} }
if (!strcmp(attr, "quad_attenuation")) if (!strcmp(attr_str, "quad_attenuation"))
{ {
m_lightobj.m_att2 = value; m_lightobj.m_att2 = value;
return 0; return 0;
} }
if (!strcmp(attr, "spotsize")) if (!strcmp(attr_str, "spotsize"))
{ {
m_lightobj.m_spotsize = value; m_lightobj.m_spotsize = value;
return 0; return 0;
} }
if (!strcmp(attr, "spotblend")) if (!strcmp(attr_str, "spotblend"))
{ {
m_lightobj.m_spotblend = value; m_lightobj.m_spotblend = value;
return 0; return 0;
@@ -275,7 +278,7 @@ int KX_LightObject::_setattr(const char *attr, PyObject *pyvalue)
if (PySequence_Check(pyvalue)) if (PySequence_Check(pyvalue))
{ {
if (!strcmp(attr, "colour") || !strcmp(attr, "color")) if (!strcmp(attr_str, "colour") || !strcmp(attr_str, "color"))
{ {
MT_Vector3 color; MT_Vector3 color;
if (PyVecTo(pyvalue, color)) if (PyVecTo(pyvalue, color))
@@ -289,13 +292,13 @@ int KX_LightObject::_setattr(const char *attr, PyObject *pyvalue)
} }
} }
if (!strcmp(attr, "SPOT") || !strcmp(attr, "SUN") || !strcmp(attr, "NORMAL")) if (!strcmp(attr_str, "SPOT") || !strcmp(attr_str, "SUN") || !strcmp(attr_str, "NORMAL"))
{ {
PyErr_Format(PyExc_RuntimeError, "Attribute %s is read only.", attr); PyErr_Format(PyExc_RuntimeError, "Attribute %s is read only.", attr_str);
return 1; return 1;
} }
return KX_GameObject::_setattr(attr, pyvalue); return KX_GameObject::py_setattro(attr, pyvalue);
} }
PyMethodDef KX_LightObject::Methods[] = { PyMethodDef KX_LightObject::Methods[] = {
@@ -308,18 +311,21 @@ PyAttributeDef KX_LightObject::Attributes[] = {
PyTypeObject KX_LightObject::Type = { PyTypeObject KX_LightObject::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_LightObject", "KX_LightObject",
sizeof(KX_LightObject), sizeof(KX_LightObject),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };

View File

@@ -62,8 +62,8 @@ public:
void UnbindShadowBuffer(class RAS_IRasterizer *ras); void UnbindShadowBuffer(class RAS_IRasterizer *ras);
void Update(); void Update();
virtual PyObject* _getattr(const char *attr); /* lens, near, far, projection_matrix */ virtual PyObject* py_getattro(PyObject *attr); /* lens, near, far, projection_matrix */
virtual int _setattr(const char *attr, PyObject *pyvalue); virtual int py_setattro(PyObject *attr, PyObject *pyvalue);
virtual bool IsLight(void) { return true; } virtual bool IsLight(void) { return true; }
}; };

View File

@@ -46,18 +46,21 @@
#include "PyObjectPlus.h" #include "PyObjectPlus.h"
PyTypeObject KX_MeshProxy::Type = { PyTypeObject KX_MeshProxy::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_MeshProxy", "KX_MeshProxy",
sizeof(KX_MeshProxy), sizeof(KX_MeshProxy),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -94,9 +97,11 @@ void KX_MeshProxy::SetMeshModified(bool v)
PyObject* PyObject*
KX_MeshProxy::_getattr(const char *attr) KX_MeshProxy::py_getattro(PyObject *attr)
{ {
if (!strcmp(attr, "materials")) char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str, "materials"))
{ {
PyObject *materials = PyList_New(0); PyObject *materials = PyList_New(0);
list<RAS_MeshMaterial>::iterator mit = m_meshobj->GetFirstMaterial(); list<RAS_MeshMaterial>::iterator mit = m_meshobj->GetFirstMaterial();
@@ -115,7 +120,7 @@ KX_MeshProxy::_getattr(const char *attr)
} }
return materials; return materials;
} }
_getattr_up(SCA_IObject); py_getattro_up(SCA_IObject);
} }

View File

@@ -54,7 +54,7 @@ public:
virtual CValue* GetReplica(); virtual CValue* GetReplica();
// stuff for python integration // stuff for python integration
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
KX_PYMETHOD(KX_MeshProxy,GetNumMaterials); KX_PYMETHOD(KX_MeshProxy,GetNumMaterials);
KX_PYMETHOD(KX_MeshProxy,GetMaterialName); KX_PYMETHOD(KX_MeshProxy,GetMaterialName);
KX_PYMETHOD(KX_MeshProxy,GetTextureName); KX_PYMETHOD(KX_MeshProxy,GetTextureName);

View File

@@ -293,18 +293,21 @@ bool KX_MouseFocusSensor::ParentObjectHasFocus(void)
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject KX_MouseFocusSensor::Type = { PyTypeObject KX_MouseFocusSensor::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_MouseFocusSensor", "KX_MouseFocusSensor",
sizeof(KX_MouseFocusSensor), sizeof(KX_MouseFocusSensor),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -333,8 +336,8 @@ PyAttributeDef KX_MouseFocusSensor::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* KX_MouseFocusSensor::_getattr(const char *attr) { PyObject* KX_MouseFocusSensor::py_getattro(PyObject *attr) {
_getattr_up(SCA_MouseSensor); py_getattro_up(SCA_MouseSensor);
} }

View File

@@ -87,7 +87,7 @@ class KX_MouseFocusSensor : public SCA_MouseSensor
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRayTarget); KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRayTarget);
KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRaySource); KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRaySource);

View File

@@ -287,18 +287,21 @@ bool KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
PyTypeObject KX_NearSensor::Type = { PyTypeObject KX_NearSensor::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_NearSensor", "KX_NearSensor",
sizeof(KX_NearSensor), sizeof(KX_NearSensor),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -327,20 +330,20 @@ PyAttributeDef KX_NearSensor::Attributes[] = {
}; };
PyObject* KX_NearSensor::_getattr(const char *attr) PyObject* KX_NearSensor::py_getattro(PyObject *attr)
{ {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(KX_TouchSensor); py_getattro_up(KX_TouchSensor);
} }
int KX_NearSensor::_setattr(const char *attr, PyObject* value) int KX_NearSensor::py_setattro(PyObject*attr, PyObject* value)
{ {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return KX_TouchSensor::_setattr(attr, value); return KX_TouchSensor::py_setattro(attr, value);
} }

View File

@@ -82,8 +82,8 @@ public:
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject* value); virtual int py_setattro(PyObject *attr, PyObject* value);
//No methods //No methods

View File

@@ -277,18 +277,21 @@ bool KX_ObjectActuator::isValid(KX_ObjectActuator::KX_OBJECT_ACT_VEC_TYPE type)
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject KX_ObjectActuator::Type = { PyTypeObject KX_ObjectActuator::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_ObjectActuator", "KX_ObjectActuator",
sizeof(KX_ObjectActuator), sizeof(KX_ObjectActuator),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -333,8 +336,8 @@ PyAttributeDef KX_ObjectActuator::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* KX_ObjectActuator::_getattr(const char *attr) { PyObject* KX_ObjectActuator::py_getattro(PyObject *attr) {
_getattr_up(SCA_IActuator); py_getattro_up(SCA_IActuator);
}; };
/* 1. set ------------------------------------------------------------------ */ /* 1. set ------------------------------------------------------------------ */

View File

@@ -153,7 +153,7 @@ public:
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForce); KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForce);
KX_PYMETHOD(KX_ObjectActuator,SetForce); KX_PYMETHOD(KX_ObjectActuator,SetForce);

View File

@@ -139,18 +139,21 @@ bool KX_ParentActuator::Update()
/* Integration hooks ------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */
PyTypeObject KX_ParentActuator::Type = { PyTypeObject KX_ParentActuator::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_ParentActuator", "KX_ParentActuator",
sizeof(KX_ParentActuator), sizeof(KX_ParentActuator),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -204,20 +207,20 @@ int KX_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE
} }
PyObject* KX_ParentActuator::_getattr(const char *attr) { PyObject* KX_ParentActuator::py_getattro(PyObject *attr) {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_IActuator); py_getattro_up(SCA_IActuator);
} }
int KX_ParentActuator::_setattr(const char *attr, PyObject* value) { int KX_ParentActuator::py_setattro(PyObject *attr, PyObject* value) {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_IActuator::_setattr(attr, value); return SCA_IActuator::py_setattro(attr, value);
} }
/* Deprecated -----> */ /* Deprecated -----> */

View File

@@ -76,8 +76,8 @@ class KX_ParentActuator : public SCA_IActuator
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject* value); virtual int py_setattro(PyObject *attr, PyObject* value);
/* These are used to get and set m_ob */ /* These are used to get and set m_ob */
static PyObject* pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);

View File

@@ -115,22 +115,27 @@ PyObject* KX_PhysicsObjectWrapper::PySetActive(PyObject* self,
} }
PyAttributeDef KX_PhysicsObjectWrapper::Attributes[] = {
{ NULL } //Sentinel
};
//python specific stuff //python specific stuff
PyTypeObject KX_PhysicsObjectWrapper::Type = { PyTypeObject KX_PhysicsObjectWrapper::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_PhysicsObjectWrapper", "KX_PhysicsObjectWrapper",
sizeof(KX_PhysicsObjectWrapper), sizeof(KX_PhysicsObjectWrapper),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -139,13 +144,13 @@ PyParentObject KX_PhysicsObjectWrapper::Parents[] = {
NULL NULL
}; };
PyObject* KX_PhysicsObjectWrapper::_getattr(const char *attr) PyObject* KX_PhysicsObjectWrapper::py_getattro(PyObject *attr)
{ {
_getattr_up(PyObjectPlus); py_getattro_up(PyObjectPlus);
} }
int KX_PhysicsObjectWrapper::_setattr(const char *attr,PyObject *pyobj) int KX_PhysicsObjectWrapper::py_setattro(PyObject *attr,PyObject *pyobj)
{ {
int result = 1; int result = 1;
@@ -158,7 +163,7 @@ int KX_PhysicsObjectWrapper::_setattr(const char *attr,PyObject *pyobj)
result = 0; result = 0;
} }
if (result) if (result)
result = PyObjectPlus::_setattr(attr,pyobj); result = PyObjectPlus::py_setattro(attr,pyobj);
return result; return result;
}; };

View File

@@ -36,8 +36,8 @@ class KX_PhysicsObjectWrapper : public PyObjectPlus
{ {
Py_Header; Py_Header;
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *value); virtual int py_setattro(PyObject *attr, PyObject *value);
public: public:
KX_PhysicsObjectWrapper(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsEnvironment* physenv,PyTypeObject *T = &Type); KX_PhysicsObjectWrapper(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsEnvironment* physenv,PyTypeObject *T = &Type);
virtual ~KX_PhysicsObjectWrapper(); virtual ~KX_PhysicsObjectWrapper();

View File

@@ -39,18 +39,21 @@
#include "KX_PyMath.h" #include "KX_PyMath.h"
PyTypeObject KX_PolyProxy::Type = { PyTypeObject KX_PolyProxy::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_PolyProxy", "KX_PolyProxy",
sizeof(KX_PolyProxy), sizeof(KX_PolyProxy),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -78,17 +81,18 @@ PyAttributeDef KX_PolyProxy::Attributes[] = {
{ NULL } //Sentinel { NULL } //Sentinel
}; };
PyObject* KX_PolyProxy::_getattr(const char *attr) PyObject* KX_PolyProxy::py_getattro(PyObject *attr)
{ {
if (!strcmp(attr, "matname")) char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str, "matname"))
{ {
return PyString_FromString(m_polygon->GetMaterial()->GetPolyMaterial()->GetMaterialName()); return PyString_FromString(m_polygon->GetMaterial()->GetPolyMaterial()->GetMaterialName());
} }
if (!strcmp(attr, "texture")) if (!strcmp(attr_str, "texture"))
{ {
return PyString_FromString(m_polygon->GetMaterial()->GetPolyMaterial()->GetTextureName()); return PyString_FromString(m_polygon->GetMaterial()->GetPolyMaterial()->GetTextureName());
} }
if (!strcmp(attr, "material")) if (!strcmp(attr_str, "material"))
{ {
RAS_IPolyMaterial *polymat = m_polygon->GetMaterial()->GetPolyMaterial(); RAS_IPolyMaterial *polymat = m_polygon->GetMaterial()->GetPolyMaterial();
if(polymat->GetFlag() & RAS_BLENDERMAT) if(polymat->GetFlag() & RAS_BLENDERMAT)
@@ -104,7 +108,7 @@ PyObject* KX_PolyProxy::_getattr(const char *attr)
return mat; return mat;
} }
} }
if (!strcmp(attr, "matid")) if (!strcmp(attr_str, "matid"))
{ {
// we'll have to scan through the material bucket of the mes and compare with // we'll have to scan through the material bucket of the mes and compare with
// the one of the polygon // the one of the polygon
@@ -119,31 +123,31 @@ PyObject* KX_PolyProxy::_getattr(const char *attr)
} }
return PyInt_FromLong(matid); return PyInt_FromLong(matid);
} }
if (!strcmp(attr, "v1")) if (!strcmp(attr_str, "v1"))
{ {
return PyInt_FromLong(m_polygon->GetVertexOffset(0)); return PyInt_FromLong(m_polygon->GetVertexOffset(0));
} }
if (!strcmp(attr, "v2")) if (!strcmp(attr_str, "v2"))
{ {
return PyInt_FromLong(m_polygon->GetVertexOffset(1)); return PyInt_FromLong(m_polygon->GetVertexOffset(1));
} }
if (!strcmp(attr, "v3")) if (!strcmp(attr_str, "v3"))
{ {
return PyInt_FromLong(m_polygon->GetVertexOffset(2)); return PyInt_FromLong(m_polygon->GetVertexOffset(2));
} }
if (!strcmp(attr, "v4")) if (!strcmp(attr_str, "v4"))
{ {
return PyInt_FromLong(((m_polygon->VertexCount()>3)?m_polygon->GetVertexOffset(3):0)); return PyInt_FromLong(((m_polygon->VertexCount()>3)?m_polygon->GetVertexOffset(3):0));
} }
if (!strcmp(attr, "visible")) if (!strcmp(attr_str, "visible"))
{ {
return PyInt_FromLong(m_polygon->IsVisible()); return PyInt_FromLong(m_polygon->IsVisible());
} }
if (!strcmp(attr, "collide")) if (!strcmp(attr_str, "collide"))
{ {
return PyInt_FromLong(m_polygon->IsCollider()); return PyInt_FromLong(m_polygon->IsCollider());
} }
_getattr_up(SCA_IObject); py_getattro_up(SCA_IObject);
} }
KX_PolyProxy::KX_PolyProxy(const RAS_MeshObject*mesh, RAS_Polygon* polygon) KX_PolyProxy::KX_PolyProxy(const RAS_MeshObject*mesh, RAS_Polygon* polygon)

View File

@@ -53,7 +53,7 @@ public:
// stuff for python integration // stuff for python integration
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getMaterialIndex) KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getMaterialIndex)
KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getNumVertex) KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getNumVertex)

View File

@@ -185,38 +185,42 @@ PyAttributeDef KX_PolygonMaterial::Attributes[] = {
}; };
PyTypeObject KX_PolygonMaterial::Type = { PyTypeObject KX_PolygonMaterial::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_PolygonMaterial", "KX_PolygonMaterial",
sizeof(KX_PolygonMaterial), sizeof(KX_PolygonMaterial),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
PyParentObject KX_PolygonMaterial::Parents[] = { PyParentObject KX_PolygonMaterial::Parents[] = {
&PyObjectPlus::Type,
&KX_PolygonMaterial::Type, &KX_PolygonMaterial::Type,
&PyObjectPlus::Type,
NULL NULL
}; };
PyObject* KX_PolygonMaterial::_getattr(const char *attr) PyObject* KX_PolygonMaterial::py_getattro(PyObject *attr)
{ {
if (!strcmp(attr, "texture")) char *attr_str= PyString_AsString(attr);
if (!strcmp(attr_str, "texture"))
return PyString_FromString(m_texturename.ReadPtr()); return PyString_FromString(m_texturename.ReadPtr());
if (!strcmp(attr, "material")) if (!strcmp(attr_str, "material"))
return PyString_FromString(m_materialname.ReadPtr()); return PyString_FromString(m_materialname.ReadPtr());
if (!strcmp(attr, "tface")) if (!strcmp(attr_str, "tface"))
return PyCObject_FromVoidPtr(m_tface, NULL); return PyCObject_FromVoidPtr(m_tface, NULL);
if (!strcmp(attr, "gl_texture")) if (!strcmp(attr_str, "gl_texture"))
{ {
Image *ima = m_tface->tpage; Image *ima = m_tface->tpage;
int bind = 0; int bind = 0;
@@ -226,49 +230,50 @@ PyObject* KX_PolygonMaterial::_getattr(const char *attr)
return PyInt_FromLong(bind); return PyInt_FromLong(bind);
} }
if (!strcmp(attr, "tile")) if (!strcmp(attr_str, "tile"))
return PyInt_FromLong(m_tile); return PyInt_FromLong(m_tile);
if (!strcmp(attr, "tilexrep")) if (!strcmp(attr_str, "tilexrep"))
return PyInt_FromLong(m_tilexrep); return PyInt_FromLong(m_tilexrep);
if (!strcmp(attr, "tileyrep")) if (!strcmp(attr_str, "tileyrep"))
return PyInt_FromLong(m_tileyrep); return PyInt_FromLong(m_tileyrep);
if (!strcmp(attr, "drawingmode")) if (!strcmp(attr_str, "drawingmode"))
return PyInt_FromLong(m_drawingmode); return PyInt_FromLong(m_drawingmode);
if (!strcmp(attr, "transparent")) if (!strcmp(attr_str, "transparent"))
return PyInt_FromLong(m_alpha); return PyInt_FromLong(m_alpha);
if (!strcmp(attr, "zsort")) if (!strcmp(attr_str, "zsort"))
return PyInt_FromLong(m_zsort); return PyInt_FromLong(m_zsort);
if (!strcmp(attr, "lightlayer")) if (!strcmp(attr_str, "lightlayer"))
return PyInt_FromLong(m_lightlayer); return PyInt_FromLong(m_lightlayer);
if (!strcmp(attr, "triangle")) if (!strcmp(attr_str, "triangle"))
// deprecated, triangle/quads shouldn't have been a material property // deprecated, triangle/quads shouldn't have been a material property
return 0; return 0;
if (!strcmp(attr, "diffuse")) if (!strcmp(attr_str, "diffuse"))
return PyObjectFrom(m_diffuse); return PyObjectFrom(m_diffuse);
if (!strcmp(attr, "shininess")) if (!strcmp(attr_str, "shininess"))
return PyFloat_FromDouble(m_shininess); return PyFloat_FromDouble(m_shininess);
if (!strcmp(attr, "specular")) if (!strcmp(attr_str, "specular"))
return PyObjectFrom(m_specular); return PyObjectFrom(m_specular);
if (!strcmp(attr, "specularity")) if (!strcmp(attr_str, "specularity"))
return PyFloat_FromDouble(m_specularity); return PyFloat_FromDouble(m_specularity);
_getattr_up(PyObjectPlus); py_getattro_up(PyObjectPlus);
} }
int KX_PolygonMaterial::_setattr(const char *attr, PyObject *pyvalue) int KX_PolygonMaterial::py_setattro(PyObject *attr, PyObject *pyvalue)
{ {
char *attr_str= PyString_AsString(attr);
if (PyFloat_Check(pyvalue)) if (PyFloat_Check(pyvalue))
{ {
float value = PyFloat_AsDouble(pyvalue); float value = PyFloat_AsDouble(pyvalue);
if (!strcmp(attr, "shininess")) if (!strcmp(attr_str, "shininess"))
{ {
m_shininess = value; m_shininess = value;
return 0; return 0;
} }
if (!strcmp(attr, "specularity")) if (!strcmp(attr_str, "specularity"))
{ {
m_specularity = value; m_specularity = value;
return 0; return 0;
@@ -278,50 +283,50 @@ int KX_PolygonMaterial::_setattr(const char *attr, PyObject *pyvalue)
if (PyInt_Check(pyvalue)) if (PyInt_Check(pyvalue))
{ {
int value = PyInt_AsLong(pyvalue); int value = PyInt_AsLong(pyvalue);
if (!strcmp(attr, "tile")) if (!strcmp(attr_str, "tile"))
{ {
m_tile = value; m_tile = value;
return 0; return 0;
} }
if (!strcmp(attr, "tilexrep")) if (!strcmp(attr_str, "tilexrep"))
{ {
m_tilexrep = value; m_tilexrep = value;
return 0; return 0;
} }
if (!strcmp(attr, "tileyrep")) if (!strcmp(attr_str, "tileyrep"))
{ {
m_tileyrep = value; m_tileyrep = value;
return 0; return 0;
} }
if (!strcmp(attr, "drawingmode")) if (!strcmp(attr_str, "drawingmode"))
{ {
m_drawingmode = value; m_drawingmode = value;
return 0; return 0;
} }
if (!strcmp(attr, "transparent")) if (!strcmp(attr_str, "transparent"))
{ {
m_alpha = value; m_alpha = value;
return 0; return 0;
} }
if (!strcmp(attr, "zsort")) if (!strcmp(attr_str, "zsort"))
{ {
m_zsort = value; m_zsort = value;
return 0; return 0;
} }
if (!strcmp(attr, "lightlayer")) if (!strcmp(attr_str, "lightlayer"))
{ {
m_lightlayer = value; m_lightlayer = value;
return 0; return 0;
} }
// This probably won't work... // This probably won't work...
if (!strcmp(attr, "triangle")) if (!strcmp(attr_str, "triangle"))
{ {
// deprecated, triangle/quads shouldn't have been a material property // deprecated, triangle/quads shouldn't have been a material property
return 0; return 0;
@@ -335,13 +340,13 @@ int KX_PolygonMaterial::_setattr(const char *attr, PyObject *pyvalue)
MT_Vector3 value; MT_Vector3 value;
if (PyVecTo(pyvalue, value)) if (PyVecTo(pyvalue, value))
{ {
if (!strcmp(attr, "diffuse")) if (!strcmp(attr_str, "diffuse"))
{ {
m_diffuse = value; m_diffuse = value;
return 0; return 0;
} }
if (!strcmp(attr, "specular")) if (!strcmp(attr_str, "specular"))
{ {
m_specular = value; m_specular = value;
return 0; return 0;
@@ -350,7 +355,7 @@ int KX_PolygonMaterial::_setattr(const char *attr, PyObject *pyvalue)
} }
} }
return PyObjectPlus::_setattr(attr, pyvalue); return PyObjectPlus::py_setattro(attr, pyvalue);
} }
KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setCustomMaterial, "setCustomMaterial(material)") KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setCustomMaterial, "setCustomMaterial(material)")

View File

@@ -115,8 +115,8 @@ public:
KX_PYMETHOD_DOC(KX_PolygonMaterial, setCustomMaterial); KX_PYMETHOD_DOC(KX_PolygonMaterial, setCustomMaterial);
KX_PYMETHOD_DOC(KX_PolygonMaterial, loadProgram); KX_PYMETHOD_DOC(KX_PolygonMaterial, loadProgram);
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject *pyvalue); virtual int py_setattro(PyObject *attr, PyObject *pyvalue);
}; };
#endif // __KX_POLYGONMATERIAL_H__ #endif // __KX_POLYGONMATERIAL_H__

View File

@@ -71,7 +71,9 @@
#include "KX_PyMath.h" #include "KX_PyMath.h"
#include "PyObjectPlus.h" #include "PyObjectPlus.h"
#include "KX_PythonInitTypes.h"
extern "C" { extern "C" {
#include "Mathutils.h" // Blender.Mathutils module copied here so the blenderlayer can use. #include "Mathutils.h" // Blender.Mathutils module copied here so the blenderlayer can use.
@@ -1257,6 +1259,7 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur
//importBlenderModules() //importBlenderModules()
setSandbox(level); setSandbox(level);
initPyTypes();
PyObject* moduleobj = PyImport_AddModule("__main__"); PyObject* moduleobj = PyImport_AddModule("__main__");
return PyModule_GetDict(moduleobj); return PyModule_GetDict(moduleobj);
@@ -1278,6 +1281,7 @@ PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLev
Py_FrozenFlag=1; Py_FrozenFlag=1;
setSandbox(level); setSandbox(level);
initPyTypes();
PyObject* moduleobj = PyImport_AddModule("__main__"); PyObject* moduleobj = PyImport_AddModule("__main__");
return PyModule_GetDict(moduleobj); return PyModule_GetDict(moduleobj);

View File

@@ -0,0 +1,204 @@
/**
* $Id: PyObjectPlus.h 19511 2009-04-03 02:16:56Z campbellbarton $
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef _adr_py_init_types_h_ // only process once,
#define _adr_py_init_types_h_ // even if multiply included
/* Only for Class::Parents */
#include "BL_BlenderShader.h"
#include "BL_ShapeActionActuator.h"
#include "KX_BlenderMaterial.h"
#include "KX_CDActuator.h"
#include "KX_CameraActuator.h"
#include "KX_ConstraintActuator.h"
#include "KX_ConstraintWrapper.h"
#include "KX_GameActuator.h"
#include "KX_Light.h"
#include "KX_MeshProxy.h"
#include "KX_MouseFocusSensor.h"
#include "KX_NetworkMessageActuator.h"
#include "KX_NetworkMessageSensor.h"
#include "KX_ObjectActuator.h"
#include "KX_ParentActuator.h"
#include "KX_PhysicsObjectWrapper.h"
#include "KX_PolyProxy.h"
#include "KX_PolygonMaterial.h"
#include "KX_SCA_AddObjectActuator.h"
#include "KX_SCA_EndObjectActuator.h"
#include "KX_SCA_ReplaceMeshActuator.h"
#include "KX_SceneActuator.h"
#include "KX_StateActuator.h"
#include "KX_TrackToActuator.h"
#include "KX_VehicleWrapper.h"
#include "KX_VertexProxy.h"
#include "SCA_2DFilterActuator.h"
#include "SCA_ANDController.h"
#include "SCA_ActuatorSensor.h"
#include "SCA_AlwaysSensor.h"
#include "SCA_DelaySensor.h"
#include "SCA_JoystickSensor.h"
#include "SCA_KeyboardSensor.h"
#include "SCA_MouseSensor.h"
#include "SCA_NANDController.h"
#include "SCA_NORController.h"
#include "SCA_ORController.h"
#include "SCA_RandomSensor.h"
#include "SCA_XNORController.h"
#include "SCA_XORController.h"
#include "KX_IpoActuator.h"
#include "KX_NearSensor.h"
#include "KX_RadarSensor.h"
#include "KX_RaySensor.h"
#include "KX_SCA_DynamicActuator.h"
#include "KX_SoundActuator.h"
#include "KX_TouchSensor.h"
#include "SCA_PropertySensor.h"
#include "SCA_PythonController.h"
#include "SCA_RandomActuator.h"
void initPyObjectPlusType(PyTypeObject **parents)
{
int i;
for (i=0; parents[i]; i++) {
if(PyType_Ready(parents[i]) < 0) {
/* This is very very unlikely */
printf("Error, pytype could not initialize, Blender may crash \"%s\"\n", parents[i]->tp_name);
return;
}
#if 0
PyObject_Print((PyObject *)parents[i], stderr, 0);
fprintf(stderr, "\n");
PyObject_Print(parents[i]->tp_dict, stderr, 0);
fprintf(stderr, "\n\n");
#endif
}
PyObject *dict= NULL;
while(i) {
i--;
if (dict) {
PyDict_Update(parents[i]->tp_dict, dict);
}
dict= parents[i]->tp_dict;
#if 1
PyObject_Print((PyObject *)parents[i], stderr, 0);
fprintf(stderr, "\n");
PyObject_Print(parents[i]->tp_dict, stderr, 0);
fprintf(stderr, "\n\n");
#endif
}
}
void initPyTypes(void)
{
/*
initPyObjectPlusType(BL_ActionActuator::Parents);
.....
*/
/* For now just do PyType_Ready */
PyType_Ready(&BL_ActionActuator::Type);
PyType_Ready(&BL_Shader::Type);
PyType_Ready(&BL_ShapeActionActuator::Type);
PyType_Ready(&CListValue::Type);
PyType_Ready(&CValue::Type);
PyType_Ready(&KX_BlenderMaterial::Type);
PyType_Ready(&KX_CDActuator::Type);
PyType_Ready(&KX_Camera::Type);
PyType_Ready(&KX_CameraActuator::Type);
PyType_Ready(&KX_ConstraintActuator::Type);
PyType_Ready(&KX_ConstraintWrapper::Type);
PyType_Ready(&KX_GameActuator::Type);
PyType_Ready(&KX_GameObject::Type);
PyType_Ready(&KX_IpoActuator::Type);
PyType_Ready(&KX_LightObject::Type);
PyType_Ready(&KX_MeshProxy::Type);
PyType_Ready(&KX_MouseFocusSensor::Type);
PyType_Ready(&KX_NearSensor::Type);
PyType_Ready(&KX_NetworkMessageActuator::Type);
PyType_Ready(&KX_NetworkMessageSensor::Type);
PyType_Ready(&KX_ObjectActuator::Type);
PyType_Ready(&KX_ParentActuator::Type);
PyType_Ready(&KX_PhysicsObjectWrapper::Type);
PyType_Ready(&KX_PolyProxy::Type);
PyType_Ready(&KX_PolygonMaterial::Type);
PyType_Ready(&KX_RadarSensor::Type);
PyType_Ready(&KX_RaySensor::Type);
PyType_Ready(&KX_SCA_AddObjectActuator::Type);
PyType_Ready(&KX_SCA_DynamicActuator::Type);
PyType_Ready(&KX_SCA_EndObjectActuator::Type);
PyType_Ready(&KX_SCA_ReplaceMeshActuator::Type);
PyType_Ready(&KX_Scene::Type);
PyType_Ready(&KX_SceneActuator::Type);
PyType_Ready(&KX_SoundActuator::Type);
PyType_Ready(&KX_StateActuator::Type);
PyType_Ready(&KX_TouchSensor::Type);
PyType_Ready(&KX_TrackToActuator::Type);
PyType_Ready(&KX_VehicleWrapper::Type);
PyType_Ready(&KX_VertexProxy::Type);
PyType_Ready(&PyObjectPlus::Type);
PyType_Ready(&SCA_2DFilterActuator::Type);
PyType_Ready(&SCA_ANDController::Type);
PyType_Ready(&SCA_ActuatorSensor::Type);
PyType_Ready(&SCA_AlwaysSensor::Type);
PyType_Ready(&SCA_DelaySensor::Type);
PyType_Ready(&SCA_ILogicBrick::Type);
PyType_Ready(&SCA_IObject::Type);
PyType_Ready(&SCA_ISensor::Type);
PyType_Ready(&SCA_JoystickSensor::Type);
PyType_Ready(&SCA_KeyboardSensor::Type);
PyType_Ready(&SCA_MouseSensor::Type);
PyType_Ready(&SCA_NANDController::Type);
PyType_Ready(&SCA_NORController::Type);
PyType_Ready(&SCA_ORController::Type);
PyType_Ready(&SCA_PropertyActuator::Type);
PyType_Ready(&SCA_PropertySensor::Type);
PyType_Ready(&SCA_PythonController::Type);
PyType_Ready(&SCA_RandomActuator::Type);
PyType_Ready(&SCA_RandomSensor::Type);
PyType_Ready(&SCA_XNORController::Type);
PyType_Ready(&SCA_XORController::Type);
}
#endif

View File

@@ -0,0 +1,35 @@
/**
* $Id: PyObjectPlus.h 19511 2009-04-03 02:16:56Z campbellbarton $
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef _adr_py_init_types_h_ // only process once,
#define _adr_py_init_types_h_ // even if multiply included
void initPyTypes(void);
#endif

View File

@@ -250,18 +250,21 @@ PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self) {
/* Python Integration Hooks */ /* Python Integration Hooks */
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
PyTypeObject KX_RadarSensor::Type = { PyTypeObject KX_RadarSensor::Type = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, 0,
"KX_RadarSensor", "KX_RadarSensor",
sizeof(KX_RadarSensor), sizeof(KX_RadarSensor),
0, 0,
PyDestructor, PyDestructor,
0, 0,
__getattr,
__setattr,
0, 0,
__repr, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods Methods
}; };
@@ -295,20 +298,20 @@ PyAttributeDef KX_RadarSensor::Attributes[] = {
{NULL} //Sentinel {NULL} //Sentinel
}; };
PyObject* KX_RadarSensor::_getattr(const char *attr) PyObject* KX_RadarSensor::py_getattro(PyObject *attr)
{ {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object = py_getattro_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(KX_NearSensor); py_getattro_up(KX_NearSensor);
} }
int KX_RadarSensor::_setattr(const char *attr, PyObject* value) int KX_RadarSensor::py_setattro(PyObject *attr, PyObject* value)
{ {
int ret = _setattr_self(Attributes, this, attr, value); int ret = py_setattro_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return KX_NearSensor::_setattr(attr, value); return KX_NearSensor::py_setattro(attr, value);
} }

View File

@@ -89,8 +89,8 @@ public:
KX_RADAR_AXIS_NEG_Z KX_RADAR_AXIS_NEG_Z
}; };
virtual PyObject* _getattr(const char *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int _setattr(const char *attr, PyObject* value); virtual int py_setattro(PyObject *attr, PyObject* value);
//Deprecated -----> //Deprecated ----->
KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeOrigin); KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeOrigin);

Some files were not shown because too many files have changed in this diff Show More