[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13933] trunk/blender/source/gameengine: Radar/Near sensor performance problem fixed

Benoit Bolsee benoit.bolsee at online.be
Sat Mar 1 20:17:38 CET 2008


Revision: 13933
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13933
Author:   ben2610
Date:     2008-03-01 20:17:37 +0100 (Sat, 01 Mar 2008)

Log Message:
-----------
Radar/Near sensor performance problem fixed

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
    trunk/blender/source/gameengine/Ketsji/KX_NearSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_NearSensor.h
    trunk/blender/source/gameengine/Ketsji/KX_TouchEventManager.cpp
    trunk/blender/source/gameengine/Ketsji/KX_TouchEventManager.h
    trunk/blender/source/gameengine/Ketsji/KX_TouchSensor.h
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
    trunk/blender/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.cpp
    trunk/blender/source/gameengine/Physics/common/PHY_DynamicTypes.h
    trunk/blender/source/gameengine/Physics/common/PHY_IPhysicsController.h
    trunk/blender/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h

Modified: trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp	2008-03-01 19:05:41 UTC (rev 13932)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp	2008-03-01 19:17:37 UTC (rev 13933)
@@ -1123,7 +1123,9 @@
 	ci.m_angularDamping = 1.f - shapeprops->m_ang_drag;
 	//need a bit of damping, else system doesn't behave well
 	ci.m_inertiaFactor = shapeprops->m_inertia/0.4f;//defaults to 0.4, don't want to change behaviour
-	
+	ci.m_collisionFilterGroup = (isbulletdyna) ? short(CcdConstructionInfo::DefaultFilter) : short(CcdConstructionInfo::StaticFilter);
+	ci.m_collisionFilterMask = (isbulletdyna) ? short(CcdConstructionInfo::AllFilter) : short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::StaticFilter);
+
 	KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,isbulletdyna);
 
 	if (objprop->m_in_active_layer)

Modified: trunk/blender/source/gameengine/Ketsji/KX_NearSensor.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_NearSensor.cpp	2008-03-01 19:05:41 UTC (rev 13932)
+++ trunk/blender/source/gameengine/Ketsji/KX_NearSensor.cpp	2008-03-01 19:17:37 UTC (rev 13933)
@@ -191,8 +191,37 @@
 	return result;
 }
 
+// this function is called at broad phase stage to check if the two controller
+// need to interact at all. It is used for Near/Radar sensor that don't need to
+// check collision with object not included in filter
+bool	KX_NearSensor::BroadPhaseFilterCollision(void*obj1,void*obj2)
+{
+	KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent());
+	
+	// need the mapping from PHY_IPhysicsController to gameobjects now
+	assert(obj1==m_physCtrl && obj2);
+	KX_ClientObjectInfo* client_info = static_cast<KX_ClientObjectInfo*>((static_cast<PHY_IPhysicsController*>(obj2))->getNewClientInfo());
 
+	KX_GameObject* gameobj = ( client_info ? 
+			client_info->m_gameobject :
+			NULL);
+	
+	if (gameobj && (gameobj != parent))
+	{
+		// only take valid colliders
+		if (client_info->m_type == KX_ClientObjectInfo::ACTOR)
+		{
+			if ((m_touchedpropname.Length() == 0) || 
+				(gameobj->GetProperty(m_touchedpropname)))
+			{
+				return true;
+			}
+		}
+	}
 
+	return false;
+}
+
 bool	KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData * coll_data)
 {
 //	KX_TouchEventManager* toucheventmgr = static_cast<KX_TouchEventManager*>(m_eventmgr);
@@ -208,20 +237,22 @@
 			client_info->m_gameobject :
 			NULL);
 	
