[Bf-blender-cvs] [7b2fe4c9ec6] master: Refactor: move Lattice .blend I/O to IDTypeInfo callbacks

Jacques Lucke noreply at git.blender.org
Fri Aug 28 16:10:29 CEST 2020


Commit: 7b2fe4c9ec683bb7da270a54c44d301016e1470d
Author: Jacques Lucke
Date:   Fri Aug 28 16:10:17 2020 +0200
Branches: master
https://developer.blender.org/rB7b2fe4c9ec683bb7da270a54c44d301016e1470d

Refactor: move Lattice .blend I/O to IDTypeInfo callbacks

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

M	source/blender/blenkernel/intern/lattice.c
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 5782fab905f..7304dd91eea 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -35,6 +35,9 @@
 
 #include "BLT_translation.h"
 
+/* Allow using deprecated functionality for .blend file I/O. */
+#define DNA_DEPRECATED_ALLOW
+
 #include "DNA_curve_types.h"
 #include "DNA_defaults.h"
 #include "DNA_key_types.h"
@@ -43,7 +46,9 @@
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
+#include "BKE_anim_data.h"
 #include "BKE_curve.h"
+#include "BKE_deform.h"
 #include "BKE_displist.h"
 #include "BKE_idtype.h"
 #include "BKE_lattice.h"
@@ -53,10 +58,10 @@
 #include "BKE_modifier.h"
 #include "BKE_object.h"
 
-#include "BKE_deform.h"
-
 #include "DEG_depsgraph_query.h"
 
+#include "BLO_read_write.h"
+
 static void lattice_init_data(ID *id)
 {
   Lattice *lattice = (Lattice *)id;
@@ -124,6 +129,59 @@ static void lattice_foreach_id(ID *id, LibraryForeachIDData *data)
   BKE_LIB_FOREACHID_PROCESS(data, lattice->key, IDWALK_CB_USER);
 }
 
