[Bf-blender-cvs] [e9d9478] gooseberry: Generic validation function to help ensure that we don't add meaningless items to a cache library.

Lukas Tönne noreply at git.blender.org
Mon Mar 23 13:02:02 CET 2015


Commit: e9d947860adb4a00c9e4b342af9343786abfc9ab
Author: Lukas Tönne
Date:   Mon Mar 2 12:10:51 2015 +0100
Branches: gooseberry
https://developer.blender.org/rBe9d947860adb4a00c9e4b342af9343786abfc9ab

Generic validation function to help ensure that we don't add meaningless
items to a cache library.

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

M	source/blender/blenkernel/BKE_cache_library.h
M	source/blender/blenkernel/intern/cache_library.c

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

diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index 98006d0..4231595 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -87,6 +87,7 @@ struct CacheItem *BKE_cache_library_add_item(struct CacheLibrary *cachelib, stru
 void BKE_cache_library_remove_item(struct CacheLibrary *cachelib, struct CacheItem *item);
 void BKE_cache_library_clear(struct CacheLibrary *cachelib);
 
+bool BKE_cache_library_validate_item(struct CacheLibrary *cachelib, struct Object *ob, int type, int index);
 void BKE_cache_library_group_update(struct Main *bmain, struct CacheLibrary *cachelib);
 
 bool BKE_cache_read_derived_mesh(struct Main *bmain, struct Scene *scene, float frame, struct Object *ob, struct DerivedMesh **r_dm);
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 6cc5dc3..6850b91 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -45,6 +45,7 @@
 
 #include "BKE_cache_library.h"
 #include "BKE_global.h"
+#include "BKE_group.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 
@@ -84,7 +85,7 @@ void BKE_cache_library_free(CacheLibrary *cachelib)
 		BLI_ghash_free(cachelib->items_hash, NULL, NULL);
 }
 
-void BKE_cache_library_unlink(CacheLibrary *cachelib)
+void BKE_cache_library_unlink(CacheLibrary *UNUSED(cachelib))
 {
 }
 
@@ -425,6 +426,9 @@ CacheItem *BKE_cache_library_add_item(CacheLibrary *cachelib, struct Object *ob,
 {
 	CacheItem *item;
 	
+	/* assert validity */
+	BLI_assert(BKE_cache_library_validate_item(cachelib, ob, type, index));
+	
 	cache_library_ensure_items_hash(cachelib);
 	
 	item = BKE_cache_library_find_item(cachelib, ob, type, index);
@@ -468,6 +472,38 @@ void BKE_cache_library_clear(CacheLibrary *cachelib)
 	BLI_listbase_clear(&cachelib->items);
 }
 
+bool BKE_cache_library_validate_item(CacheLibrary *cachelib, Object *ob, int type, int index)
+{
+	if (!cachelib || !cachelib->group)
+		return false;
+	
+	if (!BKE_group_object_exists(cachelib->group, ob))
+		return false;
+	
+	if (ELEM(type, CACHE_TYPE_DERIVED_MESH)) {
+		if (ob->type != OB_MESH)
+			return false;
+	}
+	else if (ELEM(type, CACHE_TYPE_PARTICLES, CACHE_TYPE_HAIR, CACHE_TYPE_HAIR_PATHS)) {
+		ParticleSystem *psys = BLI_findlink(&ob->particlesystem, index);
+		
+		if (!psys)
+			return false;
+		
+		if (ELEM(type, CACHE_TYPE_PARTICLES)) {
+			if (psys->part->type != PART_EMITTER)
+				return false;
+		}
+		
+		if (ELEM(type, CACHE_TYPE_HAIR, CACHE_TYPE_HAIR_PATHS)) {
+			if (psys->part->type != PART_HAIR)
+				return false;
+		}
+	}
+	
+	return true;
+}
+
 void BKE_cache_library_group_update(Main *bmain, CacheLibrary *cachelib)
 {
 	if (cachelib) {




More information about the Bf-blender-cvs mailing list