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>2009-04-08 20:57:08 +0400
committerBenoit Bolsee <benoit.bolsee@online.be>2009-04-08 20:57:08 +0400
commitdb33320df7f4db6480a15502baecaafefc1be63d (patch)
tree532ffe8782fec1909a8725b2eb0fe559af8ec704
parent370850146f5ab1af11ec3a28abd1bad2f60314a4 (diff)
BGE patch #18350: Add sendMessage() to GameLogic. Added sendMessage to both GameLogic and KX_GameObject.
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp24
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.h2
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp25
-rw-r--r--source/gameengine/Network/NG_NetworkScene.h5
-rw-r--r--source/gameengine/PyDoc/GameLogic.py13
-rw-r--r--source/gameengine/PyDoc/KX_GameObject.py11
6 files changed, 78 insertions, 2 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index ea53ffea48f..5085b52adda 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -66,6 +66,7 @@ typedef unsigned long uint_ptr;
#include "SCA_IActuator.h"
#include "SCA_ISensor.h"
#include "SCA_IController.h"
+#include "NG_NetworkScene.h" //Needed for sendMessage()
#include "PyObjectPlus.h" /* python stuff */
@@ -1039,7 +1040,8 @@ PyMethodDef KX_GameObject::Methods[] = {
KX_PYMETHODTABLE(KX_GameObject, rayCast),
KX_PYMETHODTABLE_O(KX_GameObject, getDistanceTo),
KX_PYMETHODTABLE_O(KX_GameObject, getVectTo),
-
+ KX_PYMETHODTABLE(KX_GameObject, sendMessage),
+
// deprecated
{"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, METH_NOARGS},
{"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_O},
@@ -2335,6 +2337,26 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
return Py_BuildValue("OOO", Py_None, Py_None, Py_None);
}
+KX_PYMETHODDEF_DOC_VARARGS(KX_GameObject, sendMessage,
+ "sendMessage(subject, [body, to])\n"
+"sends a message in same manner as a message actuator"
+"subject = Subject of the message (string)"
+"body = Message body (string)"
+"to = Name of object to send the message to")
+{
+ char* subject;
+ char* body = "";
+ char* to = "";
+ const STR_String& from = GetName();
+
+ if (!PyArg_ParseTuple(args, "s|sss", &subject, &body, &to))
+ return NULL;
+
+ KX_GetActiveScene()->GetNetworkScene()->SendMessage(to, from, subject, body);
+
+ Py_RETURN_NONE;
+}
+
/* ---------------------------------------------------------------------
* Some stuff taken from the header
* --------------------------------------------------------------------- */
diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h
index 08cc3031479..f4d35faaeb6 100644
--- a/source/gameengine/Ketsji/KX_GameObject.h
+++ b/source/gameengine/Ketsji/KX_GameObject.h
@@ -815,7 +815,7 @@ public:
KX_PYMETHOD_DOC(KX_GameObject,rayCast);
KX_PYMETHOD_DOC_O(KX_GameObject,getDistanceTo);
KX_PYMETHOD_DOC_O(KX_GameObject,getVectTo);
-
+ KX_PYMETHOD_DOC_VARARGS(KX_GameObject, sendMessage);
/* attributes */
static PyObject* pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 15397085b4a..57c84050397 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -67,6 +67,8 @@
#include "KX_Scene.h"
#include "SND_DeviceManager.h"
+#include "NG_NetworkScene.h" //Needed for sendMessage()
+
#include "BL_Shader.h"
#include "KX_PyMath.h"
@@ -167,6 +169,28 @@ static PyObject* gPyExpandPath(PyObject*, PyObject* args)
return PyString_FromString(expanded);
}
+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";
+
+static PyObject* gPySendMessage(PyObject*, PyObject* args)
+{
+ char* subject;
+ char* body = "";
+ char* to = "";
+ char* from = "";
+
+ if (!PyArg_ParseTuple(args, "s|sss", &subject, &body, &to, &from))
+ return NULL;
+
+ gp_KetsjiScene->GetNetworkScene()->SendMessage(to, from, subject, body);
+
+ Py_RETURN_NONE;
+}
static bool usedsp = false;
@@ -436,6 +460,7 @@ static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
static struct PyMethodDef game_methods[] = {
{"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, (PY_METHODCHAR)gPyExpandPath_doc},
+ {"sendMessage", (PyCFunction)gPySendMessage, METH_VARARGS, (PY_METHODCHAR)gPySendMessage_doc},
{"getCurrentController",
(PyCFunction) SCA_PythonController::sPyGetCurrentController,
METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::sPyGetCurrentController__doc__},
diff --git a/source/gameengine/Network/NG_NetworkScene.h b/source/gameengine/Network/NG_NetworkScene.h
index 58de9cf6af2..fc6367c3526 100644
--- a/source/gameengine/Network/NG_NetworkScene.h
+++ b/source/gameengine/Network/NG_NetworkScene.h
@@ -34,6 +34,11 @@
#include "STR_HashedString.h"
#include <vector>
+//MSVC defines SendMessage as a win api function, even though we aren't using it
+#ifdef SendMessage
+ #undef SendMessage
+#endif
+
class NG_NetworkDeviceInterface;
class NG_NetworkScene
diff --git a/source/gameengine/PyDoc/GameLogic.py b/source/gameengine/PyDoc/GameLogic.py
index da394288e25..29d1b64350a 100644
--- a/source/gameengine/PyDoc/GameLogic.py
+++ b/source/gameengine/PyDoc/GameLogic.py
@@ -205,6 +205,19 @@ def addActiveActuator(actuator, activate):
@type activate: boolean
@param activate: whether to activate or deactivate the given actuator.
"""
+def sendMessage(subject, body="", to="", from=""):
+ """
+ Sends a message.
+
+ @param subject: The subject of the message
+ @type subject: string
+ @param body: The body of the message (optional)
+ @type body: string
+ @param to: The name of the object to send the message to (optional)
+ @type to: string
+ @param from: The name of the object that the message is coming from (optional)
+ @type from: string
+ """
def getRandomFloat():
"""
Returns a random floating point value in the range [0...1)
diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py
index 42656503384..fb1e099e575 100644
--- a/source/gameengine/PyDoc/KX_GameObject.py
+++ b/source/gameengine/PyDoc/KX_GameObject.py
@@ -453,3 +453,14 @@ class KX_GameObject: # (SCA_IObject)
@type margin: float
@param margin: the collision margin distance in blender units.
"""
+ def sendMessage(subject, body="", to=""):
+ """
+ Sends a message.
+
+ @param subject: The subject of the message
+ @type subject: string
+ @param body: The body of the message (optional)
+ @type body: string
+ @param to: The name of the object to send the message to (optional)
+ @type to: string
+ """