[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39349] branches/soc-2011-pepper: BGE Animations: Adding an option to let users choose whether or not to lock animation updates to the framerate .

Mitchell Stokes mogurijin at gmail.com
Fri Aug 12 22:53:29 CEST 2011


Revision: 39349
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39349
Author:   moguri
Date:     2011-08-12 20:53:29 +0000 (Fri, 12 Aug 2011)
Log Message:
-----------
BGE Animations: Adding an option to let users choose whether or not to lock animation updates to the framerate. If this option is enabled, animations are only updated at the same speed as the animation framerate. This can give a significant speed up in performance, but at the cost of smoothness in animations. I'm defaulting this behavior to off for now, which is the behavior seen in trunk.

Modified Paths:
--------------
    branches/soc-2011-pepper/release/scripts/startup/bl_ui/properties_game.py
    branches/soc-2011-pepper/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2011-pepper/source/blender/makesrna/intern/rna_scene.c
    branches/soc-2011-pepper/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
    branches/soc-2011-pepper/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
    branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
    branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.h

Modified: branches/soc-2011-pepper/release/scripts/startup/bl_ui/properties_game.py
===================================================================
--- branches/soc-2011-pepper/release/scripts/startup/bl_ui/properties_game.py	2011-08-12 20:38:29 UTC (rev 39348)
+++ branches/soc-2011-pepper/release/scripts/startup/bl_ui/properties_game.py	2011-08-12 20:53:29 UTC (rev 39349)
@@ -342,6 +342,7 @@
         row = layout.row()
         row.prop(gs, "use_frame_rate")
         row.prop(gs, "use_display_lists")
+        row.prop(gs, "restrict_animation_updates")
 
 
 class RENDER_PT_game_display(RenderButtonsPanel, bpy.types.Panel):

Modified: branches/soc-2011-pepper/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/soc-2011-pepper/source/blender/makesdna/DNA_scene_types.h	2011-08-12 20:38:29 UTC (rev 39348)
+++ branches/soc-2011-pepper/source/blender/makesdna/DNA_scene_types.h	2011-08-12 20:53:29 UTC (rev 39349)
@@ -479,6 +479,7 @@
 #define WOPHY_BULLET	5
 
 /* GameData.flag */
+#define GAME_RESTRICT_ANIM_UPDATES			(1 << 0)
 #define GAME_ENABLE_ALL_FRAMES				(1 << 1)
 #define GAME_SHOW_DEBUG_PROPS				(1 << 2)
 #define GAME_SHOW_FRAMERATE					(1 << 3)
@@ -494,6 +495,7 @@
 #define GAME_ENABLE_ANIMATION_RECORD		(1 << 13)
 #define GAME_SHOW_MOUSE						(1 << 14)
 #define GAME_GLSL_NO_COLOR_MANAGEMENT		(1 << 15)
+/* Note: GameData.flag is a short (max 16 flags). To add more flags, GameData.flag needs to be an int */
 
 /* GameData.matmode */
 #define GAME_MAT_TEXFACE	0

