[Bf-blender-cvs] [6f50969406a] master: Cleanup: Hide implementation details for ED_keyframe_keylist.
Jeroen Bakker
noreply at git.blender.org
Tue Aug 3 08:10:38 CEST 2021
Commit: 6f50969406a751ac69d41e792d859d74410ebef6
Author: Jeroen Bakker
Date: Tue Aug 3 08:10:07 2021 +0200
Branches: master
https://developer.blender.org/rB6f50969406a751ac69d41e792d859d74410ebef6
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
===================================================================
A source/blender/blenlib/BLI_range.h
M source/blender/blenlib/CMakeLists.txt
M source/blender/editors/animation/anim_draw.c
M source/blender/editors/animation/anim_motion_paths.c
M source/blender/editors/animation/keyframes_draw.c
M source/blender/editors/animation/keyframes_keylist.c
M source/blender/editors/armature/pose_lib.c
M source/blender/editors/armature/pose_slide.c
M source/blender/editors/include/ED_keyframes_keylist.h
M source/blender/editors/screen/screen_ops.c
M source/blender/editors/space_action/action_select.c
M source/blender/editors/space_nla/nla_draw.c
===================================================================
diff --git a/source/blender/blenlib/BLI_range.h b/source/blender/blenlib/BLI_range.h
new file mode 100644
index 00000000000..ad4cd6c162e
--- /dev/null
+++ b/source/blender/blenlib/BLI_range.h
@@ -0,0 +1,34 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+/** \file
+ * \ingroup bli
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct Range2f {
+ float min;
+ float max;
+} Range2f;
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index ea5572f1c8a..b6603dce378 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -265,6 +265,7 @@ set(SRC
BLI_quadric.h
BLI_rand.h
BLI_rand.hh
+ BLI_range.h
BLI_rect.h
BLI_resource_scope.hh
BLI_scanfill.h
diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c
index baf8adf28d0..6469c47ab11 100644
--- a/source/blender/editors/animation/anim_draw.c
+++ b/source/blender/editors/animation/anim_draw.c
@@ -494,7 +494,7 @@ static bool find_prev_next_keyframes(struct bContext *C, int *r_nextfra, int *r_
Object *ob = CTX_data_active_object(C);
Mask *mask = CTX_data_edit_mask(C);
bDopeSheet ads = {NULL};
- DLRBT_Tree keys;
+ struct AnimKeylist *keylist = ED_keylist_create();
ActKeyColumn *aknext, *akprev;
float cfranext, cfraprev;
bool donenext = false, doneprev = false;
@@ -502,9 +502,6 @@ static bool find_prev_next_keyframes(struct bContext *C, int *r_nextfra, int *r_
cfranext = cfraprev = (float)(CFRA);
- /* init binarytree-list for getting keyframes */
- BLI_dlrbTree_init(&keys);
-
/* seed up dummy dopesheet context with flags to perform necessary filtering */
if ((scene->flag & SCE_KEYS_NO_SELONLY) == 0) {
/* only selected channels are included */
@@ -512,22 +509,22 @@ static bool find_prev_next_keyframes(struct bContext *C, int *r_nextfra, int *r_
}
/* populate tree with keyframe nodes */
- scene_to_keylist(&ads, scene, &keys, 0);
- gpencil_to_keylist(&ads, scene->gpd, &keys, false);
+ scene_to_keylist(&ads, scene, keylist, 0);
+ gpencil_to_keylist(&ads, scene->gpd, keylist, false);
if (ob) {
- ob_to_keylist(&ads, ob, &keys, 0);
- gpencil_to_keylist(&ads, ob->data, &keys, false);
+ ob_to_keylist(&ads, ob, keylist, 0);
+ gpencil_to_keylist(&ads, ob->data, keylist, false);
}
if (mask) {
MaskLayer *masklay = BKE_mask_layer_active(mask);
- mask_to_keylist(&ads, masklay, &keys);
+ mask_to_keylist(&ads, masklay, keylist);
}
/* find matching keyframe in the right direction */
do {
- aknext = (ActKeyColumn *)BLI_dlrbTree_search_next(&keys, compare_ak_cfraPtr, &cfranext);
+ aknext = ED_keylist_find_next(keylist, cfranext);
if (aknext) {
if (CFRA == (int)aknext->cfra) {
@@ -545,7 +542,7 @@ static bool find_prev_next_keyframes(struct bContext *C, int *r_nextfra, int *r_
} while ((aknext != NULL) && (donenext == false));
do {
- akprev = (ActKeyColumn *)BLI_dlrbTree_search_prev(&keys, compare_ak_cfraPtr, &cfraprev);
+ akprev = ED_keylist_find_prev(keylist, cfraprev);
if (akprev) {
if (CFRA == (int)akprev->cfra) {
@@ -562,7 +559,7 @@ static bool find_prev_next_keyframes(struct bContext *C, int *r_nextfra, int *r_
} while ((akprev != NULL) && (doneprev == false));
/* free temp stuff */
- BLI_dlrbTree_free(&keys);
+ ED_keylist_free(keylist);
/* any success? */
if (doneprev || donenext) {
diff --git a/source/blender/editors/animation/anim_motion_paths.c b/source/blender/editors/animation/anim_motion_paths.c
index bddd5dbff55..2a3ae35aab0 100644
--- a/source/blender/editors/animation/anim_motion_paths.c
+++ b/source/blender/editors/animation/anim_motion_paths.c
@@ -55,7 +55,7 @@ typedef struct MPathTarget {
bMotionPath *mpath; /* motion path in question */
- DLRBT_Tree keys; /* temp, to know where the keyframes are */
+ struct AnimKeylist *keylist; /* temp, to know where the keyframes are */
/* Original (Source Objects) */
Object *ob; /* source object */
@@ -187,7 +187,7 @@ static void motionpaths_calc_bake_targets(ListBase *targets, int cframe)
float mframe = (float)(cframe);
/* Tag if it's a keyframe */
- if (BLI_dlrbTree_search_exact(&mpt->keys, compare_ak_cfraPtr, &mframe)) {
+ if (ED_keylist_find_exact(mpt->keylist, mframe)) {
mpv->flag |= MOTIONPATH_VERT_KEY;
}
else {
@@ -234,52 +234,54 @@ static void motionpath_get_global_framerange(ListBase *targets, int *r_sfra, int
}
}
-static int motionpath_get_prev_keyframe(MPathTarget *mpt, DLRBT_Tree *fcu_keys, int current_frame)
+static int motionpath_get_prev_keyframe(MPathTarget *mpt,
+ struct AnimKeylist *keylist,
+ int current_frame)
{
if (current_frame <= mpt->mpath->start_frame) {
return mpt->mpath->start_frame;
}
float current_frame_float = current_frame;
- DLRBT_Node *node = BLI_dlrbTree_search_prev(fcu_keys, compare_ak_cfraPtr, ¤t_frame_float);
- if (node == NULL) {
+ const ActKeyColumn *ak = ED_keylist_find_prev(keylist, current_frame_float);
+ if (ak == NULL) {
return mpt->mpath->start_frame;
}
- ActKeyColumn *key_data = (ActKeyColumn *)node;
- return key_data->cfra;
+ return ak->cfra;
}
static int motionpath_get_prev_prev_keyframe(MPathTarget *mpt,
- DLRBT_Tree *fcu_keys,
+ struct AnimKeylist *keylist,
int current_frame)
{
- int frame = motionpath_get_prev_keyframe(mpt, fcu_keys, current_frame);
- return motionpath_get_prev_keyframe(mpt, fcu_keys, frame);
+ int frame = motionpath_get_prev_keyframe(mpt, keylist, current_frame);
+ return motionpath_get_prev_keyframe(mpt, keylist, frame);
}
-static int motionpath_get_next_keyframe(MPathTarget *mpt, DLRBT_Tree *fcu_keys, int current_frame)
+static int motionpath_get_next_keyframe(MPathTarget *mpt,
+ struct AnimKeylist *keylist,
+ int current_frame)
{
if (current_frame >= mpt->mpath->end_frame) {
return mpt->mpath->end_frame;
}
float current_frame_float = current_frame;
- DLRBT_Node *node = BLI_dlrbTree_search_next(fcu_keys, compare_ak_cfraPtr, ¤t_frame_float);
- if (node == NULL) {
+ const ActKeyColumn *ak = ED_keylist_find_next(keylist, current_frame_float);
+ if (ak == NULL) {
return mpt->mpath->end_frame;
}
- ActKeyColumn *key_data = (ActKeyColumn *)node;
- return key_data->cfra;
+ return ak->cfra;
}
static int motionpath_get_next_next_keyframe(MPathTarget *mpt,
- DLRBT_Tree *fcu_keys,
+ struct AnimKeylist *keylist,
int current_frame)
{
- int frame = motionpath_get_next_keyframe(mpt, fcu_keys, current_frame);
- return motionpath_get_next_keyframe(mpt, fcu_keys, frame);
+ int frame = motionpath_get_next_keyframe(mpt, keylist, current_frame);
+ return motionpath_get_next_keyframe(mpt, keylist, frame);
}
static bool motionpath_check_can_use_keyframe_range(MPathTarget *UNUSED(mpt),
@@ -324,17 +326,16 @@ static void motionpath_calculate_update_range(MPathTarget *mpt,
* Could be optimized further by storing some flags about which channels has been modified so
* we ignore all others (which can potentially make an update range unnecessary wide). */
for (FCurve *fcu = fcurve_list->first; fcu != NULL; fcu = fcu->next) {
- DLRBT_Tree fcu_keys;
- BLI_dlrbTree_init(&fcu_keys);
- fcurve_to_keylist(adt, fcu, &fcu_keys, 0);
+ struct AnimKeylist *keylist = ED_keylist_create();
+ fcurve_to_keylist(adt, fcu, keylist, 0);
- int fcu_sfra = motionpath_get_prev_prev_keyframe(mpt, &fcu_keys, current_frame);
- int fcu_efra = motionpath_get_next_next_keyframe(mpt, &fcu_keys, current_frame);
+ int fcu_sfra = motionpath_get_prev_prev_keyframe(mpt, keylist, current_frame);
+ int fcu_efra = motionpath_get_next_next_keyframe(mpt, keylist, current_frame);
/* Extend range further, since acceleration compensation propagates even further away. */
if (fcu->auto_smoothing != FCURVE_SMOOTH_NONE) {
- fcu_sfra = motionpath_get_prev_prev_keyframe(mpt, &fcu_keys, fcu_sfra);
- fcu_efra = motionpath_get_next_next_keyframe(mpt, &fcu_keys, fcu_efra);
+ fcu_sfra = motionpath_get_prev_prev_keyframe(mpt, keylist, fcu_sfra);
+ fcu_efra = motionpath_get_next_next_keyframe(mpt, keylist, fcu_efra);
}
if (fcu_sfra <= fcu_efra) {
@@ -342,14 +343,14 @@ static void motionpath_calculate_update_range(MPathTarget *mpt,
*r_efra = max_ii(*r_efra, fcu_efra);
}
- BLI_dlrbTree_free(&fcu_keys);
+ ED_keylist_free(keylist);
}
}
static void motionpath_free_free_tree_data(ListBase *targets)
{
LISTBASE_FOREACH (MPathTarget *, mpt, targets) {
- BLI_dlrbTree_free(&mpt->keys);
+ ED_keylist_free(mpt->keylist);
}
}
@@ -418,7 +419,7 @@ void animviz_calc_motionpaths(Depsgraph *depsgraph,
AnimData *adt = BKE_animdata_from_id(&mpt->ob_eval->id);
/* build list of all keyframes in active action for object or pchan */
- BLI_dlrbTree_init(&mpt->keys);
+ mpt->keylist = ED_keylist_create();
ListBase *fcurve_list = NULL;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list