Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/GameLogic/SCA_ParentActuator.cpp
- This file was moved from source/gameengine/Ketsji/KX_ParentActuator.cpp.
| Show All 22 Lines | |||||
| * | * | ||||
| * The Original Code is: all of this file. | * The Original Code is: all of this file. | ||||
| * | * | ||||
| * Contributor(s): none yet. | * Contributor(s): none yet. | ||||
| * | * | ||||
| * ***** END GPL LICENSE BLOCK ***** | * ***** END GPL LICENSE BLOCK ***** | ||||
| */ | */ | ||||
| /** \file gameengine/Ketsji/KX_ParentActuator.cpp | /** \file gameengine/GameLogic/SCA_ParentActuator.cpp | ||||
| * \ingroup ketsji | * \ingroup gamelogic | ||||
| */ | */ | ||||
| #include "KX_ParentActuator.h" | #include "SCA_ParentActuator.h" | ||||
| #include "KX_GameObject.h" | #include "KX_GameObject.h" | ||||
| #include "KX_PythonInit.h" | #include "KX_PythonInit.h" | ||||
| #include "PyObjectPlus.h" | #include "PyObjectPlus.h" | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Native functions */ | /* Native functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| KX_ParentActuator::KX_ParentActuator(SCA_IObject *gameobj, | SCA_ParentActuator::SCA_ParentActuator(SCA_IObject *gameobj, | ||||
| int mode, | int mode, | ||||
| bool addToCompound, | bool addToCompound, | ||||
| bool ghost, | bool ghost, | ||||
| SCA_IObject *ob) | SCA_IObject *ob) | ||||
| : SCA_IActuator(gameobj, KX_ACT_PARENT), | : SCA_IActuator(gameobj, SCA_ACT_PARENT), | ||||
| m_mode(mode), | m_mode(mode), | ||||
| m_addToCompound(addToCompound), | m_addToCompound(addToCompound), | ||||
| m_ghost(ghost), | m_ghost(ghost), | ||||
| m_ob(ob) | m_ob(ob) | ||||
| { | { | ||||
| if (m_ob) | if (m_ob) | ||||
| m_ob->RegisterActuator(this); | m_ob->RegisterActuator(this); | ||||
| } | } | ||||
| KX_ParentActuator::~KX_ParentActuator() | SCA_ParentActuator::~SCA_ParentActuator() | ||||
| { | { | ||||
| if (m_ob) | if (m_ob) | ||||
| m_ob->UnregisterActuator(this); | m_ob->UnregisterActuator(this); | ||||
| } | } | ||||
| CValue* KX_ParentActuator::GetReplica() | CValue* SCA_ParentActuator::GetReplica() | ||||
| { | { | ||||
| KX_ParentActuator* replica = new KX_ParentActuator(*this); | SCA_ParentActuator* replica = new SCA_ParentActuator(*this); | ||||
| // replication just copy the m_base pointer => common random generator | // replication just copy the m_base pointer => common random generator | ||||
| replica->ProcessReplica(); | replica->ProcessReplica(); | ||||
| return replica; | return replica; | ||||
| } | } | ||||
| void KX_ParentActuator::ProcessReplica() | void SCA_ParentActuator::ProcessReplica() | ||||
| { | { | ||||
| if (m_ob) | if (m_ob) | ||||
| m_ob->RegisterActuator(this); | m_ob->RegisterActuator(this); | ||||
| SCA_IActuator::ProcessReplica(); | SCA_IActuator::ProcessReplica(); | ||||
| } | } | ||||
| bool KX_ParentActuator::UnlinkObject(SCA_IObject* clientobj) | bool SCA_ParentActuator::UnlinkObject(SCA_IObject* clientobj) | ||||
| { | { | ||||
| if (clientobj == m_ob) | if (clientobj == m_ob) | ||||
| { | { | ||||
| // this object is being deleted, we cannot continue to track it. | // this object is being deleted, we cannot continue to track it. | ||||
| m_ob = NULL; | m_ob = NULL; | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| void KX_ParentActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map) | void SCA_ParentActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map) | ||||
| { | { | ||||
| void **h_obj = (*obj_map)[m_ob]; | void **h_obj = (*obj_map)[m_ob]; | ||||
| if (h_obj) { | if (h_obj) { | ||||
| if (m_ob) | if (m_ob) | ||||
| m_ob->UnregisterActuator(this); | m_ob->UnregisterActuator(this); | ||||
| m_ob = (SCA_IObject*)(*h_obj); | m_ob = (SCA_IObject*)(*h_obj); | ||||
| m_ob->RegisterActuator(this); | m_ob->RegisterActuator(this); | ||||
| } | } | ||||
| } | } | ||||
| bool KX_ParentActuator::Update() | bool SCA_ParentActuator::Update() | ||||
| { | { | ||||
| bool bNegativeEvent = IsNegativeEvent(); | bool bNegativeEvent = IsNegativeEvent(); | ||||
| RemoveAllEvents(); | RemoveAllEvents(); | ||||
| if (bNegativeEvent) | if (bNegativeEvent) | ||||
| return false; // do nothing on negative events | return false; // do nothing on negative events | ||||
| KX_GameObject *obj = (KX_GameObject*) GetParent(); | KX_GameObject *obj = (KX_GameObject*) GetParent(); | ||||
| Show All 13 Lines | |||||
| #ifdef WITH_PYTHON | #ifdef WITH_PYTHON | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Python functions */ | /* Python functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Integration hooks ------------------------------------------------------- */ | /* Integration hooks ------------------------------------------------------- */ | ||||
| PyTypeObject KX_ParentActuator::Type = { | PyTypeObject SCA_ParentActuator::Type = { | ||||
| PyVarObject_HEAD_INIT(NULL, 0) | PyVarObject_HEAD_INIT(NULL, 0) | ||||
| "KX_ParentActuator", | "SCA_ParentActuator", | ||||
| sizeof(PyObjectPlus_Proxy), | sizeof(PyObjectPlus_Proxy), | ||||
| 0, | 0, | ||||
| py_base_dealloc, | py_base_dealloc, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| py_base_repr, | py_base_repr, | ||||
| 0,0,0,0,0,0,0,0,0, | 0,0,0,0,0,0,0,0,0, | ||||
| Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | ||||
| 0,0,0,0,0,0,0, | 0,0,0,0,0,0,0, | ||||
| Methods, | Methods, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| &SCA_IActuator::Type, | &SCA_IActuator::Type, | ||||
| 0,0,0,0,0,0, | 0,0,0,0,0,0, | ||||
| py_base_new | py_base_new | ||||
| }; | }; | ||||
| PyMethodDef KX_ParentActuator::Methods[] = { | PyMethodDef SCA_ParentActuator::Methods[] = { | ||||
| {NULL,NULL} //Sentinel | {NULL,NULL} //Sentinel | ||||
| }; | }; | ||||
| PyAttributeDef KX_ParentActuator::Attributes[] = { | PyAttributeDef SCA_ParentActuator::Attributes[] = { | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("object", KX_ParentActuator, pyattr_get_object, pyattr_set_object), | KX_PYATTRIBUTE_RW_FUNCTION("object", SCA_ParentActuator, pyattr_get_object, pyattr_set_object), | ||||
| KX_PYATTRIBUTE_INT_RW("mode", KX_PARENT_NODEF+1, KX_PARENT_MAX-1, true, KX_ParentActuator, m_mode), | KX_PYATTRIBUTE_INT_RW("mode", KX_PARENT_NODEF+1, KX_PARENT_MAX-1, true, SCA_ParentActuator, m_mode), | ||||
| KX_PYATTRIBUTE_BOOL_RW("compound", KX_ParentActuator, m_addToCompound), | KX_PYATTRIBUTE_BOOL_RW("compound", SCA_ParentActuator, m_addToCompound), | ||||
| KX_PYATTRIBUTE_BOOL_RW("ghost", KX_ParentActuator, m_ghost), | KX_PYATTRIBUTE_BOOL_RW("ghost", SCA_ParentActuator, m_ghost), | ||||
| { NULL } //Sentinel | { NULL } //Sentinel | ||||
| }; | }; | ||||
| PyObject *KX_ParentActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | PyObject *SCA_ParentActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_ParentActuator* actuator = static_cast<KX_ParentActuator*>(self); | SCA_ParentActuator* actuator = static_cast<SCA_ParentActuator*>(self); | ||||
| if (!actuator->m_ob) | if (!actuator->m_ob) | ||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| else | else | ||||
| return actuator->m_ob->GetProxy(); | return actuator->m_ob->GetProxy(); | ||||
| } | } | ||||
| int KX_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | int SCA_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| { | { | ||||
| KX_ParentActuator* actuator = static_cast<KX_ParentActuator*>(self); | SCA_ParentActuator* actuator = static_cast<SCA_ParentActuator*>(self); | ||||
| KX_GameObject *gameobj; | KX_GameObject *gameobj; | ||||
| if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_ParentActuator")) | if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: SCA_ParentActuator")) | ||||
| return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error | return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error | ||||
| if (actuator->m_ob != NULL) | if (actuator->m_ob != NULL) | ||||
| actuator->m_ob->UnregisterActuator(actuator); | actuator->m_ob->UnregisterActuator(actuator); | ||||
| actuator->m_ob = (SCA_IObject*) gameobj; | actuator->m_ob = (SCA_IObject*) gameobj; | ||||
| if (actuator->m_ob) | if (actuator->m_ob) | ||||
| actuator->m_ob->RegisterActuator(actuator); | actuator->m_ob->RegisterActuator(actuator); | ||||
| return PY_SET_ATTR_SUCCESS; | return PY_SET_ATTR_SUCCESS; | ||||
| } | } | ||||
| #endif // WITH_PYTHON | #endif // WITH_PYTHON | ||||
| /* eof */ | /* eof */ | ||||