Refactor: move World .blend I/O to IDTypeInfo callbacks
This commit is contained in:
parent
095a53bd88
commit
60e102c0a0
|
@ -27,6 +27,9 @@
|
|||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
/* Allow using deprecated functionality for .blend file I/O. */
|
||||
#define DNA_DEPRECATED_ALLOW
|
||||
|
||||
#include "DNA_defaults.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_texture_types.h"
|
||||
|
@ -35,6 +38,7 @@
|
|||
#include "BLI_listbase.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "BKE_anim_data.h"
|
||||
#include "BKE_icons.h"
|
||||
#include "BKE_idtype.h"
|
||||
#include "BKE_lib_id.h"
|
||||
|
@ -51,6 +55,8 @@
|
|||
|
||||
#include "GPU_material.h"
|
||||
|
||||
#include "BLO_read_write.h"
|
||||
|
||||
/** Free (or release) any data used by this world (does not free the world itself). */
|
||||
static void world_free_data(ID *id)
|
||||
{
|
||||
|
@ -122,6 +128,54 @@ static void world_foreach_id(ID *id, LibraryForeachIDData *data)
|
|||
}
|
||||
}
|
||||
|
||||
static void world_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
||||
{
|
||||
World *wrld = (World *)id;
|
||||
if (wrld->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
||||
BLI_listbase_clear(&wrld->gpumaterial);
|
||||
|
||||
/* write LibData */
|
||||
BLO_write_id_struct(writer, World, id_address, &wrld->id);
|
||||
BKE_id_blend_write(writer, &wrld->id);
|
||||
|
||||
if (wrld->adt) {
|
||||
BKE_animdata_blend_write(writer, wrld->adt);
|
||||
}
|
||||
|
||||
/* nodetree is integral part of world, no libdata */
|
||||
if (wrld->nodetree) {
|
||||
BLO_write_struct(writer, bNodeTree, wrld->nodetree);
|
||||
ntreeBlendWrite(writer, wrld->nodetree);
|
||||
}
|
||||
|
||||
BKE_previewimg_blend_write(writer, wrld->preview);
|
||||
}
|
||||
}
|
||||
|
||||
static void world_blend_read_data(BlendDataReader *reader, ID *id)
|
||||
{
|
||||
World *wrld = (World *)id;
|
||||
BLO_read_data_address(reader, &wrld->adt);
|
||||
BKE_animdata_blend_read_data(reader, wrld->adt);
|
||||
|
||||
BLO_read_data_address(reader, &wrld->preview);
|
||||
BKE_previewimg_blend_read(reader, wrld->preview);
|
||||
BLI_listbase_clear(&wrld->gpumaterial);
|
||||
}
|
||||
|
||||
static void world_blend_read_lib(BlendLibReader *reader, ID *id)
|
||||
{
|
||||
World *wrld = (World *)id;
|
||||
BLO_read_id_address(reader, wrld->id.lib, &wrld->ipo); // XXX deprecated - old animation system
|
||||
}
|
||||
|
||||
static void world_blend_read_expand(BlendExpander *expander, ID *id)
|
||||
{
|
||||
World *wrld = (World *)id;
|
||||
BLO_expand(expander, wrld->ipo); // XXX deprecated - old animation system
|
||||
}
|
||||
|
||||
IDTypeInfo IDType_ID_WO = {
|
||||
.id_code = ID_WO,
|
||||
.id_filter = FILTER_ID_WO,
|
||||
|
@ -139,10 +193,10 @@ IDTypeInfo IDType_ID_WO = {
|
|||
.foreach_id = world_foreach_id,
|
||||
.foreach_cache = NULL,
|
||||
|
||||
.blend_write = NULL,
|
||||
.blend_read_data = NULL,
|
||||
.blend_read_lib = NULL,
|
||||
.blend_read_expand = NULL,
|
||||
.blend_write = world_blend_write,
|
||||
.blend_read_data = world_blend_read_data,
|
||||
.blend_read_lib = world_blend_read_lib,
|
||||
.blend_read_expand = world_blend_read_expand,
|
||||
};
|
||||
|
||||
World *BKE_world_add(Main *bmain, const char *name)
|
||||
|
|
|
@ -2911,27 +2911,6 @@ static void direct_link_key(BlendDataReader *reader, Key *key)
|
|||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Read ID: World
|
||||
* \{ */
|
||||
|
||||
static void lib_link_world(BlendLibReader *reader, World *wrld)
|
||||
{
|
||||
BLO_read_id_address(reader, wrld->id.lib, &wrld->ipo); // XXX deprecated - old animation system
|
||||
}
|
||||
|
||||
static void direct_link_world(BlendDataReader *reader, World *wrld)
|
||||
{
|
||||
BLO_read_data_address(reader, &wrld->adt);
|
||||
BKE_animdata_blend_read_data(reader, wrld->adt);
|
||||
|
||||
BLO_read_data_address(reader, &wrld->preview);
|
||||
BKE_previewimg_blend_read(reader, wrld->preview);
|
||||
BLI_listbase_clear(&wrld->gpumaterial);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Read ID: Texture
|
||||
* \{ */
|
||||
|
@ -6889,9 +6868,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
|
|||
case ID_KE:
|
||||
direct_link_key(&reader, (Key *)id);
|
||||
break;
|
||||
case ID_WO:
|
||||
direct_link_world(&reader, (World *)id);
|
||||
break;
|
||||
case ID_LI:
|
||||
direct_link_library(fd, (Library *)id, main);
|
||||
break;
|
||||
|
@ -6954,6 +6930,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
|
|||
case ID_MB:
|
||||
case ID_CU:
|
||||
case ID_CA:
|
||||
case ID_WO:
|
||||
/* Do nothing. Handled by IDTypeInfo callback. */
|
||||
break;
|
||||
}
|
||||
|
@ -7580,9 +7557,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
|
|||
* 3D viewport may contains pointers to other ID data (like bgpic)! See T41411. */
|
||||
lib_link_screen(&reader, (bScreen *)id);
|
||||
break;
|
||||
case ID_WO:
|
||||
lib_link_world(&reader, (World *)id);
|
||||
break;
|
||||
case ID_LP:
|
||||
lib_link_lightprobe(&reader, (LightProbe *)id);
|
||||
break;
|
||||
|
@ -7649,6 +7623,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
|
|||
case ID_MB:
|
||||
case ID_CU:
|
||||
case ID_CA:
|
||||
case ID_WO:
|
||||
/* Do nothing. Handled by IDTypeInfo callback. */
|
||||
break;
|
||||
}
|
||||
|
@ -8345,11 +8320,6 @@ static void expand_texture(BlendExpander *expander, Tex *tex)
|
|||
BLO_expand(expander, tex->ipo); // XXX deprecated - old animation system
|
||||
}
|
||||
|
||||
static void expand_world(BlendExpander *expander, World *wrld)
|
||||
{
|
||||
BLO_expand(expander, wrld->ipo); // XXX deprecated - old animation system
|
||||
}
|
||||
|
||||
/* callback function used to expand constraint ID-links */
|
||||
static void expand_constraint_cb(bConstraint *UNUSED(con),
|
||||
ID **idpoin,
|
||||
|
@ -8745,9 +8715,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
|
|||
case ID_TE:
|
||||
expand_texture(&expander, (Tex *)id);
|
||||
break;
|
||||
case ID_WO:
|
||||
expand_world(&expander, (World *)id);
|
||||
break;
|
||||
case ID_KE:
|
||||
expand_key(&expander, (Key *)id);
|
||||
break;
|
||||
|
|
|
@ -1440,30 +1440,6 @@ static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address)
|
|||
}
|
||||
}
|
||||
|
||||
static void write_world(BlendWriter *writer, World *wrld, const void *id_address)
|
||||
{
|
||||
if (wrld->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
||||
BLI_listbase_clear(&wrld->gpumaterial);
|
||||
|
||||
/* write LibData */
|
||||
BLO_write_id_struct(writer, World, id_address, &wrld->id);
|
||||
BKE_id_blend_write(writer, &wrld->id);
|
||||
|
||||
if (wrld->adt) {
|
||||
BKE_animdata_blend_write(writer, wrld->adt);
|
||||
}
|
||||
|
||||
/* nodetree is integral part of world, no libdata */
|
||||
if (wrld->nodetree) {
|
||||
BLO_write_struct(writer, bNodeTree, wrld->nodetree);
|
||||
ntreeBlendWrite(writer, wrld->nodetree);
|
||||
}
|
||||
|
||||
BKE_previewimg_blend_write(writer, wrld->preview);
|
||||
}
|
||||
}
|
||||
|
||||
static void write_collection_nolib(BlendWriter *writer, Collection *collection)
|
||||
{
|
||||
/* Shared function for collection data-blocks and scene master collection. */
|
||||
|
@ -2740,9 +2716,6 @@ static bool write_file_handle(Main *mainvar,
|
|||
case ID_KE:
|
||||
write_key(&writer, (Key *)id_buffer, id);
|
||||
break;
|
||||
case ID_WO:
|
||||
write_world(&writer, (World *)id_buffer, id);
|
||||
break;
|
||||
case ID_SPK:
|
||||
write_speaker(&writer, (Speaker *)id_buffer, id);
|
||||
break;
|
||||
|
@ -2802,6 +2775,7 @@ static bool write_file_handle(Main *mainvar,
|
|||
case ID_MB:
|
||||
case ID_CU:
|
||||
case ID_CA:
|
||||
case ID_WO:
|
||||
/* Do nothing, handled in IDTypeInfo callback. */
|
||||
break;
|
||||
case ID_LI:
|
||||
|
|
Loading…
Reference in New Issue