[Bf-blender-cvs] [7954e672c55] master: Readfile: refactor/factorize more handling of common ID data.

Bastien Montagne noreply at git.blender.org
Thu Feb 6 19:03:16 CET 2020


Commit: 7954e672c555037733b4ac298d558155d1862055
Author: Bastien Montagne
Date:   Thu Feb 6 16:25:15 2020 +0100
Branches: master
https://developer.blender.org/rB7954e672c555037733b4ac298d558155d1862055

Readfile: refactor/factorize more handling of common ID data.

- Move handling of private ID data (nodetree and master_collection)
under generic ID code. This shortens code a bit, but mostly avoids having
to modify all type-specific callback functions if/when we have to add
generic processing to IDs there.

- Seriously factorize `expand_xxx` area, in the same way we were already
doing in `direct_link_xxx` and `lib_link_xxx` areas.

Note that this actually also fixes some bugs (at least, potential ones),
like e.g. missing call to expand_id() for our beloved 'private ID'
(nodetrees & co), in current master code...

Differential Revision: https://developer.blender.org/D6764

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

M	source/blender/blenloader/intern/readfile.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 651f390d23e..c1a39711bf8 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2613,7 +2613,29 @@ static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_p
 /** \name Read ID
  * \{ */
 
-static void lib_link_id(FileData *fd, Main *UNUSED(bmain), ID *id)
+static void lib_link_id(FileData *fd, Main *bmain, ID *id);
+static void lib_link_nodetree(FileData *fd, Main *bmain, bNodeTree *ntree);
+static void lib_link_collection(FileData *fd, Main *bmain, Collection *collection);
+
+static void lib_link_id_private_id(FileData *fd, Main *bmain, ID *id)
+{
+  /* Handle 'private IDs'. */
+  bNodeTree *nodetree = ntreeFromID(id);
+  if (nodetree != NULL) {
+    lib_link_id(fd, bmain, &nodetree->id);
+    lib_link_nodetree(fd, bmain, nodetree);
+  }
+
+  if (GS(id->name) == ID_SCE) {
+    Scene *scene = (Scene *)id;
+    if (scene->master_collection != NULL) {
+      lib_link_id(fd, bmain, &scene->master_collection->id);
+      lib_link_collection(fd, bmain, scene->master_collection);
+    }
+  }
+}
+
+static void lib_link_id(FileData *fd, Main *bmain, ID *id)
 {
   /* Note: WM IDProperties are never written to file, hence they should always be NULL here. */
   BLI_assert((GS(id->name) != ID_WM) || id->properties == NULL);
@@ -2628,6 +2650,8 @@ static void lib_link_id(FileData *fd, Main *UNUSED(bmain), ID *id)
     id->override_library->reference = newlibadr_us(fd, id->lib, id->override_library->reference);
     id->override_library->storage = newlibadr_us(fd, id->lib, id->override_library->storage);
   }
+
+  lib_link_id_private_id(fd, bmain, id);
 }
 
 static void direct_link_id_override_property_operation_cb(FileData *fd, void *data)
@@ -2646,6 +2670,30 @@ static void direct_link_id_override_property_cb(FileData *fd, void *data)
   link_list_ex(fd, &op->operations, direct_link_id_override_property_operation_cb);
 }
 
+static void direct_link_id(FileData *fd, ID *id);
+static void direct_link_nodetree(FileData *fd, bNodeTree *ntree);
+static void direct_link_collection(FileData *fd, Collection *collection);
+
+static void direct_link_id_private_id(FileData *fd, ID *id)
+{
+  /* Handle 'private IDs'. */
+  bNodeTree **nodetree = BKE_ntree_ptr_from_id(id);
+  if (nodetree != NULL && *nodetree != NULL) {
+    *nodetree = newdataadr(fd, *nodetree);
+    direct_link_id(fd, (ID *)*nodetree);
+    direct_link_nodetree(fd, *nodetree);
+  }
+
+  if (GS(id->name) == ID_SCE) {
+    Scene *scene = (Scene *)id;
+    if (scene->master_collection != NULL) {
+      scene->master_collection = newdataadr(fd, scene->master_collection);
+      direct_link_id(fd, &scene->master_collection->id);
+      direct_link_collection(fd, scene->master_collection);
+    }
+  }
+}
+
 static void direct_link_id(FileData *fd, ID *id)
 {
   /*link direct data of ID properties*/
@@ -2685,6 +2733,9 @@ static void direct_link_id(FileData *fd, ID *id)
   if (drawdata) {
     BLI_listbase_clear((ListBase *)drawdata);
   }
+
+  /* Handle 'private IDs'. */
+  direct_link_id_private_id(fd, id);
 }
 
 /** \} */