Modified: branches/soc-2011-pepper/source/blender/makesrna/intern/rna_scene.c
===================================================================
--- branches/soc-2011-pepper/source/blender/makesrna/intern/rna_scene.c	2011-08-12 20:38:29 UTC (rev 39348)
+++ branches/soc-2011-pepper/source/blender/makesrna/intern/rna_scene.c	2011-08-12 20:53:29 UTC (rev 39349)
@@ -1919,6 +1919,10 @@
 	prop= RNA_def_property(srna, "use_auto_start", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_funcs(prop, "rna_GameSettings_auto_start_get", "rna_GameSettings_auto_start_set");
 	RNA_def_property_ui_text(prop, "Auto Start", "Automatically start game at load time");
+
+	prop= RNA_def_property(srna, "restrict_animation_updates", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", GAME_RESTRICT_ANIM_UPDATES);
+	RNA_def_property_ui_text(prop, "Restrict Animation Updates", "Restrict the number of animation updates to the animation FPS. This is better for performance, but can cause issues with smooth playback.");
 	
 	/* materials */
 	prop= RNA_def_property(srna, "material_mode", PROP_ENUM, PROP_NONE);

Modified: branches/soc-2011-pepper/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
===================================================================
--- branches/soc-2011-pepper/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp	2011-08-12 20:38:29 UTC (rev 39348)
+++ branches/soc-2011-pepper/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp	2011-08-12 20:53:29 UTC (rev 39349)
@@ -187,6 +187,7 @@
 #endif
 		bool novertexarrays = (SYS_GetCommandLineInt(syshandle, "novertexarrays", 0) != 0);
 		bool mouse_state = startscene->gm.flag & GAME_SHOW_MOUSE;
+		bool restrictAnimFPS = startscene->gm.flag & GAME_RESTRICT_ANIM_UPDATES;
 
 		if(animation_record) usefixed= true; /* override since you's always want fixed time for sim recording */
 
@@ -237,6 +238,7 @@
 		ketsjiengine->SetNetworkDevice(networkdevice);
 		ketsjiengine->SetUseFixedTime(usefixed);
 		ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
+		ketsjiengine->SetRestrictAnimationFPS(restrictAnimFPS);
 
 #ifdef WITH_PYTHON
 		CValue::SetDeprecationWarnings(nodepwarnings);

Modified: branches/soc-2011-pepper/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
===================================================================
--- branches/soc-2011-pepper/source/gameengine/GamePlayer/ghost/GPG_Application.cpp	2011-08-12 20:38:29 UTC (rev 39348)
+++ branches/soc-2011-pepper/source/gameengine/GamePlayer/ghost/GPG_Application.cpp	2011-08-12 20:53:29 UTC (rev 39349)
@@ -545,6 +545,7 @@
 		bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
 		bool useLists = (SYS_GetCommandLineInt(syshandle, "displaylists", gm->flag & GAME_DISPLAY_LISTS) != 0);
 		bool nodepwarnings = (SYS_GetCommandLineInt(syshandle, "ignore_deprecation_warnings", 1) != 0);
+		bool restrictAnimFPS = gm->flag & GAME_RESTRICT_ANIM_UPDATES;
 
 		if(GLEW_ARB_multitexture && GLEW_VERSION_1_1)
 			m_blendermat = (SYS_GetCommandLineInt(syshandle, "blender_material", 1) != 0);
@@ -627,6 +628,7 @@
 
 		m_ketsjiengine->SetUseFixedTime(fixed_framerate);
 		m_ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
+		m_ketsjiengine->SetRestrictAnimationFPS(restrictAnimFPS);
 
 		m_engineInitialized = true;
 	}

Modified: branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
===================================================================
--- branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.cpp	2011-08-12 20:38:29 UTC (rev 39348)
+++ branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.cpp	2011-08-12 20:53:29 UTC (rev 39349)
@@ -110,6 +110,7 @@
 double KX_KetsjiEngine::m_suspendedtime = 0.0;
 double KX_KetsjiEngine::m_suspendeddelta = 0.0;
 double KX_KetsjiEngine::m_average_framerate = 0.0;
+bool   KX_KetsjiEngine::m_restrict_anim_fps = false;
 
 
 /**
@@ -660,7 +661,14 @@
 				m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
 				SG_SetActiveStage(SG_STAGE_ACTUATOR_UPDATE);
 				scene->UpdateParents(m_frameTime);
-				
+
+				if (!GetRestrictAnimationFPS())
+				{
+					m_logger->StartLog(tc_animations, m_kxsystem->GetTimeInSeconds(), true);
+					SG_SetActiveStage(SG_STAGE_ANIMATION_UPDATE);
+					scene->UpdateAnimations(m_frameTime);
+				}
+
 				m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
 				SG_SetActiveStage(SG_STAGE_PHYSICS2);
 				scene->GetPhysicsEnvironment()->beginFrame();
@@ -769,21 +777,24 @@
 
 		
 	// Handle the animations independently of the logic time step
-	m_logger->StartLog(tc_animations, m_kxsystem->GetTimeInSeconds(), true);
-	SG_SetActiveStage(SG_STAGE_ANIMATION_UPDATE);
+	if (GetRestrictAnimationFPS())
+	{
+		m_logger->StartLog(tc_animations, m_kxsystem->GetTimeInSeconds(), true);
+		SG_SetActiveStage(SG_STAGE_ANIMATION_UPDATE);
 
-	double anim_timestep = 1.0/KX_GetActiveScene()->GetAnimationFPS();
-	if (m_clockTime - m_previousAnimTime > anim_timestep)
-	{
-		// Sanity/debug print to make sure we're actually going at the fps we want (should be close to anim_timestep)
-		// printf("Anim fps: %f\n", 1.0/(m_clockTime - m_previousAnimTime));
-		m_previousAnimTime = m_clockTime;
-		for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit)
+		double anim_timestep = 1.0/KX_GetActiveScene()->GetAnimationFPS();
+		if (m_clockTime - m_previousAnimTime > anim_timestep)
 		{
-			(*sceneit)->UpdateAnimations(m_frameTime);
+			// Sanity/debug print to make sure we're actually going at the fps we want (should be close to anim_timestep)
+			// printf("Anim fps: %f\n", 1.0/(m_clockTime - m_previousAnimTime));
+			m_previousAnimTime = m_clockTime;
+			for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit)
+			{
+				(*sceneit)->UpdateAnimations(m_frameTime);
+			}
 		}
+		m_previousClockTime = m_clockTime;
 	}
-	m_previousClockTime = m_clockTime;
 	
 	// Start logging time spend outside main loop
 	m_logger->StartLog(tc_outside, m_kxsystem->GetTimeInSeconds(), true);
@@ -1821,6 +1832,16 @@
 	m_maxPhysicsFrame = frame;
 }
 
+bool KX_KetsjiEngine::GetRestrictAnimationFPS()
+{
+	return m_restrict_anim_fps;
+}
+
+void KX_KetsjiEngine::SetRestrictAnimationFPS(bool bRestrictAnimFPS)
+{
+	m_restrict_anim_fps = bRestrictAnimFPS;
+}
+
 double KX_KetsjiEngine::GetAnimFrameRate()
 {
 	return m_anim_framerate;

Modified: branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.h
===================================================================
--- branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.h	2011-08-12 20:38:29 UTC (rev 39348)
+++ branches/soc-2011-pepper/source/gameengine/Ketsji/KX_KetsjiEngine.h	2011-08-12 20:53:29 UTC (rev 39349)
@@ -116,6 +116,8 @@
 	static double			m_ticrate;
 	static double			m_anim_framerate; /* for animation playback only - ipo and action */
 
+	static bool				m_restrict_anim_fps;
+
 	static double			m_suspendedtime;
 	static double			m_suspendeddelta;
 
@@ -323,6 +325,16 @@
 	static void SetMaxPhysicsFrame(int frame);
 
 	/**
+	 * Gets whether or not to lock animation updates to the animframerate
+	 */
+	static bool GetRestrictAnimationFPS();
+
+	/**
+	 * Sets whether or not to lock animation updates to the animframerate
+	 */
+	static void SetRestrictAnimationFPS(bool bRestrictAnimFPS);
+
+	/**
 	 * Gets the framerate for playing animations. (actions and ipos)
 	 */
 	static double GetAnimFrameRate();




More information about the Bf-blender-cvs mailing list