+static void lattice_blend_write(BlendWriter *writer, ID *id, const void *id_address)
+{
+  Lattice *lt = (Lattice *)id;
+  if (lt->id.us > 0 || BLO_write_is_undo(writer)) {
+    /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+    lt->editlatt = NULL;
+    lt->batch_cache = NULL;
+
+    /* write LibData */
+    BLO_write_id_struct(writer, Lattice, id_address, &lt->id);
+    BKE_id_blend_write(writer, &lt->id);
+
+    /* write animdata */
+    if (lt->adt) {
+      BKE_animdata_blend_write(writer, lt->adt);
+    }
+
+    /* direct data */
+    BLO_write_struct_array(writer, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def);
+
+    BKE_defvert_blend_write(writer, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
+  }
+}
+
+static void lattice_blend_read_data(BlendDataReader *reader, ID *id)
+{
+  Lattice *lt = (Lattice *)id;
+  BLO_read_data_address(reader, &lt->def);
+
+  BLO_read_data_address(reader, &lt->dvert);
+  BKE_defvert_blend_read(reader, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
+
+  lt->editlatt = NULL;
+  lt->batch_cache = NULL;
+
+  BLO_read_data_address(reader, &lt->adt);
+  BKE_animdata_blend_read_data(reader, lt->adt);
+}
+
+static void lattice_blend_read_lib(BlendLibReader *reader, ID *id)
+{
+  Lattice *lt = (Lattice *)id;
+  BLO_read_id_address(reader, lt->id.lib, &lt->ipo);  // XXX deprecated - old animation system
+  BLO_read_id_address(reader, lt->id.lib, &lt->key);
+}
+
+static void lattice_blend_read_expand(BlendExpander *expander, ID *id)
+{
+  Lattice *lt = (Lattice *)id;
+  BLO_expand(expander, lt->ipo);  // XXX deprecated - old animation system
+  BLO_expand(expander, lt->key);
+}
+
 IDTypeInfo IDType_ID_LT = {
     .id_code = ID_LT,
     .id_filter = FILTER_ID_LT,
@@ -141,10 +199,10 @@ IDTypeInfo IDType_ID_LT = {
     .foreach_id = lattice_foreach_id,
     .foreach_cache = NULL,
 
-    .blend_write = NULL,
-    .blend_read_data = NULL,
-    .blend_read_lib = NULL,
-    .blend_read_expand = NULL,
+    .blend_write = lattice_blend_write,
+    .blend_read_data = lattice_blend_read_data,
+    .blend_read_lib = lattice_blend_read_lib,
+    .blend_read_expand = lattice_blend_read_expand,
 };
 
 int BKE_lattice_index_from_uvw(Lattice *lt, const int u, const int v, const int w)
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 3e606a5a512..a7568bcd6ea 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -23,7 +23,7 @@
 
 #include "MEM_guardedalloc.h"
 
-/* allow using deprecated functionality for .blend file I/O */
+/* Allow using deprecated functionality for .blend file I/O. */
 #define DNA_DEPRECATED_ALLOW
 
 #include "DNA_defaults.h"
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index dd7ea003cc5..aec5a254750 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4111,32 +4111,6 @@ static void direct_link_particlesystems(BlendDataReader *reader, ListBase *parti
 
 /** \} */
 
-/* -------------------------------------------------------------------- */
-/** \name Read ID: Lattice
- * \{ */
-
-static void lib_link_latt(BlendLibReader *reader, Lattice *lt)
-{
-  BLO_read_id_address(reader, lt->id.lib, &lt->ipo);  // XXX deprecated - old animation system
-  BLO_read_id_address(reader, lt->id.lib, &lt->key);
-}
-
-static void direct_link_latt(BlendDataReader *reader, Lattice *lt)
-{
-  BLO_read_data_address(reader, &lt->def);
-
-  BLO_read_data_address(reader, &lt->dvert);
-  BKE_defvert_blend_read(reader, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
-
-  lt->editlatt = NULL;
-  lt->batch_cache = NULL;
-
-  BLO_read_data_address(reader, &lt->adt);
-  BKE_animdata_blend_read_data(reader, lt->adt);
-}
-
-/** \} */
-
 /* -------------------------------------------------------------------- */
 /** \name Read ID: Object
  * \{ */
@@ -8079,9 +8053,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
     case ID_KE:
       direct_link_key(&reader, (Key *)id);
       break;
-    case ID_LT:
-      direct_link_latt(&reader, (Lattice *)id);
-      break;
     case ID_WO:
       direct_link_world(&reader, (World *)id);
       break;
@@ -8155,6 +8126,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
       direct_link_simulation(&reader, (Simulation *)id);
       break;
     case ID_ME:
+    case ID_LT:
       /* Do nothing. Handled by IDTypeInfo callback. */
       break;
   }
@@ -8820,9 +8792,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
       case ID_LA:
         lib_link_light(&reader, (Light *)id);
         break;
-      case ID_LT:
-        lib_link_latt(&reader, (Lattice *)id);
-        break;
       case ID_MB:
         lib_link_mball(&reader, (MetaBall *)id);
         break;
@@ -8883,6 +8852,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
         lib_link_library(&reader, (Library *)id); /* Only init users. */
         break;
       case ID_ME:
+      case ID_LT:
         /* Do nothing. Handled by IDTypeInfo callback. */
         break;
     }
@@ -9699,12 +9669,6 @@ static void expand_light(BlendExpander *expander, Light *la)
   BLO_expand(expander, la->ipo);  // XXX deprecated - old animation system
 }
 
-static void expand_lattice(BlendExpander *expander, Lattice *lt)
-{
-  BLO_expand(expander, lt->ipo);  // XXX deprecated - old animation system
-  BLO_expand(expander, lt->key);
-}
-
 static void expand_world(BlendExpander *expander, World *wrld)
 {
   BLO_expand(expander, wrld->ipo);  // XXX deprecated - old animation system
@@ -10185,9 +10149,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
             case ID_WO:
               expand_world(&expander, (World *)id);
               break;
-            case ID_LT:
-              expand_lattice(&expander, (Lattice *)id);
-              break;
             case ID_LA:
               expand_light(&expander, (Light *)id);
               break;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 0c703f97f4d..a9c92719a33 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1758,29 +1758,6 @@ static void write_curve(BlendWriter *writer, Curve *cu, const void *id_address)
   }
 }
 
-static void write_lattice(BlendWriter *writer, Lattice *lt, const void *id_address)
-{
-  if (lt->id.us > 0 || BLO_write_is_undo(writer)) {
-    /* Clean up, important in undo case to reduce false detection of changed datablocks. */
-    lt->editlatt = NULL;
-    lt->batch_cache = NULL;
-
-    /* write LibData */
-    BLO_write_id_struct(writer, Lattice, id_address, &lt->id);
-    BKE_id_blend_write(writer, &lt->id);
-
-    /* write animdata */
-    if (lt->adt) {
-      BKE_animdata_blend_write(writer, lt->adt);
-    }
-
-    /* direct data */
-    BLO_write_struct_array(writer, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def);
-
-    BKE_defvert_blend_write(writer, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
-  }
-}
-
 static void write_image(BlendWriter *writer, Image *ima, const void *id_address)
 {
   if (ima->id.us > 0 || BLO_write_is_undo(writer)) {
@@ -3684,9 +3661,6 @@ static bool write_file_handle(Main *mainvar,
           case ID_LA:
             write_light(&writer, (Light *)id_buffer, id);
             break;
-          case ID_LT:
-            write_lattice(&writer, (Lattice *)id_buffer, id);
-            break;
           case ID_VF:
             write_vfont(&writer, (VFont *)id_buffer, id);
             break;
@@ -3763,6 +3737,7 @@ static bool write_file_handle(Main *mainvar,
             write_simulation(&writer, (Simulation *)id_buffer, id);
             break;
           case ID_ME:
+          case ID_LT:
             /* Do nothing, handled in IDTypeInfo callback. */
             break;
           case ID_LI:



More information about the Bf-blender-cvs mailing list