Skip to content
Snippets Groups Projects
Commit 2aff2435 authored by Joshua Leung's avatar Joshua Leung
Browse files

Patch T36209: Use binary search function for evaluating F-Curves

This provides a speedup to evaluating long F-Curves in fcurve_eval_keyframes()
by using the pre-existing binarysearch_bezt_index() function (used for keyframe
insertion) to find the relevant BezTriple on the FCurve at the current evaltime.
The current code loops over all BezTriples (sometimes not even breaking from the
loop after cvalue has been evaluated).

Reviewer Notes:
- Unlike in the original patch, we use the old/existing logic instead of
  checking that (exact == true). See comments in code and also on the tracker
  entry for this patch for more details.

Patch By: Josh Wedlake
parent 0dd52d1b
No related branches found
No related tags found
No related merge requests found
...@@ -1924,6 +1924,7 @@ static float fcurve_eval_keyframes(FCurve *fcu, BezTriple *bezts, float evaltime ...@@ -1924,6 +1924,7 @@ static float fcurve_eval_keyframes(FCurve *fcu, BezTriple *bezts, float evaltime
unsigned int a; unsigned int a;
int b; int b;
float cvalue = 0.0f; float cvalue = 0.0f;
bool exact = false;
/* get pointers */ /* get pointers */
a = fcu->totvert - 1; a = fcu->totvert - 1;
...@@ -2038,8 +2039,21 @@ static float fcurve_eval_keyframes(FCurve *fcu, BezTriple *bezts, float evaltime ...@@ -2038,8 +2039,21 @@ static float fcurve_eval_keyframes(FCurve *fcu, BezTriple *bezts, float evaltime
} }
else { else {
/* evaltime occurs somewhere in the middle of the curve */ /* evaltime occurs somewhere in the middle of the curve */
for (a = 0; prevbezt && bezt && (a < fcu->totvert - 1); a++, prevbezt = bezt, bezt++) { /* - use binary search to find appropriate keyframes */
a = binarysearch_bezt_index(bezts, evaltime, fcu->totvert, &exact);
BLI_assert(a > 0); /* a == 0, prevbezt = invalid access */
bezt = bezts;
bezt += a;
prevbezt = bezt - 1;
/* use if the key is directly on the frame, rare cases this is needed else we get 0.0 instead. */ /* use if the key is directly on the frame, rare cases this is needed else we get 0.0 instead. */
/* NOTE: Although we could just check if exact == true here, the thresholds for equality are
* different (0.01 for exact, vs 1e-8 for SMALL_NUMBER). For backwards compatibility,
* and to avoid introducing regressions for a few rare cases, let's keep the old
* method/thresholds here for now.
* -- Aligorith (2014Mar14)
*/
if (fabsf(bezt->vec[1][0] - evaltime) < SMALL_NUMBER) { if (fabsf(bezt->vec[1][0] - evaltime) < SMALL_NUMBER) {
cvalue = bezt->vec[1][1]; cvalue = bezt->vec[1][1];
} }
...@@ -2084,8 +2098,7 @@ static float fcurve_eval_keyframes(FCurve *fcu, BezTriple *bezts, float evaltime ...@@ -2084,8 +2098,7 @@ static float fcurve_eval_keyframes(FCurve *fcu, BezTriple *bezts, float evaltime
if (b) { if (b) {
berekeny(v1[1], v2[1], v3[1], v4[1], opl, 1); berekeny(v1[1], v2[1], v3[1], v4[1], opl, 1);
cvalue = opl[0]; cvalue = opl[0];
break; /* break; */
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment