diff options
Diffstat (limited to 'source/gameengine/Ketsji/KX_Scene.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.cpp | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 891cd9b3d85..200883a094c 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -431,6 +431,11 @@ void KX_Scene::RemoveNodeDestructObject(class SG_IObject* node,class CValue* gam KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CValue* gameobj) { + // for group duplication, limit the duplication of the hierarchy to the + // objects that are part of the group. + if (!IsObjectInGroup(gameobj)) + return NULL; + KX_GameObject* orgobj = (KX_GameObject*)gameobj; KX_GameObject* newobj = (KX_GameObject*)orgobj->GetReplica(); m_map_gameobject_to_replica.insert(orgobj, newobj); @@ -545,7 +550,9 @@ void KX_Scene::ReplicateLogic(KX_GameObject* newobj) if (!newsensorobj) { // no, then the sensor points outside the hierachy, keep it the same - m_logicmgr->RegisterToSensor(cont,oldsensor); + if (m_objectlist->SearchValue(oldsensorobj)) + // only replicate links that points to active objects + m_logicmgr->RegisterToSensor(cont,oldsensor); } else { @@ -583,7 +590,9 @@ void KX_Scene::ReplicateLogic(KX_GameObject* newobj) if (!newactuatorobj) { // no, then the sensor points outside the hierachy, keep it the same - m_logicmgr->RegisterToActuator(cont,oldactuator); + if (m_objectlist->SearchValue(oldactuatorobj)) + // only replicate links that points to active objects + m_logicmgr->RegisterToActuator(cont,oldactuator); } else { @@ -615,6 +624,7 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level) { KX_GameObject* groupobj = (KX_GameObject*) obj; KX_GameObject* replica; + KX_GameObject* gameobj; Object* blgroupobj = groupobj->GetBlenderObject(); Group* group; GroupObject *go; @@ -628,6 +638,10 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level) m_logicHierarchicalGameObjects.clear(); m_map_gameobject_to_replica.clear(); m_ueberExecutionPriority++; + // for groups will do something special: + // we will force the creation of objects to those in the group only + // Again, this is match what Blender is doing (it doesn't care of parent relationship) + m_groupGameObjects.clear(); group = blgroupobj->dup_group; for(go=(GroupObject*)group->gobject.first; go; go=(GroupObject*)go->next) @@ -636,13 +650,25 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level) if (blgroupobj == blenderobj) // this check is also in group_duplilist() continue; - KX_GameObject* gameobj = m_sceneConverter->FindGameObject(blenderobj); + gameobj = m_sceneConverter->FindGameObject(blenderobj); if (gameobj == NULL) { // this object has not been converted!!! // Should not happen as dupli group are created automatically continue; } + if (blenderobj->lay & group->layer==0) + { + // object is not visible in the 3D view, will not be instantiated + continue; + } + m_groupGameObjects.insert(gameobj); + } + + set<CValue*>::iterator oit; + for (oit=m_groupGameObjects.begin(); oit != m_groupGameObjects.end(); oit++) + { + gameobj = (KX_GameObject*)(*oit); if (gameobj->GetParent() != NULL) { // this object is not a top parent. Either it is the child of another @@ -651,11 +677,6 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level) // is inconsistent, skip it anyway continue; } - if (blenderobj->lay & group->layer==0) - { - // object is not visible in the 3D view, will not be instantiated - continue; - } replica = (KX_GameObject*) AddNodeReplicaObject(NULL,gameobj); // add to 'rootparent' list (this is the list of top hierarchy objects, updated each frame) m_parentlist->Add(replica->AddRef()); @@ -668,7 +689,8 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level) { SG_Node* orgnode = (*childit); SG_Node* childreplicanode = orgnode->GetSGReplica(); - replica->GetSGNode()->AddChild(childreplicanode); + if (childreplicanode) + replica->GetSGNode()->AddChild(childreplicanode); } // don't replicate logic now: we assume that the objects in the group can have // logic relationship, even outside parent relationship @@ -745,6 +767,7 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, m_logicHierarchicalGameObjects.clear(); m_map_gameobject_to_replica.clear(); + m_groupGameObjects.clear(); // todo: place a timebomb in the object, for temporarily objects :) // lifespan of zero means 'this object lives forever' @@ -778,7 +801,8 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, { SG_Node* orgnode = (*childit); SG_Node* childreplicanode = orgnode->GetSGReplica(); - replica->GetSGNode()->AddChild(childreplicanode); + if (childreplicanode) + replica->GetSGNode()->AddChild(childreplicanode); } // relink any pointers as necessary, sort of a temporary solution |