[Bf-blender-cvs] [3442a65] master: BGE Cleanup: Reducing KX_Scene's dependence on Bullet.

Mitchell Stokes noreply at git.blender.org
Wed Apr 23 23:16:53 CEST 2014


Commit: 3442a658fc24267d0fd77da72eb7b254e7079c65
Author: Mitchell Stokes
Date:   Wed Apr 23 14:08:49 2014 -0700
https://developer.blender.org/rB3442a658fc24267d0fd77da72eb7b254e7079c65

BGE Cleanup: Reducing KX_Scene's dependence on Bullet.

Instead, it now relies more on our physics abstractions (e.g.,
PHY_IPhysicsEnvironment).

===================================================================

M	source/gameengine/Ketsji/KX_Scene.cpp
M	source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
M	source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
M	source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
M	source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h

===================================================================

diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp
index 64ba17f..5088551 100644
--- a/source/gameengine/Ketsji/KX_Scene.cpp
+++ b/source/gameengine/Ketsji/KX_Scene.cpp
@@ -84,6 +84,7 @@
 #include "NG_NetworkScene.h"
 #include "PHY_IPhysicsEnvironment.h"
 #include "PHY_IGraphicController.h"
+#include "PHY_IPhysicsController.h"
 #include "KX_BlenderSceneConverter.h"
 #include "KX_MotionState.h"
 
@@ -95,8 +96,6 @@
 #ifdef WITH_BULLET
 #include "KX_SoftBodyDeformer.h"
 #include "KX_ConvertPhysicsObject.h"
-#include "CcdPhysicsEnvironment.h"
-#include "CcdPhysicsController.h"
 #endif
 
 #include "KX_Light.h"
@@ -565,7 +564,6 @@ KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CVal
 		newobj->SetGraphicController(newctrl);
 	}
 
-#ifdef WITH_BULLET
 	// replicate physics controller
 	if (orgobj->GetPhysicsController())
 	{
@@ -582,7 +580,6 @@ KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CVal
 		if (parent)
 			parent->Release();
 	}
-#endif
 
 	return newobj;
 }
@@ -1882,12 +1879,10 @@ static void MergeScene_LogicBrick(SCA_ILogicBrick* brick, KX_Scene *to)
 	brick->Replace_NetworkScene(to->GetNetworkScene());
 
 	/* near sensors have physics controllers */
-#ifdef WITH_BULLET
 	KX_TouchSensor *touch_sensor = dynamic_cast<class KX_TouchSensor *>(brick);
 	if (touch_sensor) {
 		touch_sensor->GetPhysicsController()->SetPhysicsEnvironment(to->GetPhysicsEnvironment());
 	}
-#endif
 
 	// If we end up replacing a KX_TouchEventManager, we need to make sure
 	// physics controllers are properly in place. In other words, do this
@@ -1916,10 +1911,6 @@ static void MergeScene_LogicBrick(SCA_ILogicBrick* brick, KX_Scene *to)
 #endif
 }
 
