soc-2008-mxcurioni: merged changes to revision 15705
[blender.git] / source / gameengine / Ketsji / KX_PythonInit.cpp
index a80a7f04e8f35ae933d886cc3e6164c42c60f90c..61ed8b6a8e4a8567e8e92e03dedba20c75bc514a 100644 (file)
  * Initialize Python thingies.
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#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 "GL/glew.h"
 
 #include <stdlib.h>
 
@@ -121,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());
 }
@@ -174,9 +154,7 @@ static PyObject* gPyExpandPath(PyObject*,
 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();
 
@@ -255,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());
 }
@@ -291,7 +269,7 @@ static PyObject* gPySetPhysicsDebug(PyObject*,
 
 
 
-static PyObject* gPyGetPhysicsTicRate(PyObject*, PyObject*, PyObject*)
+static PyObject* gPyGetPhysicsTicRate(PyObject*)
 {
        return PyFloat_FromDouble(PHY_GetActiveEnvironment()->getFixedTimeStep());
 }
@@ -299,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;
@@ -310,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){
@@ -339,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){
@@ -351,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){
@@ -363,25 +333,21 @@ static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
                pprint("  Max cubemap size." << size);
                pprint("");
        }
-#endif
-#if defined(GL_ARB_multitexture) && defined(WITH_GLEXT)
-       if (!getenv("WITHOUT_GLEXT")) {
-               support = ext._ARB_multitexture;
-               count = 1;
-               pprint(" GL_ARB_multitexture supported?         "<< (support?"yes.":"no."));
-               if(support){
-                       pprint(" ----------Details----------");
-                       int units=0;
-                       glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint*)&units);
-                       pprint("  Max texture units available.  " << units);
-                       pprint("");
-               }
+
+       support = GLEW_ARB_multitexture;
+       count = 1;
+       pprint(" GL_ARB_multitexture supported?         "<< (support?"yes.":"no."));
+       if(support){
+               pprint(" ----------Details----------");
+               int units=0;
+               glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint*)&units);
+               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");
 
@@ -394,19 +360,19 @@ 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 }
@@ -453,7 +419,7 @@ static PyObject* gPyEnableVisibility(PyObject*,
        }
        else
        {
-         Py_Return;         
+               return NULL;
        }
    Py_Return;
 }
@@ -477,6 +443,9 @@ static PyObject* gPyShowMouse(PyObject*,
                                gp_Canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
                }
        }
+       else {
+               return NULL;
+       }
        
    Py_Return;
 }
@@ -493,6 +462,9 @@ static PyObject* gPySetMousePosition(PyObject*,
            if (gp_Canvas)
                        gp_Canvas->SetMousePosition(x,y);
        }
+       else {
+               return NULL;
+       }
        
    Py_Return;
 }
@@ -596,6 +568,9 @@ static PyObject* gPySetMistStart(PyObject*,
                        gp_Rasterizer->SetFogStart(miststart);
                }
        }
+       else {
+               return NULL;
+       }
    Py_Return;
 }
 
@@ -614,6 +589,9 @@ static PyObject* gPySetMistEnd(PyObject*,
                        gp_Rasterizer->SetFogEnd(mistend);
                }
        }
+       else {
+               return NULL;
+       }
    Py_Return;
 }
 
@@ -651,6 +629,9 @@ static PyObject* gPyMakeScreenshot(PyObject*,
                        gp_Canvas->MakeScreenShot(filename);
                }
        }
+       else {
+               return NULL;
+       }
        Py_Return;
 }
 
@@ -666,6 +647,9 @@ static PyObject* gPyEnableMotionBlur(PyObject*,
                        gp_Rasterizer->EnableMotionBlur(motionblurvalue);
                }
        }
+       else {
+               return NULL;
+       }
        Py_Return;
 }
 
@@ -844,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()