Skip to content

Commit

Permalink
UPBGE: Move ReplicateConstrains function in KX_GameObject.
Browse files Browse the repository at this point in the history
Always try to not see ketsji from other parts.
  • Loading branch information
panzergame committed Dec 17, 2017
1 parent fa9079f commit 4b4259c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 37 deletions.
18 changes: 18 additions & 0 deletions source/gameengine/Ketsji/KX_GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,24 @@ const std::vector<bRigidBodyJointConstraint *>& KX_GameObject::GetConstraints()
return m_convertInfo->m_constraints;
}

void KX_GameObject::ReplicateConstraints(PHY_IPhysicsEnvironment *physEnv, const std::vector<KX_GameObject *>& 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;
Expand Down
3 changes: 3 additions & 0 deletions source/gameengine/Ketsji/KX_GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator
*/
const std::vector<bRigidBodyJointConstraint*>& GetConstraints();

void ReplicateConstraints(PHY_IPhysicsEnvironment *physEnv, const std::vector<KX_GameObject *>& constobj);


/**
* Get a pointer to the game object that is the parent of
* this object. Or nullptr if there is no parent. The returned
Expand Down
11 changes: 4 additions & 7 deletions source/gameengine/Ketsji/KX_Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1687,16 +1685,15 @@ bool KX_Scene::MergeScene(KX_Scene *other)

// List of all physics objects to merge (needed by ReplicateConstraints).
std::vector<KX_GameObject *> 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);
}
}

Expand Down
24 changes: 0 additions & 24 deletions source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1663,30 +1663,6 @@ void CcdPhysicsController::ReplacePhysicsShape(PHY_IPhysicsController *phyctrl)
GetPhysicsEnvironment()->RefreshCcdPhysicsController(this);
}

void CcdPhysicsController::ReplicateConstraints(KX_GameObject *replica, std::vector<KX_GameObject *> constobj)
{
if (replica->GetConstraints().empty() || !replica->GetPhysicsController())
return;

PHY_IPhysicsEnvironment *physEnv = GetPhysicsEnvironment();

std::vector<bRigidBodyJointConstraint *> constraints = replica->GetConstraints();
std::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);
std::vector<KX_GameObject *>::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
///
Expand Down
3 changes: 0 additions & 3 deletions source/gameengine/Physics/Bullet/CcdPhysicsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<KX_GameObject *> constobj);
};

/// DefaultMotionState implements standard motionstate, using btTransform
Expand Down
3 changes: 0 additions & 3 deletions source/gameengine/Physics/Common/PHY_IPhysicsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<KX_GameObject *> constobj) = 0;
};

#endif /* __PHY_IPHYSICSCONTROLLER_H__ */

0 comments on commit 4b4259c

Please sign in to comment.