[Bf-blender-cvs] [1b6dd42803d] master: Refactor: move Hair .blend I/O to IDTypeInfo callbacks

Jacques Lucke noreply at git.blender.org
Fri Sep 11 11:14:25 CEST 2020


Commit: 1b6dd42803df6698b10023ffc660319dab9be502
Author: Jacques Lucke
Date:   Fri Sep 11 11:14:17 2020 +0200
Branches: master
https://developer.blender.org/rB1b6dd42803df6698b10023ffc660319dab9be502

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

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

M	source/blender/blenkernel/intern/hair.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index 314b7228373..72e3d355ba5 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -47,6 +47,8 @@
 
 #include "DEG_depsgraph_query.h"
 
+#include "BLO_read_write.h"
+
 const char *HAIR_ATTR_POSITION = "Position";
 const char *HAIR_ATTR_RADIUS = "Radius";
 
@@ -109,6 +111,69 @@ static void hair_foreach_id(ID *id, LibraryForeachIDData *data)
   }
 }
 
+static void hair_blend_write(BlendWriter *writer, ID *id, const void *id_address)
+{
+  Hair *hair = (Hair *)id;
+  if (hair->id.us > 0 || BLO_write_is_undo(writer)) {
+    CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
+    CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE];
+    CustomData_blend_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
+    CustomData_blend_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff));
+
+    /* Write LibData */
+    BLO_write_id_struct(writer, Hair, id_address, &hair->id);
+    BKE_id_blend_write(writer, &hair->id);
+
+    /* Direct data */
+    CustomData_blend_write(writer, &hair->pdata, players, hair->totpoint, CD_MASK_ALL, &hair->id);
+    CustomData_blend_write(writer, &hair->cdata, clayers, hair->totcurve, CD_MASK_ALL, &hair->id);
+
+    BLO_write_pointer_array(writer, hair->totcol, hair->mat);
+    if (hair->adt) {
+      BKE_animdata_blend_write(writer, hair->adt);
+    }
+
+    /* Remove temporary data. */
+    if (players && players != players_buff) {
+      MEM_freeN(players);
+    }
+    if (clayers && clayers != clayers_buff) {
+      MEM_freeN(clayers);
+    }
+  }
+}
+
+static void hair_blend_read_data(BlendDataReader *reader, ID *id)
+{
+  Hair *hair = (Hair *)id;
+  BLO_read_data_address(reader, &hair->adt);
+  BKE_animdata_blend_read_data(reader, hair->adt);
+
+  /* Geometry */
+  CustomData_blend_read(reader, &hair->pdata, hair->totpoint);
+  CustomData_blend_read(reader, &hair->cdata, hair->totcurve);
+  BKE_hair_update_customdata_pointers(hair);
+
+  /* Materials */
+  BLO_read_pointer_array(reader, (void **)&hair->mat);
+}
+
+static void hair_blend_read_lib(BlendLibReader *reader, ID *id)
+{
+  Hair *hair = (Hair *)id;
+  for (int a = 0; a < hair->totcol; a++) {
+    BLO_read_id_address(reader, hair->id.lib, &hair->mat[a]);
+  }
+}
+
+static void hair_blend_read_expand(BlendExpander *expander, ID *id)
+{
+  Hair *hair = (Hair *)id;
+  for (int a = 0; a < hair->totcol; a++) {
+    BLO_expand(expander, hair->mat[a]);
+  }
+}
+
 IDTypeInfo IDType_ID_HA = {
     .id_code = ID_HA,
     .id_filter = FILTER_ID_HA,
@@ -126,10 +191,10 @@ IDTypeInfo IDType_ID_HA = {
     .foreach_id = hair_foreach_id,
     .foreach_cache = NULL,
 
-    .blend_write = NULL,
-    .blend_read_data = NULL,
-    .blend_read_lib = NULL,
-    .blend_read_expand = NULL,
+    .blend_write = hair_blend_write,
+    .blend_read_data = hair_blend_read_data,
+    .blend_read_lib = hair_blend_read_lib,
+    .blend_read_expand = hair_blend_read_expand,
 };
 
 static void hair_random(Hair *hair)
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index e6375ee6477..5003f185855 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6238,33 +6238,6 @@ static void lib_link_sound(BlendLibReader *reader, bSound *sound)
 
 /** \} */
 
-/* -------------------------------------------------------------------- */
-/** \name Read ID: Hair
- * \{ */
-
-static void lib_link_hair(BlendLibReader *reader, Hair *hair)
-{
-  for (int a = 0; a < hair->totcol; a++) {
-    BLO_read_id_address(reader, hair->id.lib, &hair->mat[a]);
-  }
-}
-
-static void direct_link_hair(BlendDataReader *reader, Hair *hair)
-{
-  BLO_read_data_address(reader, &hair->adt);
-  BKE_animdata_blend_read_data(reader, hair->adt);
-
-  /* Geometry */
-  CustomData_blend_read(reader, &hair->pdata, hair->totpoint);
-  CustomData_blend_read(reader, &hair->cdata, hair->totcurve);
-  BKE_hair_update_customdata_pointers(hair);
-
-  /* Materials */
-  BLO_read_pointer_array(reader, (void **)&hair->mat);
-}
-
-/** \} */
-
 /* -------------------------------------------------------------------- */
 /** \name Read ID: Point Cloud
  * \{ */
@@ -6532,9 +6505,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
     case ID_WS:
       direct_link_workspace(&reader, (WorkSpace *)id, main);
       break;
-    case ID_HA:
-      direct_link_hair(&reader, (Hair *)id);
-      break;
     case ID_PT:
       direct_link_pointcloud(&reader, (PointCloud *)id);
       break;
@@ -6569,6 +6539,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
     case ID_KE:
     case ID_TE:
     case ID_GD:
+    case ID_HA:
       /* Do nothing. Handled by IDTypeInfo callback. */
       break;
   }
