diff options
author | Jacques Lucke <jacques@blender.org> | 2020-09-10 16:40:08 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-09-10 16:40:32 +0300 |
commit | 8e4cc07547a7d3d5474de31ae27ac9d62bf35e9f (patch) | |
tree | 6ccdb0f6b904e5b826294838cf5cd2f6388219ee /source/blender | |
parent | 3cafaf0fa86859e81af21d55f0dbfc8c0e1b70a0 (diff) |
Refactor: move PaintCurve/Palette .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/paint.c | 47 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 42 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 31 |
3 files changed, 49 insertions, 71 deletions
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 278c6c0ee53..545d1bdee13 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -72,6 +72,8 @@ #include "RNA_enum_types.h" +#include "BLO_read_write.h" + #include "bmesh.h" static void palette_init_data(ID *id) @@ -102,6 +104,26 @@ static void palette_free_data(ID *id) BLI_freelistN(&palette->colors); } +static void palette_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Palette *palette = (Palette *)id; + if (palette->id.us > 0 || BLO_write_is_undo(writer)) { + PaletteColor *color; + BLO_write_id_struct(writer, Palette, id_address, &palette->id); + BKE_id_blend_write(writer, &palette->id); + + for (color = palette->colors.first; color; color = color->next) { + BLO_write_struct(writer, PaletteColor, color); + } + } +} + +static void palette_blend_read_data(BlendDataReader *reader, ID *id) +{ + Palette *palette = (Palette *)id; + BLO_read_list(reader, &palette->colors); +} + IDTypeInfo IDType_ID_PAL = { .id_code = ID_PAL, .id_filter = FILTER_ID_PAL, @@ -119,8 +141,8 @@ IDTypeInfo IDType_ID_PAL = { .foreach_id = NULL, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, + .blend_write = palette_blend_write, + .blend_read_data = palette_blend_read_data, .blend_read_lib = NULL, .blend_read_expand = NULL, }; @@ -146,6 +168,23 @@ static void paint_curve_free_data(ID *id) paint_curve->tot_points = 0; } +static void paint_curve_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + PaintCurve *pc = (PaintCurve *)id; + if (pc->id.us > 0 || BLO_write_is_undo(writer)) { + BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id); + BKE_id_blend_write(writer, &pc->id); + + BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points); + } +} + +static void paint_curve_blend_read_data(BlendDataReader *reader, ID *id) +{ + PaintCurve *pc = (PaintCurve *)id; + BLO_read_data_address(reader, &pc->points); +} + IDTypeInfo IDType_ID_PC = { .id_code = ID_PC, .id_filter = FILTER_ID_PC, @@ -163,8 +202,8 @@ IDTypeInfo IDType_ID_PC = { .foreach_id = NULL, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, + .blend_write = paint_curve_blend_write, + .blend_read_data = paint_curve_blend_read_data, .blend_read_lib = NULL, .blend_read_expand = NULL, }; diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 1c638079230..139f049533f 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2580,32 +2580,6 @@ static void direct_link_brush(BlendDataReader *reader, Brush *brush) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID: Palette - * \{ */ - -static void lib_link_palette(BlendLibReader *UNUSED(reader), Palette *UNUSED(palette)) -{ -} - -static void direct_link_palette(BlendDataReader *reader, Palette *palette) -{ - - /* palette itself has been read */ - BLO_read_list(reader, &palette->colors); -} - -static void lib_link_paint_curve(BlendLibReader *UNUSED(reader), PaintCurve *UNUSED(pc)) -{ -} - -static void direct_link_paint_curve(BlendDataReader *reader, PaintCurve *pc) -{ - BLO_read_data_address(reader, &pc->points); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read Animation (legacy for version patching) * \{ */ @@ -7335,12 +7309,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_MSK: direct_link_mask(&reader, (Mask *)id); break; - case ID_PAL: - direct_link_palette(&reader, (Palette *)id); - break; - case ID_PC: - direct_link_paint_curve(&reader, (PaintCurve *)id); - break; case ID_CF: direct_link_cachefile(&reader, (CacheFile *)id); break; @@ -7367,6 +7335,8 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_TXT: case ID_VF: case ID_MC: + case ID_PAL: + case ID_PC: /* Do nothing. Handled by IDTypeInfo callback. */ break; } @@ -8005,9 +7975,6 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_PA: lib_link_particlesettings(&reader, (ParticleSettings *)id); break; - case ID_PC: - lib_link_paint_curve(&reader, (PaintCurve *)id); - break; case ID_BR: lib_link_brush(&reader, (Brush *)id); break; @@ -8056,9 +8023,6 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_GD: lib_link_gpencil(&reader, (bGPdata *)id); break; - case ID_PAL: - lib_link_palette(&reader, (Palette *)id); - break; case ID_KE: lib_link_key(&reader, (Key *)id); break; @@ -8080,6 +8044,8 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_TXT: case ID_VF: case ID_MC: + case ID_PAL: + case ID_PC: /* Do nothing. Handled by IDTypeInfo callback. */ break; } diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 82cf8887396..95e86efdc39 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2483,29 +2483,6 @@ static void write_brush(BlendWriter *writer, Brush *brush, const void *id_addres } } -static void write_palette(BlendWriter *writer, Palette *palette, const void *id_address) -{ - if (palette->id.us > 0 || BLO_write_is_undo(writer)) { - PaletteColor *color; - BLO_write_id_struct(writer, Palette, id_address, &palette->id); - BKE_id_blend_write(writer, &palette->id); - - for (color = palette->colors.first; color; color = color->next) { - BLO_write_struct(writer, PaletteColor, color); - } - } -} - -static void write_paintcurve(BlendWriter *writer, PaintCurve *pc, const void *id_address) -{ - if (pc->id.us > 0 || BLO_write_is_undo(writer)) { - BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id); - BKE_id_blend_write(writer, &pc->id); - - BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points); - } -} - static void write_mask(BlendWriter *writer, Mask *mask, const void *id_address) { if (mask->id.us > 0 || BLO_write_is_undo(writer)) { @@ -3040,12 +3017,6 @@ static bool write_file_handle(Main *mainvar, case ID_BR: write_brush(&writer, (Brush *)id_buffer, id); break; - case ID_PAL: - write_palette(&writer, (Palette *)id_buffer, id); - break; - case ID_PC: - write_paintcurve(&writer, (PaintCurve *)id_buffer, id); - break; case ID_GD: write_gpencil(&writer, (bGPdata *)id_buffer, id); break; @@ -3072,6 +3043,8 @@ static bool write_file_handle(Main *mainvar, case ID_TXT: case ID_VF: case ID_MC: + case ID_PC: + case ID_PAL: /* Do nothing, handled in IDTypeInfo callback. */ break; case ID_LI: |