[Bf-blender-cvs] [0f49e4832cf] master: Cleanup: Blendwrite: Move code deciding if an ID should be written out of ID callbacks.

Bastien Montagne noreply at git.blender.org
Thu Aug 19 15:09:41 CEST 2021


Commit: 0f49e4832cf2afad437aa16ebbbe37191de9af71
Author: Bastien Montagne
Date:   Thu Aug 19 11:13:55 2021 +0200
Branches: master
https://developer.blender.org/rB0f49e4832cf2afad437aa16ebbbe37191de9af71

Cleanup: Blendwrite: Move code deciding if an ID should be written out of ID callbacks.

This was not really useful, and added estra useless steps in case and ID
should not actually be written.

Further more, it prevented clearing the usercount on write, which can be
cause a false positive 'chanhged' detection in undo/redo case.

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

M	source/blender/blenkernel/intern/action.c
M	source/blender/blenkernel/intern/armature.c
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/cachefile.c
M	source/blender/blenkernel/intern/camera.c
M	source/blender/blenkernel/intern/collection.c
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/font.c
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenkernel/intern/hair.c
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/key.c
M	source/blender/blenkernel/intern/lattice.c
M	source/blender/blenkernel/intern/light.c
M	source/blender/blenkernel/intern/lightprobe.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.cc
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/pointcloud.cc
M	source/blender/blenkernel/intern/screen.c
M	source/blender/blenkernel/intern/simulation.cc
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/volume.cc
M	source/blender/blenkernel/intern/world.c
M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index d55f023d209..981815f400a 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -186,22 +186,21 @@ static void action_foreach_id(ID *id, LibraryForeachIDData *data)
 static void action_blend_write(BlendWriter *writer, ID *id, const void *id_address)
 {
   bAction *act = (bAction *)id;
-  if (act->id.us > 0 || BLO_write_is_undo(writer)) {
-    BLO_write_id_struct(writer, bAction, id_address, &act->id);
-    BKE_id_blend_write(writer, &act->id);
 
-    BKE_fcurve_blend_write(writer, &act->curves);
+  BLO_write_id_struct(writer, bAction, id_address, &act->id);
+  BKE_id_blend_write(writer, &act->id);
 
-    LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) {
-      BLO_write_struct(writer, bActionGroup, grp);
-    }
+  BKE_fcurve_blend_write(writer, &act->curves);
 
-    LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) {
-      BLO_write_struct(writer, TimeMarker, marker);
-    }
+  LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) {
+    BLO_write_struct(writer, bActionGroup, grp);
+  }
 
-    BKE_previewimg_blend_write(writer, act->preview);
+  LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) {
+    BLO_write_struct(writer, TimeMarker, marker);
   }
+
+  BKE_previewimg_blend_write(writer, act->preview);
 }
 
 static void action_blend_read_data(BlendDataReader *reader, ID *id)
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 1f02b084534..87320c88b1b 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -212,25 +212,24 @@ static void write_bone(BlendWriter *writer, Bone *bone)
 static void armature_blend_write(BlendWriter *writer, ID *id, const void *id_address)
 {
   bArmature *arm = (bArmature *)id;
-  if (arm->id.us > 0 || BLO_write_is_undo(writer)) {
-    /* Clean up, important in undo case to reduce false detection of changed datablocks. */
-    arm->bonehash = NULL;
-    arm->edbo = NULL;
-    /* Must always be cleared (armatures don't have their own edit-data). */
-    arm->needs_flush_to_id = 0;
-    arm->act_edbone = NULL;
 
-    BLO_write_id_struct(writer, bArmature, id_address, &arm->id);
-    BKE_id_blend_write(writer, &arm->id);
+  /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+  arm->bonehash = NULL;
+  arm->edbo = NULL;
+  /* Must always be cleared (armatures don't have their own edit-data). */
+  arm->needs_flush_to_id = 0;
+  arm->act_edbone = NULL;
 
-    if (arm->adt) {
-      BKE_animdata_blend_write(writer, arm->adt);
-    }
+  BLO_write_id_struct(writer, bArmature, id_address, &arm->id);
+  BKE_id_blend_write(writer, &arm->id);
 
-    /* Direct data */
-    LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) {
-      write_bone(writer, bone);
-    }
+  if (arm->adt) {
+    BKE_animdata_blend_write(writer, arm->adt);
+  }
+
+  /* Direct data */
+  LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) {
+    write_bone(writer, bone);
   }
 }
 
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 3418e37642c..7b81187be21 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -202,48 +202,47 @@ static void brush_foreach_id(ID *id, LibraryForeachIDData *data)
 static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_address)
 {
   Brush *brush = (Brush *)id;
-  if (brush->id.us > 0 || BLO_write_is_undo(writer)) {
-    BLO_write_id_struct(writer, Brush, id_address, &brush->id);
-    BKE_id_blend_write(writer, &brush->id);
 
-    if (brush->curve) {
-      BKE_curvemapping_blend_write(writer, brush->curve);
-    }
+  BLO_write_id_struct(writer, Brush, id_address, &brush->id);
+  BKE_id_blend_write(writer, &brush->id);
 
-    if (brush->gpencil_settings) {
-      BLO_write_struct(writer, BrushGpencilSettings, brush->gpencil_settings);
+  if (brush->curve) {
+    BKE_curvemapping_blend_write(writer, brush->curve);
+  }
 
-      if (brush->gpencil_settings->curve_sensitivity) {
-        BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_sensitivity);
-      }
-      if (brush->gpencil_settings->curve_strength) {
-        BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_strength);
-      }
-      if (brush->gpencil_settings->curve_jitter) {
-        BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_jitter);
-      }
-      if (brush->gpencil_settings->curve_rand_pressure) {
-        BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_pressure);
-      }
-      if (brush->gpencil_settings->curve_rand_strength) {
-        BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_strength);
-      }
-      if (brush->gpencil_settings->curve_rand_uv) {
-        BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_uv);
-      }
-      if (brush->gpencil_settings->curve_rand_hue) {
-        BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_hue);
-      }
-      if (brush->gpencil_settings->curve_rand_saturation) {
-        BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_saturation);
-      }
-      if (brush->gpencil_settings->curve_rand_value) {
-        BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_value);
-      }
+  if (brush->gpencil_settings) {
+    BLO_write_struct(writer, BrushGpencilSettings, brush->gpencil_settings);
+
+    if (brush->gpencil_settings->curve_sensitivity) {
+      BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_sensitivity);
     }
