[Bf-blender-cvs] [3eefdc0] asset-engine: WIP Add asset sub-data dependency info.
Bastien Montagne
noreply at git.blender.org
Mon Feb 15 19:43:24 CET 2016
Commit: 3eefdc0ed7898896ad85aaf882071c8d50c28a70
Author: Bastien Montagne
Date: Mon Feb 15 16:49:30 2016 +0100
Branches: asset-engine
https://developer.blender.org/rB3eefdc0ed7898896ad85aaf882071c8d50c28a70
WIP Add asset sub-data dependency info.
We need that info (knowing which non-asset IDs are used by which asset-IDs),
otherwise managing reloading, updates etc. of assets would be impossible
(or rather, would leave a mess of unused IDs behind them).
Only partially done, non-functional yet.
This commit also adds asset repository references in libraries.
===================================================================
M source/blender/blenkernel/BKE_asset.h
M source/blender/blenkernel/BKE_library.h
M source/blender/blenkernel/intern/asset.c
M source/blender/blenkernel/intern/library.c
M source/blender/blenloader/BLO_readfile.h
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
M source/blender/makesdna/DNA_ID.h
M source/blender/makesrna/intern/rna_ID.c
M source/blender/windowmanager/intern/wm_operators.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index abf379a..858968d 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -193,6 +193,16 @@ struct FileDirEntry *BKE_filedir_entry_copy(struct FileDirEntry *entry);
void BKE_filedir_entryarr_clear(struct FileDirEntryArr *array);
+#define ASSETUUID_SUB_COMPARE(_uuida, _uuidb, _member) \
+ (memcmp((_uuida)->#_member, (_uuidb)->#_member, sizeof((_uuida)->#_member)) == 0)
+
+#define ASSETUUID_COMPARE(_uuida, _uuidb) \
+ (memcmp((_uuida), (_uuidb), sizeof(*(_uuida))) == 0)
+
+/* GHash helpers */
+unsigned int BKE_asset_uuid_hash(const void *key);
+bool BKE_asset_uuid_cmp(const void *a, const void *b);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 62c5fc9..8bf480a 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -38,6 +38,7 @@ extern "C" {
#include "BLI_compiler_attrs.h"
+struct AssetEngineType;
struct BlendThumbnail;
struct ListBase;
struct ID;
@@ -119,6 +120,16 @@ void BKE_id_ui_prefix(char name[66 + 1], const struct ID *id);
void BKE_library_make_local(struct Main *bmain, struct Library *lib, bool untagged_only, bool set_fake);
+void BKE_library_asset_repository_init(struct Library *lib, const struct AssetEngineType *aet, const char *repo_root);
+void BKE_library_asset_repository_clear(struct Library *lib);
+struct AssetRef *BKE_library_asset_repository_asset_add(struct Library *lib, const void *idv);
+void BKE_library_asset_repository_asset_remove(struct Library *lib, const void *idv);
+struct AssetRef *BKE_library_asset_repository_asset_find(struct Library *lib, const void *idv);
+void BKE_library_asset_repository_subdata_add(struct AssetRef *aref, const void *idv);
+void BKE_library_asset_repository_subdata_remove(struct AssetRef *aref, const void *idv);
+
+void BKE_libraries_asset_subdata_remove(struct Main *bmain, const void *idv);
+
typedef void (*BKE_library_free_window_manager_cb)(struct bContext *, struct wmWindowManager *);
typedef void (*BKE_library_free_notifier_reference_cb)(const void *);
typedef void (*BKE_library_free_editor_id_reference_cb)(const struct ID *);
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index c1bda6e..e2bc0d6 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -41,6 +41,7 @@
#include "BLT_translation.h"
#include "BLI_fileops_types.h"
+#include "BLI_hash_mm2a.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@@ -369,3 +370,18 @@ void BKE_filedir_entryarr_clear(FileDirEntryArr *array)
array->nbr_entries = 0;
array->nbr_entries_filtered = 0;
}
+
+/* GHash helpers */
+unsigned int BKE_asset_uuid_hash(const void *key)
+{
+ return BLI_hash_mm2((const unsigned char *)key, sizeof(AssetUUID), 0);
+}
+
+bool BKE_asset_uuid_cmp(const void *a, const void *b)
+{
+ const AssetUUID *uuid1 = a;
+ const AssetUUID *uuid2 = b;
+ return !ASSETUUID_COMPARE(uuid1, uuid2); /* Expects false when compared equal... */
+}
+
+
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 3f96792..7fcc9a0 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -75,9 +75,13 @@
#include "BLI_threads.h"
#include "BLT_translation.h"
+#include "RNA_access.h"
+#include "RNA_types.h"
+
#include "BKE_action.h"
#include "BKE_animsys.h"
#include "BKE_armature.h"
+#include "BKE_asset.h"
#include "BKE_bpath.h"
#include "BKE_brush.h"
#include "BKE_camera.h"
@@ -120,8 +124,6 @@
#include "DEG_depsgraph.h"
-#include "RNA_access.h"
-
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
@@ -1051,6 +1053,8 @@ static void BKE_library_free(Library *lib)
{
if (lib->packedfile)
freePackedFile(lib->packedfile);
+
+ BKE_library_asset_repository_clear(lib);
}
static BKE_library_free_window_manager_cb free_windowmanager_cb = NULL;
@@ -1103,6 +1107,8 @@ void BKE_libblock_free_data(Main *bmain, ID *id)
IDP_FreeProperty(id->properties);
MEM_freeN(id->properties);
}
+
+ MEM_SAFE_FREE(id->uuid);
/* this ID may be a driver target! */
BKE_animdata_main_cb(bmain, animdata_dtar_clear_cb, (void *)id);
@@ -1238,6 +1244,9 @@ void BKE_libblock_free_ex(Main *bmain, void *idv, bool do_id_user)
BLI_remlink(lb, id);
BKE_libblock_free_data(bmain, id);
+
+ BKE_libraries_asset_subdata_remove(bmain, id);
+
BKE_main_unlock(bmain);
MEM_freeN(id);
@@ -1849,6 +1858,104 @@ void BKE_library_make_local(Main *bmain, Library *lib, bool untagged_only, bool
}
}
+/* Asset managing - TODO: we most likely want to turn this into a hashing at some point, could become a bit slow
+ * when having huge assets (or many of them)... */
+void BKE_library_asset_repository_init(Library *lib, const AssetEngineType *aet, const char *repo_root)
+{
+ BKE_library_asset_repository_clear(lib);
+ lib->asset_repository = MEM_mallocN(sizeof(*lib->asset_repository), __func__);
+
+ BLI_strncpy(lib->asset_repository->asset_engine, aet->idname, sizeof(lib->asset_repository->asset_engine));
+ lib->asset_repository->asset_engine_version = aet->version;
+ BLI_strncpy(lib->asset_repository->root, repo_root, sizeof(lib->asset_repository->root));
+
+ BLI_listbase_clear(&lib->asset_repository->assets);
+}
+
+void BKE_library_asset_repository_clear(Library *lib)
+{
+ if (lib->asset_repository) {
+ for (AssetRef *aref; (aref = BLI_pophead(&lib->asset_repository->assets)); ) {
+ BLI_freelistN(&aref->id_list);
+ MEM_freeN(aref);
+ }
+ MEM_freeN(lib->asset_repository);
+ lib->asset_repository = NULL;
+ }
+}
+
+AssetRef *BKE_library_asset_repository_asset_add(Library *lib, const void *idv)
+{
+ const ID *id = idv;
+ BLI_assert(id->uuid != NULL);
+
+ AssetRef *aref = BKE_library_asset_repository_asset_find(lib, idv);
+ if (!aref) {
+ aref = MEM_callocN(sizeof(*aref), __func__);
+ aref->uuid = *id->uuid;
+ BKE_library_asset_repository_subdata_add(aref, idv);
+ BLI_addtail(&lib->asset_repository->assets, aref);
+ }
+
+ return aref;
+}
+
+AssetRef *BKE_library_asset_repository_asset_find(Library *lib, const void *idv)
+{
+ const ID *id = idv;
+ BLI_assert(id->uuid != NULL);
+
+ for (AssetRef *aref = lib->asset_repository->assets.first; aref; aref = aref->next) {
+ if (ASSETUUID_COMPARE(&aref->uuid, id->uuid)) {
+#ifndef NDEBUG
+ LinkData *link = aref->id_list.first;
+ BLI_assert(link && (link->data == idv));
+#endif
+ return aref;
+ }
+ }
+ return NULL;
+}
+
+void BKE_library_asset_repository_asset_remove(struct Library *lib, const void *idv)
+{
+ AssetRef *aref = BKE_library_asset_repository_asset_find(lib, idv);
+ BLI_remlink(&lib->asset_repository->assets, aref);
+ BLI_freelistN(&aref->id_list);
+ MEM_freeN(aref);
+}
+
+void BKE_library_asset_repository_subdata_add(struct AssetRef *aref, const void *idv)
+{
+ if (BLI_findptr(&aref->id_list, idv, offsetof(LinkData, data)) == NULL) {
+ BLI_addtail(&aref->id_list, BLI_genericNodeN((void *)idv));
+ }
+}
+
+void BKE_library_asset_repository_subdata_remove(struct AssetRef *aref, const void *idv)
+{
+ LinkData *link = BLI_findptr(&aref->id_list, idv, offsetof(LinkData, data));
+ if (link) {
+ BLI_freelinkN(&aref->id_list, link);
+ }
+}
+
+void BKE_libraries_asset_subdata_remove(struct Main *bmain, const void *idv)
+{
+ const ID *id = idv;
+
+ if (id->lib == NULL) {
+ return;
+ }
+
+ ListBase *lb = which_libbase(bmain, ID_LI);
+ for (Library *lib = lb->first; lib; lib = lib->id.next) {
+ for (AssetRef *aref = lib->asset_repository->assets.first; aref; aref = aref->next) {
+ BLI_freelinkN(&aref->id_list, BLI_findptr(&aref->id_list, idv, offsetof(LinkData, data)));
+ }
+ }
+}
+
/**
* Use after setting the ID's name
* When name exists: call 'new_id'
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index 409e3c7..ab001b8 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -104,7 +104,7 @@ struct ID *BLO_library_link_named_part_ex(
const short idcode, const char *name, const short flag,
struct Scene *scene, struct View3D *v3d);
struct ID *BLO_library_link_named_part_asset(
- struct Main *mainl, BlendHandle **bh, const struct AssetEngineType *aet,
+ struct Main *mainl, BlendHandle **bh, const struct AssetEngineType *aet, const char *root,
const short idcode, const char *name, const struct AssetUUID *uuid, const short flag,
struct Scene *scene, struct View3D *v3d);
void BLO_library_link_end(struct Main *mainl, BlendHandle **bh, short flag, struct Scene *scene, struct View3D *v3d);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 830315a..93e9e48 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7155,13 +7155,18 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
// printf("direct_link_library: filepath %s\n", lib->filepath);
lib->packedfile = direct_link_packedfile(fd, lib->packedfile);
-
+ lib->asset_repository = newdataadr(fd, lib->asset_repository);
+ BLI_listbase_clear(&lib->asset_repository->assets);
+
/* new main */
newmain = BKE_main_new();
BLI_addtail(fd->mainlist, newmain);
newmain->curlib = lib;
lib->parent = NULL;
+
+ /* Do not clear lib->asset_repository itself! */
+ BLI_listbase_clear(&lib->asset_repository->assets);
}
static void lib_link_library(FileData *UNUSED(fd), Main *main)
@@ -9761,7 +9766,7 @@ void BLO_library_link_copypaste(Main *mainl, BlendHandle *bh)
}
static ID *link_named_part_ex(
- Main *mainl, FileData *fd, const AssetEngineType *aet,
+ Main *mainl, FileData *fd, const AssetEngineType *aet, const char *root,
const short idcode, const char *name, const AssetUUID *uuid, const int flag,
Scene *scene, View3D *v3d)
{
@@ -9777,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list