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:
authorKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>2004-04-08 15:36:22 +0400
committerKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>2004-04-08 15:36:22 +0400
commit80485c2926a518b5de9db3d737abd4afb80be5a7 (patch)
tree2053f46ed955323a8dfcbdb9d99f4c46b759ad30 /source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp
parent5398f1ba77d25ff27a4e8275a1453e7ddb2f2f0d (diff)
In NaN times I suggested a python function to get the subject of a
Message using a python function of the MessageSensor. Thats a nice thing if you want complex message handling in one python script. Just get all messages, check the subject and do what you want. In the current situation you end up with several MessageSensors connected to the python script, instead of one Sensor and a smart script. Some developer (cant remember who) did implement that function, but however not the way I wanted (maybe I was not clear enough) ;-) So the getSubject() function will return whats entered in the "Subject:" filter field of the MessageSensor. Quite useless IMHO. So I added a new function getSubjects() which is similar to getBodies(), in fact I stole the code from there ;-) I left the getSubject() alone, because of backward compatibility (never saw someone using that function, but...) The future: In conjunction with a wildcard subject: filter field the getSubjects() function will be even more usefull. i.e. Player* will filter for PlayerScore, PlayerKill etc. -- Carsten Wartmann
Diffstat (limited to 'source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp')
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp
index 7e1e46d029a..ab5f9b989a7 100644
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp
+++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp
@@ -60,9 +60,10 @@ KX_NetworkMessageSensor::KX_NetworkMessageSensor(
m_Networkeventmgr(eventmgr),
m_NetworkScene(NetworkScene),
m_subject(subject),
- m_frame_message_count (0),
+ m_frame_message_count (0),
m_IsUp(false),
- m_BodyList(NULL)
+ m_BodyList(NULL),
+ m_SubjectList(NULL)
{
}
@@ -95,6 +96,11 @@ bool KX_NetworkMessageSensor::Evaluate(CValue* event)
m_BodyList = NULL;
}
+ if (m_SubjectList) {
+ m_SubjectList->Release();
+ m_SubjectList = NULL;
+ }
+
STR_String toname=GetParent()->GetName();
STR_String subject = this->m_subject;
@@ -109,6 +115,7 @@ bool KX_NetworkMessageSensor::Evaluate(CValue* event)
#endif
m_IsUp = true;
m_BodyList = new CListValue();
+ m_SubjectList = new CListValue();
}
vector<NG_NetworkMessage*>::iterator mesit;
@@ -116,12 +123,16 @@ bool KX_NetworkMessageSensor::Evaluate(CValue* event)
{
// save the body
STR_String body = (*mesit)->GetMessageText();
+ // save the subject
+ STR_String messub = (*mesit)->GetSubject();
#ifdef NAN_NET_DEBUG
if (body) {
cout << "body [" << body << "]\n";
}
#endif
m_BodyList->Add(new CStringValue(body,"body"));
+ // Store Subject
+ m_SubjectList->Add(new CStringValue(messub,"subject"));
// free the message
(*mesit)->Release();
@@ -186,6 +197,9 @@ PyMethodDef KX_NetworkMessageSensor::Methods[] = {
{"getSubject", (PyCFunction)
KX_NetworkMessageSensor::sPyGetSubject, METH_VARARGS,
GetSubject_doc},
+ {"getSubjects", (PyCFunction)
+ KX_NetworkMessageSensor::sPyGetSubjects, METH_VARARGS,
+ GetSubjects_doc},
{NULL,NULL} //Sentinel
};
@@ -243,10 +257,10 @@ PyObject* KX_NetworkMessageSensor::PyGetBodies(
Py_Return;
}
-// 4. Get the message subject
+// 4. Get the message subject: field of the message sensor
char KX_NetworkMessageSensor::GetSubject_doc[] =
"\tgetSubject()\n"
-"\tGet the subject of the message.\n";
+"\tGet the subject: field of the message sensor.\n";
PyObject* KX_NetworkMessageSensor::PyGetSubject(
PyObject* self,
@@ -260,3 +274,19 @@ PyObject* KX_NetworkMessageSensor::PyGetSubject(
Py_Return;
}
+// 5. Get the message subjects
+char KX_NetworkMessageSensor::GetSubjects_doc[] =
+"\tgetSubjects()\n"
+"\tGet list of message subjects.\n";
+
+PyObject* KX_NetworkMessageSensor::PyGetSubjects(
+ PyObject* self,
+ PyObject* args,
+ PyObject* kwds)
+{
+ if (m_SubjectList) {
+ return ((PyObject*) m_SubjectList->AddRef());
+ }
+
+ Py_Return;
+}