From e5ef601cd9da74d228df9e2ed2e952bad8f16f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 11 Jul 2024 10:49:49 +0200 Subject: [PATCH] Anim: give the `dependencies_id_types` for Actions a value dynamically Instead of hard-coding `IDType_ID_AC.dependencies_id_types = FILTER_ID_ALL`, which is overly broad, determine its value dynamically in `id_type_init()` so that it's purely based on which `IDType`s identify as 'animatable'. This should make things like ID remapping a bit more efficient, as the remapping code knows that an Action will only reference animatable data-blocks. Note that the initial value for the filter is still `FILTER_ID_ALL`, so that in cases where (by accident) the call to `BKE_idtype_init()` is omitted, semantically the situation is still correct. Not calling this function is an easy to make oversight when writing unit tests. Pull Request: https://projects.blender.org/blender/blender/pulls/124357 --- source/blender/blenkernel/intern/action.cc | 4 ++++ source/blender/blenkernel/intern/idtype.cc | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/source/blender/blenkernel/intern/action.cc b/source/blender/blenkernel/intern/action.cc index f01f2e3b65e..66cb1efb669 100644 --- a/source/blender/blenkernel/intern/action.cc +++ b/source/blender/blenkernel/intern/action.cc @@ -486,7 +486,11 @@ static AssetTypeInfo AssetType_AC = { IDTypeInfo IDType_ID_AC = { /*id_code*/ ID_AC, /*id_filter*/ FILTER_ID_AC, + + /* This value will be set dynamically in `BKE_idtype_init()` to only include + * animatable ID types (see `animrig::Binding::users()`). */ /*dependencies_id_types*/ FILTER_ID_ALL, + /*main_listbase_index*/ INDEX_ID_AC, /*struct_size*/ sizeof(bAction), /*name*/ "Action", diff --git a/source/blender/blenkernel/intern/idtype.cc b/source/blender/blenkernel/intern/idtype.cc index 19a0ca20b46..d9c07fbc5ba 100644 --- a/source/blender/blenkernel/intern/idtype.cc +++ b/source/blender/blenkernel/intern/idtype.cc @@ -109,6 +109,18 @@ static void id_type_init() BLI_assert_msg(init_types_num == INDEX_ID_MAX, "Some IDTypeInfo initialization is missing"); UNUSED_VARS_NDEBUG(init_types_num); + { /* Inspect which ID types can be animated, so that IDType_ID_AC.dependencies_id_types can be + * set to include those. The runtime ID* cache of animrig::Binding will point to any + * ID that is animated by it, and thus can point to any animatable ID type. */ + IDType_ID_AC.dependencies_id_types = 0; + for (const IDTypeInfo *id_type : id_types) { + const bool is_animatable = (id_type->flags & IDTYPE_FLAGS_NO_ANIMDATA) == 0; + if (is_animatable) { + IDType_ID_AC.dependencies_id_types |= id_type->id_filter; + } + } + } + #undef INIT_TYPE }