[Bf-blender-cvs] [df63195] master: Cleanup id->newid usage, initial work.

Bastien Montagne noreply at git.blender.org
Wed Nov 30 15:30:02 CET 2016


Commit: df63195d2a7bc374398b0b6dfa389db3b40f5a70
Author: Bastien Montagne
Date:   Wed Nov 30 15:25:54 2016 +0100
Branches: master
https://developer.blender.org/rBdf63195d2a7bc374398b0b6dfa389db3b40f5a70

Cleanup id->newid usage, initial work.

This aims at always ensuring that ID.newid (and relevant LIB_TAG_NEW)
stay in clean (i.e. cleared) state by default.

To achieve this, instead of clearing after all id copy call (would be
horribly noisy, and bad for performances), we try to completely remove
the setting of id->newid by default when copying a new ID.

This implies that areas actually needing that info (mainly, object editing
area (make single user...) and make local area) have to ensure they set
it themselves as needed.

This is far from simple change, many complex code paths to consider, so
will need some serious testing. :/

===================================================================

M	source/blender/blenkernel/BKE_animsys.h
M	source/blender/blenkernel/BKE_library.h
M	source/blender/blenkernel/intern/anim_sys.c
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/depsgraph.c
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/blenkernel/intern/sca.c
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenkernel/intern/sequencer.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/object/object_add.c
M	source/blender/editors/object/object_relations.c
M	source/blender/editors/space_outliner/outliner_tools.c
M	source/blender/editors/space_outliner/outliner_tree.c
M	source/blender/makesdna/DNA_ID.h
M	source/blender/makesrna/intern/rna_ID.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h
index 00ea323..a67e903 100644
--- a/source/blender/blenkernel/BKE_animsys.h
+++ b/source/blender/blenkernel/BKE_animsys.h
@@ -73,7 +73,7 @@ struct AnimData *BKE_animdata_copy(struct AnimData *adt, const bool do_action);
 bool BKE_animdata_copy_id(struct ID *id_to, struct ID *id_from, const bool do_action);
 
 /* Copy AnimData Actions */
-void BKE_animdata_copy_id_action(struct ID *id);
+void BKE_animdata_copy_id_action(struct ID *id, const bool set_newid);
 
 /* Merge copies of data from source AnimData block */
 typedef enum eAnimData_MergeCopy_Modes {
diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 855eb10..77ea7ec 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -80,6 +80,7 @@ void id_us_plus(struct ID *id);
 void id_us_min(struct ID *id);
 void id_fake_user_set(struct ID *id);
 void id_fake_user_clear(struct ID *id);
+void BKE_id_clear_newpoin(struct ID *id);
 
 void BKE_id_make_local_generic(struct Main *bmain, struct ID *id, const bool id_in_mainlist, const bool lib_local);
 bool id_make_local(struct Main *bmain, struct ID *id, const bool test, const bool force_local);
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index a5abc6b..2127939 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -308,17 +308,19 @@ bool BKE_animdata_copy_id(ID *id_to, ID *id_from, const bool do_action)
 	return true;
 }
 
-void BKE_animdata_copy_id_action(ID *id)
+void BKE_animdata_copy_id_action(ID *id, const bool set_newid)
 {
 	AnimData *adt = BKE_animdata_from_id(id);
 	if (adt) {
 		if (adt->action) {
 			id_us_min((ID *)adt->action);
-			adt->action = BKE_action_copy(G.main, adt->action);
+			adt->action = set_newid ? ID_NEW_SET(adt->action, BKE_action_copy(G.main, adt->action)) :
+			                          BKE_action_copy(G.main, adt->action);
 		}
 		if (adt->tmpact) {
 			id_us_min((ID *)adt->tmpact);
-			adt->tmpact = BKE_action_copy(G.main, adt->tmpact);
+			adt->tmpact = set_newid ? ID_NEW_SET(adt->tmpact, BKE_action_copy(G.main, adt->tmpact)) :
+			                          BKE_action_copy(G.main, adt->tmpact);
 		}
 	}
 }
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 8ef1fae..0d509ec 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -249,6 +249,9 @@ void BKE_brush_make_local(Main *bmain, Brush *brush, const bool lib_local)
 
 			brush_new->id.us = 0;
 
