From a088b9488d1be7388ddff34c0708616643900940 Mon Sep 17 00:00:00 2001 From: Ines Almeida Date: Mon, 9 Feb 2015 20:56:38 +0000 Subject: Recreating bge python modules instead of using existing All of the initXPythonBinding functions are changed to always creating the module instead of importing if previously existing. I can instead only remove the module return when the import is ok, so that it always inits. But then, I don't see the point in importing. I make sure that these functions are called only once per run, inside initBGE. This was not the case with GameTypes. I moved initPyTypes inside of initGameTypesPythonBinding due to that. I reorganized initGamePlayerPythonScripting and initGamePythonScripting so that they run things in the same order. initGamePlayerPythonScripting imports mathutils and aud, the other only aud. Shouldn't it be the same for both? Reviewers: campbellbarton Subscribers: sybren Projects: #game_engine, #game_python Differential Revision: https://developer.blender.org/D1070 --- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 73 ++++++++----------------- 1 file changed, 24 insertions(+), 49 deletions(-) (limited to 'source/gameengine/Ketsji/KX_PythonInitTypes.cpp') diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp index 5c1ad56147e..828fd62f205 100644 --- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp @@ -163,23 +163,34 @@ static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *a #define PyType_Ready_Attr(d, n, i) PyType_Ready_ADD(d, &n::Type, n::Attributes, NULL, i) #define PyType_Ready_AttrPtr(d, n, i) PyType_Ready_ADD(d, &n::Type, n::Attributes, n::AttributesPtr, i) -void initPyTypes(void) + + +PyDoc_STRVAR(GameTypes_module_documentation, +"This module provides access to the game engine data types." +); +static struct PyModuleDef GameTypes_module_def = { + PyModuleDef_HEAD_INIT, + "GameTypes", /* m_name */ + GameTypes_module_documentation, /* m_doc */ + 0, /* m_size */ + NULL, /* m_methods */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ +}; + + +PyMODINIT_FUNC initGameTypesPythonBinding(void) { + PyObject *m; + PyObject *dict; -/* - * initPyObjectPlusType(BL_ActionActuator::Parents); - * ..... - */ + m = PyModule_Create(&GameTypes_module_def); + PyDict_SetItemString(PySys_GetObject("modules"), GameTypes_module_def.m_name, m); - /* Use existing module where possible */ - PyObject *mod = initGameTypesPythonBinding(); + dict = PyModule_GetDict(m); - /* For now just do PyType_Ready */ - PyObject *dict = PyModule_GetDict(mod); - PyDict_SetItemString(PySys_GetObject("modules"), "GameTypes", mod); - Py_DECREF(mod); - - for (int init_getset= 1; init_getset > -1; init_getset--) { /* run twice, once to init the getsets another to run PyType_Ready */ PyType_Ready_Attr(dict, BL_ActionActuator, init_getset); PyType_Ready_Attr(dict, BL_Shader, init_getset); @@ -269,42 +280,6 @@ void initPyTypes(void) KX_GameObject_Mathutils_Callback_Init(); KX_ObjectActuator_Mathutils_Callback_Init(); #endif -} - - -PyDoc_STRVAR(GameTypes_module_documentation, -"This module provides access to the game engine data types." -); -static struct PyModuleDef GameTypes_module_def = { - PyModuleDef_HEAD_INIT, - "GameTypes", /* m_name */ - GameTypes_module_documentation, /* m_doc */ - 0, /* m_size */ - NULL, /* m_methods */ - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL, /* m_free */ -}; - - -PyMODINIT_FUNC initGameTypesPythonBinding(void) -{ - PyObject *m; - - /* Use existing module where possible */ - m = PyImport_ImportModule( "GameTypes" ); - if (m) { - Py_DECREF(m); - return m; - } - else { - PyErr_Clear(); - - // Create the module and add the functions - m = PyModule_Create(&GameTypes_module_def); - PyDict_SetItemString(PySys_GetObject("modules"), GameTypes_module_def.m_name, m); - } return m; } -- cgit v1.2.3