[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26445] trunk/blender/source/gameengine: BGE: patch #20399 Python control over adding/removing scenes.
Benoit Bolsee
benoit.bolsee at online.be
Sat Jan 30 19:23:13 CET 2010
Revision: 26445
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26445
Author: ben2610
Date: 2010-01-30 19:23:13 +0100 (Sat, 30 Jan 2010)
Log Message:
-----------
BGE: patch #20399 Python control over adding/removing scenes.
Modified Paths:
--------------
trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
trunk/blender/source/gameengine/Ketsji/KX_Scene.h
trunk/blender/source/gameengine/PyDoc/GameLogic.py
Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp 2010-01-30 18:20:56 UTC (rev 26444)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp 2010-01-30 18:23:13 UTC (rev 26445)
@@ -333,14 +333,13 @@
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 @@
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 @@
{"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)"},
Modified: trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp 2010-01-30 18:20:56 UTC (rev 26444)
+++ trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp 2010-01-30 18:23:13 UTC (rev 26445)
@@ -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 @@
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 @@
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, "")
{
Modified: trunk/blender/source/gameengine/Ketsji/KX_Scene.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_Scene.h 2010-01-30 18:20:56 UTC (rev 26444)
+++ trunk/blender/source/gameengine/Ketsji/KX_Scene.h 2010-01-30 18:23:13 UTC (rev 26445)
@@ -541,6 +541,9 @@
/* --------------------------------------------------------------------- */
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 */
Modified: trunk/blender/source/gameengine/PyDoc/GameLogic.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/GameLogic.py 2010-01-30 18:20:56 UTC (rev 26444)
+++ trunk/blender/source/gameengine/PyDoc/GameLogic.py 2010-01-30 18:23:13 UTC (rev 26445)
@@ -344,6 +344,30 @@
@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.
More information about the Bf-blender-cvs
mailing list