+			/* setting newid is mandatory for complex make_lib_local logic... */
+			ID_NEW_SET(brush, brush_new);
+
 			if (!lib_local) {
 				BKE_libblock_remap(bmain, brush, brush_new, ID_REMAP_SKIP_INDIRECT_USAGE);
 			}
diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c
index 50f8423..7361645 100644
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ b/source/blender/blenkernel/intern/depsgraph.c
@@ -1428,7 +1428,6 @@ static void scene_sort_groups(Main *bmain, Scene *sce)
 	/* test; are group objects all in this scene? */
 	for (ob = bmain->object.first; ob; ob = ob->id.next) {
 		ob->id.tag &= ~LIB_TAG_DOIT;
-		ob->id.newid = NULL; /* newid abuse for GroupObject */
 	}
 	for (base = sce->base.first; base; base = base->next)
 		base->object->id.tag |= LIB_TAG_DOIT;
@@ -1459,6 +1458,11 @@ static void scene_sort_groups(Main *bmain, Scene *sce)
 			group->gobject = listb;
 		}
 	}
+
+	/* newid abused for GroupObject, cleanup. */
+	for (ob = bmain->object.first; ob; ob = ob->id.next) {
+		ob->id.newid = NULL;
+	}
 }
 
 static void dag_scene_tag_rebuild(Scene *sce)
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index c9bad21..a2d94cc 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -436,7 +436,6 @@ static void copy_image_packedfiles(ListBase *lb_dst, const ListBase *lb_src)
 Image *BKE_image_copy(Main *bmain, Image *ima)
 {
 	Image *nima = image_alloc(bmain, ima->id.name + 2, ima->source, ima->type);
-	ima->id.newid = &nima->id;
 
 	BLI_strncpy(nima->name, ima->name, sizeof(ima->name));
 
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 3411eae..31c10c8 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -263,6 +263,14 @@ void id_fake_user_clear(ID *id)
 	}
 }
 
