[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46333] trunk/blender/source/blender/ blenkernel: Simplifying constraints code - removed relink_data() callbacks in favour of a

Joshua Leung aligorith at gmail.com
Sun May 6 03:27:52 CEST 2012


Revision: 46333
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46333
Author:   aligorith
Date:     2012-05-06 01:27:48 +0000 (Sun, 06 May 2012)
Log Message:
-----------
Simplifying constraints code - removed relink_data() callbacks in favour of a
more generic system which goes through id_looper(), reducing the maintainance
burden for new constraint authors

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_constraint.h
    trunk/blender/source/blender/blenkernel/intern/constraint.c

Modified: trunk/blender/source/blender/blenkernel/BKE_constraint.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_constraint.h	2012-05-06 01:03:51 UTC (rev 46332)
+++ trunk/blender/source/blender/blenkernel/BKE_constraint.h	2012-05-06 01:27:48 UTC (rev 46333)
@@ -87,8 +87,6 @@
 	/* data management function pointers - special handling */
 		/* free any data that is allocated separately (optional) */
 	void (*free_data)(struct bConstraint *con);
-		/* adjust pointer to other ID-data using ID_NEW(), but not to targets (optional) */
-	void (*relink_data)(struct bConstraint *con);
 		/* run the provided callback function on all the ID-blocks linked to the constraint */
 	void (*id_looper)(struct bConstraint *con, ConstraintIDFunc func, void *userdata);
 		/* copy any special data that is allocated separately (optional) */

Modified: trunk/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/constraint.c	2012-05-06 01:03:51 UTC (rev 46332)
+++ trunk/blender/source/blender/blenkernel/intern/constraint.c	2012-05-06 01:27:48 UTC (rev 46333)
@@ -648,7 +648,6 @@
 	"ConstrName", /* name */
 	"bConstrNameConstraint", /* struct name */
 	constrname_free, /* free data */
-	constrname_relink, /* relink data */
 	constrname_id_looper, /* id looper */
 	constrname_copy, /* copy data */
 	constrname_new_data, /* new data */
@@ -874,7 +873,7 @@
 			 */
 			copy_m4_m4(tempmat, cob->matrix);
 			mult_m4_m4m4(cob->matrix, parmat, tempmat);
-
+			
 			/* without this, changes to scale and rotation can change location
 			 * of a parentless bone or a disconnected bone. Even though its set
 			 * to zero above. */
@@ -892,7 +891,6 @@
 	"ChildOf", /* name */
 	"bChildOfConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	childof_id_looper, /* id looper */
 	NULL, /* copy data */
 	childof_new_data, /* new data */
@@ -1070,7 +1068,6 @@
 	"TrackTo", /* name */
 	"bTrackToConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	trackto_id_looper, /* id looper */
 	NULL, /* copy data */
 	trackto_new_data, /* new data */
@@ -1164,7 +1161,6 @@
 	"IK", /* name */
 	"bKinematicConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	kinematic_id_looper, /* id looper */
 	NULL, /* copy data */
 	kinematic_new_data, /* new data */
@@ -1350,7 +1346,6 @@
 	"Follow Path", /* name */
 	"bFollowPathConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	followpath_id_looper, /* id looper */
 	NULL, /* copy data */
 	followpath_new_data, /* new data */
@@ -1399,7 +1394,6 @@
 	"Limit Location", /* name */
 	"bLocLimitConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	NULL, /* id looper */
 	NULL, /* copy data */
 	NULL, /* new data */
@@ -1457,7 +1451,6 @@
 	"Limit Rotation", /* name */
 	"bRotLimitConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	NULL, /* id looper */
 	NULL, /* copy data */
 	NULL, /* new data */
@@ -1517,7 +1510,6 @@
 	"Limit Scaling", /* name */
 	"bSizeLimitConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	NULL, /* id looper */
 	NULL, /* copy data */
 	NULL, /* new data */
@@ -1608,7 +1600,6 @@
 	"Copy Location", /* name */
 	"bLocateLikeConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	loclike_id_looper, /* id looper */
 	NULL, /* copy data */
 	loclike_new_data, /* new data */
@@ -1721,7 +1712,6 @@
 	"Copy Rotation", /* name */
 	"bRotateLikeConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	rotlike_id_looper, /* id looper */
 	NULL, /* copy data */
 	rotlike_new_data, /* new data */
@@ -1818,7 +1808,6 @@
 	"Copy Scale", /* name */
 	"bSizeLikeConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	sizelike_id_looper, /* id looper */
 	NULL, /* copy data */
 	sizelike_new_data, /* new data */
@@ -1880,7 +1869,6 @@
 	"Copy Transforms", /* name */
 	"bTransLikeConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	translike_id_looper, /* id looper */
 	NULL, /* copy data */
 	NULL, /* new data */
@@ -1937,7 +1925,6 @@
 	"Maintain Volume", /* name */
 	"bSameVolumeConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	NULL, /* id looper */
 	NULL, /* copy data */
 	samevolume_new_data, /* new data */
@@ -1961,13 +1948,6 @@
 	BLI_freelistN(&data->targets);
 }	
 
