BGE Python API cleanup - no functionality changes
[blender.git] / source / gameengine / Ketsji / KX_TouchSensor.cpp
index 49d3d20dc3d43d90e4803a3ec34eb56e1cda88f4..79da498474016b50b39c5ebab00821335f8bf2b2 100644 (file)
@@ -245,9 +245,9 @@ PyTypeObject KX_TouchSensor::Type = {
        PyObject_HEAD_INIT(NULL)
        0,
        "KX_TouchSensor",
-       sizeof(KX_TouchSensor),
+       sizeof(PyObjectPlus_Proxy),
        0,
-       PyDestructor,
+       py_base_dealloc,
        0,
        0,
        0,
@@ -286,36 +286,19 @@ PyAttributeDef KX_TouchSensor::Attributes[] = {
        KX_PYATTRIBUTE_STRING_RW("property",0,100,false,KX_TouchSensor,m_touchedpropname),
        KX_PYATTRIBUTE_BOOL_RW("useMaterial",KX_TouchSensor,m_bFindMaterial),
        KX_PYATTRIBUTE_BOOL_RW("pulseCollisions",KX_TouchSensor,m_bTouchPulse),
-       KX_PYATTRIBUTE_DUMMY("objectHit"),
-       KX_PYATTRIBUTE_DUMMY("objectHitList"),
+       KX_PYATTRIBUTE_RO_FUNCTION("objectHit", KX_TouchSensor, pyattr_get_object_hit),
+       KX_PYATTRIBUTE_RO_FUNCTION("objectHitList", KX_TouchSensor, pyattr_get_object_hit_list),
        { NULL }        //Sentinel
 };
 
 PyObject* KX_TouchSensor::py_getattro(PyObject *attr)
-{      
-       PyObject* object= py_getattro_self(Attributes, this, attr);
-       if (object != NULL)
-               return object;
-       
-       char *attr_str= PyString_AsString(attr);
-       if (!strcmp(attr_str, "objectHit")) {
-               if (m_hitObject)        return m_hitObject->AddRef();
-               else                            Py_RETURN_NONE;
-       }
-       if (!strcmp(attr_str, "objectHitList")) {
-               return m_colliders->AddRef();
-       }
-       
+{
        py_getattro_up(SCA_ISensor);
 }
 
 int KX_TouchSensor::py_setattro(PyObject *attr, PyObject *value)
 {
-       int ret = py_setattro_self(Attributes, this, attr, value);
-       if (ret >= 0)
-               return ret;
-       
-       return SCA_ISensor::py_setattro(attr, value);
+       py_setattro_up(SCA_ISensor);
 }
 
 /* Python API */
@@ -359,7 +342,7 @@ PyObject* KX_TouchSensor::PyGetHitObject(PyObject* self)
        /* otherwise, this leaks memory */
        if (m_hitObject)
        {
-               return m_hitObject->AddRef();
+               return m_hitObject->GetProxy();
        }
        Py_RETURN_NONE;
 }
@@ -373,7 +356,7 @@ 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 */ /* Edit, this seems ok and not to leak memory - Campbell */
-       return m_colliders->AddRef();
+       return m_colliders->GetProxy();
 }
 
 /*getTouchMaterial and setTouchMaterial were never added to the api,
@@ -412,4 +395,21 @@ PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject *value)
 }
 #endif
 
+PyObject* KX_TouchSensor::pyattr_get_object_hit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+       KX_TouchSensor* self= static_cast<KX_TouchSensor*>(self_v);
+       
+       if (self->m_hitObject)
+               return self->m_hitObject->GetProxy();
+       else
+               Py_RETURN_NONE;
+}
+
+PyObject* KX_TouchSensor::pyattr_get_object_hit_list(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+       KX_TouchSensor* self= static_cast<KX_TouchSensor*>(self_v);
+       return self->m_colliders->GetProxy();
+}
+
+
 /* eof */