| Code: |
|
KX_PYMETHOD_DOC_VARARGS(KX_SCA_AddObjectActuator,InstantAddObject); |
| Code: |
|
PyMethodDef KX_SCA_AddObjectActuator::Methods[] = { {"instantAddObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyInstantAddObject, METH_VARARGS,"instantAddObject(name) : immediately add object without delay\n"}, {NULL,NULL} //Sentinel }; PyObject* KX_SCA_AddObjectActuator::PyInstantAddObject(PyObject* args) { PyObject* pystring; char* name = 0; if (!PyArg_ParseTuple(args, "s", &name)) InstantAddObject(); InstantAddObject(name); Py_RETURN_NONE; } void KX_SCA_AddObjectActuator::InstantAddObject(const char* name) { if (m_OriginalObject) { // Add an identical object, with properties inherited from the original object // 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->setAngularVelocity(m_angular_velocity,m_localAngvFlag); game_obj->ResolveCombinedVelocities(m_linear_velocity, m_angular_velocity, m_localLinvFlag, m_localAngvFlag); // If we have a new name, assign it. if(name != 0) { game_obj->SetName(name); } // keep a copy of the last object, to allow python scripters to change it if (m_lastCreatedObject) { //Let's not keep a reference to the object: it's bad, if the object is deleted //this will force to keep a "zombie" in the game for no good reason. //m_scene->DelayedReleaseObject(m_lastCreatedObject); //m_lastCreatedObject->Release(); //Instead we use the registration mechanism m_lastCreatedObject->UnregisterActuator(this); m_lastCreatedObject = NULL; } m_lastCreatedObject = replica; // no reference //m_lastCreatedObject->AddRef(); // but registration m_lastCreatedObject->RegisterActuator(this); // finished using replica? then release it replica->Release(); } } |
| stiv wrote: |
| If this is generally useful, you might want to create a patch and add it to the patch tracker:
http://wiki.blender.org/index.php/Dev:Doc/Process/Patches |