diff options
Diffstat (limited to 'source/gameengine/Ketsji/KX_PythonInit.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 114 |
1 files changed, 34 insertions, 80 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index c4110760228..d8027a4d9fc 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -525,34 +525,34 @@ static PyObject *gEvalExpression(PyObject*, PyObject* value) static struct PyMethodDef game_methods[] = { - {"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, (PY_METHODCHAR)gPyExpandPath_doc}, - {"sendMessage", (PyCFunction)gPySendMessage, METH_VARARGS, (PY_METHODCHAR)gPySendMessage_doc}, + {"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, (const char *)gPyExpandPath_doc}, + {"sendMessage", (PyCFunction)gPySendMessage, METH_VARARGS, (const char *)gPySendMessage_doc}, {"getCurrentController", (PyCFunction) SCA_PythonController::sPyGetCurrentController, - METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::sPyGetCurrentController__doc__}, + METH_NOARGS, (const char *)SCA_PythonController::sPyGetCurrentController__doc__}, {"getCurrentScene", (PyCFunction) gPyGetCurrentScene, - METH_NOARGS, (PY_METHODCHAR)gPyGetCurrentScene_doc.Ptr()}, + METH_NOARGS, (const char *)gPyGetCurrentScene_doc.Ptr()}, {"getSceneList", (PyCFunction) gPyGetSceneList, - METH_NOARGS, (PY_METHODCHAR)gPyGetSceneList_doc.Ptr()}, + METH_NOARGS, (const char *)gPyGetSceneList_doc.Ptr()}, {"addActiveActuator",(PyCFunction) SCA_PythonController::sPyAddActiveActuator, - METH_VARARGS, (PY_METHODCHAR)SCA_PythonController::sPyAddActiveActuator__doc__}, + METH_VARARGS, (const char *)SCA_PythonController::sPyAddActiveActuator__doc__}, {"getRandomFloat",(PyCFunction) gPyGetRandomFloat, - METH_NOARGS, (PY_METHODCHAR)gPyGetRandomFloat_doc.Ptr()}, - {"setGravity",(PyCFunction) gPySetGravity, METH_O, (PY_METHODCHAR)"set Gravitation"}, - {"getSpectrum",(PyCFunction) gPyGetSpectrum, METH_NOARGS, (PY_METHODCHAR)"get audio spectrum"}, - {"stopDSP",(PyCFunction) gPyStopDSP, METH_VARARGS, (PY_METHODCHAR)"stop using the audio dsp (for performance reasons)"}, - {"getMaxLogicFrame", (PyCFunction) gPyGetMaxLogicFrame, METH_NOARGS, (PY_METHODCHAR)"Gets the max number of logic frame per render frame"}, - {"setMaxLogicFrame", (PyCFunction) gPySetMaxLogicFrame, METH_VARARGS, (PY_METHODCHAR)"Sets the max number of logic frame per render frame"}, - {"getMaxPhysicsFrame", (PyCFunction) gPyGetMaxPhysicsFrame, METH_NOARGS, (PY_METHODCHAR)"Gets the max number of physics frame per render frame"}, - {"setMaxPhysicsFrame", (PyCFunction) gPySetMaxPhysicsFrame, METH_VARARGS, (PY_METHODCHAR)"Sets the max number of physics farme per render frame"}, - {"getLogicTicRate", (PyCFunction) gPyGetLogicTicRate, METH_NOARGS, (PY_METHODCHAR)"Gets the logic tic rate"}, - {"setLogicTicRate", (PyCFunction) gPySetLogicTicRate, METH_VARARGS, (PY_METHODCHAR)"Sets the logic tic rate"}, - {"getPhysicsTicRate", (PyCFunction) gPyGetPhysicsTicRate, METH_NOARGS, (PY_METHODCHAR)"Gets the physics tic rate"}, - {"setPhysicsTicRate", (PyCFunction) gPySetPhysicsTicRate, METH_VARARGS, (PY_METHODCHAR)"Sets the physics tic rate"}, - {"getAverageFrameRate", (PyCFunction) gPyGetAverageFrameRate, METH_NOARGS, (PY_METHODCHAR)"Gets the estimated average frame rate"}, - {"getBlendFileList", (PyCFunction)gPyGetBlendFileList, METH_VARARGS, (PY_METHODCHAR)"Gets a list of blend files in the same directory as the current blend file"}, - {"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, (PY_METHODCHAR)"Prints GL Extension Info"}, - {"EvalExpression", (PyCFunction)gEvalExpression, METH_O, (PY_METHODCHAR)"Evaluate a string as a game logic expression"}, + METH_NOARGS, (const char *)gPyGetRandomFloat_doc.Ptr()}, + {"setGravity",(PyCFunction) gPySetGravity, METH_O, (const char *)"set Gravitation"}, + {"getSpectrum",(PyCFunction) gPyGetSpectrum, METH_NOARGS, (const char *)"get audio spectrum"}, + {"stopDSP",(PyCFunction) gPyStopDSP, METH_VARARGS, (const char *)"stop using the audio dsp (for performance reasons)"}, + {"getMaxLogicFrame", (PyCFunction) gPyGetMaxLogicFrame, METH_NOARGS, (const char *)"Gets the max number of logic frame per render frame"}, + {"setMaxLogicFrame", (PyCFunction) gPySetMaxLogicFrame, METH_VARARGS, (const char *)"Sets the max number of logic frame per render frame"}, + {"getMaxPhysicsFrame", (PyCFunction) gPyGetMaxPhysicsFrame, METH_NOARGS, (const char *)"Gets the max number of physics frame per render frame"}, + {"setMaxPhysicsFrame", (PyCFunction) gPySetMaxPhysicsFrame, METH_VARARGS, (const char *)"Sets the max number of physics farme per render frame"}, + {"getLogicTicRate", (PyCFunction) gPyGetLogicTicRate, METH_NOARGS, (const char *)"Gets the logic tic rate"}, + {"setLogicTicRate", (PyCFunction) gPySetLogicTicRate, METH_VARARGS, (const char *)"Sets the logic tic rate"}, + {"getPhysicsTicRate", (PyCFunction) gPyGetPhysicsTicRate, METH_NOARGS, (const char *)"Gets the physics tic rate"}, + {"setPhysicsTicRate", (PyCFunction) gPySetPhysicsTicRate, METH_VARARGS, (const char *)"Sets the physics tic rate"}, + {"getAverageFrameRate", (PyCFunction) gPyGetAverageFrameRate, METH_NOARGS, (const char *)"Gets the estimated average frame rate"}, + {"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"}, + {"EvalExpression", (PyCFunction)gEvalExpression, METH_O, (const char *)"Evaluate a string as a game logic expression"}, {NULL, (PyCFunction) NULL, 0, NULL } }; @@ -1019,7 +1019,6 @@ static char Rasterizer_module_documentation[] = "This is the Python API for the game engine of Rasterizer" ; -#if (PY_VERSION_HEX >= 0x03000000) static struct PyModuleDef GameLogic_module_def = { {}, /* m_base */ "GameLogic", /* m_name */ @@ -1031,7 +1030,6 @@ static struct PyModuleDef GameLogic_module_def = { 0, /* m_clear */ 0, /* m_free */ }; -#endif PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack to get gravity hook { @@ -1055,16 +1053,9 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack } else { PyErr_Clear(); - // Create the module and add the functions -#if (PY_VERSION_HEX >= 0x03000000) m = PyModule_Create(&GameLogic_module_def); PyDict_SetItemString(PySys_GetObject("modules"), GameLogic_module_def.m_name, m); -#else - m = Py_InitModule4("GameLogic", game_methods, - GameLogic_module_documentation, - (PyObject*)NULL,PYTHON_API_VERSION); -#endif } // Add some symbolic constants to the module @@ -1346,18 +1337,11 @@ PyObject *KXpy_import(PyObject *self, PyObject *args) PyObject *locals = NULL; PyObject *fromlist = NULL; PyObject *l, *m, *n; - -#if (PY_VERSION_HEX >= 0x02060000) - int dummy_val; /* what does this do?*/ + int level; /* not used yet */ if (!PyArg_ParseTuple(args, "s|OOOi:m_import", - &name, &globals, &locals, &fromlist, &dummy_val)) + &name, &globals, &locals, &fromlist, &level)) return NULL; -#else - if (!PyArg_ParseTuple(args, "s|OOO:m_import", - &name, &globals, &locals, &fromlist)) - return NULL; -#endif /* check for builtin modules */ m = PyImport_AddModule("sys"); @@ -1614,7 +1598,7 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur */ static bool first_time = true; -#if (PY_VERSION_HEX < 0x03000000) +#if 0 // TODO - py3 STR_String pname = progname; Py_SetProgramName(pname.Ptr()); #endif @@ -1623,9 +1607,8 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur Py_Initialize(); if(argv && first_time) { /* browser plugins dont currently set this */ -#if (PY_VERSION_HEX < 0x03000000) - PySys_SetArgv(argc, argv); -#else + // Until python support ascii again, we use our own. + // PySys_SetArgv(argc, argv); int i; PyObject *py_argv= PyList_New(argc); @@ -1634,9 +1617,7 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur PySys_SetObject("argv", py_argv); Py_DECREF(py_argv); -#endif } - //importBlenderModules() setSandbox(level); initPyTypes(); @@ -1670,7 +1651,7 @@ void exitGamePlayerPythonScripting() */ PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level, Main *maggie) { -#if (PY_VERSION_HEX < 0x03000000) +#if 0 // XXX TODO Py3 STR_String pname = progname; Py_SetProgramName(pname.Ptr()); #endif @@ -1698,7 +1679,6 @@ void exitGamePythonScripting() } -#if (PY_VERSION_HEX >= 0x03000000) static struct PyModuleDef Rasterizer_module_def = { {}, /* m_base */ "Rasterizer", /* m_name */ @@ -1710,7 +1690,6 @@ static struct PyModuleDef Rasterizer_module_def = { 0, /* m_clear */ 0, /* m_free */ }; -#endif PyObject* initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas) { @@ -1733,14 +1712,8 @@ PyObject* initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas) PyErr_Clear(); // Create the module and add the functions -#if (PY_VERSION_HEX >= 0x03000000) m = PyModule_Create(&Rasterizer_module_def); PyDict_SetItemString(PySys_GetObject("modules"), Rasterizer_module_def.m_name, m); -#else - m = Py_InitModule4("Rasterizer", rasterizer_methods, - Rasterizer_module_documentation, - (PyObject*)NULL,PYTHON_API_VERSION); -#endif } // Add some symbolic constants to the module @@ -1791,12 +1764,7 @@ static PyObject* gPyEventToString(PyObject*, PyObject* value) dict = PyModule_GetDict(mod); while (PyDict_Next(dict, &pos, &key, &val)) { -#if (PY_VERSION_HEX >= 0x03000000) if (PyObject_RichCompareBool(value, val, Py_EQ)) { -#else - if (PyObject_Compare(value, val)==0) { -#endif - ret = key; break; } @@ -1832,13 +1800,11 @@ static PyObject* gPyEventToCharacter(PyObject*, PyObject* args) static struct PyMethodDef gamekeys_methods[] = { - {"EventToCharacter", (PyCFunction)gPyEventToCharacter, METH_VARARGS, (PY_METHODCHAR)gPyEventToCharacter_doc}, - {"EventToString", (PyCFunction)gPyEventToString, METH_O, (PY_METHODCHAR)gPyEventToString_doc}, + {"EventToCharacter", (PyCFunction)gPyEventToCharacter, METH_VARARGS, (const char *)gPyEventToCharacter_doc}, + {"EventToString", (PyCFunction)gPyEventToString, METH_O, (const char *)gPyEventToString_doc}, { NULL, (PyCFunction) NULL, 0, NULL } }; - -#if (PY_VERSION_HEX >= 0x03000000) static struct PyModuleDef GameKeys_module_def = { {}, /* m_base */ "GameKeys", /* m_name */ @@ -1850,7 +1816,6 @@ static struct PyModuleDef GameKeys_module_def = { 0, /* m_clear */ 0, /* m_free */ }; -#endif PyObject* initGameKeys() { @@ -1868,14 +1833,8 @@ PyObject* initGameKeys() PyErr_Clear(); // Create the module and add the functions -#if (PY_VERSION_HEX >= 0x03000000) m = PyModule_Create(&GameKeys_module_def); PyDict_SetItemString(PySys_GetObject("modules"), GameKeys_module_def.m_name, m); -#else - m = Py_InitModule4("GameKeys", gamekeys_methods, - GameKeys_module_documentation, - (PyObject*)NULL,PYTHON_API_VERSION); -#endif } // Add some symbolic constants to the module @@ -2007,17 +1966,17 @@ PyObject* initGameKeys() PyObject* initMathutils() { - return Mathutils_Init("Mathutils"); // Use as a top level module in BGE + return Mathutils_Init(); } PyObject* initGeometry() { - return Geometry_Init("Geometry"); // Use as a top level module in BGE + return Geometry_Init(); } PyObject* initBGL() { - return BGL_Init("BGL"); // Use as a top level module in BGE + return BGL_Init(); } void KX_SetActiveScene(class KX_Scene* scene) @@ -2053,13 +2012,8 @@ int saveGamePythonConfig( char **marshal_buffer) // PyObject_Print(pyGlobalDictMarshal, stderr, 0); char *marshal_cstring; -#if PY_VERSION_HEX < 0x03000000 - marshal_cstring = _PyUnicode_AsString(pyGlobalDictMarshal); - marshal_length= PyString_Size(pyGlobalDictMarshal); -#else // py3 uses byte arrays - marshal_cstring = PyBytes_AsString(pyGlobalDictMarshal); + marshal_cstring = PyBytes_AsString(pyGlobalDictMarshal); // py3 uses byte arrays marshal_length= PyBytes_Size(pyGlobalDictMarshal); -#endif *marshal_buffer = new char[marshal_length + 1]; memcpy(*marshal_buffer, marshal_cstring, marshal_length); Py_DECREF(pyGlobalDictMarshal); |