BGE Animations: Adding the concept of priority back. Priority is handled on a per...
authorMitchell Stokes <mogurijin@gmail.com>
Thu, 23 Jun 2011 22:12:49 +0000 (22:12 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Thu, 23 Jun 2011 22:12:49 +0000 (22:12 +0000)
source/gameengine/Converter/BL_ActionActuator.cpp
source/gameengine/Ketsji/BL_Action.cpp
source/gameengine/Ketsji/BL_Action.h
source/gameengine/Ketsji/BL_ActionManager.cpp
source/gameengine/Ketsji/BL_ActionManager.h
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_GameObject.h

index d1f500abebd8cdc946ad618f9023b5196068a80e..3368e43c9e8118bbc6475599ad7ba743d27f0fb7 100644 (file)
@@ -184,7 +184,7 @@ bool BL_ActionActuator::Update(double curtime, bool frame)
        if (!m_is_going && bPositiveEvent)
        {               
                m_is_going = true;
-               obj->PlayAction(m_action->id.name+2, start, end, m_layer, m_blendin, play_mode, 0, m_ipo_flags);
+               obj->PlayAction(m_action->id.name+2, start, end, m_layer, m_priority, m_blendin, play_mode, 0, m_ipo_flags);
                if (m_end_reset)
                        obj->SetActionFrame(m_layer, m_localtime);
        }
@@ -204,7 +204,7 @@ bool BL_ActionActuator::Update(double curtime, bool frame)
                else if (m_playtype == ACT_ACTION_LOOP_END)
                {
                        // Convert into a play and let it finish
-                       obj->PlayAction(m_action->id.name+2, start, end, m_layer, 0, BL_Action::ACT_MODE_PLAY, 0, m_ipo_flags);
+                       obj->PlayAction(m_action->id.name+2, start, end, m_layer, 0, 0, BL_Action::ACT_MODE_PLAY, 0, m_ipo_flags);
                        obj->SetActionFrame(m_layer, m_localtime);
 
                        return true;
index 8f77d2728b2b09254c8e5f5f490f92483aa0efe3..06cf031885968a7cdf6a945c25077e83ce8b53a1 100644 (file)
@@ -60,6 +60,7 @@ BL_Action::BL_Action(class KX_GameObject* gameobj)
        m_blendframe(0.f),
        m_blendstart(0.f),
        m_speed(0.f),
+       m_priority(0),
        m_ipo_flags(0),
        m_pose(NULL),
        m_blendpose(NULL),
@@ -105,12 +106,19 @@ BL_Action::~BL_Action()
 void BL_Action::Play(const char* name,
                                        float start,
                                        float end,
+                                       short priority,
                                        float blendin,
                                        short play_mode,
                                        short blend_mode,
                                        short ipo_flags,
                                        float playback_speed)
 {
+
+       // Only start playing a new action if we're done, or if
+       // the new action has a higher priority
+       if (priority != 0 && !IsDone() && priority >= m_priority)
+               return;
+       m_priority = priority;
        bAction* prev_action = m_action;
 
        // First try to load the action
index fc80d9bea34075ea9208e8199b352a7bb4c8c550..b5d9f0566cd79f7a6b51681a082e0c77aaf4e591 100644 (file)
@@ -56,6 +56,8 @@ private:
 
        float m_speed;
 
+       short m_priority;
+
        short m_playmode;
        short m_blendmode;
 
@@ -72,6 +74,7 @@ public:
        void Play(const char* name,
                        float start,
                        float end,
+                       short priority,
                        float blendin,
                        short play_mode,
                        short blend_mode,
index 935e9129d2123aaf379a6b83a52285e581bb44fd..9e847b20c9d4da1f57a8ef31e6b010cc9e758dd7 100644 (file)
@@ -60,18 +60,14 @@ void BL_ActionManager::PlayAction(const char* name,
                                                                float start,
                                                                float end,
                                                                short layer,
+                                                               short priority,
                                                                float blendin,
                                                                short play_mode,
                                                                short blend_mode,
                                                                short ipo_flags,
                                                                float playback_speed)
 {
-       // Remove a currently running action on this layer if there is one
-       if (m_layers[layer])
-               StopAction(layer);
-
-       // Create a new action
-       m_layers[layer]->Play(name, start, end, blendin, play_mode, blend_mode, ipo_flags, playback_speed);
+       m_layers[layer]->Play(name, start, end, priority, blendin, play_mode, blend_mode, ipo_flags, playback_speed);
 }
 
 void BL_ActionManager::StopAction(short layer)
index f4ef43d3801c368e23a05fe5b1bf84365d4f6d36..41907c202047b505155ff4b7dafd3b9436614bac 100644 (file)
@@ -46,6 +46,7 @@ public:
                                        float start,
                                        float end,
                                        short layer=0,
+                                       short priority=0,
                                        float blendin=0.f,
                                        short play_mode=0,
                                        short blend_mode=0,
index aa0ce14a3ccf5df7691d6c9ddcdbbf4935d6696d..175a2b6ccdf4e898065df4c722470e813c02ec58 100644 (file)
@@ -364,13 +364,14 @@ void KX_GameObject::PlayAction(const char* name,
                                                                float start,
                                                                float end,
                                                                short layer,
+                                                               short priority,
                                                                float blendin,
                                                                short play_mode,
                                                                short blend_mode,
                                                                short ipo_flags,
                                                                float playback_speed)
 {
-       GetActionManager()->PlayAction(name, start, end, layer, blendin, play_mode, blend_mode, ipo_flags, playback_speed);
+       GetActionManager()->PlayAction(name, start, end, layer, priority, blendin, play_mode, blend_mode, ipo_flags, playback_speed);
 }
 
 void KX_GameObject::StopAction(short layer)
@@ -3034,19 +3035,19 @@ KX_PYMETHODDEF_DOC_VARARGS(KX_GameObject, sendMessage,
 }
 
 KX_PYMETHODDEF_DOC(KX_GameObject, playAction,
-       "playAction(name, start_frame, end_frame, layer=0, blendin=0, play_mode=ACT_MODE_PLAY, blend_mode=ACT_BLEND_NONE, ipo_flags=0, speed=1.0)\n"
+       "playAction(name, start_frame, end_frame, layer=0, priority=0 blendin=0, play_mode=ACT_MODE_PLAY, blend_mode=ACT_BLEND_NONE, ipo_flags=0, speed=1.0)\n"
        "plays an action\n")
 {
        const char* name;
        float start, end, blendin=0.f, speed=1.f;
-       short layer=0;
+       short layer=0, priority=0;
        short ipo_flags=0;
        short play_mode=0, blend_mode=0;
 
-       static const char *kwlist[] = {"name", "start_frame", "end_frame", "layer", "blendin", "play_mode", "blend_mode", "ipo_flags", "speed", NULL};
+       static const char *kwlist[] = {"name", "start_frame", "end_frame", "layer", "priority", "blendin", "play_mode", "blend_mode", "ipo_flags", "speed", NULL};
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwds, "sff|hfhhhf", const_cast<char**>(kwlist),
-                                                                       &name, &start, &end, &layer, &blendin, &play_mode, &blend_mode, &ipo_flags, &speed))
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "sff|hhfhhhf", const_cast<char**>(kwlist),
+                                                                       &name, &start, &end, &layer, &priority, &blendin, &play_mode, &blend_mode, &ipo_flags, &speed))
                return NULL;
 
        if (layer < 0 || layer > MAX_ACTION_LAYERS)
@@ -3067,7 +3068,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, playAction,
                blend_mode = BL_Action::ACT_BLEND_NONE;
        }
 
-       PlayAction(name, start, end, layer, blendin, play_mode, blend_mode, ipo_flags, speed);
+       PlayAction(name, start, end, layer, priority, blendin, play_mode, blend_mode, ipo_flags, speed);
 
        Py_RETURN_NONE;
 }
index b97dad1a35e7c3c6b9fe88da126395ca832cfbfe..b5ece5f8ac88ab7ea3a08a8b8d52e80190fbaaae 100644 (file)
@@ -215,6 +215,7 @@ public:
                                        float start,
                                        float end,
                                        short layer=0,
+                                       short priority=0,
                                        float blendin=0.f,
                                        short play_mode=0,
                                        short blend_mode=0,