BGE: Remove function DisableCcdPhysicsController and EnableCcdPhysicsController in CcdPhysicsEnvironment
Replace EnableCcdPhysicsController by AddCcdPhysicsController and DisableCcdPhysicsController by RemoveCcdPhysicsController. Tested with compound shapes and collision sensors. Reviewers:agoose77, ideasman42
This commit is contained in:
@@ -1627,7 +1627,7 @@ void CcdPhysicsController::AddCompoundChild(PHY_IPhysicsController* child)
|
||||
// must update the broadphase cache,
|
||||
GetPhysicsEnvironment()->RefreshCcdPhysicsController(this);
|
||||
// remove the children
|
||||
GetPhysicsEnvironment()->DisableCcdPhysicsController(childCtrl);
|
||||
GetPhysicsEnvironment()->RemoveCcdPhysicsController(childCtrl);
|
||||
}
|
||||
|
||||
/* Reverse function of the above, it will remove a shape from a compound shape
|
||||
@@ -1683,7 +1683,7 @@ void CcdPhysicsController::RemoveCompoundChild(PHY_IPhysicsController* child)
|
||||
// must update the broadphase cache,
|
||||
GetPhysicsEnvironment()->RefreshCcdPhysicsController(this);
|
||||
// reactivate the children
|
||||
GetPhysicsEnvironment()->EnableCcdPhysicsController(childCtrl);
|
||||
GetPhysicsEnvironment()->AddCcdPhysicsController(childCtrl);
|
||||
}
|
||||
|
||||
PHY_IPhysicsController* CcdPhysicsController::GetReplica()
|
||||
|
@@ -461,6 +461,11 @@ m_scalingPropagated(false)
|
||||
|
||||
void CcdPhysicsEnvironment::AddCcdPhysicsController(CcdPhysicsController* ctrl)
|
||||
{
|
||||
// the controller is already added we do nothing
|
||||
if (!m_controllers.insert(ctrl).second) {
|
||||
return;
|
||||
}
|
||||
|
||||
btRigidBody* body = ctrl->GetRigidBody();
|
||||
btCollisionObject* obj = ctrl->GetCollisionObject();
|
||||
|
||||
@@ -469,8 +474,6 @@ void CcdPhysicsEnvironment::AddCcdPhysicsController(CcdPhysicsController* ctrl)
|
||||
if (body)
|
||||
body->setGravity( m_gravity );
|
||||
|
||||
m_controllers.insert(ctrl);
|
||||
|
||||
if (body)
|
||||
{
|
||||
//use explicit group/filter for finer control over collision in bullet => near/radar sensor
|
||||
@@ -505,6 +508,15 @@ 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)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//also remove constraint
|
||||
btRigidBody* body = ctrl->GetRigidBody();
|
||||
if (body)
|
||||
@@ -555,13 +567,6 @@ bool CcdPhysicsEnvironment::RemoveCcdPhysicsController(CcdPhysicsController* ctr
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ctrl->m_registerCount != 0)
|
||||
printf("Warning: removing controller with non-zero m_registerCount: %d\n", ctrl->m_registerCount);
|
||||
|
||||
//remove it from the triggers
|
||||
m_triggerControllers.erase(ctrl);
|
||||
|
||||
return (m_controllers.erase(ctrl) != 0);
|
||||
}
|
||||
|
||||
void CcdPhysicsEnvironment::UpdateCcdPhysicsController(CcdPhysicsController* ctrl, btScalar newMass, int newCollisionFlags, short int newCollisionGroup, short int newCollisionMask)
|
||||
@@ -597,43 +602,6 @@ void CcdPhysicsEnvironment::UpdateCcdPhysicsController(CcdPhysicsController* ctr
|
||||
ctrl->m_cci.m_collisionFlags = newCollisionFlags;
|
||||
}
|
||||
|
||||
void CcdPhysicsEnvironment::EnableCcdPhysicsController(CcdPhysicsController* ctrl)
|
||||
{
|
||||
if (m_controllers.insert(ctrl).second)
|
||||
{
|
||||
btCollisionObject* obj = ctrl->GetCollisionObject();
|
||||
obj->setUserPointer(ctrl);
|
||||
// update the position of the object from the user
|
||||
if (ctrl->GetMotionState())
|
||||
{
|
||||
btTransform xform = CcdPhysicsController::GetTransformFromMotionState(ctrl->GetMotionState());
|
||||
ctrl->SetCenterOfMassTransform(xform);
|
||||
}
|
||||
m_dynamicsWorld->addCollisionObject(obj,
|
||||
ctrl->GetCollisionFilterGroup(), ctrl->GetCollisionFilterMask());
|
||||
}
|
||||
}
|
||||
|
||||
void CcdPhysicsEnvironment::DisableCcdPhysicsController(CcdPhysicsController* ctrl)
|
||||
{
|
||||
if (m_controllers.erase(ctrl))
|
||||
{
|
||||
btRigidBody* body = ctrl->GetRigidBody();
|
||||
if (body)
|
||||
{
|
||||
m_dynamicsWorld->removeRigidBody(body);
|
||||
} else
|
||||
{
|
||||
if (ctrl->GetSoftBody())
|
||||
{
|
||||
} else
|
||||
{
|
||||
m_dynamicsWorld->removeCollisionObject(ctrl->GetCollisionObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CcdPhysicsEnvironment::RefreshCcdPhysicsController(CcdPhysicsController* ctrl)
|
||||
{
|
||||
btCollisionObject* obj = ctrl->GetCollisionObject();
|
||||
@@ -2204,15 +2172,8 @@ btTypedConstraint* CcdPhysicsEnvironment::GetConstraintById(int constraintId)
|
||||
|
||||
void CcdPhysicsEnvironment::AddSensor(PHY_IPhysicsController* ctrl)
|
||||
{
|
||||
|
||||
CcdPhysicsController* ctrl1 = (CcdPhysicsController* )ctrl;
|
||||
// addSensor() is a "light" function for bullet because it is used
|
||||
// dynamically when the sensor is activated. Use enableCcdPhysicsController() instead
|
||||
//if (m_controllers.insert(ctrl1).second)
|
||||
//{
|
||||
// addCcdPhysicsController(ctrl1);
|
||||
//}
|
||||
EnableCcdPhysicsController(ctrl1);
|
||||
AddCcdPhysicsController(ctrl1);
|
||||
}
|
||||
|
||||
bool CcdPhysicsEnvironment::RemoveCollisionCallback(PHY_IPhysicsController* ctrl)
|
||||
@@ -2227,7 +2188,7 @@ bool CcdPhysicsEnvironment::RemoveCollisionCallback(PHY_IPhysicsController* ctrl
|
||||
|
||||
void CcdPhysicsEnvironment::RemoveSensor(PHY_IPhysicsController* ctrl)
|
||||
{
|
||||
DisableCcdPhysicsController((CcdPhysicsController*)ctrl);
|
||||
RemoveCcdPhysicsController((CcdPhysicsController*)ctrl);
|
||||
}
|
||||
|
||||
void CcdPhysicsEnvironment::AddTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)
|
||||
|
@@ -221,10 +221,6 @@ protected:
|
||||
|
||||
void UpdateCcdPhysicsController(CcdPhysicsController* ctrl, btScalar newMass, int newCollisionFlags, short int newCollisionGroup, short int newCollisionMask);
|
||||
|
||||
void DisableCcdPhysicsController(CcdPhysicsController* ctrl);
|
||||
|
||||
void EnableCcdPhysicsController(CcdPhysicsController* ctrl);
|
||||
|
||||
void RefreshCcdPhysicsController(CcdPhysicsController* ctrl);
|
||||
|
||||
bool IsActiveCcdPhysicsController(CcdPhysicsController *ctrl);
|
||||
|
Reference in New Issue
Block a user