@@ -7204,9 +7175,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
       case ID_CF:
         lib_link_cachefiles(&reader, (CacheFile *)id);
         break;
-      case ID_HA:
-        lib_link_hair(&reader, (Hair *)id);
-        break;
       case ID_PT:
         lib_link_pointcloud(&reader, (PointCloud *)id);
         break;
@@ -7248,6 +7216,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
       case ID_KE:
       case ID_TE:
       case ID_GD:
+      case ID_HA:
         /* Do nothing. Handled by IDTypeInfo callback. */
         break;
     }
@@ -8191,13 +8160,6 @@ static void expand_workspace(BlendExpander *expander, WorkSpace *workspace)
   }
 }
 
-static void expand_hair(BlendExpander *expander, Hair *hair)
-{
-  for (int a = 0; a < hair->totcol; a++) {
-    BLO_expand(expander, hair->mat[a]);
-  }
-}
-
 static void expand_pointcloud(BlendExpander *expander, PointCloud *pointcloud)
 {
   for (int a = 0; a < pointcloud->totcol; a++) {
@@ -8286,9 +8248,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
             case ID_WS:
               expand_workspace(&expander, (WorkSpace *)id);
               break;
-            case ID_HA:
-              expand_hair(&expander, (Hair *)id);
-              break;
             case ID_PT:
               expand_pointcloud(&expander, (PointCloud *)id);
               break;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index b9320bb40e3..e8c5e09599c 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2104,37 +2104,6 @@ static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const voi
   }
 }
 
-static void write_hair(BlendWriter *writer, Hair *hair, const void *id_address)
-{
-  if (hair->id.us > 0 || BLO_write_is_undo(writer)) {
-    CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
-    CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE];
-    CustomData_blend_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
-    CustomData_blend_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff));
-
-    /* Write LibData */
-    BLO_write_id_struct(writer, Hair, id_address, &hair->id);
-    BKE_id_blend_write(writer, &hair->id);
-
-    /* Direct data */
-    CustomData_blend_write(writer, &hair->pdata, players, hair->totpoint, CD_MASK_ALL, &hair->id);
-    CustomData_blend_write(writer, &hair->cdata, clayers, hair->totcurve, CD_MASK_ALL, &hair->id);
-
-    BLO_write_pointer_array(writer, hair->totcol, hair->mat);
-    if (hair->adt) {
-      BKE_animdata_blend_write(writer, hair->adt);
-    }
-
-    /* Remove temporary data. */
-    if (players && players != players_buff) {
-      MEM_freeN(players);
-    }
-    if (clayers && clayers != clayers_buff) {
-      MEM_freeN(clayers);
-    }
-  }
-}
-
 static void write_pointcloud(BlendWriter *writer, PointCloud *pointcloud, const void *id_address)
 {
   if (pointcloud->id.us > 0 || BLO_write_is_undo(writer)) {
@@ -2519,9 +2488,6 @@ static bool write_file_handle(Main *mainvar,
           case ID_CF:
             write_cachefile(&writer, (CacheFile *)id_buffer, id);
             break;
-          case ID_HA:
-            write_hair(&writer, (Hair *)id_buffer, id);
-            break;
           case ID_PT:
             write_pointcloud(&writer, (PointCloud *)id_buffer, id);
             break;
@@ -2556,6 +2522,7 @@ static bool write_file_handle(Main *mainvar,
           case ID_KE:
           case ID_TE:
           case ID_GD:
+          case ID_HA:
             /* Do nothing, handled in IDTypeInfo callback. */
             break;
           case ID_LI:



More information about the Bf-blender-cvs mailing list