diff options
author | Sergey Sharybin <sergey@blender.org> | 2020-08-05 12:54:18 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey@blender.org> | 2020-08-11 13:17:13 +0300 |
commit | 6f99dfc0c6032fa5644031f6355ff59e8e10261d (patch) | |
tree | 2b874bc3b38617c348a1c1ee51a63c17c56530da /source/blender/blenkernel/intern/modifier.c | |
parent | ca2c4907fb1af301af59d8c922759e947e2675c7 (diff) |
Modifier: Maintain per-modifier session UUID
Allows to keep track of modifiers, which is required, for example,
for runtime data preservation in depsgraph.
Diffstat (limited to 'source/blender/blenkernel/intern/modifier.c')
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 5789e0f0557..afd02d7001e 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -41,6 +41,7 @@ #include "BLI_linklist.h" #include "BLI_listbase.h" #include "BLI_path_util.h" +#include "BLI_session_uuid.h" #include "BLI_string.h" #include "BLI_string_utils.h" #include "BLI_utildefines.h" @@ -150,6 +151,8 @@ ModifierData *BKE_modifier_new(int type) mti->initData(md); } + BKE_modifier_session_uuid_generate(md); + return md; } @@ -192,6 +195,11 @@ void BKE_modifier_free(ModifierData *md) BKE_modifier_free_ex(md, 0); } +void BKE_modifier_session_uuid_generate(ModifierData *md) +{ + md->session_uuid = BLI_session_uuid_generate(); +} + bool BKE_modifier_unique_name(ListBase *modifiers, ModifierData *md) { if (modifiers && md) { @@ -368,6 +376,17 @@ void BKE_modifier_copydata_ex(ModifierData *md, ModifierData *target, const int mti->foreachObjectLink(target, NULL, (ObjectWalkFunc)modifier_copy_data_id_us_cb, NULL); } } + + if (flag & LIB_ID_CREATE_NO_MAIN) { + /* Make sure UUID is the same between the source and the target. + * This is needed in the cases when UUID is to be preserved and when there is no copyData + * callback, or the copyData does not do full byte copy of the modifier data. */ + target->session_uuid = md->session_uuid; + } + else { + /* In the case copyData made full byte copy force UUID to be re-generated. */ + BKE_modifier_session_uuid_generate(md); + } } void BKE_modifier_copydata(ModifierData *md, ModifierData *target) @@ -1071,3 +1090,26 @@ struct ModifierData *BKE_modifier_get_evaluated(Depsgraph *depsgraph, } return BKE_modifiers_findby_name(object_eval, md->name); } + +void BKE_modifier_check_uuids_unique_and_report(const Object *object) +{ + struct GSet *used_uuids = BLI_gset_new( + BLI_session_uuid_ghash_hash, BLI_session_uuid_ghash_compare, "modifier used uuids"); + + LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) { + const SessionUUID *session_uuid = &md->session_uuid; + if (!BLI_session_uuid_is_generated(session_uuid)) { + printf("Modifier %s -> %s does not have UUID generated.\n", object->id.name + 2, md->name); + continue; + } + + if (BLI_gset_lookup(used_uuids, session_uuid) != NULL) { + printf("Modifier %s -> %s has duplicate UUID generated.\n", object->id.name + 2, md->name); + continue; + } + + BLI_gset_insert(used_uuids, (void *)session_uuid); + } + + BLI_gset_free(used_uuids, NULL); +} |