BGE: Fix collision callbacks for compound controllers

It fix some mistakes in b5e9653035 and made a more safety behavior for collision callbacks used in compound controllers during adding and removing.
This commit is contained in:
Porteries Tristan 2015-05-05 19:42:27 +02:00
parent 962d53e144
commit 4616a7a4d3
2 changed files with 26 additions and 5 deletions

View File

@ -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);

View File

@ -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)