BGE Animations: Now animations are only updated based on the set animation speed...
authorMitchell Stokes <mogurijin@gmail.com>
Thu, 14 Jul 2011 07:03:33 +0000 (07:03 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Thu, 14 Jul 2011 07:03:33 +0000 (07:03 +0000)
source/gameengine/Ketsji/KX_KetsjiEngine.cpp
source/gameengine/Ketsji/KX_KetsjiEngine.h
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_Scene.h
source/gameengine/SceneGraph/SG_IObject.h

index ea0b00e52fd53f6adb1f43c789a373d864d74f82..ac018752444143ea97ad9831935b82e6adf1d188 100644 (file)
@@ -91,7 +91,8 @@
 
 const char KX_KetsjiEngine::m_profileLabels[tc_numCategories][15] = {
        "Physics:",             // tc_physics
-       "Logic",                // tc_logic
+       "Logic:",               // tc_logic
+       "Animations:",  // tc_animations
        "Network:",             // tc_network
        "Scenegraph:",  // tc_scenegraph
        "Sound:",               // tc_sound
@@ -137,6 +138,7 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system)
        m_frameTime(0.f),
        m_clockTime(0.f),
        m_previousClockTime(0.f),
+       m_previousAnimTime(0.f),
 
 
        m_exitcode(KX_EXIT_REQUEST_NO_REQUEST),
@@ -652,6 +654,16 @@ else
                                scene->LogicUpdateFrame(m_frameTime, true);
                                
                                scene->LogicEndFrame();
+
+                               // Handle animations
+                               double anim_timestep = 1.0/scene->GetAnimationFPS();
+                               if (m_clockTime - m_previousAnimTime > anim_timestep)
+                               {
+                                       m_previousAnimTime = m_clockTime;
+                                       m_logger->StartLog(tc_animations, m_kxsystem->GetTimeInSeconds(), true);
+                                       SG_SetActiveStage(SG_STAGE_ANIMATION_UPDATE);
+                                       scene->UpdateAnimations(m_frameTime);
+                               }
        
                                // Actuators can affect the scenegraph
                                m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
index 8cd6fdb8f5f418120cf795128fca51fd6169f686..89419bb77739591dda792ebe0806ccecc3f0b3a5 100644 (file)
@@ -108,6 +108,7 @@ private:
        double                          m_frameTime;//discrete timestamp of the 'game logic frame'
        double                          m_clockTime;//current time
        double                          m_previousClockTime;//previous clock time
+       double                          m_previousAnimTime; //the last time animations were updated
        double                          m_remainingTime;
 
        static int                              m_maxLogicFrame;        /* maximum number of consecutive logic frame */
@@ -147,6 +148,7 @@ private:
                tc_first = 0,
                tc_physics = 0,
                tc_logic,
+               tc_animations,
                tc_network,
                tc_scenegraph,
                tc_sound,
index 27bf5d19b14b66700e6818aacf898448281cdfac..a49c1bf4b4cbd48f918ae500277b73d55d786cff 100644 (file)
@@ -1502,13 +1502,15 @@ void KX_Scene::LogicBeginFrame(double curtime)
        m_logicmgr->BeginFrame(curtime, 1.0/KX_KetsjiEngine::GetTicRate());
 }
 
-
-
-void KX_Scene::LogicUpdateFrame(double curtime, bool frame)
+void KX_Scene::UpdateAnimations(double curtime)
 {
        // Update any animations
        for (int i=0; i<GetObjectList()->GetCount(); ++i)
                ((KX_GameObject*)GetObjectList()->GetValue(i))->UpdateActionManager(curtime);
+}
+
+void KX_Scene::LogicUpdateFrame(double curtime, bool frame)
+{
        m_logicmgr->UpdateFrame(curtime, frame);
 }
 
@@ -1671,6 +1673,11 @@ double KX_Scene::getSuspendedDelta()
        return m_suspendeddelta;
 }
 
+short KX_Scene::GetAnimationFPS()
+{
+       return m_blenderScene->r.frs_sec;
+}
+
 #ifdef USE_BULLET
 #include "KX_BulletPhysicsController.h"
 #endif
index 367bf0b82da21e0a08a8b8390fd782a25d48d04c..da9cc12c76aee84019d3fd5d3abf1a679c079f0e 100644 (file)
@@ -340,6 +340,7 @@ public:
         */
        void LogicBeginFrame(double curtime);
        void LogicUpdateFrame(double curtime, bool frame);
+       void UpdateAnimations(double curtime);
 
                void                                            
        LogicEndFrame(
@@ -565,6 +566,8 @@ public:
        void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment*       physEnv);
 
        void    SetGravity(const MT_Vector3& gravity);
+
+       short GetAnimationFPS();
        
        /**
         * Sets the node tree for this scene.
index e709699c08abc437713f133a0f2963cf58f967d2..c42935bc487c8cc050e9dea1a171d07d8bb5a6b3 100644 (file)
@@ -49,6 +49,7 @@ enum SG_Stage
        SG_STAGE_CONTROLLER_UPDATE,
        SG_STAGE_ACTUATOR,
        SG_STAGE_ACTUATOR_UPDATE,
+       SG_STAGE_ANIMATION_UPDATE,
        SG_STAGE_PHYSICS2,
        SG_STAGE_PHYSICS2_UPDATE,
        SG_STAGE_SCENE,