Revision: 20022
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20022
Author:   ben2610
Date:     2009-05-01 22:34:23 +0200 (Fri, 01 May 2009)

Log Message:
-----------
BGE performance:

- Vast performance increase when removing scene containing large number of 
  objects: the sensor/controller map was updated for each deleted object, 
  causing massive slow down when the number of objects was large (O(n^2)).
- Use reference when scanning the sensor map => avoid useless copy.
- Remove dynamically the object bounding box from the DBVT when the object
  is invisible => faster culling.

Modified Paths:
--------------
    trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.h
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp

Modified: trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.cpp      
2009-05-01 19:02:23 UTC (rev 20021)
+++ trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.cpp      
2009-05-01 20:34:23 UTC (rev 20022)
@@ -79,6 +79,13 @@
        m_activeActuators.clear();
 }
 
+// this function is a performance helper when the scene is destoyed
+// without it, the map updated for each object... a massive slow down when 
there are
+// large number of objects. By clearing the map upfront we avoid the waster of 
time.
+void SCA_LogicManager::RemoveSensorMap()
+{
+       m_sensorcontrollermapje.clear();
+}
 
 /*
 // this kind of fixes bug 398 but breakes games, so better leave it out for 
now.
@@ -171,12 +178,16 @@
 
 void SCA_LogicManager::RemoveSensor(SCA_ISensor* sensor)
 {
-       controllerlist contlist = m_sensorcontrollermapje[sensor];
-       for (controllerlist::const_iterator c= 
contlist.begin();!(c==contlist.end());c++)
+       sensormap_t::const_iterator mit = m_sensorcontrollermapje.find(sensor);
+       if (mit != m_sensorcontrollermapje.end())
        {
-               (*c)->UnlinkSensor(sensor);
+               const controllerlist& contlist = mit->second;
+               for (controllerlist::const_iterator c= 
contlist.begin();!(c==contlist.end());c++)
+               {
+                       (*c)->UnlinkSensor(sensor);
+               }
+               m_sensorcontrollermapje.erase(sensor);
        }
-    m_sensorcontrollermapje.erase(sensor);
        sensor->UnregisterToManager();
 }
 
@@ -184,7 +195,7 @@
 {
        controller->UnlinkAllSensors();
        controller->UnlinkAllActuators();
-       std::map<SCA_ISensor*,controllerlist>::iterator sit;
+       sensormap_t::iterator sit;
        for (sit = 
m_sensorcontrollermapje.begin();!(sit==m_sensorcontrollermapje.end());++sit)
        {
                (*sit).second.remove(controller);
@@ -197,10 +208,10 @@
        m_removedActuators.push_back(SmartActuatorPtr(actuator,0));
        // take care that no controller can use this actuator again !
 
-       std::map<SCA_ISensor*,controllerlist>::const_iterator sit;
+       sensormap_t::const_iterator sit;
        for (sit = 
m_sensorcontrollermapje.begin();!(sit==m_sensorcontrollermapje.end());++sit)
        {
-               controllerlist contlist = (*sit).second;
+               const controllerlist& contlist = sit->second;
                for (list<SCA_IController*>::const_iterator c= 
contlist.begin();!(c==contlist.end());c++)
                {
                        (*c)->UnlinkActuator(actuator);
@@ -237,8 +248,8 @@
        !(is==m_activatedsensors.end());is++)
        {
                SCA_ISensor* sensor = *is;
-                controllerlist contlist = m_sensorcontrollermapje[sensor];
-               for (list<SCA_IController*>::const_iterator c= contlist.begin();
+        const controllerlist& contlist = m_sensorcontrollermapje[sensor];
+        for (list<SCA_IController*>::const_iterator c= contlist.begin();
                        !(c==contlist.end());c++)
                {
                                SCA_IController* contr = 
*c;//controllerarray->at(c);

Modified: trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.h        
2009-05-01 19:02:23 UTC (rev 20021)
+++ trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.h        
2009-05-01 20:34:23 UTC (rev 20022)
@@ -47,7 +47,8 @@
 #include "KX_HashedPtr.h"
 
 using namespace std;
-typedef list<class SCA_IController*> controllerlist;
+typedef std::list<class SCA_IController*> controllerlist;
+typedef std::map<class SCA_ISensor*,controllerlist > sensormap_t;
 
 /** 
  * This manager handles sensor, controllers and actuators.
@@ -101,7 +102,7 @@
        set<class SmartActuatorPtr>                     m_activeActuators;
        set<class SmartControllerPtr>           m_triggeredControllerSet;
 
-       map<SCA_ISensor*,controllerlist >       m_sensorcontrollermapje;
+       sensormap_t                                                     
m_sensorcontrollermapje;
 
        // need to find better way for this
        // also known as FactoryManager...
@@ -116,6 +117,9 @@
 public:
        SCA_LogicManager();
        virtual ~SCA_LogicManager();
+       // can ONLY be used during scene destruction, avoid massive slow down 
when scene has many many objects
+       void RemoveSensorMap();         
+
        //void  SetKeyboardManager(SCA_KeyboardManager* keyboardmgr) { 
m_keyboardmgr=keyboardmgr;}
        void    RegisterEventManager(SCA_EventManager* eventmgr);
        void    RegisterToSensor(SCA_IController* controller,

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp    2009-05-01 
19:02:23 UTC (rev 20021)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp    2009-05-01 
20:34:23 UTC (rev 20022)
@@ -628,6 +628,8 @@
 {
        if (GetSGNode()) {
                m_bVisible = v;
+               if (m_pGraphicController)
+                       m_pGraphicController->Activate(m_bVisible);
                if (recursive)
                        setVisible_recursive(GetSGNode(), v);
        }

Modified: trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp 2009-05-01 19:02:23 UTC 
(rev 20021)
+++ trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp 2009-05-01 20:34:23 UTC 
(rev 20022)
@@ -208,6 +208,8 @@
        // It's still there but we remove all properties here otherwise some
        // reference might be hanging and causing late release of objects
        RemoveAllDebugProperties();
+       // early removal of sensor map to avoid massive slow down when there 
are many objects
+       m_logicmgr->RemoveSensorMap();
 
        while (GetRootParentList()->GetCount() > 0) 
        {


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to