diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2011-07-14 11:03:33 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2011-07-14 11:03:33 +0400 |
commit | ad08de4c2afda4456585f6e9bb462be1143f9c14 (patch) | |
tree | 7393dad9f2c76c6d2e36d485698ba7b2ecb53f11 /source | |
parent | d838d82151efaa801276db0f0c972b5bbc8f1876 (diff) |
BGE Animations: Now animations are only updated based on the set animation speed. This offers a significant performance increase (about 2x fps in my animation stress tests) for cases such as the defaults: 60fps logic and 30fps animations. This means that animations now only have to be updated half the time. I've also added Animations as a profiling category. This is the time spent in Blender's animation code, and not in the BL_ShapeDeformer (the mesh deformation). I'd like the add the deformation too, but right now it's counted in the rasterizer, and I don't see an obviously clean way to have it counted as animation instead. I'll investigate more.
Diffstat (limited to 'source')
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 14 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.h | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.cpp | 13 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.h | 3 | ||||
-rw-r--r-- | source/gameengine/SceneGraph/SG_IObject.h | 1 |
5 files changed, 29 insertions, 4 deletions
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index ea0b00e52fd..ac018752444 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -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); diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index 8cd6fdb8f5f..89419bb7773 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -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, diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 27bf5d19b14..a49c1bf4b4c 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -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 diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 367bf0b82da..da9cc12c76a 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -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. diff --git a/source/gameengine/SceneGraph/SG_IObject.h b/source/gameengine/SceneGraph/SG_IObject.h index e709699c08a..c42935bc487 100644 --- a/source/gameengine/SceneGraph/SG_IObject.h +++ b/source/gameengine/SceneGraph/SG_IObject.h @@ -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, |