-#ifdef WITH_BULLET
-#include "CcdGraphicController.h" // XXX  ctrl->SetPhysicsEnvironment(to->GetPhysicsEnvironment());
-#endif
-
 static void MergeScene_GameObject(KX_GameObject* gameobj, KX_Scene *to, KX_Scene *from)
 {
 	{
@@ -1972,12 +1963,10 @@ static void MergeScene_GameObject(KX_GameObject* gameobj, KX_Scene *to, KX_Scene
 		ctrl->SetPhysicsEnvironment(to->GetPhysicsEnvironment());
 	}
 
-#ifdef WITH_BULLET
 	ctrl = gameobj->GetPhysicsController();
 	if (ctrl) {
 		ctrl->SetPhysicsEnvironment(to->GetPhysicsEnvironment());
 	}
-#endif
 
 	/* SG_Node can hold a scene reference */
 	SG_Node *sg= gameobj->GetSGNode();
@@ -2008,9 +1997,8 @@ static void MergeScene_GameObject(KX_GameObject* gameobj, KX_Scene *to, KX_Scene
 
 bool KX_Scene::MergeScene(KX_Scene *other)
 {
-#ifdef WITH_BULLET
-	CcdPhysicsEnvironment *env=			dynamic_cast<CcdPhysicsEnvironment *>(this->GetPhysicsEnvironment());
-	CcdPhysicsEnvironment *env_other=	dynamic_cast<CcdPhysicsEnvironment *>(other->GetPhysicsEnvironment());
+	PHY_IPhysicsEnvironment *env = this->GetPhysicsEnvironment();
+	PHY_IPhysicsEnvironment *env_other = other->GetPhysicsEnvironment();
 
 	if ((env==NULL) != (env_other==NULL)) /* TODO - even when both scenes have NONE physics, the other is loaded with bullet enabled, ??? */
 	{
@@ -2018,7 +2006,6 @@ bool KX_Scene::MergeScene(KX_Scene *other)
 		printf("\tsource %d, terget %d\n", (int)(env!=NULL), (int)(env_other!=NULL));
 		return false;
 	}
-#endif // WITH_BULLET
 
 	if (GetSceneConverter() != other->GetSceneConverter()) {
 		printf("KX_Scene::MergeScene: converters differ, aborting\n");
@@ -2060,10 +2047,8 @@ bool KX_Scene::MergeScene(KX_Scene *other)
 	GetLightList()->MergeList(other->GetLightList());
 	other->GetLightList()->ReleaseAndRemoveAll();
 
-#ifdef WITH_BULLET
-	if (env) /* bullet scene? - dummy scenes don't need touching */
+	if (env)
 		env->MergeEnvironment(env_other);
-#endif
 
 	/* move materials across, assume they both use the same scene-converters
 	 * Do this after lights are merged so materials can use the lights in shaders
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
index b6a46b4..dcd30ea 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
@@ -1871,8 +1871,12 @@ btDispatcher*	CcdPhysicsEnvironment::GetDispatcher()
 	return m_dynamicsWorld->getDispatcher();
 }
 
-void CcdPhysicsEnvironment::MergeEnvironment(CcdPhysicsEnvironment *other)
+void CcdPhysicsEnvironment::MergeEnvironment(PHY_IPhysicsEnvironment *other_env)
 {
+	CcdPhysicsEnvironment *other = dynamic_cast<CcdPhysicsEnvironment*>(other_env);
+	printf("KX_Scene::MergeScene: Other scene is not using Bullet physics, not merging physics.\n");
+	return;
+
 	std::set<CcdPhysicsController*>::iterator it;
 
 	while (other->m_controllers.begin() != other->m_controllers.end())
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
index 0e8ac94..4e002f5 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
@@ -258,7 +258,7 @@ protected:
 	
 		class btConstraintSolver*	GetConstraintSolver();
 
-		void MergeEnvironment(CcdPhysicsEnvironment *other);
+		void MergeEnvironment(PHY_IPhysicsEnvironment *other_env);
 
 	protected:
 		
diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
index 41462f9..c06a8d9 100644
--- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
+++ b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
@@ -103,6 +103,11 @@ public:
 			return 0.f;
 		}
 
+	virtual void MergeEnvironment(PHY_IPhysicsEnvironment *other_env)
+	{
+		// Dummy, nothing to do here
+	}
+
 		
 #ifdef WITH_CXX_GUARDEDALLOC
 	MEM_CXX_CLASS_ALLOC_FUNCS("GE:DummyPhysicsEnvironment")
diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
index b1a0480..d2574b3 100644
--- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
+++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
@@ -188,6 +188,8 @@ class PHY_IPhysicsEnvironment
 		
 		virtual void	ExportFile(const char* filename) {};
 
+		virtual void MergeEnvironment(PHY_IPhysicsEnvironment *other_env) = 0;
+
 
 #ifdef WITH_CXX_GUARDEDALLOC
 	MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_IPhysicsEnvironment")




More information about the Bf-blender-cvs mailing list