From 6f50969406a751ac69d41e792d859d74410ebef6 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 3 Aug 2021 08:10:07 +0200 Subject: Cleanup: Hide implementation details for ED_keyframe_keylist. For T78995 we want to change the data structure of keylists to improve performance. (Probably a Vector with bin-search capabilities). This patch hides the internal structure of the keylists behind `AnimKeylist` structure. This allows us to change the internals without 'breaking' where it is being used. The change adds functions to create, free, find and walk over the keylist. Reviewed By: sybren Maniphest Tasks: T78995 Differential Revision: https://developer.blender.org/D11974 --- .../blender/editors/space_action/action_select.c | 48 +++++++++++----------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'source/blender/editors/space_action') diff --git a/source/blender/editors/space_action/action_select.c b/source/blender/editors/space_action/action_select.c index 59d2063ea84..64ccca2c907 100644 --- a/source/blender/editors/space_action/action_select.c +++ b/source/blender/editors/space_action/action_select.c @@ -93,7 +93,7 @@ static bAnimListElem *actkeys_find_list_element_at_position(bAnimContext *ac, } static void actkeys_list_element_to_keylist(bAnimContext *ac, - DLRBT_Tree *anim_keys, + struct AnimKeylist *keylist, bAnimListElem *ale) { AnimData *adt = ANIM_nla_mapping_get(ac, ale); @@ -107,44 +107,44 @@ static void actkeys_list_element_to_keylist(bAnimContext *ac, switch (ale->datatype) { case ALE_SCE: { Scene *scene = (Scene *)ale->key_data; - scene_to_keylist(ads, scene, anim_keys, 0); + scene_to_keylist(ads, scene, keylist, 0); break; } case ALE_OB: { Object *ob = (Object *)ale->key_data; - ob_to_keylist(ads, ob, anim_keys, 0); + ob_to_keylist(ads, ob, keylist, 0); break; } case ALE_ACT: { bAction *act = (bAction *)ale->key_data; - action_to_keylist(adt, act, anim_keys, 0); + action_to_keylist(adt, act, keylist, 0); break; } case ALE_FCURVE: { FCurve *fcu = (FCurve *)ale->key_data; - fcurve_to_keylist(adt, fcu, anim_keys, 0); + fcurve_to_keylist(adt, fcu, keylist, 0); break; } } } else if (ale->type == ANIMTYPE_SUMMARY) { /* dopesheet summary covers everything */ - summary_to_keylist(ac, anim_keys, 0); + summary_to_keylist(ac, keylist, 0); } else if (ale->type == ANIMTYPE_GROUP) { /* TODO: why don't we just give groups key_data too? */ bActionGroup *agrp = (bActionGroup *)ale->data; - agroup_to_keylist(adt, agrp, anim_keys, 0); + agroup_to_keylist(adt, agrp, keylist, 0); } else if (ale->type == ANIMTYPE_GPLAYER) { /* TODO: why don't we just give gplayers key_data too? */ bGPDlayer *gpl = (bGPDlayer *)ale->data; - gpl_to_keylist(ads, gpl, anim_keys); + gpl_to_keylist(ads, gpl, keylist); } else if (ale->type == ANIMTYPE_MASKLAYER) { /* TODO: why don't we just give masklayers key_data too? */ MaskLayer *masklay = (MaskLayer *)ale->data; - mask_to_keylist(ads, masklay, anim_keys); + mask_to_keylist(ads, masklay, keylist); } } @@ -160,9 +160,8 @@ static void actkeys_find_key_in_list_element(bAnimContext *ac, View2D *v2d = &ac->region->v2d; - DLRBT_Tree anim_keys; - BLI_dlrbTree_init(&anim_keys); - actkeys_list_element_to_keylist(ac, &anim_keys, ale); + struct AnimKeylist *keylist = ED_keylist_create(); + actkeys_list_element_to_keylist(ac, keylist, ale); AnimData *adt = ANIM_nla_mapping_get(ac, ale); @@ -174,22 +173,21 @@ static void actkeys_find_key_in_list_element(bAnimContext *ac, float xmin = UI_view2d_region_to_view_x(v2d, region_x - (int)key_hsize); float xmax = UI_view2d_region_to_view_x(v2d, region_x + (int)key_hsize); - for (ActKeyColumn *ak = anim_keys.root; ak; ak = (ak->cfra < xmin) ? ak->right : ak->left) { - if (IN_RANGE(ak->cfra, xmin, xmax)) { - /* set the frame to use, and apply inverse-correction for NLA-mapping - * so that the frame will get selected by the selection functions without - * requiring to map each frame once again... - */ - *r_selx = BKE_nla_tweakedit_remap(adt, ak->cfra, NLATIME_CONVERT_UNMAP); - *r_frame = ak->cfra; - *r_found = true; - *r_is_selected = (ak->sel & SELECT) != 0; - break; - } + const ActKeyColumn *ak = ED_keylist_find_any_between(keylist, xmin, xmax); + if (ak) { + + /* set the frame to use, and apply inverse-correction for NLA-mapping + * so that the frame will get selected by the selection functions without + * requiring to map each frame once again... + */ + *r_selx = BKE_nla_tweakedit_remap(adt, ak->cfra, NLATIME_CONVERT_UNMAP); + *r_frame = ak->cfra; + *r_found = true; + *r_is_selected = (ak->sel & SELECT) != 0; } /* cleanup temporary lists */ - BLI_dlrbTree_free(&anim_keys); + ED_keylist_free(keylist); } static void actkeys_find_key_at_position(bAnimContext *ac, -- cgit v1.2.3