[Bf-blender-cvs] [d32aadab6e3] asset-metadata: Adapt to new file read/write design from master
Julian Eisel
noreply at git.blender.org
Mon Aug 31 16:04:13 CEST 2020
Commit: d32aadab6e3ea2a85152fbd98f87babb9245c572
Author: Julian Eisel
Date: Mon Aug 31 16:00:05 2020 +0200
Branches: asset-metadata
https://developer.blender.org/rBd32aadab6e3ea2a85152fbd98f87babb9245c572
Adapt to new file read/write design from master
Partially a compile fix for previous commit. But also moving asset-data
read/write into `asset.c`, like we do it for more and more
data-structures in master.
===================================================================
M source/blender/blenkernel/BKE_asset.h
M source/blender/blenkernel/intern/asset.c
M source/blender/blenkernel/intern/lib_id.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index 4954a2d64d2..bb81a05921c 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -27,6 +27,9 @@
extern "C" {
#endif
+struct BlendWriter;
+struct BlendDataReader;
+
struct AssetData *BKE_asset_data_create(void);
void BKE_asset_data_free(struct AssetData *asset_data);
@@ -40,6 +43,9 @@ struct CustomTagEnsureResult BKE_assetdata_tag_ensure(struct AssetData *asset_da
const char *name);
void BKE_assetdata_tag_remove(struct AssetData *asset_data, struct CustomTag *tag);
+void BKE_assetdata_write(struct BlendWriter *writer, struct AssetData *asset_data);
+void BKE_assetdata_read(struct BlendDataReader *reader, struct AssetData *asset_data);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index 8053c0cedb0..0f62ee6df1d 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -27,9 +27,12 @@
#include "BKE_asset.h"
#include "BKE_icons.h"
+#include "DNA_ID.h"
#include "DNA_asset_types.h"
#include "DNA_defaults.h"
+#include "BLO_read_write.h"
+
#include "MEM_guardedalloc.h"
AssetData *BKE_asset_data_create(void)
@@ -76,3 +79,25 @@ void BKE_assetdata_tag_remove(AssetData *asset_data, CustomTag *tag)
{
BLI_freelinkN(&asset_data->tags, tag);
}
+
+/* .blend file API -------------------------------------------- */
+
+void BKE_assetdata_write(BlendWriter *writer, AssetData *asset_data)
+{
+ BLO_write_struct(writer, AssetData, asset_data);
+
+ if (asset_data->description) {
+ BLO_write_string(writer, asset_data->description);
+ }
+ LISTBASE_FOREACH (CustomTag *, tag, &asset_data->tags) {
+ BLO_write_struct(writer, CustomTag, tag);
+ }
+}
+
+void BKE_assetdata_read(BlendDataReader *reader, AssetData *asset_data)
+{
+ /* asset_data itself has been read already. */
+
+ BLO_read_data_address(reader, &asset_data->description);
+ BLO_read_list(reader, &asset_data->tags);
+}
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index f8f171bd9d7..d35b052208f 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -56,6 +56,7 @@
#include "BKE_anim_data.h"
#include "BKE_armature.h"
+#include "BKE_asset.h"
#include "BKE_bpath.h"
#include "BKE_context.h"
#include "BKE_global.h"
@@ -2334,6 +2335,10 @@ void BKE_id_reorder(const ListBase *lb, ID *id, ID *relative, bool after)
void BKE_id_blend_write(BlendWriter *writer, ID *id)
{
+ if (id->asset_data) {
+ BKE_assetdata_write(writer, id->asset_data);
+ }
+
/* ID_WM's id->properties are considered runtime only, and never written in .blend file. */
if (id->properties && !ELEM(GS(id->name), ID_WM)) {
IDP_BlendWrite(writer, id->properties);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 137733f2534..2f9bd424303 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -115,6 +115,7 @@
#include "BKE_action.h"
#include "BKE_anim_data.h"
#include "BKE_armature.h"
+#include "BKE_asset.h"
#include "BKE_brush.h"
#include "BKE_collection.h"
#include "BKE_colortools.h"
@@ -2437,12 +2438,6 @@ static int direct_link_id_restore_recalc(const FileData *fd,
return recalc;
}
-static void direct_link_assetdata(BlendDataReader *reader, AssetData *asset_data)
-{
- BLO_read_data_address(reader, &asset_data->description);
- BLO_read_list(reader, &asset_data->tags);
-}
-
static void direct_link_id_common(
BlendDataReader *reader, Library *current_library, ID *id, ID *id_old, const int tag)
{
@@ -2472,7 +2467,7 @@ static void direct_link_id_common(
if (id->asset_data) {
BLO_read_data_address(reader, &id->asset_data);
- direct_link_assetdata(reader, id->asset_data);
+ BKE_assetdata_read(reader, id->asset_data);
}
/*link direct data of ID properties*/
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 1353d055604..d6067383c96 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -660,45 +660,6 @@ static void writelist_id(WriteData *wd, int filecode, const char *structname, co
* These functions are used by blender's .blend system for file saving/loading.
* \{ */
-static void write_assetdata(BlendWriter *writer, AssetData *asset_data)
-{
- BLO_write_struct(writer, AssetData, asset_data);
-
- if (asset_data->description) {
- BLO_write_string(writer, asset_data->description);
- }
- LISTBASE_FOREACH (CustomTag *, tag, &asset_data->tags) {
- BLO_write_struct(writer, CustomTag, tag);
- }
-}
-
-static void write_iddata(BlendWriter *writer, ID *id)
-{
- /* ID_WM's id->properties are considered runtime only, and never written in .blend file. */
- if (id->properties && !ELEM(GS(id->name), ID_WM)) {
- IDP_BlendWrite(writer, id->properties);
- }
-
- if (id->override_library) {
- BLO_write_struct(writer, IDOverrideLibrary, id->override_library);
-
- BLO_write_struct_list(writer, IDOverrideLibraryProperty, &id->override_library->properties);
- LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &id->override_library->properties) {
- BLO_write_string(writer, op->rna_path);
-
- BLO_write_struct_list(writer, IDOverrideLibraryPropertyOperation, &op->operations);
- LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &op->operations) {
- if (opop->subitem_reference_name) {
- BLO_write_string(writer, opop->subitem_reference_name);
- }
- if (opop->subitem_local_name) {
- BLO_write_string(writer, opop->subitem_local_name);
- }
- }
- }
- }
-}
-
static void write_previews(BlendWriter *writer, const PreviewImage *prv_orig)
{
/* Note we write previews also for undo steps. It takes up some memory,
More information about the Bf-blender-cvs
mailing list