BGE API cleanup: DynamicActuator, ReplaceMeshActuator, TrackToActuator.

This commit is contained in:
Benoit Bolsee 2009-03-31 21:03:15 +00:00
parent 1f0e5f5807
commit f6f47a08eb
11 changed files with 192 additions and 31 deletions

@ -49,6 +49,7 @@
#include "KX_KetsjiEngine.h"
#include "KX_RadarSensor.h"
#include "KX_RaySensor.h"
#include "KX_SCA_DynamicActuator.h"
#include "SCA_IInputDevice.h"
#include "SCA_PropertySensor.h"
@ -1079,6 +1080,13 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack
KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_Y, KX_RaySensor::KX_RAY_AXIS_NEG_X);
KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_Z, KX_RaySensor::KX_RAY_AXIS_NEG_Z);
/* Dynamic actuator */
KX_MACRO_addTypesToDict(d, KX_DYN_RESTORE_DYNAMICS, KX_SCA_DynamicActuator::KX_DYN_RESTORE_DYNAMICS);
KX_MACRO_addTypesToDict(d, KX_DYN_DISABLE_DYNAMICS, KX_SCA_DynamicActuator::KX_DYN_DISABLE_DYNAMICS);
KX_MACRO_addTypesToDict(d, KX_DYN_ENABLE_RIGID_BODY, KX_SCA_DynamicActuator::KX_DYN_ENABLE_RIGID_BODY);
KX_MACRO_addTypesToDict(d, KX_DYN_DISABLE_RIGID_BODY, KX_SCA_DynamicActuator::KX_DYN_DISABLE_RIGID_BODY);
KX_MACRO_addTypesToDict(d, KX_DYN_SET_MASS, KX_SCA_DynamicActuator::KX_DYN_SET_MASS);
// Check for errors
if (PyErr_Occurred())
{

@ -36,6 +36,7 @@
// Please look here for revision history.
#include "KX_SCA_DynamicActuator.h"
#include "blendef.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
@ -80,21 +81,34 @@ PyParentObject KX_SCA_DynamicActuator::Parents[] = {
PyMethodDef KX_SCA_DynamicActuator::Methods[] = {
// ---> deprecated
KX_PYMETHODTABLE(KX_SCA_DynamicActuator, setOperation),
KX_PYMETHODTABLE(KX_SCA_DynamicActuator, getOperation),
{NULL,NULL} //Sentinel
};
PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = {
KX_PYATTRIBUTE_SHORT_RW("operation",0,4,false,KX_SCA_DynamicActuator,m_dyn_operation),
KX_PYATTRIBUTE_FLOAT_RW("mass",0.0,MAXFLOAT,KX_SCA_DynamicActuator,m_setmass),
{ NULL } //Sentinel
};
PyObject* KX_SCA_DynamicActuator::_getattr(const char *attr)
{
_getattr_up(SCA_IActuator);
PyObject* object = _getattr_self(Attributes, this, attr);
if (object != NULL)
return object;
_getattr_up(SCA_IActuator);
}
int KX_SCA_DynamicActuator::_setattr(const char *attr, PyObject* value)
{
int ret = _setattr_self(Attributes, this, attr, value);
if (ret >= 0)
return ret;
return SCA_IActuator::_setattr(attr, value);
}
/* 1. setOperation */
@ -107,6 +121,7 @@ KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, setOperation,
"\t 3 = disable rigid body\n"
"Change the dynamic status of the parent object.\n")
{
ShowDeprecationWarning("setOperation()", "the operation property");
int dyn_operation;
if (!PyArg_ParseTuple(args, "i", &dyn_operation))
@ -126,6 +141,7 @@ KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, getOperation,
"Returns the operation type of this actuator.\n"
)
{
ShowDeprecationWarning("getOperation()", "the operation property");
return PyInt_FromLong((long)m_dyn_operation);
}

@ -64,7 +64,18 @@ class KX_SCA_DynamicActuator : public SCA_IActuator
virtual bool
Update();
//Python Interface
enum DynamicOperation {
KX_DYN_RESTORE_DYNAMICS = 0,
KX_DYN_DISABLE_DYNAMICS,
KX_DYN_ENABLE_RIGID_BODY,
KX_DYN_DISABLE_RIGID_BODY,
KX_DYN_SET_MASS,
};
virtual PyObject* _getattr(const char *attr);
virtual int _setattr(const char *attr, PyObject *value);
/* 1. setOperation */
KX_PYMETHOD_DOC(KX_SCA_DynamicActuator,setOperation);

@ -82,23 +82,62 @@ PyParentObject KX_SCA_ReplaceMeshActuator::Parents[] = {
PyMethodDef KX_SCA_ReplaceMeshActuator::Methods[] = {
{"setMesh", (PyCFunction) KX_SCA_ReplaceMeshActuator::sPySetMesh, METH_O, (PY_METHODCHAR)SetMesh_doc},
KX_PYMETHODTABLE(KX_SCA_ReplaceMeshActuator, instantReplaceMesh),
// Deprecated ----->
{"setMesh", (PyCFunction) KX_SCA_ReplaceMeshActuator::sPySetMesh, METH_O, (PY_METHODCHAR)SetMesh_doc},
KX_PYMETHODTABLE(KX_SCA_ReplaceMeshActuator, getMesh),
{NULL,NULL} //Sentinel
};
PyAttributeDef KX_SCA_ReplaceMeshActuator::Attributes[] = {
KX_PYATTRIBUTE_RW_FUNCTION("mesh", KX_SCA_ReplaceMeshActuator, pyattr_get_mesh, pyattr_set_mesh),
{ NULL } //Sentinel
};
PyObject* KX_SCA_ReplaceMeshActuator::_getattr(const char *attr)
{
_getattr_up(SCA_IActuator);
PyObject* object = _getattr_self(Attributes, this, attr);
if (object != NULL)
return object;
_getattr_up(SCA_IActuator);
}
int KX_SCA_ReplaceMeshActuator::_setattr(const char *attr, PyObject* value)
{
int ret = _setattr_self(Attributes, this, attr, value);
if (ret >= 0)
return ret;
return SCA_IActuator::_setattr(attr, value);
}
PyObject* KX_SCA_ReplaceMeshActuator::pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
KX_SCA_ReplaceMeshActuator* actuator = static_cast<KX_SCA_ReplaceMeshActuator*>(self);
if (!actuator->m_mesh)
Py_RETURN_NONE;
return PyString_FromString(const_cast<char *>(actuator->m_mesh->GetName().ReadPtr()));
}
int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
KX_SCA_ReplaceMeshActuator* actuator = static_cast<KX_SCA_ReplaceMeshActuator*>(self);
if (value == Py_None) {
actuator->m_mesh = NULL;
} else {
char* meshname = PyString_AsString(value);
if (!meshname) {
PyErr_SetString(PyExc_ValueError, "Expected the name of a mesh or None");
return 1;
}
void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(meshname));
if (mesh==NULL) {
PyErr_SetString(PyExc_ValueError, "The mesh name given does not exist");
return 1;
}
actuator->m_mesh= (class RAS_MeshObject*)mesh;
}
return 0;
}
/* 1. setMesh */
const char KX_SCA_ReplaceMeshActuator::SetMesh_doc[] =
@ -108,6 +147,7 @@ const char KX_SCA_ReplaceMeshActuator::SetMesh_doc[] =
PyObject* KX_SCA_ReplaceMeshActuator::PySetMesh(PyObject* self, PyObject* value)
{
ShowDeprecationWarning("setMesh()", "the mesh property");
if (value == Py_None) {
m_mesh = NULL;
} else {
@ -133,6 +173,7 @@ KX_PYMETHODDEF_DOC(KX_SCA_ReplaceMeshActuator, getMesh,
"Returns the name of the mesh to be substituted.\n"
)
{
ShowDeprecationWarning("getMesh()", "the mesh property");
if (!m_mesh)
Py_RETURN_NONE;

@ -69,9 +69,14 @@ class KX_SCA_ReplaceMeshActuator : public SCA_IActuator
virtual bool
Update();
virtual PyObject* _getattr(const char *attr);
void InstantReplaceMesh();
virtual PyObject* _getattr(const char *attr);
virtual int _setattr(const char *attr, PyObject* value);
static PyObject* pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
/* 1. setMesh */
KX_PYMETHOD_DOC_O(KX_SCA_ReplaceMeshActuator,SetMesh);
KX_PYMETHOD_DOC(KX_SCA_ReplaceMeshActuator,getMesh);

@ -402,7 +402,7 @@ bool KX_TrackToActuator::Update(double curtime, bool frame)
// set the models tranformation properties
curobj->NodeSetLocalOrientation(mat);
curobj->NodeSetLocalPosition(localpos);
curobj->UpdateTransform();
//curobj->UpdateTransform();
}
else
{
@ -456,12 +456,11 @@ PyParentObject KX_TrackToActuator::Parents[] = {
PyMethodDef KX_TrackToActuator::Methods[] = {
// ---> deprecated
{"setTime", (PyCFunction) KX_TrackToActuator::sPySetTime, METH_VARARGS, (PY_METHODCHAR)SetTime_doc},
{"getTime", (PyCFunction) KX_TrackToActuator::sPyGetTime, METH_VARARGS, (PY_METHODCHAR)GetTime_doc},
{"setUse3D", (PyCFunction) KX_TrackToActuator::sPySetUse3D, METH_VARARGS, (PY_METHODCHAR)SetUse3D_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},
@ -469,39 +468,55 @@ PyMethodDef KX_TrackToActuator::Methods[] = {
};
PyAttributeDef KX_TrackToActuator::Attributes[] = {
KX_PYATTRIBUTE_INT_RW("time",0,1000,true,KX_TrackToActuator,m_time),
KX_PYATTRIBUTE_BOOL_RW("user3D",KX_TrackToActuator,m_allow3D),
KX_PYATTRIBUTE_RW_FUNCTION("object", KX_TrackToActuator, pyattr_get_object, pyattr_set_object),
{ NULL } //Sentinel
};
PyObject* KX_TrackToActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
KX_TrackToActuator* actuator = static_cast<KX_TrackToActuator*>(self);
if (!actuator->m_object)
Py_RETURN_NONE;
else
return actuator->m_object->AddRef();
}
int KX_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
KX_TrackToActuator* actuator = static_cast<KX_TrackToActuator*>(self);
KX_GameObject *gameobj;
if (!ConvertPythonToGameObject(value, &gameobj, true))
return 1; // ConvertPythonToGameObject sets the error
if (actuator->m_object != NULL)
actuator->m_object->UnregisterActuator(actuator);
actuator->m_object = (SCA_IObject*) gameobj;
if (actuator->m_object)
actuator->m_object->RegisterActuator(actuator);
return 0;
}
PyObject* KX_TrackToActuator::_getattr(const char *attr)
{
if (!strcmp(attr, "object")) {
if (!m_object) Py_RETURN_NONE;
else return m_object->AddRef();
}
PyObject* object = _getattr_self(Attributes, this, attr);
if (object != NULL)
return object;
_getattr_up(SCA_IActuator);
}
int KX_TrackToActuator::_setattr(const char *attr, PyObject* value)
{
if (!strcmp(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;
}
int ret = _setattr_self(Attributes, this, attr, value);
if (ret >= 0)
return ret;
return SCA_IActuator::_setattr(attr, value);
}
@ -563,6 +578,7 @@ const char KX_TrackToActuator::SetTime_doc[] =
"\tSet the time in frames with which to delay the tracking motion.\n";
PyObject* KX_TrackToActuator::PySetTime(PyObject* self, PyObject* args, PyObject* kwds)
{
ShowDeprecationWarning("setTime()", "the timer property");
int timeArg;
if (!PyArg_ParseTuple(args, "i", &timeArg))
@ -584,6 +600,7 @@ const char KX_TrackToActuator::GetTime_doc[] =
"\tReturn the time in frames with which the tracking motion is delayed.\n";
PyObject* KX_TrackToActuator::PyGetTime(PyObject* self, PyObject* args, PyObject* kwds)
{
ShowDeprecationWarning("getTime()", "the timer property");
return PyInt_FromLong(m_time);
}
@ -595,6 +612,7 @@ const char KX_TrackToActuator::GetUse3D_doc[] =
"\tReturns 1 if the motion is allowed to extend in the z-direction.\n";
PyObject* KX_TrackToActuator::PyGetUse3D(PyObject* self, PyObject* args, PyObject* kwds)
{
ShowDeprecationWarning("setTime()", "the use3D property");
return PyInt_FromLong(!(m_allow3D == 0));
}
@ -608,6 +626,7 @@ const char KX_TrackToActuator::SetUse3D_doc[] =
"\tset to 0 to lock the tracking motion to the x-y plane.\n";
PyObject* KX_TrackToActuator::PySetUse3D(PyObject* self, PyObject* args, PyObject* kwds)
{
ShowDeprecationWarning("setTime()", "the use3D property");
int boolArg;
if (!PyArg_ParseTuple(args, "i", &boolArg)) {

@ -74,7 +74,11 @@ class KX_TrackToActuator : public SCA_IActuator
/* Python part */
virtual PyObject* _getattr(const char *attr);
virtual int _setattr(const char *attr, PyObject* value);
/* These are used to get and set m_ob */
static PyObject* pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
/* 1. setObject */
KX_PYMETHOD_DOC_O(KX_TrackToActuator,SetObject);
/* 2. getObject */

@ -72,6 +72,7 @@ Documentation for the GameLogic Module.
- L{SoundActuator<KX_SoundActuator.KX_SoundActuator>}
- L{TrackToActuator<KX_TrackToActuator.KX_TrackToActuator>}
- L{VisibilityActuator<KX_VisibilityActuator.KX_VisibilityActuator>}
- L{DynamicActuator<KX_SCA_DynamicActuator.KX_SCA_DynamicActuator>}
Most logic brick's methods are accessors for the properties available in the logic buttons.
Consult the logic bricks documentation for more information on how each logic brick works.
@ -156,6 +157,14 @@ Documentation for the GameLogic Module.
@var KX_RAY_AXIS_NEG_X: See L{KX_RaySensor}
@var KX_RAY_AXIS_NEG_Y: See L{KX_RaySensor}
@var KX_RAY_AXIS_NEG_Z: See L{KX_RaySensor}
@group Dynamic Actuator: KX_DYN_RESTORE_DYNAMICS, KX_DYN_DISABLE_DYNAMICS, KX_DYN_ENABLE_RIGID_BODY, KX_DYN_DISABLE_RIGID_BODY, KX_DYN_SET_MASS
@var KX_DYN_RESTORE_DYNAMICS: See L{KX_SCA_DynamicActuator}
@var KX_DYN_DISABLE_DYNAMICS: See L{KX_SCA_DynamicActuator}
@var KX_DYN_ENABLE_RIGID_BODY: See L{KX_SCA_DynamicActuator}
@var KX_DYN_DISABLE_RIGID_BODY: See L{KX_SCA_DynamicActuator}
@var KX_DYN_SET_MASS: See L{KX_SCA_DynamicActuator}
"""

@ -0,0 +1,30 @@
# $Id$
# Documentation for KX_SCA_DynamicActuator
from SCA_IActuator import *
class KX_SCA_DynamicActuator(SCA_IActuator):
"""
Dynamic Actuator.
@ivar operation: the type of operation of the actuator, 0-4
KX_DYN_RESTORE_DYNAMICS, KX_DYN_DISABLE_DYNAMICS,
KX_DYN_ENABLE_RIGID_BODY, KX_DYN_DISABLE_RIGID_BODY, KX_DYN_SET_MASS
@type operation: integer
@ivar mass: the mass value for the KX_DYN_SET_MASS operation
@type mass: float
"""
def setOperation(operation):
"""
DEPRECATED: Use the operation property instead.
Set the type of operation when the actuator is activated:
0 = restore dynamics
1 = disable dynamics
2 = enable rigid body
3 = disable rigid body
4 = set mass
"""
def getOperatoin()
"""
DEPRECATED: Use the operation property instead.
return the type of operation
"""

@ -55,9 +55,15 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator):
This will generate a warning in the console:
C{ERROR: GameObject I{OBName} ReplaceMeshActuator I{ActuatorName} without object}
Properties:
@ivar mesh: the name of the mesh that will replace the current one
Set to None to disable actuator
@type mesh: string or None if no mesh is set
"""
def setMesh(name):
"""
DEPRECATED: Use the mesh property instead.
Sets the name of the mesh that will replace the current one.
When the name is None it will unset the mesh value so no action is taken.
@ -65,6 +71,7 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator):
"""
def getMesh():
"""
DEPRECATED: Use the mesh property instead.
Returns the name of the mesh that will replace the current one.
Returns None if no mesh has been scheduled to be added.

@ -15,9 +15,15 @@ class KX_TrackToActuator(SCA_IActuator):
@ivar object: the object this actuator tracks.
@type object: KX_GameObject or None
@ivar time: the time in frames with which to delay the tracking motion
@type time: integer
@ivar use3D: the tracking motion to use 3D
@type use3D: boolean
"""
def setObject(object):
"""
DEPRECATED: Use the object property.
Sets the object to track.
@type object: L{KX_GameObject}, string or None
@ -25,6 +31,7 @@ class KX_TrackToActuator(SCA_IActuator):
"""
def getObject(name_only):
"""
DEPRECATED: Use the object property.
Returns the name of the object to track.
@type name_only: bool
@ -33,18 +40,21 @@ class KX_TrackToActuator(SCA_IActuator):
"""
def setTime(time):
"""
DEPRECATED: Use the time property.
Sets the time in frames with which to delay the tracking motion.
@type time: integer
"""
def getTime():
"""
DEPRECATED: Use the time property.
Returns the time in frames with which the tracking motion is delayed.
@rtype: integer
"""
def setUse3D(use3d):
"""
DEPRECATED: Use the use3D property.
Sets the tracking motion to use 3D.
@type use3d: boolean
@ -53,6 +63,7 @@ class KX_TrackToActuator(SCA_IActuator):
"""
def getUse3D():
"""
DEPRECATED: Use the use3D property.
Returns True if the tracking motion will track in the z direction.
@rtype: boolean