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:
authorBenoit Bolsee <benoit.bolsee@online.be>2009-03-28 00:54:16 +0300
committerBenoit Bolsee <benoit.bolsee@online.be>2009-03-28 00:54:16 +0300
commit059c2a10c4df53a7cd96689e8a60be2afd4b4d46 (patch)
treee10a8b1b1327afdd631a51010c74fd630e431b99 /source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
parente392eb4d9c9eb98730a841cb4317835122d69287 (diff)
BGE API cleanup: AddObject, DeleteObject and Scene actuator added.
Diffstat (limited to 'source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp')
-rw-r--r--source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp110
1 files changed, 74 insertions, 36 deletions
diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
index 68b704f4889..7c4f60a7f0a 100644
--- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
+++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
@@ -38,7 +38,7 @@
#include "SCA_IScene.h"
#include "KX_GameObject.h"
#include "KX_IPhysicsController.h"
-
+#include "blendef.h"
#include "PyObjectPlus.h"
#ifdef HAVE_CONFIG_H
@@ -53,9 +53,9 @@ KX_SCA_AddObjectActuator::KX_SCA_AddObjectActuator(SCA_IObject *gameobj,
SCA_IObject *original,
int time,
SCA_IScene* scene,
- const MT_Vector3& linvel,
+ const float *linvel,
bool linv_local,
- const MT_Vector3& angvel,
+ const float *angvel,
bool angv_local,
PyTypeObject* T)
:
@@ -63,12 +63,16 @@ KX_SCA_AddObjectActuator::KX_SCA_AddObjectActuator(SCA_IObject *gameobj,
m_OriginalObject(original),
m_scene(scene),
- m_linear_velocity(linvel),
m_localLinvFlag(linv_local),
-
- m_angular_velocity(angvel),
m_localAngvFlag(angv_local)
{
+ m_linear_velocity[0] = linvel[0];
+ m_linear_velocity[1] = linvel[1];
+ m_linear_velocity[2] = linvel[2];
+ m_angular_velocity[0] = angvel[0];
+ m_angular_velocity[1] = angvel[1];
+ m_angular_velocity[2] = angvel[2];
+
if (m_OriginalObject)
m_OriginalObject->RegisterActuator(this);
@@ -188,6 +192,7 @@ PyParentObject KX_SCA_AddObjectActuator::Parents[] = {
NULL
};
PyMethodDef KX_SCA_AddObjectActuator::Methods[] = {
+ // ---> deprecated
{"setTime", (PyCFunction) KX_SCA_AddObjectActuator::sPySetTime, METH_O, (PY_METHODCHAR)SetTime_doc},
{"getTime", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetTime, METH_NOARGS, (PY_METHODCHAR)GetTime_doc},
{"getLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLinearVelocity, METH_NOARGS, (PY_METHODCHAR)GetLinearVelocity_doc},
@@ -196,8 +201,6 @@ PyMethodDef KX_SCA_AddObjectActuator::Methods[] = {
{"setAngularVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPySetAngularVelocity, METH_VARARGS, (PY_METHODCHAR)SetAngularVelocity_doc},
{"getLastCreatedObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLastCreatedObject, METH_NOARGS,"getLastCreatedObject() : get the object handle to the last created object\n"},
{"instantAddObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyInstantAddObject, METH_NOARGS,"instantAddObject() : immediately add object without delay\n"},
-
- // ---> deprecated
{"setObject", (PyCFunction) KX_SCA_AddObjectActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc},
{"getObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc},
@@ -205,41 +208,65 @@ PyMethodDef KX_SCA_AddObjectActuator::Methods[] = {
};
PyAttributeDef KX_SCA_AddObjectActuator::Attributes[] = {
+ KX_PYATTRIBUTE_RW_FUNCTION("object",KX_SCA_AddObjectActuator,pyattr_get_object,pyattr_set_object),
+ KX_PYATTRIBUTE_RO_FUNCTION("objectLastCreated",KX_SCA_AddObjectActuator,pyattr_get_objectLastCreated),
+ KX_PYATTRIBUTE_INT_RW("time",0,2000,true,KX_SCA_AddObjectActuator,m_timeProp),
+ KX_PYATTRIBUTE_FLOAT_ARRAY_RW("linearVelocity",-MAXFLOAT,MAXFLOAT,KX_SCA_AddObjectActuator,m_linear_velocity,3),
+ KX_PYATTRIBUTE_FLOAT_ARRAY_RW("angularVelocity",-MAXFLOAT,MAXFLOAT,KX_SCA_AddObjectActuator,m_angular_velocity,3),
{ NULL } //Sentinel
};
-PyObject* KX_SCA_AddObjectActuator::_getattr(const char *attr)
+PyObject* KX_SCA_AddObjectActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
- if (!strcmp(attr, "object")) {
- if (!m_OriginalObject) Py_RETURN_NONE;
- else return m_OriginalObject->AddRef();
- } else if (!strcmp(attr, "objectLastCreated")) {
- if (!m_OriginalObject) Py_RETURN_NONE;
- else return m_lastCreatedObject->AddRef();
- }
-
- _getattr_up(SCA_IActuator);
+ KX_SCA_AddObjectActuator* actuator = static_cast<KX_SCA_AddObjectActuator*>(self);
+ if (!actuator->m_OriginalObject)
+ Py_RETURN_NONE;
+ else
+ return actuator->m_OriginalObject->AddRef();
}
-int KX_SCA_AddObjectActuator::_setattr(const char *attr, PyObject* value) {
-
- if (!strcmp(attr, "object")) {
- KX_GameObject *gameobj;
+int KX_SCA_AddObjectActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ KX_SCA_AddObjectActuator* actuator = static_cast<KX_SCA_AddObjectActuator*>(self);
+ KX_GameObject *gameobj;
- if (!ConvertPythonToGameObject(value, &gameobj, true))
- return 1; // ConvertPythonToGameObject sets the error
+ if (!ConvertPythonToGameObject(value, &gameobj, true))
+ return 1; // ConvertPythonToGameObject sets the error
- if (m_OriginalObject != NULL)
- m_OriginalObject->UnregisterActuator(this);
+ if (actuator->m_OriginalObject != NULL)
+ actuator->m_OriginalObject->UnregisterActuator(actuator);
- m_OriginalObject = (SCA_IObject*)gameobj;
+ actuator->m_OriginalObject = (SCA_IObject*)gameobj;
- if (m_OriginalObject)
- m_OriginalObject->RegisterActuator(this);
+ if (actuator->m_OriginalObject)
+ actuator->m_OriginalObject->RegisterActuator(actuator);
- return 0;
- }
-
+ return 0;
+}
+
+PyObject* KX_SCA_AddObjectActuator::pyattr_get_objectLastCreated(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
+{
+ KX_SCA_AddObjectActuator* actuator = static_cast<KX_SCA_AddObjectActuator*>(self);
+ if (!actuator->m_lastCreatedObject)
+ Py_RETURN_NONE;
+ else
+ return actuator->m_lastCreatedObject->AddRef();
+}
+
+
+PyObject* KX_SCA_AddObjectActuator::_getattr(const char *attr)
+{
+ PyObject* object = _getattr_self(Attributes, this, attr);
+ if (object != NULL)
+ return object;
+ _getattr_up(SCA_IActuator);
+}
+
+int KX_SCA_AddObjectActuator::_setattr(const char *attr, PyObject* value)
+{
+ int ret = _setattr_self(Attributes, this, attr, value);
+ if (ret >= 0)
+ return ret;
return SCA_IActuator::_setattr(attr, value);
}
@@ -280,6 +307,7 @@ const char KX_SCA_AddObjectActuator::SetTime_doc[] =
PyObject* KX_SCA_AddObjectActuator::PySetTime(PyObject* self, PyObject* value)
{
+ ShowDeprecationWarning("setTime()", "the time property");
int deltatime = PyInt_AsLong(value);
if (deltatime==-1 && PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, "expected an int");
@@ -296,12 +324,13 @@ PyObject* KX_SCA_AddObjectActuator::PySetTime(PyObject* self, PyObject* value)
/* 3. getTime */
const char KX_SCA_AddObjectActuator::GetTime_doc[] =
-"GetTime()\n"
+"getTime()\n"
"\tReturns the lifetime of the object that will be added.\n";
PyObject* KX_SCA_AddObjectActuator::PyGetTime(PyObject* self)
{
+ ShowDeprecationWarning("getTime()", "the time property");
return PyInt_FromLong(m_timeProp);
}
@@ -339,6 +368,7 @@ const char KX_SCA_AddObjectActuator::GetLinearVelocity_doc[] =
PyObject* KX_SCA_AddObjectActuator::PyGetLinearVelocity(PyObject* self)
{
+ ShowDeprecationWarning("getLinearVelocity()", "the linearVelocity property");
PyObject *retVal = PyList_New(3);
PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(m_linear_velocity[0]));
@@ -361,12 +391,15 @@ const char KX_SCA_AddObjectActuator::SetLinearVelocity_doc[] =
PyObject* KX_SCA_AddObjectActuator::PySetLinearVelocity(PyObject* self, PyObject* args)
{
+ ShowDeprecationWarning("setLinearVelocity()", "the linearVelocity property");
float vecArg[3];
if (!PyArg_ParseTuple(args, "fff", &vecArg[0], &vecArg[1], &vecArg[2]))
return NULL;
- m_linear_velocity.setValue(vecArg);
+ m_linear_velocity[0] = vecArg[0];
+ m_linear_velocity[1] = vecArg[1];
+ m_linear_velocity[2] = vecArg[2];
Py_RETURN_NONE;
}
@@ -378,6 +411,7 @@ const char KX_SCA_AddObjectActuator::GetAngularVelocity_doc[] =
PyObject* KX_SCA_AddObjectActuator::PyGetAngularVelocity(PyObject* self)
{
+ ShowDeprecationWarning("getAngularVelocity()", "the angularVelocity property");
PyObject *retVal = PyList_New(3);
PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(m_angular_velocity[0]));
@@ -400,12 +434,15 @@ const char KX_SCA_AddObjectActuator::SetAngularVelocity_doc[] =
PyObject* KX_SCA_AddObjectActuator::PySetAngularVelocity(PyObject* self, PyObject* args)
{
+ ShowDeprecationWarning("setAngularVelocity()", "the angularVelocity property");
float vecArg[3];
if (!PyArg_ParseTuple(args, "fff", &vecArg[0], &vecArg[1], &vecArg[2]))
return NULL;
- m_angular_velocity.setValue(vecArg);
+ m_angular_velocity[0] = vecArg[0];
+ m_angular_velocity[1] = vecArg[1];
+ m_angular_velocity[2] = vecArg[2];
Py_RETURN_NONE;
}
@@ -417,7 +454,7 @@ void KX_SCA_AddObjectActuator::InstantAddObject()
// Now it needs to be added to the current scene.
SCA_IObject* replica = m_scene->AddReplicaObject(m_OriginalObject,GetParent(),m_timeProp );
KX_GameObject * game_obj = static_cast<KX_GameObject *>(replica);
- game_obj->setLinearVelocity(m_linear_velocity,m_localLinvFlag);
+ game_obj->setLinearVelocity(m_linear_velocity ,m_localLinvFlag);
game_obj->setAngularVelocity(m_angular_velocity,m_localAngvFlag);
game_obj->ResolveCombinedVelocities(m_linear_velocity, m_angular_velocity, m_localLinvFlag, m_localAngvFlag);
@@ -453,6 +490,7 @@ const char KX_SCA_AddObjectActuator::GetLastCreatedObject_doc[] =
PyObject* KX_SCA_AddObjectActuator::PyGetLastCreatedObject(PyObject* self)
{
+ ShowDeprecationWarning("getLastCreatedObject()", "the objectLastCreated property");
SCA_IObject* result = this->GetLastCreatedObject();
// if result->GetSGNode() is NULL