Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-09-11 12:39:06 +0300
committerJacques Lucke <jacques@blender.org>2020-09-11 12:39:06 +0300
commit12693b807ec0f3daf16f05ae621c7aec98ce2c61 (patch)
treecc14a6d79042fbf5f4ecd0c7ee000472e6961321 /source/blender
parent1025b5b924ce7a25b4db9b63f43cd2bba55fbede (diff)
Refactor: move Volume .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/intern/volume.cc65
-rw-r--r--source/blender/blenloader/BLO_read_write.h2
-rw-r--r--source/blender/blenloader/intern/readfile.c48
-rw-r--r--source/blender/blenloader/intern/writefile.c24
4 files changed, 65 insertions, 74 deletions
diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc
index f99be2f6aee..eb871e41f8e 100644
--- a/source/blender/blenkernel/intern/volume.cc
+++ b/source/blender/blenkernel/intern/volume.cc
@@ -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)
diff --git a/source/blender/blenloader/BLO_read_write.h b/source/blender/blenloader/BLO_read_write.h
index e05c1046b95..8a6811444af 100644
--- a/source/blender/blenloader/BLO_read_write.h
+++ b/source/blender/blenloader/BLO_read_write.h
@@ -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);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index f72568ed11f..f32168092eb 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6239,36 +6239,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;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 386cdfc50eb..8390838163d 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -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: