BGE: patch #20399 Python control over adding/removing scenes.
This commit is contained in:
@@ -333,14 +333,13 @@ static PyObject* gPyLoadGlobalDict(PyObject*)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static char gPySendMessage_doc[] =
|
||||
"sendMessage(subject, [body, to, from])\n\
|
||||
sends a message in same manner as a message actuator\
|
||||
subject = Subject of the message\
|
||||
body = Message body\
|
||||
to = Name of object to send the message to\
|
||||
from = Name of object to sned the string from";
|
||||
from = Name of object to send the string from";
|
||||
|
||||
static PyObject* gPySendMessage(PyObject*, PyObject* args)
|
||||
{
|
||||
@@ -496,6 +495,25 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args)
|
||||
return list;
|
||||
}
|
||||
|
||||
static char gPyAddScene_doc[] =
|
||||
"addScene(name, [overlay])\n\
|
||||
adds a scene to the game engine\n\
|
||||
name = Name of the scene\n\
|
||||
overlay = Overlay or underlay";
|
||||
static PyObject* gPyAddScene(PyObject*, PyObject* args)
|
||||
{
|
||||
char* name;
|
||||
int overlay = 1;
|
||||
KX_Scene* scene = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s|i:addScene", &name , &overlay))
|
||||
return NULL;
|
||||
|
||||
gp_KetsjiEngine->ConvertAndAddScene(name, (overlay != 0));
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static const char *gPyGetCurrentScene_doc =
|
||||
"getCurrentScene()\n"
|
||||
"Gets a reference to the current scene.\n";
|
||||
@@ -722,15 +740,11 @@ static struct PyMethodDef game_methods[] = {
|
||||
{"saveGlobalDict", (PyCFunction)gPySaveGlobalDict, METH_NOARGS, (const char *)gPySaveGlobalDict_doc},
|
||||
{"loadGlobalDict", (PyCFunction)gPyLoadGlobalDict, METH_NOARGS, (const char *)gPyLoadGlobalDict_doc},
|
||||
{"sendMessage", (PyCFunction)gPySendMessage, METH_VARARGS, (const char *)gPySendMessage_doc},
|
||||
{"getCurrentController",
|
||||
(PyCFunction) SCA_PythonController::sPyGetCurrentController,
|
||||
METH_NOARGS, SCA_PythonController::sPyGetCurrentController__doc__},
|
||||
{"getCurrentScene", (PyCFunction) gPyGetCurrentScene,
|
||||
METH_NOARGS, gPyGetCurrentScene_doc},
|
||||
{"getSceneList", (PyCFunction) gPyGetSceneList,
|
||||
METH_NOARGS, (const char *)gPyGetSceneList_doc},
|
||||
{"getRandomFloat",(PyCFunction) gPyGetRandomFloat,
|
||||
METH_NOARGS, (const char *)gPyGetRandomFloat_doc},
|
||||
{"getCurrentController", (PyCFunction) SCA_PythonController::sPyGetCurrentController, METH_NOARGS, SCA_PythonController::sPyGetCurrentController__doc__},
|
||||
{"getCurrentScene", (PyCFunction) gPyGetCurrentScene, METH_NOARGS, gPyGetCurrentScene_doc},
|
||||
{"getSceneList", (PyCFunction) gPyGetSceneList, METH_NOARGS, (const char *)gPyGetSceneList_doc},
|
||||
{"addScene", (PyCFunction)gPyAddScene, METH_VARARGS, (const char *)gPyAddScene_doc},
|
||||
{"getRandomFloat",(PyCFunction) gPyGetRandomFloat, METH_NOARGS, (const char *)gPyGetRandomFloat_doc},
|
||||
{"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)"},
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#endif //WIN32
|
||||
|
||||
#include "KX_Scene.h"
|
||||
#include "KX_PythonInit.h"
|
||||
#include "MT_assert.h"
|
||||
#include "KX_KetsjiEngine.h"
|
||||
#include "KX_BlenderMaterial.h"
|
||||
@@ -1864,6 +1865,9 @@ PyTypeObject KX_Scene::Type = {
|
||||
|
||||
PyMethodDef KX_Scene::Methods[] = {
|
||||
KX_PYMETHODTABLE(KX_Scene, addObject),
|
||||
KX_PYMETHODTABLE(KX_Scene, end),
|
||||
KX_PYMETHODTABLE(KX_Scene, restart),
|
||||
KX_PYMETHODTABLE(KX_Scene, replace),
|
||||
|
||||
/* dict style access */
|
||||
KX_PYMETHODTABLE(KX_Scene, get),
|
||||
@@ -2136,6 +2140,39 @@ KX_PYMETHODDEF_DOC(KX_Scene, addObject,
|
||||
return replica->GetProxy();
|
||||
}
|
||||
|
||||
KX_PYMETHODDEF_DOC(KX_Scene, end,
|
||||
"end()\n"
|
||||
"Removes this scene from the game.\n")
|
||||
{
|
||||
|
||||
KX_GetActiveEngine()->RemoveScene(m_sceneName);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
KX_PYMETHODDEF_DOC(KX_Scene, restart,
|
||||
"restart()\n"
|
||||
"Restarts this scene.\n")
|
||||
{
|
||||
KX_GetActiveEngine()->ReplaceScene(m_sceneName, m_sceneName);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
KX_PYMETHODDEF_DOC(KX_Scene, replace,
|
||||
"replace(newScene)\n"
|
||||
"Replaces this scene with another one.\n")
|
||||
{
|
||||
char* name;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s:replace", &name))
|
||||
return NULL;
|
||||
|
||||
KX_GetActiveEngine()->ReplaceScene(m_sceneName, name);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* Matches python dict.get(key, [default]) */
|
||||
KX_PYMETHODDEF_DOC(KX_Scene, get, "")
|
||||
{
|
||||
|
||||
@@ -541,6 +541,9 @@ public:
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
KX_PYMETHOD_DOC(KX_Scene, addObject);
|
||||
KX_PYMETHOD_DOC(KX_Scene, end);
|
||||
KX_PYMETHOD_DOC(KX_Scene, restart);
|
||||
KX_PYMETHOD_DOC(KX_Scene, replace);
|
||||
KX_PYMETHOD_DOC(KX_Scene, get);
|
||||
|
||||
/* attributes */
|
||||
|
||||
@@ -344,6 +344,30 @@ def addActiveActuator(actuator, activate):
|
||||
@type activate: boolean
|
||||
@param activate: whether to activate or deactivate the given actuator.
|
||||
"""
|
||||
def loadGlobalDict():
|
||||
"""
|
||||
Loads GameLogic.globalDict from a file.
|
||||
"""
|
||||
def saveGlobalDict():
|
||||
"""
|
||||
Saves GameLogic.globalDict to a file.
|
||||
"""
|
||||
def addScene(name, overlay=1):
|
||||
"""
|
||||
Loads a scene into the game engine.
|
||||
|
||||
@param name: The name of the scene
|
||||
@type name: string
|
||||
@param body: Overlay or underlay (optional)
|
||||
@type body: int
|
||||
"""
|
||||
def removeScene(name):
|
||||
"""
|
||||
Removes a scene from the game engine.
|
||||
|
||||
@param name: The name of the scene
|
||||
@type name: string
|
||||
"""
|
||||
def sendMessage(subject, body="", to="", message_from=""):
|
||||
"""
|
||||
Sends a message to sensors in any active scene.
|
||||
|
||||
Reference in New Issue
Block a user