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

This commit is contained in:
2020-09-10 17:31:18 +02:00
parent be5cbbabce
commit 0c7e77d416
3 changed files with 48 additions and 57 deletions

View File

@@ -28,12 +28,15 @@
#include "BLT_translation.h"
#include "BKE_anim_data.h"
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BKE_main.h"
#include "BKE_speaker.h"
#include "BLO_read_write.h"
static void speaker_init_data(ID *id)
{
Speaker *speaker = (Speaker *)id;
@@ -50,6 +53,44 @@ static void speaker_foreach_id(ID *id, LibraryForeachIDData *data)
BKE_LIB_FOREACHID_PROCESS(data, speaker->sound, IDWALK_CB_USER);
}
static void speaker_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
Speaker *spk = (Speaker *)id;
if (spk->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Speaker, id_address, &spk->id);
BKE_id_blend_write(writer, &spk->id);
if (spk->adt) {
BKE_animdata_blend_write(writer, spk->adt);
}
}
}
static void speaker_blend_read_data(BlendDataReader *reader, ID *id)
{
Speaker *spk = (Speaker *)id;
BLO_read_data_address(reader, &spk->adt);
BKE_animdata_blend_read_data(reader, spk->adt);
#if 0
spk->sound = newdataadr(fd, spk->sound);
direct_link_sound(fd, spk->sound);
#endif
}
static void speaker_blend_read_lib(BlendLibReader *reader, ID *id)
{
Speaker *spk = (Speaker *)id;
BLO_read_id_address(reader, spk->id.lib, &spk->sound);
}
static void speaker_blend_read_expand(BlendExpander *expander, ID *id)
{
Speaker *spk = (Speaker *)id;
BLO_expand(expander, spk->sound);
}
IDTypeInfo IDType_ID_SPK = {
.id_code = ID_SPK,
.id_filter = FILTER_ID_SPK,
@@ -67,10 +108,10 @@ IDTypeInfo IDType_ID_SPK = {
.foreach_id = speaker_foreach_id,
.foreach_cache = NULL,
.blend_write = NULL,
.blend_read_data = NULL,
.blend_read_lib = NULL,
.blend_read_expand = NULL,
.blend_write = speaker_blend_write,
.blend_read_data = speaker_blend_read_data,
.blend_read_lib = speaker_blend_read_lib,
.blend_read_expand = speaker_blend_read_expand,
};
void *BKE_speaker_add(Main *bmain, const char *name)

View File

@@ -6444,28 +6444,6 @@ static void direct_link_lightprobe(BlendDataReader *reader, LightProbe *prb)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Read ID: Speaker
* \{ */
static void lib_link_speaker(BlendLibReader *reader, Speaker *spk)
{
BLO_read_id_address(reader, spk->id.lib, &spk->sound);
}
static void direct_link_speaker(BlendDataReader *reader, Speaker *spk)
{
BLO_read_data_address(reader, &spk->adt);
BKE_animdata_blend_read_data(reader, spk->adt);
#if 0
spk->sound = newdataadr(fd, spk->sound);
direct_link_sound(fd, spk->sound);
#endif
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Read ID: Sound
* \{ */
@@ -6789,9 +6767,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_LI:
direct_link_library(fd, (Library *)id, main);
break;
case ID_SPK:
direct_link_speaker(&reader, (Speaker *)id);
break;
case ID_SO:
direct_link_sound(&reader, (bSound *)id);
break;
@@ -6847,6 +6822,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_CA:
case ID_WO:
case ID_MSK:
case ID_SPK:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
@@ -7473,9 +7449,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_LP:
lib_link_lightprobe(&reader, (LightProbe *)id);
break;
case ID_SPK:
lib_link_speaker(&reader, (Speaker *)id);
break;
case ID_PA:
lib_link_particlesettings(&reader, (ParticleSettings *)id);
break;
@@ -7538,6 +7511,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_CA:
case ID_WO:
case ID_MSK:
case ID_SPK:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
@@ -8496,11 +8470,6 @@ static void expand_cachefile(BlendExpander *UNUSED(expander), CacheFile *UNUSED(
{
}
static void expand_speaker(BlendExpander *expander, Speaker *spk)
{
BLO_expand(expander, spk->sound);
}
static void expand_sound(BlendExpander *expander, bSound *snd)
{
BLO_expand(expander, snd->ipo); // XXX deprecated - old animation system
@@ -8510,7 +8479,6 @@ static void expand_lightprobe(BlendExpander *UNUSED(expander), LightProbe *UNUSE
{
}
static void expand_gpencil(BlendExpander *expander, bGPdata *gpd)
{
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
@@ -8612,9 +8580,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
case ID_KE:
expand_key(&expander, (Key *)id);
break;
case ID_SPK:
expand_speaker(&expander, (Speaker *)id);
break;
case ID_SO:
expand_sound(&expander, (bSound *)id);
break;

View File

@@ -2187,19 +2187,6 @@ static void write_armature(BlendWriter *writer, bArmature *arm, const void *id_a
}
}
static void write_speaker(BlendWriter *writer, Speaker *spk, const void *id_address)
{
if (spk->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
BLO_write_id_struct(writer, Speaker, id_address, &spk->id);
BKE_id_blend_write(writer, &spk->id);
if (spk->adt) {
BKE_animdata_blend_write(writer, spk->adt);
}
}
}
static void write_sound(BlendWriter *writer, bSound *sound, const void *id_address)
{
if (sound->id.us > 0 || BLO_write_is_undo(writer)) {
@@ -2665,9 +2652,6 @@ static bool write_file_handle(Main *mainvar,
case ID_KE:
write_key(&writer, (Key *)id_buffer, id);
break;
case ID_SPK:
write_speaker(&writer, (Speaker *)id_buffer, id);
break;
case ID_LP:
write_probe(&writer, (LightProbe *)id_buffer, id);
break;
@@ -2726,6 +2710,7 @@ static bool write_file_handle(Main *mainvar,
case ID_CA:
case ID_WO:
case ID_MSK:
case ID_SPK:
/* Do nothing, handled in IDTypeInfo callback. */
break;
case ID_LI: