[Bf-blender-cvs] [114d200df81] asset-engine: Asset API: add Views.

Bastien Montagne noreply at git.blender.org
Thu Sep 21 18:04:18 CEST 2017


Commit: 114d200df81b01ab87732e1332b87b691d29159d
Author: Bastien Montagne
Date:   Thu Sep 21 18:01:19 2017 +0200
Branches: asset-engine
https://developer.blender.org/rB114d200df81b01ab87732e1332b87b691d29159d

Asset API: add Views.

This commit add new 'View' forth layer, below history one (Revision).

It also adds a real UUID for the asset repository (as usual, asset
engines not needing it can just set it to zeros), will make Amber's life
(and all multi-repositories engines) easier.

Also fix one or two issues found on the road.

Code builds and links datablocks from libraries in the 'old way'. Real
test will come when re-enabling Amber and adapting it to new API though.

===================================================================

M	source/blender/blenkernel/BKE_asset_engine.h
M	source/blender/blenkernel/intern/asset_engine.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/space_file/filelist.c
M	source/blender/makesdna/DNA_ID.h
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_asset.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_asset_engine.h b/source/blender/blenkernel/BKE_asset_engine.h
index 9f36a8eca26..fa99c2d12c4 100644
--- a/source/blender/blenkernel/BKE_asset_engine.h
+++ b/source/blender/blenkernel/BKE_asset_engine.h
@@ -45,6 +45,7 @@ struct FileDirEntryArr;
 struct FileDirEntry;
 struct FileDirEntryVariant;
 struct FileDirEntryRevision;
+struct FileDirEntryView;
 struct ExtensionRNA;
 struct ID;
 struct IDProperty;
@@ -249,6 +250,8 @@ typedef enum FileCheckType {
 	CHECK_ALL   = CHECK_DIRS | CHECK_FILES,
 } FileCheckType;
 
+void BKE_filedir_view_free(struct FileDirEntryView *view);
+
 void BKE_filedir_revision_free(struct FileDirEntryRevision *rev);
 
 void BKE_filedir_variant_free(struct FileDirEntryVariant *var);
@@ -263,9 +266,11 @@ void BKE_filedir_entryarr_clear(struct FileDirEntryArr *array);
 	(memcmp((_uuida)->_member, (_uuidb)->_member, sizeof((_uuida)->_member)) == 0)
 
 #define ASSETUUID_COMPARE(_uuida, _uuidb) \
-	(ASSETUUID_SUB_COMPARE(_uuida, _uuidb, uuid_asset) && \
+	(ASSETUUID_SUB_COMPARE(_uuida, _uuidb, uuid_repository) && \
+	 ASSETUUID_SUB_COMPARE(_uuida, _uuidb, uuid_asset) && \
 	 ASSETUUID_SUB_COMPARE(_uuida, _uuidb, uuid_variant) && \
-	 ASSETUUID_SUB_COMPARE(_uuida, _uuidb, uuid_revision))
+	 ASSETUUID_SUB_COMPARE(_uuida, _uuidb, uuid_revision) && \
+	 ASSETUUID_SUB_COMPARE(_uuida, _uuidb, uuid_view))
 
 /* Various helpers */
 unsigned int BKE_asset_uuid_hash(const void *key);
diff --git a/source/blender/blenkernel/intern/asset_engine.c b/source/blender/blenkernel/intern/asset_engine.c
index 8fa651bdef1..d0a0857c518 100644
--- a/source/blender/blenkernel/intern/asset_engine.c
+++ b/source/blender/blenkernel/intern/asset_engine.c
@@ -191,12 +191,14 @@ static void asset_engine_load_pre(AssetEngine *engine, AssetUUIDList *r_uuids, F
 		for (en = r_entries->entries.first, uuid = r_uuids->uuids; en; en = en->next, uuid++) {
 			FileDirEntryVariant *var = BLI_findlink(&en->variants, en->act_variant);
 
+			memcpy(uuid->uuid_repository, en->uuid_repository, sizeof(uuid->uuid_repository));
+
 			memcpy(uuid->uuid_asset, en->uuid, sizeof(uuid->uuid_asset));
 
 			BLI_assert(var);
 			memcpy(uuid->uuid_variant, var->uuid, sizeof(uuid->uuid_variant));
 
-			memcpy(uuid->uuid_revision, en->entry->uuid, sizeof(uuid->uuid_revision));
+			memcpy(uuid->uuid_view, en->entry->uuid, sizeof(uuid->uuid_view));
 		}
 	}
 
