[Bf-blender-cvs] [026f967] asset-engine: Various fixes with asset engine and new code...

Bastien Montagne noreply at git.blender.org
Mon Apr 13 17:28:01 CEST 2015


Commit: 026f967dff977d603407073e19b03ccd2b3e05e2
Author: Bastien Montagne
Date:   Mon Apr 13 17:27:06 2015 +0200
Branches: asset-engine
https://developer.blender.org/rB026f967dff977d603407073e19b03ccd2b3e05e2

Various fixes with asset engine and new code...

Still not working completely, and need small rework in asset-experiments first.

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

M	release/scripts/startup/bl_operators/amber.py
M	source/blender/editors/space_file/filelist.c

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

diff --git a/release/scripts/startup/bl_operators/amber.py b/release/scripts/startup/bl_operators/amber.py
index 4f51f9a..9b6cfb4 100644
--- a/release/scripts/startup/bl_operators/amber.py
+++ b/release/scripts/startup/bl_operators/amber.py
@@ -215,13 +215,8 @@ class AssetEngineAmber(AssetEngine):
     def __init__(self):
         self.executor = futures.ThreadPoolExecutor(8)  # Using threads for now, if issues arise we'll switch to process.
         self.jobs = {}
-        self.root = ""
-        self.uuids = {}
-        self.repo = {}
-        self.dirs = []
-        self.tags_source = []
 
-        self.sortedfiltered = []
+        self.reset()
 
         self.job_uuid = 1
 
@@ -231,6 +226,15 @@ class AssetEngineAmber(AssetEngine):
         #     Even though it does not seem to be an issue, this is not nice and shall be fixed somehow.
         #~ self.executor.shutdown(wait=False)
 
+    def reset(self):
+        print("Amber Reset!")
+        self.root = ""
+        self.uuids = {}
+        self.repo = {}
+        self.dirs = []
+        self.tags_source = []
+
+        self.sortedfiltered = []
 
     def status(self, job_id):
         if job_id:
@@ -261,10 +265,12 @@ class AssetEngineAmber(AssetEngine):
         #~ print(entries.root_path, job_id, job)
         if job is not None and isinstance(job, AmberJobList):
             if job.root != entries.root_path:
+                self.reset()
                 self.jobs[job_id] = AmberJobList(self.executor, job_id, entries.root_path)
             else:
                 job.update(self.repo, self.dirs, self.uuids)
         elif self.root != entries.root_path:
+            self.reset()
             job_id = self.job_uuid
             self.job_uuid += 1
             self.jobs[job_id] = AmberJobList(self.executor, job_id, entries.root_path)
@@ -317,6 +323,7 @@ class AssetEngineAmber(AssetEngine):
 
     def entries_block_get(self, start_index, end_index, entries):
         if self.repo:
+            print("self repo", len(self.sortedfiltered), start_index, end_index)
             for _n, euuid, e in self.sortedfiltered[start_index:end_index]:
                 uuid = binascii.unhexlify(euuid)
                 entry = entries.entries.add()
@@ -330,26 +337,22 @@ class AssetEngineAmber(AssetEngine):
                 act_rev = None
                 for vuuid, v in e["variants"].items():
                     variant_uuid = binascii.unhexlify(vuuid)
-                    variant, existing_ruuids = existing_vuuids.get(variant_uuid, (None, {}))
-                    if variant is None:
-                        variant = entry.variants.add()
-                        variant.uuid = variant_uuid
-                        variant.name = v["name"]
-                        variant.description = v["description"]
-                        existing_vuuids[variant_uuid] = (variant, existing_ruuids)  # Not really needed, but for sake of consistency...
-                        ruuids = vuuids[variant_uuid] = {}
+                    variant = entry.variants.add()
+                    variant.uuid = variant_uuid
+                    variant.name = v["name"]
+                    variant.description = v["description"]
+                    ruuids = {}
+                    vuuids[variant_uuid] = (variant, ruuids)  # Not really needed, but for sake of consistency...
                     if vuuid == e["variant_default"]:
                         entry.variants.active = variant
                     for ruuid, r in v["revisions"].items():
                         revision_uuid = binascii.unhexlify(ruuid)
-                        revision = existing_ruuids.get(revision_uuid, None)
-                        if revision is None:
-                            revision = variant.revisions.add()
-                            revision.uuid = revision_uuid
-                            #~ revision.comment = r["comment"]
-                            revision.size = r["size"]
-                            revision.timestamp = r["timestamp"]
-                            ruuids[revision_uuid] = (r["path_archive"], r["path"])
+                        revision = variant.revisions.add()
+                        revision.uuid = revision_uuid
+                        #~ revision.comment = r["comment"]
+                        revision.size = r["size"]
+                        revision.timestamp = r["timestamp"]
+                        ruuids[revision_uuid] = (r["path_archive"], r["path"])
                         if ruuid == v["revision_default"]:
                             variant.revisions.active = revision
                             if vuuid == e["variant_default"]:
@@ -357,6 +360,7 @@ class AssetEngineAmber(AssetEngine):
                 if act_rev:
                     entry.relpath = act_rev["path"]
         else:
