blender/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp

243 lines
5.9 KiB
C++
Raw Normal View History

2002-10-12 11:37:38 +00:00
/**
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
2002-10-12 11:37:38 +00:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
* Ketsji Logic Extenstion: Network Message Actuator generic implementation
*/
#include "NG_NetworkScene.h"
#include "KX_NetworkMessageActuator.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
2002-10-12 11:37:38 +00:00
KX_NetworkMessageActuator::KX_NetworkMessageActuator(
SCA_IObject* gameobj, // the actuator controlling object
NG_NetworkScene* networkscene, // needed for replication
const STR_String &toPropName,
const STR_String &subject,
int bodyType,
const STR_String &body,
PyTypeObject* T) :
SCA_IActuator(gameobj,T),
m_networkscene(networkscene),
m_toPropName(toPropName),
m_subject(subject),
m_bPropBody(bodyType),
2002-10-12 11:37:38 +00:00
m_body(body)
{
}
KX_NetworkMessageActuator::~KX_NetworkMessageActuator()
{
}
// returns true if the actuators needs to be running over several frames
bool KX_NetworkMessageActuator::Update()
2002-10-12 11:37:38 +00:00
{
//printf("update messageactuator\n");
bool bNegativeEvent = IsNegativeEvent();
RemoveAllEvents();
if (bNegativeEvent) {
return false; // do nothing on negative events
//printf("messageactuator false event\n");
}
//printf("messageactuator true event\n");
if (m_bPropBody) // ACT_MESG_PROP in DNA_actuator_types.h
2002-10-12 11:37:38 +00:00
{
m_networkscene->SendMessage(
m_toPropName,
GetParent()->GetName(),
m_subject,
BGE performance, 4th round: logic This commit extends the technique of dynamic linked list to the logic system to eliminate as much as possible temporaries, map lookup or full scan. The logic engine is now free of memory allocation, which is an important stability factor. The overhead of the logic system is reduced by a factor between 3 and 6 depending on the logic setup. This is the speed-up you can expect on a logic setup using simple bricks. Heavy bricks like python controllers and ray sensors will still take about the same time to execute so the speed up will be less important. The core of the logic engine has been much reworked but the functionality is still the same except for one thing: the priority system on the execution of controllers. The exact same remark applies to actuators but I'll explain for controllers only: Previously, it was possible, with the "executePriority" attribute to set a controller to run before any other controllers in the game. Other than that, the sequential execution of controllers, as defined in Blender was guaranteed by default. With the new system, the sequential execution of controllers is still guaranteed but only within the controllers of one object. the user can no longer set a controller to run before any other controllers in the game. The "executePriority" attribute controls the execution of controllers within one object. The priority is a small number starting from 0 for the first controller and incrementing for each controller. If this missing feature is a must, a special method can be implemented to set a controller to run before all other controllers. Other improvements: - Systematic use of reference in parameter passing to avoid unnecessary data copy - Use pre increment in iterator instead of post increment to avoid temporary allocation - Use const char* instead of STR_String whenever possible to avoid temporary allocation - Fix reference counting bugs (memory leak) - Fix a crash in certain cases of state switching and object deletion - Minor speed up in property sensor - Removal of objects during the game is a lot faster
2009-05-10 20:53:58 +00:00
GetParent()->GetPropertyText(m_body));
2002-10-12 11:37:38 +00:00
} else
{
m_networkscene->SendMessage(
m_toPropName,
GetParent()->GetName(),
m_subject,
m_body);
}
return false;
}
CValue* KX_NetworkMessageActuator::GetReplica()
{
KX_NetworkMessageActuator* replica =
new KX_NetworkMessageActuator(*this);
replica->ProcessReplica();
return replica;
}
/* -------------------------------------------------------------------- */
/* Python interface --------------------------------------------------- */
/* -------------------------------------------------------------------- */
/* Integration hooks -------------------------------------------------- */
PyTypeObject KX_NetworkMessageActuator::Type = {
#if (PY_VERSION_HEX >= 0x02060000)
PyVarObject_HEAD_INIT(NULL, 0)
#else
/* python 2.5 and below */
PyObject_HEAD_INIT( NULL ) /* required py macro */
0, /* ob_size */
#endif
2002-10-12 11:37:38 +00:00
"KX_NetworkMessageActuator",
sizeof(PyObjectPlus_Proxy),
2002-10-12 11:37:38 +00:00
0,
py_base_dealloc,
2002-10-12 11:37:38 +00:00
0,
0,
0,
0,
py_base_repr,
0,0,0,0,0,0,
py_base_getattro,
py_base_setattro,
0,0,0,0,0,0,0,0,0,
Methods
2002-10-12 11:37:38 +00:00
};
PyParentObject KX_NetworkMessageActuator::Parents[] = {
&KX_NetworkMessageActuator::Type,
&SCA_IActuator::Type,
&SCA_ILogicBrick::Type,
&CValue::Type,
NULL
};
PyMethodDef KX_NetworkMessageActuator::Methods[] = {
// Deprecated ----->
2002-10-12 11:37:38 +00:00
{"setToPropName", (PyCFunction)
KX_NetworkMessageActuator::sPySetToPropName, METH_VARARGS},
{"setSubject", (PyCFunction)
KX_NetworkMessageActuator::sPySetSubject, METH_VARARGS},
{"setBodyType", (PyCFunction)
KX_NetworkMessageActuator::sPySetBodyType, METH_VARARGS},
{"setBody", (PyCFunction)
KX_NetworkMessageActuator::sPySetBody, METH_VARARGS},
// <-----
2002-10-12 11:37:38 +00:00
{NULL,NULL} // Sentinel
};
PyAttributeDef KX_NetworkMessageActuator::Attributes[] = {
KX_PYATTRIBUTE_STRING_RW("propName", 0, 100, false, KX_NetworkMessageActuator, m_toPropName),
KX_PYATTRIBUTE_STRING_RW("subject", 0, 100, false, KX_NetworkMessageActuator, m_subject),
KX_PYATTRIBUTE_BOOL_RW("usePropBody", KX_NetworkMessageActuator, m_bPropBody),
KX_PYATTRIBUTE_STRING_RW("body", 0, 100, false, KX_NetworkMessageActuator, m_body),
{ NULL } //Sentinel
};
PyObject* KX_NetworkMessageActuator::py_getattro(PyObject *attr) {
py_getattro_up(SCA_IActuator);
2002-10-12 11:37:38 +00:00
}
PyObject* KX_NetworkMessageActuator::py_getattro_dict() {
py_getattro_dict_up(SCA_IActuator);
}
int KX_NetworkMessageActuator::py_setattro(PyObject *attr, PyObject *value) {
py_setattro_up(SCA_IActuator);
}
// Deprecated ----->
2002-10-12 11:37:38 +00:00
// 1. SetToPropName
PyObject* KX_NetworkMessageActuator::PySetToPropName(
PyObject* args,
PyObject* kwds)
{
ShowDeprecationWarning("setToProp()", "the propName property");
2002-10-12 11:37:38 +00:00
char* ToPropName;
if (PyArg_ParseTuple(args, "s:setToPropName", &ToPropName)) {
2002-10-12 11:37:38 +00:00
m_toPropName = ToPropName;
}
else {
return NULL;
}
2002-10-12 11:37:38 +00:00
Py_RETURN_NONE;
2002-10-12 11:37:38 +00:00
}
// 2. SetSubject
PyObject* KX_NetworkMessageActuator::PySetSubject(
PyObject* args,
PyObject* kwds)
{
ShowDeprecationWarning("setSubject()", "the subject property");
2002-10-12 11:37:38 +00:00
char* Subject;
if (PyArg_ParseTuple(args, "s:setSubject", &Subject)) {
2002-10-12 11:37:38 +00:00
m_subject = Subject;
}
else {
return NULL;
}
Py_RETURN_NONE;
2002-10-12 11:37:38 +00:00
}
// 3. SetBodyType
PyObject* KX_NetworkMessageActuator::PySetBodyType(
PyObject* args,
PyObject* kwds)
{
ShowDeprecationWarning("setBodyType()", "the usePropBody property");
2002-10-12 11:37:38 +00:00
int BodyType;
if (PyArg_ParseTuple(args, "i:setBodyType", &BodyType)) {
m_bPropBody = (BodyType != 0);
2002-10-12 11:37:38 +00:00
}
else {
return NULL;
}
2002-10-12 11:37:38 +00:00
Py_RETURN_NONE;
2002-10-12 11:37:38 +00:00
}
// 4. SetBody
PyObject* KX_NetworkMessageActuator::PySetBody(
PyObject* args,
PyObject* kwds)
{
ShowDeprecationWarning("setBody()", "the body property");
2002-10-12 11:37:38 +00:00
char* Body;
if (PyArg_ParseTuple(args, "s:setBody", &Body)) {
2002-10-12 11:37:38 +00:00
m_body = Body;
}
else {
return NULL;
}
2002-10-12 11:37:38 +00:00
Py_RETURN_NONE;
2002-10-12 11:37:38 +00:00
}
// <----- Deprecated