Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-04-12 13:56:30 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-12 13:56:30 +0400
commit5b306b7541bfc60342b70bcc55456d5c453a294a (patch)
tree267232e135a123f3f75051a9732a9ab35370d769 /source/gameengine/Ketsji
parent55d2b184ec1b2c1adfe182ead937cedae1a8208d (diff)
BGE Python API
added defines PY_SET_ATTR_FAIL, PY_SET_ATTR_MISSING and PY_SET_ATTR_SUCCESS This is useful when objects that have user defined attributes (GameObject and Scene) When calling setattr on the parent, a return value of PY_SET_ATTR_FAIL means the attribute exists but failed to be set, so don't set the custom attribute.
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r--source/gameengine/Ketsji/KX_ConstraintWrapper.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_Light.cpp22
-rw-r--r--source/gameengine/Ketsji/KX_Scene.h8
-rw-r--r--source/gameengine/Ketsji/KX_VehicleWrapper.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_VertexProxy.cpp36
5 files changed, 35 insertions, 35 deletions
diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
index edd6e991e9f..6f4d970c568 100644
--- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
+++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
@@ -101,7 +101,7 @@ PyObject* KX_ConstraintWrapper::py_getattro(PyObject *attr)
int KX_ConstraintWrapper::py_setattro(PyObject *attr,PyObject* pyobj)
{
int result = 1;
-
+ /* what the heck is this supposed to do?, needs attention */
if (PyList_Check(pyobj))
{
result = 0;
diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp
index f996f86d751..059345ea8de 100644
--- a/source/gameengine/Ketsji/KX_Light.cpp
+++ b/source/gameengine/Ketsji/KX_Light.cpp
@@ -225,14 +225,14 @@ int KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue)
if (!strcmp(attr_str, "layer"))
{
m_lightobj.m_layer = value;
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
if (!strcmp(attr_str, "type"))
{
if (value >= RAS_LightObject::LIGHT_SPOT && value <= RAS_LightObject::LIGHT_NORMAL)
m_lightobj.m_type = (RAS_LightObject::LightType) value;
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
}
@@ -242,37 +242,37 @@ int KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue)
if (!strcmp(attr_str, "energy"))
{
m_lightobj.m_energy = value;
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
if (!strcmp(attr_str, "distance"))
{
m_lightobj.m_distance = value;
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
if (!strcmp(attr_str, "lin_attenuation"))
{
m_lightobj.m_att1 = value;
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
if (!strcmp(attr_str, "quad_attenuation"))
{
m_lightobj.m_att2 = value;
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
if (!strcmp(attr_str, "spotsize"))
{
m_lightobj.m_spotsize = value;
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
if (!strcmp(attr_str, "spotblend"))
{
m_lightobj.m_spotblend = value;
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
}
@@ -286,16 +286,16 @@ int KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue)
m_lightobj.m_red = color[0];
m_lightobj.m_green = color[1];
m_lightobj.m_blue = color[2];
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
- return 1;
+ return PY_SET_ATTR_FAIL;
}
}
if (!strcmp(attr_str, "SPOT") || !strcmp(attr_str, "SUN") || !strcmp(attr_str, "NORMAL"))
{
PyErr_Format(PyExc_RuntimeError, "Attribute %s is read only.", attr_str);
- return 1;
+ return PY_SET_ATTR_FAIL;
}
return KX_GameObject::py_setattro(attr, pyvalue);
diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h
index 1bdfbd45d20..b70c6d3e8d3 100644
--- a/source/gameengine/Ketsji/KX_Scene.h
+++ b/source/gameengine/Ketsji/KX_Scene.h
@@ -597,13 +597,13 @@ public:
int ret= ((PyObjectPlus*) self)->py_setattro(attr, value);
- if (ret) {
- if (!PyDict_SetItem(((KX_Scene *) self)->m_attrlist, attr, value)) {
+ if (ret==PY_SET_ATTR_MISSING) {
+ if (PyDict_SetItem(((KX_Scene *) self)->m_attrlist, attr, value)==0) {
PyErr_Clear();
- ret= 0;
+ ret= PY_SET_ATTR_SUCCESS;
}
else {
- ret= -1;
+ ret= PY_SET_ATTR_FAIL;
}
}
diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
index 315b60922b7..98f5a1ea87d 100644
--- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
+++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
@@ -331,7 +331,7 @@ PyObject* KX_VehicleWrapper::py_getattro(PyObject *attr)
int KX_VehicleWrapper::py_setattro(PyObject *attr,PyObject* pyobj)
{
-
+ /* TODO - strange setattr, needs updating */
PyTypeObject* type = pyobj->ob_type;
int result = 1;
diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp
index bb12f405332..6a160dff7b7 100644
--- a/source/gameengine/Ketsji/KX_VertexProxy.cpp
+++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp
@@ -171,9 +171,9 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue)
{
m_vertex->SetXYZ(vec);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
- return 1;
+ return PY_SET_ATTR_FAIL;
}
if (!strcmp(attr_str, "UV"))
@@ -183,9 +183,9 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue)
{
m_vertex->SetUV(vec);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
- return 1;
+ return PY_SET_ATTR_FAIL;
}
if (!strcmp(attr_str, "color") || !strcmp(attr_str, "colour"))
@@ -195,9 +195,9 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue)
{
m_vertex->SetRGBA(vec);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
- return 1;
+ return PY_SET_ATTR_FAIL;
}
if (!strcmp(attr_str, "normal"))
@@ -207,9 +207,9 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue)
{
m_vertex->SetNormal(vec);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
- return 1;
+ return PY_SET_ATTR_FAIL;
}
}
@@ -223,7 +223,7 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue)
pos.x() = val;
m_vertex->SetXYZ(pos);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
if (!strcmp(attr_str, "y"))
@@ -231,7 +231,7 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue)
pos.y() = val;
m_vertex->SetXYZ(pos);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
if (!strcmp(attr_str, "z"))
@@ -239,7 +239,7 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue)
pos.z() = val;
m_vertex->SetXYZ(pos);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
// uv
@@ -249,7 +249,7 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue)
uv[0] = val;
m_vertex->SetUV(uv);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
if (!strcmp(attr_str, "v"))
@@ -257,7 +257,7 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue)
uv[1] = val;
m_vertex->SetUV(uv);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
// uv
@@ -275,7 +275,7 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue)
uv[1] = val;
m_vertex->SetUV2(uv);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
// col
@@ -287,28 +287,28 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue)
cp[0] = (unsigned char) val;
m_vertex->SetRGBA(icol);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
if (!strcmp(attr_str, "g"))
{
cp[1] = (unsigned char) val;
m_vertex->SetRGBA(icol);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
if (!strcmp(attr_str, "b"))
{
cp[2] = (unsigned char) val;
m_vertex->SetRGBA(icol);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
if (!strcmp(attr_str, "a"))
{
cp[3] = (unsigned char) val;
m_vertex->SetRGBA(icol);
m_mesh->SetMeshModified(true);
- return 0;
+ return PY_SET_ATTR_SUCCESS;
}
}