[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57945] branches/soc-2013-depsgraph_mt/ source/blender: Move bevel list and path from Curve to Object datablock

Sergey Sharybin sergey.vfx at gmail.com
Tue Jul 2 21:23:19 CEST 2013


Revision: 57945
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57945
Author:   nazgul
Date:     2013-07-02 19:23:19 +0000 (Tue, 02 Jul 2013)
Log Message:
-----------
Move bevel list and path from Curve to Object datablock

I know this is not so much nice to have this guys hanging
around in a general Object datablock and ideally they better
be wrapped around into a structure like DerivedMesh or
something like this. But this is pure runtime only stuff and
we could re-wrap them around later.

Main purpose of this is making curves more thread safe,
so no separate threads will ever start freeing the same path
or the same bevel list.

It also makes sense because path and bevel shall include
deformation coming from modifiers which are applying on
pre-tesselation point and different objects could have
different set of modifiers. This used to be really confusing
in the past and now dtaa which depends on object is stored
in an object, making things clear for understanding even.

This doesn't make curve code fully thread-safe due to
pre-tesselation modifiers still modifies actual nurbs and
lock is still needed in makeDispListsCurveTypes, but this
change makes usage of paths safe for threading.

Once modifiers will stop modifying actual nurbs, curves
will be fully safe for threading.

Modified Paths:
--------------
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/anim.c
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/armature.c
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/constraint.c
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/curve.c
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/depsgraph.c
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/displist.c
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/effect.c
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/font.c
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/lattice.c
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/object.c
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/scene.c
    branches/soc-2013-depsgraph_mt/source/blender/blenloader/intern/readfile.c
    branches/soc-2013-depsgraph_mt/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2013-depsgraph_mt/source/blender/makesdna/DNA_curve_types.h
    branches/soc-2013-depsgraph_mt/source/blender/makesdna/DNA_object_types.h
    branches/soc-2013-depsgraph_mt/source/blender/modifiers/intern/MOD_array.c

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/anim.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/anim.c	2013-07-02 19:23:12 UTC (rev 57944)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/anim.c	2013-07-02 19:23:19 UTC (rev 57945)
@@ -509,11 +509,11 @@
 	}
 	cu = ob->data;
 
-	if (cu->path) free_path(cu->path);
-	cu->path = NULL;
+	if (ob->path) free_path(ob->path);
+	ob->path = NULL;
 	
 	/* weak! can only use first curve */
-	bl = cu->bev.first;
+	bl = ob->bev.first;
 	if (bl == NULL || !bl->nr) {
 		return;
 	}
@@ -521,7 +521,7 @@
 	nurbs = BKE_curve_nurbs_get(cu);
 	nu = nurbs->first;
 
-	cu->path = path = MEM_callocN(sizeof(Path), "calc_curvepath");
+	ob->path = path = MEM_callocN(sizeof(Path), "calc_curvepath");
 	
 	/* if POLY: last vertice != first vertice */
 	cycl = (bl->poly != -1);
@@ -630,15 +630,15 @@
 
 	if (ob == NULL || ob->type != OB_CURVE) return 0;
 	cu = ob->data;
