Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2007-08-07 15:26:39 +0400
committerJoshua Leung <aligorith@gmail.com>2007-08-07 15:26:39 +0400
commit44e030656295ffb597fc63f6f08c61fe4afaed59 (patch)
treea7cc23165c5e58d23efc2c1d877cf81da041a759 /source/blender/src/editipo.c
parentb3eb06f8a975094af1bd6ade2ab4b89c2f656d14 (diff)
== IPO Cleaning - Refactor ==
I've finally come to the conclusion that the old code used to clean up IPO-curves was utterly unsafe/unstable. It used to have a lot of memory-related bugs early on, which I had resolved, but still I found a file where this broke quite badly (thanks Cessen). Now the code should be saner, as it does away with that evil memory copying that seems to be at fault. It would be advisable to have this properly tested for a few days before considering it for inclusion in 2.45 (stable) branch.
Diffstat (limited to 'source/blender/src/editipo.c')
-rw-r--r--source/blender/src/editipo.c84
1 files changed, 31 insertions, 53 deletions
diff --git a/source/blender/src/editipo.c b/source/blender/src/editipo.c
index 80590f335f4..d111fab2692 100644
--- a/source/blender/src/editipo.c
+++ b/source/blender/src/editipo.c
@@ -3393,51 +3393,54 @@ void clean_ipo(void)
void clean_ipo_curve(IpoCurve *icu)
{
- BezTriple *bezt=NULL, *beztn=NULL;
- BezTriple *newb, *newbs;
- int totCount, newCount, i;
+ BezTriple *old_bezts, *bezt, *beztn;
+ BezTriple *lastb;
+ int totCount, i;
float thresh;
/* check if any points */
- if (!icu) return;
- totCount= icu->totvert;
- newCount= 1;
- if (totCount<=1) return;
+ if (icu == NULL || icu->totvert <= 1)
+ return;
/* get threshold for match-testing */
thresh= G.scene->toolsettings->clean_thresh;
- /* add first keyframe and setup tempolary array of beztriples */
- newb = newbs = MEM_callocN(sizeof(BezTriple)*totCount, "NewBezTriples");
- bezt= icu->bezt;
- *newb= *bezt;
- bezt++;
+ /* make a copy of the old BezTriples, and clear IPO curve */
+ old_bezts = icu->bezt;
+ totCount = icu->totvert;
+ icu->bezt = NULL;
+ icu->totvert = 0;
+
+ /* now insert first vertex */
+ bezt = old_bezts;
+ insert_vert_ipo(icu, bezt->vec[1][0], bezt->vec[1][1]);
/* loop through beztriples, comparing them */
- for (i=0; i<totCount && newCount<totCount; i++, bezt++) {
+ for (i=1; i<totCount; i++) {
float prev[2], cur[2], next[2];
- /* get references for quicker access */
- memcpy(prev, newb->vec[1], sizeof(float)*2);
- memcpy(cur, bezt->vec[1], sizeof(float)*2);
-
+ /* get BezTriples and their values */
if (i < (totCount - 1)) {
- beztn = (bezt + 1);
- memcpy(next, beztn->vec[1], sizeof(float)*2);
+ beztn = (old_bezts + (i+1));
+ next[0]= beztn->vec[1][0]; next[1]= beztn->vec[1][1];
}
else {
beztn = NULL;
next[0] = next[1] = 0.0f;
}
+ lastb= (icu->bezt + (icu->totvert - 1));
+ bezt= (old_bezts + i);
+
+ /* get references for quicker access */
+ prev[0] = lastb->vec[1][0]; prev[1] = lastb->vec[1][1];
+ cur[0] = bezt->vec[1][0]; cur[1] = bezt->vec[1][1];
/* check if current bezt occurs at same time as last ok */
if ((cur[0] - prev[0]) <= thresh) {
/* only add if values are a considerable distance apart */
if (IS_EQT(cur[1], prev[1], thresh) == 0) {
/* add new keyframe */
- newCount++;
- newb++;
- *newb = *bezt;
+ insert_vert_ipo(icu, cur[0], cur[1]);
}
}
else {
@@ -3446,51 +3449,26 @@ void clean_ipo_curve(IpoCurve *icu)
/* does current have same value as previous and next? */
if (IS_EQT(cur[1], prev[1], thresh) == 0) {
/* add new keyframe*/
- newb++;
- *newb = *bezt;
- newCount++;
+ insert_vert_ipo(icu, cur[0], cur[1]);
}
else if (IS_EQT(cur[1], next[1], thresh) == 0) {
/* add new keyframe */
- newb++;
- *newb = *bezt;
- newCount++;
+ insert_vert_ipo(icu, cur[0], cur[1]);
}
}
else {
/* add if value doesn't equal that of previous */
if (IS_EQT(cur[1], prev[1], thresh) == 0) {
/* add new keyframe */
- newb++;
- *newb = *bezt;
- newCount++;
+ insert_vert_ipo(icu, cur[0], cur[1]);
}
}
}
}
-
- /* we only need to free stuff if the number of verts changed */
- if (totCount != newCount) {
- BezTriple *newbz;
-
- /* make a copy of the array which uses only as much memory as is needed */
- newbz= MEM_callocN(sizeof(BezTriple)*newCount, "BezTriples");
- memcpy(newbz, newbs, sizeof(BezTriple)*newCount);
-
- /* free old arrays and assign new */
- MEM_freeN(icu->bezt);
- MEM_freeN(newbs);
- icu->bezt= newbz;
- icu->totvert= newCount;
- }
- else {
- /* free temporary memory we used */
- MEM_freeN(newbs);
- }
- /* fix up handles and make sure points are in order */
- sort_time_ipocurve(icu);
- calchandles_ipocurve(icu);
+ /* now free the memory used by the old BezTriples */
+ if (old_bezts)
+ MEM_freeN(old_bezts);
}
void smooth_ipo(void)