Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 * Ketsji Logic Extenstion: Network Message Actuator generic implementation 00027 */ 00028 00034 #include <stddef.h> 00035 00036 #include "NG_NetworkScene.h" 00037 #include "KX_NetworkMessageActuator.h" 00038 00039 KX_NetworkMessageActuator::KX_NetworkMessageActuator( 00040 SCA_IObject* gameobj, // the actuator controlling object 00041 NG_NetworkScene* networkscene, // needed for replication 00042 const STR_String &toPropName, 00043 const STR_String &subject, 00044 int bodyType, 00045 const STR_String &body) : 00046 SCA_IActuator(gameobj, KX_ACT_MESSAGE), 00047 m_networkscene(networkscene), 00048 m_toPropName(toPropName), 00049 m_subject(subject), 00050 m_bPropBody(bodyType), 00051 m_body(body) 00052 { 00053 } 00054 00055 KX_NetworkMessageActuator::~KX_NetworkMessageActuator() 00056 { 00057 } 00058 00059 // returns true if the actuators needs to be running over several frames 00060 bool KX_NetworkMessageActuator::Update() 00061 { 00062 //printf("update messageactuator\n"); 00063 bool bNegativeEvent = IsNegativeEvent(); 00064 RemoveAllEvents(); 00065 00066 if (bNegativeEvent) { 00067 return false; // do nothing on negative events 00068 //printf("messageactuator false event\n"); 00069 } 00070 //printf("messageactuator true event\n"); 00071 00072 if (m_bPropBody) // ACT_MESG_PROP in DNA_actuator_types.h 00073 { 00074 m_networkscene->SendMessage( 00075 m_toPropName, 00076 GetParent()->GetName(), 00077 m_subject, 00078 GetParent()->GetPropertyText(m_body)); 00079 } else 00080 { 00081 m_networkscene->SendMessage( 00082 m_toPropName, 00083 GetParent()->GetName(), 00084 m_subject, 00085 m_body); 00086 } 00087 return false; 00088 } 00089 00090 CValue* KX_NetworkMessageActuator::GetReplica() 00091 { 00092 KX_NetworkMessageActuator* replica = new KX_NetworkMessageActuator(*this); 00093 replica->ProcessReplica(); 00094 00095 return replica; 00096 } 00097 00098 #ifdef WITH_PYTHON 00099 00100 /* -------------------------------------------------------------------- */ 00101 /* Python interface --------------------------------------------------- */ 00102 /* -------------------------------------------------------------------- */ 00103 00104 /* Integration hooks -------------------------------------------------- */ 00105 PyTypeObject KX_NetworkMessageActuator::Type = { 00106 PyVarObject_HEAD_INIT(NULL, 0) 00107 "KX_NetworkMessageActuator", 00108 sizeof(PyObjectPlus_Proxy), 00109 0, 00110 py_base_dealloc, 00111 0, 00112 0, 00113 0, 00114 0, 00115 py_base_repr, 00116 0,0,0,0,0,0,0,0,0, 00117 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, 00118 0,0,0,0,0,0,0, 00119 Methods, 00120 0, 00121 0, 00122 &SCA_IActuator::Type, 00123 0,0,0,0,0,0, 00124 py_base_new 00125 }; 00126 00127 PyMethodDef KX_NetworkMessageActuator::Methods[] = { 00128 {NULL,NULL} // Sentinel 00129 }; 00130 00131 PyAttributeDef KX_NetworkMessageActuator::Attributes[] = { 00132 KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, KX_NetworkMessageActuator, m_toPropName), 00133 KX_PYATTRIBUTE_STRING_RW("subject", 0, 100, false, KX_NetworkMessageActuator, m_subject), 00134 KX_PYATTRIBUTE_BOOL_RW("usePropBody", KX_NetworkMessageActuator, m_bPropBody), 00135 KX_PYATTRIBUTE_STRING_RW("body", 0, 16384, false, KX_NetworkMessageActuator, m_body), 00136 { NULL } //Sentinel 00137 }; 00138 00139 #endif // WITH_PYTHON