[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60998] trunk/blender/source/blender/ editors: Make anim system safer for threading

Sergey Sharybin sergey.vfx at gmail.com
Tue Oct 29 19:10:49 CET 2013


Revision: 60998
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60998
Author:   nazgul
Date:     2013-10-29 18:10:48 +0000 (Tue, 29 Oct 2013)
Log Message:
-----------
Make anim system safer for threading

Remove usages of ANIM_unit_mapping_apply_fcurve in favor of
runtime scale factor apply.

There're still calls to ANIM_nla_mapping_apply_fcurve are
hanging around, they're the next t be cleaned up!

Modified Paths:
--------------
    trunk/blender/source/blender/editors/animation/anim_draw.c
    trunk/blender/source/blender/editors/include/ED_anim_api.h
    trunk/blender/source/blender/editors/space_graph/graph_draw.c
    trunk/blender/source/blender/editors/space_graph/graph_edit.c
    trunk/blender/source/blender/editors/space_graph/graph_select.c
    trunk/blender/source/blender/editors/transform/transform_conversions.c
    trunk/blender/source/blender/editors/transform/transform_generics.c

Modified: trunk/blender/source/blender/editors/animation/anim_draw.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_draw.c	2013-10-29 17:46:01 UTC (rev 60997)
+++ trunk/blender/source/blender/editors/animation/anim_draw.c	2013-10-29 18:10:48 UTC (rev 60998)
@@ -389,76 +389,4 @@
 	return 1.0f;
 }
 
-/* ----------------------- */
-
-/* helper function for ANIM_unit_mapping_apply_fcurve -> mapping callback for unit mapping */
-static short bezt_unit_mapping_apply(KeyframeEditData *ked, BezTriple *bezt)
-{
-	/* mapping factor is stored in f1, flags are stored in i1 */
-	const bool only_keys = (ked->i1 & ANIM_UNITCONV_ONLYKEYS) != 0;
-	const bool sel_vs = (ked->i1 & ANIM_UNITCONV_SELVERTS) != 0;
-	const bool skip_knot = (ked->i1 & ANIM_UNITCONV_SKIPKNOTS) != 0;
-	float fac = ked->f1;
-	
-	/* adjust BezTriple handles only if allowed to */
-	if (only_keys == false) {
-		if ((sel_vs == false) || (bezt->f1 & SELECT))
-			bezt->vec[0][1] *= fac;
-		if ((sel_vs == false) || (bezt->f3 & SELECT))
-			bezt->vec[2][1] *= fac;
-	}
-	
-	if (skip_knot == false) {
-		if ((sel_vs == false) || (bezt->f2 & SELECT))
-			bezt->vec[1][1] *= fac;
-	}
-	
-	return 0;
-}
-
-/* Apply/Unapply units conversions to keyframes */
-void ANIM_unit_mapping_apply_fcurve(Scene *scene, ID *id, FCurve *fcu, short flag)
-{
-	KeyframeEditData ked;
-	KeyframeEditFunc sel_cb;
-	float fac;
-	
-	/* abort if rendering - we may get some race condition issues... */
-	if (G.is_rendering) return;
-	
-	/* calculate mapping factor, and abort if nothing to change */
-	fac = ANIM_unit_mapping_get_factor(scene, id, fcu, (flag & ANIM_UNITCONV_RESTORE));
-	if (fac == 1.0f)
-		return;
-	
-	/* init edit data 
-	 *	- mapping factor is stored in f1
-	 *	- flags are stored in 'i1'
-	 */
-	memset(&ked, 0, sizeof(KeyframeEditData));
-	ked.f1 = (float)fac;
-	ked.i1 = (int)flag;
-	
-	/* only selected? */
-	if (flag & ANIM_UNITCONV_ONLYSEL)
-		sel_cb = ANIM_editkeyframes_ok(BEZT_OK_SELECTED);
-	else
-		sel_cb = NULL;
-	
-	/* apply to F-Curve */
-	ANIM_fcurve_keyframes_loop(&ked, fcu, sel_cb, bezt_unit_mapping_apply, NULL);
-	
-	// FIXME: loop here for samples should be generalised
-	// TODO: only sel?
-	if (fcu->fpt) {
-		FPoint *fpt;
-		unsigned int i;
-		
-		for (i = 0, fpt = fcu->fpt; i < fcu->totvert; i++, fpt++) {
-			/* apply unit mapping */
-			fpt->vec[1] *= fac;
-		}
-	}
-}
-
 /* *************************************************** */

