[Bf-blender-cvs] [524e03cae1c] id_copy_refactor: Huuuuge refactor of Scene copying, added to generic library ID copying.

Bastien Montagne noreply at git.blender.org
Tue Jul 11 15:58:01 CEST 2017


Commit: 524e03cae1c3a7f263efc1a5de4101b5876ba82f
Author: Bastien Montagne
Date:   Tue Jul 11 10:31:04 2017 +0200
Branches: id_copy_refactor
https://developer.blender.org/rB524e03cae1c3a7f263efc1a5de4101b5876ba82f

Huuuuge refactor of Scene copying, added to generic library ID copying.

Note: there are several known issues with this commit (and most likely
more unknown ones), to be fixed in next ones.

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

M	source/blender/blenkernel/BKE_animsys.h
M	source/blender/blenkernel/BKE_freestyle.h
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/BKE_scene.h
M	source/blender/blenkernel/BKE_sequencer.h
M	source/blender/blenkernel/intern/anim_sys.c
M	source/blender/blenkernel/intern/freestyle.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenkernel/intern/sequencer.c
M	source/blender/editors/space_sequencer/sequencer_edit.c

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

diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h
index 420ae4bb12d..147bdc84e4a 100644
--- a/source/blender/blenkernel/BKE_animsys.h
+++ b/source/blender/blenkernel/BKE_animsys.h
@@ -102,7 +102,7 @@ struct KS_Path *BKE_keyingset_add_path(struct KeyingSet *ks, struct ID *id, cons
 struct KS_Path *BKE_keyingset_find_path(struct KeyingSet *ks, struct ID *id, const char group_name[], const char rna_path[], int array_index, int group_mode);
 
 /* Copy all KeyingSets in the given list */
-void BKE_keyingsets_copy(struct ListBase *newlist, struct ListBase *list);
+void BKE_keyingsets_copy(struct ListBase *newlist, const struct ListBase *list);
 
 /* Free the given Keying Set path */
 void BKE_keyingset_free_path(struct KeyingSet *ks, struct KS_Path *ksp);
diff --git a/source/blender/blenkernel/BKE_freestyle.h b/source/blender/blenkernel/BKE_freestyle.h
index 50407f3bdfc..1045fde0039 100644
--- a/source/blender/blenkernel/BKE_freestyle.h
+++ b/source/blender/blenkernel/BKE_freestyle.h
@@ -50,7 +50,7 @@ typedef struct FreestyleModuleSettings FreestyleModuleSettings;
 /* FreestyleConfig */
 void BKE_freestyle_config_init(FreestyleConfig *config);
 void BKE_freestyle_config_free(FreestyleConfig *config);
-void BKE_freestyle_config_copy(FreestyleConfig *new_config, FreestyleConfig *config);
+void BKE_freestyle_config_copy(FreestyleConfig *new_config, FreestyleConfig *config, const int flag);
 
 /* FreestyleConfig.modules */
 FreestyleModuleConfig *BKE_freestyle_module_add(FreestyleConfig *config);
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 0802da8619a..f7e6ab59d20 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -118,7 +118,7 @@ void               BKE_paint_curve_make_local(struct Main *bmain, struct PaintCu
 
 void BKE_paint_init(struct Scene *sce, PaintMode mode, const char col[3]);
 void BKE_paint_free(struct Paint *p);
-void BKE_paint_copy(struct Paint *src, struct Paint *tar);
+void BKE_paint_copy(struct Paint *src, struct Paint *tar, const int flag);
 
 void BKE_paint_cavity_curve_preset(struct Paint *p, int preset);
 
diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h
index d2152950bff..f1680b6ccbf 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -98,6 +98,7 @@ void BKE_scene_base_flag_from_objects(struct Scene *scene);
 void BKE_scene_set_background(struct Main *bmain, struct Scene *sce);
 struct Scene *BKE_scene_set_name(struct Main *bmain, const char *name);
 
+void BKE_scene_copy_data(struct Main *bmain, struct Scene *sce_dst, const struct Scene *sce_src, const int flag);
 struct Scene *BKE_scene_copy(struct Main *bmain, struct Scene *sce, int type);
 void BKE_scene_groups_relink(struct Scene *sce);
 
diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h
index 811e9136fc9..87d63b7d6f6 100644
--- a/source/blender/blenkernel/BKE_sequencer.h
+++ b/source/blender/blenkernel/BKE_sequencer.h
@@ -352,8 +352,8 @@ void BKE_sequencer_refresh_sound_length(struct Scene *scene);
 
 void BKE_sequence_base_unique_name_recursive(ListBase *seqbasep, struct Sequence *seq);
 void BKE_sequence_base_dupli_recursive(
-        struct Scene *scene, struct Scene *scene_to, ListBase *nseqbase, ListBase *seqbase,
-        int dupe_flag);
+        const struct Scene *scene, struct Scene *scene_to, struct ListBase *nseqbase, const struct ListBase *seqbase,
+        int dupe_flag, const int flag);
 bool BKE_sequence_is_valid_check(struct Sequence *seq);
 
 void BKE_sequencer_clear_scene_in_allseqs(struct Main *bmain, struct Scene *sce);
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index 539901a59d5..23ae5a69843 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -1347,7 +1347,7 @@ void BKE_keyingset_free_path(KeyingSet *ks, KS_Path *ksp)
 }
 
 /* Copy all KeyingSets in the given list */