+void BKE_id_clear_newpoin(ID *id)
+{
+	if (id->newid) {
+		id->newid->tag &= ~LIB_TAG_NEW;
+	}
+	id->newid = NULL;
+}
+
 static int id_expand_local_callback(
         void *UNUSED(user_data), struct ID *id_self, struct ID **id_pointer, int UNUSED(cd_flag))
 {
@@ -326,6 +334,17 @@ void BKE_id_make_local_generic(Main *bmain, ID *id, const bool id_in_mainlist, c
 			if (id_copy(bmain, id, &id_new, false)) {
 				id_new->us = 0;
 
+				/* setting newid is mandatory for complex make_lib_local logic... */
+				ID_NEW_SET(id, id_new);
+				Key *key = BKE_key_from_id(id), *key_new = BKE_key_from_id(id);
+				if (key && key_new) {
+					ID_NEW_SET(key, key_new);
+				}
+				bNodeTree *ntree = ntreeFromID(id), *ntree_new = ntreeFromID(id_new);
+				if (ntree && ntree_new) {
+					ID_NEW_SET(ntree, ntree_new);
+				}
+
 				if (!lib_local) {
 					BKE_libblock_remap(bmain, id, id_new, ID_REMAP_SKIP_INDIRECT_USAGE);
 				}
@@ -337,6 +356,8 @@ void BKE_id_make_local_generic(Main *bmain, ID *id, const bool id_in_mainlist, c
 /**
  * Calls the appropriate make_local method for the block, unless test is set.
  *
+ * \note Always set ID->newid pointer in case it gets duplicated...
+ *
  * \param lib_local Special flag used when making a whole library's content local, it needs specific handling.
  *
  * \return true if the block can be made local.
@@ -561,6 +582,7 @@ bool id_copy(Main *bmain, ID *id, ID **newid, bool test)
 	return false;
 }
 
+/** Does *not* set ID->newid pointer. */
 bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop)
 {
 	ID *newid = NULL;
@@ -571,11 +593,11 @@ bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop)
 		if (RNA_property_editable(ptr, prop)) {
 			if (id_copy(CTX_data_main(C), id, &newid, false) && newid) {
 				/* copy animation actions too */
-				BKE_animdata_copy_id_action(id);
+				BKE_animdata_copy_id_action(id, false);
 				/* us is 1 by convention, but RNA_property_pointer_set
 				 * will also increment it, so set it to zero */
 				newid->us = 0;
-				
+
 				/* assign copy */
 				RNA_id_pointer_create(newid, &idptr);
 				RNA_property_pointer_set(ptr, prop, idptr);
@@ -1120,9 +1142,6 @@ void *BKE_libblock_copy(Main *bmain, ID *id)
 
 		memcpy(cpn + sizeof(ID), cp + sizeof(ID), idn_len - sizeof(ID));
 	}
-	
-	id->newid = idn;
-	idn->tag |= LIB_TAG_NEW;
 
 	BKE_libblock_copy_data(idn, id, false);
 	
@@ -1147,8 +1166,6 @@ void *BKE_libblock_copy_nolib(ID *id, const bool do_action)
 		memcpy(cpn + sizeof(ID), cp + sizeof(ID), idn_len - sizeof(ID));
 	}
 
-	id->newid = idn;
-	idn->tag |= LIB_TAG_NEW;
 	idn->us = 1;
 
 	BKE_libblock_copy_data(idn, id, do_action);
@@ -1662,7 +1679,6 @@ void BKE_library_make_local(
 		const bool do_skip = (id && !BKE_idcode_is_linkable(GS(id->name)));
 
 		for (; id; id = id->next) {
-			id->newid = NULL;
 			id->tag &= ~LIB_TAG_DOIT;
 
 			if (id->lib == NULL) {
@@ -1862,6 +1878,7 @@ void BKE_library_make_local(
 		}
 	}
 
+	BKE_main_id_clear_newpoins(bmain);
 	BLI_memarena_free(linklist_mem);
 }
 
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 4489ca9..c6666ec 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1215,6 +1215,9 @@ void BKE_object_make_local_ex(Main *bmain, Object *ob, const bool lib_local, con
 			ob_new->id.us = 0;
 			ob_new->proxy = ob_new->proxy_from = ob_new->proxy_group = NULL;
 
+			/* setting newid is mandatory for complex make_lib_local logic... */
+			ID_NEW_SET(ob, ob_new);
+
 			if (!lib_local) {
 				BKE_libblock_remap(bmain, ob, ob_new, ID_REMAP_SKIP_INDIRECT_USAGE);
 			}
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index ebf9f01..628222e 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -225,8 +225,8 @@ RigidBodyCon *BKE_rigidbody_copy_constraint(Object *ob)
 /* preserve relationships between constraints and rigid bodies after duplication */
 void BKE_rigidbody_relink_constraint(RigidBodyCon *rbc)
 {
-	ID_NEW(rbc->ob1);
-	ID_NEW(rbc->ob2);
+	ID_NEW_REMAP(rbc->ob1);
+	ID_NEW_REMAP(rbc->ob2);
 }
 
 /* ************************************** */
diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c
index c7f4060..fa22134 100644
--- a/source/blender/blenkernel/intern/sca.c
+++ b/source/blender/blenkernel/intern/sca.c
@@ -602,41 +602,41 @@ void set_sca_new_poins_ob(Object *ob)
 		if (act->flag & ACT_NEW) {
 			if (act->type==ACT_EDIT_OBJECT) {
 				bEditObjectActuator *eoa= act->data;
-				ID_NEW(eoa->ob);
+				ID_NEW_REMAP(eoa->ob);
 			}
 			else if (act->type==ACT_SCENE) {
 				bSceneActuator *sca= act->data;
-				ID_NEW(sca->camera);
+				ID_NEW_REMAP(sca->camera);
 			}
 			else if (act->type==ACT_CAMERA) {
 				bCameraActuator *ca= act->data;
-				ID_NEW(ca->ob);
+				ID_NEW_REMAP(ca->ob);
 			}
 			else if (act->type==ACT_OBJECT) {
 				bObjectActuator *oa= act->data;
-				ID_NEW(oa->reference);
+				ID_NEW_REMAP(oa->reference);
 			}
 			else if (act->type==ACT_MESSAGE) {
 				bMessageActuator *ma= act->data;
-				ID_NEW(ma->toObject);
+				ID_NEW_REMAP(ma->toObject);
 			}
 			else if (act->type==ACT_PARENT) {
 				bParentActuator *para = act->data;
-				ID_NEW(para->ob);
+				ID_NEW_REMAP(para->ob);
 			}
 			else if (act->type==ACT_ARMATURE) {
 				bArmatureActuator *aa = act->data;
-				ID_NEW(aa->target);
-				ID_NEW(aa->subtarget);
+				ID_NEW_REMAP(aa

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list