2.50:
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r19820:HEAD Notes: * Game and sequencer RNA, and sequencer header are now out of date a bit after changes in trunk. * I didn't know how to port these bugfixes, most likely they are not needed anymore. * Fix "duplicate strip" always increase the user count for ipo. * IPO pinning on sequencer strips was lost during Undo.
This commit is contained in:
@@ -30,6 +30,8 @@
|
||||
#include "SCA_LogicManager.h"
|
||||
#include "SCA_IActuator.h"
|
||||
#include "SCA_ISensor.h"
|
||||
#include "PyObjectPlus.h"
|
||||
#include "../Ketsji/KX_PythonSeq.h" /* not nice, only need for KX_PythonSeq_CreatePyObject */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
@@ -39,7 +41,8 @@ SCA_IController::SCA_IController(SCA_IObject* gameobj,
|
||||
PyTypeObject* T)
|
||||
:
|
||||
SCA_ILogicBrick(gameobj,T),
|
||||
m_statemask(0)
|
||||
m_statemask(0),
|
||||
m_justActivated(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -47,19 +50,19 @@ SCA_IController::SCA_IController(SCA_IObject* gameobj,
|
||||
|
||||
SCA_IController::~SCA_IController()
|
||||
{
|
||||
UnlinkAllActuators();
|
||||
//UnlinkAllActuators();
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::vector<class SCA_ISensor*>& SCA_IController::GetLinkedSensors()
|
||||
std::vector<class SCA_ISensor*>& SCA_IController::GetLinkedSensors()
|
||||
{
|
||||
return m_linkedsensors;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::vector<class SCA_IActuator*>& SCA_IController::GetLinkedActuators()
|
||||
std::vector<class SCA_IActuator*>& SCA_IController::GetLinkedActuators()
|
||||
{
|
||||
return m_linkedactuators;
|
||||
}
|
||||
@@ -68,13 +71,14 @@ const std::vector<class SCA_IActuator*>& SCA_IController::GetLinkedActuators()
|
||||
|
||||
void SCA_IController::UnlinkAllSensors()
|
||||
{
|
||||
if (IsActive())
|
||||
std::vector<class SCA_ISensor*>::iterator sensit;
|
||||
for (sensit = m_linkedsensors.begin();!(sensit==m_linkedsensors.end());++sensit)
|
||||
{
|
||||
std::vector<class SCA_ISensor*>::iterator sensit;
|
||||
for (sensit = m_linkedsensors.begin();!(sensit==m_linkedsensors.end());++sensit)
|
||||
if (IsActive())
|
||||
{
|
||||
(*sensit)->DecLink();
|
||||
}
|
||||
(*sensit)->UnlinkController(this);
|
||||
}
|
||||
m_linkedsensors.clear();
|
||||
}
|
||||
@@ -83,34 +87,18 @@ void SCA_IController::UnlinkAllSensors()
|
||||
|
||||
void SCA_IController::UnlinkAllActuators()
|
||||
{
|
||||
if (IsActive())
|
||||
std::vector<class SCA_IActuator*>::iterator actit;
|
||||
for (actit = m_linkedactuators.begin();!(actit==m_linkedactuators.end());++actit)
|
||||
{
|
||||
std::vector<class SCA_IActuator*>::iterator actit;
|
||||
for (actit = m_linkedactuators.begin();!(actit==m_linkedactuators.end());++actit)
|
||||
if (IsActive())
|
||||
{
|
||||
(*actit)->DecLink();
|
||||
}
|
||||
(*actit)->UnlinkController(this);
|
||||
}
|
||||
m_linkedactuators.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
void SCA_IController::Trigger(SCA_LogicManager* logicmgr)
|
||||
{
|
||||
//for (int i=0;i<m_linkedactuators.size();i++)
|
||||
for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
|
||||
!(i==m_linkedactuators.end());i++)
|
||||
{
|
||||
SCA_IActuator* actua = *i;//m_linkedactuators.at(i);
|
||||
|
||||
logicmgr->AddActiveActuator(actua);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
void SCA_IController::LinkToActuator(SCA_IActuator* actua)
|
||||
{
|
||||
m_linkedactuators.push_back(actua);
|
||||
@@ -127,18 +115,18 @@ void SCA_IController::UnlinkActuator(class SCA_IActuator* actua)
|
||||
{
|
||||
if ((*actit) == actua)
|
||||
{
|
||||
break;
|
||||
if (IsActive())
|
||||
{
|
||||
(*actit)->DecLink();
|
||||
}
|
||||
*actit = m_linkedactuators.back();
|
||||
m_linkedactuators.pop_back();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
if (!(actit==m_linkedactuators.end()))
|
||||
{
|
||||
if (IsActive())
|
||||
{
|
||||
(*actit)->DecLink();
|
||||
}
|
||||
m_linkedactuators.erase(actit);
|
||||
}
|
||||
printf("Missing link from controller %s:%s to actuator %s:%s\n",
|
||||
m_gameobj->GetName().ReadPtr(), GetName().ReadPtr(),
|
||||
actua->GetParent()->GetName().ReadPtr(), actua->GetName().ReadPtr());
|
||||
}
|
||||
|
||||
void SCA_IController::LinkToSensor(SCA_ISensor* sensor)
|
||||
@@ -157,20 +145,21 @@ void SCA_IController::UnlinkSensor(class SCA_ISensor* sensor)
|
||||
{
|
||||
if ((*sensit) == sensor)
|
||||
{
|
||||
break;
|
||||
if (IsActive())
|
||||
{
|
||||
sensor->DecLink();
|
||||
}
|
||||
*sensit = m_linkedsensors.back();
|
||||
m_linkedsensors.pop_back();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
if (!(sensit==m_linkedsensors.end()))
|
||||
{
|
||||
if (IsActive())
|
||||
{
|
||||
(*sensit)->DecLink();
|
||||
}
|
||||
m_linkedsensors.erase(sensit);
|
||||
}
|
||||
printf("Missing link from controller %s:%s to sensor %s:%s\n",
|
||||
m_gameobj->GetName().ReadPtr(), GetName().ReadPtr(),
|
||||
sensor->GetParent()->GetName().ReadPtr(), sensor->GetName().ReadPtr());
|
||||
}
|
||||
|
||||
|
||||
void SCA_IController::ApplyState(unsigned int state)
|
||||
{
|
||||
std::vector<class SCA_IActuator*>::iterator actit;
|
||||
@@ -185,13 +174,13 @@ void SCA_IController::ApplyState(unsigned int state)
|
||||
{
|
||||
(*actit)->IncLink();
|
||||
}
|
||||
|
||||
for (sensit = m_linkedsensors.begin();!(sensit==m_linkedsensors.end());++sensit)
|
||||
{
|
||||
(*sensit)->IncLink();
|
||||
// remember that this controller just activated that sensor
|
||||
(*sensit)->AddNewController(this);
|
||||
}
|
||||
SetActive(true);
|
||||
m_justActivated = true;
|
||||
}
|
||||
} else if (IsActive())
|
||||
{
|
||||
@@ -204,6 +193,168 @@ void SCA_IController::ApplyState(unsigned int state)
|
||||
(*sensit)->DecLink();
|
||||
}
|
||||
SetActive(false);
|
||||
m_justActivated = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Python api */
|
||||
|
||||
PyTypeObject SCA_IController::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
|
||||
"SCA_IController",
|
||||
sizeof(PyObjectPlus_Proxy),
|
||||
0,
|
||||
py_base_dealloc,
|
||||
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
|
||||
};
|
||||
|
||||
PyParentObject SCA_IController::Parents[] = {
|
||||
&SCA_IController::Type,
|
||||
&CValue::Type,
|
||||
NULL
|
||||
};
|
||||
|
||||
PyMethodDef SCA_IController::Methods[] = {
|
||||
//Deprecated functions ------>
|
||||
{"getSensor", (PyCFunction) SCA_IController::sPyGetSensor, METH_O},
|
||||
{"getActuator", (PyCFunction) SCA_IController::sPyGetActuator, METH_O},
|
||||
{"getSensors", (PyCFunction) SCA_IController::sPyGetSensors, METH_NOARGS},
|
||||
{"getActuators", (PyCFunction) SCA_IController::sPyGetActuators, METH_NOARGS},
|
||||
{"getState", (PyCFunction) SCA_IController::sPyGetState, METH_NOARGS},
|
||||
//<----- Deprecated
|
||||
{NULL,NULL} //Sentinel
|
||||
};
|
||||
|
||||
PyAttributeDef SCA_IController::Attributes[] = {
|
||||
KX_PYATTRIBUTE_RO_FUNCTION("state", SCA_IController, pyattr_get_state),
|
||||
KX_PYATTRIBUTE_RO_FUNCTION("sensors", SCA_IController, pyattr_get_sensors),
|
||||
KX_PYATTRIBUTE_RO_FUNCTION("actuators", SCA_IController, pyattr_get_actuators),
|
||||
KX_PYATTRIBUTE_BOOL_RW("useHighPriority",SCA_IController,m_bookmark),
|
||||
{ NULL } //Sentinel
|
||||
};
|
||||
|
||||
PyObject* SCA_IController::py_getattro(PyObject *attr)
|
||||
{
|
||||
py_getattro_up(SCA_ILogicBrick);
|
||||
}
|
||||
|
||||
PyObject* SCA_IController::py_getattro_dict() {
|
||||
py_getattro_dict_up(SCA_ILogicBrick);
|
||||
}
|
||||
|
||||
int SCA_IController::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
py_setattro_up(SCA_ILogicBrick);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PyObject* SCA_IController::PyGetActuators()
|
||||
{
|
||||
ShowDeprecationWarning("getActuators()", "the actuators property");
|
||||
|
||||
PyObject* resultlist = PyList_New(m_linkedactuators.size());
|
||||
for (unsigned int index=0;index<m_linkedactuators.size();index++)
|
||||
{
|
||||
PyList_SET_ITEM(resultlist,index, m_linkedactuators[index]->GetProxy());
|
||||
}
|
||||
|
||||
return resultlist;
|
||||
}
|
||||
|
||||
PyObject* SCA_IController::PyGetSensor(PyObject* value)
|
||||
{
|
||||
ShowDeprecationWarning("getSensor(string)", "the sensors[string] property");
|
||||
|
||||
char *scriptArg = PyString_AsString(value);
|
||||
if (scriptArg==NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "controller.getSensor(string): Python Controller, expected a string (sensor name)");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (unsigned int index=0;index<m_linkedsensors.size();index++)
|
||||
{
|
||||
SCA_ISensor* sensor = m_linkedsensors[index];
|
||||
STR_String& realname = sensor->GetName();
|
||||
if (realname == scriptArg)
|
||||
{
|
||||
return sensor->GetProxy();
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_AttributeError, "controller.getSensor(string): Python Controller, unable to find requested sensor \"%s\"", scriptArg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject* SCA_IController::PyGetActuator(PyObject* value)
|
||||
{
|
||||
ShowDeprecationWarning("getActuator(string)", "the actuators[string] property");
|
||||
|
||||
char *scriptArg = PyString_AsString(value);
|
||||
if (scriptArg==NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "controller.getActuator(string): Python Controller, expected a string (actuator name)");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (unsigned int index=0;index<m_linkedactuators.size();index++)
|
||||
{
|
||||
SCA_IActuator* actua = m_linkedactuators[index];
|
||||
if (actua->GetName() == scriptArg)
|
||||
{
|
||||
return actua->GetProxy();
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_AttributeError, "controller.getActuator(string): Python Controller, unable to find requested actuator \"%s\"", scriptArg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject* SCA_IController::PyGetSensors()
|
||||
{
|
||||
ShowDeprecationWarning("getSensors()", "the sensors property");
|
||||
|
||||
PyObject* resultlist = PyList_New(m_linkedsensors.size());
|
||||
for (unsigned int index=0;index<m_linkedsensors.size();index++)
|
||||
{
|
||||
PyList_SET_ITEM(resultlist,index, m_linkedsensors[index]->GetProxy());
|
||||
}
|
||||
|
||||
return resultlist;
|
||||
}
|
||||
|
||||
PyObject* SCA_IController::PyGetState()
|
||||
{
|
||||
ShowDeprecationWarning("getState()", "the state property");
|
||||
return PyInt_FromLong(m_statemask);
|
||||
}
|
||||
|
||||
PyObject* SCA_IController::pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
SCA_IController* self= static_cast<SCA_IController*>(self_v);
|
||||
return PyInt_FromLong(self->m_statemask);
|
||||
}
|
||||
|
||||
PyObject* SCA_IController::pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
return KX_PythonSeq_CreatePyObject((static_cast<SCA_IController*>(self_v))->m_proxy, KX_PYGENSEQ_CONT_TYPE_SENSORS);
|
||||
}
|
||||
|
||||
PyObject* SCA_IController::pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
return KX_PythonSeq_CreatePyObject((static_cast<SCA_IController*>(self_v))->m_proxy, KX_PYGENSEQ_CONT_TYPE_ACTUATORS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user