synched with trunk at revision 36569
[blender.git] / source / gameengine / Ketsji / KX_KetsjiEngine.cpp
index dfac6e1..eef543e 100644 (file)
  * The engine ties all game modules together. 
  */
 
-#ifdef WIN32
+/** \file gameengine/Ketsji/KX_KetsjiEngine.cpp
+ *  \ingroup ketsji
+ */
+
+
+#if defined(WIN32) && !defined(FREE_WINDOWS)
 #pragma warning (disable : 4786)
 #endif //WIN32
 
 #include <iostream>
+#include <stdio.h>
 
 #include "KX_KetsjiEngine.h"
 
@@ -55,6 +61,7 @@
 #include "KX_Scene.h"
 #include "MT_CmMatrix4x4.h"
 #include "KX_Camera.h"
+#include "KX_FontObject.h"
 #include "KX_Dome.h"
 #include "KX_Light.h"
 #include "KX_PythonInit.h"
 #include "KX_TimeCategoryLogger.h"
 
 #include "RAS_FramingManager.h"
-#include "stdio.h"
 #include "DNA_world_types.h"
 #include "DNA_scene_types.h"
 
+#include "KX_NavMeshObject.h"
+
 // If define: little test for Nzc: guarded drawing. If the canvas is
 // not valid, skip rendering this frame.
 //#define NZC_GUARDED_OUTPUT
@@ -112,7 +120,7 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system)
        m_rendertools(NULL),
        m_sceneconverter(NULL),
        m_networkdevice(NULL),
-#ifndef DISABLE_PYTHON
+#ifdef WITH_PYTHON
        m_pythondictionary(NULL),
 #endif
        m_keyboarddevice(NULL),
@@ -233,9 +241,9 @@ void KX_KetsjiEngine::SetRasterizer(RAS_IRasterizer* rasterizer)
        m_rasterizer = rasterizer;
 }
 
-#ifndef DISABLE_PYTHON
+#ifdef WITH_PYTHON
 /*
- * At the moment the GameLogic module is imported into 'pythondictionary' after this function is called.
+ * At the moment the bge.logic module is imported into 'pythondictionary' after this function is called.
  * if this function ever changes to assign a copy, make sure the game logic module is imported into this dictionary before hand.
  */
 void KX_KetsjiEngine::SetPyNamespace(PyObject* pythondictionary)
@@ -285,6 +293,7 @@ void KX_KetsjiEngine::RenderDome()
                return;
 
        KX_SceneList::iterator sceneit;
+       KX_Scene* scene;
 
        int n_renders=m_dome->GetNumberRenders();// usually 4 or 6
        for (int i=0;i<n_renders;i++){
@@ -292,7 +301,7 @@ void KX_KetsjiEngine::RenderDome()
                for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++)
                // for each scene, call the proceed functions
                {
-                       KX_Scene* scene = *sceneit;
+                       scene = *sceneit;
                        KX_Camera* cam = scene->GetActiveCamera();
 
                        m_rendertools->BeginFrame(m_rasterizer);
@@ -368,6 +377,10 @@ void KX_KetsjiEngine::RenderDome()
                        );
        }
        m_dome->Draw();
+       // Draw Callback for the last scene
+#ifdef WITH_PYTHON
+       scene->RunDrawingCallbacks(scene->GetPostDrawCB());
+#endif 
        EndFrame();
 }
 
@@ -607,7 +620,7 @@ else
                                m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
                                SG_SetActiveStage(SG_STAGE_PHYSICS1);
                                // set Python hooks for each scene
-#ifndef DISABLE_PYTHON
+#ifdef WITH_PYTHON
                                PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
 #endif
                                KX_SetActiveScene(scene);
@@ -711,7 +724,7 @@ else
                                m_suspendeddelta = scene->getSuspendedDelta();
                                
                                // set Python hooks for each scene
-#ifndef DISABLE_PYTHON
+#ifdef WITH_PYTHON
                                PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
 #endif
                                KX_SetActiveScene(scene);
@@ -941,6 +954,14 @@ int KX_KetsjiEngine::GetExitCode()
                if (m_scenes.begin()==m_scenes.end())
                        m_exitcode = KX_EXIT_REQUEST_NO_SCENES_LEFT;
        }
