- Attributes for the collision sensor: propertyName, materialCheck, pulseCollisions, objectHit and objectHitList.

Removed a check in Python API touch.setProperty() for the property name on the sensor owner before allowing the name to be set - it makes no sense and isnt checked when creating the sensor.
- SCA_DelaySensor.py indent error making epydoc fail.
This commit is contained in:
2009-02-26 04:17:23 +00:00
parent 97e70ef3c4
commit 6bfb8ca6b0
5 changed files with 100 additions and 62 deletions

View File

@@ -311,10 +311,10 @@ PyParentObject KX_NearSensor::Parents[] = {
PyMethodDef KX_NearSensor::Methods[] = {
{"setProperty", (PyCFunction) KX_NearSensor::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc},
{"getProperty", (PyCFunction) KX_NearSensor::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc},
{"getHitObject",(PyCFunction) KX_NearSensor::sPyGetHitObject, METH_VARARGS, (PY_METHODCHAR)GetHitObject_doc},
{"getHitObjectList", (PyCFunction) KX_NearSensor::sPyGetHitObjectList, METH_VARARGS, (PY_METHODCHAR)GetHitObjectList_doc},
{"setProperty", (PyCFunction) KX_NearSensor::sPySetProperty, METH_O, (PY_METHODCHAR)SetProperty_doc},
{"getProperty", (PyCFunction) KX_NearSensor::sPyGetProperty, METH_NOARGS, (PY_METHODCHAR)GetProperty_doc},
{"getHitObject",(PyCFunction) KX_NearSensor::sPyGetHitObject, METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc},
{"getHitObjectList", (PyCFunction) KX_NearSensor::sPyGetHitObjectList, METH_NOARGS, (PY_METHODCHAR)GetHitObjectList_doc},
{NULL,NULL} //Sentinel
};

View File

@@ -270,20 +270,57 @@ PyParentObject KX_TouchSensor::Parents[] = {
PyMethodDef KX_TouchSensor::Methods[] = {
{"setProperty",
(PyCFunction) KX_TouchSensor::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc},
(PyCFunction) KX_TouchSensor::sPySetProperty, METH_O, (PY_METHODCHAR)SetProperty_doc},
{"getProperty",
(PyCFunction) KX_TouchSensor::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc},
(PyCFunction) KX_TouchSensor::sPyGetProperty, METH_NOARGS, (PY_METHODCHAR)GetProperty_doc},
{"getHitObject",
(PyCFunction) KX_TouchSensor::sPyGetHitObject, METH_VARARGS, (PY_METHODCHAR)GetHitObject_doc},
(PyCFunction) KX_TouchSensor::sPyGetHitObject, METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc},
{"getHitObjectList",
(PyCFunction) KX_TouchSensor::sPyGetHitObjectList, METH_VARARGS, (PY_METHODCHAR)GetHitObjectList_doc},
(PyCFunction) KX_TouchSensor::sPyGetHitObjectList, METH_NOARGS, (PY_METHODCHAR)GetHitObjectList_doc},
{NULL,NULL} //Sentinel
};
PyObject* KX_TouchSensor::_getattr(const char *attr) {
PyAttributeDef KX_TouchSensor::Attributes[] = {
KX_PYATTRIBUTE_STRING_RW("propertyName",0,100,false,KX_TouchSensor,m_touchedpropname),
KX_PYATTRIBUTE_BOOL_RW("materialCheck",KX_TouchSensor,m_bFindMaterial),
KX_PYATTRIBUTE_BOOL_RW("pulseCollisions",KX_TouchSensor,m_bTouchPulse),
{ NULL } //Sentinel
};
PyObject* KX_TouchSensor::_getattr(const char *attr)
{
if (!strcmp(attr, "objectHit")) {
if (m_hitObject) return m_hitObject->AddRef();
else Py_RETURN_NONE;
}
if (!strcmp(attr, "objectHitList")) {
return m_colliders->AddRef();
}
PyObject* object= _getattr_self(Attributes, this, attr);
if (object != NULL)
return object;
_getattr_up(SCA_ISensor);
}
int KX_TouchSensor::_setattr(const char *attr, PyObject *value)
{
int ret = _setattr_self(Attributes, this, attr, value);
if (ret >= 0)
return ret;
if (!strcmp(attr, "objectHit")) {
PyErr_SetString(PyExc_AttributeError, "attribute \"objectHit\" is read only");
return 1;
}
if (!strcmp(attr, "objectHitList")) {
PyErr_SetString(PyExc_AttributeError, "attribute \"objectHit\" is read only");
return 1;
}
return SCA_ISensor::_setattr(attr, value);
}
/* Python API */
/* 1. setProperty */
@@ -293,23 +330,16 @@ const char KX_TouchSensor::SetProperty_doc[] =
"\tSet the property or material to collide with. Use\n"
"\tsetTouchMaterial() to switch between properties and\n"
"\tmaterials.";
PyObject* KX_TouchSensor::PySetProperty(PyObject* self,
PyObject* args,
PyObject* kwds) {
char *nameArg;
if (!PyArg_ParseTuple(args, "s", &nameArg)) {
PyObject* KX_TouchSensor::PySetProperty(PyObject* self, PyObject* value)
{
ShowDeprecationWarning("setProperty()", "the propertyName property");
char *nameArg= PyString_AsString(value);
if (nameArg==NULL) {
PyErr_SetString(PyExc_ValueError, "expected a ");
return NULL;
}
CValue* prop = GetParent()->FindIdentifier(nameArg);
if (!prop->IsError()) {
m_touchedpropname = nameArg;
} else {
; /* not found ... */
}
prop->Release();
m_touchedpropname = nameArg;
Py_RETURN_NONE;
}
/* 2. getProperty */
@@ -318,19 +348,16 @@ const char KX_TouchSensor::GetProperty_doc[] =
"\tReturns the property or material to collide with. Use\n"
"\tgetTouchMaterial() to find out whether this sensor\n"
"\tlooks for properties or materials.";
PyObject* KX_TouchSensor::PyGetProperty(PyObject* self,
PyObject* args,
PyObject* kwds) {
PyObject* KX_TouchSensor::PyGetProperty(PyObject* self) {
return PyString_FromString(m_touchedpropname);
}
const char KX_TouchSensor::GetHitObject_doc[] =
"getHitObject()\n"
;
PyObject* KX_TouchSensor::PyGetHitObject(PyObject* self,
PyObject* args,
PyObject* kwds)
PyObject* KX_TouchSensor::PyGetHitObject(PyObject* self)
{
ShowDeprecationWarning("getHitObject()", "the objectHit property");
/* to do: do Py_IncRef if the object is already known in Python */
/* otherwise, this leaks memory */
if (m_hitObject)
@@ -344,13 +371,11 @@ const char KX_TouchSensor::GetHitObjectList_doc[] =
"getHitObjectList()\n"
"\tReturn a list of the objects this object collided with,\n"
"\tbut only those matching the property/material condition.\n";
PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self,
PyObject* args,
PyObject* kwds)
PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self)
{
ShowDeprecationWarning("getHitObjectList()", "the objectHitList property");
/* to do: do Py_IncRef if the object is already known in Python */
/* otherwise, this leaks memory */
/* otherwise, this leaks memory */ /* Edit, this seems ok and not to leak memory - Campbell */
return m_colliders->AddRef();
}
@@ -359,24 +384,25 @@ const char KX_TouchSensor::GetTouchMaterial_doc[] =
"getTouchMaterial()\n"
"\tReturns KX_TRUE if this sensor looks for a specific material,\n"
"\tKX_FALSE if it looks for a specific property.\n" ;
PyObject* KX_TouchSensor::PyGetTouchMaterial(PyObject* self,
PyObject* args,
PyObject* kwds)
PyObject* KX_TouchSensor::PyGetTouchMaterial(PyObject* self)
{
ShowDeprecationWarning("getTouchMaterial()", "the materialCheck property");
return PyInt_FromLong(m_bFindMaterial);
}
/* 6. setTouchMaterial */
#if 0
const char KX_TouchSensor::SetTouchMaterial_doc[] =
"setTouchMaterial(flag)\n"
"\t- flag: KX_TRUE or KX_FALSE.\n"
"\tSet flag to KX_TRUE to switch on positive pulse mode,\n"
"\tKX_FALSE to switch off positive pulse mode.\n" ;
PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject* args, PyObject* kwds)
PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject *value)
{
int pulseArg = 0;
int pulseArg = PyInt_AsLong(value);
if(!PyArg_ParseTuple(args, "i", &pulseArg)) {
if(pulseArg ==-1 && PyErr_Occurred()) {
PyErr_SetString(PyExc_ValueError, "expected a bool");
return NULL;
}
@@ -384,6 +410,6 @@ PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject* args, PyO
Py_RETURN_NONE;
}
#endif
/* eof */

View File

@@ -121,19 +121,22 @@ public:
/* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr);
virtual int _setattr(const char *attr, PyObject *value);
/* 1. setProperty */
KX_PYMETHOD_DOC(KX_TouchSensor,SetProperty);
KX_PYMETHOD_DOC_O(KX_TouchSensor,SetProperty);
/* 2. getProperty */
KX_PYMETHOD_DOC(KX_TouchSensor,GetProperty);
KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetProperty);
/* 3. getHitObject */
KX_PYMETHOD_DOC(KX_TouchSensor,GetHitObject);
KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetHitObject);
/* 4. getHitObject */
KX_PYMETHOD_DOC(KX_TouchSensor,GetHitObjectList);
KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetHitObjectList);
/* 5. getTouchMaterial */
KX_PYMETHOD_DOC(KX_TouchSensor,GetTouchMaterial);
KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetTouchMaterial);
#if 0
/* 6. setTouchMaterial */
KX_PYMETHOD_DOC(KX_TouchSensor,SetTouchMaterial);
KX_PYMETHOD_DOC_O(KX_TouchSensor,SetTouchMaterial);
#endif
};