+            print("self dirs", len(self.sortedfiltered), start_index, end_index)
             for path, size, timestamp, uuid in self.sortedfiltered[start_index:end_index]:
                 entry = entries.entries.add()
                 entry.type = {'DIR'}
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index c757fb9..b82a700 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -667,7 +667,11 @@ void filelist_sort_filter(struct FileList *filelist)
 			                                                     filelist->filter_data.filter_glob,
 			                                                     filelist->filter_data.filter_search,
 			                                                     &filelist->filelist);
+			printf("%s: changed: %d\n", __func__, changed);
 		}
+		filelist_cache_clear(&filelist->filelist_cache);
+		filelist->need_sorting = false;
+		filelist->need_filtering = false;
 	}
 	else {
 		if (filelist_need_sorting(filelist)) {
@@ -1350,6 +1354,7 @@ void filelist_setdir(struct FileList *filelist, char *r_dir)
 
 	if (!STREQ(filelist->filelist.root, r_dir)) {
 		BLI_strncpy(filelist->filelist.root, r_dir, sizeof(filelist->filelist.root));
+		printf("%s: Forcing Reset!!!\n", __func__);
 		filelist->force_reset = true;
 	}
 }
@@ -1414,14 +1419,60 @@ static FileDirEntry *filelist_file_ex(struct FileList *filelist, const int index
 	printf("requesting file %d (not yet cached)\n", index);
 
 	/* Else, we have to add new entry to 'misc' cache - and possibly make room for it first! */
-	ret = filelist_intern_create_entry(filelist, index);
-	old_index = cache->misc_entries_indices[cache->misc_cursor];
-	if ((old = BLI_ghash_popkey(cache->misc_entries, SET_INT_IN_POINTER(old_index), NULL))) {
-		filelist_intern_release_entry(filelist, old);
-	}
-	BLI_ghash_insert(cache->misc_entries, SET_INT_IN_POINTER(index), ret);
-	cache->misc_entries_indices[cache->misc_cursor] = index;
-	cache->misc_cursor = (cache->misc_cursor + 1) % FILELIST_ENTRYCACHESIZE;
+	if (filelist->ae) {
+		FileDirEntryArr tmp_arr;
+
+		if (!filelist->ae->type->entries_block_get) {
+			printf("%s: Asset Engine %s does not implement 'entries_block_get'...\n", __func__, filelist->ae->type->name);
+			return NULL;
+		}
+
+		tmp_arr = filelist->filelist;
+		BLI_listbase_clear(&tmp_arr.entries);
+		if (!filelist->ae->type->entries_block_get(filelist->ae, index, index + 1, &tmp_arr)) {
+			printf("%s: Failed to get [%d:%d] from AE %s\n", __func__, index, index + 1, filelist->ae->type->name);
+			BKE_filedir_entryarr_clear(&tmp_arr);
+			return NULL;
+		}
+
+		ret = tmp_arr.entries.first;
+		BLI_assert(!BLI_listbase_is_empty(&ret->variants) && ret->nbr_variants);
+		BLI_assert(ret->act_variant < ret->nbr_variants);
+		if (!ret->name) {
+			char buff[FILE_MAX_LIBEXTRA];
+			ret->name = BLI_strdup(fileentry_uiname(filelist->filelist.root,
+			                                        ret->relpath, ret->typeflag, buff));
+		}
+		if (!ret->entry) {
+			FileDirEntryVariant *variant = BLI_findlink(&ret->variants, ret->act_variant);
+			BLI_assert(!BLI_listbase_is_empty(&variant->revisions) && variant->nbr_revisions);
+			BLI_assert(variant->act_revision < variant->nbr_revisions);
+			ret->entry = BLI_findlink(&variant->revisions, variant->act_revision);
+			BLI_assert(ret->entry);
+		}
+
+		old_index = cache->misc_entries_indices[cache->misc_cursor];
+		if ((old = BLI_ghash_popkey(cache->misc_entries, SET_INT_IN_POINTER(old_index), NULL))) {
+			BLI_remlink(&filelist->filelist.entries, old);
+			BKE_filedir_entry_free(old);
+		}
+		BLI_ghash_insert(cache->misc_entries, SET_INT_IN_POINTER(index), ret);
+		cache->misc_entries_indices[cache->misc_cursor] = index;
+		cache->misc_cursor = (cache->misc_cursor + 1) % FILELIST_ENTRYCACHESIZE;
+
+		/* Using filelist->filelist.entries as owner of that mem! */
+		BLI_movelisttolist(&filelist->filelist.entries, &tmp_arr.entries);
+	}
+	else {
+		ret = filelist_intern_create_entry(filelist, index);
+		old_index = cache->misc_entries_indices[cache->misc_cursor];
+		if ((old = BLI_ghash_popkey(cache->misc_entries, SET_INT_IN_POINTER(old_index), NULL))) {
+			filelist_intern_release_entry(filelist, old);
+		}
+		BLI_ghash_insert(cache->misc_entries, SET_INT_IN_POINTER(index), ret);
+		cache->misc_entries_indices[cache->misc_cursor] = index;
+		cache->misc_cursor = (cache->misc_cursor + 1) % FILELIST_ENTRYCACHESIZE;
+	}
 
 #if 0  /* Actually no, only block cached entries should have preview imho. */
 	if (cache->previews_pool) {




More information about the Bf-blender-cvs mailing list