There was a problem with the last merge :S
[blender.git] / source / gameengine / Ketsji / KX_PythonInit.cpp
index 1a6aafafabf766224c27c736b7e57c536fad5b32..61ed8b6a8e4a8567e8e92e03dedba20c75bc514a 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
  *
  * Contributor(s): none yet.
  *
- * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * ***** END GPL LICENSE BLOCK *****
  * Initialize Python thingies.
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "GL/glew.h"
 
-#ifdef WIN32
-#include <windows.h>
-#endif // WIN32
-#ifdef __APPLE__
-#define GL_GLEXT_LEGACY 1
-#include <OpenGL/gl.h>
-#include <OpenGL/glu.h>
-#else
-#include <GL/gl.h>
-#if defined(__sun__) && !defined(__sparc__)
-#include <mesa/glu.h>
-#else
-#include <GL/glu.h>
-#endif
-#endif
+#include <stdlib.h>
 
 #ifdef WIN32
 #pragma warning (disable : 4786)
 //#include "BPY_extern.h"
 #endif 
 
+#include "BKE_utildefines.h"
+#include "BKE_global.h"
+#include "BLI_blenlib.h"
+
 static void setSandbox(TPythonSecurityLevel level);
 
 
@@ -118,9 +103,7 @@ void        KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,cons
 static PyObject* ErrorObject;
 STR_String gPyGetRandomFloat_doc="getRandomFloat returns a random floating point value in the range [0..1)";
 
-static PyObject* gPyGetRandomFloat(PyObject*,
-                                       PyObject*, 
-                                       PyObject*)
+static PyObject* gPyGetRandomFloat(PyObject*)
 {
        return PyFloat_FromDouble(MT_random());
 }
@@ -141,13 +124,37 @@ static PyObject* gPySetGravity(PyObject*,
        return NULL;
 }
 
+static char gPyExpandPath_doc[] =
+"(path) - Converts a blender internal path into a proper file system path.\n\
+path - the string path to convert.\n\n\
+Use / as directory separator in path\n\
+You can use '//' at the start of the string to define a relative path;\n\
+Blender replaces that string by the directory of the startup .blend or runtime\n\
+file to make a full path name (doesn't change during the game, even if you load\n\
+other .blend).\n\
+The function also converts the directory separator to the local file system format.";
+
+static PyObject* gPyExpandPath(PyObject*,
+                                                               PyObject* args, 
+                                                               PyObject*)
+{
+       char expanded[FILE_MAXDIR + FILE_MAXFILE];
+       char* filename;
+       
+       if (PyArg_ParseTuple(args,"s",&filename))
+       {
+               BLI_strncpy(expanded, filename, FILE_MAXDIR + FILE_MAXFILE);
+               BLI_convertstringcode(expanded, G.sce);
+               return PyString_FromString(expanded);
+       }
+       return NULL;
+}
+
 
 static bool usedsp = false;
 
 // this gets a pointer to an array filled with floats
-static PyObject* gPyGetSpectrum(PyObject*,
-                                                               PyObject* args, 
-                                                               PyObject*)
+static PyObject* gPyGetSpectrum(PyObject*)
 {
        SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance();
 
@@ -226,7 +233,7 @@ static PyObject* gPySetLogicTicRate(PyObject*,
        return NULL;
 }
 
-static PyObject* gPyGetLogicTicRate(PyObject*, PyObject*, PyObject*)
+static PyObject* gPyGetLogicTicRate(PyObject*)
 {
        return PyFloat_FromDouble(KX_KetsjiEngine::GetTicRate());
 }
@@ -262,7 +269,7 @@ static PyObject* gPySetPhysicsDebug(PyObject*,
 
 
 
-static PyObject* gPyGetPhysicsTicRate(PyObject*, PyObject*, PyObject*)
+static PyObject* gPyGetPhysicsTicRate(PyObject*)
 {
        return PyFloat_FromDouble(PHY_GetActiveEnvironment()->getFixedTimeStep());
 }
@@ -270,9 +277,7 @@ static PyObject* gPyGetPhysicsTicRate(PyObject*, PyObject*, PyObject*)
 static STR_String gPyGetCurrentScene_doc =  
 "getCurrentScene()\n"
 "Gets a reference to the current scene.\n";
-static PyObject* gPyGetCurrentScene(PyObject* self,
-                                          PyObject* args, 
-                                          PyObject* kwds)
+static PyObject* gPyGetCurrentScene(PyObject* self)
 {
        Py_INCREF(gp_KetsjiScene);
        return (PyObject*) gp_KetsjiScene;
@@ -281,17 +286,13 @@ static PyObject* gPyGetCurrentScene(PyObject* self,
 static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
 {
 #define pprint(x) std::cout << x << std::endl;
-       bgl::BL_EXTInfo ext = bgl::RAS_EXT_support;
        bool count=0;
        bool support=0;
        pprint("Supported Extensions...");
-#ifdef GL_ARB_shader_objects
-       pprint(" GL_ARB_shader_objects supported?       "<< (ext._ARB_shader_objects?"yes.":"no."));
+       pprint(" GL_ARB_shader_objects supported?       "<< (GLEW_ARB_shader_objects?"yes.":"no."));
        count = 1;
-#endif
 
-#ifdef GL_ARB_vertex_shader
-       support= ext._ARB_vertex_shader;
+       support= GLEW_ARB_vertex_shader;
        pprint(" GL_ARB_vertex_shader supported?        "<< (support?"yes.":"no."));
        count = 1;
        if(support){
@@ -310,9 +311,8 @@ static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
                pprint("  Max combined texture units." << max);
                pprint("");
        }
-#endif
-#ifdef GL_ARB_fragment_shader
-       support=ext._ARB_fragment_shader;
+
+       support=GLEW_ARB_fragment_shader;
        pprint(" GL_ARB_fragment_shader supported?      "<< (support?"yes.":"no."));
        count = 1;
        if(support){
@@ -322,9 +322,8 @@ static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
                pprint("  Max uniform components." << max);
                pprint("");
        }
-#endif
-#ifdef GL_ARB_texture_cube_map
-       support = ext._ARB_texture_cube_map;
+
+       support = GLEW_ARB_texture_cube_map;
        pprint(" GL_ARB_texture_cube_map supported?     "<< (support?"yes.":"no."));
        count = 1;
        if(support){
@@ -334,9 +333,8 @@ static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
                pprint("  Max cubemap size." << size);
                pprint("");
        }
-#endif
-#ifdef GL_ARB_multitexture
-       support = ext._ARB_multitexture;
+
+       support = GLEW_ARB_multitexture;
        count = 1;
        pprint(" GL_ARB_multitexture supported?         "<< (support?"yes.":"no."));
        if(support){
@@ -346,11 +344,10 @@ static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
                pprint("  Max texture units available.  " << units);
                pprint("");
        }
-#endif
-#ifdef GL_ARB_texture_env_combine
-       pprint(" GL_ARB_texture_env_combine supported?  "<< (ext._ARB_texture_env_combine?"yes.":"no."));
+
+       pprint(" GL_ARB_texture_env_combine supported?  "<< (GLEW_ARB_texture_env_combine?"yes.":"no."));
        count = 1;
-#endif
+
        if(!count)
                pprint("No extenstions are used in this build");
 
@@ -360,21 +357,22 @@ static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
 
 
 static struct PyMethodDef game_methods[] = {
+       {"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, gPyExpandPath_doc},
        {"getCurrentController",
        (PyCFunction) SCA_PythonController::sPyGetCurrentController,
-       METH_VARARGS, SCA_PythonController::sPyGetCurrentController__doc__},
+       METH_NOARGS, SCA_PythonController::sPyGetCurrentController__doc__},
        {"getCurrentScene", (PyCFunction) gPyGetCurrentScene,
-       METH_VARARGS, gPyGetCurrentScene_doc.Ptr()},
+       METH_NOARGS, gPyGetCurrentScene_doc.Ptr()},
        {"addActiveActuator",(PyCFunction) SCA_PythonController::sPyAddActiveActuator,
        METH_VARARGS, SCA_PythonController::sPyAddActiveActuator__doc__},
        {"getRandomFloat",(PyCFunction) gPyGetRandomFloat,
-       METH_VARARGS,gPyGetRandomFloat_doc.Ptr()},
+       METH_NOARGS,gPyGetRandomFloat_doc.Ptr()},
        {"setGravity",(PyCFunction) gPySetGravity, METH_VARARGS,"set Gravitation"},
-       {"getSpectrum",(PyCFunction) gPyGetSpectrum, METH_VARARGS,"get audio spectrum"},
+       {"getSpectrum",(PyCFunction) gPyGetSpectrum, METH_NOARGS,"get audio spectrum"},
        {"stopDSP",(PyCFunction) gPyStopDSP, METH_VARARGS,"stop using the audio dsp (for performance reasons)"},
-       {"getLogicTicRate", (PyCFunction) gPyGetLogicTicRate, METH_VARARGS, "Gets the logic tic rate"},
+       {"getLogicTicRate", (PyCFunction) gPyGetLogicTicRate, METH_NOARGS, "Gets the logic tic rate"},
        {"setLogicTicRate", (PyCFunction) gPySetLogicTicRate, METH_VARARGS, "Sets the logic tic rate"},
-       {"getPhysicsTicRate", (PyCFunction) gPyGetPhysicsTicRate, METH_VARARGS, "Gets the physics tic rate"},
+       {"getPhysicsTicRate", (PyCFunction) gPyGetPhysicsTicRate, METH_NOARGS, "Gets the physics tic rate"},
        {"setPhysicsTicRate", (PyCFunction) gPySetPhysicsTicRate, METH_VARARGS, "Sets the physics tic rate"},
        {"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, "Prints GL Extension Info"},
        {NULL, (PyCFunction) NULL, 0, NULL }
@@ -421,7 +419,7 @@ static PyObject* gPyEnableVisibility(PyObject*,
        }
        else
        {
-         Py_Return;         
+               return NULL;
        }
    Py_Return;
 }
@@ -445,6 +443,9 @@ static PyObject* gPyShowMouse(PyObject*,
                                gp_Canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
                }
        }
+       else {
+               return NULL;
+       }
        
    Py_Return;
 }
@@ -461,6 +462,9 @@ static PyObject* gPySetMousePosition(PyObject*,
            if (gp_Canvas)
                        gp_Canvas->SetMousePosition(x,y);
        }
+       else {
+               return NULL;
+       }
        
    Py_Return;
 }
@@ -564,6 +568,9 @@ static PyObject* gPySetMistStart(PyObject*,
                        gp_Rasterizer->SetFogStart(miststart);
                }
        }
