[Bf-blender-cvs] [09ac1b78b68] override-recursive-resync: Bulk commit of current override recursive resync.

Bastien Montagne noreply at git.blender.org
Tue May 18 18:51:03 CEST 2021


Commit: 09ac1b78b686edf4f28de9f1d0c5cff9aa2debf4
Author: Bastien Montagne
Date:   Tue May 18 18:48:20 2021 +0200
Branches: override-recursive-resync
https://developer.blender.org/rB09ac1b78b686edf4f28de9f1d0c5cff9aa2debf4

Bulk commit of current override recursive resync.

Mostly to get test builds for artists, code seems to be working, but
final commit will need to be split, and there is some cleanup to be done
first anyway.

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

M	source/blender/blenkernel/BKE_lib_override.h
M	source/blender/blenkernel/BKE_lib_remap.h
M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/blenkernel/intern/lib_override.c
M	source/blender/blenkernel/intern/lib_query.c
M	source/blender/blenkernel/intern/lib_remap.c
M	source/blender/modifiers/intern/MOD_skin.c

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

diff --git a/source/blender/blenkernel/BKE_lib_override.h b/source/blender/blenkernel/BKE_lib_override.h
index f1ed5a453ba..0275c2c235c 100644
--- a/source/blender/blenkernel/BKE_lib_override.h
+++ b/source/blender/blenkernel/BKE_lib_override.h
@@ -47,6 +47,7 @@ struct ID;
 struct IDOverrideLibrary;
 struct IDOverrideLibraryProperty;
 struct IDOverrideLibraryPropertyOperation;
+struct Library;
 struct Main;
 struct Object;
 struct PointerRNA;
@@ -68,7 +69,9 @@ bool BKE_lib_override_library_is_user_edited(struct ID *id);
 struct ID *BKE_lib_override_library_create_from_id(struct Main *bmain,
                                                    struct ID *reference_id,
                                                    const bool do_tagged_remap);