Modified: trunk/blender/source/blender/editors/include/ED_anim_api.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_anim_api.h	2013-10-29 17:46:01 UTC (rev 60997)
+++ trunk/blender/source/blender/editors/include/ED_anim_api.h	2013-10-29 18:10:48 UTC (rev 60998)
@@ -564,9 +564,6 @@
 /* Get unit conversion factor for given ID + F-Curve */
 float ANIM_unit_mapping_get_factor(struct Scene *scene, struct ID *id, struct FCurve *fcu, short restore);
 
-/* Apply/Unapply units conversions to keyframes */
-void ANIM_unit_mapping_apply_fcurve(struct Scene *scene, struct ID *id, struct FCurve *fcu, short flag);
-
 /* ------------- Utility macros ----------------------- */
 
 /* provide access to Keyframe Type info in BezTriple

Modified: trunk/blender/source/blender/editors/space_graph/graph_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_draw.c	2013-10-29 17:46:01 UTC (rev 60997)
+++ trunk/blender/source/blender/editors/space_graph/graph_draw.c	2013-10-29 18:10:48 UTC (rev 60998)
@@ -206,7 +206,7 @@
 }
 
 /* helper func - draw handle vertices only for an F-Curve (if it is not protected) */
-static void draw_fcurve_vertices_handles(FCurve *fcu, SpaceIpo *sipo, View2D *v2d, short sel, short sel_handle_only)
+static void draw_fcurve_vertices_handles(FCurve *fcu, SpaceIpo *sipo, View2D *v2d, short sel, short sel_handle_only, float units_scale)
 {
 	BezTriple *bezt = fcu->bezt;
 	BezTriple *prevbezt = NULL;
@@ -216,6 +216,9 @@
 	/* get view settings */
 	hsize = UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE) * U.pixelsize;
 	UI_view2d_getscale(v2d, &xscale, &yscale);
+
+	/* Compensate OGL scale sued for unit mapping, so circle will be circle, not ellipse */
+	yscale *= units_scale;
 	
 	/* set handle color */
 	if (sel) UI_ThemeColor(TH_HANDLE_VERTEX_SELECT);
@@ -271,7 +274,7 @@
 }
 
 
-static void draw_fcurve_vertices(SpaceIpo *sipo, ARegion *ar, FCurve *fcu, short do_handles, short sel_handle_only)
+static void draw_fcurve_vertices(SpaceIpo *sipo, ARegion *ar, FCurve *fcu, short do_handles, short sel_handle_only, float units_scale)
 {
 	View2D *v2d = &ar->v2d;
 	
@@ -287,10 +290,10 @@
 	/* draw the two handles first (if they're shown, the curve doesn't have just a single keyframe, and the curve is being edited) */
 	if (do_handles) {
 		set_fcurve_vertex_color(fcu, 0);
-		draw_fcurve_vertices_handles(fcu, sipo, v2d, 0, sel_handle_only);
+		draw_fcurve_vertices_handles(fcu, sipo, v2d, 0, sel_handle_only, units_scale);
 		
 		set_fcurve_vertex_color(fcu, 1);
-		draw_fcurve_vertices_handles(fcu, sipo, v2d, 1, sel_handle_only);
+		draw_fcurve_vertices_handles(fcu, sipo, v2d, 1, sel_handle_only, units_scale);
 	}
 		
 	/* draw keyframes over the handles */
@@ -547,12 +550,15 @@
 	FPoint *fpt = prevfpt + 1;
 	float fac, v[2];
 	int b = fcu->totvert - 1;
-	
+	float unit_scale;
+
+	/* apply unit mapping */
+	glPushMatrix();
+	unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, 0);
+	glScalef(1.0f, unit_scale, 1.0f);
+
 	glBegin(GL_LINE_STRIP);
 	
-	/* apply unit mapping */
-	ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 0);
-	
 	/* extrapolate to left? - left-side of view comes before first keyframe? */
 	if (prevfpt->vec[0] > v2d->cur.xmin) {
 		v[0] = v2d->cur.xmin;
@@ -611,10 +617,8 @@
 		glVertex2fv(v);
 	}
 	
-	/* unapply unit mapping */
-	ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, ANIM_UNITCONV_RESTORE);
-	
 	glEnd();
+	glPopMatrix();
 }
 
 /* helper func - draw one repeat of an F-Curve */
@@ -627,12 +631,15 @@
 	float fac = 0.0f;
 	int b = fcu->totvert - 1;
 	int resol;
-	
+	float unit_scale;
+
+	/* apply unit mapping */
+	glPushMatrix();
+	unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, 0);
+	glScalef(1.0f, unit_scale, 1.0f);
+
 	glBegin(GL_LINE_STRIP);
 	
