BGE: Action and ShapeKey Actuator PingPong playmode.
authorDalai Felinto <dfelinto@gmail.com>
Wed, 16 Feb 2011 19:53:39 +0000 (19:53 +0000)
committerDalai Felinto <dfelinto@gmail.com>
Wed, 16 Feb 2011 19:53:39 +0000 (19:53 +0000)
I have no idea why this hasn't been implemented before (the DEFINES were even there already). But since the Ipo (Fcurve) Actuator supports it I don't see why Action and ShapeKey shouldn't.
More than a new feature or a bugfix this is actually a step forward into unifying them.

source/blender/makesrna/intern/rna_actuator.c
source/gameengine/Converter/BL_ActionActuator.cpp
source/gameengine/Converter/BL_ActionActuator.h
source/gameengine/Converter/BL_ShapeActionActuator.cpp
source/gameengine/Converter/BL_ShapeActionActuator.h
source/gameengine/Ketsji/KX_PythonInit.cpp

index 0fe8483dfaca9172a9290d12767ecae02c525dca..80a5a5fbe4fb1a805db36ba6872a40606684ac48 100644 (file)
@@ -549,6 +549,7 @@ static void rna_def_action_actuator(BlenderRNA *brna)
 
        static EnumPropertyItem prop_type_items[] ={
                {ACT_ACTION_PLAY, "PLAY", 0, "Play", ""},
+               {ACT_ACTION_PINGPONG, "PINGPONG", 0, "Ping Pong", ""},
                {ACT_ACTION_FLIPPER, "FLIPPER", 0, "Flipper", ""},
                {ACT_ACTION_LOOP_STOP, "LOOPSTOP", 0, "Loop Stop", ""},
                {ACT_ACTION_LOOP_END, "LOOPEND", 0, "Loop End", ""},
@@ -1778,6 +1779,7 @@ static void rna_def_shape_action_actuator(BlenderRNA *brna)
 
        static EnumPropertyItem prop_type_items[] ={
                {ACT_ACTION_PLAY, "PLAY", 0, "Play", ""},
+               {ACT_ACTION_PINGPONG, "PINGPONG", 0, "Ping Pong", ""},
                {ACT_ACTION_FLIPPER, "FLIPPER", 0, "Flipper", ""},
                {ACT_ACTION_LOOP_STOP, "LOOPSTOP", 0, "Loop Stop", ""},
                {ACT_ACTION_LOOP_END, "LOOPEND", 0, "Loop End", ""},
index ac35007129a9db5615acdd23ae4834ca4fe9af21..859bcab5c6adee3448f0d45bcb2938920cfc1762 100644 (file)
@@ -232,6 +232,16 @@ bool BL_ActionActuator::Update(double curtime, bool frame)
                        apply=false;
                }
                break;
+       case ACT_ACTION_PINGPONG:
+               if (bPositiveEvent){
+                       if (!(m_flag & ACT_FLAG_LOCKINPUT)){
+                               m_flag &= ~ACT_FLAG_KEYUP;
+                               m_localtime = m_starttime;
+                               m_starttime = curtime;
+                               m_flag |= ACT_FLAG_LOCKINPUT;
+                       }
+               }
+               break;
        case ACT_ACTION_FLIPPER:
                if (bPositiveEvent){
                        if (!(m_flag & ACT_FLAG_LOCKINPUT)){
@@ -306,6 +316,18 @@ bool BL_ActionActuator::Update(double curtime, bool frame)
                break;
        case ACT_ACTION_LOOP_STOP:
                break;
+       case ACT_ACTION_PINGPONG:
+               if (wrap){
+                       if (!(m_flag & ACT_FLAG_REVERSE))
+                               m_localtime = m_endframe;
+                       else 
+                               m_localtime = m_startframe;
+
+                       m_flag &= ~ACT_FLAG_LOCKINPUT;
+                       m_flag ^= ACT_FLAG_REVERSE; //flip direction
+                       keepgoing = false;
+               }
+               break;
        case ACT_ACTION_FLIPPER:
                if (wrap){
                        if (!(m_flag & ACT_FLAG_REVERSE)){
index 9682c0e45f75d0f8d8aa93f5c4d8706d2707bc8f..bfbb160e4645369f42128cd41dae9c6ae1a4ade2 100644 (file)
@@ -121,6 +121,7 @@ public:
 
                switch (act->m_playtype) {
                        case ACT_ACTION_PLAY:
+                       case ACT_ACTION_PINGPONG:
                        case ACT_ACTION_FLIPPER:
                        case ACT_ACTION_LOOP_STOP:
                        case ACT_ACTION_LOOP_END:
index 4f6e07206dd8914ecb09a095b569ceec0dc610c5..d4ced2634eaab2ea9fef3077eba6e03ddbfed040 100644 (file)
@@ -226,6 +226,16 @@ bool BL_ShapeActionActuator::Update(double curtime, bool frame)
                        apply=false;
                }
                break;
+       case ACT_ACTION_PINGPONG:
+               if (bPositiveEvent){
+                       if (!(m_flag & ACT_FLAG_LOCKINPUT)){
+                               m_flag &= ~ACT_FLAG_KEYUP;
+                               m_localtime = m_starttime;
+                               m_starttime = curtime;
+                               m_flag |= ACT_FLAG_LOCKINPUT;
+                       }
+               }
+               break;
        case ACT_ACTION_FLIPPER:
                if (bPositiveEvent){
                        if (!(m_flag & ACT_FLAG_LOCKINPUT)){
@@ -300,6 +310,18 @@ bool BL_ShapeActionActuator::Update(double curtime, bool frame)
                break;
        case ACT_ACTION_LOOP_STOP:
                break;
+       case ACT_ACTION_PINGPONG:
+               if (wrap){
+                       if (!(m_flag & ACT_FLAG_REVERSE))
+                               m_localtime = m_endframe;
+                       else 
+                               m_localtime = m_startframe;
+
+                       m_flag &= ~ACT_FLAG_LOCKINPUT;
+                       m_flag ^= ACT_FLAG_REVERSE; //flip direction
+                       keepgoing = false;
+               }
+               break;
        case ACT_ACTION_FLIPPER:
                if (wrap){
                        if (!(m_flag & ACT_FLAG_REVERSE)){
index e6457e2c686d336968ce1c7c6d8b736142cfc31e..64b75967874b65ef055971c2906b87b3d60ac068 100644 (file)
@@ -113,6 +113,7 @@ public:
 
                switch (act->m_playtype) {
                        case ACT_ACTION_PLAY:
+                       case ACT_ACTION_PINGPONG:
                        case ACT_ACTION_FLIPPER:
                        case ACT_ACTION_LOOP_STOP:
                        case ACT_ACTION_LOOP_END:
index 8cc62e2c2fb12d9a07cfd5a7ee03c07079979551..d0a6a9a9bec0ecbcd140849fe86436c0ae4e2495 100644 (file)
@@ -1398,6 +1398,7 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack
 
        /* 7. Action actuator                                                                                                      */
        KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PLAY,        ACT_ACTION_PLAY);
+       KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PINGPONG,    ACT_ACTION_PINGPONG);
        KX_MACRO_addTypesToDict(d, KX_ACTIONACT_FLIPPER,     ACT_ACTION_FLIPPER);
        KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPSTOP,    ACT_ACTION_LOOP_STOP);
        KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPEND,     ACT_ACTION_LOOP_END);