-static void pycon_relink (bConstraint *con)
-{
-	bPythonConstraint *data= con->data;
-	
-	ID_NEW(data->text);
-}
-
 static void pycon_copy (bConstraint *con, bConstraint *srccon)
 {
 	bPythonConstraint *pycon = (bPythonConstraint *)con->data;
@@ -2076,7 +2056,6 @@
 	"Script", /* name */
 	"bPythonConstraint", /* struct name */
 	pycon_free, /* free data */
-	pycon_relink, /* relink data */
 	pycon_id_looper, /* id looper */
 	pycon_copy, /* copy data */
 	pycon_new_data, /* new data */
@@ -2088,12 +2067,6 @@
 
 /* -------- Action Constraint ----------- */
 
-static void actcon_relink (bConstraint *con)
-{
-	bActionConstraint *data= con->data;
-	ID_NEW(data->act);
-}
-
 static void actcon_new_data (void *cdata)
 {
 	bActionConstraint *data= (bActionConstraint *)cdata;
@@ -2248,7 +2221,6 @@
 	"Action", /* name */
 	"bActionConstraint", /* struct name */
 	NULL, /* free data */
-	actcon_relink, /* relink data */
 	actcon_id_looper, /* id looper */
 	NULL, /* copy data */
 	actcon_new_data, /* new data */
@@ -2560,7 +2532,6 @@
 	"Locked Track", /* name */
 	"bLockTrackConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	locktrack_id_looper, /* id looper */
 	NULL, /* copy data */
 	locktrack_new_data, /* new data */
@@ -2685,7 +2656,6 @@
 	"Limit Distance", /* name */
 	"bDistLimitConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	distlimit_id_looper, /* id looper */
 	NULL, /* copy data */
 	distlimit_new_data, /* new data */
@@ -2860,7 +2830,6 @@
 	"Stretch To", /* name */
 	"bStretchToConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	stretchto_id_looper, /* id looper */
 	NULL, /* copy data */
 	stretchto_new_data, /* new data */
@@ -3005,7 +2974,6 @@
 	"Floor", /* name */
 	"bMinMaxConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	minmax_id_looper, /* id looper */
 	NULL, /* copy data */
 	minmax_new_data, /* new data */
@@ -3066,7 +3034,6 @@
 	"Rigid Body Joint", /* name */
 	"bRigidBodyJointConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	rbj_id_looper, /* id looper */
 	NULL, /* copy data */
 	rbj_new_data, /* new data */
@@ -3242,7 +3209,6 @@
 	"Clamp To", /* name */
 	"bClampToConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	clampto_id_looper, /* id looper */
 	NULL, /* copy data */
 	NULL, /* new data */
@@ -3389,7 +3355,6 @@
 	"Transform", /* name */
 	"bTransformConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	transform_id_looper, /* id looper */
 	NULL, /* copy data */
 	transform_new_data, /* new data */
@@ -3547,7 +3512,6 @@
 	"Shrinkwrap", /* name */
 	"bShrinkwrapConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	shrinkwrap_id_looper, /* id looper */
 	NULL, /* copy data */
 	NULL, /* new data */
@@ -3675,7 +3639,6 @@
 	"Damped Track", /* name */
 	"bDampTrackConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	damptrack_id_looper, /* id looper */
 	NULL, /* copy data */
 	damptrack_new_data, /* new data */
@@ -3773,7 +3736,6 @@
 	"Spline IK", /* name */
 	"bSplineIKConstraint", /* struct name */
 	splineik_free, /* free data */
-	NULL, /* relink data */
 	splineik_id_looper, /* id looper */
 	splineik_copy, /* copy data */
 	splineik_new_data, /* new data */
@@ -3898,7 +3860,6 @@
 	"Pivot", /* name */
 	"bPivotConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	pivotcon_id_looper, /* id looper */
 	NULL, /* copy data */
 	NULL, /* new data */ // XXX: might be needed to get 'normal' pivot behavior...
@@ -4092,7 +4053,6 @@
 	"Follow Track", /* name */
 	"bFollowTrackConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	followtrack_id_looper, /* id looper */
 	NULL, /* copy data */
 	followtrack_new_data, /* new data */
@@ -4147,7 +4107,6 @@
 	"Camera Solver", /* name */
 	"bCameraSolverConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	camerasolver_id_looper, /* id looper */
 	NULL, /* copy data */
 	camerasolver_new_data, /* new data */
@@ -4221,7 +4180,6 @@
 	"Object Solver", /* name */
 	"bObjectSolverConstraint", /* struct name */
 	NULL, /* free data */
-	NULL, /* relink data */
 	objectsolver_id_looper, /* id looper */
 	NULL, /* copy data */
 	objectsolver_new_data, /* new data */
@@ -4501,36 +4459,27 @@
 
 /* ......... */
 
+/* helper for relink_constraints() - call ID_NEW() on every ID reference the constraint has */
+static void con_relink_id_cb(bConstraint *UNUSED(con), ID **idpoin, short UNUSED(isReference), void *UNUSED(userdata))
+{
+	/* ID_NEW() expects a struct with inline "id" member as first
+	 * since we've got the actual ID block, let's just inline this
+	 * code. 
+	 *
+	 * See ID_NEW(a) in BKE_utildefines.h
+	 */
+	if ((*idpoin) && (*idpoin)->newid)
+		(*idpoin) = (void *)(*idpoin)->newid;
+}
+
 /* Reassign links that constraints have to other data (called during file loading?) */
 void relink_constraints(ListBase *conlist)
 {
-	bConstraint *con;
-	bConstraintTarget *ct;
-	
-	for (con= conlist->first; con; con= con->next) {
-		bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
-		
-		if (cti) {
-			/* relink any targets */
-			if (cti->get_constraint_targets) {
-				ListBase targets = {NULL, NULL};
-				
-				cti->get_constraint_targets(con, &targets);
-				for (ct= targets.first; ct; ct= ct->next) {
-					ID_NEW(ct->tar);
-				}
-				
-				if (cti->flush_constraint_targets)
-					cti->flush_constraint_targets(con, &targets, 0);
-			}
-			
-			/* relink any other special data */
-			if (cti->relink_data)
-				cti->relink_data(con);
-		}
-	}
+	/* just a wrapper around ID-loop for just calling ID_NEW() on all ID refs */
+	id_loop_constraints(conlist, con_relink_id_cb, NULL);
 }
 
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list