Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Bolsee <benoit.bolsee@online.be>2010-01-30 21:23:13 +0300
committerBenoit Bolsee <benoit.bolsee@online.be>2010-01-30 21:23:13 +0300
commitcfdd53a4f8e7e80754fd1c6c796bf4410a0213a5 (patch)
tree5be1cfe234713339ef4e9075e0c39d6e6db0c4ef /source/gameengine
parent0c899f7ded58ef25e29bb60d393b101c40a6ccc5 (diff)
BGE: patch #20399 Python control over adding/removing scenes.
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp36
-rw-r--r--source/gameengine/Ketsji/KX_Scene.cpp37
-rw-r--r--source/gameengine/Ketsji/KX_Scene.h3
-rw-r--r--source/gameengine/PyDoc/GameLogic.py24
4 files changed, 89 insertions, 11 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 5e109770fee..ce81e4195fa 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -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)"},
diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp
index c8c5b33693b..4d25b2742d7 100644
--- a/source/gameengine/Ketsji/KX_Scene.cpp
+++ b/source/gameengine/Ketsji/KX_Scene.cpp
@@ -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, "")
{
diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h
index 602e919b58d..5a66863d3e0 100644
--- a/source/gameengine/Ketsji/KX_Scene.h
+++ b/source/gameengine/Ketsji/KX_Scene.h
@@ -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 */
diff --git a/source/gameengine/PyDoc/GameLogic.py b/source/gameengine/PyDoc/GameLogic.py
index 3cf15636892..a6681bf562d 100644
--- a/source/gameengine/PyDoc/GameLogic.py
+++ b/source/gameengine/PyDoc/GameLogic.py
@@ -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.