@@ -219,6 +221,9 @@ static void asset_engine_load_pre(AssetEngine *engine, AssetUUIDList *r_uuids, F
 	for (en = r_entries->entries.first, uuid = r_uuids->uuids; en; en = en->next, uuid++) {
 		FileDirEntryVariant *var;
 		FileDirEntryRevision *rev;
+		FileDirEntryView *view;
+
+		memcpy(uuid->uuid_repository, en->uuid_repository, sizeof(uuid->uuid_repository));
 
 		memcpy(uuid->uuid_asset, en->uuid, sizeof(uuid->uuid_asset));
 
@@ -229,6 +234,10 @@ static void asset_engine_load_pre(AssetEngine *engine, AssetUUIDList *r_uuids, F
 		rev = BLI_findlink(&var->revisions, var->act_revision);
 		BLI_assert(rev);
 		memcpy(uuid->uuid_revision, rev->uuid, sizeof(uuid->uuid_revision));
+
+		view = BLI_findlink(&rev->views, rev->act_view);
+		BLI_assert(view);
+		memcpy(uuid->uuid_view, view->uuid, sizeof(uuid->uuid_view));
 	}
 }
 
@@ -254,11 +263,33 @@ FileDirEntryArr *BKE_asset_engine_uuids_load_pre(AssetEngine *engine, AssetUUIDL
 
 /* FileDirxxx handling. */
 
+void BKE_filedir_view_free(FileDirEntryView *view)
+{
+	if (view->name) {
+		MEM_freeN(view->name);
+	}
+	if (view->description) {
+		MEM_freeN(view->description);
+	}
+	MEM_freeN(view);
+}
+
 void BKE_filedir_revision_free(FileDirEntryRevision *rev)
 {
 	if (rev->comment) {
 		MEM_freeN(rev->comment);
 	}
+
+	if (!BLI_listbase_is_empty(&rev->views)) {
+		FileDirEntryView *view, *view_next;
+
+		for (view = rev->views.first; view; view = view_next) {
+			view_next = view->next;
+			BKE_filedir_view_free(view);
+		}
+
+		BLI_listbase_clear(&rev->views);
+	}
 	MEM_freeN(rev);
 }
 
@@ -350,9 +381,7 @@ FileDirEntry *BKE_filedir_entry_copy(FileDirEntry *entry)
 		BLI_listbase_clear(&entry_new->variants);
 		for (act_var = 0, var = entry->variants.first; var; act_var++, var = var->next) {
 			FileDirEntryVariant *var_new = MEM_dupallocN(var);
-			FileDirEntryRevision *rev;
 			const bool is_act_var = (act_var == entry->act_variant);
-			int act_rev;
 
 			if (var->name) {
 				var_new->name = MEM_dupallocN(var->name);
@@ -362,6 +391,8 @@ FileDirEntry *BKE_filedir_entry_copy(FileDirEntry *entry)
 			}
 
 			BLI_listbase_clear(&var_new->revisions);
+			FileDirEntryRevision *rev;
+			int act_rev;
 			for (act_rev = 0, rev = var->revisions.first; rev; act_rev++, rev = rev->next) {
 				FileDirEntryRevision *rev_new = MEM_dupallocN(rev);
 				const bool is_act_rev = (act_rev == var->act_revision);
@@ -370,11 +401,28 @@ FileDirEntry *BKE_filedir_entry_copy(FileDirEntry *entry)
 					rev_new->comment = MEM_dupallocN(rev->comment);
 				}
 
-				BLI_addtail(&var_new->revisions, rev_new);
-
-				if (is_act_var && is_act_rev) {
-					entry_new->entry = rev_new;
+				BLI_listbase_clear(&var_new->revisions);
+				FileDirEntryView *view;
+				int act_view;
+				for (act_view = 0, view = rev->views.first; view; act_view++, view = view->next) {
+					FileDirEntryView *view_new = MEM_dupallocN(view);
+					const bool is_act_view = (act_view == rev->act_view);
+
+					if (view->name) {
+						view_new->name = MEM_dupallocN(view->name);
+					}
+					if (view->description) {
+						view_new->description = MEM_dupallocN(view->description);
+					}
+
+					BLI_addtail(&rev_new->views, view_new);
+
+					if (is_act_var && is_act_rev && is_act_view) {
+						entry_new->entry = view_new;
+					}
 				}
+
+				BLI_addtail(&var_new->revisions, rev_new);
 			}
 
 			BLI_addtail(&entry_new->variants, var_new);
@@ -401,14 +449,22 @@ void BKE_filedir_entryarr_clear(FileDirEntryArr *array)
 		BKE_filedir_entry_free(entry);
 	}
 	BLI_listbase_clear(&array->entries);
-    array->nbr_entries = 0;
+	array->nbr_entries = 0;
 	array->nbr_entries_filtered = 0;
 }
 
 /* Various helpers */
 unsigned int BKE_asset_uuid_hash(const void *key)
 {
-	return BLI_hash_mm2((const unsigned char *)key, sizeof(AssetUUID), 0);
+	BLI_HashMurmur2A mm2a;
+	const AssetUUID *uuid = key;
+	BLI_hash_mm2a_init(&mm2a, 0);
+	BLI_hash_mm2a_add(&mm2a, (const uchar *)uuid->uuid_repository, sizeof(uuid->uuid_repository));
+	BLI_hash_mm2a_add(&mm2a, (const uchar *)uuid->uuid_asset, sizeof(uuid->uuid_asset));
+	BLI_hash_mm2a_add(&mm2a, (const uchar *)uuid->uuid_variant, sizeof(uuid->uuid_variant));
+	BLI_hash_mm2a_add(&mm2a, (const uchar *)uuid->uuid_revision, sizeof(uuid->uuid_revision));
+	BLI_hash_mm2a_add(&mm2a, (const uchar *)uuid->uuid_view, sizeof(uuid->uuid_view));
+	return BLI_hash_mm2a_end(&mm2a);
 }
 
 bool BKE_asset_uuid_cmp(const void *a, const void *b)
@@ -421,8 +477,10 @@ bool BKE_asset_uuid_cmp(const void *a, const void *b)
 void BKE_asset_uuid_print(const AssetUUID *uuid)
 {
 	/* TODO print nicer (as 128bit hexadecimal...). */
-	printf("[%d,%d,%d,%d][%d,%d,%d,%d][%d,%d,%d,%d]\n",
+	printf("[%d,%d,%d,%d][%d,%d,%d,%d][%d,%d,%d,%d][%d,%d,%d,%d][%d,%d,%d,%d]\n",
+	       uuid->uuid_repository[0], uuid->uuid_repository[1], uuid->uuid_repository[2], uuid->uuid_repository[3],
 	       uuid->uuid_asset[0], uuid->uuid_asset[1], uuid->uuid_asset[2], uuid->uuid_asset[3],
 	       uuid->uuid_variant[0], uuid->uuid_variant[1], uuid->uuid_variant[2], uuid->uuid_variant[3],
-	       uuid->uuid_revision[0], uuid->uuid_revision[1], uuid->uuid_revision[2], uuid->uuid_revision[3]);
+	       uuid->uuid_revision[0], uuid->uuid_revision[1], uuid->uuid_revision[2], uuid->uuid_revision[3],
+	       uuid->uuid_view[0], uuid->uuid_view[1], uuid->uuid_view[2], uuid->uuid_view[3]);
 }
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index f8a65fc70cb..48e08acaf91 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -10265,7 +10265,7 @@ static ID *link_named_part_ex(
 			id->tag |= LIB_TAG_DOIT;
 	}
 
-	if (id && uuid) {
+	if (id && uuid && aet) {
 		BLI_assert(root);
 
 		id->uuid = MEM_mallocN(sizeof(*id->uuid), __func__);
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 697113b0472..ad1398f844a 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -1281,6 +1281,8 @@ static void filelist_cache_previews_push(FileList *filelist, FileDirEntry *entry
 				BLI_assert(uuids->nbr_uuids == 0);
 				uuids->uuids = MEM_callocN(++uuids->nbr_uuids * sizeof(*uuids->uuids), __func__);
 			}
+			memcpy(uuids->uuids[uuids->nbr_uuids - 1].uuid_repository, entry->uuid_repository,
+			       sizeof(uuids->uuids[uuids->nbr_uuids - 1].uuid_repository));
 			memcpy(uuids->uuids[uuids->nbr_uuids - 1].uuid_asset, entry->uuid,
 			       sizeof(uuids->uuids[uuids->nbr_uuids - 1].uuid_asset));
 			/* No real need to call ae->type->previews_get() here, update callback will do so anyway. */
@@ -1614,16 +1616,16 @@ static FileDirEntry *filelist_file_create_entry(FileList *filelist, const int in
 	}
 	else {
 		FileListInternEntry *entry = filelist->filelist_intern.filtered[index];
-		FileDirEntryRevision *rev;
+		FileDirEntryView *view;
 
 		ret = MEM_callocN(sizeof(*ret), __func__);
-		rev = MEM_callocN(sizeof(*rev), __func__);
+		view = MEM_callocN(sizeof(*view), __func__);
 
-		rev->size = (uint64_t)entry->st.st_size;
+		view->size = (uint64_t)entry->st.st_size;
 
-		rev->time = (int64_t)entry->st.st_mtime;
+		view->time = (int64_t)entry->st.st_mtime;
 
-		ret->entry = rev;
+		ret->entry = view;
 		ret->relpath = BLI_strdup(entry->relpath);
 		ret->name = BLI_strdup(entry->name);
 		ret->description = BLI_strdupcat(filelist->filelist.root, entry->relpath);
@@ -1670,7 +1672,12 @@ static FileDirEntry *filelist_file_create_entries_block(FileList *filelist, cons
 				FileDirEntryVariant *variant = BLI_findlink(&entry->variants, entry->act_variant);
 				BLI_assert(!BLI_listbase_is_empty(&variant->revisions) && variant->nbr_revisions);
 				BLI_assert(variant->act_revision < variant->nbr_revisions);
-				entry->entry = BLI_find

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list