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
This commit is contained in:
Sybren A. Stüvel
2024-07-11 10:49:49 +02:00
parent c4ed24ce9f
commit e5ef601cd9
2 changed files with 16 additions and 0 deletions

View File

@@ -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",

View File

@@ -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
}