Changeset View
Standalone View
source/gameengine/Ketsji/KX_Scene.cpp
| Context not available. | |||||
| #include "BL_ModifierDeformer.h" | #include "BL_ModifierDeformer.h" | ||||
| #include "BL_ShapeDeformer.h" | #include "BL_ShapeDeformer.h" | ||||
| #include "BL_DeformableGameObject.h" | #include "BL_DeformableGameObject.h" | ||||
| #include "BL_BlenderDataConversion.h" | |||||
| #include "KX_ObstacleSimulation.h" | #include "KX_ObstacleSimulation.h" | ||||
| #ifdef WITH_BULLET | #ifdef WITH_BULLET | ||||
| Context not available. | |||||
| newobj->ResetState(); | newobj->ResetState(); | ||||
| } | } | ||||
| void KX_Scene::ReplicateConstraints(KX_GameObject* replica) | |||||
moguri: Should the scene be handling this? Seems like something we should delegate to the physics… | |||||
hg1AuthorUnsubmitted Not Done Inline ActionsMoving ReplicateConstraints() into the physics controller is not so easy. To get the target object(s) I need to loop trough m_logicHierarchicalGameObjects. hg1: Moving ReplicateConstraints() into the physics controller is not so easy. To get the target… | |||||
| { | |||||
| if (replica->GetConstraints().size() > 0) { | |||||
| /* make sure to return, because createConstraint() would crash */ | |||||
| if (!replica->GetPhysicsController()) { | |||||
| return; | |||||
| } | |||||
| replica->ClearConstraintsData(); | |||||
| vector<bRigidBodyJointConstraint*> constraints = replica->GetConstraints(); | |||||
| vector<bRigidBodyJointConstraint*>::iterator consit; | |||||
| /* object could have some constraints, iterate over all of theme to ensure | |||||
| * that every constraint is recreated */ | |||||
| for (consit = constraints.begin(); consit != constraints.end(); ++consit) { | |||||
| /* try to find the constraint targets in the list of group objects */ | |||||
| bRigidBodyJointConstraint* dat = (*consit); | |||||
| vector<KX_GameObject*>::iterator memit; | |||||
| for (memit = m_logicHierarchicalGameObjects.begin(); | |||||
| memit != m_logicHierarchicalGameObjects.end(); ++memit) | |||||
| { | |||||
| KX_GameObject *member = (*memit); | |||||
| /* if the group member is the actual target for the constraint */ | |||||
| if (dat->tar->id.name+2 == member->GetName() && member->GetPhysicsController()) { | |||||
| PHY_IPhysicsController *physctr_repl = replica->GetPhysicsController(); | |||||
| PHY_IPhysicsController *physctr_memb = member->GetPhysicsController(); | |||||
| setup_constraint4object(replica, this, dat, physctr_repl, physctr_memb); | |||||
moguriUnsubmitted Not Done Inline ActionsAlthough, getting access to BL_BlenderDataConversion::setup_constraint4object() might be difficult from the physics controller (in relation to the comment on line 703). Perhaps this function should be moved from BL_BlenderDataConversion into the physics environment? moguri: Although, getting access to BL_BlenderDataConversion::setup_constraint4object() might be… | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| void KX_Scene::RemoveConstraints(CValue* replica) | |||||
| { | |||||
| KX_GameObject* newobj = (KX_GameObject*) replica; | |||||
| if (newobj->GetConstraintsData().size() > 0) { | |||||
| if (m_physicsEnvironment) { | |||||
| vector<ConstraintData*> constList = newobj->GetConstraintsData(); | |||||
| for (vector<ConstraintData*>::iterator constID = constList.begin(); | |||||
| constID != constList.end(); ++constID) | |||||
| { | |||||
| m_physicsEnvironment->RemoveConstraint((*constID)->m_constraintId); | |||||
| delete (*constID); | |||||
| } | |||||
| newobj->ClearConstraintsData(); | |||||
| } | |||||
| } | |||||
| } | |||||
| void KX_Scene::DupliGroupRecurse(CValue* obj, int level) | void KX_Scene::DupliGroupRecurse(CValue* obj, int level) | ||||
| { | { | ||||
| KX_GameObject* groupobj = (KX_GameObject*) obj; | KX_GameObject* groupobj = (KX_GameObject*) obj; | ||||
Not Done Inline ActionsStoring (*git)->GetPhysicsController() in a temporary variable may increase readability. sybren: Storing `(*git)->GetPhysicsController()` in a temporary variable may increase readability. | |||||
| Context not available. | |||||
| duplilist.push_back((*git)); | duplilist.push_back((*git)); | ||||
| } | } | ||||
| /* now replicate all constraints */ | |||||
| for (git = m_logicHierarchicalGameObjects.begin(); !(git == m_logicHierarchicalGameObjects.end()); ++git) | |||||
| { | |||||
| ReplicateConstraints((*git)); | |||||
| (*git)->ClearConstraints(); | |||||
| } | |||||
| for (git = duplilist.begin(); !(git == duplilist.end()); ++git) | for (git = duplilist.begin(); !(git == duplilist.end()); ++git) | ||||
| { | { | ||||
| DupliGroupRecurse((*git), level+1); | DupliGroupRecurse((*git), level+1); | ||||
| Context not available. | |||||
| void KX_Scene::DelayedRemoveObject(class CValue* gameobj) | void KX_Scene::DelayedRemoveObject(class CValue* gameobj) | ||||
| { | { | ||||
| //KX_GameObject* newobj = (KX_GameObject*) gameobj; | /* the constraints must be removed before the game object is removed */ | ||||
| RemoveConstraints(gameobj); | |||||
moguriUnsubmitted Not Done Inline ActionsShouldn't this be handled in NewRemoveObject? I would think we could get a crash if something tries to reference constraints before the rest of the object is deleted at the end of the frame. moguri: Shouldn't this be handled in NewRemoveObject? I would think we could get a crash if something… | |||||
hg1AuthorUnsubmitted Not Done Inline ActionsIn a earlier version had done this. But this was producing some kind of bug. hg1: In a earlier version had done this. But this was producing some kind of bug.
I can't remember… | |||||
| if (!m_euthanasyobjects->SearchValue(gameobj)) | if (!m_euthanasyobjects->SearchValue(gameobj)) | ||||
| { | { | ||||
| m_euthanasyobjects->Add(gameobj->AddRef()); | m_euthanasyobjects->Add(gameobj->AddRef()); | ||||
| } | } | ||||
| } | } | ||||
| int KX_Scene::NewRemoveObject(class CValue* gameobj) | int KX_Scene::NewRemoveObject(class CValue* gameobj) | ||||
| { | { | ||||
| int ret; | int ret; | ||||
| Context not available. | |||||
Should the scene be handling this? Seems like something we should delegate to the physics controller.