[Bf-blender-cvs] [a9f39fa197e] blenloader-api: initial blenloader api
Jacques Lucke
noreply at git.blender.org
Fri Mar 6 14:58:49 CET 2020
Commit: a9f39fa197e69c307e8cf32992d650a2c8b90ae1
Author: Jacques Lucke
Date: Fri Mar 6 14:50:39 2020 +0100
Branches: blenloader-api
https://developer.blender.org/rBa9f39fa197e69c307e8cf32992d650a2c8b90ae1
initial blenloader api
===================================================================
M source/blender/blenloader/BLO_readfile.h
M source/blender/blenloader/BLO_writefile.h
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
===================================================================
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index 00dbe334356..df1d9bc3d1f 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -176,6 +176,11 @@ struct BlendThumbnail *BLO_thumbnail_from_file(const char *filepath);
extern const struct bTheme U_theme_default;
extern const struct UserDef U_default;
+typedef struct BloReadData BloReadData;
+
+void *BLO_read_new_address(BloReadData *rd, const void *old_address);
+bool BLO_read_requires_endian_switch(BloReadData *rd);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenloader/BLO_writefile.h b/source/blender/blenloader/BLO_writefile.h
index d83abf7f9ed..db29ea5e5c0 100644
--- a/source/blender/blenloader/BLO_writefile.h
+++ b/source/blender/blenloader/BLO_writefile.h
@@ -40,4 +40,26 @@ extern bool BLO_write_file_mem(struct Main *mainvar,
struct MemFile *current,
int write_flags);
+typedef struct BloWriteData BloWriteData;
+
+void BLO_write_data(BloWriteData *wd, const void *data_ptr, int length);
+void BLO_write_struct_by_name(BloWriteData *wd, const char *struct_name, const void *data_ptr);
+void BLO_write_struct_array_by_name(BloWriteData *wd,
+ const char *struct_name,
+ const void *data_ptr,
+ int array_size);
+void BLO_write_struct_by_id(BloWriteData *wd, int struct_id, const void *data_ptr);
+void BLO_write_struct_array_by_id(BloWriteData *wd,
+ int struct_id,
+ const void *data_ptr,
+ int array_size);
+
+int BLO_get_struct_id_by_name(BloWriteData *wd, const char *struct_name);
+#define BLO_get_struct_id(wd, struct_name) BLO_get_struct_id_by_name(wd, ##struct_name)
+
+#define BLO_write_struct(wd, struct_name, data_ptr) \
+ BLO_write_struct_by_id(wd, BLO_get_struct_id(struct_name), data_ptr)
+#define BLO_write_struct_array(wd, struct_name, data_ptr, array_size) \
+ BLO_write_struct_array_by_id(wd, BLO_get_struct_id(struct_name), data_ptr, array_size)
+
#endif
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 4d46435eea0..bdf10977b6f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -11879,4 +11879,14 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
BKE_main_free(main_newid);
}
+void *BLO_read_new_address(BloReadData *rd, const void *old_address)
+{
+ return newdataadr((FileData *)rd, old_address);
+}
+
+bool BLO_read_requires_endian_switch(BloReadData *rd)
+{
+ return (((FileData *)rd)->flags & FD_FLAGS_SWITCH_ENDIAN) != 0;
+}
+
/** \} */
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index dece8740789..49b920debc0 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -4173,4 +4173,44 @@ bool BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int w
return (err == 0);
}
+void BLO_write_data(BloWriteData *wd, const void *data_ptr, int length)
+{
+ writedata((WriteData *)wd, DATA, length, data_ptr);
+}
+
+void BLO_write_struct_by_name(BloWriteData *wd, const char *struct_name, const void *data_ptr)
+{
+ int struct_id = BLO_get_struct_id_by_name(wd, struct_name);
+ BLO_write_struct_by_id(wd, struct_id, data_ptr);
+}
+
+void BLO_write_struct_array_by_name(BloWriteData *wd,
+ const char *struct_name,
+ const void *data_ptr,
+ int array_size)
+{
+ int struct_id = BLO_get_struct_id_by_name(wd, struct_name);
+ BLO_write_struct_array_by_id(wd, struct_id, data_ptr, array_size);
+}
+
+void BLO_write_struct_by_id(BloWriteData *wd, int struct_id, const void *data_ptr)
+{
+ writestruct_nr((WriteData *)wd, DATA, struct_id, 1, data_ptr);
+}
+
+void BLO_write_struct_array_by_id(BloWriteData *wd,
+ int struct_id,
+ const void *data_ptr,
+ int array_size)
+{
+ writestruct_nr((WriteData *)wd, DATA, struct_id, array_size, data_ptr);
+}
+
+int BLO_get_struct_id_by_name(BloWriteData *wd, const char *struct_name)
+{
+ int struct_id = DNA_struct_find_nr(((WriteData *)wd)->sdna, struct_name);
+ BLI_assert(struct_id >= 0);
+ return struct_id;
+}
+
/** \} */
More information about the Bf-blender-cvs
mailing list