Refactor: move Volume .blend I/O to IDTypeInfo callbacks
This commit is contained in:
parent
1025b5b924
commit
12693b807e
|
@ -51,6 +51,8 @@
|
|||
|
||||
#include "DEG_depsgraph_query.h"
|
||||
|
||||
#include "BLO_read_write.h"
|
||||
|
||||
#include "CLG_log.h"
|
||||
|
||||
#ifdef WITH_OPENVDB
|
||||
|
@ -509,6 +511,61 @@ static void volume_foreach_cache(ID *id,
|
|||
function_callback(id, &key, (void **)&volume->runtime.grids, 0, user_data);
|
||||
}
|
||||
|
||||
static void volume_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
||||
{
|
||||
Volume *volume = (Volume *)id;
|
||||
if (volume->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
||||
volume->runtime.grids = 0;
|
||||
|
||||
/* write LibData */
|
||||
BLO_write_id_struct(writer, Volume, id_address, &volume->id);
|
||||
BKE_id_blend_write(writer, &volume->id);
|
||||
|
||||
/* direct data */
|
||||
BLO_write_pointer_array(writer, volume->totcol, volume->mat);
|
||||
if (volume->adt) {
|
||||
BKE_animdata_blend_write(writer, volume->adt);
|
||||
}
|
||||
|
||||
BKE_packedfile_blend_write(writer, volume->packedfile);
|
||||
}
|
||||
}
|
||||
|
||||
static void volume_blend_read_data(BlendDataReader *reader, ID *id)
|
||||
{
|
||||
Volume *volume = (Volume *)id;
|
||||
BLO_read_data_address(reader, &volume->adt);
|
||||
BKE_animdata_blend_read_data(reader, volume->adt);
|
||||
|
||||
BKE_packedfile_blend_read(reader, &volume->packedfile);
|
||||
volume->runtime.frame = 0;
|
||||
|
||||
/* materials */
|
||||
BLO_read_pointer_array(reader, (void **)&volume->mat);
|
||||
}
|
||||
|
||||
static void volume_blend_read_lib(BlendLibReader *reader, ID *id)
|
||||
{
|
||||
Volume *volume = (Volume *)id;
|
||||
/* Needs to be done *after* cache pointers are restored (call to
|
||||
* `foreach_cache`/`blo_cache_storage_entry_restore_in_new`), easier for now to do it in
|
||||
* lib_link... */
|
||||
BKE_volume_init_grids(volume);
|
||||
|
||||
for (int a = 0; a < volume->totcol; a++) {
|
||||
BLO_read_id_address(reader, volume->id.lib, &volume->mat[a]);
|
||||
}
|
||||
}
|
||||
|
||||
static void volume_blend_read_expand(BlendExpander *expander, ID *id)
|
||||
{
|
||||
Volume *volume = (Volume *)id;
|
||||
for (int a = 0; a < volume->totcol; a++) {
|
||||
BLO_expand(expander, volume->mat[a]);
|
||||
}
|
||||
}
|
||||
|
||||
IDTypeInfo IDType_ID_VO = {
|
||||
/* id_code */ ID_VO,
|
||||
/* id_filter */ FILTER_ID_VO,
|
||||
|
@ -526,10 +583,10 @@ IDTypeInfo IDType_ID_VO = {
|
|||
/* foreach_id */ volume_foreach_id,
|
||||
/* foreach_cache */ volume_foreach_cache,
|
||||
|
||||
/* blend_write */ NULL,
|
||||
/* blend_read_data */ NULL,
|
||||
/* blend_read_lib */ NULL,
|
||||
/* blend_read_expand */ NULL,
|
||||
/* blend_write */ volume_blend_write,
|
||||
/* blend_read_data */ volume_blend_read_data,
|
||||
/* blend_read_lib */ volume_blend_read_lib,
|
||||
/* blend_read_expand */ volume_blend_read_expand,
|
||||
};
|
||||
|
||||
void BKE_volume_init_grids(Volume *volume)
|
||||
|
|
|
@ -210,7 +210,7 @@ bool BLO_read_data_is_undo(BlendDataReader *reader);
|
|||
ID *BLO_read_get_new_id_address(BlendLibReader *reader, struct Library *lib, struct ID *id);
|
||||
|
||||
#define BLO_read_id_address(reader, lib, id_ptr_p) \
|
||||
*(id_ptr_p) = (void *)BLO_read_get_new_id_address((reader), (lib), (ID *)*(id_ptr_p))
|
||||
*((void **)id_ptr_p) = (void *)BLO_read_get_new_id_address((reader), (lib), (ID *)*(id_ptr_p))
|
||||
|
||||
/* Misc. */
|
||||
bool BLO_read_lib_is_undo(BlendLibReader *reader);
|
||||
|
|
|
@ -6238,36 +6238,6 @@ static void lib_link_sound(BlendLibReader *reader, bSound *sound)
|
|||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Read ID: Volume
|
||||
* \{ */
|
||||
|
||||
static void lib_link_volume(BlendLibReader *reader, Volume *volume)
|
||||
{
|
||||
/* Needs to be done *after* cache pointers are restored (call to
|
||||
* `foreach_cache`/`blo_cache_storage_entry_restore_in_new`), easier for now to do it in
|
||||
* lib_link... */
|
||||
BKE_volume_init_grids(volume);
|
||||
|
||||
for (int a = 0; a < volume->totcol; a++) {
|
||||
BLO_read_id_address(reader, volume->id.lib, &volume->mat[a]);
|
||||
}
|
||||
}
|
||||
|
||||
static void direct_link_volume(BlendDataReader *reader, Volume *volume)
|
||||
{
|
||||
BLO_read_data_address(reader, &volume->adt);
|
||||
BKE_animdata_blend_read_data(reader, volume->adt);
|
||||
|
||||
BKE_packedfile_blend_read(reader, &volume->packedfile);
|
||||
volume->runtime.frame = 0;
|
||||
|
||||
/* materials */
|
||||
BLO_read_pointer_array(reader, (void **)&volume->mat);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Read ID: Simulation
|
||||
* \{ */
|
||||
|
@ -6479,9 +6449,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
|
|||
case ID_WS:
|
||||
direct_link_workspace(&reader, (WorkSpace *)id, main);
|
||||
break;
|
||||
case ID_VO:
|
||||
direct_link_volume(&reader, (Volume *)id);
|
||||
break;
|
||||
case ID_SIM:
|
||||
direct_link_simulation(&reader, (Simulation *)id);
|
||||
break;
|
||||
|
@ -6512,6 +6479,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
|
|||
case ID_GD:
|
||||
case ID_HA:
|
||||
case ID_PT:
|
||||
case ID_VO:
|
||||
/* Do nothing. Handled by IDTypeInfo callback. */
|
||||
break;
|
||||
}
|
||||
|
@ -7147,9 +7115,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
|
|||
case ID_CF:
|
||||
lib_link_cachefiles(&reader, (CacheFile *)id);
|
||||
break;
|
||||
case ID_VO:
|
||||
lib_link_volume(&reader, (Volume *)id);
|
||||
break;
|
||||
case ID_SIM:
|
||||
lib_link_simulation(&reader, (Simulation *)id);
|
||||
break;
|
||||
|
@ -7187,6 +7152,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
|
|||
case ID_GD:
|
||||
case ID_HA:
|
||||
case ID_PT:
|
||||
case ID_VO:
|
||||
/* Do nothing. Handled by IDTypeInfo callback. */
|
||||
break;
|
||||
}
|
||||
|
@ -8130,13 +8096,6 @@ static void expand_workspace(BlendExpander *expander, WorkSpace *workspace)
|
|||
}
|
||||
}
|
||||
|
||||
static void expand_volume(BlendExpander *expander, Volume *volume)
|
||||
{
|
||||
for (int a = 0; a < volume->totcol; a++) {
|
||||
BLO_expand(expander, volume->mat[a]);
|
||||
}
|
||||
}
|
||||
|
||||
static void expand_simulation(BlendExpander *expander, Simulation *simulation)
|
||||
{
|
||||
LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) {
|
||||
|
@ -8211,9 +8170,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
|
|||
case ID_WS:
|
||||
expand_workspace(&expander, (WorkSpace *)id);
|
||||
break;
|
||||
case ID_VO:
|
||||
expand_volume(&expander, (Volume *)id);
|
||||
break;
|
||||
case ID_SIM:
|
||||
expand_simulation(&expander, (Simulation *)id);
|
||||
break;
|
||||
|
|
|
@ -2104,26 +2104,6 @@ static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const voi
|
|||
}
|
||||
}
|
||||
|
||||
static void write_volume(BlendWriter *writer, Volume *volume, const void *id_address)
|
||||
{
|
||||
if (volume->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
||||
volume->runtime.grids = 0;
|
||||
|
||||
/* write LibData */
|
||||
BLO_write_id_struct(writer, Volume, id_address, &volume->id);
|
||||
BKE_id_blend_write(writer, &volume->id);
|
||||
|
||||
/* direct data */
|
||||
BLO_write_pointer_array(writer, volume->totcol, volume->mat);
|
||||
if (volume->adt) {
|
||||
BKE_animdata_blend_write(writer, volume->adt);
|
||||
}
|
||||
|
||||
BKE_packedfile_blend_write(writer, volume->packedfile);
|
||||
}
|
||||
}
|
||||
|
||||
static void write_simulation(BlendWriter *writer, Simulation *simulation, const void *id_address)
|
||||
{
|
||||
if (simulation->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
|
@ -2461,9 +2441,6 @@ static bool write_file_handle(Main *mainvar,
|
|||
case ID_CF:
|
||||
write_cachefile(&writer, (CacheFile *)id_buffer, id);
|
||||
break;
|
||||
case ID_VO:
|
||||
write_volume(&writer, (Volume *)id_buffer, id);
|
||||
break;
|
||||
case ID_SIM:
|
||||
write_simulation(&writer, (Simulation *)id_buffer, id);
|
||||
break;
|
||||
|
@ -2494,6 +2471,7 @@ static bool write_file_handle(Main *mainvar,
|
|||
case ID_GD:
|
||||
case ID_HA:
|
||||
case ID_PT:
|
||||
case ID_VO:
|
||||
/* Do nothing, handled in IDTypeInfo callback. */
|
||||
break;
|
||||
case ID_LI:
|
||||
|
|
Loading…
Reference in New Issue