Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-09-10 17:47:12 +0300
committerJacques Lucke <jacques@blender.org>2020-09-10 17:47:12 +0300
commit8a65afac1e4c4f4ef25b6c9e01cde3bc64bae48a (patch)
tree8f48a25295a950aeb28cd292d4d65ab2081d2735 /source
parenta82bb8f5f09a2a85bfa2f3985ca2a37a177895bb (diff)
Refactor: move Curve .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/curve.c167
-rw-r--r--source/blender/blenloader/intern/readfile.c119
-rw-r--r--source/blender/blenloader/intern/writefile.c51
3 files changed, 166 insertions, 171 deletions
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 351f73ea76e..dfa8d65d117 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -28,12 +28,16 @@
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
+#include "BLI_endian_switch.h"
#include "BLI_ghash.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
+/* Allow using deprecated functionality for .blend file I/O. */
+#define DNA_DEPRECATED_ALLOW
+
#include "DNA_anim_types.h"
#include "DNA_curve_types.h"
#include "DNA_defaults.h"
@@ -44,6 +48,7 @@
#include "DNA_object_types.h"
#include "DNA_vfont_types.h"
+#include "BKE_anim_data.h"
#include "BKE_curve.h"
#include "BKE_displist.h"
#include "BKE_font.h"
@@ -59,6 +64,8 @@
#include "CLG_log.h"
+#include "BLO_read_write.h"
+
/* globals */
/* local */
@@ -131,6 +138,158 @@ static void curve_foreach_id(ID *id, LibraryForeachIDData *data)
BKE_LIB_FOREACHID_PROCESS(data, curve->vfontbi, IDWALK_CB_USER);
}
+static void curve_blend_write(BlendWriter *writer, ID *id, const void *id_address)
+{
+ Curve *cu = (Curve *)id;
+ if (cu->id.us > 0 || BLO_write_is_undo(writer)) {
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ cu->editnurb = NULL;
+ cu->editfont = NULL;
+ cu->batch_cache = NULL;
+
+ /* write LibData */
+ BLO_write_id_struct(writer, Curve, id_address, &cu->id);
+ BKE_id_blend_write(writer, &cu->id);
+
+ /* direct data */
+ BLO_write_pointer_array(writer, cu->totcol, cu->mat);
+ if (cu->adt) {
+ BKE_animdata_blend_write(writer, cu->adt);
+ }
+
+ if (cu->vfont) {
+ BLO_write_raw(writer, cu->len + 1, cu->str);
+ BLO_write_struct_array(writer, CharInfo, cu->len_char32 + 1, cu->strinfo);
+ BLO_write_struct_array(writer, TextBox, cu->totbox, cu->tb);
+ }
+ else {
+ /* is also the order of reading */
+ LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
+ BLO_write_struct(writer, Nurb, nu);
+ }
+ LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
+ if (nu->type == CU_BEZIER) {
+ BLO_write_struct_array(writer, BezTriple, nu->pntsu, nu->bezt);
+ }
+ else {
+ BLO_write_struct_array(writer, BPoint, nu->pntsu * nu->pntsv, nu->bp);
+ if (nu->knotsu) {
+ BLO_write_float_array(writer, KNOTSU(nu), nu->knotsu);
+ }
+ if (nu->knotsv) {
+ BLO_write_float_array(writer, KNOTSV(nu), nu->knotsv);
+ }
+ }
+ }
+ }
+ }
+}
+
+static void switch_endian_knots(Nurb *nu)
+{
+ if (nu->knotsu) {
+ BLI_endian_switch_float_array(nu->knotsu, KNOTSU(nu));
+ }
+ if (nu->knotsv) {
+ BLI_endian_switch_float_array(nu->knotsv, KNOTSV(nu));
+ }
+}
+
+static void curve_blend_read_data(BlendDataReader *reader, ID *id)
+{
+ Curve *cu = (Curve *)id;
+ BLO_read_data_address(reader, &cu->adt);
+ BKE_animdata_blend_read_data(reader, cu->adt);
+
+ /* Protect against integer overflow vulnerability. */
+ CLAMP(cu->len_char32, 0, INT_MAX - 4);
+
+ BLO_read_pointer_array(reader, (void **)&cu->mat);
+
+ BLO_read_data_address(reader, &cu->str);
+ BLO_read_data_address(reader, &cu->strinfo);
+ BLO_read_data_address(reader, &cu->tb);
+
+ if (cu->vfont == NULL) {
+ BLO_read_list(reader, &(cu->nurb));
+ }
+ else {
+ cu->nurb.first = cu->nurb.last = NULL;
+
+ TextBox *tb = MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), "TextBoxread");
+ if (cu->tb) {
+ memcpy(tb, cu->tb, cu->totbox * sizeof(TextBox));
+ MEM_freeN(cu->tb);
+ cu->tb = tb;
+ }
+ else {
+ cu->totbox = 1;
+ cu->actbox = 1;
+ cu->tb = tb;
+ cu->tb[0].w = cu->linewidth;
+ }
+ if (cu->wordspace == 0.0f) {
+ cu->wordspace = 1.0f;
+ }
+ }
+
+ cu->editnurb = NULL;
+ cu->editfont = NULL;
+ cu->batch_cache = NULL;
+
+ LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
+ BLO_read_data_address(reader, &nu->bezt);
+ BLO_read_data_address(reader, &nu->bp);
+ BLO_read_data_address(reader, &nu->knotsu);
+ BLO_read_data_address(reader, &nu->knotsv);
+ if (cu->vfont == NULL) {
+ nu->charidx = 0;
+ }
+
+ if (BLO_read_requires_endian_switch(reader)) {
+ switch_endian_knots(nu);
+ }
+ }
+ cu->texflag &= ~CU_AUTOSPACE_EVALUATED;
+}
+
+static void curve_blend_read_lib(BlendLibReader *reader, ID *id)
+{
+ Curve *cu = (Curve *)id;
+ for (int a = 0; a < cu->totcol; a++) {
+ BLO_read_id_address(reader, cu->id.lib, &cu->mat[a]);
+ }
+
+ BLO_read_id_address(reader, cu->id.lib, &cu->bevobj);
+ BLO_read_id_address(reader, cu->id.lib, &cu->taperobj);
+ BLO_read_id_address(reader, cu->id.lib, &cu->textoncurve);
+ BLO_read_id_address(reader, cu->id.lib, &cu->vfont);
+ BLO_read_id_address(reader, cu->id.lib, &cu->vfontb);
+ BLO_read_id_address(reader, cu->id.lib, &cu->vfonti);
+ BLO_read_id_address(reader, cu->id.lib, &cu->vfontbi);
+
+ BLO_read_id_address(reader, cu->id.lib, &cu->ipo); // XXX deprecated - old animation system
+ BLO_read_id_address(reader, cu->id.lib, &cu->key);
+}
+
+static void curve_blend_read_expand(BlendExpander *expander, ID *id)
+{
+ Curve *cu = (Curve *)id;
+ for (int a = 0; a < cu->totcol; a++) {
+ BLO_expand(expander, cu->mat[a]);
+ }
+
+ BLO_expand(expander, cu->vfont);
+ BLO_expand(expander, cu->vfontb);
+ BLO_expand(expander, cu->vfonti);
+ BLO_expand(expander, cu->vfontbi);
+ BLO_expand(expander, cu->key);
+ BLO_expand(expander, cu->ipo); // XXX deprecated - old animation system
+ BLO_expand(expander, cu->bevobj);
+ BLO_expand(expander, cu->taperobj);
+ BLO_expand(expander, cu->textoncurve);
+}
+
IDTypeInfo IDType_ID_CU = {
.id_code = ID_CU,
.id_filter = FILTER_ID_CU,
@@ -148,10 +307,10 @@ IDTypeInfo IDType_ID_CU = {
.foreach_id = curve_foreach_id,
.foreach_cache = NULL,
- .blend_write = NULL,
- .blend_read_data = NULL,
- .blend_read_lib = NULL,
- .blend_read_expand = NULL,
+ .blend_write = curve_blend_write,
+ .blend_read_data = curve_blend_read_data,
+ .blend_read_lib = curve_blend_read_lib,
+ .blend_read_expand = curve_blend_read_expand,
};
static int cu_isectLL(const float v1[3],
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 0ab4c9b4171..b3816588daa 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2965,97 +2965,6 @@ static void direct_link_world(BlendDataReader *reader, World *wrld)
/** \} */
/* -------------------------------------------------------------------- */
-/** \name Read ID: Curve
- * \{ */
-
-static void lib_link_curve(BlendLibReader *reader, Curve *cu)
-{
- for (int a = 0; a < cu->totcol; a++) {
- BLO_read_id_address(reader, cu->id.lib, &cu->mat[a]);
- }
-
- BLO_read_id_address(reader, cu->id.lib, &cu->bevobj);
- BLO_read_id_address(reader, cu->id.lib, &cu->taperobj);
- BLO_read_id_address(reader, cu->id.lib, &cu->textoncurve);
- BLO_read_id_address(reader, cu->id.lib, &cu->vfont);
- BLO_read_id_address(reader, cu->id.lib, &cu->vfontb);
- BLO_read_id_address(reader, cu->id.lib, &cu->vfonti);
- BLO_read_id_address(reader, cu->id.lib, &cu->vfontbi);
-
- BLO_read_id_address(reader, cu->id.lib, &cu->ipo); // XXX deprecated - old animation system
- BLO_read_id_address(reader, cu->id.lib, &cu->key);
-}
-
-static void switch_endian_knots(Nurb *nu)
-{
- if (nu->knotsu) {
- BLI_endian_switch_float_array(nu->knotsu, KNOTSU(nu));
- }
- if (nu->knotsv) {
- BLI_endian_switch_float_array(nu->knotsv, KNOTSV(nu));
- }
-}
-
-static void direct_link_curve(BlendDataReader *reader, Curve *cu)
-{
- BLO_read_data_address(reader, &cu->adt);
- BKE_animdata_blend_read_data(reader, cu->adt);
-
- /* Protect against integer overflow vulnerability. */
- CLAMP(cu->len_char32, 0, INT_MAX - 4);
-
- BLO_read_pointer_array(reader, (void **)&cu->mat);
-
- BLO_read_data_address(reader, &cu->str);
- BLO_read_data_address(reader, &cu->strinfo);
- BLO_read_data_address(reader, &cu->tb);
-
- if (cu->vfont == NULL) {
- BLO_read_list(reader, &(cu->nurb));
- }
- else {
- cu->nurb.first = cu->nurb.last = NULL;
-
- TextBox *tb = MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), "TextBoxread");
- if (cu->tb) {
- memcpy(tb, cu->tb, cu->totbox * sizeof(TextBox));
- MEM_freeN(cu->tb);
- cu->tb = tb;
- }
- else {
- cu->totbox = 1;
- cu->actbox = 1;
- cu->tb = tb;
- cu->tb[0].w = cu->linewidth;
- }
- if (cu->wordspace == 0.0f) {
- cu->wordspace = 1.0f;
- }
- }
-
- cu->editnurb = NULL;
- cu->editfont = NULL;
- cu->batch_cache = NULL;
-
- LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
- BLO_read_data_address(reader, &nu->bezt);
- BLO_read_data_address(reader, &nu->bp);
- BLO_read_data_address(reader, &nu->knotsu);
- BLO_read_data_address(reader, &nu->knotsv);
- if (cu->vfont == NULL) {
- nu->charidx = 0;
- }
-
- if (BLO_read_requires_endian_switch(reader)) {
- switch_endian_knots(nu);
- }
- }
- cu->texflag &= ~CU_AUTOSPACE_EVALUATED;
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
/** \name Read ID: Texture
* \{ */
@@ -7003,9 +6912,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_OB:
direct_link_object(&reader, (Object *)id);
break;
- case ID_CU:
- direct_link_curve(&reader, (Curve *)id);
- break;
case ID_TE:
direct_link_texture(&reader, (Tex *)id);
break;
@@ -7081,6 +6987,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_LA:
case ID_MA:
case ID_MB:
+ case ID_CU:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
@@ -7728,9 +7635,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_CA:
lib_link_camera(&reader, (Camera *)id);
break;
- case ID_CU:
- lib_link_curve(&reader, (Curve *)id);
- break;
case ID_CF:
lib_link_cachefiles(&reader, (CacheFile *)id);
break;
@@ -7780,6 +7684,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_LA:
case ID_MA:
case ID_MB:
+ case ID_CU:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
@@ -8481,23 +8386,6 @@ static void expand_world(BlendExpander *expander, World *wrld)
BLO_expand(expander, wrld->ipo); // XXX deprecated - old animation system
}
-static void expand_curve(BlendExpander *expander, Curve *cu)
-{
- for (int a = 0; a < cu->totcol; a++) {
- BLO_expand(expander, cu->mat[a]);
- }
-
- BLO_expand(expander, cu->vfont);
- BLO_expand(expander, cu->vfontb);
- BLO_expand(expander, cu->vfonti);
- BLO_expand(expander, cu->vfontbi);
- BLO_expand(expander, cu->key);
- BLO_expand(expander, cu->ipo); // XXX deprecated - old animation system
- BLO_expand(expander, cu->bevobj);
- BLO_expand(expander, cu->taperobj);
- BLO_expand(expander, cu->textoncurve);
-}
-
/* callback function used to expand constraint ID-links */
static void expand_constraint_cb(bConstraint *UNUSED(con),
ID **idpoin,
@@ -8901,9 +8789,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
case ID_OB:
expand_object(&expander, (Object *)id);
break;
- case ID_CU:
- expand_curve(&expander, (Curve *)id);
- break;
case ID_SCE:
expand_scene(&expander, (Scene *)id);
break;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 328ce70eda7..dd307da40fd 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1431,53 +1431,6 @@ static void write_camera(BlendWriter *writer, Camera *cam, const void *id_addres
}
}
-static void write_curve(BlendWriter *writer, Curve *cu, const void *id_address)
-{
- if (cu->id.us > 0 || BLO_write_is_undo(writer)) {
- /* Clean up, important in undo case to reduce false detection of changed datablocks. */
- cu->editnurb = NULL;
- cu->editfont = NULL;
- cu->batch_cache = NULL;
-
- /* write LibData */
- BLO_write_id_struct(writer, Curve, id_address, &cu->id);
- BKE_id_blend_write(writer, &cu->id);
-
- /* direct data */
- BLO_write_pointer_array(writer, cu->totcol, cu->mat);
- if (cu->adt) {
- BKE_animdata_blend_write(writer, cu->adt);
- }
-
- if (cu->vfont) {
- BLO_write_raw(writer, cu->len + 1, cu->str);
- BLO_write_struct_array(writer, CharInfo, cu->len_char32 + 1, cu->strinfo);
- BLO_write_struct_array(writer, TextBox, cu->totbox, cu->tb);
- }
- else {
- /* is also the order of reading */
- LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
- BLO_write_struct(writer, Nurb, nu);
- }
- LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
- if (nu->type == CU_BEZIER) {
- BLO_write_struct_array(writer, BezTriple, nu->pntsu, nu->bezt);
- }
- else {
-
- BLO_write_struct_array(writer, BPoint, nu->pntsu * nu->pntsv, nu->bp);
- if (nu->knotsu) {
- BLO_write_float_array(writer, KNOTSU(nu), nu->knotsu);
- }
- if (nu->knotsv) {
- BLO_write_float_array(writer, KNOTSV(nu), nu->knotsv);
- }
- }
- }
- }
- }
-}
-
static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address)
{
if (tex->id.us > 0 || BLO_write_is_undo(writer)) {
@@ -2801,9 +2754,6 @@ static bool write_file_handle(Main *mainvar,
case ID_SCE:
write_scene(&writer, (Scene *)id_buffer, id);
break;
- case ID_CU:
- write_curve(&writer, (Curve *)id_buffer, id);
- break;
case ID_CA:
write_camera(&writer, (Camera *)id_buffer, id);
break;
@@ -2870,6 +2820,7 @@ static bool write_file_handle(Main *mainvar,
case ID_LA:
case ID_MA:
case ID_MB:
+ case ID_CU:
/* Do nothing, handled in IDTypeInfo callback. */
break;
case ID_LI: