BGE: Add recursive dupli group deletion
authorThomas Szepe <HG1_public@gmx.net>
Sun, 11 Oct 2015 12:08:38 +0000 (14:08 +0200)
committerThomas Szepe <HG1_public@gmx.net>
Sun, 11 Oct 2015 12:08:38 +0000 (14:08 +0200)
This patch will delete all associated objects from a group instance (dupli group) if the are deleted.

Reviewers: brita_, sybren, lordloki, moguri

Reviewed By: lordloki, moguri

Projects: #game_engine

Maniphest Tasks: T36388

Differential Revision: https://developer.blender.org/D1205

source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_Scene.h

index 723736906a900a0eecce6283c7615283f42aa5d5..c9c63371713d138154d3a62f9badd92d4bf1bebd 100644 (file)
@@ -1006,17 +1006,28 @@ void KX_Scene::RemoveObject(class CValue* gameobj)
        //newobj->SetSGNode(0);
 }
 
        //newobj->SetSGNode(0);
 }
 
+void KX_Scene::RemoveDupliGroup(class CValue *gameobj)
+{
+       KX_GameObject *newobj = (KX_GameObject *) gameobj;
+
+       if (newobj->IsDupliGroup()) {
+               for (int i = 0; i < newobj->GetInstanceObjects()->GetCount(); i++) {
+                       CValue *obj = newobj->GetInstanceObjects()->GetValue(i);
+                       DelayedRemoveObject(obj);
+               }
+       }
+}
+
 void KX_Scene::DelayedRemoveObject(class CValue* gameobj)
 {
 void KX_Scene::DelayedRemoveObject(class CValue* gameobj)
 {
-       //KX_GameObject* newobj = (KX_GameObject*) gameobj;
+       RemoveDupliGroup(gameobj);
+
        if (!m_euthanasyobjects->SearchValue(gameobj))
        {
                m_euthanasyobjects->Add(gameobj->AddRef());
        if (!m_euthanasyobjects->SearchValue(gameobj))
        {
                m_euthanasyobjects->Add(gameobj->AddRef());
-       } 
+       }
 }
 
 }
 
-
-
 int KX_Scene::NewRemoveObject(class CValue* gameobj)
 {
        int ret;
 int KX_Scene::NewRemoveObject(class CValue* gameobj)
 {
        int ret;
index 4f7ad98f30d0390338ba18f663abbd7913269f4a..046ad25c09cbfd0ddc31eb6e2e4a26c423ac4e71 100644 (file)
@@ -339,6 +339,7 @@ public:
        void RemoveNodeDestructObject(SG_IObject* node,
                                      CValue* gameobj);
        void RemoveObject(CValue* gameobj);
        void RemoveNodeDestructObject(SG_IObject* node,
                                      CValue* gameobj);
        void RemoveObject(CValue* gameobj);
+       void RemoveDupliGroup(CValue *gameobj);
        void DelayedRemoveObject(CValue* gameobj);
        
        int NewRemoveObject(CValue* gameobj);
        void DelayedRemoveObject(CValue* gameobj);
        
        int NewRemoveObject(CValue* gameobj);