2.50: svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r19323:HEAD
Notes: * blenderbuttons and ICON_SNAP_PEEL_OBJECT were not merged.
This commit is contained in:
@@ -154,10 +154,10 @@ int SCA_PythonController::IsTriggered(class SCA_ISensor* sensor)
|
||||
static const char* sPyGetCurrentController__doc__;
|
||||
#endif
|
||||
|
||||
|
||||
PyObject* SCA_PythonController::sPyGetCurrentController(PyObject* self)
|
||||
/* warning, self is not the SCA_PythonController, its a PyObjectPlus_Proxy */
|
||||
PyObject* SCA_PythonController::sPyGetCurrentController(PyObject *self)
|
||||
{
|
||||
return m_sCurrentController->AddRef();
|
||||
return m_sCurrentController->GetProxy();
|
||||
}
|
||||
|
||||
SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
|
||||
@@ -176,10 +176,10 @@ SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Expecting an actuator type */
|
||||
else if (BGE_PROXY_CHECK_TYPE(value)) {
|
||||
PyObjectPlus *value_plus= BGE_PROXY_REF(value); /* Expecting an actuator type */ // XXX TODO - CHECK TYPE
|
||||
for(it = lacts.begin(); it!= lacts.end(); it++) {
|
||||
if( static_cast<SCA_IActuator*>(value) == (*it) ) {
|
||||
if( static_cast<SCA_IActuator*>(value_plus) == (*it) ) {
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
@@ -187,7 +187,7 @@ SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
|
||||
|
||||
/* set the exception */
|
||||
PyObject *value_str = PyObject_Repr(value); /* new ref */
|
||||
PyErr_Format(PyExc_ValueError, "'%s' not in this controllers actuator list", PyString_AsString(value_str));
|
||||
PyErr_Format(PyExc_ValueError, "'%s' not in this python controllers actuator list", PyString_AsString(value_str));
|
||||
Py_DECREF(value_str);
|
||||
|
||||
return false;
|
||||
@@ -197,15 +197,12 @@ SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
|
||||
static const char* sPyAddActiveActuator__doc__;
|
||||
#endif
|
||||
|
||||
PyObject* SCA_PythonController::sPyAddActiveActuator(
|
||||
|
||||
PyObject* self,
|
||||
PyObject* args)
|
||||
/* warning, self is not the SCA_PythonController, its a PyObjectPlus_Proxy */
|
||||
PyObject* SCA_PythonController::sPyAddActiveActuator(PyObject* self, PyObject* args)
|
||||
{
|
||||
|
||||
PyObject* ob1;
|
||||
int activate;
|
||||
if (!PyArg_ParseTuple(args, "Oi", &ob1,&activate))
|
||||
if (!PyArg_ParseTuple(args, "Oi:addActiveActuator", &ob1,&activate))
|
||||
return NULL;
|
||||
|
||||
SCA_IActuator* actu = LinkedActuatorFromPy(ob1);
|
||||
@@ -224,22 +221,22 @@ const char* SCA_PythonController::sPyAddActiveActuator__doc__= "addActiveActuato
|
||||
const char SCA_PythonController::GetActuators_doc[] = "getActuator";
|
||||
|
||||
PyTypeObject SCA_PythonController::Type = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0,
|
||||
"SCA_PythonController",
|
||||
sizeof(SCA_PythonController),
|
||||
sizeof(PyObjectPlus_Proxy),
|
||||
0,
|
||||
PyDestructor,
|
||||
0,
|
||||
__getattr,
|
||||
__setattr,
|
||||
0, //&MyPyCompare,
|
||||
__repr,
|
||||
0, //&cvalue_as_number,
|
||||
py_base_dealloc,
|
||||
0,
|
||||
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_PythonController::Parents[] = {
|
||||
@@ -265,6 +262,8 @@ PyMethodDef SCA_PythonController::Methods[] = {
|
||||
};
|
||||
|
||||
PyAttributeDef SCA_PythonController::Attributes[] = {
|
||||
KX_PYATTRIBUTE_RO_FUNCTION("state", SCA_PythonController, pyattr_get_state),
|
||||
KX_PYATTRIBUTE_RW_FUNCTION("script", SCA_PythonController, pyattr_get_script, pyattr_set_script),
|
||||
{ NULL } //Sentinel
|
||||
};
|
||||
|
||||
@@ -298,7 +297,7 @@ bool SCA_PythonController::Compile()
|
||||
* their user count. Not to mention holding references to wrapped data.
|
||||
* This is especially bad when the PyObject for the wrapped data is free'd, after blender
|
||||
* has alredy dealocated the pointer */
|
||||
PySys_SetObject( (char *)"last_traceback", Py_None);
|
||||
PySys_SetObject( (char *)"last_traceback", NULL);
|
||||
PyErr_Clear(); /* just to be sure */
|
||||
|
||||
return false;
|
||||
@@ -356,7 +355,7 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
|
||||
* their user count. Not to mention holding references to wrapped data.
|
||||
* This is especially bad when the PyObject for the wrapped data is free'd, after blender
|
||||
* has alredy dealocated the pointer */
|
||||
PySys_SetObject( (char *)"last_traceback", Py_None);
|
||||
PySys_SetObject( (char *)"last_traceback", NULL);
|
||||
PyErr_Clear(); /* just to be sure */
|
||||
|
||||
//PyRun_SimpleString(m_scriptText.Ptr());
|
||||
@@ -372,41 +371,17 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
|
||||
|
||||
|
||||
|
||||
PyObject* SCA_PythonController::_getattr(const char *attr)
|
||||
PyObject* SCA_PythonController::py_getattro(PyObject *attr)
|
||||
{
|
||||
if (!strcmp(attr,"state")) {
|
||||
return PyInt_FromLong(m_statemask);
|
||||
}
|
||||
if (!strcmp(attr,"script")) {
|
||||
return PyString_FromString(m_scriptText);
|
||||
}
|
||||
_getattr_up(SCA_IController);
|
||||
py_getattro_up(SCA_IController);
|
||||
}
|
||||
|
||||
int SCA_PythonController::_setattr(const char *attr, PyObject *value)
|
||||
int SCA_PythonController::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
if (!strcmp(attr,"state")) {
|
||||
PyErr_SetString(PyExc_AttributeError, "state is read only");
|
||||
return 1;
|
||||
}
|
||||
if (!strcmp(attr,"script")) {
|
||||
char *scriptArg = PyString_AsString(value);
|
||||
|
||||
if (scriptArg==NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "expected a string (script name)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* set scripttext sets m_bModified to true,
|
||||
so next time the script is needed, a reparse into byte code is done */
|
||||
this->SetScriptText(scriptArg);
|
||||
|
||||
return 1;
|
||||
}
|
||||
return SCA_IController::_setattr(attr, value);
|
||||
py_setattro_up(SCA_IController);
|
||||
}
|
||||
|
||||
PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value)
|
||||
PyObject* SCA_PythonController::PyActivate(PyObject *value)
|
||||
{
|
||||
SCA_IActuator* actu = LinkedActuatorFromPy(value);
|
||||
if(actu==NULL)
|
||||
@@ -418,7 +393,7 @@ PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* SCA_PythonController::PyDeActivate(PyObject* self, PyObject *value)
|
||||
PyObject* SCA_PythonController::PyDeActivate(PyObject *value)
|
||||
{
|
||||
SCA_IActuator* actu = LinkedActuatorFromPy(value);
|
||||
if(actu==NULL)
|
||||
@@ -430,26 +405,26 @@ PyObject* SCA_PythonController::PyDeActivate(PyObject* self, PyObject *value)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* SCA_PythonController::PyGetActuators(PyObject* self)
|
||||
PyObject* SCA_PythonController::PyGetActuators()
|
||||
{
|
||||
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]->AddRef());
|
||||
PyList_SET_ITEM(resultlist,index, m_linkedactuators[index]->GetProxy());
|
||||
}
|
||||
|
||||
return resultlist;
|
||||
}
|
||||
|
||||
const char SCA_PythonController::GetSensor_doc[] =
|
||||
"GetSensor (char sensorname) return linked sensor that is named [sensorname]\n";
|
||||
"getSensor (char sensorname) return linked sensor that is named [sensorname]\n";
|
||||
PyObject*
|
||||
SCA_PythonController::PyGetSensor(PyObject* self, PyObject* value)
|
||||
SCA_PythonController::PyGetSensor(PyObject* value)
|
||||
{
|
||||
|
||||
char *scriptArg = PyString_AsString(value);
|
||||
if (scriptArg==NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "expected a string (sensor name)");
|
||||
PyErr_SetString(PyExc_TypeError, "controller.getSensor(string): Python Controller, expected a string (sensor name)");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -459,27 +434,25 @@ SCA_PythonController::PyGetSensor(PyObject* self, PyObject* value)
|
||||
STR_String realname = sensor->GetName();
|
||||
if (realname == scriptArg)
|
||||
{
|
||||
return sensor->AddRef();
|
||||
return sensor->GetProxy();
|
||||
}
|
||||
}
|
||||
|
||||
char emsg[96];
|
||||
PyOS_snprintf( emsg, sizeof( emsg ), "Unable to find requested sensor \"%s\"", scriptArg );
|
||||
PyErr_SetString(PyExc_AttributeError, emsg);
|
||||
PyErr_Format(PyExc_AttributeError, "controller.getSensor(string): Python Controller, unable to find requested sensor \"%s\"", scriptArg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char SCA_PythonController::GetActuator_doc[] =
|
||||
"GetActuator (char sensorname) return linked actuator that is named [actuatorname]\n";
|
||||
"getActuator (char sensorname) return linked actuator that is named [actuatorname]\n";
|
||||
PyObject*
|
||||
SCA_PythonController::PyGetActuator(PyObject* self, PyObject* value)
|
||||
SCA_PythonController::PyGetActuator(PyObject* value)
|
||||
{
|
||||
|
||||
char *scriptArg = PyString_AsString(value);
|
||||
if (scriptArg==NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "expected a string (actuator name)");
|
||||
PyErr_SetString(PyExc_TypeError, "controller.getActuator(string): Python Controller, expected a string (actuator name)");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -488,39 +461,37 @@ SCA_PythonController::PyGetActuator(PyObject* self, PyObject* value)
|
||||
SCA_IActuator* actua = m_linkedactuators[index];
|
||||
if (actua->GetName() == scriptArg)
|
||||
{
|
||||
return actua->AddRef();
|
||||
return actua->GetProxy();
|
||||
}
|
||||
}
|
||||
|
||||
char emsg[96];
|
||||
PyOS_snprintf( emsg, sizeof( emsg ), "Unable to find requested actuator \"%s\"", scriptArg );
|
||||
PyErr_SetString(PyExc_AttributeError, emsg);
|
||||
PyErr_Format(PyExc_AttributeError, "controller.getActuator(string): Python Controller, unable to find requested actuator \"%s\"", scriptArg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
const char SCA_PythonController::GetSensors_doc[] = "getSensors returns a list of all attached sensors";
|
||||
PyObject*
|
||||
SCA_PythonController::PyGetSensors(PyObject* self)
|
||||
SCA_PythonController::PyGetSensors()
|
||||
{
|
||||
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]->AddRef());
|
||||
PyList_SET_ITEM(resultlist,index, m_linkedsensors[index]->GetProxy());
|
||||
}
|
||||
|
||||
return resultlist;
|
||||
}
|
||||
|
||||
/* 1. getScript */
|
||||
PyObject* SCA_PythonController::PyGetScript(PyObject* self)
|
||||
PyObject* SCA_PythonController::PyGetScript()
|
||||
{
|
||||
ShowDeprecationWarning("getScript()", "the script property");
|
||||
return PyString_FromString(m_scriptText);
|
||||
}
|
||||
|
||||
/* 2. setScript */
|
||||
PyObject* SCA_PythonController::PySetScript(PyObject* self, PyObject* value)
|
||||
PyObject* SCA_PythonController::PySetScript(PyObject* value)
|
||||
{
|
||||
char *scriptArg = PyString_AsString(value);
|
||||
|
||||
@@ -540,10 +511,41 @@ PyObject* SCA_PythonController::PySetScript(PyObject* self, PyObject* value)
|
||||
}
|
||||
|
||||
/* 1. getScript */
|
||||
PyObject* SCA_PythonController::PyGetState(PyObject* self)
|
||||
PyObject* SCA_PythonController::PyGetState()
|
||||
{
|
||||
ShowDeprecationWarning("getState()", "the state property");
|
||||
return PyInt_FromLong(m_statemask);
|
||||
}
|
||||
|
||||
PyObject* SCA_PythonController::pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
SCA_PythonController* self= static_cast<SCA_PythonController*>(self_v);
|
||||
return PyInt_FromLong(self->m_statemask);
|
||||
}
|
||||
|
||||
PyObject* SCA_PythonController::pyattr_get_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
SCA_PythonController* self= static_cast<SCA_PythonController*>(self_v);
|
||||
return PyString_FromString(self->m_scriptText);
|
||||
}
|
||||
|
||||
int SCA_PythonController::pyattr_set_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
||||
{
|
||||
SCA_PythonController* self= static_cast<SCA_PythonController*>(self_v);
|
||||
|
||||
char *scriptArg = PyString_AsString(value);
|
||||
|
||||
if (scriptArg==NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "controller.script = string: Python Controller, expected a string script text");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* set scripttext sets m_bModified to true,
|
||||
so next time the script is needed, a reparse into byte code is done */
|
||||
self->SetScriptText(scriptArg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* eof */
|
||||
|
||||
Reference in New Issue
Block a user