Make GameLogic work for python autocomplete (after running the BGE once at least)

only clear newly added items from the gameLogic dictionary rather then the whole dictionary.
This commit is contained in:
Campbell Barton 2008-09-23 00:37:19 +00:00
parent 18c954e95b
commit 7a28ca4398

@ -326,8 +326,10 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
ketsjiengine->SetPythonDictionary(dictionaryobject);
initRasterizer(rasterizer, canvas);
PyObject *gameLogic = initGameLogic(ketsjiengine, startscene);
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module.
PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
PyObject *gameLogic_keys = PyDict_Keys(PyModule_GetDict(gameLogic));
PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module.
initGameKeys();
initPythonConstraintBinding();
initMathutils();
@ -401,8 +403,20 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
// inside the GameLogic dictionary when the python interpreter is finalized.
// which allows the scene to safely delete them :)
// see: (space.c)->start_game
PyDict_Clear(PyModule_GetDict(gameLogic));
PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict);
//PyDict_Clear(PyModule_GetDict(gameLogic));
// Keep original items, means python plugins will autocomplete members
int listIndex;
PyObject *gameLogic_keys_new = PyDict_Keys(PyModule_GetDict(gameLogic));
for (listIndex=0; listIndex < PyList_Size(gameLogic_keys_new); listIndex++) {
PyObject* item = PyList_GET_ITEM(gameLogic_keys_new, listIndex);
if (!PySequence_Contains(gameLogic_keys, item)) {
PyDict_DelItem( PyModule_GetDict(gameLogic), item);
}
}
Py_DECREF(gameLogic_keys_new);
gameLogic_keys_new = NULL;
ketsjiengine->StopEngine();
exitGamePythonScripting();
@ -413,6 +427,9 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
delete sceneconverter;
sceneconverter = NULL;
}
Py_DECREF(gameLogic_keys);
gameLogic_keys = NULL;
}
// set the cursor back to normal
canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);