diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2011-07-16 09:25:15 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2011-07-16 09:25:15 +0400 |
commit | c9c51776ee08827f7d6c7b8b4d671a4660c32b64 (patch) | |
tree | ed399d18d198d144c2e079576cb7551ec325548f /source | |
parent | 04e028a0c5d9ffe2edc3a42a90e9314dbd9e95c5 (diff) |
BGE Animations: Some updates to the Python api:
* Adding methods KX_GameObject.stopAction() and KX_GameObject.isPlayingAction().
* Made all layer arguments optional. This means I had to change setActionFrame(layer, frame) to setActionFrame(frame, layer=0). This seems a little backwards to me, but I guess that's what you get with optional arguments. Also, this will break existing scripts.
* Made sure to check user supplied layer values on all action methods. Previously this was only done for playAction().
* Fixed a few newline issues.
Diffstat (limited to 'source')
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 70 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.h | 2 |
2 files changed, 58 insertions, 14 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index cc275bad200..4d841e78d70 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1561,8 +1561,10 @@ PyMethodDef KX_GameObject::Methods[] = { KX_PYMETHODTABLE(KX_GameObject, sendMessage), KX_PYMETHODTABLE_KEYWORDS(KX_GameObject, playAction), + KX_PYMETHODTABLE(KX_GameObject, stopAction), KX_PYMETHODTABLE(KX_GameObject, getActionFrame), KX_PYMETHODTABLE(KX_GameObject, setActionFrame), + KX_PYMETHODTABLE(KX_GameObject, isPlayingAction), // dict style access for props {"get",(PyCFunction) KX_GameObject::sPyget, METH_VARARGS}, @@ -3041,9 +3043,18 @@ KX_PYMETHODDEF_DOC_VARARGS(KX_GameObject, sendMessage, Py_RETURN_NONE; } +static void layer_check(short &layer, const char *method_name) +{ + if (layer < 0 || layer > MAX_ACTION_LAYERS) + { + printf("KX_GameObject.%s(): given layer (%d) is out of range (0 - %d), setting to 0.\n", method_name, layer, MAX_ACTION_LAYERS-1); + layer = 0; + } +} + KX_PYMETHODDEF_DOC(KX_GameObject, playAction, "playAction(name, start_frame, end_frame, layer=0, priority=0 blendin=0, play_mode=ACT_MODE_PLAY, layer_weight=0.0, ipo_flags=0, speed=1.0)\n" - "plays an action\n") + "Plays an action\n") { const char* name; float start, end, blendin=0.f, speed=1.f, layer_weight=0.f; @@ -3057,11 +3068,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, playAction, &name, &start, &end, &layer, &priority, &blendin, &play_mode, &layer_weight, &ipo_flags, &speed)) return NULL; - if (layer < 0 || layer > MAX_ACTION_LAYERS) - { - printf("KX_GameObject.playAction(): given layer (%d) is out of range (0 - %d), setting to 0", layer, MAX_ACTION_LAYERS-1); - layer = 0; - } + layer_check(layer, "playAction"); if (play_mode < 0 || play_mode > BL_Action::ACT_MODE_MAX) { @@ -3080,33 +3087,68 @@ KX_PYMETHODDEF_DOC(KX_GameObject, playAction, Py_RETURN_NONE; } +KX_PYMETHODDEF_DOC(KX_GameObject, stopAction, + "stopAction(layer=0)\n" + "Stop playing the action on the given layer\n") +{ + short layer=0; + + if (!PyArg_ParseTuple(args, "|h:stopAction", &layer)) + return NULL; + + layer_check(layer, "stopAction"); + + StopAction(layer); + + Py_RETURN_NONE; +} + KX_PYMETHODDEF_DOC(KX_GameObject, getActionFrame, - "getActionFrame(layer)\n" - "Gets the current frame of the action playing in the supplied layer") + "getActionFrame(layer=0)\n" + "Gets the current frame of the action playing in the supplied layer\n") { - short layer; + short layer=0; - if (!PyArg_ParseTuple(args, "h:getActionFrame", &layer)) + if (!PyArg_ParseTuple(args, "|h:getActionFrame", &layer)) return NULL; + layer_check(layer, "getActionFrame"); + return PyLong_FromLong(GetActionFrame(layer)); } KX_PYMETHODDEF_DOC(KX_GameObject, setActionFrame, - "setActionFrame(layer, frame)\n" - "Set the current frame of the action playing in the supplied layer") + "setActionFrame(frame, layer=0)\n" + "Set the current frame of the action playing in the supplied layer\n") { - short layer; + short layer=0; float frame; - if (!PyArg_ParseTuple(args, "hf:setActionFrame", &layer, &frame)) + if (!PyArg_ParseTuple(args, "f|h:setActionFrame", &frame, &layer)) return NULL; + layer_check(layer, "setActionFrame"); + SetActionFrame(layer, frame); Py_RETURN_NONE; } +KX_PYMETHODDEF_DOC(KX_GameObject, isPlayingAction, + "isPlayingAction(layer=0)\n" + "Checks to see if there is an action playing in the given layer\n") +{ + short layer=0; + + if (!PyArg_ParseTuple(args, "|h:isPlayingAction", &layer)) + return NULL; + + layer_check(layer, "isPlayingAction"); + + return PyBool_FromLong(!IsActionDone(layer)); +} + + /* dict style access */ diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 7e052e6d057..40bd86fed1b 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -914,8 +914,10 @@ public: KX_PYMETHOD_VARARGS(KX_GameObject, ReinstancePhysicsMesh); KX_PYMETHOD_DOC(KX_GameObject, playAction); + KX_PYMETHOD_DOC(KX_GameObject, stopAction); KX_PYMETHOD_DOC(KX_GameObject, getActionFrame); KX_PYMETHOD_DOC(KX_GameObject, setActionFrame); + KX_PYMETHOD_DOC(KX_GameObject, isPlayingAction); /* Dict access */ KX_PYMETHOD_VARARGS(KX_GameObject,get); |