diff options
Diffstat (limited to 'source/gameengine/Ketsji/KX_PythonInit.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 214 |
1 files changed, 120 insertions, 94 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 2fef74ca33d..76eb915a30d 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -37,9 +37,6 @@ #endif #ifdef WITH_PYTHON -# ifdef _POSIX_C_SOURCE -# undef _POSIX_C_SOURCE -# endif # ifdef _XOPEN_SOURCE # undef _XOPEN_SOURCE # endif @@ -101,7 +98,6 @@ extern "C" { #include "SCA_PythonKeyboard.h" #include "SCA_PythonMouse.h" #include "KX_ConstraintActuator.h" -#include "KX_IpoActuator.h" #include "KX_SoundActuator.h" #include "KX_StateActuator.h" #include "BL_ActionActuator.h" @@ -201,8 +197,12 @@ void KX_RasterizerDrawDebugCircle(const MT_Vector3& center, const MT_Scalar radi #ifdef WITH_PYTHON -static PyObject *gp_OrigPythonSysPath= NULL; -static PyObject *gp_OrigPythonSysModules= NULL; + +static struct { + PyObject *path; + PyObject *meta_path; + PyObject *modules; +} gp_sys_backup = {NULL}; /* Macro for building the keyboard translation */ //#define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, PyLong_FromLong(SCA_IInputDevice::KX_##name)) @@ -552,6 +552,64 @@ static PyObject *gPyGetAverageFrameRate(PyObject *) return PyFloat_FromDouble(KX_KetsjiEngine::GetAverageFrameRate()); } +static PyObject *gPyGetUseExternalClock(PyObject *) +{ + return PyBool_FromLong(gp_KetsjiEngine->GetUseExternalClock()); +} + +static PyObject *gPySetUseExternalClock(PyObject *, PyObject *args) +{ + bool bUseExternalClock; + + if (!PyArg_ParseTuple(args, "p:setUseExternalClock", &bUseExternalClock)) + return NULL; + + gp_KetsjiEngine->SetUseExternalClock(bUseExternalClock); + Py_RETURN_NONE; +} + +static PyObject *gPyGetClockTime(PyObject *) +{ + return PyFloat_FromDouble(gp_KetsjiEngine->GetClockTime()); +} + +static PyObject *gPySetClockTime(PyObject *, PyObject *args) +{ + double externalClockTime; + + if (!PyArg_ParseTuple(args, "d:setClockTime", &externalClockTime)) + return NULL; + + gp_KetsjiEngine->SetClockTime(externalClockTime); + Py_RETURN_NONE; +} + +static PyObject *gPyGetFrameTime(PyObject *) +{ + return PyFloat_FromDouble(gp_KetsjiEngine->GetFrameTime()); +} + +static PyObject *gPyGetRealTime(PyObject *) +{ + return PyFloat_FromDouble(gp_KetsjiEngine->GetRealTime()); +} + +static PyObject *gPyGetTimeScale(PyObject *) +{ + return PyFloat_FromDouble(gp_KetsjiEngine->GetTimeScale()); +} + +static PyObject *gPySetTimeScale(PyObject *, PyObject *args) +{ + double time_scale; + + if (!PyArg_ParseTuple(args, "d:setTimeScale", &time_scale)) + return NULL; + + gp_KetsjiEngine->SetTimeScale(time_scale); + Py_RETURN_NONE; +} + static PyObject *gPyGetBlendFileList(PyObject *, PyObject *args) { char cpath[sizeof(gp_GamePythonPath)]; @@ -651,71 +709,10 @@ static PyObject *pyPrintStats(PyObject *,PyObject *,PyObject *) static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *) { -#define pprint(x) std::cout << x << std::endl; - bool count=0; - bool support=0; - pprint("Supported Extensions..."); - pprint(" GL_ARB_shader_objects supported? "<< (GLEW_ARB_shader_objects?"yes.":"no.")); - count = 1; - - support= GLEW_ARB_vertex_shader; - pprint(" GL_ARB_vertex_shader supported? "<< (support?"yes.":"no.")); - count = 1; - if (support) { - pprint(" ----------Details----------"); - int max=0; - glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, (GLint*)&max); - pprint(" Max uniform components." << max); - - glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, (GLint*)&max); - pprint(" Max varying floats." << max); - - glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, (GLint*)&max); - pprint(" Max vertex texture units." << max); - - glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, (GLint*)&max); - pprint(" Max combined texture units." << max); - pprint(""); - } - - support=GLEW_ARB_fragment_shader; - pprint(" GL_ARB_fragment_shader supported? "<< (support?"yes.":"no.")); - count = 1; - if (support) { - pprint(" ----------Details----------"); - int max=0; - glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, (GLint*)&max); - pprint(" Max uniform components." << max); - pprint(""); - } - - support = GLEW_ARB_texture_cube_map; - pprint(" GL_ARB_texture_cube_map supported? "<< (support?"yes.":"no.")); - count = 1; - if (support) { - pprint(" ----------Details----------"); - int size=0; - glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, (GLint*)&size); - pprint(" Max cubemap size." << size); - 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(""); - } - - pprint(" GL_ARB_texture_env_combine supported? "<< (GLEW_ARB_texture_env_combine?"yes.":"no.")); - count = 1; - - if (!count) - pprint("No extenstions are used in this build"); + if (gp_Rasterizer) + gp_Rasterizer->PrintHardwareInfo(); + else + printf("Warning: no rasterizer detected for PrintGLInfo!\n"); Py_RETURN_NONE; } @@ -912,7 +909,19 @@ static struct PyMethodDef game_methods[] = { {"setAnimRecordFrame", (PyCFunction) gPySetAnimRecordFrame, METH_VARARGS, (const char *)"Sets the current frame number used for animation recording"}, {"getExitKey", (PyCFunction) gPyGetExitKey, METH_NOARGS, (const char *)"Gets the key used to exit the game engine"}, {"setExitKey", (PyCFunction) gPySetExitKey, METH_VARARGS, (const char *)"Sets the key used to exit the game engine"}, + {"getUseExternalClock", (PyCFunction) gPyGetUseExternalClock, METH_NOARGS, (const char *)"Get if we use the time provided by an external clock"}, + {"setUseExternalClock", (PyCFunction) gPySetUseExternalClock, METH_VARARGS, (const char *)"Set if we use the time provided by an external clock"}, + {"getClockTime", (PyCFunction) gPyGetClockTime, METH_NOARGS, (const char *)"Get the last BGE render time. " + "The BGE render time is the simulated time corresponding to the next scene that will be renderered"}, + {"setClockTime", (PyCFunction) gPySetClockTime, METH_VARARGS, (const char *)"Set the BGE render time. " + "The BGE render time is the simulated time corresponding to the next scene that will be rendered"}, + {"getFrameTime", (PyCFunction) gPyGetFrameTime, METH_NOARGS, (const char *)"Get the BGE last frametime. " + "The BGE frame time is the simulated time corresponding to the last call of the logic system"}, + {"getRealTime", (PyCFunction) gPyGetRealTime, METH_NOARGS, (const char *)"Get the real system time. " + "The real-time corresponds to the system time" }, {"getAverageFrameRate", (PyCFunction) gPyGetAverageFrameRate, METH_NOARGS, (const char *)"Gets the estimated average frame rate"}, + {"getTimeScale", (PyCFunction) gPyGetTimeScale, METH_NOARGS, (const char *)"Get the time multiplier"}, + {"setTimeScale", (PyCFunction) gPySetTimeScale, METH_VARARGS, (const char *)"Set the time multiplier"}, {"getBlendFileList", (PyCFunction)gPyGetBlendFileList, METH_VARARGS, (const char *)"Gets a list of blend files in the same directory as the current blend file"}, {"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, (const char *)"Prints GL Extension Info"}, {"PrintMemInfo", (PyCFunction)pyPrintStats, METH_NOARGS, (const char *)"Print engine statistics"}, @@ -1804,6 +1813,7 @@ PyMODINIT_FUNC initGameLogicPythonBinding() KX_MACRO_addTypesToDict(d, KX_GAME_QUIT, KX_GameActuator::KX_GAME_QUIT); KX_MACRO_addTypesToDict(d, KX_GAME_SAVECFG, KX_GameActuator::KX_GAME_SAVECFG); KX_MACRO_addTypesToDict(d, KX_GAME_LOADCFG, KX_GameActuator::KX_GAME_LOADCFG); + KX_MACRO_addTypesToDict(d, KX_GAME_SCREENSHOT, KX_GameActuator::KX_GAME_SCREENSHOT); /* Scene Actuator Modes */ KX_MACRO_addTypesToDict(d, KX_SCENE_RESTART, KX_SceneActuator::KX_SCENE_RESTART); @@ -1901,11 +1911,12 @@ PyMODINIT_FUNC initGameLogicPythonBinding() return m; } -/* Explanation of +/** + * Explanation of * - * - backupPySysObjects() : stores sys.path in gp_OrigPythonSysPath - * - initPySysObjects(main) : initializes the blendfile and library paths - * - restorePySysObjects() : restores sys.path from gp_OrigPythonSysPath + * - backupPySysObjects() : stores sys.path in #gp_sys_backup + * - initPySysObjects(main) : initializes the blendfile and library paths + * - restorePySysObjects() : restores sys.path from #gp_sys_backup * * These exist so the current blend dir "//" can always be used to import modules from. * the reason we need a few functions for this is that python is not only used by the game engine @@ -1922,16 +1933,21 @@ PyMODINIT_FUNC initGameLogicPythonBinding() */ static void backupPySysObjects(void) { - PyObject *sys_path= PySys_GetObject("path"); /* should never fail */ - PyObject *sys_mods= PySys_GetObject("modules"); /* should never fail */ + PyObject *sys_path = PySys_GetObject("path"); + PyObject *sys_meta_path = PySys_GetObject("meta_path"); + PyObject *sys_mods = PySys_GetObject("modules"); /* paths */ - Py_XDECREF(gp_OrigPythonSysPath); /* just in case its set */ - gp_OrigPythonSysPath = PyList_GetSlice(sys_path, 0, INT_MAX); /* copy the list */ + Py_XDECREF(gp_sys_backup.path); /* just in case its set */ + gp_sys_backup.path = PyList_GetSlice(sys_path, 0, INT_MAX); /* copy the list */ + /* meta_paths */ + Py_XDECREF(gp_sys_backup.meta_path); /* just in case its set */ + gp_sys_backup.meta_path = PyList_GetSlice(sys_meta_path, 0, INT_MAX); /* copy the list */ + /* modules */ - Py_XDECREF(gp_OrigPythonSysModules); /* just in case its set */ - gp_OrigPythonSysModules = PyDict_Copy(sys_mods); /* copy the list */ + Py_XDECREF(gp_sys_backup.modules); /* just in case its set */ + gp_sys_backup.modules = PyDict_Copy(sys_mods); /* copy the dict */ } @@ -1961,15 +1977,17 @@ static void initPySysObjects__append(PyObject *sys_path, const char *filename) } static void initPySysObjects(Main *maggie) { - PyObject *sys_path= PySys_GetObject("path"); /* should never fail */ + PyObject *sys_path = PySys_GetObject("path"); + PyObject *sys_meta_path = PySys_GetObject("meta_path"); - if (gp_OrigPythonSysPath==NULL) { + if (gp_sys_backup.path == NULL) { /* backup */ backupPySysObjects(); } else { /* get the original sys path when the BGE started */ - PyList_SetSlice(sys_path, 0, INT_MAX, gp_OrigPythonSysPath); + PyList_SetSlice(sys_path, 0, INT_MAX, gp_sys_backup.path); + PyList_SetSlice(sys_meta_path, 0, INT_MAX, gp_sys_backup.meta_path); } Library *lib= (Library *)maggie->library.first; @@ -1989,22 +2007,30 @@ static void initPySysObjects(Main *maggie) static void restorePySysObjects(void) { - if (gp_OrigPythonSysPath==NULL) + if (gp_sys_backup.path == NULL) { return; - - PyObject *sys_path= PySys_GetObject("path"); /* should never fail */ - PyObject *sys_mods= PySys_GetObject("modules"); /* should never fail */ + } + + /* will never fail */ + PyObject *sys_path = PySys_GetObject("path"); + PyObject *sys_meta_path = PySys_GetObject("meta_path"); + PyObject *sys_mods = PySys_GetObject("modules"); /* paths */ - PyList_SetSlice(sys_path, 0, INT_MAX, gp_OrigPythonSysPath); - Py_DECREF(gp_OrigPythonSysPath); - gp_OrigPythonSysPath= NULL; + PyList_SetSlice(sys_path, 0, INT_MAX, gp_sys_backup.path); + Py_DECREF(gp_sys_backup.path); + gp_sys_backup.path = NULL; + + /* meta_path */ + PyList_SetSlice(sys_meta_path, 0, INT_MAX, gp_sys_backup.meta_path); + Py_DECREF(gp_sys_backup.meta_path); + gp_sys_backup.meta_path = NULL; /* modules */ PyDict_Clear(sys_mods); - PyDict_Update(sys_mods, gp_OrigPythonSysModules); - Py_DECREF(gp_OrigPythonSysModules); - gp_OrigPythonSysModules= NULL; + PyDict_Update(sys_mods, gp_sys_backup.modules); + Py_DECREF(gp_sys_backup.modules); + gp_sys_backup.modules = NULL; // fprintf(stderr, "\nRestore Path: %d ", PyList_GET_SIZE(sys_path)); |