From 4b4259ca1af5a852c1a7e1e6eb8945f6f821d324 Mon Sep 17 00:00:00 2001 From: Porteries Tristan Date: Sun, 17 Dec 2017 14:03:08 +0100 Subject: [PATCH] UPBGE: Move ReplicateConstrains function in KX_GameObject. Always try to not see ketsji from other parts. --- source/gameengine/Ketsji/KX_GameObject.cpp | 18 ++++++++++++++ source/gameengine/Ketsji/KX_GameObject.h | 3 +++ source/gameengine/Ketsji/KX_Scene.cpp | 11 ++++----- .../Physics/Bullet/CcdPhysicsController.cpp | 24 ------------------- .../Physics/Bullet/CcdPhysicsController.h | 3 --- .../Physics/Common/PHY_IPhysicsController.h | 3 --- 6 files changed, 25 insertions(+), 37 deletions(-) diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 43acae52d575..bc5d3c7ae0c0 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -278,6 +278,24 @@ const std::vector& KX_GameObject::GetConstraints() return m_convertInfo->m_constraints; } +void KX_GameObject::ReplicateConstraints(PHY_IPhysicsEnvironment *physEnv, const std::vector& constobj) +{ + if (!m_physicsController || m_convertInfo->m_constraints.empty()) { + return; + } + + // Object could have some constraints, iterate over all of theme to ensure that every constraint is recreated. + for (bRigidBodyJointConstraint *dat : m_convertInfo->m_constraints) { + // Try to find the constraint targets in the list of group objects. + for (KX_GameObject *member : constobj) { + // If the group member is the actual target for the constraint. + if ((dat->tar->id.name + 2) == member->GetName() && member->GetPhysicsController()) { + physEnv->SetupObjectConstraints(this, member, dat); + } + } + } +} + KX_GameObject* KX_GameObject::GetParent() { KX_GameObject* result = nullptr; diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index a4ebd0040aa9..7a149d72ad7a 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -195,6 +195,9 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator */ const std::vector& GetConstraints(); + void ReplicateConstraints(PHY_IPhysicsEnvironment *physEnv, const std::vector& constobj); + + /** * Get a pointer to the game object that is the parent of * this object. Or nullptr if there is no parent. The returned diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 85de7403482c..edff43324968 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -804,9 +804,7 @@ void KX_Scene::DupliGroupRecurse(KX_GameObject *groupobj, int level) // Now look if object in the hierarchy have dupli group and recurse. for (KX_GameObject *gameobj : m_logicHierarchicalGameObjects) { // Replicate all constraints. - if (gameobj->GetPhysicsController()) { - gameobj->GetPhysicsController()->ReplicateConstraints(gameobj, m_logicHierarchicalGameObjects); - } + gameobj->ReplicateConstraints(m_physicsEnvironment, m_logicHierarchicalGameObjects); if (gameobj != groupobj && gameobj->IsDupliGroup()) { // Can't instantiate group immediately as it destroys m_logicHierarchicalGameObjects. @@ -1687,16 +1685,15 @@ bool KX_Scene::MergeScene(KX_Scene *other) // List of all physics objects to merge (needed by ReplicateConstraints). std::vector physicsObjects; - for (KX_GameObject *gameobj : *otherObjects) { + for (KX_GameObject *gameobj : otherObjects) { if (gameobj->GetPhysicsController()) { physicsObjects.push_back(gameobj); } } - for (unsigned int i = 0; i < physicsObjects.size(); ++i) { - KX_GameObject *gameobj = physicsObjects[i]; + for (KX_GameObject *gameobj : physicsObjects) { // Replicate all constraints in the right physics environment. - gameobj->GetPhysicsController()->ReplicateConstraints(gameobj, physicsObjects); + gameobj->ReplicateConstraints(m_physicsEnvironment, physicsObjects); } } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index 33a1198359ad..02cfbd44bf0f 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -1663,30 +1663,6 @@ void CcdPhysicsController::ReplacePhysicsShape(PHY_IPhysicsController *phyctrl) GetPhysicsEnvironment()->RefreshCcdPhysicsController(this); } -void CcdPhysicsController::ReplicateConstraints(KX_GameObject *replica, std::vector constobj) -{ - if (replica->GetConstraints().empty() || !replica->GetPhysicsController()) - return; - - PHY_IPhysicsEnvironment *physEnv = GetPhysicsEnvironment(); - - std::vector constraints = replica->GetConstraints(); - std::vector::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); - std::vector::iterator memit; - for (memit = constobj.begin(); memit != constobj.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()) - physEnv->SetupObjectConstraints(replica, member, dat); - } - } -} - /////////////////////////////////////////////////////////// ///A small utility class, DefaultMotionState /// diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index d77bf0828818..98a4b822734d 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -868,9 +868,6 @@ class CcdPhysicsController : public PHY_IPhysicsController, public mt::SimdClass virtual bool ReinstancePhysicsShape(KX_GameObject *from_gameobj, RAS_MeshObject *from_meshobj, bool dupli = false); virtual void ReplacePhysicsShape(PHY_IPhysicsController *phyctrl); - - /* Method to replicate rigid body joint contraints for group instances. */ - virtual void ReplicateConstraints(KX_GameObject *gameobj, std::vector constobj); }; /// DefaultMotionState implements standard motionstate, using btTransform diff --git a/source/gameengine/Physics/Common/PHY_IPhysicsController.h b/source/gameengine/Physics/Common/PHY_IPhysicsController.h index 5a7093bfe2e2..c4d344f34456 100644 --- a/source/gameengine/Physics/Common/PHY_IPhysicsController.h +++ b/source/gameengine/Physics/Common/PHY_IPhysicsController.h @@ -152,9 +152,6 @@ class PHY_IPhysicsController : public PHY_IController virtual bool ReinstancePhysicsShape(KX_GameObject *from_gameobj, RAS_MeshObject *from_meshobj, bool dupli = false) = 0; virtual void ReplacePhysicsShape(PHY_IPhysicsController *phyctrl) = 0; - - /* Method to replicate rigid body joint contraints for group instances. */ - virtual void ReplicateConstraints(KX_GameObject *gameobj, std::vector constobj) = 0; }; #endif /* __PHY_IPHYSICSCONTROLLER_H__ */