[Bf-blender-cvs] [897e97f] master: ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).

Bastien Montagne noreply at git.blender.org
Wed Jun 22 18:11:51 CEST 2016


Commit: 897e97f078e64e5ee5fbbd929fd1e46240371ef4
Author: Bastien Montagne
Date:   Wed Jun 22 17:29:38 2016 +0200
Branches: master
https://developer.blender.org/rB897e97f078e64e5ee5fbbd929fd1e46240371ef4

ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).

This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.

Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).

One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).

This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).

This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.

A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)

Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.

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

M	source/blender/blenkernel/BKE_animsys.h
M	source/blender/blenkernel/BKE_curve.h
M	source/blender/blenkernel/BKE_group.h
M	source/blender/blenkernel/BKE_library.h
M	source/blender/blenkernel/BKE_library_query.h
A	source/blender/blenkernel/BKE_library_remap.h
M	source/blender/blenkernel/BKE_linestyle.h
M	source/blender/blenkernel/BKE_mask.h
M	source/blender/blenkernel/BKE_mball.h
M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/BKE_sca.h
M	source/blender/blenkernel/BKE_scene.h
M	source/blender/blenkernel/BKE_screen.h
M	source/blender/blenkernel/BKE_sound.h
M	source/blender/blenkernel/BKE_world.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/action.c
M	source/blender/blenkernel/intern/anim_sys.c
M	source/blender/blenkernel/intern/armature.c
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/camera.c
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/effect.c
M	source/blender/blenkernel/intern/font.c
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenkernel/intern/group.c
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/key.c
M	source/blender/blenkernel/intern/lamp.c
M	source/blender/blenkernel/intern/lattice.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/library_query.c
A	source/blender/blenkernel/intern/library_remap.c
M	source/blender/blenkernel/intern/linestyle.c
M	source/blender/blenkernel/intern/mask.c
M	source/blender/blenkernel/intern/material.c
M	source/blender/blenkernel/intern/mball.c
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/movieclip.c
M	source/blender/blenkernel/intern/node.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/sca.c
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenkernel/intern/screen.c
M	source/blender/blenkernel/intern/sequencer.c
M	source/blender/blenkernel/intern/sound.c
M	source/blender/blenkernel/intern/speaker.c
M	source/blender/blenkernel/intern/text.c
M	source/blender/blenkernel/intern/texture.c
M	source/blender/blenkernel/intern/world.c
M	source/blender/compositor/operations/COM_MaskOperation.cpp
M	source/blender/editors/animation/anim_channels_edit.c
M	source/blender/editors/include/ED_buttons.h
M	source/blender/editors/include/ED_node.h
M	source/blender/editors/include/ED_outliner.h
M	source/blender/editors/include/ED_util.h
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/mesh/editmesh_undo.c
M	source/blender/editors/object/object_add.c
M	source/blender/editors/object/object_group.c
M	source/blender/editors/render/render_preview.c
M	source/blender/editors/screen/screen_edit.c
M	source/blender/editors/sound/sound_ops.c
M	source/blender/editors/space_action/space_action.c
M	source/blender/editors/space_buttons/buttons_context.c
M	source/blender/editors/space_buttons/space_buttons.c
M	source/blender/editors/space_clip/space_clip.c
M	source/blender/editors/space_graph/space_graph.c
M	source/blender/editors/space_image/space_image.c
M	source/blender/editors/space_logic/space_logic.c
M	source/blender/editors/space_nla/space_nla.c
M	source/blender/editors/space_node/node_edit.c
M	source/blender/editors/space_node/space_node.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/editors/space_outliner/outliner_edit.c
M	source/blender/editors/space_outliner/outliner_intern.h
M	source/blender/editors/space_outliner/outliner_tools.c
M	source/blender/editors/space_outliner/space_outliner.c
M	source/blender/editors/space_sequencer/space_sequencer.c
M	source/blender/editors/space_text/space_text.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/editors/util/ed_util.c
M	source/blender/makesrna/intern/rna_ID.c
M	source/blender/makesrna/intern/rna_main_api.c
M	source/blender/nodes/shader/node_shader_tree.c
M	source/blender/render/intern/source/pipeline.c
M	source/blender/render/intern/source/render_texture.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_init_exit.c
M	source/gameengine/GamePlayer/ghost/GPG_ghost.cpp

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

diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h
index 6524aff..772e085 100644
--- a/source/blender/blenkernel/BKE_animsys.h
+++ b/source/blender/blenkernel/BKE_animsys.h
@@ -62,7 +62,7 @@ struct AnimData *BKE_animdata_add_id(struct ID *id);
 bool BKE_animdata_set_action(struct ReportList *reports, struct ID *id, struct bAction *act);
 
 /* Free AnimData */
-void BKE_animdata_free(struct ID *id);
+void BKE_animdata_free(struct ID *id, const bool do_id_user);
 
 /* Copy AnimData */
 struct AnimData *BKE_animdata_copy(struct AnimData *adt, const bool do_action);
diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index 061270b..23b3128 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -66,7 +66,6 @@ typedef struct CurveCache {
 #define CU_DO_2DFILL(cu)  ((((cu)->flag & CU_3D) == 0) && (((cu)->flag & (CU_FRONT | CU_BACK)) != 0))
 
 /* ** Curve ** */
-void BKE_curve_unlink(struct Curve *cu);
 void BKE_curve_free(struct Curve *cu);
 void BKE_curve_editfont_free(struct Curve *cu);
 void BKE_curve_init(struct Curve *cu);
diff --git a/source/blender/blenkernel/BKE_group.h b/source/blender/blenkernel/BKE_group.h
index 9056e48..ae6e52b 100644
--- a/source/blender/blenkernel/BKE_group.h
+++ b/source/blender/blenkernel/BKE_group.h
@@ -41,7 +41,6 @@ struct Object;
 struct Scene;
 
 void          BKE_group_free(struct Group *group);
-void          BKE_group_unlink(struct Main *bmain, struct Group *group);
 struct Group *BKE_group_add(struct Main *bmain, const char *name);
 struct Group *BKE_group_copy(struct Group *group);
 bool          BKE_group_object_add(struct Group *group, struct Object *ob, struct Scene *scene, struct Base *base);
diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 2215fbf..56f040a 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -60,13 +60,15 @@ void  BKE_libblock_relink(struct ID *id);
 void  BKE_libblock_rename(struct Main *bmain, struct ID *id, const char *name) ATTR_NONNULL();
 void  BLI_libblock_ensure_unique_name(struct Main *bmain, const char *name) ATTR_NONNULL();
 
+struct ID *BKE_libblock_find_name_ex(struct Main *bmain, const short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+struct ID *BKE_libblock_find_name(const short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+
+/* library_remap.c (keep here since they're general functions) */
 void  BKE_libblock_free(struct Main *bmain, void *idv) ATTR_NONNULL();
 void  BKE_libblock_free_ex(struct Main *bmain, void *idv, bool do_id_user) ATTR_NONNULL();
 void  BKE_libblock_free_us(struct Main *bmain, void *idv) ATTR_NONNULL();
 void  BKE_libblock_free_data(struct Main *bmain, struct ID *id) ATTR_NONNULL();
-
-struct ID *BKE_libblock_find_name_ex(struct Main *bmain, const short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
-struct ID *BKE_libblock_find_name(const short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+void  BKE_libblock_delete(struct Main *bmain, void *idv) ATTR_NONNULL();
 
 void BKE_id_lib_local_paths(struct Main *bmain, struct Library *lib, struct ID *id);
 void id_lib_extern(struct ID *id);
@@ -82,7 +84,6 @@ void id_fake_user_clear(struct ID *id);
 bool id_make_local(struct ID *id, bool test);
 bool id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, struct PropertyRNA *prop);
 bool id_copy(struct ID *id, struct ID **newid, bool test);
-bool id_unlink(struct ID *id, int test);
 void id_sort_by_name(struct ListBase *lb, struct ID *id);
 
 bool new_id(struct ListBase *lb, struct ID *id, const char *name);
@@ -119,16 +120,11 @@ void BKE_main_lib_objects_recalc_all(struct Main *bmain);
 /* (MAX_ID_NAME - 2) + 3 */
 void BKE_id_ui_prefix(char name[66 + 1], const struct ID *id);
 
+void BKE_library_free(struct Library *lib);
+
 void BKE_library_make_local(
         struct Main *bmain, const struct Library *lib, const bool untagged_only, const bool set_fake);
 
-typedef void (*BKE_library_free_window_manager_cb)(struct bContext *, struct wmWindowManager *);
-typedef void (*BKE_library_free_notifier_reference_cb)(const void *);
-typedef void (*BKE_library_free_editor_id_reference_cb)(const struct ID *);
-
-void BKE_library_callback_free_window_manager_set(BKE_library_free_window_manager_cb func);
-void BKE_library_callback_free_notifier_reference_set(BKE_library_free_notifier_reference_cb func);
-void BKE_library_callback_free_editor_id_reference_set(BKE_library_free_editor_id_reference_cb func);
 
 /* use when "" is given to new_id() */
 #define ID_FALLBACK_NAME N_("Untitled")
diff --git a/source/blender/blenkernel/BKE_library_query.h b/source/blender/blenkernel/BKE_library_query.h
index 2e73be5..c89dce9 100644
--- a/source/blender/blenkernel/BKE_library_query.h
+++ b/source/blender/blenkernel/BKE_library_query.h
@@ -32,6 +32,7 @@
  */
 
 struct ID;
+struct Main;
 
 /* Tips for the callback for cases it's gonna to modify the pointer. */
 enum {
diff --git a/source/blender/blenkernel/BKE_library_remap.h b/source/blender/blenkernel/BKE_library_remap.h
new file mode 100644
index 0000000..e85a3e6
--- /dev/null
+++ b/source/blender/blenkernel/BKE_library_remap.h
@@ -0,0 +1,76 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef __BKE_LIBRARY_REMAP_H__
+#define __BKE_LIBRARY_REMAP_H__
+
+/** \file BKE_library_remap.h
+ *  \ingroup bke
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "BLI_compiler_attrs.h"
+
+/* BKE_libblock_free, delete are declared in BKE_library.h for convenience. */
+
+/* Also IDRemap->flag. */
+enum {
+	/* Do not remap indirect usages of IDs (that is, when user is some linked data). */
+	ID_REMAP_SKIP_INDIRECT_USAGE    = 1 << 0,
+	/* This flag should always be set, *except for 'unlink' scenarios* (only relevant when new_id == NULL).
+	 * Basically, when unset, NEVER_NULL ID usages will keep pointing to old_id, but (if needed) old_id user count
+	 * will still be decremented. This is mandatory for 'delete ID' case, but in all other situation this would lead
+	 * to invalid user counts! */
+	ID_REMAP_SKIP_NEVER_NULL_USAGE  = 1 << 1,
+	/* This tells the callback func to flag with LIB_DOIT all IDs using target one with a 'never NULL' pointer
+	 * (like e.g. Object->data). */
+	ID_REMAP_FLAG_NEVER_NULL_USAGE  = 1 << 2,
+	/* This tells the callback func to force setting IDs using target one with a 'never NULL' pointer to NULL.
+	 * WARNING! Use with extreme care, this will leave database in broken state! */
+	ID_REMAP_FORCE_NEVER_NULL_USAGE = 1 << 3,
+};
+
+/* Note: Requiring new_id to be non-null, this *may* not be the case ultimately, but makes things simpler for now. */
+void BKE_libblock_remap_locked(
+        struct Main *bmain, void *old_idv, void *new_idv,
+        const short remap_flags) ATTR_NONNULL(1, 2);
+void BKE_libblock_remap(
+        struct Main *bmain, void *old_idv, void *new_idv,
+        const short remap_flags) ATTR_NONNULL(1, 2);
+
+void BKE_libblock_unlink(struct Main *bmain, void *idv, const bool do_flag_never_null) ATTR_NONNULL();
+
+void BKE_libblock_relink_ex(void *idv, void *old_idv, void *new_idv, const bool us_min_never_null) ATTR_NONNULL(1);
+
+
+typedef void (*BKE_library_free_window_manager_cb)(struct bContext *, struct wmWindowManager *);
+typedef void (*BKE_library_free_notifier_reference_cb)(const void *);
+typedef void (*BKE_library_remap_editor_id_reference_cb)(struct ID *, struct ID *);
+
+void BKE_library_callback_free_window_manager_set(BKE_library_free_window_manager_cb func);
+void BKE_library_callback_free_notifier_reference_set(BKE_library_free_notifier_reference_cb func);
+void BKE_library_callback_remap_editor_id_reference_set(BKE_library_remap_editor_id_reference_cb func);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* __BKE_LIBRARY_REMAP_H__ */
\ No newline at end of file
diff --git a/source/blender/blenkernel/BKE_linestyle.h b/source/blender/blenkernel/BKE_linestyle.h
index e3eead4..e343cd2 100644
--- a/source/blender/blenkernel/BKE_linestyle.h
+++ b/source/blender/blenkernel/BKE_linestyle.h
@@ -79,8 +79,6 @@ void BKE_linestyle_geometry_modifier_move(FreestyleLineStyle *linestyle, LineSty
 void BKE_linestyle_modifier_list_color_ramps(FreestyleLineStyle *linestyle, ListBase *listbase);
 char *BKE_linestyle_path_to_color_ramp(FreestyleLineStyle *linestyle, struct ColorBand *color_ramp);
 
-void BKE_linestyle_target_object_unlink(FreestyleLineStyle *linestyle, struct Object *ob);
-
 bool BKE_linestyle_use_textures(FreestyleLineStyle *linestyle, const bool use_shading_nodes);
 
 void BKE_linestyle_default_shader(const struct bContext *C, FreestyleLineStyle *linestyle);
diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h
index 25893d5..f3d12b5 100644
--- a/source/blender/blenkernel/BKE_mask.h
+++ b/source/blender/blenkernel/BKE_mask.h
@@ -125,8 +125,7 @@ struct Mask *BKE_mask_new(struct Main *bmain, const char *name);
 struct Mask *BKE_mask_copy_nolib(struct Mask *mask);
 struct Mask *BKE_mask_copy(struct Mask *mask);
 
-void BKE_mask_free_nolib(struct Mask *mask);
-void BKE_mask_free(struct Main *bmain, struct Mask *mask);
+void BKE_mask_free(struct Mask *mask);
 
 void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2]);
 void BKE_mask_coord

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list