[Bf-blender-cvs] [4616a7a] master: BGE: Fix collision callbacks for compound controllers

Porteries Tristan noreply at git.blender.org
Tue May 5 19:54:37 CEST 2015


Commit: 4616a7a4d3656049f8aef1170a9715c19a2aeed1
Author: Porteries Tristan
Date:   Tue May 5 19:42:27 2015 +0200
Branches: master
https://developer.blender.org/rB4616a7a4d3656049f8aef1170a9715c19a2aeed1

BGE: Fix collision callbacks for compound controllers

It fix some mistakes in b5e96530353ef22d184a60cd2b59a5e451ee211f and made a more safety behavior for collision callbacks used in compound controllers during adding and removing.

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

M	source/gameengine/Physics/Bullet/CcdPhysicsController.h
M	source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp

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

diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
index 4fcdc70..e3172e7 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
@@ -515,6 +515,11 @@ protected:
 		return (--m_registerCount == 0) ? true : false;
 	}
 
+	bool Registered() const
+	{
+		return (m_registerCount != 0);
+	}
+
 	void addCcdConstraintRef(btTypedConstraint* c);
 	void removeCcdConstraintRef(btTypedConstraint* c);
 	btTypedConstraint* getCcdConstraintRef(int index);
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
index c81d9c7..37cc26f 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
@@ -466,6 +466,14 @@ void	CcdPhysicsEnvironment::AddCcdPhysicsController(CcdPhysicsController* ctrl)
 		return;
 	}
 
+	/* In the case of compound child controller (see also RemoveCcdPhysicsController)
+	 * we add the controller to the trigger controlers list : m_triggerControllers
+	 * if it use collision callbacks.
+	 */
+	if (ctrl->Registered()) {
+		m_triggerControllers.insert(ctrl);
+	}
+
 	btRigidBody* body = ctrl->GetRigidBody();
 	btCollisionObject* obj = ctrl->GetCollisionObject();
 
@@ -508,15 +516,21 @@ void	CcdPhysicsEnvironment::AddCcdPhysicsController(CcdPhysicsController* ctrl)
 
 bool	CcdPhysicsEnvironment::RemoveCcdPhysicsController(CcdPhysicsController* ctrl)
 {
-	// the controller is still used as sensor
-	if (ctrl->m_registerCount != 0)
-		printf("Warning: removing controller with non-zero m_registerCount: %d\n", ctrl->m_registerCount);
-
 	// if the physics controller is already removed we do nothing
-	if (!m_controllers.erase(ctrl) || !m_triggerControllers.erase(ctrl)) {
+	if (!m_controllers.erase(ctrl)) {
 		return false;
 	}
 
+	/* In the case of compound child controller which use collision callbacks
+	 * we remove it from the m_triggerControllers list but leave m_registerCount
+	 * to know in AddCcdPhysicsController if we have to add it in m_triggerControllers
+	 * and to avoid an useless added in RequestCollisionCallback, indeed we can't register
+	 * more than one time a controller.
+	 */
+	if (ctrl->Registered()) {
+		m_triggerControllers.erase(ctrl);
+	}
+
 	//also remove constraint
 	btRigidBody* body = ctrl->GetRigidBody();
 	if (body)
@@ -567,6 +581,8 @@ bool	CcdPhysicsEnvironment::RemoveCcdPhysicsController(CcdPhysicsController* ctr
 			}
 		}
 	}
+
+	return true;
 }
 
 void	CcdPhysicsEnvironment::UpdateCcdPhysicsController(CcdPhysicsController* ctrl, btScalar newMass, int newCollisionFlags, short int newCollisionGroup, short int newCollisionMask)




More information about the Bf-blender-cvs mailing list