synched with trunk at revision 36569
[blender.git] / source / gameengine / Ketsji / KX_Scene.cpp
index 28dc660..5e0e460 100644 (file)
@@ -87,6 +87,7 @@
 #include "BL_ModifierDeformer.h"
 #include "BL_ShapeDeformer.h"
 #include "BL_DeformableGameObject.h"
+#include "KX_ObstacleSimulation.h"
 
 #ifdef USE_BULLET
 #include "KX_SoftBodyDeformer.h"
@@ -213,6 +214,19 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice,
 
        m_bucketmanager=new RAS_BucketManager();
        
+       bool showObstacleSimulation = scene->gm.flag & GAME_SHOW_OBSTACLE_SIMULATION;
+       switch (scene->gm.obstacleSimulation)
+       {
+       case OBSTSIMULATION_TOI_rays:
+               m_obstacleSimulation = new KX_ObstacleSimulationTOI_rays((MT_Scalar)scene->gm.levelHeight, showObstacleSimulation);
+               break;
+       case OBSTSIMULATION_TOI_cells:
+               m_obstacleSimulation = new KX_ObstacleSimulationTOI_cells((MT_Scalar)scene->gm.levelHeight, showObstacleSimulation);
+               break;
+       default:
+               m_obstacleSimulation = NULL;
+       }
+       
 #ifdef WITH_PYTHON
        m_attr_dict = PyDict_New(); /* new ref */
        m_draw_call_pre = NULL;
@@ -235,6 +249,9 @@ KX_Scene::~KX_Scene()
                this->RemoveObject(parentobj);
        }
 
+       if (m_obstacleSimulation)
+               delete m_obstacleSimulation;
+
        if(m_objectlist)
                m_objectlist->Release();
 
@@ -1526,6 +1543,10 @@ void KX_Scene::LogicEndFrame()
                obj->Release();
                RemoveObject(obj);
        }
+
+       //prepare obstacle simulation for new frame
+       if (m_obstacleSimulation)
+               m_obstacleSimulation->UpdateObstacles();
 }
 
 
@@ -1953,6 +1974,8 @@ PyMethodDef KX_Scene::Methods[] = {
        KX_PYMETHODTABLE(KX_Scene, replace),
        KX_PYMETHODTABLE(KX_Scene, suspend),
        KX_PYMETHODTABLE(KX_Scene, resume),
+       KX_PYMETHODTABLE(KX_Scene, drawObstacleSimulation),
+
        
        /* dict style access */
        KX_PYMETHODTABLE(KX_Scene, get),
@@ -2277,6 +2300,16 @@ KX_PYMETHODDEF_DOC(KX_Scene, resume,
        Py_RETURN_NONE;
 }
 
+KX_PYMETHODDEF_DOC(KX_Scene, drawObstacleSimulation,
+                                  "drawObstacleSimulation()\n"
+                                  "Draw debug visualization of obstacle simulation.\n")
+{
+       if (GetObstacleSimulation())
+               GetObstacleSimulation()->DrawObstacles();
+
+       Py_RETURN_NONE;
+}
+
 /* Matches python dict.get(key, [default]) */
 KX_PYMETHODDEF_DOC(KX_Scene, get, "")
 {