+       else {
+               return NULL;
+       }
    Py_Return;
 }
 
@@ -582,6 +589,9 @@ static PyObject* gPySetMistEnd(PyObject*,
                        gp_Rasterizer->SetFogEnd(mistend);
                }
        }
+       else {
+               return NULL;
+       }
    Py_Return;
 }
 
@@ -619,6 +629,9 @@ static PyObject* gPyMakeScreenshot(PyObject*,
                        gp_Canvas->MakeScreenShot(filename);
                }
        }
+       else {
+               return NULL;
+       }
        Py_Return;
 }
 
@@ -634,6 +647,9 @@ static PyObject* gPyEnableMotionBlur(PyObject*,
                        gp_Rasterizer->EnableMotionBlur(motionblurvalue);
                }
        }
+       else {
+               return NULL;
+       }
        Py_Return;
 }
 
@@ -812,20 +828,9 @@ PyObject* initGameLogic(KX_Scene* scene) // quick hack to get gravity hook
                Py_FatalError("can't initialize module GameLogic");
     }
 
-       return d;
-}
-
-void dictionaryClearByHand(PyObject *dict)
-{
-       // Clears the dictionary by hand:
-       // This prevents, extra references to global variables
-       // inside the GameLogic dictionary when the python interpreter is finalized.
-       // which allows the scene to safely delete them :)
-       // see: (space.c)->start_game
-       if(dict) PyDict_Clear(dict);
+       return m;
 }
 
-
 // Python Sandbox code
 // override builtin functions import() and open()
 
@@ -1159,3 +1164,8 @@ void PHY_SetActiveScene(class KX_Scene* scene)
 {
        gp_KetsjiScene = scene;
 }
+
+class KX_Scene* PHY_GetActiveScene()
+{
+       return gp_KetsjiScene;
+}