"object" and "objectLastCreated" attribute for actuators, deprecates getObject/setObject() & getLastCreatedObject()

also removed some warnings
This commit is contained in:
Campbell Barton 2009-02-19 10:34:51 +00:00
parent 92d4ef0939
commit c597863783
12 changed files with 167 additions and 17 deletions

@ -169,8 +169,8 @@ protected:
short m_playtype; short m_playtype;
short m_priority; short m_priority;
struct bAction *m_action; struct bAction *m_action;
STR_String m_propname;
STR_String m_framepropname; STR_String m_framepropname;
STR_String m_propname;
vector<float> m_blendshape; vector<float> m_blendshape;
}; };

@ -398,9 +398,9 @@ PyParentObject KX_CameraActuator::Parents[] = {
}; };
PyMethodDef KX_CameraActuator::Methods[] = { PyMethodDef KX_CameraActuator::Methods[] = {
// ---> deprecated (all)
{"setObject",(PyCFunction) KX_CameraActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc}, {"setObject",(PyCFunction) KX_CameraActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc},
{"getObject",(PyCFunction) KX_CameraActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc}, {"getObject",(PyCFunction) KX_CameraActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc},
// ---> deprecated
{"setMin" ,(PyCFunction) KX_CameraActuator::sPySetMin, METH_VARARGS, (PY_METHODCHAR)SetMin_doc}, {"setMin" ,(PyCFunction) KX_CameraActuator::sPySetMin, METH_VARARGS, (PY_METHODCHAR)SetMin_doc},
{"getMin" ,(PyCFunction) KX_CameraActuator::sPyGetMin, METH_NOARGS, (PY_METHODCHAR)GetMin_doc}, {"getMin" ,(PyCFunction) KX_CameraActuator::sPyGetMin, METH_NOARGS, (PY_METHODCHAR)GetMin_doc},
{"setMax" ,(PyCFunction) KX_CameraActuator::sPySetMax, METH_VARARGS, (PY_METHODCHAR)SetMax_doc}, {"setMax" ,(PyCFunction) KX_CameraActuator::sPySetMax, METH_VARARGS, (PY_METHODCHAR)SetMax_doc},
@ -421,14 +421,40 @@ PyAttributeDef KX_CameraActuator::Attributes[] = {
}; };
PyObject* KX_CameraActuator::_getattr(const STR_String& attr) { PyObject* KX_CameraActuator::_getattr(const STR_String& attr) {
PyObject* object = _getattr_self(Attributes, this, attr); PyObject* object;
if (attr == "object") {
if (!m_ob) Py_RETURN_NONE;
else return m_ob->AddRef();
}
object = _getattr_self(Attributes, this, attr);
if (object != NULL) if (object != NULL)
return object; return object;
_getattr_up(SCA_IActuator); _getattr_up(SCA_IActuator);
} }
int KX_CameraActuator::_setattr(const STR_String& attr, PyObject* value) { int KX_CameraActuator::_setattr(const STR_String& attr, PyObject* value) {
int ret = _setattr_self(Attributes, this, attr, value); int ret;
if (attr == "object") {
KX_GameObject *gameobj;
if (!ConvertPythonToGameObject(value, &gameobj, true))
return 1; // ConvertPythonToGameObject sets the error
if (m_ob != NULL)
m_ob->UnregisterActuator(this);
m_ob = (SCA_IObject*)gameobj;
if (m_ob)
m_ob->RegisterActuator(this);
return 0;
}
ret = _setattr_self(Attributes, this, attr, value);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
return SCA_IActuator::_setattr(attr, value); return SCA_IActuator::_setattr(attr, value);
@ -442,6 +468,9 @@ const char KX_CameraActuator::GetObject_doc[] =
PyObject* KX_CameraActuator::PyGetObject(PyObject* self, PyObject* args) PyObject* KX_CameraActuator::PyGetObject(PyObject* self, PyObject* args)
{ {
int ret_name_only = 1; int ret_name_only = 1;
ShowDeprecationWarning("getObject()", "the object property");
if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) if (!PyArg_ParseTuple(args, "|i", &ret_name_only))
return NULL; return NULL;
@ -462,6 +491,8 @@ PyObject* KX_CameraActuator::PySetObject(PyObject* self, PyObject* value)
{ {
KX_GameObject *gameobj; KX_GameObject *gameobj;
ShowDeprecationWarning("setObject()", "the object property");
if (!ConvertPythonToGameObject(value, &gameobj, true)) if (!ConvertPythonToGameObject(value, &gameobj, true))
return NULL; // ConvertPythonToGameObject sets the error return NULL; // ConvertPythonToGameObject sets the error

@ -166,15 +166,44 @@ PyParentObject KX_ParentActuator::Parents[] = {
}; };
PyMethodDef KX_ParentActuator::Methods[] = { PyMethodDef KX_ParentActuator::Methods[] = {
// ---> deprecated (all)
{"setObject", (PyCFunction) KX_ParentActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc}, {"setObject", (PyCFunction) KX_ParentActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc},
{"getObject", (PyCFunction) KX_ParentActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc}, {"getObject", (PyCFunction) KX_ParentActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc},
{NULL,NULL} //Sentinel {NULL,NULL} //Sentinel
}; };
PyObject* KX_ParentActuator::_getattr(const STR_String& attr) { PyObject* KX_ParentActuator::_getattr(const STR_String& attr) {
if (attr == "object") {
if (!m_ob) Py_RETURN_NONE;
else return m_ob->AddRef();
}
_getattr_up(SCA_IActuator); _getattr_up(SCA_IActuator);
} }
int KX_ParentActuator::_setattr(const STR_String& attr, PyObject* value) {
if (attr == "object") {
KX_GameObject *gameobj;
if (!ConvertPythonToGameObject(value, &gameobj, true))
return 1; // ConvertPythonToGameObject sets the error
if (m_ob != NULL)
m_ob->UnregisterActuator(this);
m_ob = (SCA_IObject*)gameobj;
if (m_ob)
m_ob->RegisterActuator(this);
return 0;
}
return SCA_IActuator::_setattr(attr, value);
}
/* 1. setObject */ /* 1. setObject */
const char KX_ParentActuator::SetObject_doc[] = const char KX_ParentActuator::SetObject_doc[] =
"setObject(object)\n" "setObject(object)\n"
@ -183,6 +212,8 @@ const char KX_ParentActuator::SetObject_doc[] =
PyObject* KX_ParentActuator::PySetObject(PyObject* self, PyObject* value) { PyObject* KX_ParentActuator::PySetObject(PyObject* self, PyObject* value) {
KX_GameObject *gameobj; KX_GameObject *gameobj;
ShowDeprecationWarning("setObject()", "the object property");
if (!ConvertPythonToGameObject(value, &gameobj, true)) if (!ConvertPythonToGameObject(value, &gameobj, true))
return NULL; // ConvertPythonToGameObject sets the error return NULL; // ConvertPythonToGameObject sets the error
@ -206,6 +237,9 @@ const char KX_ParentActuator::GetObject_doc[] =
PyObject* KX_ParentActuator::PyGetObject(PyObject* self, PyObject* args) PyObject* KX_ParentActuator::PyGetObject(PyObject* self, PyObject* args)
{ {
int ret_name_only = 1; int ret_name_only = 1;
ShowDeprecationWarning("getObject()", "the object property");
if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) if (!PyArg_ParseTuple(args, "|i", &ret_name_only))
return NULL; return NULL;

@ -77,6 +77,7 @@ class KX_ParentActuator : public SCA_IActuator
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const STR_String& attr); virtual PyObject* _getattr(const STR_String& attr);
virtual int _setattr(const STR_String& attr, PyObject* value);
/* 1. setObject */ /* 1. setObject */
KX_PYMETHOD_DOC_O(KX_ParentActuator,SetObject); KX_PYMETHOD_DOC_O(KX_ParentActuator,SetObject);

@ -188,9 +188,7 @@ PyParentObject KX_SCA_AddObjectActuator::Parents[] = {
NULL NULL
}; };
PyMethodDef KX_SCA_AddObjectActuator::Methods[] = { PyMethodDef KX_SCA_AddObjectActuator::Methods[] = {
{"setObject", (PyCFunction) KX_SCA_AddObjectActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc},
{"setTime", (PyCFunction) KX_SCA_AddObjectActuator::sPySetTime, METH_O, (PY_METHODCHAR)SetTime_doc}, {"setTime", (PyCFunction) KX_SCA_AddObjectActuator::sPySetTime, METH_O, (PY_METHODCHAR)SetTime_doc},
{"getObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc},
{"getTime", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetTime, METH_NOARGS, (PY_METHODCHAR)GetTime_doc}, {"getTime", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetTime, METH_NOARGS, (PY_METHODCHAR)GetTime_doc},
{"getLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLinearVelocity, METH_NOARGS, (PY_METHODCHAR)GetLinearVelocity_doc}, {"getLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLinearVelocity, METH_NOARGS, (PY_METHODCHAR)GetLinearVelocity_doc},
{"setLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPySetLinearVelocity, METH_VARARGS, (PY_METHODCHAR)SetLinearVelocity_doc}, {"setLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPySetLinearVelocity, METH_VARARGS, (PY_METHODCHAR)SetLinearVelocity_doc},
@ -199,15 +197,50 @@ PyMethodDef KX_SCA_AddObjectActuator::Methods[] = {
{"getLastCreatedObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLastCreatedObject, METH_NOARGS,"getLastCreatedObject() : get the object handle to the last created object\n"}, {"getLastCreatedObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLastCreatedObject, METH_NOARGS,"getLastCreatedObject() : get the object handle to the last created object\n"},
{"instantAddObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyInstantAddObject, METH_NOARGS,"instantAddObject() : immediately add object without delay\n"}, {"instantAddObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyInstantAddObject, METH_NOARGS,"instantAddObject() : immediately add object without delay\n"},
// ---> deprecated
{"setObject", (PyCFunction) KX_SCA_AddObjectActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc},
{"getObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc},
{NULL,NULL} //Sentinel {NULL,NULL} //Sentinel
}; };
PyObject* KX_SCA_AddObjectActuator::_getattr(const STR_String& attr) PyObject* KX_SCA_AddObjectActuator::_getattr(const STR_String& attr)
{ {
if (attr == "object") {
if (!m_OriginalObject) Py_RETURN_NONE;
else return m_OriginalObject->AddRef();
}
else if (attr == "objectLastCreated") {
if (!m_OriginalObject) Py_RETURN_NONE;
else return m_lastCreatedObject->AddRef();
}
_getattr_up(SCA_IActuator); _getattr_up(SCA_IActuator);
} }
int KX_SCA_AddObjectActuator::_setattr(const STR_String& attr, PyObject* value) {
if (attr == "object") {
KX_GameObject *gameobj;
if (!ConvertPythonToGameObject(value, &gameobj, true))
return 1; // ConvertPythonToGameObject sets the error
if (m_OriginalObject != NULL)
m_OriginalObject->UnregisterActuator(this);
m_OriginalObject = (SCA_IObject*)gameobj;
if (m_OriginalObject)
m_OriginalObject->RegisterActuator(this);
return 0;
}
return SCA_IActuator::_setattr(attr, value);
}
/* 1. setObject */ /* 1. setObject */
const char KX_SCA_AddObjectActuator::SetObject_doc[] = const char KX_SCA_AddObjectActuator::SetObject_doc[] =
"setObject(object)\n" "setObject(object)\n"
@ -218,6 +251,8 @@ PyObject* KX_SCA_AddObjectActuator::PySetObject(PyObject* self, PyObject* value)
{ {
KX_GameObject *gameobj; KX_GameObject *gameobj;
ShowDeprecationWarning("setObject()", "the object property");
if (!ConvertPythonToGameObject(value, &gameobj, true)) if (!ConvertPythonToGameObject(value, &gameobj, true))
return NULL; // ConvertPythonToGameObject sets the error return NULL; // ConvertPythonToGameObject sets the error
@ -277,6 +312,9 @@ const char KX_SCA_AddObjectActuator::GetObject_doc[] =
PyObject* KX_SCA_AddObjectActuator::PyGetObject(PyObject* self, PyObject* args) PyObject* KX_SCA_AddObjectActuator::PyGetObject(PyObject* self, PyObject* args)
{ {
int ret_name_only = 1; int ret_name_only = 1;
ShowDeprecationWarning("getObject()", "the object property");
if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) if (!PyArg_ParseTuple(args, "|i", &ret_name_only))
return NULL; return NULL;

@ -60,13 +60,16 @@ class KX_SCA_AddObjectActuator : public SCA_IActuator
/// Linear velocity upon creation of the object. /// Linear velocity upon creation of the object.
MT_Vector3 m_linear_velocity; MT_Vector3 m_linear_velocity;
/// Apply the velocity locally
bool m_localLinvFlag;
/// Angular velocity upon creation of the object. /// Angular velocity upon creation of the object.
MT_Vector3 m_angular_velocity; MT_Vector3 m_angular_velocity;
/// Apply the velocity locally /// Apply the velocity locally
bool m_localLinvFlag; bool m_localAngvFlag;
bool m_localAngvFlag;
SCA_IObject* m_lastCreatedObject; SCA_IObject* m_lastCreatedObject;
@ -107,10 +110,8 @@ public:
virtual bool virtual bool
Update(); Update();
virtual PyObject* virtual PyObject* _getattr(const STR_String& attr);
_getattr( virtual int _setattr(const STR_String& attr, PyObject* value);
const STR_String& attr
);
SCA_IObject* SCA_IObject*
GetLastCreatedObject( GetLastCreatedObject(

@ -456,12 +456,15 @@ PyParentObject KX_TrackToActuator::Parents[] = {
PyMethodDef KX_TrackToActuator::Methods[] = { PyMethodDef KX_TrackToActuator::Methods[] = {
{"setObject", (PyCFunction) KX_TrackToActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc},
{"getObject", (PyCFunction) KX_TrackToActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc},
{"setTime", (PyCFunction) KX_TrackToActuator::sPySetTime, METH_VARARGS, (PY_METHODCHAR)SetTime_doc}, {"setTime", (PyCFunction) KX_TrackToActuator::sPySetTime, METH_VARARGS, (PY_METHODCHAR)SetTime_doc},
{"getTime", (PyCFunction) KX_TrackToActuator::sPyGetTime, METH_VARARGS, (PY_METHODCHAR)GetTime_doc}, {"getTime", (PyCFunction) KX_TrackToActuator::sPyGetTime, METH_VARARGS, (PY_METHODCHAR)GetTime_doc},
{"setUse3D", (PyCFunction) KX_TrackToActuator::sPySetUse3D, METH_VARARGS, (PY_METHODCHAR)SetUse3D_doc}, {"setUse3D", (PyCFunction) KX_TrackToActuator::sPySetUse3D, METH_VARARGS, (PY_METHODCHAR)SetUse3D_doc},
{"getUse3D", (PyCFunction) KX_TrackToActuator::sPyGetUse3D, METH_VARARGS, (PY_METHODCHAR)GetUse3D_doc}, {"getUse3D", (PyCFunction) KX_TrackToActuator::sPyGetUse3D, METH_VARARGS, (PY_METHODCHAR)GetUse3D_doc},
// ---> deprecated
{"setObject", (PyCFunction) KX_TrackToActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc},
{"getObject", (PyCFunction) KX_TrackToActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc},
{NULL,NULL} //Sentinel {NULL,NULL} //Sentinel
}; };
@ -469,10 +472,36 @@ PyMethodDef KX_TrackToActuator::Methods[] = {
PyObject* KX_TrackToActuator::_getattr(const STR_String& attr) PyObject* KX_TrackToActuator::_getattr(const STR_String& attr)
{ {
if (attr == "object") {
if (!m_object) Py_RETURN_NONE;
else return m_object->AddRef();
}
_getattr_up(SCA_IActuator); _getattr_up(SCA_IActuator);
} }
int KX_TrackToActuator::_setattr(const STR_String& attr, PyObject* value) {
int ret;
if (attr == "object") {
KX_GameObject *gameobj;
if (!ConvertPythonToGameObject(value, &gameobj, true))
return 1; // ConvertPythonToGameObject sets the error
if (m_object != NULL)
m_object->UnregisterActuator(this);
m_object = (SCA_IObject*)gameobj;
if (m_object)
m_object->RegisterActuator(this);
return 0;
}
return SCA_IActuator::_setattr(attr, value);
}
/* 1. setObject */ /* 1. setObject */
const char KX_TrackToActuator::SetObject_doc[] = const char KX_TrackToActuator::SetObject_doc[] =
@ -483,6 +512,8 @@ PyObject* KX_TrackToActuator::PySetObject(PyObject* self, PyObject* value)
{ {
KX_GameObject *gameobj; KX_GameObject *gameobj;
ShowDeprecationWarning("setObject()", "the object property");
if (!ConvertPythonToGameObject(value, &gameobj, true)) if (!ConvertPythonToGameObject(value, &gameobj, true))
return NULL; // ConvertPythonToGameObject sets the error return NULL; // ConvertPythonToGameObject sets the error
@ -506,6 +537,9 @@ const char KX_TrackToActuator::GetObject_doc[] =
PyObject* KX_TrackToActuator::PyGetObject(PyObject* self, PyObject* args) PyObject* KX_TrackToActuator::PyGetObject(PyObject* self, PyObject* args)
{ {
int ret_name_only = 1; int ret_name_only = 1;
ShowDeprecationWarning("getObject()", "the object property");
if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) if (!PyArg_ParseTuple(args, "|i", &ret_name_only))
return NULL; return NULL;

@ -73,6 +73,7 @@ class KX_TrackToActuator : public SCA_IActuator
/* Python part */ /* Python part */
virtual PyObject* _getattr(const STR_String& attr); virtual PyObject* _getattr(const STR_String& attr);
virtual int _setattr(const STR_String& attr, PyObject* value);
/* 1. setObject */ /* 1. setObject */
KX_PYMETHOD_DOC_O(KX_TrackToActuator,SetObject); KX_PYMETHOD_DOC_O(KX_TrackToActuator,SetObject);

@ -14,7 +14,8 @@ class KX_CameraActuator(SCA_IActuator):
@type height: float @type height: float
@ivar xy: axis this actuator is tracking, true=X, false=Y @ivar xy: axis this actuator is tracking, true=X, false=Y
@type xy: boolean @type xy: boolean
@ivar object: the object this actuator tracks.
@type object: KX_GameObject or None
@author: snail @author: snail
""" """
def getObject(name_only = 1): def getObject(name_only = 1):

@ -5,6 +5,9 @@ from SCA_IActuator import *
class KX_ParentActuator(SCA_IActuator): class KX_ParentActuator(SCA_IActuator):
""" """
The parent actuator can set or remove an objects parent object. The parent actuator can set or remove an objects parent object.
@ivar object: the object this actuator sets the parent too.
@type object: KX_GameObject or None
""" """
def setObject(object): def setObject(object):
""" """

@ -5,6 +5,10 @@ from SCA_IActuator import *
class KX_SCA_AddObjectActuator(SCA_IActuator): class KX_SCA_AddObjectActuator(SCA_IActuator):
""" """
Edit Object Actuator (in Add Object Mode) Edit Object Actuator (in Add Object Mode)
@ivar object: the object this actuator adds.
@type object: KX_GameObject or None
@ivar objectLastCreated: the last added object from this actuator (read only).
@type objectLastCreated: KX_GameObject or None
@warning: An Add Object actuator will be ignored if at game start, the linked object doesn't exist @warning: An Add Object actuator will be ignored if at game start, the linked object doesn't exist
(or is empty) or the linked object is in an active layer. (or is empty) or the linked object is in an active layer.

@ -13,6 +13,8 @@ class KX_TrackToActuator(SCA_IActuator):
C{ERROR: GameObject I{OBName} no object in EditObjectActuator I{ActuatorName}} C{ERROR: GameObject I{OBName} no object in EditObjectActuator I{ActuatorName}}
@ivar object: the object this actuator tracks.
@type object: KX_GameObject or None
""" """
def setObject(object): def setObject(object):
""" """