[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15975] trunk/blender/source/gameengine: BGE fix bug #17430: BGE Collide/ Touch Sensor interfearing with other unrelated sensor states.
Benoit Bolsee
benoit.bolsee at online.be
Tue Aug 5 18:23:33 CEST 2008
Revision: 15975
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15975
Author: ben2610
Date: 2008-08-05 18:23:33 +0200 (Tue, 05 Aug 2008)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/source/gameengine/Ketsji/KX_TouchEventManager.cpp
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
Modified: trunk/blender/source/gameengine/Ketsji/KX_TouchEventManager.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_TouchEventManager.cpp 2008-08-05 16:12:40 UTC (rev 15974)
+++ trunk/blender/source/gameengine/Ketsji/KX_TouchEventManager.cpp 2008-08-05 16:23:33 UTC (rev 15975)
@@ -100,17 +100,17 @@
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);
}
Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp 2008-08-05 16:12:40 UTC (rev 15974)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp 2008-08-05 16:23:33 UTC (rev 15975)
@@ -42,7 +42,8 @@
{
m_collisionDelay = 0;
m_newClientInfo = 0;
-
+ m_registerCount = 0;
+
m_MotionState = ci.m_MotionState;
m_bulletMotionState = 0;
@@ -217,7 +218,7 @@
void CcdPhysicsController::PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl)
{
m_MotionState = motionstate;
-
+ m_registerCount = 0;
m_body = 0;
Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h 2008-08-05 16:12:40 UTC (rev 15974)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h 2008-08-05 16:23:33 UTC (rev 15975)
@@ -110,12 +110,19 @@
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);
Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp 2008-08-05 16:12:40 UTC (rev 15974)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp 2008-08-05 16:23:33 UTC (rev 15975)
@@ -439,6 +439,9 @@
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::disableCcdPhysicsController(CcdPhysicsController* ctrl)
+{
+ if (m_controllers.erase(ctrl))
+ {
+ m_dynamicsWorld->removeRigidBody(ctrl->GetRigidBody());
+ }
+}
void CcdPhysicsEnvironment::beginFrame()
@@ -885,13 +895,17 @@
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 @@
{
CcdPhysicsController* ccdCtrl = static_cast<CcdPhysicsController*>(ctrl);
- //printf("requestCollisionCallback\n");
- m_triggerControllers.insert(ccdCtrl);
+ if (ccdCtrl->Register())
+ m_triggerControllers.insert(ccdCtrl);
}
void CcdPhysicsEnvironment::CallbackTriggers()
Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h 2008-08-05 16:12:40 UTC (rev 15974)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h 2008-08-05 16:23:33 UTC (rev 15975)
@@ -186,10 +186,7 @@
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);
More information about the Bf-blender-cvs
mailing list