BGE Python API
Use each types dictionary to store attributes PyAttributeDef's so it uses pythons hash lookup (which it was already doing for methods) rather then doing a string lookup on the array each time. This also means attributes can be found in the type without having to do a dir() on the instance.
This commit is contained in:
@@ -1037,21 +1037,14 @@ PyAttributeDef BL_ActionActuator::Attributes[] = {
|
||||
};
|
||||
|
||||
PyObject* BL_ActionActuator::py_getattro(PyObject *attr) {
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int BL_ActionActuator::py_setattro(PyObject *attr, PyObject* value) {
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PyObject* BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
|
||||
|
||||
@@ -486,17 +486,11 @@ PyAttributeDef BL_ShapeActionActuator::Attributes[] = {
|
||||
|
||||
|
||||
PyObject* BL_ShapeActionActuator::py_getattro(PyObject* attr) {
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int BL_ShapeActionActuator::py_setattro(PyObject *attr, PyObject* value) {
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
/* setStart */
|
||||
|
||||
@@ -98,6 +98,10 @@ PyMethodDef PyObjectPlus::Methods[] = {
|
||||
{NULL, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyAttributeDef PyObjectPlus::Attributes[] = {
|
||||
{NULL} //Sentinel
|
||||
};
|
||||
|
||||
/*------------------------------
|
||||
* PyObjectPlus Parents -- Every class, even the abstract one should have parents
|
||||
------------------------------*/
|
||||
@@ -136,128 +140,555 @@ int PyObjectPlus::py_setattro(PyObject *attr, PyObject* value)
|
||||
return 1;
|
||||
}
|
||||
|
||||
PyObject *PyObjectPlus::py_get_attrdef(void *self, const PyAttributeDef *attrdef)
|
||||
{
|
||||
if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY)
|
||||
{
|
||||
// fake attribute, ignore
|
||||
return NULL;
|
||||
}
|
||||
if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION)
|
||||
{
|
||||
// the attribute has no field correspondance, handover processing to function.
|
||||
if (attrdef->m_getFunction == NULL)
|
||||
return NULL;
|
||||
return (*attrdef->m_getFunction)(self, attrdef);
|
||||
}
|
||||
char *ptr = reinterpret_cast<char*>(self)+attrdef->m_offset;
|
||||
if (attrdef->m_length > 1)
|
||||
{
|
||||
PyObject* resultlist = PyList_New(attrdef->m_length);
|
||||
for (unsigned int i=0; i<attrdef->m_length; i++)
|
||||
{
|
||||
switch (attrdef->m_type) {
|
||||
case KX_PYATTRIBUTE_TYPE_BOOL:
|
||||
{
|
||||
bool *val = reinterpret_cast<bool*>(ptr);
|
||||
ptr += sizeof(bool);
|
||||
PyList_SetItem(resultlist,i,PyInt_FromLong(*val));
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_SHORT:
|
||||
{
|
||||
short int *val = reinterpret_cast<short int*>(ptr);
|
||||
ptr += sizeof(short int);
|
||||
PyList_SetItem(resultlist,i,PyInt_FromLong(*val));
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_ENUM:
|
||||
// enum are like int, just make sure the field size is the same
|
||||
if (sizeof(int) != attrdef->m_size)
|
||||
{
|
||||
Py_DECREF(resultlist);
|
||||
return NULL;
|
||||
}
|
||||
// walkthrough
|
||||
case KX_PYATTRIBUTE_TYPE_INT:
|
||||
{
|
||||
int *val = reinterpret_cast<int*>(ptr);
|
||||
ptr += sizeof(int);
|
||||
PyList_SetItem(resultlist,i,PyInt_FromLong(*val));
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_FLOAT:
|
||||
{
|
||||
float *val = reinterpret_cast<float*>(ptr);
|
||||
ptr += sizeof(float);
|
||||
PyList_SetItem(resultlist,i,PyFloat_FromDouble(*val));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// no support for array of complex data
|
||||
Py_DECREF(resultlist);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return resultlist;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (attrdef->m_type) {
|
||||
case KX_PYATTRIBUTE_TYPE_BOOL:
|
||||
{
|
||||
bool *val = reinterpret_cast<bool*>(ptr);
|
||||
return PyInt_FromLong(*val);
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_SHORT:
|
||||
{
|
||||
short int *val = reinterpret_cast<short int*>(ptr);
|
||||
return PyInt_FromLong(*val);
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_ENUM:
|
||||
// enum are like int, just make sure the field size is the same
|
||||
if (sizeof(int) != attrdef->m_size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
// walkthrough
|
||||
case KX_PYATTRIBUTE_TYPE_INT:
|
||||
{
|
||||
int *val = reinterpret_cast<int*>(ptr);
|
||||
return PyInt_FromLong(*val);
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_FLOAT:
|
||||
{
|
||||
float *val = reinterpret_cast<float*>(ptr);
|
||||
return PyFloat_FromDouble(*val);
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_STRING:
|
||||
{
|
||||
STR_String *val = reinterpret_cast<STR_String*>(ptr);
|
||||
return PyString_FromString(*val);
|
||||
}
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
PyObject *PyObjectPlus::py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr)
|
||||
{
|
||||
char *attr_str= PyString_AsString(attr);
|
||||
|
||||
const PyAttributeDef *attrdef;
|
||||
|
||||
for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++)
|
||||
{
|
||||
if (!strcmp(attr_str, attrdef->m_name))
|
||||
{
|
||||
if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY)
|
||||
{
|
||||
// fake attribute, ignore
|
||||
return NULL;
|
||||
}
|
||||
if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION)
|
||||
{
|
||||
// the attribute has no field correspondance, handover processing to function.
|
||||
if (attrdef->m_getFunction == NULL)
|
||||
return NULL;
|
||||
return (*attrdef->m_getFunction)(self, attrdef);
|
||||
}
|
||||
char *ptr = reinterpret_cast<char*>(self)+attrdef->m_offset;
|
||||
if (attrdef->m_length > 1)
|
||||
{
|
||||
PyObject* resultlist = PyList_New(attrdef->m_length);
|
||||
for (unsigned int i=0; i<attrdef->m_length; i++)
|
||||
{
|
||||
switch (attrdef->m_type) {
|
||||
case KX_PYATTRIBUTE_TYPE_BOOL:
|
||||
{
|
||||
bool *val = reinterpret_cast<bool*>(ptr);
|
||||
ptr += sizeof(bool);
|
||||
PyList_SetItem(resultlist,i,PyInt_FromLong(*val));
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_SHORT:
|
||||
{
|
||||
short int *val = reinterpret_cast<short int*>(ptr);
|
||||
ptr += sizeof(short int);
|
||||
PyList_SetItem(resultlist,i,PyInt_FromLong(*val));
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_ENUM:
|
||||
// enum are like int, just make sure the field size is the same
|
||||
if (sizeof(int) != attrdef->m_size)
|
||||
{
|
||||
Py_DECREF(resultlist);
|
||||
return NULL;
|
||||
}
|
||||
// walkthrough
|
||||
case KX_PYATTRIBUTE_TYPE_INT:
|
||||
{
|
||||
int *val = reinterpret_cast<int*>(ptr);
|
||||
ptr += sizeof(int);
|
||||
PyList_SetItem(resultlist,i,PyInt_FromLong(*val));
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_FLOAT:
|
||||
{
|
||||
float *val = reinterpret_cast<float*>(ptr);
|
||||
ptr += sizeof(float);
|
||||
PyList_SetItem(resultlist,i,PyFloat_FromDouble(*val));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// no support for array of complex data
|
||||
Py_DECREF(resultlist);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return resultlist;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (attrdef->m_type) {
|
||||
case KX_PYATTRIBUTE_TYPE_BOOL:
|
||||
{
|
||||
bool *val = reinterpret_cast<bool*>(ptr);
|
||||
return PyInt_FromLong(*val);
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_SHORT:
|
||||
{
|
||||
short int *val = reinterpret_cast<short int*>(ptr);
|
||||
return PyInt_FromLong(*val);
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_ENUM:
|
||||
// enum are like int, just make sure the field size is the same
|
||||
if (sizeof(int) != attrdef->m_size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
// walkthrough
|
||||
case KX_PYATTRIBUTE_TYPE_INT:
|
||||
{
|
||||
int *val = reinterpret_cast<int*>(ptr);
|
||||
return PyInt_FromLong(*val);
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_FLOAT:
|
||||
{
|
||||
float *val = reinterpret_cast<float*>(ptr);
|
||||
return PyFloat_FromDouble(*val);
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_STRING:
|
||||
{
|
||||
STR_String *val = reinterpret_cast<STR_String*>(ptr);
|
||||
return PyString_FromString(*val);
|
||||
}
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return py_get_attrdef(self, attrdef);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
int PyObjectPlus::py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value)
|
||||
int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyObject *value)
|
||||
{
|
||||
const PyAttributeDef *attrdef;
|
||||
void *undoBuffer = NULL;
|
||||
void *sourceBuffer = NULL;
|
||||
size_t bufferSize = 0;
|
||||
|
||||
char *ptr = reinterpret_cast<char*>(self)+attrdef->m_offset;
|
||||
if (attrdef->m_length > 1)
|
||||
{
|
||||
if (!PySequence_Check(value))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected a sequence");
|
||||
return 1;
|
||||
}
|
||||
if (PySequence_Size(value) != attrdef->m_length)
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "incorrect number of elements in sequence");
|
||||
return 1;
|
||||
}
|
||||
switch (attrdef->m_type)
|
||||
{
|
||||
case KX_PYATTRIBUTE_TYPE_FUNCTION:
|
||||
if (attrdef->m_setFunction == NULL)
|
||||
{
|
||||
PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org");
|
||||
return 1;
|
||||
}
|
||||
return (*attrdef->m_setFunction)(self, attrdef, value);
|
||||
case KX_PYATTRIBUTE_TYPE_BOOL:
|
||||
bufferSize = sizeof(bool);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_SHORT:
|
||||
bufferSize = sizeof(short int);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_ENUM:
|
||||
case KX_PYATTRIBUTE_TYPE_INT:
|
||||
bufferSize = sizeof(int);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_FLOAT:
|
||||
bufferSize = sizeof(float);
|
||||
break;
|
||||
default:
|
||||
// should not happen
|
||||
PyErr_SetString(PyExc_AttributeError, "Unsupported attribute type, report to blender.org");
|
||||
return 1;
|
||||
}
|
||||
// let's implement a smart undo method
|
||||
bufferSize *= attrdef->m_length;
|
||||
undoBuffer = malloc(bufferSize);
|
||||
sourceBuffer = ptr;
|
||||
if (undoBuffer)
|
||||
{
|
||||
memcpy(undoBuffer, sourceBuffer, bufferSize);
|
||||
}
|
||||
for (int i=0; i<attrdef->m_length; i++)
|
||||
{
|
||||
PyObject *item = PySequence_GetItem(value, i); /* new ref */
|
||||
// we can decrement the reference immediately, the reference count
|
||||
// is at least 1 because the item is part of an array
|
||||
Py_DECREF(item);
|
||||
switch (attrdef->m_type)
|
||||
{
|
||||
case KX_PYATTRIBUTE_TYPE_BOOL:
|
||||
{
|
||||
bool *var = reinterpret_cast<bool*>(ptr);
|
||||
ptr += sizeof(bool);
|
||||
if (PyInt_Check(item))
|
||||
{
|
||||
*var = (PyInt_AsLong(item) != 0);
|
||||
}
|
||||
else if (PyBool_Check(item))
|
||||
{
|
||||
*var = (item == Py_True);
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected an integer or a bool");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_SHORT:
|
||||
{
|
||||
short int *var = reinterpret_cast<short int*>(ptr);
|
||||
ptr += sizeof(short int);
|
||||
if (PyInt_Check(item))
|
||||
{
|
||||
long val = PyInt_AsLong(item);
|
||||
if (attrdef->m_clamp)
|
||||
{
|
||||
if (val < attrdef->m_imin)
|
||||
val = attrdef->m_imin;
|
||||
else if (val > attrdef->m_imax)
|
||||
val = attrdef->m_imax;
|
||||
}
|
||||
else if (val < attrdef->m_imin || val > attrdef->m_imax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "item value out of range");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
*var = (short int)val;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected an integer");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_ENUM:
|
||||
// enum are equivalent to int, just make sure that the field size matches:
|
||||
if (sizeof(int) != attrdef->m_size)
|
||||
{
|
||||
PyErr_SetString(PyExc_AttributeError, "attribute size check error, report to blender.org");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
// walkthrough
|
||||
case KX_PYATTRIBUTE_TYPE_INT:
|
||||
{
|
||||
int *var = reinterpret_cast<int*>(ptr);
|
||||
ptr += sizeof(int);
|
||||
if (PyInt_Check(item))
|
||||
{
|
||||
long val = PyInt_AsLong(item);
|
||||
if (attrdef->m_clamp)
|
||||
{
|
||||
if (val < attrdef->m_imin)
|
||||
val = attrdef->m_imin;
|
||||
else if (val > attrdef->m_imax)
|
||||
val = attrdef->m_imax;
|
||||
}
|
||||
else if (val < attrdef->m_imin || val > attrdef->m_imax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "item value out of range");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
*var = (int)val;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected an integer");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_FLOAT:
|
||||
{
|
||||
float *var = reinterpret_cast<float*>(ptr);
|
||||
ptr += sizeof(float);
|
||||
double val = PyFloat_AsDouble(item);
|
||||
if (val == -1.0 && PyErr_Occurred())
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected a float");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
else if (attrdef->m_clamp)
|
||||
{
|
||||
if (val < attrdef->m_fmin)
|
||||
val = attrdef->m_fmin;
|
||||
else if (val > attrdef->m_fmax)
|
||||
val = attrdef->m_fmax;
|
||||
}
|
||||
else if (val < attrdef->m_fmin || val > attrdef->m_fmax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "item value out of range");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
*var = (float)val;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// should not happen
|
||||
PyErr_SetString(PyExc_AttributeError, "attribute type check error, report to blender.org");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
}
|
||||
// no error, call check function if any
|
||||
if (attrdef->m_checkFunction != NULL)
|
||||
{
|
||||
if ((*attrdef->m_checkFunction)(self, attrdef) != 0)
|
||||
{
|
||||
// post check returned an error, restore values
|
||||
UNDO_AND_ERROR:
|
||||
if (undoBuffer)
|
||||
{
|
||||
memcpy(sourceBuffer, undoBuffer, bufferSize);
|
||||
free(undoBuffer);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (undoBuffer)
|
||||
free(undoBuffer);
|
||||
return 0;
|
||||
}
|
||||
else // simple attribute value
|
||||
{
|
||||
if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION)
|
||||
{
|
||||
if (attrdef->m_setFunction == NULL)
|
||||
{
|
||||
PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org");
|
||||
return 1;
|
||||
}
|
||||
return (*attrdef->m_setFunction)(self, attrdef, value);
|
||||
}
|
||||
if (attrdef->m_checkFunction != NULL)
|
||||
{
|
||||
// post check function is provided, prepare undo buffer
|
||||
sourceBuffer = ptr;
|
||||
switch (attrdef->m_type)
|
||||
{
|
||||
case KX_PYATTRIBUTE_TYPE_BOOL:
|
||||
bufferSize = sizeof(bool);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_SHORT:
|
||||
bufferSize = sizeof(short);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_ENUM:
|
||||
case KX_PYATTRIBUTE_TYPE_INT:
|
||||
bufferSize = sizeof(int);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_FLOAT:
|
||||
bufferSize = sizeof(float);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_STRING:
|
||||
sourceBuffer = reinterpret_cast<STR_String*>(ptr)->Ptr();
|
||||
if (sourceBuffer)
|
||||
bufferSize = strlen(reinterpret_cast<char*>(sourceBuffer))+1;
|
||||
break;
|
||||
default:
|
||||
PyErr_SetString(PyExc_AttributeError, "unknown attribute type, report to blender.org");
|
||||
return 1;
|
||||
}
|
||||
if (bufferSize)
|
||||
{
|
||||
undoBuffer = malloc(bufferSize);
|
||||
if (undoBuffer)
|
||||
{
|
||||
memcpy(undoBuffer, sourceBuffer, bufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (attrdef->m_type)
|
||||
{
|
||||
case KX_PYATTRIBUTE_TYPE_BOOL:
|
||||
{
|
||||
bool *var = reinterpret_cast<bool*>(ptr);
|
||||
if (PyInt_Check(value))
|
||||
{
|
||||
*var = (PyInt_AsLong(value) != 0);
|
||||
}
|
||||
else if (PyBool_Check(value))
|
||||
{
|
||||
*var = (value == Py_True);
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected an integer or a bool");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_SHORT:
|
||||
{
|
||||
short int *var = reinterpret_cast<short int*>(ptr);
|
||||
if (PyInt_Check(value))
|
||||
{
|
||||
long val = PyInt_AsLong(value);
|
||||
if (attrdef->m_clamp)
|
||||
{
|
||||
if (val < attrdef->m_imin)
|
||||
val = attrdef->m_imin;
|
||||
else if (val > attrdef->m_imax)
|
||||
val = attrdef->m_imax;
|
||||
}
|
||||
else if (val < attrdef->m_imin || val > attrdef->m_imax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "value out of range");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
*var = (short int)val;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected an integer");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_ENUM:
|
||||
// enum are equivalent to int, just make sure that the field size matches:
|
||||
if (sizeof(int) != attrdef->m_size)
|
||||
{
|
||||
PyErr_SetString(PyExc_AttributeError, "attribute size check error, report to blender.org");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
// walkthrough
|
||||
case KX_PYATTRIBUTE_TYPE_INT:
|
||||
{
|
||||
int *var = reinterpret_cast<int*>(ptr);
|
||||
if (PyInt_Check(value))
|
||||
{
|
||||
long val = PyInt_AsLong(value);
|
||||
if (attrdef->m_clamp)
|
||||
{
|
||||
if (val < attrdef->m_imin)
|
||||
val = attrdef->m_imin;
|
||||
else if (val > attrdef->m_imax)
|
||||
val = attrdef->m_imax;
|
||||
}
|
||||
else if (val < attrdef->m_imin || val > attrdef->m_imax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "value out of range");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
*var = (int)val;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected an integer");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_FLOAT:
|
||||
{
|
||||
float *var = reinterpret_cast<float*>(ptr);
|
||||
double val = PyFloat_AsDouble(value);
|
||||
if (val == -1.0 && PyErr_Occurred())
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected a float");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
else if (attrdef->m_clamp)
|
||||
{
|
||||
if (val < attrdef->m_fmin)
|
||||
val = attrdef->m_fmin;
|
||||
else if (val > attrdef->m_fmax)
|
||||
val = attrdef->m_fmax;
|
||||
}
|
||||
else if (val < attrdef->m_fmin || val > attrdef->m_fmax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "value out of range");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
*var = (float)val;
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_STRING:
|
||||
{
|
||||
STR_String *var = reinterpret_cast<STR_String*>(ptr);
|
||||
if (PyString_Check(value))
|
||||
{
|
||||
char *val = PyString_AsString(value);
|
||||
if (attrdef->m_clamp)
|
||||
{
|
||||
if (strlen(val) < attrdef->m_imin)
|
||||
{
|
||||
// can't increase the length of the string
|
||||
PyErr_SetString(PyExc_ValueError, "string length too short");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
else if (strlen(val) > attrdef->m_imax)
|
||||
{
|
||||
// trim the string
|
||||
char c = val[attrdef->m_imax];
|
||||
val[attrdef->m_imax] = 0;
|
||||
*var = val;
|
||||
val[attrdef->m_imax] = c;
|
||||
break;
|
||||
}
|
||||
} else if (strlen(val) < attrdef->m_imin || strlen(val) > attrdef->m_imax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "string length out of range");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
*var = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected a string");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// should not happen
|
||||
PyErr_SetString(PyExc_AttributeError, "unknown attribute type, report to blender.org");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
}
|
||||
// check if post processing is needed
|
||||
if (attrdef->m_checkFunction != NULL)
|
||||
{
|
||||
if ((*attrdef->m_checkFunction)(self, attrdef) != 0)
|
||||
{
|
||||
// restore value
|
||||
RESTORE_AND_ERROR:
|
||||
if (undoBuffer)
|
||||
{
|
||||
if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_STRING)
|
||||
{
|
||||
// special case for STR_String: restore the string
|
||||
STR_String *var = reinterpret_cast<STR_String*>(ptr);
|
||||
*var = reinterpret_cast<char*>(undoBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// other field type have direct values
|
||||
memcpy(ptr, undoBuffer, bufferSize);
|
||||
}
|
||||
}
|
||||
FREE_AND_ERROR:
|
||||
if (undoBuffer)
|
||||
free(undoBuffer);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (undoBuffer)
|
||||
free(undoBuffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int PyObjectPlus::py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value)
|
||||
{
|
||||
const PyAttributeDef *attrdef;
|
||||
char *attr_str= PyString_AsString(attr);
|
||||
|
||||
for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++)
|
||||
@@ -270,427 +701,13 @@ int PyObjectPlus::py_setattro_self(const PyAttributeDef attrlist[], void *self,
|
||||
PyErr_SetString(PyExc_AttributeError, "property is read-only");
|
||||
return 1;
|
||||
}
|
||||
char *ptr = reinterpret_cast<char*>(self)+attrdef->m_offset;
|
||||
if (attrdef->m_length > 1)
|
||||
{
|
||||
if (!PySequence_Check(value))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected a sequence");
|
||||
return 1;
|
||||
}
|
||||
if (PySequence_Size(value) != attrdef->m_length)
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "incorrect number of elements in sequence");
|
||||
return 1;
|
||||
}
|
||||
switch (attrdef->m_type)
|
||||
{
|
||||
case KX_PYATTRIBUTE_TYPE_FUNCTION:
|
||||
if (attrdef->m_setFunction == NULL)
|
||||
{
|
||||
PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org");
|
||||
return 1;
|
||||
}
|
||||
return (*attrdef->m_setFunction)(self, attrdef, value);
|
||||
case KX_PYATTRIBUTE_TYPE_BOOL:
|
||||
bufferSize = sizeof(bool);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_SHORT:
|
||||
bufferSize = sizeof(short int);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_ENUM:
|
||||
case KX_PYATTRIBUTE_TYPE_INT:
|
||||
bufferSize = sizeof(int);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_FLOAT:
|
||||
bufferSize = sizeof(float);
|
||||
break;
|
||||
default:
|
||||
// should not happen
|
||||
PyErr_SetString(PyExc_AttributeError, "Unsupported attribute type, report to blender.org");
|
||||
return 1;
|
||||
}
|
||||
// let's implement a smart undo method
|
||||
bufferSize *= attrdef->m_length;
|
||||
undoBuffer = malloc(bufferSize);
|
||||
sourceBuffer = ptr;
|
||||
if (undoBuffer)
|
||||
{
|
||||
memcpy(undoBuffer, sourceBuffer, bufferSize);
|
||||
}
|
||||
for (int i=0; i<attrdef->m_length; i++)
|
||||
{
|
||||
PyObject *item = PySequence_GetItem(value, i); /* new ref */
|
||||
// we can decrement the reference immediately, the reference count
|
||||
// is at least 1 because the item is part of an array
|
||||
Py_DECREF(item);
|
||||
switch (attrdef->m_type)
|
||||
{
|
||||
case KX_PYATTRIBUTE_TYPE_BOOL:
|
||||
{
|
||||
bool *var = reinterpret_cast<bool*>(ptr);
|
||||
ptr += sizeof(bool);
|
||||
if (PyInt_Check(item))
|
||||
{
|
||||
*var = (PyInt_AsLong(item) != 0);
|
||||
}
|
||||
else if (PyBool_Check(item))
|
||||
{
|
||||
*var = (item == Py_True);
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected an integer or a bool");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_SHORT:
|
||||
{
|
||||
short int *var = reinterpret_cast<short int*>(ptr);
|
||||
ptr += sizeof(short int);
|
||||
if (PyInt_Check(item))
|
||||
{
|
||||
long val = PyInt_AsLong(item);
|
||||
if (attrdef->m_clamp)
|
||||
{
|
||||
if (val < attrdef->m_imin)
|
||||
val = attrdef->m_imin;
|
||||
else if (val > attrdef->m_imax)
|
||||
val = attrdef->m_imax;
|
||||
}
|
||||
else if (val < attrdef->m_imin || val > attrdef->m_imax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "item value out of range");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
*var = (short int)val;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected an integer");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_ENUM:
|
||||
// enum are equivalent to int, just make sure that the field size matches:
|
||||
if (sizeof(int) != attrdef->m_size)
|
||||
{
|
||||
PyErr_SetString(PyExc_AttributeError, "attribute size check error, report to blender.org");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
// walkthrough
|
||||
case KX_PYATTRIBUTE_TYPE_INT:
|
||||
{
|
||||
int *var = reinterpret_cast<int*>(ptr);
|
||||
ptr += sizeof(int);
|
||||
if (PyInt_Check(item))
|
||||
{
|
||||
long val = PyInt_AsLong(item);
|
||||
if (attrdef->m_clamp)
|
||||
{
|
||||
if (val < attrdef->m_imin)
|
||||
val = attrdef->m_imin;
|
||||
else if (val > attrdef->m_imax)
|
||||
val = attrdef->m_imax;
|
||||
}
|
||||
else if (val < attrdef->m_imin || val > attrdef->m_imax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "item value out of range");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
*var = (int)val;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected an integer");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_FLOAT:
|
||||
{
|
||||
float *var = reinterpret_cast<float*>(ptr);
|
||||
ptr += sizeof(float);
|
||||
double val = PyFloat_AsDouble(item);
|
||||
if (val == -1.0 && PyErr_Occurred())
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected a float");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
else if (attrdef->m_clamp)
|
||||
{
|
||||
if (val < attrdef->m_fmin)
|
||||
val = attrdef->m_fmin;
|
||||
else if (val > attrdef->m_fmax)
|
||||
val = attrdef->m_fmax;
|
||||
}
|
||||
else if (val < attrdef->m_fmin || val > attrdef->m_fmax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "item value out of range");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
*var = (float)val;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// should not happen
|
||||
PyErr_SetString(PyExc_AttributeError, "attribute type check error, report to blender.org");
|
||||
goto UNDO_AND_ERROR;
|
||||
}
|
||||
}
|
||||
// no error, call check function if any
|
||||
if (attrdef->m_checkFunction != NULL)
|
||||
{
|
||||
if ((*attrdef->m_checkFunction)(self, attrdef) != 0)
|
||||
{
|
||||
// post check returned an error, restore values
|
||||
UNDO_AND_ERROR:
|
||||
if (undoBuffer)
|
||||
{
|
||||
memcpy(sourceBuffer, undoBuffer, bufferSize);
|
||||
free(undoBuffer);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (undoBuffer)
|
||||
free(undoBuffer);
|
||||
return 0;
|
||||
}
|
||||
else // simple attribute value
|
||||
{
|
||||
if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION)
|
||||
{
|
||||
if (attrdef->m_setFunction == NULL)
|
||||
{
|
||||
PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org");
|
||||
return 1;
|
||||
}
|
||||
return (*attrdef->m_setFunction)(self, attrdef, value);
|
||||
}
|
||||
if (attrdef->m_checkFunction != NULL)
|
||||
{
|
||||
// post check function is provided, prepare undo buffer
|
||||
sourceBuffer = ptr;
|
||||
switch (attrdef->m_type)
|
||||
{
|
||||
case KX_PYATTRIBUTE_TYPE_BOOL:
|
||||
bufferSize = sizeof(bool);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_SHORT:
|
||||
bufferSize = sizeof(short);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_ENUM:
|
||||
case KX_PYATTRIBUTE_TYPE_INT:
|
||||
bufferSize = sizeof(int);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_FLOAT:
|
||||
bufferSize = sizeof(float);
|
||||
break;
|
||||
case KX_PYATTRIBUTE_TYPE_STRING:
|
||||
sourceBuffer = reinterpret_cast<STR_String*>(ptr)->Ptr();
|
||||
if (sourceBuffer)
|
||||
bufferSize = strlen(reinterpret_cast<char*>(sourceBuffer))+1;
|
||||
break;
|
||||
default:
|
||||
PyErr_SetString(PyExc_AttributeError, "unknown attribute type, report to blender.org");
|
||||
return 1;
|
||||
}
|
||||
if (bufferSize)
|
||||
{
|
||||
undoBuffer = malloc(bufferSize);
|
||||
if (undoBuffer)
|
||||
{
|
||||
memcpy(undoBuffer, sourceBuffer, bufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (attrdef->m_type)
|
||||
{
|
||||
case KX_PYATTRIBUTE_TYPE_BOOL:
|
||||
{
|
||||
bool *var = reinterpret_cast<bool*>(ptr);
|
||||
if (PyInt_Check(value))
|
||||
{
|
||||
*var = (PyInt_AsLong(value) != 0);
|
||||
}
|
||||
else if (PyBool_Check(value))
|
||||
{
|
||||
*var = (value == Py_True);
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected an integer or a bool");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_SHORT:
|
||||
{
|
||||
short int *var = reinterpret_cast<short int*>(ptr);
|
||||
if (PyInt_Check(value))
|
||||
{
|
||||
long val = PyInt_AsLong(value);
|
||||
if (attrdef->m_clamp)
|
||||
{
|
||||
if (val < attrdef->m_imin)
|
||||
val = attrdef->m_imin;
|
||||
else if (val > attrdef->m_imax)
|
||||
val = attrdef->m_imax;
|
||||
}
|
||||
else if (val < attrdef->m_imin || val > attrdef->m_imax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "value out of range");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
*var = (short int)val;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected an integer");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_ENUM:
|
||||
// enum are equivalent to int, just make sure that the field size matches:
|
||||
if (sizeof(int) != attrdef->m_size)
|
||||
{
|
||||
PyErr_SetString(PyExc_AttributeError, "attribute size check error, report to blender.org");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
// walkthrough
|
||||
case KX_PYATTRIBUTE_TYPE_INT:
|
||||
{
|
||||
int *var = reinterpret_cast<int*>(ptr);
|
||||
if (PyInt_Check(value))
|
||||
{
|
||||
long val = PyInt_AsLong(value);
|
||||
if (attrdef->m_clamp)
|
||||
{
|
||||
if (val < attrdef->m_imin)
|
||||
val = attrdef->m_imin;
|
||||
else if (val > attrdef->m_imax)
|
||||
val = attrdef->m_imax;
|
||||
}
|
||||
else if (val < attrdef->m_imin || val > attrdef->m_imax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "value out of range");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
*var = (int)val;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected an integer");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_FLOAT:
|
||||
{
|
||||
float *var = reinterpret_cast<float*>(ptr);
|
||||
double val = PyFloat_AsDouble(value);
|
||||
if (val == -1.0 && PyErr_Occurred())
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected a float");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
else if (attrdef->m_clamp)
|
||||
{
|
||||
if (val < attrdef->m_fmin)
|
||||
val = attrdef->m_fmin;
|
||||
else if (val > attrdef->m_fmax)
|
||||
val = attrdef->m_fmax;
|
||||
}
|
||||
else if (val < attrdef->m_fmin || val > attrdef->m_fmax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "value out of range");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
*var = (float)val;
|
||||
break;
|
||||
}
|
||||
case KX_PYATTRIBUTE_TYPE_STRING:
|
||||
{
|
||||
STR_String *var = reinterpret_cast<STR_String*>(ptr);
|
||||
if (PyString_Check(value))
|
||||
{
|
||||
char *val = PyString_AsString(value);
|
||||
if (attrdef->m_clamp)
|
||||
{
|
||||
if (strlen(val) < attrdef->m_imin)
|
||||
{
|
||||
// can't increase the length of the string
|
||||
PyErr_SetString(PyExc_ValueError, "string length too short");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
else if (strlen(val) > attrdef->m_imax)
|
||||
{
|
||||
// trim the string
|
||||
char c = val[attrdef->m_imax];
|
||||
val[attrdef->m_imax] = 0;
|
||||
*var = val;
|
||||
val[attrdef->m_imax] = c;
|
||||
break;
|
||||
}
|
||||
} else if (strlen(val) < attrdef->m_imin || strlen(val) > attrdef->m_imax)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "string length out of range");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
*var = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "expected a string");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// should not happen
|
||||
PyErr_SetString(PyExc_AttributeError, "unknown attribute type, report to blender.org");
|
||||
goto FREE_AND_ERROR;
|
||||
}
|
||||
}
|
||||
// check if post processing is needed
|
||||
if (attrdef->m_checkFunction != NULL)
|
||||
{
|
||||
if ((*attrdef->m_checkFunction)(self, attrdef) != 0)
|
||||
{
|
||||
// restore value
|
||||
RESTORE_AND_ERROR:
|
||||
if (undoBuffer)
|
||||
{
|
||||
if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_STRING)
|
||||
{
|
||||
// special case for STR_String: restore the string
|
||||
STR_String *var = reinterpret_cast<STR_String*>(ptr);
|
||||
*var = reinterpret_cast<char*>(undoBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// other field type have direct values
|
||||
memcpy(ptr, undoBuffer, bufferSize);
|
||||
}
|
||||
}
|
||||
FREE_AND_ERROR:
|
||||
if (undoBuffer)
|
||||
free(undoBuffer);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (undoBuffer)
|
||||
free(undoBuffer);
|
||||
return 0;
|
||||
|
||||
return py_set_attrdef(self, attrdef, value);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*------------------------------
|
||||
* PyObjectPlus repr -- representations
|
||||
|
||||
@@ -99,20 +99,42 @@ static inline void Py_Fatal(const char *M) {
|
||||
// to be properly passed up the hierarchy.
|
||||
|
||||
#define py_getattro_up(Parent) \
|
||||
PyObject *rvalue; \
|
||||
\
|
||||
PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \
|
||||
\
|
||||
if (descr == NULL) { \
|
||||
PyErr_Clear(); \
|
||||
rvalue = Parent::py_getattro(attr); \
|
||||
if(descr) { \
|
||||
if (PyCObject_Check(descr)) { \
|
||||
return py_get_attrdef((void *)this, (const PyAttributeDef*)PyCObject_AsVoidPtr(descr)); \
|
||||
} else { \
|
||||
return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \
|
||||
} \
|
||||
} else { \
|
||||
rvalue= PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \
|
||||
PyErr_Clear(); \
|
||||
PyObject *rvalue= Parent::py_getattro(attr); \
|
||||
\
|
||||
if (strcmp(PyString_AsString(attr), "__dict__")==0) { \
|
||||
return py_getattr_dict(rvalue, Methods, Attributes); \
|
||||
} \
|
||||
\
|
||||
return rvalue; \
|
||||
} \
|
||||
\
|
||||
if (strcmp(PyString_AsString(attr), "__dict__")==0) {\
|
||||
rvalue = py_getattr_dict(rvalue, Methods, Attributes); \
|
||||
} \
|
||||
return rvalue; \
|
||||
return NULL;
|
||||
|
||||
|
||||
#define py_setattro_up(Parent) \
|
||||
PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \
|
||||
\
|
||||
if(descr) { \
|
||||
if (PyCObject_Check(descr)) { \
|
||||
return py_set_attrdef((void *)this, (const PyAttributeDef*)PyCObject_AsVoidPtr(descr), value); \
|
||||
} else { \
|
||||
PyErr_Format(PyExc_AttributeError, "\"%s\" cannot be set", PyString_AsString(attr)); \
|
||||
return -1; \
|
||||
} \
|
||||
} else { \
|
||||
PyErr_Clear(); \
|
||||
return Parent::py_setattro(attr, value); \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -376,8 +398,14 @@ public:
|
||||
{
|
||||
return ((PyObjectPlus*) PyObj)->py_getattro(attr);
|
||||
}
|
||||
|
||||
static PyObject* py_get_attrdef(void *self, const PyAttributeDef *attrdef);
|
||||
static int py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyObject *value);
|
||||
|
||||
#if 0
|
||||
static PyObject *py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr);
|
||||
static int py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value);
|
||||
#endif
|
||||
|
||||
virtual int py_delattro(PyObject *attr);
|
||||
virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method
|
||||
|
||||
@@ -162,10 +162,11 @@ PyAttributeDef SCA_ActuatorSensor::Attributes[] = {
|
||||
};
|
||||
|
||||
PyObject* SCA_ActuatorSensor::py_getattro(PyObject *attr) {
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_ISensor); /* implicit return! */
|
||||
py_getattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
int SCA_ActuatorSensor::py_setattro(PyObject *attr, PyObject *value) {
|
||||
py_setattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*)
|
||||
@@ -180,13 +181,6 @@ int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SCA_ActuatorSensor::py_setattro(PyObject *attr, PyObject *value) {
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_ISensor::py_setattro(attr, value);
|
||||
}
|
||||
|
||||
/* 3. getActuator */
|
||||
const char SCA_ActuatorSensor::GetActuator_doc[] =
|
||||
"getActuator()\n"
|
||||
|
||||
@@ -179,17 +179,11 @@ PyAttributeDef SCA_DelaySensor::Attributes[] = {
|
||||
};
|
||||
|
||||
PyObject* SCA_DelaySensor::py_getattro(PyObject *attr) {
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
int SCA_DelaySensor::py_setattro(PyObject *attr, PyObject *value) {
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_ISensor::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -280,18 +280,12 @@ int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef)
|
||||
PyObject*
|
||||
SCA_ILogicBrick::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(CValue);
|
||||
}
|
||||
|
||||
int SCA_ILogicBrick::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return CValue::py_setattro(attr, value);
|
||||
py_setattro_up(CValue);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -462,18 +462,12 @@ PyAttributeDef SCA_ISensor::Attributes[] = {
|
||||
PyObject*
|
||||
SCA_ISensor::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_ILogicBrick);
|
||||
}
|
||||
|
||||
int SCA_ISensor::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_ILogicBrick::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_ILogicBrick);
|
||||
}
|
||||
|
||||
PyObject* SCA_ISensor::pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
|
||||
@@ -336,18 +336,12 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = {
|
||||
|
||||
PyObject* SCA_JoystickSensor::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
int SCA_JoystickSensor::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_ISensor::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -833,16 +833,10 @@ PyAttributeDef SCA_KeyboardSensor::Attributes[] = {
|
||||
PyObject*
|
||||
SCA_KeyboardSensor::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
int SCA_KeyboardSensor::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_ISensor::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
@@ -343,18 +343,12 @@ PyAttributeDef SCA_MouseSensor::Attributes[] = {
|
||||
|
||||
PyObject* SCA_MouseSensor::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
int SCA_MouseSensor::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_ISensor::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
/* eof */
|
||||
|
||||
@@ -261,17 +261,11 @@ PyAttributeDef SCA_PropertyActuator::Attributes[] = {
|
||||
};
|
||||
|
||||
PyObject* SCA_PropertyActuator::py_getattro(PyObject *attr) {
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int SCA_PropertyActuator::py_setattro(PyObject *attr, PyObject *value) {
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
/* 1. setProperty */
|
||||
|
||||
@@ -353,17 +353,11 @@ PyAttributeDef SCA_PropertySensor::Attributes[] = {
|
||||
|
||||
|
||||
PyObject* SCA_PropertySensor::py_getattro(PyObject *attr) {
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_ISensor); /* implicit return! */
|
||||
py_getattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
int SCA_PropertySensor::py_setattro(PyObject *attr, PyObject *value) {
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_ISensor::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
/* 1. getType */
|
||||
|
||||
@@ -376,20 +376,12 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
|
||||
|
||||
PyObject* SCA_PythonController::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
|
||||
py_getattro_up(SCA_IController);
|
||||
}
|
||||
|
||||
int SCA_PythonController::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
|
||||
return SCA_IController::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IController);
|
||||
}
|
||||
|
||||
PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value)
|
||||
|
||||
@@ -392,18 +392,12 @@ int SCA_RandomActuator::pyattr_set_seed(void *self, const struct KX_PYATTRIBUTE_
|
||||
}
|
||||
|
||||
PyObject* SCA_RandomActuator::py_getattro(PyObject *attr) {
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int SCA_RandomActuator::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
/* 1. setSeed */
|
||||
|
||||
@@ -167,18 +167,12 @@ PyAttributeDef SCA_RandomSensor::Attributes[] = {
|
||||
};
|
||||
|
||||
PyObject* SCA_RandomSensor::py_getattro(PyObject *attr) {
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
int SCA_RandomSensor::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_ISensor::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
/* 1. setSeed */
|
||||
|
||||
@@ -154,17 +154,11 @@ PyAttributeDef KX_NetworkMessageActuator::Attributes[] = {
|
||||
};
|
||||
|
||||
PyObject* KX_NetworkMessageActuator::py_getattro(PyObject *attr) {
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int KX_NetworkMessageActuator::py_setattro(PyObject *attr, PyObject *value) {
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
// Deprecated ----->
|
||||
|
||||
@@ -224,16 +224,10 @@ PyAttributeDef KX_NetworkMessageSensor::Attributes[] = {
|
||||
};
|
||||
|
||||
PyObject* KX_NetworkMessageSensor::py_getattro(PyObject *attr) {
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
int KX_NetworkMessageSensor::py_setattro(PyObject *attr, PyObject *value) {
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_ISensor::py_setattro(attr, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -217,18 +217,12 @@ int KX_CDActuator::pyattr_setGain(void *self, const struct KX_PYATTRIBUTE_DEF *a
|
||||
|
||||
PyObject* KX_CDActuator::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int KX_CDActuator::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -534,20 +534,12 @@ PyParentObject KX_Camera::Parents[] = {
|
||||
|
||||
PyObject* KX_Camera::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
|
||||
py_getattro_up(KX_GameObject);
|
||||
}
|
||||
|
||||
int KX_Camera::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
|
||||
return KX_GameObject::py_setattro(attr, value);
|
||||
py_setattro_up(KX_GameObject);
|
||||
}
|
||||
|
||||
KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, sphereInsideFrustum,
|
||||
|
||||
@@ -422,18 +422,11 @@ PyAttributeDef KX_CameraActuator::Attributes[] = {
|
||||
};
|
||||
|
||||
PyObject* KX_CameraActuator::py_getattro(PyObject *attr) {
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int KX_CameraActuator::py_setattro(PyObject *attr, PyObject* value) {
|
||||
int ret;
|
||||
ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
/* get obj ---------------------------------------------------------- */
|
||||
|
||||
@@ -256,18 +256,12 @@ PyAttributeDef KX_GameActuator::Attributes[] = {
|
||||
PyObject*
|
||||
KX_GameActuator::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int KX_GameActuator::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1511,20 +1511,12 @@ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_
|
||||
|
||||
PyObject* KX_GameObject::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
|
||||
py_getattro_up(SCA_IObject);
|
||||
}
|
||||
|
||||
int KX_GameObject::py_setattro(PyObject *attr, PyObject *value) // py_setattro method
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
|
||||
return SCA_IObject::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IObject);
|
||||
}
|
||||
|
||||
PyObject* KX_GameObject::PyApplyForce(PyObject* self, PyObject* args)
|
||||
|
||||
@@ -474,20 +474,12 @@ PyAttributeDef KX_IpoActuator::Attributes[] = {
|
||||
};
|
||||
|
||||
PyObject* KX_IpoActuator::py_getattro(PyObject *attr) {
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int KX_IpoActuator::py_setattro(PyObject *attr, PyObject *value) // py_setattro method
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
/* set --------------------------------------------------------------------- */
|
||||
|
||||
@@ -99,10 +99,6 @@ void KX_MeshProxy::SetMeshModified(bool v)
|
||||
|
||||
PyObject* KX_MeshProxy::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
|
||||
py_getattro_up(SCA_IObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -332,18 +332,10 @@ PyAttributeDef KX_NearSensor::Attributes[] = {
|
||||
|
||||
PyObject* KX_NearSensor::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
|
||||
py_getattro_up(KX_TouchSensor);
|
||||
}
|
||||
|
||||
int KX_NearSensor::py_setattro(PyObject*attr, PyObject* value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
|
||||
return KX_TouchSensor::py_setattro(attr, value);
|
||||
py_setattro_up(KX_TouchSensor);
|
||||
}
|
||||
|
||||
@@ -208,19 +208,11 @@ int KX_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE
|
||||
|
||||
|
||||
PyObject* KX_ParentActuator::py_getattro(PyObject *attr) {
|
||||
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int KX_ParentActuator::py_setattro(PyObject *attr, PyObject* value) {
|
||||
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
/* Deprecated -----> */
|
||||
|
||||
@@ -232,21 +232,13 @@ PyParentObject KX_PolygonMaterial::Parents[] = {
|
||||
};
|
||||
|
||||
PyObject* KX_PolygonMaterial::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
|
||||
{
|
||||
py_getattro_up(PyObjectPlus);
|
||||
}
|
||||
|
||||
int KX_PolygonMaterial::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
|
||||
return PyObjectPlus::py_setattro(attr, value);
|
||||
py_setattro_up(PyObjectPlus);
|
||||
}
|
||||
|
||||
KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setCustomMaterial, "setCustomMaterial(material)")
|
||||
|
||||
@@ -129,13 +129,26 @@ void initPyObjectPlusType(PyTypeObject **parents)
|
||||
|
||||
|
||||
|
||||
static void PyType_Ready_ADD(PyObject *dict, PyTypeObject * tp)
|
||||
static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *attributes)
|
||||
{
|
||||
PyAttributeDef *attr;
|
||||
PyObject *item;
|
||||
|
||||
PyType_Ready(tp);
|
||||
PyDict_SetItemString(dict, tp->tp_name, (PyObject *)tp);
|
||||
|
||||
/* store attr defs in the tp_dict for to avoid string lookups */
|
||||
for(attr= attributes; attr->m_name; attr++) {
|
||||
item= PyCObject_FromVoidPtr(attr, NULL);
|
||||
PyDict_SetItemString(tp->tp_dict, attr->m_name, item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#define PyType_Ready_Attr(d, n) PyType_Ready_ADD(d, &n::Type, n::Attributes)
|
||||
|
||||
void initPyTypes(void)
|
||||
{
|
||||
|
||||
@@ -150,68 +163,68 @@ void initPyTypes(void)
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), "GameTypes", mod);
|
||||
Py_DECREF(mod);
|
||||
|
||||
PyType_Ready_ADD(dict, &BL_ActionActuator::Type);
|
||||
PyType_Ready_ADD(dict, &BL_Shader::Type);
|
||||
PyType_Ready_ADD(dict, &BL_ShapeActionActuator::Type);
|
||||
PyType_Ready_ADD(dict, &CListValue::Type);
|
||||
PyType_Ready_ADD(dict, &CValue::Type);
|
||||
PyType_Ready_ADD(dict, &KX_BlenderMaterial::Type);
|
||||
PyType_Ready_ADD(dict, &KX_CDActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_Camera::Type);
|
||||
PyType_Ready_ADD(dict, &KX_CameraActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_ConstraintActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_ConstraintWrapper::Type);
|
||||
PyType_Ready_ADD(dict, &KX_GameActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_GameObject::Type);
|
||||
PyType_Ready_ADD(dict, &KX_IpoActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_LightObject::Type);
|
||||
PyType_Ready_ADD(dict, &KX_MeshProxy::Type);
|
||||
PyType_Ready_ADD(dict, &KX_MouseFocusSensor::Type);
|
||||
PyType_Ready_ADD(dict, &KX_NearSensor::Type);
|
||||
PyType_Ready_ADD(dict, &KX_NetworkMessageActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_NetworkMessageSensor::Type);
|
||||
PyType_Ready_ADD(dict, &KX_ObjectActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_ParentActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_PhysicsObjectWrapper::Type);
|
||||
PyType_Ready_ADD(dict, &KX_PolyProxy::Type);
|
||||
PyType_Ready_ADD(dict, &KX_PolygonMaterial::Type);
|
||||
PyType_Ready_ADD(dict, &KX_RadarSensor::Type);
|
||||
PyType_Ready_ADD(dict, &KX_RaySensor::Type);
|
||||
PyType_Ready_ADD(dict, &KX_SCA_AddObjectActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_SCA_DynamicActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_SCA_EndObjectActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_SCA_ReplaceMeshActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_Scene::Type);
|
||||
PyType_Ready_ADD(dict, &KX_SceneActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_SoundActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_StateActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_TouchSensor::Type);
|
||||
PyType_Ready_ADD(dict, &KX_TrackToActuator::Type);
|
||||
PyType_Ready_ADD(dict, &KX_VehicleWrapper::Type);
|
||||
PyType_Ready_ADD(dict, &KX_VertexProxy::Type);
|
||||
PyType_Ready_ADD(dict, &KX_VisibilityActuator::Type);
|
||||
PyType_Ready_ADD(dict, &PyObjectPlus::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_2DFilterActuator::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_ANDController::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_ActuatorSensor::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_AlwaysSensor::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_DelaySensor::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_ILogicBrick::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_IObject::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_ISensor::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_JoystickSensor::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_KeyboardSensor::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_MouseSensor::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_NANDController::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_NORController::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_ORController::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_PropertyActuator::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_PropertySensor::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_PythonController::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_RandomActuator::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_RandomSensor::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_XNORController::Type);
|
||||
PyType_Ready_ADD(dict, &SCA_XORController::Type);
|
||||
PyType_Ready_Attr(dict, BL_ActionActuator);
|
||||
PyType_Ready_Attr(dict, BL_Shader);
|
||||
PyType_Ready_Attr(dict, BL_ShapeActionActuator);
|
||||
PyType_Ready_Attr(dict, CListValue);
|
||||
PyType_Ready_Attr(dict, CValue);
|
||||
PyType_Ready_Attr(dict, KX_BlenderMaterial);
|
||||
PyType_Ready_Attr(dict, KX_CDActuator);
|
||||
PyType_Ready_Attr(dict, KX_Camera);
|
||||
PyType_Ready_Attr(dict, KX_CameraActuator);
|
||||
PyType_Ready_Attr(dict, KX_ConstraintActuator);
|
||||
PyType_Ready_Attr(dict, KX_ConstraintWrapper);
|
||||
PyType_Ready_Attr(dict, KX_GameActuator);
|
||||
PyType_Ready_Attr(dict, KX_GameObject);
|
||||
PyType_Ready_Attr(dict, KX_IpoActuator);
|
||||
PyType_Ready_Attr(dict, KX_LightObject);
|
||||
PyType_Ready_Attr(dict, KX_MeshProxy);
|
||||
PyType_Ready_Attr(dict, KX_MouseFocusSensor);
|
||||
PyType_Ready_Attr(dict, KX_NearSensor);
|
||||
PyType_Ready_Attr(dict, KX_NetworkMessageActuator);
|
||||
PyType_Ready_Attr(dict, KX_NetworkMessageSensor);
|
||||
PyType_Ready_Attr(dict, KX_ObjectActuator);
|
||||
PyType_Ready_Attr(dict, KX_ParentActuator);
|
||||
PyType_Ready_Attr(dict, KX_PhysicsObjectWrapper);
|
||||
PyType_Ready_Attr(dict, KX_PolyProxy);
|
||||
PyType_Ready_Attr(dict, KX_PolygonMaterial);
|
||||
PyType_Ready_Attr(dict, KX_RadarSensor);
|
||||
PyType_Ready_Attr(dict, KX_RaySensor);
|
||||
PyType_Ready_Attr(dict, KX_SCA_AddObjectActuator);
|
||||
PyType_Ready_Attr(dict, KX_SCA_DynamicActuator);
|
||||
PyType_Ready_Attr(dict, KX_SCA_EndObjectActuator);
|
||||
PyType_Ready_Attr(dict, KX_SCA_ReplaceMeshActuator);
|
||||
PyType_Ready_Attr(dict, KX_Scene);
|
||||
PyType_Ready_Attr(dict, KX_SceneActuator);
|
||||
PyType_Ready_Attr(dict, KX_SoundActuator);
|
||||
PyType_Ready_Attr(dict, KX_StateActuator);
|
||||
PyType_Ready_Attr(dict, KX_TouchSensor);
|
||||
PyType_Ready_Attr(dict, KX_TrackToActuator);
|
||||
PyType_Ready_Attr(dict, KX_VehicleWrapper);
|
||||
PyType_Ready_Attr(dict, KX_VertexProxy);
|
||||
PyType_Ready_Attr(dict, KX_VisibilityActuator);
|
||||
PyType_Ready_Attr(dict, PyObjectPlus);
|
||||
PyType_Ready_Attr(dict, SCA_2DFilterActuator);
|
||||
PyType_Ready_Attr(dict, SCA_ANDController);
|
||||
PyType_Ready_Attr(dict, SCA_ActuatorSensor);
|
||||
PyType_Ready_Attr(dict, SCA_AlwaysSensor);
|
||||
PyType_Ready_Attr(dict, SCA_DelaySensor);
|
||||
PyType_Ready_Attr(dict, SCA_ILogicBrick);
|
||||
PyType_Ready_Attr(dict, SCA_IObject);
|
||||
PyType_Ready_Attr(dict, SCA_ISensor);
|
||||
PyType_Ready_Attr(dict, SCA_JoystickSensor);
|
||||
PyType_Ready_Attr(dict, SCA_KeyboardSensor);
|
||||
PyType_Ready_Attr(dict, SCA_MouseSensor);
|
||||
PyType_Ready_Attr(dict, SCA_NANDController);
|
||||
PyType_Ready_Attr(dict, SCA_NORController);
|
||||
PyType_Ready_Attr(dict, SCA_ORController);
|
||||
PyType_Ready_Attr(dict, SCA_PropertyActuator);
|
||||
PyType_Ready_Attr(dict, SCA_PropertySensor);
|
||||
PyType_Ready_Attr(dict, SCA_PythonController);
|
||||
PyType_Ready_Attr(dict, SCA_RandomActuator);
|
||||
PyType_Ready_Attr(dict, SCA_RandomSensor);
|
||||
PyType_Ready_Attr(dict, SCA_XNORController);
|
||||
PyType_Ready_Attr(dict, SCA_XORController);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -300,18 +300,10 @@ PyAttributeDef KX_RadarSensor::Attributes[] = {
|
||||
|
||||
PyObject* KX_RadarSensor::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
|
||||
py_getattro_up(KX_NearSensor);
|
||||
}
|
||||
|
||||
int KX_RadarSensor::py_setattro(PyObject *attr, PyObject* value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
|
||||
return KX_NearSensor::py_setattro(attr, value);
|
||||
py_setattro_up(KX_NearSensor);
|
||||
}
|
||||
|
||||
@@ -446,17 +446,11 @@ PyObject* KX_RaySensor::PyGetHitNormal(PyObject* self)
|
||||
|
||||
|
||||
PyObject* KX_RaySensor::py_getattro(PyObject *attr) {
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
int KX_RaySensor::py_setattro(PyObject *attr, PyObject *value) {
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_ISensor::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
// <----- Deprecated
|
||||
// <----- Deprecated
|
||||
|
||||
@@ -257,18 +257,12 @@ PyObject* KX_SCA_AddObjectActuator::pyattr_get_objectLastCreated(void *self, con
|
||||
|
||||
PyObject* KX_SCA_AddObjectActuator::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int KX_SCA_AddObjectActuator::py_setattro(PyObject *attr, PyObject* value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
/* 1. setObject */
|
||||
|
||||
@@ -94,18 +94,12 @@ PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = {
|
||||
|
||||
PyObject* KX_SCA_DynamicActuator::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int KX_SCA_DynamicActuator::py_setattro(PyObject *attr, PyObject* value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -96,18 +96,12 @@ PyAttributeDef KX_SCA_ReplaceMeshActuator::Attributes[] = {
|
||||
|
||||
PyObject* KX_SCA_ReplaceMeshActuator::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int KX_SCA_ReplaceMeshActuator::py_setattro(PyObject *attr, PyObject* value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
PyObject* KX_SCA_ReplaceMeshActuator::pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
|
||||
|
||||
@@ -1594,11 +1594,7 @@ PyAttributeDef KX_Scene::Attributes[] = {
|
||||
|
||||
PyObject* KX_Scene::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
|
||||
object = PyDict_GetItem(m_attrlist, attr);
|
||||
PyObject *object = PyDict_GetItem(m_attrlist, attr);
|
||||
if (object)
|
||||
{
|
||||
Py_INCREF(object);
|
||||
|
||||
@@ -278,18 +278,12 @@ PyAttributeDef KX_SceneActuator::Attributes[] = {
|
||||
|
||||
PyObject* KX_SceneActuator::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int KX_SceneActuator::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
PyObject* KX_SceneActuator::pyattr_get_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
|
||||
|
||||
@@ -292,20 +292,13 @@ PyAttributeDef KX_TouchSensor::Attributes[] = {
|
||||
};
|
||||
|
||||
PyObject* KX_TouchSensor::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object= py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
{
|
||||
py_getattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
int KX_TouchSensor::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
|
||||
return SCA_ISensor::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
/* Python API */
|
||||
|
||||
@@ -506,18 +506,12 @@ int KX_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUT
|
||||
|
||||
PyObject* KX_TrackToActuator::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int KX_TrackToActuator::py_setattro(PyObject *attr, PyObject* value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
/* 1. setObject */
|
||||
|
||||
@@ -136,18 +136,12 @@ PyAttributeDef KX_VisibilityActuator::Attributes[] = {
|
||||
|
||||
PyObject* KX_VisibilityActuator::py_getattro(PyObject *attr)
|
||||
{
|
||||
PyObject* object = py_getattro_self(Attributes, this, attr);
|
||||
if (object != NULL)
|
||||
return object;
|
||||
py_getattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
int KX_VisibilityActuator::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
int ret = py_setattro_self(Attributes, this, attr, value);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
return SCA_IActuator::py_setattro(attr, value);
|
||||
py_setattro_up(SCA_IActuator);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user