@@ -3874,14 +3925,9 @@ static void direct_link_camera(FileData *fd, Camera *ca)
 /** \name Read ID: Light
  * \{ */
 
-static void lib_link_light(FileData *fd, Main *bmain, Light *la)
+static void lib_link_light(FileData *fd, Main *UNUSED(bmain), Light *la)
 {
   la->ipo = newlibadr_us(fd, la->id.lib, la->ipo);  // XXX deprecated - old animation system
-
-  if (la->nodetree) {
-    lib_link_id(fd, bmain, &la->nodetree->id);
-    lib_link_ntree(fd, la->id.lib, la->nodetree);
-  }
 }
 
 static void direct_link_light(FileData *fd, Light *la)
@@ -3894,12 +3940,6 @@ static void direct_link_light(FileData *fd, Light *la)
     direct_link_curvemapping(fd, la->curfalloff);
   }
 
-  la->nodetree = newdataadr(fd, la->nodetree);
-  if (la->nodetree) {
-    direct_link_id(fd, &la->nodetree->id);
-    direct_link_nodetree(fd, la->nodetree);
-  }
-
   la->preview = direct_link_preview_image(fd, la->preview);
 }
 
@@ -4016,14 +4056,9 @@ static void direct_link_mball(FileData *fd, MetaBall *mb)
 /** \name Read ID: World
  * \{ */
 
-static void lib_link_world(FileData *fd, Main *bmain, World *wrld)
+static void lib_link_world(FileData *fd, Main *UNUSED(bmain), World *wrld)
 {
   wrld->ipo = newlibadr_us(fd, wrld->id.lib, wrld->ipo);  // XXX deprecated - old animation system
-
-  if (wrld->nodetree) {
-    lib_link_id(fd, bmain, &wrld->nodetree->id);
-    lib_link_ntree(fd, wrld->id.lib, wrld->nodetree);
-  }
 }
 
 static void direct_link_world(FileData *fd, World *wrld)
@@ -4031,12 +4066,6 @@ static void direct_link_world(FileData *fd, World *wrld)
   wrld->adt = newdataadr(fd, wrld->adt);
   direct_link_animdata(fd, wrld->adt);
 
-  wrld->nodetree = newdataadr(fd, wrld->nodetree);
-  if (wrld->nodetree) {
-    direct_link_id(fd, &wrld->nodetree->id);
-    direct_link_nodetree(fd, wrld->nodetree);
-  }
-
   wrld->preview = direct_link_preview_image(fd, wrld->preview);
   BLI_listbase_clear(&wrld->gpumaterial);
 }
@@ -4278,15 +4307,10 @@ static void direct_link_curve(FileData *fd, Curve *cu)
 /** \name Read ID: Texture
  * \{ */
 
-static void lib_link_texture(FileData *fd, Main *bmain, Tex *tex)
+static void lib_link_texture(FileData *fd, Main *UNUSED(bmain), Tex *tex)
 {
   tex->ima = newlibadr_us(fd, tex->id.lib, tex->ima);
   tex->ipo = newlibadr_us(fd, tex->id.lib, tex->ipo);  // XXX deprecated - old animation system
-
-  if (tex->nodetree) {
-    lib_link_id(fd, bmain, &tex->nodetree->id);
-    lib_link_ntree(fd, tex->id.lib, tex->nodetree);
-  }
 }
 
 static void direct_link_texture(FileData *fd, Tex *tex)
@@ -4296,12 +4320,6 @@ static void direct_link_texture(FileData *fd, Tex *tex)
 
   tex->coba = newdataadr(fd, tex->coba);
 
-  tex->nodetree = newdataadr(fd, tex->nodetree);
-  if (tex->nodetree) {
-    direct_link_id(fd, &tex->nodetree->id);
-    direct_link_nodetree(fd, tex->nodetree);
-  }
-
   tex->preview = direct_link_preview_image(fd, tex->preview);
 
   tex->iuser.ok = 1;
@@ -4314,15 +4332,10 @@ static void direct_link_texture(FileData *fd, Tex *tex)
 /** \name Read ID: Material
  * \{ */
 
