Radar/Near sensor performance problem fixed
[blender-staging.git] / source / gameengine / Ketsji / KX_TouchEventManager.cpp
index 4c999b0ed693c56448c889e262fc7ee2602a0aac..8e546b896bca849b6e0d69ef0d93d146e21d07bb 100644 (file)
@@ -54,6 +54,7 @@ KX_TouchEventManager::KX_TouchEventManager(class SCA_LogicManager* logicmgr,
 
        m_physEnv->addTouchCallback(PHY_OBJECT_RESPONSE, KX_TouchEventManager::newCollisionResponse, this);
        m_physEnv->addTouchCallback(PHY_SENSOR_RESPONSE, KX_TouchEventManager::newCollisionResponse, this);
+       m_physEnv->addTouchCallback(PHY_BROADPH_RESPONSE, KX_TouchEventManager::newBroadphaseResponse, this);
 
 }
 
@@ -79,6 +80,26 @@ bool  KX_TouchEventManager::newCollisionResponse(void *client_data,
        return false;
 }
 
+bool    KX_TouchEventManager::newBroadphaseResponse(void *client_data, 
+                                                       void *object1,
+                                                       void *object2,
+                                                       const PHY_CollData *coll_data)
+{
+       PHY_IPhysicsController* ctrl = static_cast<PHY_IPhysicsController*>(object1);
+       KX_ClientObjectInfo* info = (ctrl) ? static_cast<KX_ClientObjectInfo*>(ctrl->getNewClientInfo()) : NULL;
+       // This call back should only be called for controllers of Near and Radar sensor
+       if (info &&
+        info->m_sensors.size() == 1 &&
+               (info->m_type == KX_ClientObjectInfo::NEAR ||
+                info->m_type == KX_ClientObjectInfo::RADAR))
+       {
+               // only one sensor for this type of object
+               KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(*info->m_sensors.begin());
+               return touchsensor->BroadPhaseFilterCollision(object1,object2);
+       }
+       return true;
+}
+
 void KX_TouchEventManager::RegisterSensor(SCA_ISensor* sensor)
 {
        KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(sensor);