Radar/Near sensor performance problem fixed
[blender-staging.git] / source / gameengine / Ketsji / KX_NearSensor.cpp
index 34561045cab2e157d7c2724291715b6524bcfa24..8f85a889d21ab5d01583c1bb78b0a2123b8a9ca8 100644 (file)
@@ -191,7 +191,36 @@ bool KX_NearSensor::Evaluate(CValue* event)
        return result;
 }
 
+// this function is called at broad phase stage to check if the two controller
+// need to interact at all. It is used for Near/Radar sensor that don't need to
+// check collision with object not included in filter
+bool   KX_NearSensor::BroadPhaseFilterCollision(void*obj1,void*obj2)
+{
+       KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent());
+       
+       // need the mapping from PHY_IPhysicsController to gameobjects now
+       assert(obj1==m_physCtrl && obj2);
+       KX_ClientObjectInfo* client_info = static_cast<KX_ClientObjectInfo*>((static_cast<PHY_IPhysicsController*>(obj2))->getNewClientInfo());
 
+       KX_GameObject* gameobj = ( client_info ? 
+                       client_info->m_gameobject :
+                       NULL);
+       
+       if (gameobj && (gameobj != parent))
+       {
+               // only take valid colliders
+               if (client_info->m_type == KX_ClientObjectInfo::ACTOR)
+               {
+                       if ((m_touchedpropname.Length() == 0) || 
+                               (gameobj->GetProperty(m_touchedpropname)))
+                       {
+                               return true;
+                       }
+               }
+       }
+
+       return false;
+}
 
 bool   KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData * coll_data)
 {
@@ -208,20 +237,22 @@ bool      KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData
                        client_info->m_gameobject :
                        NULL);
        
-       if (gameobj && (gameobj != parent))
+       // these checks are done already in BroadPhaseFilterCollision()
+       if (gameobj /*&& (gameobj != parent)*/)
        {
                if (!m_colliders->SearchValue(gameobj))
                        m_colliders->Add(gameobj->AddRef());
                // only take valid colliders
-               if (client_info->m_type == KX_ClientObjectInfo::ACTOR)
-               {
-                       if ((m_touchedpropname.Length() == 0) || 
-                               (gameobj->GetProperty(m_touchedpropname)))
-                       {
+               // These checks are done already in BroadPhaseFilterCollision()
+               //if (client_info->m_type == KX_ClientObjectInfo::ACTOR)
+               //{
+               //      if ((m_touchedpropname.Length() == 0) || 
+               //              (gameobj->GetProperty(m_touchedpropname)))
+               //      {
                                m_bTriggered = true;
                                m_hitObject = gameobj;
-                       }
-               }
+               //      }
+               //}
        }
        
        return DT_CONTINUE;