diff options
author | Porteries Tristan <republicthunderbolt9@gmail.com> | 2015-05-05 20:42:27 +0300 |
---|---|---|
committer | Porteries Tristan <republicthunderbolt9@gmail.com> | 2015-05-05 20:54:12 +0300 |
commit | 4616a7a4d3656049f8aef1170a9715c19a2aeed1 (patch) | |
tree | 3b3d20850e105bed9891dcf79af8baf57be96a5c | |
parent | 962d53e144149ab75ea28327ccbb22e91fa5d91e (diff) |
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.
-rw-r--r-- | source/gameengine/Physics/Bullet/CcdPhysicsController.h | 5 | ||||
-rw-r--r-- | source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp | 26 |
2 files changed, 26 insertions, 5 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index 4fcdc70c5a8..e3172e7fc45 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 c81d9c7de94..37cc26f6364 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) |