[Bf-blender-cvs] [7ed6e3a5ef4] blenloader-api: simplify writing array

Jacques Lucke noreply at git.blender.org
Sat Mar 7 19:09:28 CET 2020


Commit: 7ed6e3a5ef43b55d1d34e1d862399fdfa48cf36c
Author: Jacques Lucke
Date:   Sat Mar 7 18:23:46 2020 +0100
Branches: blenloader-api
https://developer.blender.org/rB7ed6e3a5ef43b55d1d34e1d862399fdfa48cf36c

simplify writing array

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

M	source/blender/blenloader/BLO_callback_api.h
M	source/blender/blenloader/intern/writefile.c
M	source/blender/modifiers/intern/MOD_correctivesmooth.c
M	source/blender/modifiers/intern/MOD_hook.c
M	source/blender/modifiers/intern/MOD_meshdeform.c
M	source/blender/modifiers/intern/MOD_surfacedeform.c

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

diff --git a/source/blender/blenloader/BLO_callback_api.h b/source/blender/blenloader/BLO_callback_api.h
index 295ea6ab83b..18f4e70e56b 100644
--- a/source/blender/blenloader/BLO_callback_api.h
+++ b/source/blender/blenloader/BLO_callback_api.h
@@ -14,8 +14,6 @@ typedef struct BloReader BloReader;
  **********************************************/
 
 void BLO_write_raw(BloWriter *writer, int size_in_bytes, const void *data_ptr);
-#define BLO_write_raw_array(writer, element_size, length, data_ptr) \
-  BLO_write_raw(writer, (int)(element_size) * (int)(length), data_ptr)
 
 void BLO_write_struct_by_name(BloWriter *writer, const char *struct_name, const void *data_ptr);
 void BLO_write_struct_array_by_name(BloWriter *writer,
@@ -37,6 +35,11 @@ int BLO_get_struct_id_by_name(BloWriter *writer, const char *struct_name);
   BLO_write_struct_array_by_id( \
       writer, BLO_get_struct_id(writer, struct_name), array_size, data_ptr)
 
+void BLO_write_int32_array(BloWriter *writer, int size, int32_t *data_ptr);
+void BLO_write_uint32_array(BloWriter *writer, int size, uint32_t *data_ptr);
+void BLO_write_float_array(BloWriter *writer, int size, float *data_ptr);
+void BLO_write_float3_array(BloWriter *writer, int size, float *data_ptr);
+
 /* API for file reading.
  **********************************************/
 
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index fdefd94df64..25e2cb6043f 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -4095,4 +4095,24 @@ int BLO_get_struct_id_by_name(BloWriter *writer, const char *struct_name)
   return struct_id;
 }
 
+void BLO_write_int32_array(BloWriter *writer, int size, int32_t *data_ptr)
+{
+  BLO_write_raw(writer, sizeof(int32_t) * size, data_ptr);
+}
+
+void BLO_write_uint32_array(BloWriter *writer, int size, uint32_t *data_ptr)
+{
+  BLO_write_raw(writer, sizeof(uint32_t) * size, data_ptr);
+}
+
+void BLO_write_float_array(BloWriter *writer, int size, float *data_ptr)
+{
+  BLO_write_raw(writer, sizeof(float) * size, data_ptr);
+}
+
+void BLO_write_float3_array(BloWriter *writer, int size, float *data_ptr)
+{
+  BLO_write_raw(writer, sizeof(float) * 3 * size, data_ptr);
+}
+
 /** \} */
diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c
index 24a9ba3cc80..99ffaec4ca3 100644
--- a/source/blender/modifiers/intern/MOD_correctivesmooth.c
+++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c
@@ -121,7 +121,7 @@ static void bloWrite(BloWriter *writer, const ModifierData *md)
   CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md;
 
   if (csmd->bind_coords) {
-    BLO_write_raw_array(writer, sizeof(float[3]), csmd->bind_coords_num, csmd->bind_coords);
+    BLO_write_float3_array(writer, (int)csmd->bind_coords_num, (float *)csmd->bind_coords);
   }
 }
 
diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c
index b155ccff776..18b1327d956 100644
--- a/source/blender/modifiers/intern/MOD_hook.c
+++ b/source/blender/modifiers/intern/MOD_hook.c
@@ -132,7 +132,7 @@ static void bloWrite(BloWriter *writer, const ModifierData *md)
   if (hmd->curfalloff) {
     BKE_curvemapping_blo_write_ptr(writer, hmd->curfalloff);
   }
-  BLO_write_raw_array(writer, sizeof(int), hmd->totindex, hmd->indexar);
+  BLO_write_int32_array(writer, hmd->totindex, hmd->indexar);
 }
 
 static void bloRead(BloReader *reader, ModifierData *md)
diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c
index b48a3bcc491..c86470d1a24 100644
--- a/source/blender/modifiers/intern/MOD_meshdeform.c
+++ b/source/blender/modifiers/intern/MOD_meshdeform.c
@@ -171,12 +171,12 @@ static void bloWrite(BloWriter *writer, const ModifierData *md)
   int size = mmd->dyngridsize;
 
   BLO_write_struct_array(writer, MDefInfluence, mmd->totinfluence, mmd->bindinfluences);
-  BLO_write_raw_array(writer, sizeof(int), mmd->totvert + 1, mmd->bindoffsets);
-  BLO_write_raw_array(writer, sizeof(float) * 3, mmd->totcagevert, mmd->bindcagecos);
+  BLO_write_int32_array(writer, mmd->totvert + 1, mmd->bindoffsets);
+  BLO_write_float3_array(writer, mmd->totcagevert, mmd->bindcagecos);
 
   BLO_write_struct_array(writer, MDefCell, size * size * size, mmd->dyngrid);
   BLO_write_struct_array(writer, MDefInfluence, mmd->totinfluence, mmd->dyninfluences);
-  BLO_write_raw_array(writer, sizeof(int), mmd->totvert, mmd->dynverts);
+  BLO_write_int32_array(writer, mmd->totvert, mmd->dynverts);
 }
 
 static void bloRead(BloReader *reader, ModifierData *md)
diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c
index c3eded956fb..699a08bc89a 100644
--- a/source/blender/modifiers/intern/MOD_surfacedeform.c
+++ b/source/blender/modifiers/intern/MOD_surfacedeform.c
@@ -217,13 +217,13 @@ static void bloWrite(BloWriter *writer, const ModifierData *md)
       if (smd->verts[i].binds) {
         for (int j = 0; j < smd->verts[i].numbinds; j++) {
           SDefBind *bind = &smd->verts[i].binds[j];
-          BLO_write_raw_array(writer, sizeof(int), bind->numverts, bind->vert_inds);
+          BLO_write_int32_array(writer, bind->numverts, bind->vert_inds);
 
           if (ELEM(bind->mode, MOD_SDEF_MODE_CENTROID, MOD_SDEF_MODE_LOOPTRI)) {
-            BLO_write_raw(writer, sizeof(float) * 3, bind->vert_weights);
+            BLO_write_float3_array(writer, 1, bind->vert_weights);
           }
           else {
-            BLO_write_raw_array(writer, sizeof(float), bind->numverts, bind->vert_weights);
+            BLO_write_float_array(writer, bind->numverts, bind->vert_weights);
           }
         }
       }



More information about the Bf-blender-cvs mailing list