-	if (gameobj && (gameobj != parent))
+	// these checks are done already in BroadPhaseFilterCollision()
+	if (gameobj /*&& (gameobj != parent)*/)
 	{
 		if (!m_colliders->SearchValue(gameobj))
 			m_colliders->Add(gameobj->AddRef());
 		// only take valid colliders
-		if (client_info->m_type == KX_ClientObjectInfo::ACTOR)
-		{
-			if ((m_touchedpropname.Length() == 0) || 
-				(gameobj->GetProperty(m_touchedpropname)))
-			{
+		// These checks are done already in BroadPhaseFilterCollision()
+		//if (client_info->m_type == KX_ClientObjectInfo::ACTOR)
+		//{
+		//	if ((m_touchedpropname.Length() == 0) || 
+		//		(gameobj->GetProperty(m_touchedpropname)))
+		//	{
 				m_bTriggered = true;
 				m_hitObject = gameobj;
-			}
-		}
+		//	}
+		//}
 	}
 	
 	return DT_CONTINUE;

Modified: trunk/blender/source/gameengine/Ketsji/KX_NearSensor.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_NearSensor.h	2008-03-01 19:05:41 UTC (rev 13932)
+++ trunk/blender/source/gameengine/Ketsji/KX_NearSensor.h	2008-03-01 19:17:37 UTC (rev 13933)
@@ -77,6 +77,7 @@
 	virtual void ReParent(SCA_IObject* parent);
 	virtual bool	NewHandleCollision(void* obj1,void* obj2,
 						 const PHY_CollData * coll_data); 
+	virtual bool	BroadPhaseFilterCollision(void*obj1,void*obj2);
 	virtual void RegisterSumo(KX_TouchEventManager *touchman);
 	
 	virtual PyObject* _getattr(const STR_String& attr);

Modified: trunk/blender/source/gameengine/Ketsji/KX_TouchEventManager.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_TouchEventManager.cpp	2008-03-01 19:05:41 UTC (rev 13932)
+++ trunk/blender/source/gameengine/Ketsji/KX_TouchEventManager.cpp	2008-03-01 19:17:37 UTC (rev 13933)
@@ -54,6 +54,7 @@
 
 	m_physEnv->addTouchCallback(PHY_OBJECT_RESPONSE, KX_TouchEventManager::newCollisionResponse, this);
 	m_physEnv->addTouchCallback(PHY_SENSOR_RESPONSE, KX_TouchEventManager::newCollisionResponse, this);
+	m_physEnv->addTouchCallback(PHY_BROADPH_RESPONSE, KX_TouchEventManager::newBroadphaseResponse, this);
 
 }
 
@@ -79,6 +80,26 @@
 	return false;
 }
 
+bool	 KX_TouchEventManager::newBroadphaseResponse(void *client_data, 
+							void *object1,
+							void *object2,
+							const PHY_CollData *coll_data)
+{
+	PHY_IPhysicsController* ctrl = static_cast<PHY_IPhysicsController*>(object1);
+	KX_ClientObjectInfo* info = (ctrl) ? static_cast<KX_ClientObjectInfo*>(ctrl->getNewClientInfo()) : NULL;
+	// This call back should only be called for controllers of Near and Radar sensor
+	if (info &&
+        info->m_sensors.size() == 1 &&
+		(info->m_type == KX_ClientObjectInfo::NEAR ||
+		 info->m_type == KX_ClientObjectInfo::RADAR))
+	{
+		// only one sensor for this type of object
+		KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(*info->m_sensors.begin());
+		return touchsensor->BroadPhaseFilterCollision(object1,object2);
+	}
+	return true;
+}
+
 void KX_TouchEventManager::RegisterSensor(SCA_ISensor* sensor)
 {
 	KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(sensor);

Modified: trunk/blender/source/gameengine/Ketsji/KX_TouchEventManager.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_TouchEventManager.h	2008-03-01 19:05:41 UTC (rev 13932)
+++ trunk/blender/source/gameengine/Ketsji/KX_TouchEventManager.h	2008-03-01 19:17:37 UTC (rev 13933)
@@ -56,7 +56,12 @@
 						void *object1,
 						void *object2,
 						const PHY_CollData *coll_data);
-	
+
+	static bool newBroadphaseResponse(void *client_data, 
+						void *object1,
+						void *object2,
+						const PHY_CollData *coll_data);
+
 	virtual bool	NewHandleCollision(void* obj1,void* obj2,
 						const PHY_CollData * coll_data); 
 