-	if (cu->path == NULL || cu->path->data == NULL) {
+	if (ob->path == NULL || ob->path->data == NULL) {
 		printf("no path!\n");
 		return 0;
 	}
-	path = cu->path;
+	path = ob->path;
 	pp = path->data;
 	
 	/* test for cyclic */
-	bl = cu->bev.first;
+	bl = ob->bev.first;
 	if (!bl) return 0;
 	if (!bl->nr) return 0;
 	if (bl->poly > -1) cycl = 1;

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/armature.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/armature.c	2013-07-02 19:23:12 UTC (rev 57944)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/armature.c	2013-07-02 19:23:19 UTC (rev 57945)
@@ -1816,18 +1816,16 @@
 	 *     - this is a workaround for a depsgraph bug...
 	 */
 	if (ikData->tar) {
-		Curve *cu = ikData->tar->data;
-
 		/* note: when creating constraints that follow path, the curve gets the CU_PATH set now,
 		 *       currently for paths to work it needs to go through the bevlist/displist system (ton)
 		 */
 
 		/* only happens on reload file, but violates depsgraph still... fix! */
-		if (ELEM(NULL, cu->path, cu->path->data)) {
+		if (ELEM(NULL, ikData->tar->path, ikData->tar->path->data)) {
 			BKE_displist_make_curveTypes(scene, ikData->tar, 0);
 			
 			/* path building may fail in EditMode after removing verts [#33268]*/
-			if (ELEM(NULL, cu->path, cu->path->data)) {
+			if (ELEM(NULL, ikData->tar->path, ikData->tar->path->data)) {
 				/* BLI_assert(cu->path != NULL); */
 				return;
 			}
@@ -1891,7 +1889,6 @@
 	 * since it's easier to determine the positions of all the joints beforehand this way
 	 */
 	if ((ikData->flag & CONSTRAINT_SPLINEIK_SCALE_LIMITED) && (totLength != 0.0f)) {
-		Curve *cu = (Curve *)ikData->tar->data;
 		float splineLen, maxScale;
 		int i;
 
@@ -1904,7 +1901,7 @@
 
 		/* get the current length of the curve */
 		/* NOTE: this is assumed to be correct even after the curve was resized */
-		splineLen = cu->path->totdist;
+		splineLen = ikData->tar->path->totdist;
 
 		/* calculate the scale factor to multiply all the path values by so that the
 		 * bone chain retains its current length, such that

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/constraint.c	2013-07-02 19:23:12 UTC (rev 57944)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/constraint.c	2013-07-02 19:23:19 UTC (rev 57945)
@@ -1164,10 +1164,10 @@
 		 */
 		
 		/* only happens on reload file, but violates depsgraph still... fix! */
-		if (cu->path == NULL || cu->path->data == NULL)
+		if (ct->tar->path == NULL || ct->tar->path->data == NULL)
 			BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
 		
-		if (cu->path && cu->path->data) {
+		if (ct->tar->path && ct->tar->path->data) {
 			float quat[4];
 			if ((data->followflag & FOLLOWPATH_STATIC) == 0) {
 				/* animated position along curve depending on time */
@@ -1934,10 +1934,8 @@
 	if (VALID_CONS_TARGET(ct)) {
 		/* special exception for curves - depsgraph issues */
 		if (ct->tar->type == OB_CURVE) {
-			Curve *cu = ct->tar->data;
-			
 			/* this check is to make sure curve objects get updated on file load correctly.*/
-			if (cu->path == NULL || cu->path->data == NULL) /* only happens on reload file, but violates depsgraph still... fix! */
+			if (ct->tar->path == NULL || ct->tar->path->data == NULL) /* only happens on reload file, but violates depsgraph still... fix! */
 				BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
 		}
 		
@@ -3008,14 +3006,12 @@
 static void clampto_get_tarmat(bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
 {
 	if (VALID_CONS_TARGET(ct)) {
-		Curve *cu = ct->tar->data;
-		
 		/* note: when creating constraints that follow path, the curve gets the CU_PATH set now,
 		 *		currently for paths to work it needs to go through the bevlist/displist system (ton) 
 		 */
 		
 		/* only happens on reload file, but violates depsgraph still... fix! */
-		if (cu->path == NULL || cu->path->data == NULL)
+		if (ct->tar->path == NULL || ct->tar->path->data == NULL)
 			BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
 	}
 	
@@ -3033,7 +3029,6 @@
 	
 	/* only evaluate if there is a target and it is a curve */
 	if (VALID_CONS_TARGET(ct) && (ct->tar->type == OB_CURVE)) {
-		Curve *cu = data->tar->data;
 		float obmat[4][4], ownLoc[3];
 		float curveMin[3], curveMax[3];
 		float targetMatrix[4][4] = MAT4_UNITY;
@@ -3046,7 +3041,7 @@
 		BKE_object_minmax(ct->tar, curveMin, curveMax, TRUE);
 		
 		/* get targetmatrix */
-		if (cu->path && cu->path->data) {
+		if (data->tar->path && data->tar->path->data) {
 			float vec[4], dir[3], totmat[4][4];
 			float curvetime;
 			short clamp_axis;
@@ -3649,14 +3644,12 @@
 static void splineik_get_tarmat(bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
 {
 	if (VALID_CONS_TARGET(ct)) {
-		Curve *cu = ct->tar->data;
-		
 		/* note: when creating constraints that follow path, the curve gets the CU_PATH set now,
 		 *		currently for paths to work it needs to go through the bevlist/displist system (ton) 
 		 */
 		
 		/* only happens on reload file, but violates depsgraph still... fix! */
-		if (cu->path == NULL || cu->path->data == NULL)
+		if (ct->tar->path == NULL || ct->tar->path->data == NULL)
 			BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
 	}
 	

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/curve.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/curve.c	2013-07-02 19:23:12 UTC (rev 57944)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/curve.c	2013-07-02 19:23:19 UTC (rev 57945)
@@ -145,7 +145,6 @@
 void BKE_curve_free(Curve *cu)
 {
 	BKE_nurbList_free(&cu->nurb);
-	BLI_freelistN(&cu->bev);
 	BKE_curve_editfont_free(cu);
 
 	BKE_curve_editNurb_free(cu);
@@ -160,8 +159,6 @@
 		MEM_freeN(cu->strinfo);
 	if (cu->bb)
 		MEM_freeN(cu->bb);
-	if (cu->path)
-		free_path(cu->path);
 	if (cu->tb)
 		MEM_freeN(cu->tb);
 }
@@ -227,9 +224,6 @@
 	cun->key = BKE_key_copy(cu->key);
 	if (cun->key) cun->key->from = (ID *)cun;
 
-	cun->bev.first = cun->bev.last = NULL;
-	cun->path = NULL;
-
 	cun->editnurb = NULL;
 	cun->editfont = NULL;
 	cun->selboxes = NULL;
@@ -2264,16 +2258,19 @@
 	int a, b, nr, poly, resolu = 0, len = 0;
 	int do_tilt, do_radius, do_weight;
 	int is_editmode = 0;
+	ListBase *bev;
 
 	/* this function needs an object, because of tflag and upflag */
 	cu = ob->data;
 
+	bev = &ob->bev;
+
 	/* do we need to calculate the radius for each point? */
 	/* do_radius = (cu->bevobj || cu->taperobj || (cu->flag & CU_FRONT) || (cu->flag & CU_BACK)) ? 0 : 1; */
 
 	/* STEP 1: MAKE POLYS  */
 
-	BLI_freelistN(&(cu->bev));
+	BLI_freelistN(&(ob->bev));
 	if (cu->editnurb && ob->type != OB_FONT) {
 		ListBase *nurbs = BKE_curve_editNurbs_get(cu);
 		nu = nurbs->first;
@@ -2297,7 +2294,7 @@
 		 * enforced in the UI but can go wrong possibly */
 		if (!BKE_nurb_check_valid_u(nu)) {
 			bl = MEM_callocN(sizeof(BevList) + 1 * sizeof(BevPoint), "makeBevelList1");
-			BLI_addtail(&(cu->bev), bl);
+			BLI_addtail(bev, bl);
 			bl->nr = 0;
 		}
 		else {
@@ -2309,7 +2306,7 @@
 			if (nu->type == CU_POLY) {
 				len = nu->pntsu;
 				bl = MEM_callocN(sizeof(BevList) + len * sizeof(BevPoint), "makeBevelList2");
-				BLI_addtail(&(cu->bev), bl);
+				BLI_addtail(bev, bl);
 
 				if (nu->flagu & CU_NURB_CYCLIC) bl->poly = 0;
 				else bl->poly = -1;
@@ -2332,7 +2329,7 @@
 				/* in case last point is not cyclic */
 				len = resolu * (nu->pntsu + (nu->flagu & CU_NURB_CYCLIC) - 1) + 1;
 				bl = MEM_callocN(sizeof(BevList) + len * sizeof(BevPoint), "makeBevelBPoints");
-				BLI_addtail(&(cu->bev), bl);
+				BLI_addtail(bev, bl);
 
 				if (nu->flagu & CU_NURB_CYCLIC) bl->poly = 0;
 				else bl->poly = -1;
@@ -2418,7 +2415,7 @@
 					len = (resolu * SEGMENTSU(nu));
 
 					bl = MEM_callocN(sizeof(BevList) + len * sizeof(BevPoint), "makeBevelList3");
-					BLI_addtail(&(cu->bev), bl);
+					BLI_addtail(bev, bl);
 					bl->nr = len;
 					bl->dupe_nr = 0;
 					if (nu->flagu & CU_NURB_CYCLIC) bl->poly = 0;
@@ -2436,7 +2433,7 @@
 	}
 
 	/* STEP 2: DOUBLE POINTS AND AUTOMATIC RESOLUTION, REDUCE DATABLOCKS */
-	bl = cu->bev.first;
+	bl = bev->first;
 	while (bl) {
 		if (bl->nr) { /* null bevel items come from single points */
 			nr = bl->nr;
@@ -2458,7 +2455,7 @@
 		}
 		bl = bl->next;
 	}
-	bl = cu->bev.first;
+	bl = bev->first;
 	while (bl) {
 		blnext = bl->next;
 		if (bl->nr && bl->dupe_nr) {
@@ -2466,8 +2463,8 @@
 			blnew = MEM_mallocN(sizeof(BevList) + nr * sizeof(BevPoint), "makeBevelList4");
 			memcpy(blnew, bl, sizeof(BevList));
 			blnew->nr = 0;
-			BLI_remlink(&(cu->bev), bl);
-			BLI_insertlinkbefore(&(cu->bev), blnext, blnew);    /* to make sure bevlijst is tuned with nurblist */
+			BLI_remlink(bev, bl);
+			BLI_insertlinkbefore(bev, blnext, blnew);    /* to make sure bevlijst is tuned with nurblist */
 			bevp0 = (BevPoint *)(bl + 1);
 			bevp1 = (BevPoint *)(blnew + 1);
 			nr = bl->nr;
@@ -2486,7 +2483,7 @@
 	}
 
 	/* STEP 3: POLYS COUNT AND AUTOHOLE */
-	bl = cu->bev.first;
+	bl = bev->first;
 	poly = 0;
 	while (bl) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list