Adding an option for action actuator - "Continue" this means animations always play...
authorCampbell Barton <ideasman42@gmail.com>
Thu, 10 Jul 2008 14:23:19 +0000 (14:23 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 10 Jul 2008 14:23:19 +0000 (14:23 +0000)
When using states, an action like kick or throw can often switch out before finishing playing the action, and there was no way to play from the start frame the second time round. (even setting the actions current frame through python doesn't work work)

source/blender/makesdna/DNA_actuator_types.h
source/blender/src/buttons_logic.c
source/gameengine/Converter/BL_ActionActuator.cpp
source/gameengine/Converter/BL_ActionActuator.h
source/gameengine/Converter/KX_ConvertActuators.cpp
source/gameengine/PyDoc/BL_ActionActuator.py

index 77ebef744eb0690e4528771656783fe1b3cabd7c..a467722e8e19d3b3048819fa1a408d82ac17d470 100644 (file)
@@ -51,8 +51,9 @@ typedef struct bActionActuator {
        int     sta, end;               /* Start & End frames */                        
        char    name[32];               /* For property-driven playback */      
        char    frameProp[32];  /* Set this property to the actions current frame */
-       int     blendin;                /* Number of frames of blending */      
-       short   priority;               /* Execution priority */                        
+       short   blendin;                /* Number of frames of blending */
+       short   priority;               /* Execution priority */
+       short   end_reset;      /* Ending the actuator (negative pulse) wont reset the the action to its starting frame */
        short   strideaxis;             /* Displacement axis */
        float   stridelength;   /* Displacement incurred by cycle */
 } bActionActuator;                                                                                             
index 7050e61a6ac0d9bfa7fbb866e36af159feb55dfd..cc4df06e22d49f306bfacbd6409c01525dcaf6b9 100644 (file)
@@ -1769,23 +1769,27 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh
 #else
                        str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
 #endif
-                       uiDefButS(block, MENU, B_REDR, str, xco+30, yco-24, (width-60)/2, 19, &aa->type, 0.0, 0.0, 0.0, 0.0, "Action playback type");
-                       uiDefIDPoinBut(block, test_actionpoin_but, ID_AC, 1, "AC: ", xco+30 + ((width-60)/2), yco-24, (width-60)/2, 19, &aa->act, "Action name");
+                       uiDefButS(block, MENU, B_REDR, str, xco+10, yco-24, width/3, 19, &aa->type, 0.0, 0.0, 0.0, 0.0, "Action playback type");
+                       uiDefIDPoinBut(block, test_actionpoin_but, ID_AC, 1, "AC: ", xco+10+ (width/3), yco-24, ((width/3)*2) - (20 + 60), 19, &aa->act, "Action name");
+                       
+                       uiDefButBitS(block, TOGN, 1, 0, "Continue", xco+((width/3)*2)+20, yco-24, 60, 19,
+                                        &aa->end_reset, 0.0, 0.0, 0, 0, "Restore last frame when switching on/off, otherwise play from the start each time");
+                       
                        
                        if(aa->type == ACT_ACTION_FROM_PROP)
                        {
-                               uiDefBut(block, TEX, 0, "Prop: ",xco+30, yco-44, width-60, 19, aa->name, 0.0, 31.0, 0, 0, "Use this property to define the Action position");
+                               uiDefBut(block, TEX, 0, "Prop: ",xco+10, yco-44, width-20, 19, aa->name, 0.0, 31.0, 0, 0, "Use this property to define the Action position");
                        }
                        else
                        {
-                               uiDefButI(block, NUM, 0, "Sta: ",xco+30, yco-44, (width-60)/2, 19, &aa->sta, 0.0, MAXFRAMEF, 0, 0, "Start frame");
-                               uiDefButI(block, NUM, 0, "End: ",xco+30+(width-60)/2, yco-44, (width-60)/2, 19, &aa->end, 0.0, MAXFRAMEF, 0, 0, "End frame");
+                               uiDefButI(block, NUM, 0, "Sta: ",xco+10, yco-44, (width-20)/2, 19, &aa->sta, 0.0, MAXFRAMEF, 0, 0, "Start frame");
+                               uiDefButI(block, NUM, 0, "End: ",xco+10+(width-20)/2, yco-44, (width-20)/2, 19, &aa->end, 0.0, MAXFRAMEF, 0, 0, "End frame");
                        }
                                                
-                       uiDefButI(block, NUM, 0, "Blendin: ", xco+30, yco-64, (width-60)/2, 19, &aa->blendin, 0.0, MAXFRAMEF, 0.0, 0.0, "Number of frames of motion blending");
-                       uiDefButS(block, NUM, 0, "Priority: ", xco+30+(width-60)/2, yco-64, (width-60)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers, With 2 or more actions at once, the overriding channels must be lower in the stack");
+                       uiDefButS(block, NUM, 0, "Blendin: ", xco+10, yco-64, (width-20)/2, 19, &aa->blendin, 0.0, 32767, 0.0, 0.0, "Number of frames of motion blending");
+                       uiDefButS(block, NUM, 0, "Priority: ", xco+10+(width-20)/2, yco-64, (width-20)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers, With 2 or more actions at once, the overriding channels must be lower in the stack");
                        
-                       uiDefBut(block, TEX, 0, "FrameProp: ",xco+30, yco-84, width-60, 19, aa->frameProp, 0.0, 31.0, 0, 0, "Assign this property this actions current frame number");                  
+                       uiDefBut(block, TEX, 0, "FrameProp: ",xco+10, yco-84, width-20, 19, aa->frameProp, 0.0, 31.0, 0, 0, "Assign this property this actions current frame number");                  
 
                        
 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
index 44f6ec1af90b08820ea1c9ba530b1df24576aa1c..5d6dd694765241c8ab204692a5dd8d94ccee3af6 100644 (file)
@@ -184,6 +184,11 @@ bool BL_ActionActuator::Update(double curtime, bool frame)
                
                if (bNegativeEvent)
                {
+                       // dont continue where we left off when restarting
+                       if (m_end_reset) {
+                               m_flag &= ~ACT_FLAG_LOCKINPUT;
+                       }
+                       
                        if (!(m_flag & ACT_FLAG_ACTIVE))
                                return false;
                        m_flag &= ~ACT_FLAG_ACTIVE;
@@ -472,8 +477,10 @@ PyMethodDef BL_ActionActuator::Methods[] = {
        {"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},    
+       {"getType", (PyCFunction) BL_ActionActuator::sPyGetType, METH_VARARGS, GetType_doc},
        {"setType", (PyCFunction) BL_ActionActuator::sPySetType, METH_VARARGS, SetType_doc},
+       {"getContinue", (PyCFunction) BL_ActionActuator::sPyGetContinue, METH_NOARGS, 0},       
+       {"setContinue", (PyCFunction) BL_ActionActuator::sPySetContinue, METH_O, 0},
        {NULL,NULL} //Sentinel
 };
 
@@ -978,7 +985,26 @@ PyObject* BL_ActionActuator::PySetType(PyObject* self,
        default:
                printf("Invalid type for action actuator: %d\n", typeArg); /* error */
     }
+       Py_RETURN_NONE;
+}
+
+PyObject* BL_ActionActuator::PyGetContinue(PyObject* self) {
+    return PyInt_FromLong((long)(m_end_reset==0));
+}
+
+PyObject* BL_ActionActuator::PySetContinue(PyObject* self, PyObject* value) {
+       int param = PyObject_IsTrue( value );
        
-    Py_Return;
+       if( param == -1 ) {
+               PyErr_SetString( PyExc_TypeError, "expected True/False or 0/1" );
+               return NULL;
+       }
+
+       if (param) {
+               m_end_reset = 0;
+       } else {
+               m_end_reset = 1;
+       }
+    Py_RETURN_NONE;
 }
 
index 190f727c9c3eb5b8a7b7062432295ed5bc626de7..a67b6d29b7453abdc366916f12467cfcc927da1a 100644 (file)
@@ -47,6 +47,7 @@ public:
                                                short   playtype,
                                                short   blendin,
                                                short   priority,
+                                               short   end_reset,
                                                float   stride,
                                                PyTypeObject* T=&Type) 
                : SCA_IActuator(gameobj,T),
@@ -64,6 +65,7 @@ public:
                m_stridelength(stride),
                m_playtype(playtype),
                m_priority(priority),
+               m_end_reset(end_reset),
                m_pose(NULL),
                m_blendpose(NULL),
                m_userpose(NULL),
@@ -101,6 +103,8 @@ public:
 //     KX_PYMETHOD(BL_ActionActuator,GetChannel);
        KX_PYMETHOD_DOC(BL_ActionActuator,GetType);
        KX_PYMETHOD_DOC(BL_ActionActuator,SetType);
+       KX_PYMETHOD_NOARGS(BL_ActionActuator,GetContinue);
+       KX_PYMETHOD_O(BL_ActionActuator,SetContinue);
 
        virtual PyObject* _getattr(const STR_String& attr);
 
@@ -137,6 +141,7 @@ protected:
        float   m_stridelength;
        short   m_playtype;
        short   m_priority;
+       short   m_end_reset;
        struct bPose* m_pose;
        struct bPose* m_blendpose;
        struct bPose* m_userpose;
index 9b1bc1e6b901ea5e97cdd42caf1af88d09b074c3..1f87e9d9ac74db88783acfb088f6c032d0032bb7 100644 (file)
@@ -193,6 +193,7 @@ void BL_ConvertActuators(char* maggiename,
                                                actact->type, // + 1, because Blender starts to count at zero,
                                                actact->blendin,
                                                actact->priority,
+                                               actact->end_reset,
                                                actact->stridelength
                                                // Ketsji at 1, because zero is reserved for "NoDef"
                                                );
index 41f41080c315b81fb770e75c302285d6bff7ab2f..d56888cde8006a0a5b6784795d53426a61e1d220 100644 (file)
@@ -86,6 +86,14 @@ class BL_ActionActuator(SCA_IActuator):
                @param mode: KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND
                @type mode: integer
                """
+       
+       def setContinue(cont):
+               """
+               Set the actions continue option True or False. see getContinue.
+
+               @param cont: The continue option.
+               @type cont: bool
+               """
 
        def getType():
                """
@@ -94,6 +102,13 @@ class BL_ActionActuator(SCA_IActuator):
                @rtype: integer
                @return: KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND
                """
+
+       def getContinue():
+               """
+               When True, the action will always play from where last left off, otherwise negative events to this actuator will reset it to its start frame.
+           
+               @rtype: bool
+               """
        
        def getAction():
                """