-    if (brush->gradient) {
-      BLO_write_struct(writer, ColorBand, brush->gradient);
+    if (brush->gpencil_settings->curve_strength) {
+      BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_strength);
     }
+    if (brush->gpencil_settings->curve_jitter) {
+      BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_jitter);
+    }
+    if (brush->gpencil_settings->curve_rand_pressure) {
+      BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_pressure);
+    }
+    if (brush->gpencil_settings->curve_rand_strength) {
+      BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_strength);
+    }
+    if (brush->gpencil_settings->curve_rand_uv) {
+      BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_uv);
+    }
+    if (brush->gpencil_settings->curve_rand_hue) {
+      BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_hue);
+    }
+    if (brush->gpencil_settings->curve_rand_saturation) {
+      BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_saturation);
+    }
+    if (brush->gpencil_settings->curve_rand_value) {
+      BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_value);
+    }
+  }
+  if (brush->gradient) {
+    BLO_write_struct(writer, ColorBand, brush->gradient);
   }
 }
 
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index 8dd28c889f5..4a60564b4a1 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -97,19 +97,18 @@ static void cache_file_free_data(ID *id)
 static void cache_file_blend_write(BlendWriter *writer, ID *id, const void *id_address)
 {
   CacheFile *cache_file = (CacheFile *)id;
-  if (cache_file->id.us > 0 || BLO_write_is_undo(writer)) {
-    /* Clean up, important in undo case to reduce false detection of changed datablocks. */
-    BLI_listbase_clear(&cache_file->object_paths);
-    cache_file->handle = NULL;
-    memset(cache_file->handle_filepath, 0, sizeof(cache_file->handle_filepath));
-    cache_file->handle_readers = NULL;
 
-    BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id);
-    BKE_id_blend_write(writer, &cache_file->id);
+  /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+  BLI_listbase_clear(&cache_file->object_paths);
+  cache_file->handle = NULL;
+  memset(cache_file->handle_filepath, 0, sizeof(cache_file->handle_filepath));
+  cache_file->handle_readers = NULL;
 
-    if (cache_file->adt) {
-      BKE_animdata_blend_write(writer, cache_file->adt);
-    }
+  BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id);
+  BKE_id_blend_write(writer, &cache_file->id);
+
+  if (cache_file->adt) {
+    BKE_animdata_blend_write(writer, cache_file->adt);
   }
 }
 
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 5172b067eba..46b079fb42e 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -122,18 +122,17 @@ static void camera_foreach_id(ID *id, LibraryForeachIDData *data)
 static void camera_blend_write(BlendWriter *writer, ID *id, const void *id_address)
 {
   Camera *cam = (Camera *)id;
-  if (cam->id.us > 0 || BLO_write_is_undo(writer)) {
-    /* write LibData */
-    BLO_write_id_struct(writer, Camera, id_address, &cam->id);
-    BKE_id_blend_write(writer, &cam->id);
 
-    if (cam->adt) {
-      BKE_animdata_blend_write(writer, cam->adt);
-    }
+  /* write LibData */
+  BLO_write_id_struct(writer, Camera, id_address, &cam->id);
+  BKE_id_blend_write(writer, &cam->id);
 
-    LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) {
-      BLO_write_struct(writer, CameraBGImage, bgpic);
-    }
+  if (cam->adt) {
+    BKE_animdata_blend_write(writer, cam->adt);
+  }
+
+  LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) {
+    BLO_write_struct(writer, CameraBGImage, bgpic);
   }
 }
 
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index b62e33ff564..d36e9b67d00 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -214,20 +214,19 @@ void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collectio
 static void coll

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list