Refactor: move Texture .blend I/O to IDTypeInfo callbacks

This commit is contained in:
2020-09-11 10:35:36 +02:00
parent b2fc067854
commit 16fecdf994
3 changed files with 69 additions and 74 deletions

View File

@@ -36,6 +36,9 @@
#include "BLT_translation.h"
/* Allow using deprecated functionality for .blend file I/O. */
#define DNA_DEPRECATED_ALLOW
#include "DNA_brush_types.h"
#include "DNA_color_types.h"
#include "DNA_defaults.h"
@@ -50,6 +53,7 @@
#include "BKE_main.h"
#include "BKE_anim_data.h"
#include "BKE_colorband.h"
#include "BKE_colortools.h"
#include "BKE_icons.h"
@@ -65,6 +69,8 @@
#include "RE_shader_ext.h"
#include "BLO_read_write.h"
static void texture_init_data(ID *id)
{
Tex *texture = (Tex *)id;
@@ -134,6 +140,62 @@ static void texture_foreach_id(ID *id, LibraryForeachIDData *data)
BKE_LIB_FOREACHID_PROCESS(data, texture->ima, IDWALK_CB_USER);
}
static void texture_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Tex *tex = (Tex *)id;
if (tex->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Tex, id_address, &tex->id);
BKE_id_blend_write(writer, &tex->id);
if (tex->adt) {
BKE_animdata_blend_write(writer, tex->adt);
}
/* direct data */
if (tex->coba) {
BLO_write_struct(writer, ColorBand, tex->coba);
}
/* nodetree is integral part of texture, no libdata */
if (tex->nodetree) {
BLO_write_struct(writer, bNodeTree, tex->nodetree);
ntreeBlendWrite(writer, tex->nodetree);
}
BKE_previewimg_blend_write(writer, tex->preview);
}
}
static void texture_blend_read_data(BlendDataReader *reader, ID *id)
{
Tex *tex = (Tex *)id;
BLO_read_data_address(reader, &tex->adt);
BKE_animdata_blend_read_data(reader, tex->adt);
BLO_read_data_address(reader, &tex->coba);
BLO_read_data_address(reader, &tex->preview);
BKE_previewimg_blend_read(reader, tex->preview);
tex->iuser.ok = 1;
tex->iuser.scene = NULL;
}
static void texture_blend_read_lib(BlendLibReader *reader, ID *id)
{
Tex *tex = (Tex *)id;
BLO_read_id_address(reader, tex->id.lib, &tex->ima);
BLO_read_id_address(reader, tex->id.lib, &tex->ipo); // XXX deprecated - old animation system
}
static void texture_blend_read_expand(BlendExpander *expander, ID *id)
{
Tex *tex = (Tex *)id;
BLO_expand(expander, tex->ima);
BLO_expand(expander, tex->ipo); // XXX deprecated - old animation system
}
IDTypeInfo IDType_ID_TE = {
.id_code = ID_TE,
.id_filter = FILTER_ID_TE,
@@ -151,10 +213,10 @@ IDTypeInfo IDType_ID_TE = {
.foreach_id = texture_foreach_id,
.foreach_cache = NULL,
.blend_write = NULL,
.blend_read_data = NULL,
.blend_read_lib = NULL,
.blend_read_expand = NULL,
.blend_write = texture_blend_write,
.blend_read_data = texture_blend_read_data,
.blend_read_lib = texture_blend_read_lib,
.blend_read_expand = texture_blend_read_expand,
};
/* Utils for all IDs using those texture slots. */

View File

@@ -2803,32 +2803,6 @@ void blo_do_versions_key_uidgen(Key *key)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Read ID: Texture
* \{ */
static void lib_link_texture(BlendLibReader *reader, Tex *tex)
{
BLO_read_id_address(reader, tex->id.lib, &tex->ima);
BLO_read_id_address(reader, tex->id.lib, &tex->ipo); // XXX deprecated - old animation system
}
static void direct_link_texture(BlendDataReader *reader, Tex *tex)
{
BLO_read_data_address(reader, &tex->adt);
BKE_animdata_blend_read_data(reader, tex->adt);
BLO_read_data_address(reader, &tex->coba);
BLO_read_data_address(reader, &tex->preview);
BKE_previewimg_blend_read(reader, tex->preview);
tex->iuser.ok = 1;
tex->iuser.scene = NULL;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Read ID: Particle Settings
* \{ */
@@ -6630,9 +6604,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_TE:
direct_link_texture(&reader, (Tex *)id);
break;
case ID_IP:
direct_link_ipo(&reader, (Ipo *)id);
break;
@@ -6692,6 +6663,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_AR:
case ID_LP:
case ID_KE:
case ID_TE:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
@@ -7336,9 +7308,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_VO:
lib_link_volume(&reader, (Volume *)id);
break;
case ID_TE:
lib_link_texture(&reader, (Tex *)id);
break;
case ID_GD:
lib_link_gpencil(&reader, (bGPdata *)id);
break;
@@ -7375,6 +7344,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_AR:
case ID_LP:
case ID_KE:
case ID_TE:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
@@ -8060,12 +8030,6 @@ static void expand_collection(BlendExpander *expander, Collection *collection)
#endif
}
static void expand_texture(BlendExpander *expander, Tex *tex)
{
BLO_expand(expander, tex->ima);
BLO_expand(expander, tex->ipo); // XXX deprecated - old animation system
}
/* callback function used to expand constraint ID-links */
static void expand_constraint_cb(bConstraint *UNUSED(con),
ID **idpoin,
@@ -8412,9 +8376,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
case ID_SCE:
expand_scene(&expander, (Scene *)id);
break;
case ID_TE:
expand_texture(&expander, (Tex *)id);
break;
case ID_SO:
expand_sound(&expander, (bSound *)id);
break;

View File

@@ -1393,32 +1393,6 @@ static void write_object(BlendWriter *writer, Object *ob, const void *id_address
}
}
static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address)
{
if (tex->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Tex, id_address, &tex->id);
BKE_id_blend_write(writer, &tex->id);
if (tex->adt) {
BKE_animdata_blend_write(writer, tex->adt);
}
/* direct data */
if (tex->coba) {
BLO_write_struct(writer, ColorBand, tex->coba);
}
/* nodetree is integral part of texture, no libdata */
if (tex->nodetree) {
BLO_write_struct(writer, bNodeTree, tex->nodetree);
ntreeBlendWrite(writer, tex->nodetree);
}
BKE_previewimg_blend_write(writer, tex->preview);
}
}
static void write_collection_nolib(BlendWriter *writer, Collection *collection)
{
/* Shared function for collection data-blocks and scene master collection. */
@@ -2580,9 +2554,6 @@ static bool write_file_handle(Main *mainvar,
case ID_OB:
write_object(&writer, (Object *)id_buffer, id);
break;
case ID_TE:
write_texture(&writer, (Tex *)id_buffer, id);
break;
case ID_PA:
write_particlesettings(&writer, (ParticleSettings *)id_buffer, id);
break;
@@ -2627,6 +2598,7 @@ static bool write_file_handle(Main *mainvar,
case ID_AR:
case ID_LP:
case ID_KE:
case ID_TE:
/* Do nothing, handled in IDTypeInfo callback. */
break;
case ID_LI: