fixing some issues: force needs to wake up objects, property sensor issue, island...
[blender.git] / source / gameengine / Ketsji / KXNetwork / KX_NetworkMessageSensor.cpp
index 1eeceb55469e179c6a2b6b13a7283294df2b2e29..a01673f569fbadf3d366bac0372ac1b2aca76451 100644 (file)
 #include "ListValue.h"
 #include "StringValue.h"
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #ifdef NAN_NET_DEBUG
   #include <iostream>
 #endif
@@ -56,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)
 {
 }
 
@@ -85,12 +90,18 @@ bool KX_NetworkMessageSensor::Evaluate(CValue* event)
        bool result = false;
        bool WasUp = m_IsUp;
 
-       m_IsUp = false;
+//     m_IsUp = false;
+
        if (m_BodyList) {
                m_BodyList->Release();
                m_BodyList = NULL;
        }
 
+       if (m_SubjectList) {
+               m_SubjectList->Release();
+               m_SubjectList = NULL;
+       }
+
        STR_String toname=GetParent()->GetName();
        STR_String subject = this->m_subject;
 
@@ -105,6 +116,7 @@ bool KX_NetworkMessageSensor::Evaluate(CValue* event)
 #endif
                m_IsUp = true;
                m_BodyList = new CListValue();
+               m_SubjectList = new CListValue();
        }
 
        vector<NG_NetworkMessage*>::iterator mesit;
@@ -112,12 +124,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();
@@ -134,7 +150,10 @@ bool KX_NetworkMessageSensor::Evaluate(CValue* event)
 bool KX_NetworkMessageSensor::IsPositiveTrigger()
 {
 //     printf("KX_NetworkMessageSensor IsPositiveTrigger\n");
-       return m_IsUp;
+       //attempt to fix [ #3809 ] IPO Actuator does not work with some Sensors
+       //a better solution is to properly introduce separate Edge and Level triggering concept
+
+       return true;//m_IsUp;
 }
 
 /* --------------------------------------------------------------------- */
@@ -182,10 +201,13 @@ 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
 };
 
-PyObject* KX_NetworkMessageSensor::_getattr(char* attr) {
+PyObject* KX_NetworkMessageSensor::_getattr(const STR_String& attr) {
        _getattr_up(SCA_ISensor); // implicit return!
 }
 
@@ -239,10 +261,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,
@@ -256,3 +278,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;
+}