+       
+       // check if the window has been closed.
+       if(!m_exitcode)
+       {
+               //if(!m_canvas->Check()) {
+               //      m_exitcode = KX_EXIT_REQUEST_OUTSIDE;
+               //}
+       }
 
        return m_exitcode;
 }
@@ -961,44 +982,17 @@ void KX_KetsjiEngine::DoSound(KX_Scene* scene)
        KX_Camera* cam = scene->GetActiveCamera();
        if (!cam)
                return;
-       MT_Point3 listenerposition = cam->NodeGetWorldPosition();
-       MT_Vector3 listenervelocity = cam->GetLinearVelocity();
-       MT_Matrix3x3 listenerorientation = cam->NodeGetWorldOrientation();
-
-       {
-               AUD_3DData data;
-               float f;
-
-               listenerorientation.getValue3x3(data.orientation);
-               listenerposition.getValue(data.position);
-               listenervelocity.getValue(data.velocity);
-
-               f = data.position[1];
-               data.position[1] = data.position[2];
-               data.position[2] = -f;
 
-               f = data.velocity[1];
-               data.velocity[1] = data.velocity[2];
-               data.velocity[2] = -f;
+       float f[4];
 
-               f = data.orientation[1];
-               data.orientation[1] = data.orientation[2];
-               data.orientation[2] = -f;
+       cam->NodeGetWorldPosition().getValue(f);
+       AUD_setListenerLocation(f);
 
-               f = data.orientation[3];
-               data.orientation[3] = -data.orientation[6];
-               data.orientation[6] = f;
+       cam->GetLinearVelocity().getValue(f);
+       AUD_setListenerVelocity(f);
 
-               f = data.orientation[4];
-               data.orientation[4] = -data.orientation[8];
-               data.orientation[8] = -f;
-
-               f = data.orientation[5];
-               data.orientation[5] = data.orientation[7];
-               data.orientation[7] = f;
-
-               AUD_updateListener(&data);
-       }
+       cam->NodeGetWorldOrientation().getRotation().getValue(f);
+       AUD_setListenerOrientation(f);
 }
 
 
@@ -1309,16 +1303,32 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam)
        m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true);
        SG_SetActiveStage(SG_STAGE_RENDER);
 
-#ifndef DISABLE_PYTHON
+#ifdef WITH_PYTHON
        // Run any pre-drawing python callbacks
        scene->RunDrawingCallbacks(scene->GetPreDrawCB());
 #endif
 
        scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools);
+
+       //render all the font objects for this scene
+       RenderFonts(scene);
        
        if (scene->GetPhysicsEnvironment())
                scene->GetPhysicsEnvironment()->debugDrawWorld();
 }
+
+void KX_KetsjiEngine::RenderFonts(KX_Scene* scene)
+{
+       list<class KX_FontObject*>* fonts = scene->GetFonts();
+       
+       list<KX_FontObject*>::iterator it = fonts->begin();
+       while(it != fonts->end())
+       {
+               (*it)->DrawText();
+               ++it;
+       }
+}
+
 /*
 To run once per scene
 */
@@ -1326,10 +1336,10 @@ void KX_KetsjiEngine::PostRenderScene(KX_Scene* scene)
 {
        m_rendertools->MotionBlur(m_rasterizer);
        scene->Render2DFilters(m_canvas);
-#ifndef DISABLE_PYTHON
+#ifdef WITH_PYTHON
        scene->RunDrawingCallbacks(scene->GetPostDrawCB());     
 #endif
-       m_rasterizer->FlushDebugLines();
+       m_rasterizer->FlushDebugShapes();
 }
 
 void KX_KetsjiEngine::StopEngine()
@@ -1621,7 +1631,8 @@ KX_Scene* KX_KetsjiEngine::CreateScene(Scene *scene)
                                                                          m_mousedevice,
                                                                          m_networkdevice,
                                                                          scene->id.name+2,
-                                                                         scene);
+                                                                         scene,
+                                                                         m_canvas);
 
        m_sceneconverter->ConvertScene(tmpscene,
                                                          m_rendertools,