-	/* apply unit mapping */
-	ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, 0);
-	
 	/* extrapolate to left? */
 	if (prevbezt->vec[1][0] > v2d->cur.xmin) {
 		/* left-side of view comes before first keyframe, so need to extend as not cyclic */
@@ -766,10 +773,8 @@
 		glVertex2fv(v1);
 	}
 	
-	/* unapply unit mapping */
-	ANIM_unit_mapping_apply_fcurve(ac->scene, id, fcu, ANIM_UNITCONV_RESTORE);
-	
 	glEnd();
+	glPopMatrix();
 } 
 
 /* Debugging -------------------------------- */
@@ -1014,9 +1019,11 @@
 				}
 			}
 			else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) {
-				/* apply unit mapping */
-				ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, 0);
-				
+				float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, 0);
+
+				glPushMatrix();
+				glScalef(1.0f, unit_scale, 1.0f);
+
 				if (fcu->bezt) {
 					int do_handles = draw_fcurve_handles_check(sipo, fcu);
 					
@@ -1027,15 +1034,14 @@
 						glDisable(GL_BLEND);
 					}
 					
-					draw_fcurve_vertices(sipo, ar, fcu, do_handles, (sipo->flag & SIPO_SELVHANDLESONLY));
+					draw_fcurve_vertices(sipo, ar, fcu, do_handles, (sipo->flag & SIPO_SELVHANDLESONLY), unit_scale);
 				}
 				else {
 					/* samples: only draw two indicators at either end as indicators */
 					draw_fcurve_samples(sipo, ar, fcu);
 				}
-				
-				/* unapply unit mapping */
-				ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, ANIM_UNITCONV_RESTORE);
+
+				glPopMatrix();
 			}
 		}
 		

Modified: trunk/blender/source/blender/editors/space_graph/graph_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_edit.c	2013-10-29 17:46:01 UTC (rev 60997)
+++ trunk/blender/source/blender/editors/space_graph/graph_edit.c	2013-10-29 18:10:48 UTC (rev 60998)
@@ -1787,20 +1787,23 @@
 	
 	for (ale = anim_data.first; ale; ale = ale->next) {
 		AnimData *adt = ANIM_nla_mapping_get(&ac, ale);
-		
-		/* apply unit corrections */
-		ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYKEYS);
-		
+		KeyframeEditData current_ked;
+		float unit_scale = ANIM_unit_mapping_get_factor(ac.scene, ale->id, ale->key_data, ANIM_UNITCONV_ONLYKEYS);
+
+		memset(&current_ked, 0, sizeof(current_ked));
+
 		if (adt) {
 			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); 
-			ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_calc_average, NULL);
+			ANIM_fcurve_keyframes_loop(&current_ked, ale->key_data, NULL, bezt_calc_average, NULL);
 			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1); 
 		}
 		else
-			ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_calc_average, NULL);
-		
-		/* unapply unit corrections */
-		ANIM_unit_mapping_apply_fcurve(ac.scene, ale->id, ale->key_data, ANIM_UNITCONV_RESTORE | ANIM_UNITCONV_ONLYKEYS);
+			ANIM_fcurve_keyframes_loop(&current_ked, ale->key_data, NULL, bezt_calc_average, NULL);
+
+		ked.f1 += current_ked.f1;
+		ked.i1 += current_ked.i1;
+		ked.f2 += current_ked.f2 / unit_scale;
+		ked.i2 += current_ked.i2;
 	}
 	
 	BLI_freelistN(&anim_data);
@@ -1865,6 +1868,7 @@
 	
 	KeyframeEditData ked;
 	KeyframeEditFunc edit_cb;
+	float cursor_value = 0.0f;
 	
 	/* filter data */
 	filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
@@ -1881,16 +1885,16 @@
 	}
 	else if (mode == GRAPHKEYS_SNAP_VALUE) {
 		SpaceIpo *sipo = (SpaceIpo *)ac->sl;
-		ked.f1 = (sipo) ? sipo->cursorVal : 0.0f;
+		cursor_value = (sipo) ? sipo->cursorVal : 0.0f;
 	}
 	
 	/* snap keyframes */
 	for (ale = anim_data.first; ale; ale = ale->next) {
 		AnimData *adt = ANIM_nla_mapping_get(ac, ale);
-		
-		/* apply unit corrections */
-		ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, ale->key_data, 0);
-		
+		float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, ale->key_data, 0);
+
+		ked.f1 = cursor_value / unit_scale;
+
 		if (adt) {
 			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1); 
 			ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve);
@@ -1898,9 +1902,6 @@
 		}
 		else 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list