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