[Bf-blender-cvs] [59727c7] alembic_pointcache: Unlink and cleanup functions when objects or the cached group get unlinked or changed.

Lukas Tönne noreply at git.blender.org
Tue Feb 24 12:11:01 CET 2015


Commit: 59727c736ad9e13f7ec5eb246007520ab17b5e04
Author: Lukas Tönne
Date:   Tue Feb 24 12:10:27 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB59727c736ad9e13f7ec5eb246007520ab17b5e04

Unlink and cleanup functions when objects or the cached group get
unlinked or changed.

===================================================================

M	source/blender/blenkernel/BKE_cache_library.h
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/blenkernel/intern/group.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/makesrna/intern/rna_cache_library.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index f4fb0ab..c68fe6a 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -42,7 +42,7 @@ struct CacheLibrary *BKE_cache_library_add(struct Main *bmain, const char *name)
 struct CacheLibrary *BKE_cache_library_copy(struct CacheLibrary *cachelib);
 void BKE_cache_library_free(struct CacheLibrary *cachelib);
 
-void BKE_cache_library_make_object_list(struct Main *main, struct CacheLibrary *cachelib, struct ListBase *lb);
+void BKE_cache_library_make_object_list(struct Main *bmain, struct CacheLibrary *cachelib, struct ListBase *lb);
 
 typedef struct CacheLibraryObjectsIterator {
 	ListBase objects;
@@ -80,5 +80,8 @@ int BKE_cache_item_name_length(struct Object *ob, int type, int index);
 struct CacheItem *BKE_cache_library_find_item(struct CacheLibrary *cachelib, struct Object *ob, int type, int index);
 struct CacheItem *BKE_cache_library_add_item(struct CacheLibrary *cachelib, struct Object *ob, int type, int index);
 void BKE_cache_library_remove_item(struct CacheLibrary *cachelib, struct CacheItem *item);
+void BKE_cache_library_clear(struct CacheLibrary *cachelib);
+
+void BKE_cache_library_group_update(struct Main *bmain, struct CacheLibrary *cachelib);
 
 #endif
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 752ecc3..cb06427 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -101,7 +101,7 @@ static void cache_library_tag_recursive(CacheLibrary *cachelib, int level, Objec
 }
 
 /* tag IDs contained in the cache library group */
-void BKE_cache_library_make_object_list(Main *main, CacheLibrary *cachelib, ListBase *lb)
+void BKE_cache_library_make_object_list(Main *bmain, CacheLibrary *cachelib, ListBase *lb)
 {
 	if (cachelib && cachelib->group) {
 		Object *ob;
@@ -109,14 +109,14 @@ void BKE_cache_library_make_object_list(Main *main, CacheLibrary *cachelib, List
 		GroupObject *gob;
 		
 		/* clear tags */
-		BKE_main_id_tag_idcode(main, ID_OB, false);
+		BKE_main_id_tag_idcode(bmain, ID_OB, false);
 		
 		for (gob = cachelib->group->gobject.first; gob; gob = gob->next) {
 			cache_library_tag_recursive(cachelib, 0, gob->ob);
 		}
 		
 		/* store object pointers in the list */
-		for (ob = main->object.first; ob; ob = ob->id.next) {
+		for (ob = bmain->object.first; ob; ob = ob->id.next) {
 			if (ob->id.flag & LIB_DOIT) {
 				link = MEM_callocN(sizeof(LinkData), "cache library ID link");
 				link->data = ob;
@@ -422,6 +422,48 @@ void BKE_cache_library_remove_item(CacheLibrary *cachelib, CacheItem *item)
 	}
 }
 
+void BKE_cache_library_clear(CacheLibrary *cachelib)
+{
+	CacheItem *item, *item_next;
+	
+	if (cachelib->items_hash)
+		BLI_ghash_clear(cachelib->items_hash, NULL, NULL);
+	
+	for (item = cachelib->items.first; item; item = item_next) {
+		item_next = item->next;
+		MEM_freeN(item);
+	}
+	BLI_listbase_clear(&cachelib->items);
+}
+
+void BKE_cache_library_group_update(Main *bmain, CacheLibrary *cachelib)
+{
+	if (cachelib) {
+		CacheItem *item, *item_next;
+		
+		/* clear tags */
+		BKE_main_id_tag_idcode(bmain, ID_OB, false);
+		
+		if (cachelib->group) {
+			GroupObject *gob;
+			for (gob = cachelib->group->gobject.first; gob; gob = gob->next) {
+				cache_library_tag_recursive(cachelib, 0, gob->ob);
+			}
+		}
+		
+		/* remove unused items */
+		for (item = cachelib->items.first; item; item = item_next) {
+			item_next = item->next;
+			
+			BLI_assert(item->ob != NULL);
+			
+			if (!(item->ob->id.flag & LIB_DOIT)) {
+				BKE_cache_library_remove_item(cachelib, item);
+			}
+		}
+	}
+}
+
 /* ========================================================================= */
 
 #if 0
diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c
index ae3ab83..f3869e4 100644
--- a/source/blender/blenkernel/intern/group.c
+++ b/source/blender/blenkernel/intern/group.c
@@ -36,6 +36,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_cache_library_types.h"
 #include "DNA_group_types.h"
 #include "DNA_material_types.h"
 #include "DNA_object_types.h"
@@ -45,7 +46,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
 
-
+#include "BKE_cache_library.h"
 #include "BKE_depsgraph.h"
 #include "BKE_global.h"
 #include "BKE_group.h"
@@ -78,6 +79,7 @@ void BKE_group_unlink(Group *group)
 	Scene *sce;
 	SceneRenderLayer *srl;
 	ParticleSystem *psys;
+	CacheLibrary *cachelib;
 	
 	for (ma = bmain->mat.first; ma; ma = ma->id.next) {
 		if (ma->group == group)
@@ -128,6 +130,13 @@ void BKE_group_unlink(Group *group)
 		}
 	}
 	
+	for (cachelib = bmain->cache_library.first; cachelib; cachelib = cachelib->id.next) {
+		if (cachelib->group == group) {
+			cachelib->group = NULL;
+			BKE_cache_library_group_update(G.main, cachelib);
+		}
+	}
+	
 	/* group stays in library, but no members */
 	BKE_group_free(group);
 	group->id.us = 0;
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index fa0ad32..b77eb24 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -38,6 +38,7 @@
 
 #include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
+#include "DNA_cache_library_types.h"
 #include "DNA_camera_types.h"
 #include "DNA_constraint_types.h"
 #include "DNA_group_types.h"
@@ -76,6 +77,7 @@
 #include "BKE_armature.h"
 #include "BKE_action.h"
 #include "BKE_bullet.h"
+#include "BKE_cache_library.h"
 #include "BKE_deform.h"
 #include "BKE_depsgraph.h"
 #include "BKE_DerivedMesh.h"
@@ -447,6 +449,7 @@ void BKE_object_unlink(Object *ob)
 	ARegion *ar;
 	RegionView3D *rv3d;
 	LodLevel *lod;
+	CacheLibrary *cachelib;
 	int a, found;
 	
 	unlink_controllers(&ob->controllers);
@@ -819,6 +822,17 @@ void BKE_object_unlink(Object *ob)
 		}
 		camera = camera->id.next;
 	}
+
+	/* cache libraries */
+	for (cachelib = bmain->cache_library.first; cachelib; cachelib = cachelib->id.next) {
+		CacheItem *item, *item_next;
+		for (item = cachelib->items.first; item; item = item_next) {
+			item_next = item->next;
+			if (item->ob == ob) {
+				BKE_cache_library_remove_item(cachelib, item);
+			}
+		}
+	}
 }
 
 /* actual check for internal data, not context or flags */
diff --git a/source/blender/makesrna/intern/rna_cache_library.c b/source/blender/makesrna/intern/rna_cache_library.c
index b9819bf..e48dd53 100644
--- a/source/blender/makesrna/intern/rna_cache_library.c
+++ b/source/blender/makesrna/intern/rna_cache_library.c
@@ -84,6 +84,15 @@ static void rna_CacheLibrary_update(Main *UNUSED(main), Scene *UNUSED(scene), Po
 {
 }
 
+static void rna_CacheLibrary_group_update(Main *main, Scene *scene, PointerRNA *ptr)
+{
+	CacheLibrary *cachelib = ptr->data;
+	
+	BKE_cache_library_group_update(main, cachelib);
+	
+	rna_CacheLibrary_update(main, scene, ptr);
+}
+
 /* ========================================================================= */
 
 static PointerRNA rna_ObjectCache_object_get(PointerRNA *ptr)
@@ -277,7 +286,7 @@ static void rna_def_cache_library(BlenderRNA *brna)
 	prop = RNA_def_property(srna, "group", PROP_POINTER, PROP_NONE);
 	RNA_def_property_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Group", "Cached object group");
-	RNA_def_property_update(prop, 0, "rna_CacheLibrary_update");
+	RNA_def_property_update(prop, 0, "rna_CacheLibrary_group_update");
 	
 	prop = RNA_def_property(srna, "object_caches", PROP_COLLECTION, PROP_NONE);
 	RNA_def_property_struct_type(prop, "ObjectCache");




More information about the Bf-blender-cvs mailing list