[Bf-blender-cvs] [c2012a6] gooseberry: Enable frame updates of duplicache through use of an invalidation flag.
Lukas Tönne
noreply at git.blender.org
Mon Mar 23 13:03:46 CET 2015
Commit: c2012a68b8fc4a086325add9fea8e2839a791d4a
Author: Lukas Tönne
Date: Tue Mar 17 09:36:43 2015 +0100
Branches: gooseberry
https://developer.blender.org/rBc2012a68b8fc4a086325add9fea8e2839a791d4a
Enable frame updates of duplicache through use of an invalidation flag.
===================================================================
M source/blender/blenkernel/BKE_anim.h
M source/blender/blenkernel/intern/depsgraph.c
M source/blender/blenkernel/intern/object.c
M source/blender/blenkernel/intern/object_dupli.c
M source/blender/editors/io/io_cache_library.c
M source/blender/makesdna/DNA_object_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index 3f6ae79..04cb2b0 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -78,7 +78,7 @@ struct ListBase *group_duplilist(struct EvaluationContext *eval_ctx, struct Scen
void free_object_duplilist(struct ListBase *lb);
int count_duplilist(struct Object *ob);
-void BKE_object_dupli_cache_update(struct Scene *scene, struct Object *ob, struct EvaluationContext *eval_ctx);
+void BKE_object_dupli_cache_update(struct Scene *scene, struct Object *ob, struct EvaluationContext *eval_ctx, float frame);
void BKE_object_dupli_cache_clear(struct Object *ob);
void BKE_object_dupli_cache_free(struct Object *ob);
bool BKE_object_dupli_cache_contains(struct Object *ob, struct Object *other);
diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c
index 1ebd34e..3418da7 100644
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ b/source/blender/blenkernel/intern/depsgraph.c
@@ -2141,6 +2141,10 @@ static void dag_object_time_update_flags(Main *bmain, Scene *scene, Object *ob)
}
}
+ /* invalidate dupli cache */
+ if (ob->dup_cache)
+ ob->dup_cache->flag |= DUPCACHE_FLAG_DIRTY;
+
if (ob->recalc & OB_RECALC_OB)
lib_id_recalc_tag(bmain, &ob->id);
if (ob->recalc & OB_RECALC_DATA)
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 67687d9..2c68255 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -3229,8 +3229,6 @@ void BKE_object_handle_update_ex(EvaluationContext *eval_ctx,
}
/* quick cache removed */
-
- BKE_object_dupli_cache_update(scene, ob, eval_ctx);
}
ob->recalc &= ~OB_RECALC_ALL;
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 558f810..388be0c 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1227,17 +1227,9 @@ static const DupliGenerator *get_dupli_generator(const DupliContext *ctx)
/* Returns a list of DupliObject */
ListBase *object_duplilist_ex(EvaluationContext *eval_ctx, Scene *scene, Object *ob, bool update)
{
- /* XXX Warning: this could potentially lead to a lot of unnecessary cache reading!
- * In the future proper depsgraph integration of dupli cache updates would be desirable.
- */
-#if 0
if (update) {
- if (G.debug & G_DEBUG)
- printf("Update dupli cache for object '%s'\n", ob->id.name+2);
-
- BKE_object_dupli_cache_update(scene, ob, eval_ctx);
+ BKE_object_dupli_cache_update(scene, ob, eval_ctx, (float)scene->r.cfra);
}
-#endif
if (ob->dup_cache) {
/* Note: duplis in the cache don't have the main duplicator obmat applied.
@@ -1400,7 +1392,7 @@ static DupliObject *dupli_cache_add_object(DupliCache *dupcache)
/* ------------------------------------------------------------------------- */
-void BKE_object_dupli_cache_update(Scene *scene, Object *ob, EvaluationContext *eval_ctx)
+void BKE_object_dupli_cache_update(Scene *scene, Object *ob, EvaluationContext *eval_ctx, float frame)
{
const eCacheLibrary_EvalMode eval_mode = eval_ctx->mode == DAG_EVAL_RENDER ? CACHE_LIBRARY_EVAL_RENDER : CACHE_LIBRARY_EVAL_VIEWPORT;
Main *bmain = G.main;
@@ -1409,18 +1401,25 @@ void BKE_object_dupli_cache_update(Scene *scene, Object *ob, EvaluationContext *
if ((ob->transflag & OB_DUPLIGROUP) && ob->dup_group &&
BKE_cache_test_dupligroup(bmain, eval_mode, ob->dup_group)) {
- if (ob->dup_cache) {
- dupli_cache_clear(ob->dup_cache);
+ if (ob->dup_cache && !(ob->dup_cache->flag & DUPCACHE_FLAG_DIRTY)) {
+ /* skip if cache is valid */
}
else {
- ob->dup_cache = dupli_cache_new();
- }
-
- {
- /* TODO at this point we could apply animation offset */
- float frame = (float)scene->r.cfra;
+ if (G.debug & G_DEBUG)
+ printf("Update dupli cache for object '%s'\n", ob->id.name+2);
+ if (ob->dup_cache) {
+ dupli_cache_clear(ob->dup_cache);
+ }
+ else {
+ ob->dup_cache = dupli_cache_new();
+ }
+
+ /* TODO at this point we could apply animation offset */
BKE_cache_read_dupligroup(bmain, scene, frame, eval_mode, ob->dup_group, ob->dup_cache);
+
+ ob->dup_cache->flag &= ~DUPCACHE_FLAG_DIRTY;
+ ob->dup_cache->cfra = frame;
}
}
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index 094f9b1..faf1d6a 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -602,7 +602,7 @@ static int cache_library_rebuild_dupligroup_exec(bContext *C, wmOperator *UNUSED
eval_ctx.mode = DAG_EVAL_VIEWPORT;
- BKE_object_dupli_cache_update(scene, ob, &eval_ctx);
+ BKE_object_dupli_cache_update(scene, ob, &eval_ctx, (float)scene->r.cfra);
return OPERATOR_FINISHED;
}
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index 06d827e..1c8d5a8 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -355,11 +355,17 @@ typedef struct DupliObjectData {
} DupliObjectData;
typedef struct DupliCache {
- struct GHash *ghash;
+ int flag;
+ float cfra; /* frame for which the cache was constructed */
+ struct GHash *ghash;
ListBase duplilist;
} DupliCache;
+typedef enum eDupliCache_Flag {
+ DUPCACHE_FLAG_DIRTY = (1 << 0), /* cache requires update */
+} eDupliCache_Flag;
+
/* **************** OBJECT ********************* */
/* used many places... should be specialized */
More information about the Bf-blender-cvs
mailing list