diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2008-06-23 19:32:44 +0400 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2008-06-23 19:32:44 +0400 |
commit | 75e22a1917fb638a67d475b224cb6e368e821783 (patch) | |
tree | 3026b6fa8be1cb2f7a4f2e99c1c3535cceca27da /source/gameengine | |
parent | cb6fd8927cbdc12b299a1ccaea4321ddf162dd4d (diff) |
BGE patch #14386: Action Actuator Current Frame Prop. This patch is very usefull for action feedback logic: a sensor on the property can be used to detect a certain moment in the action and trigger more stuff. The property must be on float type for best results
Diffstat (limited to 'source/gameengine')
-rw-r--r-- | source/gameengine/Converter/BL_ActionActuator.cpp | 49 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_ActionActuator.h | 7 | ||||
-rw-r--r-- | source/gameengine/Converter/KX_ConvertActuators.cpp | 2 |
3 files changed, 57 insertions, 1 deletions
diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index ad126ebf123..83be5d3a14f 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -49,6 +49,7 @@ #include "BLI_arithb.h" #include "MT_Matrix4x4.h" #include "BKE_utildefines.h" +#include "FloatValue.h" #ifdef HAVE_CONFIG_H #include <config.h> @@ -348,6 +349,18 @@ bool BL_ActionActuator::Update(double curtime, bool frame) break; } + /* Set the property if its defined */ + if (m_framepropname) { + CValue* propowner = GetParent(); + CValue* oldprop = propowner->GetProperty(m_framepropname); + CValue* newval = new CFloatValue(m_localtime); + if (oldprop) { + oldprop->SetValue(newval); + } else { + propowner->SetProperty(m_framepropname, newval); + } + newval->Release(); + } if (bNegativeEvent) m_blendframe=0.0; @@ -446,6 +459,7 @@ PyMethodDef BL_ActionActuator::Methods[] = { {"setPriority", (PyCFunction) BL_ActionActuator::sPySetPriority, METH_VARARGS, SetPriority_doc}, {"setFrame", (PyCFunction) BL_ActionActuator::sPySetFrame, METH_VARARGS, SetFrame_doc}, {"setProperty", (PyCFunction) BL_ActionActuator::sPySetProperty, METH_VARARGS, SetProperty_doc}, + {"setFrameProperty", (PyCFunction) BL_ActionActuator::sPySetFrameProperty, METH_VARARGS, SetFrameProperty_doc}, {"setBlendtime", (PyCFunction) BL_ActionActuator::sPySetBlendtime, METH_VARARGS, SetBlendtime_doc}, {"getAction", (PyCFunction) BL_ActionActuator::sPyGetAction, METH_VARARGS, GetAction_doc}, @@ -455,6 +469,7 @@ PyMethodDef BL_ActionActuator::Methods[] = { {"getPriority", (PyCFunction) BL_ActionActuator::sPyGetPriority, METH_VARARGS, GetPriority_doc}, {"getFrame", (PyCFunction) BL_ActionActuator::sPyGetFrame, METH_VARARGS, GetFrame_doc}, {"getProperty", (PyCFunction) BL_ActionActuator::sPyGetProperty, METH_VARARGS, GetProperty_doc}, + {"getFrameProperty", (PyCFunction) BL_ActionActuator::sPyGetFrameProperty, METH_VARARGS, GetFrameProperty_doc}, {"setChannel", (PyCFunction) BL_ActionActuator::sPySetChannel, METH_VARARGS, SetChannel_doc}, // {"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_VARARGS}, {"getType", (PyCFunction) BL_ActionActuator::sPyGetType, METH_VARARGS, GetType_doc}, @@ -502,6 +517,21 @@ PyObject* BL_ActionActuator::PyGetProperty(PyObject* self, return result; } +/* getProperty */ +char BL_ActionActuator::GetFrameProperty_doc[] = +"getFrameProperty()\n" +"\tReturns the name of the property, that is set to the current frame number.\n"; + +PyObject* BL_ActionActuator::PyGetFrameProperty(PyObject* self, + PyObject* args, + PyObject* kwds) { + PyObject *result; + + result = Py_BuildValue("s", (const char *)m_framepropname); + + return result; +} + /* getFrame */ char BL_ActionActuator::GetFrame_doc[] = "getFrame()\n" @@ -763,6 +793,25 @@ PyObject* BL_ActionActuator::PySetProperty(PyObject* self, return Py_None; } +/* setFrameProperty */ +char BL_ActionActuator::SetFrameProperty_doc[] = +"setFrameProperty(prop)\n" +"\t - prop : A string specifying the property of the frame set up update.\n"; + +PyObject* BL_ActionActuator::PySetFrameProperty(PyObject* self, + PyObject* args, + PyObject* kwds) { + char *string; + + if (PyArg_ParseTuple(args,"s",&string)) + { + m_framepropname = string; + } + + Py_INCREF(Py_None); + return Py_None; +} + /* PyObject* BL_ActionActuator::PyGetChannel(PyObject* self, PyObject* args, diff --git a/source/gameengine/Converter/BL_ActionActuator.h b/source/gameengine/Converter/BL_ActionActuator.h index 62edcc7fad7..190f727c9c3 100644 --- a/source/gameengine/Converter/BL_ActionActuator.h +++ b/source/gameengine/Converter/BL_ActionActuator.h @@ -40,6 +40,7 @@ public: Py_Header; BL_ActionActuator(SCA_IObject* gameobj, const STR_String& propname, + const STR_String& framepropname, float starttime, float endtime, struct bAction *action, @@ -67,7 +68,8 @@ public: m_blendpose(NULL), m_userpose(NULL), m_action(action), - m_propname(propname) + m_propname(propname), + m_framepropname(framepropname) { }; virtual ~BL_ActionActuator(); @@ -84,6 +86,7 @@ public: KX_PYMETHOD_DOC(BL_ActionActuator,SetEnd); KX_PYMETHOD_DOC(BL_ActionActuator,SetFrame); KX_PYMETHOD_DOC(BL_ActionActuator,SetProperty); + KX_PYMETHOD_DOC(BL_ActionActuator,SetFrameProperty); KX_PYMETHOD_DOC(BL_ActionActuator,SetBlendtime); KX_PYMETHOD_DOC(BL_ActionActuator,SetChannel); @@ -94,6 +97,7 @@ public: KX_PYMETHOD_DOC(BL_ActionActuator,GetEnd); KX_PYMETHOD_DOC(BL_ActionActuator,GetFrame); KX_PYMETHOD_DOC(BL_ActionActuator,GetProperty); + KX_PYMETHOD_DOC(BL_ActionActuator,GetFrameProperty); // KX_PYMETHOD(BL_ActionActuator,GetChannel); KX_PYMETHOD_DOC(BL_ActionActuator,GetType); KX_PYMETHOD_DOC(BL_ActionActuator,SetType); @@ -138,6 +142,7 @@ protected: struct bPose* m_userpose; struct bAction *m_action; STR_String m_propname; + STR_String m_framepropname; }; enum { diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index c02c2a29595..89e2925a6c1 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -178,10 +178,12 @@ void BL_ConvertActuators(char* maggiename, if (blenderobject->type==OB_ARMATURE){ bActionActuator* actact = (bActionActuator*) bact->data; STR_String propname = (actact->name ? actact->name : ""); + STR_String propframe = (actact->frameProp ? actact->frameProp : ""); BL_ActionActuator* tmpbaseact = new BL_ActionActuator( gameobj, propname, + propframe, actact->sta, actact->end, actact->act, |