[Bf-blender-cvs] [13f0b59] master: Use new generic BKE_id_expand_local() for both make_local() and copy() functions of actions, brushes and particles.

Bastien Montagne noreply at git.blender.org
Mon Jul 11 22:35:14 CEST 2016


Commit: 13f0b59f1180042b07f439d36841a52a6ddcd75e
Author: Bastien Montagne
Date:   Mon Jul 11 19:39:34 2016 +0200
Branches: master
https://developer.blender.org/rB13f0b59f1180042b07f439d36841a52a6ddcd75e

Use new generic BKE_id_expand_local() for both make_local() and copy() functions of actions, brushes and particles.

This greatly simplifies said code, once again no change expected from user PoV.

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

M	source/blender/blenkernel/intern/action.c
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/particle.c

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

diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index aa733e8..5712026 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -113,6 +113,7 @@ void BKE_action_make_local(Main *bmain, bAction *act)
 	if (is_local) {
 		if (!is_lib) {
 			id_clear_lib_data(bmain, &act->id);
+			BKE_id_expand_local(&act->id, false);
 		}
 		else {
 			bAction *act_new = BKE_action_copy(bmain, act);
@@ -183,6 +184,8 @@ bAction *BKE_action_copy(Main *bmain, bAction *src)
 		}
 	}
 	
+	BKE_id_expand_local(&dst->id, true);
+
 	if (ID_IS_LINKED_DATABLOCK(src)) {
 		BKE_id_lib_local_paths(bmain, src->id.lib, &dst->id);
 	}
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index ee7af7e..814934a 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -178,15 +178,6 @@ Brush *BKE_brush_copy(Main *bmain, Brush *brush)
 	
 	brushn = BKE_libblock_copy(bmain, &brush->id);
 
-	if (brush->mtex.tex)
-		id_us_plus((ID *)brush->mtex.tex);
-
-	if (brush->mask_mtex.tex)
-		id_us_plus((ID *)brush->mask_mtex.tex);
-
-	if (brush->paint_curve)
-		id_us_plus((ID *)brush->paint_curve);
-
 	if (brush->icon_imbuf)
 		brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf);
 
@@ -197,6 +188,8 @@ Brush *BKE_brush_copy(Main *bmain, Brush *brush)
 	/* enable fake user by default */
 	id_fake_user_set(&brush->id);
 
+	BKE_id_expand_local(&brushn->id, true);
+
 	if (ID_IS_LINKED_DATABLOCK(brush)) {
 		BKE_id_lib_local_paths(bmain, brush->id.lib, &brushn->id);
 	}
@@ -218,21 +211,6 @@ void BKE_brush_free(Brush *brush)
 	BKE_previewimg_free(&(brush->preview));
 }
 
-static int extern_local_brush_callback(
-        void *UNUSED(user_data), struct ID *UNUSED(id_self), struct ID **id_pointer, int cd_flag)
-{
-	/* We only tag usercounted ID usages as extern... Why? */
-	if ((cd_flag & IDWALK_USER) && *id_pointer) {
-		id_lib_extern(*id_pointer);
-	}
-	return IDWALK_RET_NOP;
-}
-
-static void extern_local_brush(Brush *brush)
-{
-	BKE_library_foreach_ID_link(&brush->id, extern_local_brush_callback, NULL, 0);
-}
-
 void BKE_brush_make_local(Main *bmain, Brush *brush)
 {
 	bool is_local = false, is_lib = false;
@@ -256,7 +234,7 @@ void BKE_brush_make_local(Main *bmain, Brush *brush)
 	if (is_local) {
 		if (!is_lib) {
 			id_clear_lib_data(bmain, &brush->id);
-			extern_local_brush(brush);
+			BKE_id_expand_local(&brush->id, false);
 
 			/* enable fake user by default */
 			id_fake_user_set(&brush->id);
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 8c8a789..8d42aae 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -3312,6 +3312,7 @@ ParticleSettings *BKE_particlesettings_copy(Main *bmain, ParticleSettings *part)
 	int a;
 
 	partn = BKE_libblock_copy(bmain, &part->id);
+
 	partn->pd = MEM_dupallocN(part->pd);
 	partn->pd2 = MEM_dupallocN(part->pd2);
 	partn->effector_weights = MEM_dupallocN(part->effector_weights);
@@ -3328,12 +3329,13 @@ ParticleSettings *BKE_particlesettings_copy(Main *bmain, ParticleSettings *part)
 		if (part->mtex[a]) {
 			partn->mtex[a] = MEM_mallocN(sizeof(MTex), "psys_copy_tex");
 			memcpy(partn->mtex[a], part->mtex[a], sizeof(MTex));
-			id_us_plus((ID *)partn->mtex[a]->tex);
 		}
 	}
 
 	BLI_duplicatelist(&partn->dupliweights, &part->dupliweights);
 	
+	BKE_id_expand_local(&partn->id, true);
+
 	if (ID_IS_LINKED_DATABLOCK(part)) {
 		BKE_id_lib_local_paths(bmain, part->id.lib, &partn->id);
 	}
@@ -3341,21 +3343,6 @@ ParticleSettings *BKE_particlesettings_copy(Main *bmain, ParticleSettings *part)
 	return partn;
 }
 
-static int extern_local_particlesettings_callback(
-        void *UNUSED(user_data), struct ID *UNUSED(id_self), struct ID **id_pointer, int cd_flag)
-{
-	/* We only tag usercounted ID usages as extern... Why? */
-	if ((cd_flag & IDWALK_USER) && *id_pointer) {
-		id_lib_extern(*id_pointer);
-	}
-	return IDWALK_RET_NOP;
-}
-
-static void expand_local_particlesettings(ParticleSettings *part)
-{
-	BKE_library_foreach_ID_link(&part->id, extern_local_particlesettings_callback, NULL, 0);
-}
-
 void BKE_particlesettings_make_local(Main *bmain, ParticleSettings *part)
 {
 	bool is_local = false, is_lib = false;
@@ -3374,7 +3361,7 @@ void BKE_particlesettings_make_local(Main *bmain, ParticleSettings *part)
 	if (is_local) {
 		if (!is_lib) {
 			id_clear_lib_data(bmain, &part->id);
-			expand_local_particlesettings(part);
+			BKE_id_expand_local(&part->id, false);
 		}
 		else {
 			ParticleSettings *part_new = BKE_particlesettings_copy(bmain, part);




More information about the Bf-blender-cvs mailing list