Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp
| Context not available. | |||||
| #include <stddef.h> | #include <stddef.h> | ||||
| #include "KX_NetworkMessageSensor.h" | #include "KX_NetworkMessageSensor.h" | ||||
| #include "KX_NetworkEventManager.h" | #include "KX_NetworkMessageScene.h" | ||||
| #include "NG_NetworkMessage.h" | |||||
| #include "NG_NetworkScene.h" | |||||
| #include "NG_NetworkObject.h" | |||||
| #include "SCA_IObject.h" | #include "SCA_IObject.h" | ||||
| #include "EXP_InputParser.h" | #include "EXP_InputParser.h" | ||||
| #include "EXP_ListValue.h" | #include "EXP_ListValue.h" | ||||
| Context not available. | |||||
| #endif | #endif | ||||
| KX_NetworkMessageSensor::KX_NetworkMessageSensor( | KX_NetworkMessageSensor::KX_NetworkMessageSensor( | ||||
| class KX_NetworkEventManager* eventmgr, // our eventmanager | SCA_EventManager *eventmgr, // our eventmanager | ||||
| class NG_NetworkScene *NetworkScene, // our scene | class KX_NetworkMessageScene *NetworkScene, // our scene | ||||
| SCA_IObject* gameobj, // the sensor controlling object | SCA_IObject *gameobj, // the sensor controlling object | ||||
| const STR_String &subject | const std::string &subject) | ||||
| ) : | :SCA_ISensor(gameobj, eventmgr), | ||||
| SCA_ISensor(gameobj,eventmgr), | m_NetworkScene(NetworkScene), | ||||
| m_NetworkScene(NetworkScene), | m_subject(subject), | ||||
| m_subject(subject), | m_frame_message_count(0), | ||||
| m_frame_message_count (0), | m_BodyList(NULL), | ||||
| m_BodyList(NULL), | m_SubjectList(NULL) | ||||
| m_SubjectList(NULL) | |||||
| { | { | ||||
| Init(); | Init(); | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| } | } | ||||
| CValue* KX_NetworkMessageSensor::GetReplica() | CValue *KX_NetworkMessageSensor::GetReplica() | ||||
| { | { | ||||
| // This is the standard sensor implementation of GetReplica | // This is the standard sensor implementation of GetReplica | ||||
| // There may be more network message sensor specific stuff to do here. | // There may be more network message sensor specific stuff to do here. | ||||
| CValue* replica = new KX_NetworkMessageSensor(*this); | CValue *replica = new KX_NetworkMessageSensor(*this); | ||||
| if (replica == NULL) return NULL; | if (replica == NULL) { | ||||
| return NULL; | |||||
| } | |||||
| replica->ProcessReplica(); | replica->ProcessReplica(); | ||||
| return replica; | return replica; | ||||
| } | } | ||||
| // Return true only for flank (UP and DOWN) | /// Return true only for flank (UP and DOWN) | ||||
| bool KX_NetworkMessageSensor::Evaluate() | bool KX_NetworkMessageSensor::Evaluate() | ||||
| { | { | ||||
| bool result = false; | bool result = false; | ||||
| Context not available. | |||||
| m_SubjectList = NULL; | m_SubjectList = NULL; | ||||
| } | } | ||||
| STR_String& toname=GetParent()->GetName(); | std::string toname = GetParent()->GetName(); | ||||
| STR_String& subject = this->m_subject; | std::string& subject = this->m_subject; | ||||
| vector<NG_NetworkMessage*> messages = | const std::vector<KX_NetworkMessageManager::Message> messages = | ||||
| m_NetworkScene->FindMessages(toname,"",subject,true); | m_NetworkScene->FindMessages(toname, subject); | ||||
| m_frame_message_count = messages.size(); | m_frame_message_count = messages.size(); | ||||
| if (!messages.empty()) { | if (!messages.empty()) { | ||||
| #ifdef NAN_NET_DEBUG | #ifdef NAN_NET_DEBUG | ||||
| printf("KX_NetworkMessageSensor found one or more messages\n"); | std::cout << "KX_NetworkMessageSensor found one or more messages" << std::endl; | ||||
| #endif | #endif | ||||
| m_IsUp = true; | m_IsUp = true; | ||||
| m_BodyList = new CListValue(); | m_BodyList = new CListValue(); | ||||
| m_SubjectList = new CListValue(); | m_SubjectList = new CListValue(); | ||||
| } | } | ||||
| vector<NG_NetworkMessage*>::iterator mesit; | std::vector<KX_NetworkMessageManager::Message>::const_iterator mesit; | ||||
| for (mesit=messages.begin();mesit!=messages.end();mesit++) | for (mesit = messages.begin(); mesit != messages.end(); mesit++) { | ||||
| { | |||||
| // save the body | // save the body | ||||
| const STR_String& body = (*mesit)->GetMessageText(); | const std::string& body = (*mesit).body; | ||||
| // save the subject | // save the subject | ||||
| const STR_String& messub = (*mesit)->GetSubject(); | const std::string& messub = (*mesit).subject; | ||||
| #ifdef NAN_NET_DEBUG | #ifdef NAN_NET_DEBUG | ||||
| if (body) { | if (body) { | ||||
| cout << "body [" << body << "]\n"; | cout << "body [" << body << "]\n"; | ||||
| } | } | ||||
| #endif | #endif | ||||
| m_BodyList->Add(new CStringValue(body,"body")); | m_BodyList->Add(new CStringValue(body, "body")); | ||||
| // Store Subject | // Store Subject | ||||
| m_SubjectList->Add(new CStringValue(messub,"subject")); | m_SubjectList->Add(new CStringValue(messub, "subject")); | ||||
| // free the message | |||||
| (*mesit)->Release(); | |||||
| } | } | ||||
| messages.clear(); | |||||
| result = (WasUp != m_IsUp); | result = (WasUp != m_IsUp); | ||||
| Context not available. | |||||
| return result; | return result; | ||||
| } | } | ||||
| // return true for being up (no flank needed) | /// return true for being up (no flank needed) | ||||
| bool KX_NetworkMessageSensor::IsPositiveTrigger() | bool KX_NetworkMessageSensor::IsPositiveTrigger() | ||||
| { | { | ||||
| // printf("KX_NetworkMessageSensor IsPositiveTrigger\n"); | |||||
| //attempt to fix [ #3809 ] IPO Actuator does not work with some Sensors | //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 | //a better solution is to properly introduce separate Edge and Level triggering concept | ||||
| Context not available. | |||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| py_base_repr, | py_base_repr, | ||||
| 0,0,0,0,0,0,0,0,0, | 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
| Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | ||||
| 0,0,0,0,0,0,0, | 0, 0, 0, 0, 0, 0, 0, | ||||
| Methods, | Methods, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| &SCA_ISensor::Type, | &SCA_ISensor::Type, | ||||
| 0,0,0,0,0,0, | 0, 0, 0, 0, 0, 0, | ||||
| py_base_new | py_base_new | ||||
| }; | }; | ||||
| PyMethodDef KX_NetworkMessageSensor::Methods[] = { | PyMethodDef KX_NetworkMessageSensor::Methods[] = { | ||||
| {NULL,NULL} //Sentinel | {NULL, NULL} //Sentinel | ||||
| }; | }; | ||||
| PyAttributeDef KX_NetworkMessageSensor::Attributes[] = { | PyAttributeDef KX_NetworkMessageSensor::Attributes[] = { | ||||
| Context not available. | |||||
| KX_PYATTRIBUTE_INT_RO("frameMessageCount", KX_NetworkMessageSensor, m_frame_message_count), | KX_PYATTRIBUTE_INT_RO("frameMessageCount", KX_NetworkMessageSensor, m_frame_message_count), | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("bodies", KX_NetworkMessageSensor, pyattr_get_bodies), | KX_PYATTRIBUTE_RO_FUNCTION("bodies", KX_NetworkMessageSensor, pyattr_get_bodies), | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("subjects", KX_NetworkMessageSensor, pyattr_get_subjects), | KX_PYATTRIBUTE_RO_FUNCTION("subjects", KX_NetworkMessageSensor, pyattr_get_subjects), | ||||
| { NULL } //Sentinel | KX_PYATTRIBUTE_NULL //Sentinel | ||||
| }; | }; | ||||
| PyObject *KX_NetworkMessageSensor::pyattr_get_bodies(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject *KX_NetworkMessageSensor::pyattr_get_bodies(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_NetworkMessageSensor *self = static_cast<KX_NetworkMessageSensor*>(self_v); | KX_NetworkMessageSensor *self = static_cast<KX_NetworkMessageSensor *>(self_v); | ||||
| if (self->m_BodyList) { | if (self->m_BodyList) { | ||||
| return self->m_BodyList->GetProxy(); | return self->m_BodyList->GetProxy(); | ||||
| } else { | } | ||||
| else { | |||||
| return (new CListValue())->NewProxy(true); | return (new CListValue())->NewProxy(true); | ||||
| } | } | ||||
| } | } | ||||
| PyObject *KX_NetworkMessageSensor::pyattr_get_subjects(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject *KX_NetworkMessageSensor::pyattr_get_subjects(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_NetworkMessageSensor *self = static_cast<KX_NetworkMessageSensor*>(self_v); | KX_NetworkMessageSensor *self = static_cast<KX_NetworkMessageSensor *>(self_v); | ||||
| if (self->m_SubjectList) { | if (self->m_SubjectList) { | ||||
| return self->m_SubjectList->GetProxy(); | return self->m_SubjectList->GetProxy(); | ||||
| } else { | } | ||||
| else { | |||||
| return (new CListValue())->NewProxy(true); | return (new CListValue())->NewProxy(true); | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||