Revision: 38424
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38424
Author:   moguri
Date:     2011-07-16 05:25:15 +0000 (Sat, 16 Jul 2011)
Log Message:
-----------
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.

Modified Paths:
--------------
    branches/soc-2011-pepper/source/gameengine/Ketsji/KX_GameObject.cpp
    branches/soc-2011-pepper/source/gameengine/Ketsji/KX_GameObject.h

Modified: branches/soc-2011-pepper/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- branches/soc-2011-pepper/source/gameengine/Ketsji/KX_GameObject.cpp 
2011-07-15 23:55:20 UTC (rev 38423)
+++ branches/soc-2011-pepper/source/gameengine/Ketsji/KX_GameObject.cpp 
2011-07-16 05:25:15 UTC (rev 38424)
@@ -1561,8 +1561,10 @@
        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 @@
        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 @@
                                                                        &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 @@
        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 */
 
 

Modified: branches/soc-2011-pepper/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- branches/soc-2011-pepper/source/gameengine/Ketsji/KX_GameObject.h   
2011-07-15 23:55:20 UTC (rev 38423)
+++ branches/soc-2011-pepper/source/gameengine/Ketsji/KX_GameObject.h   
2011-07-16 05:25:15 UTC (rev 38424)
@@ -914,8 +914,10 @@
        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);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to