Revision: 19603
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19603
Author:   ben2610
Date:     2009-04-08 18:57:08 +0200 (Wed, 08 Apr 2009)

Log Message:
-----------
BGE patch #18350: Add sendMessage() to GameLogic. Added sendMessage to both 
GameLogic and KX_GameObject.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
    trunk/blender/source/gameengine/Network/NG_NetworkScene.h
    trunk/blender/source/gameengine/PyDoc/GameLogic.py
    trunk/blender/source/gameengine/PyDoc/KX_GameObject.py

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp    2009-04-08 
16:51:35 UTC (rev 19602)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp    2009-04-08 
16:57:08 UTC (rev 19603)
@@ -66,6 +66,7 @@
 #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 @@
        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 @@
                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
  * --------------------------------------------------------------------- */

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h      2009-04-08 
16:51:35 UTC (rev 19602)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h      2009-04-08 
16:57:08 UTC (rev 19603)
@@ -815,7 +815,7 @@
        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);

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp    2009-04-08 
16:51:35 UTC (rev 19602)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp    2009-04-08 
16:57:08 UTC (rev 19603)
@@ -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,7 +169,29 @@
        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;
 
 // this gets a pointer to an array filled with floats
@@ -436,6 +460,7 @@
 
 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__},

Modified: trunk/blender/source/gameengine/Network/NG_NetworkScene.h
===================================================================
--- trunk/blender/source/gameengine/Network/NG_NetworkScene.h   2009-04-08 
16:51:35 UTC (rev 19602)
+++ trunk/blender/source/gameengine/Network/NG_NetworkScene.h   2009-04-08 
16:57:08 UTC (rev 19603)
@@ -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

Modified: trunk/blender/source/gameengine/PyDoc/GameLogic.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/GameLogic.py  2009-04-08 16:51:35 UTC 
(rev 19602)
+++ trunk/blender/source/gameengine/PyDoc/GameLogic.py  2009-04-08 16:57:08 UTC 
(rev 19603)
@@ -205,6 +205,19 @@
        @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)

Modified: trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/KX_GameObject.py      2009-04-08 
16:51:35 UTC (rev 19602)
+++ trunk/blender/source/gameengine/PyDoc/KX_GameObject.py      2009-04-08 
16:57:08 UTC (rev 19603)
@@ -453,3 +453,14 @@
                @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
+               """


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to