View File

@@ -1,13 +1,26 @@
# $Id$
# Documentation for KX_TouchSensor
from SCA_ISensor import *
from KX_GameObject import *
class KX_TouchSensor(SCA_ISensor):
"""
Touch sensor detects collisions between objects.
@ivar propertyName: The name of the property or material this sensor detects (depending on the materialCheck property).
@type propertyName: string
@ivar materialCheck: when enabled this sensor checks for object materials rather then properties.
@type materialCheck: bool
@ivar pulseCollisions: The last collided object.
@type pulseCollisions: bool
@ivar objectHit: The last collided object. (Read Only)
@type objectHit: L{KX_GameObject} or None
@ivar objectHitList: A list of colliding objects. (Read Only)
@type objectHitList: list
"""
def setProperty(name):
"""
DEPRECATED: use the propertyName property
Set the property or material to collide with. Use
setTouchMaterial() to switch between properties and
materials.
@@ -15,22 +28,25 @@ class KX_TouchSensor(SCA_ISensor):
"""
def getProperty():
"""
DEPRECATED: use the propertyName property
Returns the property or material to collide with. Use
getTouchMaterial() to find out whether this sensor
looks for properties or materials.
looks for properties or materials. (B{deprecated})
@rtype: string
"""
def getHitObject():
"""
Returns the last object hit by this touch sensor.
DEPRECATED: use the objectHit property
Returns the last object hit by this touch sensor. (B{deprecated})
@rtype: L{KX_GameObject}
"""
def getHitObjectList():
"""
Returns a list of all objects hit in the last frame.
DEPRECATED: use the objectHitList property
Returns a list of all objects hit in the last frame. (B{deprecated})
Only objects that have the requisite material/property are listed.
@@ -38,13 +54,7 @@ class KX_TouchSensor(SCA_ISensor):
"""
def getTouchMaterial():
"""
DEPRECATED: use the materialCheck property
Returns KX_TRUE if this sensor looks for a specific material,
KX_FALSE if it looks for a specific property.
"""
def setTouchMaterial(flag):
"""
Set flag to KX_TRUE to switch on positive pulse mode,
KX_FALSE to switch off positive pulse mode.
@type flag: KX_TRUE or KX_FALSE.
KX_FALSE if it looks for a specific property. (B{deprecated})
"""

View File

@@ -20,10 +20,9 @@ class SCA_DelaySensor(SCA_ISensor):
@type delay: integer.
@ivar duration: length of the ON period in number of frame after the initial OFF period.
If duration is greater than 0, a negative trigger is sent at the end of the ON pulse.
@type duration: integer
@ivar repeat: 1 if the OFF-ON cycle should be repeated indefinately, 0 if it should run once.
@type repeat: integer
@type duration: integer
@ivar repeat: 1 if the OFF-ON cycle should be repeated indefinately, 0 if it should run once.
@type repeat: integer
"""
def setDelay(delay):
"""