Modified: trunk/blender/source/gameengine/Ketsji/KX_TouchSensor.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_TouchSensor.h	2008-03-01 19:05:41 UTC (rev 13932)
+++ trunk/blender/source/gameengine/Ketsji/KX_TouchSensor.h	2008-03-01 19:17:37 UTC (rev 13933)
@@ -57,8 +57,6 @@
 	class SCA_EventManager*	m_eventmgr;
 	
 	class PHY_IPhysicsController*	m_physCtrl;
-	class PHY_ResponseTable*		m_responstTable;
-	class PHY_PhysicsController*	m_responsObject;
 
 	bool					m_bCollision;
 	bool					m_bTriggered;
@@ -86,7 +84,11 @@
 
 	virtual bool	NewHandleCollision(void*obj1,void*obj2,const PHY_CollData* colldata);
 
-	PHY_PhysicsController*	GetPhysicsController() { return m_responsObject;}
+	// Allows to do pre-filtering and save computation time
+	// obj1 = sensor physical controller, obj2 = physical controller of second object
+	// return value = true if collision should be checked on pair of object
+	virtual bool	BroadPhaseFilterCollision(void*obj1,void*obj2) { return true; }
+
   
 
 	virtual bool IsPositiveTrigger() {

Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp	2008-03-01 19:05:41 UTC (rev 13932)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp	2008-03-01 19:17:37 UTC (rev 13933)
@@ -36,6 +36,7 @@
 
 
 btVector3 startVel(0,0,0);//-10000);
+
 CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci)
 :m_cci(ci)
 {
@@ -119,17 +120,20 @@
 		m_cci.m_linearDamping,m_cci.m_angularDamping,
 		m_cci.m_friction,m_cci.m_restitution);
 
-	
-
 	//
 	// init the rigidbody properly
 	//
 	
 	//setMassProps this also sets collisionFlags
 	//convert collision flags!
-
+	//special case: a near/radar sensor controller should not be defined static or it will
+	//generate loads of static-static collision messages on the console
+	if ((m_cci.m_collisionFilterGroup & CcdConstructionInfo::SensorFilter) != 0)
+	{
+		// reset the flags that have been set so far
+		m_body->setCollisionFlags(0);
+	}
 	m_body->setCollisionFlags(m_body->getCollisionFlags() | m_cci.m_collisionFlags);
-	
 	m_body->setGravity( m_cci.m_gravity);
 	m_body->setDamping(m_cci.m_linearDamping, m_cci.m_angularDamping);
 
@@ -141,12 +145,14 @@
 	if (m_cci.m_physicsEnv)
 		m_cci.m_physicsEnv->removeCcdPhysicsController(this);
 
-	delete m_MotionState;
+	if (m_MotionState)
+		delete m_MotionState;
 	if (m_bulletMotionState)
 		delete m_bulletMotionState;
 	delete m_body;
 }
 
+
 		/**
 			SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
 		*/

Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h	2008-03-01 19:05:41 UTC (rev 13932)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h	2008-03-01 19:17:37 UTC (rev 13933)
@@ -46,7 +46,8 @@
 	        StaticFilter = 2,
 	        KinematicFilter = 4,
 	        DebrisFilter = 8,
-	        AllFilter = DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter,
+			SensorFilter = 16,
+	        AllFilter = DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorFilter,
 	};
 
 
@@ -61,6 +62,7 @@
 		m_collisionFlags(0),
 		m_collisionFilterGroup(DefaultFilter),
 		m_collisionFilterMask(AllFilter),
+		m_collisionShape(0),
 		m_MotionState(0),
 		m_physicsEnv(0),
 		m_inertiaFactor(1.f)
@@ -85,9 +87,8 @@
 	short int	m_collisionFilterGroup;
 	short int	m_collisionFilterMask;
 
-
-	btCollisionShape*			m_collisionShape;
-	class	PHY_IMotionState*			m_MotionState;
+	class btCollisionShape*	m_collisionShape;
+	class PHY_IMotionState*	m_MotionState;
 	
 	CcdPhysicsEnvironment*	m_physicsEnv; //needed for self-replication

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list