Merged 15170:15635 from trunk (no conflicts or even merges)
[blender.git] / source / gameengine / GamePlayer / ghost / GPG_Application.cpp
index 19f387bc760e1783c91188e6d4ef47c0a478f5ea..b5ebffb93784e3652ddcfee0920dd460e04d1899 100644 (file)
@@ -1,15 +1,12 @@
 /**
  * $Id$
  *
- * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version. The Blender
- * Foundation also sells licenses for use in proprietary software under
- * the Blender License.  See http://www.blender.org/BL/ for information
- * about this.
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,7 +24,7 @@
  *
  * Contributor(s): none yet.
  *
- * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * ***** END GPL LICENSE BLOCK *****
  * GHOST Blender Player application implementation file.
  */
 
        #include <windows.h>
 #endif
 
-#ifdef __APPLE__
-#define GL_GLEXT_LEGACY 1
-#include <OpenGL/gl.h>
-#include <OpenGL/glu.h>
-#else
-#include <GL/gl.h>
-#include <GL/glu.h>
-#endif
+#include "GL/glew.h"
 
 #include "GPG_Application.h"
 
 #include <iostream>
 #include <MT_assert.h>
+#include <stdlib.h>
 
 /**********************************
  * Begin Blender include block
@@ -132,7 +123,8 @@ GPG_Application::GPG_Application(GHOST_ISystem* system, struct Main* maggie, STR
          m_sceneconverter(0),
          m_networkdevice(0), 
          m_audiodevice(0),
-         m_blendermat(0)
+         m_blendermat(0),
+         m_blenderglslmat(0)
 {
        fSystem = system;
 }
@@ -356,6 +348,7 @@ bool GPG_Application::startFullScreen(
 
 
 
+
 bool GPG_Application::StartGameEngine(int stereoMode)
 {
        bool success = initEngine(m_mainWindow, stereoMode);
@@ -434,10 +427,12 @@ bool GPG_Application::processEvent(GHOST_IEvent* event)
                                        m_exitRequested = m_ketsjiengine->GetExitCode();
                                        
                                        // kick the engine
-                                       m_ketsjiengine->NextFrame();
-                                       
-                                       // render the frame
-                                       m_ketsjiengine->Render();
+                                       bool renderFrame = m_ketsjiengine->NextFrame();
+                                       if (renderFrame)
+                                       {
+                                               // render the frame
+                                               m_ketsjiengine->Render();
+                                       }
                                }
                                m_exitString = m_ketsjiengine->GetExitString();
                        }
@@ -482,7 +477,8 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
 {
        if (!m_engineInitialized)
        {
-               bgl::InitExtensions(1);
+               glewInit();
+               bgl::InitExtensions(true);
 
                // get and set the preferences
                SYS_SystemHandle syshandle = SYS_GetSystem();
@@ -493,25 +489,19 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
                // SYS_WriteCommandLineInt(syshandle, "vertexarrays",1);                
                bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
                bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
+               bool fixedFr = (G.fileflags & G_FILE_ENABLE_ALL_FRAMES);
+
+               bool showPhysics = (G.fileflags & G_FILE_SHOW_PHYSICS);
+               SYS_WriteCommandLineInt(syshandle, "show_physics", showPhysics);
+
+               bool fixed_framerate= (SYS_GetCommandLineInt(syshandle, "fixed_framerate", fixedFr) != 0);
                bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
-               bool useVertexArrays = SYS_GetCommandLineInt(syshandle,"vertexarrays",1) != 0;
                bool useLists = (SYS_GetCommandLineInt(syshandle, "displaylists", G.fileflags & G_FILE_DIAPLAY_LISTS) != 0);
-#ifdef GL_ARB_multitexture
-               int gameflag =(G.fileflags & G_FILE_GAME_MAT);
-               // ----------------------------------
-               if(bgl::RAS_EXT_support._ARB_multitexture && bgl::QueryVersion(1, 1)) {
+
+               if(GLEW_ARB_multitexture && GLEW_VERSION_1_1) {
+                       int gameflag =(G.fileflags & G_FILE_GAME_MAT);
                        m_blendermat = (SYS_GetCommandLineInt(syshandle, "blender_material", gameflag) != 0);
-                       int unitmax=0;
-                       glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint*)&unitmax);
-                       bgl::max_texture_units = MAXTEX>unitmax?unitmax:MAXTEX;
-                       //std::cout << "using(" << bgl::max_texture_units << ") of(" << unitmax << ") texture units." << std::endl;
-               } else {
-                       bgl::max_texture_units = 0;
                }
-#else
-               m_blendermat=0;
-#endif//GL_ARB_multitexture
-               // ----------------------------------
        
                // create the canvas, rasterizer and rendertools
                m_canvas = new GPG_Canvas(window);
@@ -523,12 +513,17 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
                if (!m_rendertools)
                        goto initFailed;
                
-               if(useLists)
-                       m_rasterizer = new RAS_ListRasterizer(m_canvas);
-               else if (useVertexArrays && bgl::QueryVersion(1, 1))
+               if(useLists) {
+                       if(GLEW_VERSION_1_1)
+                               m_rasterizer = new RAS_ListRasterizer(m_canvas, true);
+                       else
+                               m_rasterizer = new RAS_ListRasterizer(m_canvas);
+               }
+               else if (GLEW_VERSION_1_1)
                        m_rasterizer = new RAS_VAOpenGLRasterizer(m_canvas);
                else
                        m_rasterizer = new RAS_OpenGLRasterizer(m_canvas);
+
                m_rasterizer->SetStereoMode((RAS_IRasterizer::StereoMode) stereoMode);
                if (!m_rasterizer)
                        goto initFailed;
@@ -573,7 +568,7 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
                m_ketsjiengine->SetAudioDevice(m_audiodevice);
                m_ketsjiengine->SetTimingDisplay(frameRate, false, false);
 
-               m_ketsjiengine->SetUseFixedTime(false);
+               m_ketsjiengine->SetUseFixedTime(fixed_framerate);
                m_ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
 
                m_engineInitialized = true;
@@ -635,6 +630,8 @@ bool GPG_Application::startEngine(void)
                //              sceneconverter->SetAlwaysUseExpandFraming(true);
                if(m_blendermat)
                        m_sceneconverter->SetMaterials(true);
+               if(m_blenderglslmat)
+                       m_sceneconverter->SetGLSLMaterials(true);
 
                KX_Scene* startscene = new KX_Scene(m_keyboard,
                        m_mouse,
@@ -642,18 +639,23 @@ bool GPG_Application::startEngine(void)
                        m_audiodevice,
                        startscenename);
                
+               
                // some python things
-               PyObject* m_dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest);
-               m_ketsjiengine->SetPythonDictionary(m_dictionaryobject);
+               PyObject* dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest);
+               m_ketsjiengine->SetPythonDictionary(dictionaryobject);
                initRasterizer(m_rasterizer, m_canvas);
-               initGameLogic(startscene);
+               PyDict_SetItemString(dictionaryobject, "GameLogic", initGameLogic(startscene)); // Same as importing the module
                initGameKeys();
                initPythonConstraintBinding();
-               
+
+
+
+
+
                m_sceneconverter->ConvertScene(
                        startscenename,
                        startscene,
-                       m_dictionaryobject,
+                       dictionaryobject,
                        m_keyboard,
                        m_rendertools,
                        m_canvas);
@@ -664,7 +666,7 @@ bool GPG_Application::startEngine(void)
                        m_frameTimer = m_system->installTimer(0, kTimerFreq, frameTimerProc, m_mainWindow);
                }
                m_rasterizer->Init();
-               m_ketsjiengine->StartEngine();
+               m_ketsjiengine->StartEngine(true);
                m_engineRunning = true;
                
        }
@@ -823,11 +825,12 @@ bool GPG_Application::handleKey(GHOST_IEvent* event, bool isDown)
        {
                GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
                GHOST_TEventKeyData* keyData = static_cast<GHOST_TEventKeyData*>(eventData);
-               if (fSystem->getFullScreen()) {
-                       if (keyData->key == GHOST_kKeyEsc) {
+               //no need for this test
+               //if (fSystem->getFullScreen()) {
+                       if (keyData->key == GHOST_kKeyEsc && !m_keyboard->m_hookesc) {
                                m_exitRequested = KX_EXIT_REQUEST_OUTSIDE;
                        }
-               }
+               //}
                m_keyboard->ConvertEvent(keyData->key, isDown);
                handled = true;
        }