-bool BKE_lib_override_library_create_from_tag(struct Main *bmain);
+bool BKE_lib_override_library_create_from_tag(struct Main *bmain,
+                                              const struct Library *reference_library,
+                                              const bool do_no_main);
 bool BKE_lib_override_library_create(struct Main *bmain,
                                      struct Scene *scene,
                                      struct ViewLayer *view_layer,
diff --git a/source/blender/blenkernel/BKE_lib_remap.h b/source/blender/blenkernel/BKE_lib_remap.h
index 705d2b030e5..e806dedc14c 100644
--- a/source/blender/blenkernel/BKE_lib_remap.h
+++ b/source/blender/blenkernel/BKE_lib_remap.h
@@ -85,6 +85,10 @@ enum {
    * freed ones).
    */
   ID_REMAP_FORCE_INTERNAL_RUNTIME_POINTERS = 1 << 7,
+  /** Force handling user count even for IDs that are outside of Main (used in some cases when
+   * dealing with IDs temporarily out of Main, but which will be put in it ultimately).
+   */
+  ID_REMAP_FORCE_USER_REFCOUNT = 1 << 8,
 };
 
 /* Note: Requiring new_id to be non-null, this *may* not be the case ultimately,
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index df7a4a862ea..9aff061f8f9 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -1221,14 +1221,6 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int ori
   BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || bmain != NULL);
   BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || (flag & LIB_ID_CREATE_NO_ALLOCATE) == 0);
   BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || (flag & LIB_ID_CREATE_LOCAL) == 0);
-  if (!is_private_id_data) {
-    /* When we are handling private ID data, we might still want to manage usercounts, even
-     * though that ID data-block is actually outside of Main... */
-    BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) == 0 ||
-               (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) != 0);
-  }
-  /* Never implicitly copy shapekeys when generating temp data outside of Main database. */
-  BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) == 0 || (flag & LIB_ID_COPY_SHAPEKEY) == 0);
 
   /* 'Private ID' data handling. */
   if ((bmain != NULL) && is_private_id_data) {
@@ -1361,13 +1353,14 @@ void id_sort_by_name(ListBase *lb, ID *id, ID *id_sorting_hint)
   BLI_remlink(lb, id);
 
   /* Check if we can actually insert id before or after id_sorting_hint, if given. */
-  if (!ELEM(id_sorting_hint, NULL, id)) {
+  if (!ELEM(id_sorting_hint, NULL, id) && id_sorting_hint->lib == id->lib) {
     BLI_assert(BLI_findindex(lb, id_sorting_hint) >= 0);
 
     ID *id_sorting_hint_next = id_sorting_hint->next;
     if (BLI_strcasecmp(id_sorting_hint->name, id->name) < 0 &&
         (id_sorting_hint_next == NULL ||
-         BLI_strcasecmp(id_sorting_hint_next->name, id->name) > 0)) {
+         BLI_strcasecmp(id_sorting_hint_next->name, id->name) > 0 ||
+         id_sorting_hint_next->lib != id->lib)) {
       BLI_insertlinkafter(lb, id_sorting_hint, id);
       return;
     }
@@ -1375,7 +1368,8 @@ void id_sort_by_name(ListBase *lb, ID *id, ID *id_sorting_hint)
     ID *id_sorting_hint_prev = id_sorting_hint->prev;
     if (BLI_strcasecmp(id_sorting_hint->name, id->name) > 0 &&
         (id_sorting_hint_prev == NULL ||
-         BLI_strcasecmp(id_sorting_hint_prev->name, id->name) < 0)) {
+         BLI_strcasecmp(id_sorting_hint_prev->name, id->name) < 0 ||
+         id_sorting_hint_prev->lib != id->lib)) {
       BLI_insertlinkbefore(lb, id_sorting_hint, id);
       return;
     }
@@ -1389,16 +1383,33 @@ void id_sort_by_name(ListBase *lb, ID *id, ID *id_sorting_hint)
   /* Note: We start from the end, because in typical 'heavy' case (insertion of lots of IDs at
    * once using the same base name), newly inserted items will generally be towards the end
    * (higher extension numbers). */
-  for (idtest = lb->last, item_array_index = ID_SORT_STEP_SIZE - 1; idtest != NULL;
-       idtest = idtest->prev, item_array_index--) {
+  bool is_in_library = false;
+  item_array_index = ID_SORT_STEP_SIZE - 1;
+  for (idtest = lb->last; idtest != NULL; idtest = idtest->prev) {
+    if (is_in_library) {
+      if (idtest->lib != id->lib) {
+        /* We got out of expected library 'range' in the list, so we are done here and can move on
+         * to the next step. */
+        break;
+      }
+    }
+    else if (idtest->lib == id->lib) {
+      /* We are entering the expected library 'range' of IDs in the list. */
+      is_in_library = true;
+    }
+
+    if (!is_in_library) {
+      continue;
+    }
+
     item_array[item_array_index] = idtest;
     if (item_array_index == 0) {
-      if ((idtest->lib == NULL && id->lib != NULL) ||
-          BLI_strcasecmp(idtest->name, id->name) <= 0) {
+      if (BLI_strcasecmp(idtest->name, id->name) <= 0) {
         break;
       }
       item_array_index = ID_SORT_STEP_SIZE;
     }
+    item_array_index--;
   }
 
   /* Step two: we go forward in the selected chunk of items and check all of them, as we know
@@ -1410,7 +1421,7 @@ void id_sort_by_name(ListBase *lb, ID *id, ID *id_sorting_hint)
    * So we can increment that index in any case. */
   for (item_array_index++; item_array_index < ID_SORT_STEP_SIZE; item_array_index++) {
     idtest = item_array[item_array_index];
-    if ((idtest->lib != NULL && id->lib == NULL) || BLI_strcasecmp(idtest->name, id->name) > 0) {
+    if (BLI_strcasecmp(idtest->name, id->name) > 0) {
       BLI_insertlinkbefore(lb, idtest, id);
       break;
     }
@@ -1418,12 +1429,18 @@ void id_sort_by_name(ListBase *lb, ID *id, ID *id_sorting_hint)
   if (item_array_index == ID_SORT_STEP_SIZE) {
     if (idtest == NULL) {
       /* If idtest is NULL here, it means that in the first loop, the last comparison was
-       * performed exactly on the first item of the list, and that it also failed. In other
-       * words, all items in the list are greater than inserted one, so we can put it at the
-       * start of the list. */
-      /* Note that BLI_insertlinkafter() would have same behavior in that case, but better be
-       * explicit here. */
-      BLI_addhead(lb, id);
+       * performed exactly on the first item of the list, and that it also failed. And that the
+       * second loop was not walked at all.
+       *
+       * In other words, if `id` is local, all the items in the list are greater than the inserted
+       * one, so we can put it at the start of the list. Or, if `id` is linked, it is the first one
+       * of its library, and we can put it at the very end of the list. */
+      if (ID_IS_LINKED(id)) {
+        BLI_addtail(lb, id);
+      }
+      else {
+        BLI_addhead(lb, id);
+      }
     }
     else {
       BLI_insertlinkafter(lb, idtest, id);
@@ -1691,12 +1708,14 @@ static bool check_for_dupid(ListBase *lb, ID *id, char *name, ID **r_id_sorting_
  */
 bool BKE_id_new_name_validate(ListBase *lb, ID *id, const char *tname)
 {
-  bool result;
+  bool result = false;
   char name[MAX_ID_NAME - 2];
 
   /* if library, don't rename */
   if (ID_IS_LINKED(id)) {
-    return false;
+    id_sort_by_name(lb, id, NULL);
+
+    return result;
   }
 
   /* if no name given, use name of current ID
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index 8341c5b6e78..abf74ce05e2 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -80,6 +80,18 @@ static void lib_override_library_property_clear(IDOverrideLibraryProperty *op);
 static void lib_override_library_property_operation_clear(
     IDOverrideLibraryPropertyOperation *opop);
 
+/** Get override data for a given ID. Needed because of our beloved shape keys snowflake. */
+BLI_INLINE IDOverrideLibrary *lib_override_get(ID *id)
+{
+  if (GS(id->name) == ID_KE) {
+    /* Shape keys are not linkable, therefore they have no override data, and use the one from
+     * their owner instead... */
+    BLI_assert(id->override_library == NULL);
+    return ((Key *)id)->from->override_library;
+  }
+  return id->override_library;
+}
+
 /** Initialize empty overriding of \a reference_id by \a local_id. */
 IDOverrideLibrary *BKE_lib_override_library_init(ID *local_id, ID *reference_id)
 {
@@ -194,12 +206,17 @@ void BKE_lib_override_library_free(struct IDOverrideLibrary **override, const bo
   *override = NULL;
 }
 
-static ID *lib_override_library_create_from(Main *bmain, ID *reference_id)
+static ID *lib_override_library_create_from(Main *bmain,
+                                            ID *reference_id,
+                                            const int lib_id_copy_flags)
 {
   /* Note: We do not want to copy possible override data from reference here (whether it is an
    * override template, or already an override of some other ref data). */
-  ID *local_id = BKE_id_copy_ex(
-      bmain, reference_id, NULL, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_NO_LIB_OVERRIDE);
+  ID *local_id = BKE_id_copy_ex(bmain,
+                                reference_id,
+                                NULL,
+                                LIB_ID_COPY_DEFAULT | LIB_ID_COPY_NO_LIB_OVERRIDE |
+                                    lib_id_copy_flags);
 
   if (local_id == NULL) {
     return NULL;
@@ -257,7 +274,7 @@ ID *BKE_lib_override_library_create_from_id(Main *bmain,
   BLI_assert(ref

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list