-static void lib_link_material(FileData *fd, Main *bmain, Material *ma)
+static void lib_link_material(FileData *fd, Main *UNUSED(bmain), Material *ma)
 {
   ma->ipo = newlibadr_us(fd, ma->id.lib, ma->ipo);  // XXX deprecated - old animation system
 
-  if (ma->nodetree) {
-    lib_link_id(fd, bmain, &ma->nodetree->id);
-    lib_link_ntree(fd, ma->id.lib, ma->nodetree);
-  }
-
   /* relink grease pencil settings */
   if (ma->gp_style != NULL) {
     MaterialGPencilStyle *gp_style = ma->gp_style;
@@ -4342,12 +4355,6 @@ static void direct_link_material(FileData *fd, Material *ma)
 
   ma->texpaintslot = NULL;
 
-  ma->nodetree = newdataadr(fd, ma->nodetree);
-  if (ma->nodetree) {
-    direct_link_id(fd, &ma->nodetree->id);
-    direct_link_nodetree(fd, ma->nodetree);
-  }
-
   ma->preview = direct_link_preview_image(fd, ma->preview);
   BLI_listbase_clear(&ma->gpumaterial);
 
@@ -6325,7 +6332,7 @@ static bool scene_validate_setscene__liblink(Scene *sce, const int totscene)
 }
 #endif
 
-static void lib_link_scene(FileData *fd, Main *bmain, Scene *sce)
+static void lib_link_scene(FileData *fd, Main *UNUSED(bmain), Scene *sce)
 {
   lib_link_keyingsets(fd, &sce->id, &sce->keyingsets);
 
@@ -6459,8 +6466,6 @@ static void lib_link_scene(FileData *fd, Main *bmain, Scene *sce)
   }
 
   if (sce->nodetree) {
-    lib_link_id(fd, bmain, &sce->nodetree->id);
-    lib_link_ntree(fd, sce->id.lib, sce->nodetree);
     composite_patch(sce->nodetree, sce);
   }
 
@@ -6483,11 +6488,6 @@ static void lib_link_scene(FileData *fd, Main *bmain, Scene *sce)
   }
 #endif
 
-  if (sce->master_collection) {
-    lib_link_id(fd, bmain, &sce->master_collection->id);
-    lib_link_collection_data(fd, sce->id.lib, sce->master_collection);
-  }
-
   for (ViewLayer *view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
     lib_link_view_layer(fd, sce->id.lib, view_layer);
   }
@@ -6817,12 +6817,6 @@ static void direct_link_scene(FileData *fd, Scene *sce)
     link_list(fd, &(srl->freestyleConfig.linesets));
   }
 
-  sce->nodetree = newdataadr(fd, sce->nodetree);
-  if (sce->nodetree) {
-    direct_link_id(fd, &sce->nodetree->id);
-    direct_link_nodetree(fd, sce->nodetree);
-  }
-
   direct_link_view_settings(fd, &sce->view_settings);
 
   sce->rigidbody_world = newdataadr(fd, sce->rigidbody_world);
@@ -6878,13 +6872,6 @@ static void direct_link_scene(FileData *fd, Scene *sce)
   }
 #endif
 
-  if (sce->master_collection) {
-    sce->master_collection = newdataadr(fd, sce->master_collection);
-    /* Needed because this is an ID outside of Main. */
-    direct_link_id(fd, &sce->master_collection->id);
-    direct_link_collection(fd, sce->master_collection);
-  }
-
   /* insert into global old-new map for reading without UI (link_global accesses it again) */
   link_glob_list(fd, &sce->view_layers);
   for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
@@ -8576,7 +8563,7 @@ static void lib_link_mask(FileData *fd, Main *UNUSED(bmain), Mask *mask)
 /** \name Read ID: Line Style
  * \{ */
 
-static void lib_link_linestyle(FileData *fd, Main *bmain, FreestyleLineStyle *linestyle)
+static void lib_link_linestyle(FileData *fd, Main *UNUSED(bmain), FreestyleLineStyle *linestyle)
 {
   LineStyleModifier *m;
 
@@ -8617,10 +8604,6 @@ static void lib_link_linestyle(FileData *fd, Main *bmain, FreestyleLineStyle *li
       mtex->object = newlibadr(fd, linestyle->id.lib, mtex->object);
     }
   }
-  if (linestyle->nodetree) {
-    lib_link_id(fd, bmain, &linestyle->nodetree->id);
-    lib_link_ntree(fd, linestyle->id.lib, linestyle->nodetree);
-  }
 }
 
 static void direct_link_linestyle_color_modifier(FileData *fd, LineStyleModifier *modifier)
@@ -8811,11 +8794,6 @@ static void direct_link_linestyle(FileData *fd, FreestyleLineStyle *linestyle)
   for (a = 0; a < MAX_MTEX; a++) {
     linestyle->mtex[a] = newdataadr(fd, linestyle->mtex[a]);
   }
-  linestyle->nodetree = newdataadr(fd, linestyle-

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list