[Bf-blender-cvs] [a8fc3c88efd] master: Refactor: Move linestyle foreach_id to new IDTypeInfo structure.

Bastien Montagne noreply at git.blender.org
Fri May 15 19:04:00 CEST 2020


Commit: a8fc3c88efda66bcd8bada24ec0c8eb1e76cc852
Author: Bastien Montagne
Date:   Fri May 15 18:45:54 2020 +0200
Branches: master
https://developer.blender.org/rBa8fc3c88efda66bcd8bada24ec0c8eb1e76cc852

Refactor: Move linestyle foreach_id to new IDTypeInfo structure.

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

M	source/blender/blenkernel/intern/lib_query.c
M	source/blender/blenkernel/intern/linestyle.c

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

diff --git a/source/blender/blenkernel/intern/lib_query.c b/source/blender/blenkernel/intern/lib_query.c
index 6fa546804e2..228620d5d34 100644
--- a/source/blender/blenkernel/intern/lib_query.c
+++ b/source/blender/blenkernel/intern/lib_query.c
@@ -977,45 +977,7 @@ static void library_foreach_ID_link(Main *bmain,
       }
 
       case ID_LS: {
-        FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id;
-
-        for (i = 0; i < MAX_MTEX; i++) {
-          if (linestyle->mtex[i]) {
-            BKE_texture_mtex_foreach_id(&data, linestyle->mtex[i]);
-          }
-        }
-        if (linestyle->nodetree) {
-          /* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
-          BKE_library_foreach_ID_embedded(&data, (ID **)&linestyle->nodetree);
-        }
-
-        LISTBASE_FOREACH (LineStyleModifier *, lsm, &linestyle->color_modifiers) {
-          if (lsm->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
-            LineStyleColorModifier_DistanceFromObject *p =
-                (LineStyleColorModifier_DistanceFromObject *)lsm;
-            if (p->target) {
-              CALLBACK_INVOKE(p->target, IDWALK_CB_NOP);
-            }
-          }
-        }
-        LISTBASE_FOREACH (LineStyleModifier *, lsm, &linestyle->alpha_modifiers) {
-          if (lsm->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
-            LineStyleAlphaModifier_DistanceFromObject *p =
-                (LineStyleAlphaModifier_DistanceFromObject *)lsm;
-            if (p->target) {
-              CALLBACK_INVOKE(p->target, IDWALK_CB_NOP);
-            }
-          }
-        }
-        LISTBASE_FOREACH (LineStyleModifier *, lsm, &linestyle->thickness_modifiers) {
-          if (lsm->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
-            LineStyleThicknessModifier_DistanceFromObject *p =
-                (LineStyleThicknessModifier_DistanceFromObject *)lsm;
-            if (p->target) {
-              CALLBACK_INVOKE(p->target, IDWALK_CB_NOP);
-            }
-          }
-        }
+        BLI_assert(0);
         break;
       }
 
diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c
index 0401ae48b5c..a389af5c47f 100644
--- a/source/blender/blenkernel/intern/linestyle.c
+++ b/source/blender/blenkernel/intern/linestyle.c
@@ -45,9 +45,11 @@
 #include "BKE_freestyle.h"
 #include "BKE_idtype.h"
 #include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
 #include "BKE_linestyle.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
+#include "BKE_texture.h"
 
 static void linestyle_init_data(ID *id)
 {
@@ -144,6 +146,49 @@ static void linestyle_free_data(ID *id)
   }
 }
 
+static void linestyle_foreach_id(ID *id, LibraryForeachIDData *data)
+{
+  FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id;
+
+  for (int i = 0; i < MAX_MTEX; i++) {
+    if (linestyle->mtex[i]) {
+      BKE_texture_mtex_foreach_id(data, linestyle->mtex[i]);
+    }
+  }
+  if (linestyle->nodetree) {
+    /* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
+    BKE_library_foreach_ID_embedded(data, (ID **)&linestyle->nodetree);
+  }
+
+  LISTBASE_FOREACH (LineStyleModifier *, lsm, &linestyle->color_modifiers) {
+    if (lsm->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
+      LineStyleColorModifier_DistanceFromObject *p = (LineStyleColorModifier_DistanceFromObject *)
+          lsm;
+      if (p->target) {
+        BKE_LIB_FOREACHID_PROCESS(data, p->target, IDWALK_CB_NOP);
+      }
+    }
+  }
+  LISTBASE_FOREACH (LineStyleModifier *, lsm, &linestyle->alpha_modifiers) {
+    if (lsm->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
+      LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *)
+          lsm;
+      if (p->target) {
+        BKE_LIB_FOREACHID_PROCESS(data, p->target, IDWALK_CB_NOP);
+      }
+    }
+  }
+  LISTBASE_FOREACH (LineStyleModifier *, lsm, &linestyle->thickness_modifiers) {
+    if (lsm->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
+      LineStyleThicknessModifier_DistanceFromObject *p =
+          (LineStyleThicknessModifier_DistanceFromObject *)lsm;
+      if (p->target) {
+        BKE_LIB_FOREACHID_PROCESS(data, p->target, IDWALK_CB_NOP);
+      }
+    }
+  }
+}
+
 IDTypeInfo IDType_ID_LS = {
     .id_code = ID_LS,
     .id_filter = FILTER_ID_LS,
@@ -158,6 +203,7 @@ IDTypeInfo IDType_ID_LS = {
     .copy_data = linestyle_copy_data,
     .free_data = linestyle_free_data,
     .make_local = NULL,
+    .foreach_id = linestyle_foreach_id,
 };
 
 static const char *modifier_name[LS_MODIFIER_NUM] = {



More information about the Bf-blender-cvs mailing list