[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38385] branches/soc-2011-pepper/source/ gameengine: BGE Animations: Now animations are only updated based on the set animation speed.

Mitchell Stokes mogurijin at gmail.com
Thu Jul 14 09:03:34 CEST 2011


Revision: 38385
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38385
Author:   moguri
Date:     2011-07-14 07:03:33 +0000 (Thu, 14 Jul 2011)
Log Message:
-----------
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.

Modified Paths:
--------------
    branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
    branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.h
    branches/soc-2011-pepper/source/gameengine/Ketsji/KX_Scene.cpp
    branches/soc-2011-pepper/source/gameengine/Ketsji/KX_Scene.h
    branches/soc-2011-pepper/source/gameengine/SceneGraph/SG_IObject.h

Modified: branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
===================================================================
--- branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.cpp	2011-07-14 06:16:31 UTC (rev 38384)
+++ branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.cpp	2011-07-14 07:03:33 UTC (rev 38385)
@@ -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 @@
 	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 @@
 				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);

Modified: branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.h
===================================================================
--- branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.h	2011-07-14 06:16:31 UTC (rev 38384)
+++ branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.h	2011-07-14 07:03:33 UTC (rev 38385)
@@ -108,6 +108,7 @@
 	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 @@
 		tc_first = 0,
 		tc_physics = 0,
 		tc_logic,
+		tc_animations,
 		tc_network,
 		tc_scenegraph,
 		tc_sound,

Modified: branches/soc-2011-pepper/source/gameengine/Ketsji/KX_Scene.cpp
===================================================================
--- branches/soc-2011-pepper/source/gameengine/Ketsji/KX_Scene.cpp	2011-07-14 06:16:31 UTC (rev 38384)
+++ branches/soc-2011-pepper/source/gameengine/Ketsji/KX_Scene.cpp	2011-07-14 07:03:33 UTC (rev 38385)
@@ -1502,13 +1502,15 @@
 	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 @@
 	return m_suspendeddelta;
 }
 
+short KX_Scene::GetAnimationFPS()
+{
+	return m_blenderScene->r.frs_sec;
+}
+
 #ifdef USE_BULLET
 #include "KX_BulletPhysicsController.h"
 #endif

Modified: branches/soc-2011-pepper/source/gameengine/Ketsji/KX_Scene.h
===================================================================
--- branches/soc-2011-pepper/source/gameengine/Ketsji/KX_Scene.h	2011-07-14 06:16:31 UTC (rev 38384)
+++ branches/soc-2011-pepper/source/gameengine/Ketsji/KX_Scene.h	2011-07-14 07:03:33 UTC (rev 38385)
@@ -340,6 +340,7 @@
 	 */
 	void LogicBeginFrame(double curtime);
 	void LogicUpdateFrame(double curtime, bool frame);
+	void UpdateAnimations(double curtime);
 
 		void						
 	LogicEndFrame(
@@ -565,6 +566,8 @@
 	void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment*	physEnv);
 
 	void	SetGravity(const MT_Vector3& gravity);
+
+	short GetAnimationFPS();
 	
 	/**
 	 * Sets the node tree for this scene.

Modified: branches/soc-2011-pepper/source/gameengine/SceneGraph/SG_IObject.h
===================================================================
--- branches/soc-2011-pepper/source/gameengine/SceneGraph/SG_IObject.h	2011-07-14 06:16:31 UTC (rev 38384)
+++ branches/soc-2011-pepper/source/gameengine/SceneGraph/SG_IObject.h	2011-07-14 07:03:33 UTC (rev 38385)
@@ -49,6 +49,7 @@
 	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,




More information about the Bf-blender-cvs mailing list