-void BKE_keyingsets_copy(ListBase *newlist, ListBase *list)
+void BKE_keyingsets_copy(ListBase *newlist, const ListBase *list)
 {
 	KeyingSet *ksn;
 	KS_Path *kspn;
diff --git a/source/blender/blenkernel/intern/freestyle.c b/source/blender/blenkernel/intern/freestyle.c
index 0a0b023df82..05dba538b26 100644
--- a/source/blender/blenkernel/intern/freestyle.c
+++ b/source/blender/blenkernel/intern/freestyle.c
@@ -44,7 +44,7 @@
 
 // function declarations
 static FreestyleLineSet *alloc_lineset(void);
-static void copy_lineset(FreestyleLineSet *new_lineset, FreestyleLineSet *lineset);
+static void copy_lineset(FreestyleLineSet *new_lineset, FreestyleLineSet *lineset, const int flag);
 static FreestyleModuleConfig *alloc_module(void);
 static void copy_module(FreestyleModuleConfig *new_module, FreestyleModuleConfig *module);
 
@@ -79,7 +79,7 @@ void BKE_freestyle_config_free(FreestyleConfig *config)
 	BLI_freelistN(&config->modules);
 }
 
-void BKE_freestyle_config_copy(FreestyleConfig *new_config, FreestyleConfig *config)
+void BKE_freestyle_config_copy(FreestyleConfig *new_config, FreestyleConfig *config, const int flag)
 {
 	FreestyleLineSet *lineset, *new_lineset;
 	FreestyleModuleConfig *module, *new_module;
@@ -93,7 +93,7 @@ void BKE_freestyle_config_copy(FreestyleConfig *new_config, FreestyleConfig *con
 	BLI_listbase_clear(&new_config->linesets);
 	for (lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) {
 		new_lineset = alloc_lineset();
-		copy_lineset(new_lineset, lineset);
+		copy_lineset(new_lineset, lineset, flag);
 		BLI_addtail(&new_config->linesets, (void *)new_lineset);
 	}
 
@@ -105,11 +105,9 @@ void BKE_freestyle_config_copy(FreestyleConfig *new_config, FreestyleConfig *con
 	}
 }
 
-static void copy_lineset(FreestyleLineSet *new_lineset, FreestyleLineSet *lineset)
+static void copy_lineset(FreestyleLineSet *new_lineset, FreestyleLineSet *lineset, const int flag)
 {
 	new_lineset->linestyle = lineset->linestyle;
-	if (new_lineset->linestyle)
-		id_us_plus(&new_lineset->linestyle->id);
 	new_lineset->flags = lineset->flags;
 	new_lineset->selection = lineset->selection;
 	new_lineset->qi = lineset->qi;
@@ -118,10 +116,12 @@ static void copy_lineset(FreestyleLineSet *new_lineset, FreestyleLineSet *linese
 	new_lineset->edge_types = lineset->edge_types;
 	new_lineset->exclude_edge_types = lineset->exclude_edge_types;
 	new_lineset->group = lineset->group;
-	if (new_lineset->group) {
-		id_us_plus(&new_lineset->group->id);
-	}
 	strcpy(new_lineset->name, lineset->name);
+
+	if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) {
+		id_us_plus((ID *)new_lineset->linestyle);
+		id_us_plus((ID *)new_lineset->group);
+	}
 }
 
 static FreestyleModuleConfig *alloc_module(void)
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 2c28501eb11..c5d816328a1 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -383,7 +383,6 @@ bool id_make_local(Main *bmain, ID *id, const bool test, const bool lib_local)
 
 	switch ((ID_Type)GS(id->name)) {
 		case ID_SCE:
-			/* Partially implemented (has no copy...). */
 			if (!test) BKE_scene_make_local(bmain, (Scene *)id, lib_local);
 			return true;
 		case ID_OB:
@@ -423,14 +422,12 @@ bool id_make_local(Main *bmain, ID *id, const bool test, const bool lib_local)
 			if (!test) BKE_world_make_local(bmain, (World *)id, lib_local);
 			return true;
 		case ID_VF:
-			/* Partially implemented (has no copy...). */
 			if (!test) BKE_vfont_make_local(bmain, (VFont *)id, lib_local);
 			return true;
 		case ID_TXT:
 			if (!test) BKE_text_make_local(bmain, (Text *)id, lib_local);
 			return true;
 		case ID_SO:
-			/* Partially implemented (has no copy...). */
 			if (!test) BKE_sound_make_local(bmain, (bSound *)id, lib_local);
 			return true;
 		case ID_GR:
@@ -527,8 +524,7 @@ static int id_copy_libmanagement_cb(void *user_data, ID *id_self, ID **id_pointe
 bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, const bool test)
 {
 #define LIB_ID_TYPES_NOCOPY ID_LI, ID_SCR, ID_WM,  /* Not supported */ \
-                            ID_IP,  /* Deprecated */ \
-                            ID_SCE  /* Temp, TODO */
+                            ID_IP  /* Deprecated */
 
 	if (ELEM(GS(id->name), LIB_ID_TYPES_NOCOPY)) {
 		return false;
@@ -539,6 +535,9 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 	}
 
 	switch ((ID_Type)GS(id->name)) {
+		case ID_SCE:
+			if (!test) BKE_scene_copy_data(bmain, (Scene *)*r_newid, (Scene *)id, flag);
+			break;
 		case ID_OB:
 			if (!test) BKE_object_copy_data(bmain, (Object *)*r_newid, (Object *)id, flag);
 			break;
@@ -626,8 +625,6 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 		case ID_VF:
 			if (!test) BKE_vfont_copy_data(bmain, (VFont *)*r_newid, (VFont *)id, flag);
 			break;
-		case ID_SCE:
-			return false;  /* not implemented */
 		case ID_LI:
 		case ID_SCR:
 		case ID_WM:
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 6bbcd535f27..1882afc03ad 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -551,12 +551,15 @@ void BKE_paint_free(Paint *paint)
  * still do a id_us_plus(), rather then if we were copying between 2 existing
  * scenes where a matching value should decrease the existing user count as
  * with paint_brush_set() */
-void BKE_paint_copy(Paint *src, Paint *tar)
+void BKE_paint_copy(Paint *src, Paint *tar, const int flag)
 {
 	tar->brush = src->brush;
-	id_us_plus((ID *)tar->brush);
-	id_us_plus((ID *)tar->palette);
 	tar->cavity_curve = curvemapping_copy(src->cavity_curve);
+
+	if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) {
+		id_us_plus((ID *)tar->brush);
+		id_us_plus((ID *)tar->palette);
+	}
 }
 
 void BKE_paint_stroke_get_average(Scene *scene, Object *ob, float stroke[3])
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rig

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list