BGE fix bug #17430: BGE Collide/Touch Sensor interfearing with other unrelated sensor states. The bug was introduced in the recent logic optimization patch. It only affects collision and touch sensors. The bug is fixed by keeping track of registration count.
This commit is contained in:
@@ -100,17 +100,17 @@ bool KX_TouchEventManager::newBroadphaseResponse(void *client_data,
|
||||
void KX_TouchEventManager::RegisterSensor(SCA_ISensor* sensor)
|
||||
{
|
||||
KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(sensor);
|
||||
m_sensors.insert(touchsensor);
|
||||
|
||||
touchsensor->RegisterSumo(this);
|
||||
if (m_sensors.insert(touchsensor).second)
|
||||
// the sensor was effectively inserted, register it
|
||||
touchsensor->RegisterSumo(this);
|
||||
}
|
||||
|
||||
void KX_TouchEventManager::RemoveSensor(SCA_ISensor* sensor)
|
||||
{
|
||||
KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(sensor);
|
||||
m_sensors.erase(touchsensor);
|
||||
|
||||
touchsensor->UnregisterSumo(this);
|
||||
if (m_sensors.erase(touchsensor))
|
||||
// the sensor was effectively removed, unregister it
|
||||
touchsensor->UnregisterSumo(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci)
|
||||
{
|
||||
m_collisionDelay = 0;
|
||||
m_newClientInfo = 0;
|
||||
|
||||
m_registerCount = 0;
|
||||
|
||||
m_MotionState = ci.m_MotionState;
|
||||
m_bulletMotionState = 0;
|
||||
|
||||
@@ -217,7 +218,7 @@ void CcdPhysicsController::WriteDynamicsToMotionState()
|
||||
void CcdPhysicsController::PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl)
|
||||
{
|
||||
m_MotionState = motionstate;
|
||||
|
||||
m_registerCount = 0;
|
||||
|
||||
|
||||
m_body = 0;
|
||||
|
||||
@@ -110,12 +110,19 @@ class CcdPhysicsController : public PHY_IPhysicsController
|
||||
|
||||
|
||||
void* m_newClientInfo;
|
||||
|
||||
int m_registerCount; // needed when multiple sensors use the same controller
|
||||
CcdConstructionInfo m_cci;//needed for replication
|
||||
void GetWorldOrientation(btMatrix3x3& mat);
|
||||
|
||||
void CreateRigidbody();
|
||||
|
||||
bool Register() {
|
||||
return (m_registerCount++ == 0) ? true : false;
|
||||
}
|
||||
bool Unregister() {
|
||||
return (--m_registerCount == 0) ? true : false;
|
||||
}
|
||||
|
||||
protected:
|
||||
void setWorldOrientation(const btMatrix3x3& mat);
|
||||
|
||||
|
||||
@@ -439,6 +439,9 @@ void CcdPhysicsEnvironment::removeCcdPhysicsController(CcdPhysicsController* ctr
|
||||
m_dynamicsWorld->removeRigidBody(ctrl->GetRigidBody());
|
||||
m_controllers.erase(ctrl);
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -473,6 +476,13 @@ void CcdPhysicsEnvironment::enableCcdPhysicsController(CcdPhysicsController* ctr
|
||||
}
|
||||
}
|
||||
|
||||
void CcdPhysicsEnvironment::disableCcdPhysicsController(CcdPhysicsController* ctrl)
|
||||
{
|
||||
if (m_controllers.erase(ctrl))
|
||||
{
|
||||
m_dynamicsWorld->removeRigidBody(ctrl->GetRigidBody());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CcdPhysicsEnvironment::beginFrame()
|
||||
@@ -885,13 +895,17 @@ void CcdPhysicsEnvironment::addSensor(PHY_IPhysicsController* ctrl)
|
||||
|
||||
void CcdPhysicsEnvironment::removeCollisionCallback(PHY_IPhysicsController* ctrl)
|
||||
{
|
||||
m_triggerControllers.erase((CcdPhysicsController*)ctrl);
|
||||
CcdPhysicsController* ccdCtrl = (CcdPhysicsController*)ctrl;
|
||||
if (ccdCtrl->Unregister())
|
||||
m_triggerControllers.erase(ccdCtrl);
|
||||
}
|
||||
|
||||
|
||||
void CcdPhysicsEnvironment::removeSensor(PHY_IPhysicsController* ctrl)
|
||||
{
|
||||
removeCcdPhysicsController((CcdPhysicsController*)ctrl);
|
||||
removeCollisionCallback(ctrl);
|
||||
|
||||
disableCcdPhysicsController((CcdPhysicsController*)ctrl);
|
||||
}
|
||||
|
||||
void CcdPhysicsEnvironment::addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)
|
||||
@@ -930,8 +944,8 @@ void CcdPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctr
|
||||
{
|
||||
CcdPhysicsController* ccdCtrl = static_cast<CcdPhysicsController*>(ctrl);
|
||||
|
||||
//printf("requestCollisionCallback\n");
|
||||
m_triggerControllers.insert(ccdCtrl);
|
||||
if (ccdCtrl->Register())
|
||||
m_triggerControllers.insert(ccdCtrl);
|
||||
}
|
||||
|
||||
void CcdPhysicsEnvironment::CallbackTriggers()
|
||||
|
||||
@@ -186,10 +186,7 @@ protected:
|
||||
|
||||
void updateCcdPhysicsController(CcdPhysicsController* ctrl, btScalar newMass, int newCollisionFlags, short int newCollisionGroup, short int newCollisionMask);
|
||||
|
||||
void disableCcdPhysicsController(CcdPhysicsController* ctrl)
|
||||
{
|
||||
removeCcdPhysicsController(ctrl);
|
||||
}
|
||||
void disableCcdPhysicsController(CcdPhysicsController* ctrl);
|
||||
|
||||
void enableCcdPhysicsController(CcdPhysicsController* ctrl);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user