Commit: 89b570570acdcf2648380fea9ab039d39f5d2693 Author: Jacques Lucke Date: Thu Sep 10 16:37:11 2020 +0200 Branches: master https://developer.blender.org/rB89b570570acdcf2648380fea9ab039d39f5d2693
Refactor: move MetaBall .blend I/O to IDTypeInfo callbacks =================================================================== M source/blender/blenkernel/intern/mball.c M source/blender/blenloader/intern/readfile.c M source/blender/blenloader/intern/writefile.c =================================================================== diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 2a1ac12baaa..d71c100ed87 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -35,6 +35,9 @@ #include "MEM_guardedalloc.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_defaults.h" #include "DNA_material_types.h" #include "DNA_meta_types.h" @@ -50,6 +53,7 @@ #include "BKE_main.h" +#include "BKE_anim_data.h" #include "BKE_curve.h" #include "BKE_displist.h" #include "BKE_idtype.h" @@ -62,6 +66,8 @@ #include "DEG_depsgraph.h" +#include "BLO_read_write.h" + static void metaball_init_data(ID *id) { MetaBall *metaball = (MetaBall *)id; @@ -110,6 +116,71 @@ static void metaball_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void metaball_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + MetaBall *mb = (MetaBall *)id; + if (mb->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + BLI_listbase_clear(&mb->disp); + mb->editelems = NULL; + /* Must always be cleared (meta's don't have their own edit-data). */ + mb->needs_flush_to_id = 0; + mb->lastelem = NULL; + mb->batch_cache = NULL; + + /* write LibData */ + BLO_write_id_struct(writer, MetaBall, id_address, &mb->id); + BKE_id_blend_write(writer, &mb->id); + + /* direct data */ + BLO_write_pointer_array(writer, mb->totcol, mb->mat); + if (mb->adt) { + BKE_animdata_blend_write(writer, mb->adt); + } + + LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) { + BLO_write_struct(writer, MetaElem, ml); + } + } +} + +static void metaball_blend_read_data(BlendDataReader *reader, ID *id) +{ + MetaBall *mb = (MetaBall *)id; + BLO_read_data_address(reader, &mb->adt); + BKE_animdata_blend_read_data(reader, mb->adt); + + BLO_read_pointer_array(reader, (void **)&mb->mat); + + BLO_read_list(reader, &(mb->elems)); + + BLI_listbase_clear(&mb->disp); + mb->editelems = NULL; + /* Must always be cleared (meta's don't have their own edit-data). */ + mb->needs_flush_to_id = 0; + /* mb->edit_elems.first= mb->edit_elems.last= NULL;*/ + mb->lastelem = NULL; + mb->batch_cache = NULL; +} + +static void metaball_blend_read_lib(BlendLibReader *reader, ID *id) +{ + MetaBall *mb = (MetaBall *)id; + for (int a = 0; a < mb->totcol; a++) { + BLO_read_id_address(reader, mb->id.lib, &mb->mat[a]); + } + + BLO_read_id_address(reader, mb->id.lib, &mb->ipo); // XXX deprecated - old animation system +} + +static void metaball_blend_read_expand(BlendExpander *expander, ID *id) +{ + MetaBall *mb = (MetaBall *)id; + for (int a = 0; a < mb->totcol; a++) { + BLO_expand(expander, mb->mat[a]); + } +} + IDTypeInfo IDType_ID_MB = { .id_code = ID_MB, .id_filter = FILTER_ID_MB, @@ -127,10 +198,10 @@ IDTypeInfo IDType_ID_MB = { .foreach_id = metaball_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = metaball_blend_write, + .blend_read_data = metaball_blend_read_data, + .blend_read_lib = metaball_blend_read_lib, + .blend_read_expand = metaball_blend_read_expand, }; /* Functions */ diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 277ccce3560..0ab4c9b4171 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2943,39 +2943,6 @@ static void direct_link_key(BlendDataReader *reader, Key *key) /** \} */ -/* -------------------------------------------------------------------- */ -/** \name Read ID: Meta Ball - * \{ */ - -static void lib_link_mball(BlendLibReader *reader, MetaBall *mb) -{ - for (int a = 0; a < mb->totcol; a++) { - BLO_read_id_address(reader, mb->id.lib, &mb->mat[a]); - } - - BLO_read_id_address(reader, mb->id.lib, &mb->ipo); // XXX deprecated - old animation system -} - -static void direct_link_mball(BlendDataReader *reader, MetaBall *mb) -{ - BLO_read_data_address(reader, &mb->adt); - BKE_animdata_blend_read_data(reader, mb->adt); - - BLO_read_pointer_array(reader, (void **)&mb->mat); - - BLO_read_list(reader, &(mb->elems)); - - BLI_listbase_clear(&mb->disp); - mb->editelems = NULL; - /* Must always be cleared (meta's don't have their own edit-data). */ - mb->needs_flush_to_id = 0; - /* mb->edit_elems.first= mb->edit_elems.last= NULL;*/ - mb->lastelem = NULL; - mb->batch_cache = NULL; -} - -/** \} */ - /* -------------------------------------------------------------------- */ /** \name Read ID: World * \{ */ @@ -7039,9 +7006,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_CU: direct_link_curve(&reader, (Curve *)id); break; - case ID_MB: - direct_link_mball(&reader, (MetaBall *)id); - break; case ID_TE: direct_link_texture(&reader, (Tex *)id); break; @@ -7116,6 +7080,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_IM: case ID_LA: case ID_MA: + case ID_MB: /* Do nothing. Handled by IDTypeInfo callback. */ break; } @@ -7763,9 +7728,6 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_CA: lib_link_camera(&reader, (Camera *)id); break; - case ID_MB: - lib_link_mball(&reader, (MetaBall *)id); - break; case ID_CU: lib_link_curve(&reader, (Curve *)id); break; @@ -7817,6 +7779,7 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_IM: case ID_LA: case ID_MA: + case ID_MB: /* Do nothing. Handled by IDTypeInfo callback. */ break; } @@ -8518,13 +8481,6 @@ static void expand_world(BlendExpander *expander, World *wrld) BLO_expand(expander, wrld->ipo); // XXX deprecated - old animation system } -static void expand_mball(BlendExpander *expander, MetaBall *mb) -{ - for (int a = 0; a < mb->totcol; a++) { - BLO_expand(expander, mb->mat[a]); - } -} - static void expand_curve(BlendExpander *expander, Curve *cu) { for (int a = 0; a < cu->totcol; a++) { @@ -8948,9 +8904,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) case ID_CU: expand_curve(&expander, (Curve *)id); break; - case ID_MB: - expand_mball(&expander, (MetaBall *)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 acf4e1ca635..db7a41c8622 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1431,32 +1431,6 @@ static void write_camera(BlendWriter *writer, Camera *cam, const void *id_addres } } -static void write_mball(BlendWriter *writer, MetaBall *mb, const void *id_address) -{ - if (mb->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - BLI_listbase_clear(&mb->disp); - mb->editelems = NULL; - /* Must always be cleared (meta's don't have their own edit-data). */ - mb->needs_flush_to_id = 0; - mb->lastelem = NULL; - mb->batch_cache = NULL; - - /* write LibData */ - BLO_write_id_struct(writer, MetaBall, id_address, &mb->id); - BKE_id_blend_write(writer, &mb->id); - - /* direct data */ - BLO_write_pointer_array(writer, mb->totcol, mb->mat); - if (mb->adt) { - BKE_animdata_blend_write(writer, mb->adt); - } - - LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) { - BLO_write_struct(writer, MetaElem, ml); - } - } -} static void write_curve(BlendWriter *writer, Curve *cu, const void *id_address) { @@ -2831,9 +2805,6 @@ static bool write_file_handle(Main *mainvar, case ID_CU: write_curve(&writer, (Curve *)id_buffer, id); break; - case ID_MB: - write_mball(&writer, (MetaBall *)id_buffer, id); - break; case ID_CA: write_camera(&writer, (Camera *)id_buffer, id); break; @@ -2899,6 +2870,7 @@ static bool write_file_handle(Main *mainvar, case ID_IM: case ID_LA: case ID_MA: + case ID_MB: /* Do nothing, handled in IDTypeInfo callback. */ break; case ID_LI: _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs