[Bf-blender-cvs] [fb13e40ce13] blenloader-api: move curve profile writing/reading to blenkernel

Jacques Lucke noreply at git.blender.org
Sat Mar 7 16:24:17 CET 2020


Commit: fb13e40ce131c115eebea382a276752f4718b071
Author: Jacques Lucke
Date:   Sat Mar 7 16:17:52 2020 +0100
Branches: blenloader-api
https://developer.blender.org/rBfb13e40ce131c115eebea382a276752f4718b071

move curve profile writing/reading to blenkernel

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

M	source/blender/blenkernel/BKE_curveprofile.h
M	source/blender/blenkernel/intern/curveprofile.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenkernel/BKE_curveprofile.h b/source/blender/blenkernel/BKE_curveprofile.h
index ecbaa365bac..9d0a17a527a 100644
--- a/source/blender/blenkernel/BKE_curveprofile.h
+++ b/source/blender/blenkernel/BKE_curveprofile.h
@@ -30,6 +30,8 @@ extern "C" {
 
 struct CurveProfile;
 struct CurveProfilePoint;
+struct BloWriter;
+struct BloReader;
 
 void BKE_curveprofile_set_defaults(struct CurveProfile *profile);
 
@@ -78,6 +80,9 @@ void BKE_curveprofile_evaluate_length_portion(const struct CurveProfile *profile
                                               float *x_out,
                                               float *y_out);
 
+void BKE_curveprofile_write_file(struct BloWriter *writer, const struct CurveProfile *profile);
+void BKE_curveprofile_read_file(struct BloReader *reader, struct CurveProfile *profile);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/curveprofile.c b/source/blender/blenkernel/intern/curveprofile.c
index cd25d616454..443c7d5508d 100644
--- a/source/blender/blenkernel/intern/curveprofile.c
+++ b/source/blender/blenkernel/intern/curveprofile.c
@@ -41,6 +41,8 @@
 #include "BKE_curve.h"
 #include "BKE_fcurve.h"
 
+#include "BLO_callback_api.h"
+
 void BKE_curveprofile_free_data(CurveProfile *profile)
 {
   MEM_SAFE_FREE(profile->path);
@@ -1070,3 +1072,16 @@ void BKE_curveprofile_evaluate_length_portion(const CurveProfile *profile,
   *x_out = interpf(profile->table[i].x, profile->table[i + 1].x, lerp_factor);
   *y_out = interpf(profile->table[i].y, profile->table[i + 1].y, lerp_factor);
 }
+
+void BKE_curveprofile_write_file(BloWriter *writer, const CurveProfile *profile)
+{
+  BLO_write_struct(writer, CurveProfile, profile);
+  BLO_write_struct_array(writer, CurveProfilePoint, profile->path_len, profile->path);
+}
+
+void BKE_curveprofile_read_file(BloReader *reader, CurveProfile *profile)
+{
+  BLO_read_update_address(reader, profile->path);
+  profile->table = NULL;
+  profile->segments = NULL;
+}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index b6028da0ea9..c87ece8d6e3 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -112,6 +112,7 @@
 #include "BKE_colortools.h"
 #include "BKE_constraint.h"
 #include "BKE_curve.h"
+#include "BKE_curveprofile.h"
 #include "BKE_effect.h"
 #include "BKE_fcurve.h"
 #include "BKE_fluid.h"
@@ -2724,19 +2725,6 @@ static void direct_link_id(FileData *fd, ID *id)
 
 /** \} */
 
-/* -------------------------------------------------------------------- */
-/** \name Read CurveProfile
- * \{ */
-
-static void direct_link_curveprofile(FileData *fd, CurveProfile *profile)
-{
-  profile->path = newdataadr(fd, profile->path);
-  profile->table = NULL;
-  profile->segments = NULL;
-}
-
-/** \} */
-
 /* -------------------------------------------------------------------- */
 /** \name Read ID: Brush
  * \{ */
@@ -5620,7 +5608,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb, Object *ob)
       BevelModifierData *bmd = (BevelModifierData *)md;
       bmd->custom_profile = newdataadr(fd, bmd->custom_profile);
       if (bmd->custom_profile) {
-        direct_link_curveprofile(fd, bmd->custom_profile);
+        BKE_curveprofile_read_file(wrap_reader(fd), bmd->custom_profile);
       }
     }
   }
@@ -6548,7 +6536,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
     sce->toolsettings->custom_bevel_profile_preset = newdataadr(
         fd, sce->toolsettings->custom_bevel_profile_preset);
     if (sce->toolsettings->custom_bevel_profile_preset) {
-      direct_link_curveprofile(fd, sce->toolsettings->custom_bevel_profile_preset);
+      BKE_curveprofile_read_file(wrap_reader(fd), sce->toolsettings->custom_bevel_profile_preset);
     }
   }
 
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index bbc9c17473f..0548b688113 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -153,6 +153,7 @@
 #include "BKE_colortools.h"
 #include "BKE_constraint.h"
 #include "BKE_curve.h"
+#include "BKE_curveprofile.h"
 #include "BKE_fcurve.h"
 #include "BKE_global.h"  // for G
 #include "BKE_gpencil_modifier.h"
@@ -950,12 +951,6 @@ static void write_animdata(WriteData *wd, AnimData *adt)
   write_nladata(wd, &adt->nla_tracks);
 }
 
-static void write_CurveProfile(WriteData *wd, CurveProfile *profile)
-{
-  writestruct(wd, DATA, CurveProfile, 1, profile);
-  writestruct(wd, DATA, CurveProfilePoint, profile->path_len, profile->path);
-}
-
 static void write_node_socket_default_value(WriteData *wd, bNodeSocket *sock)
 {
   if (sock->default_value == NULL) {
@@ -1740,7 +1735,7 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
     else if (md->type == eModifierType_Bevel) {
       BevelModifierData *bmd = (BevelModifierData *)md;
       if (bmd->custom_profile) {
-        write_CurveProfile(wd, bmd->custom_profile);
+        BKE_curveprofile_write_file(wrap_writer(wd), bmd->custom_profile);
       }
     }
   }
@@ -2499,7 +2494,7 @@ static void write_scene(WriteData *wd, Scene *sce)
   }
   /* Write the curve profile to the file. */
   if (tos->custom_bevel_profile_preset) {
-    write_CurveProfile(wd, tos->custom_bevel_profile_preset);
+    BKE_curveprofile_write_file(wrap_writer(wd), tos->custom_bevel_profile_preset);
   }
 
   write_paint(wd, &tos->imapaint.paint);



More information about the Bf-blender-cvs mailing list