Commit: aec80da8f86ecd1b2c9e8463d891df6fcbecb61a
Author: Bastien Montagne
Date:   Wed Apr 6 17:38:12 2016 +0200
Branches: asset-engine
https://developer.blender.org/rBaec80da8f86ecd1b2c9e8463d891df6fcbecb61a

More or less finished shell of 'update' code.

Code only reports which datablocks/assets shall be reloaded etc. so far, actual
reloading needs id-remap code (and hence will be implemented in asset-experiment
branch later).

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

M       release/scripts/startup/bl_operators/amber.py
M       source/blender/blenkernel/BKE_asset.h
M       source/blender/blenkernel/intern/blender.c
M       source/blender/editors/space_file/filelist.c
M       source/blender/makesrna/intern/rna_asset.c

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

diff --git a/release/scripts/startup/bl_operators/amber.py 
b/release/scripts/startup/bl_operators/amber.py
index b661f62..4e6e2d5 100644
--- a/release/scripts/startup/bl_operators/amber.py
+++ b/release/scripts/startup/bl_operators/amber.py
@@ -476,6 +476,12 @@ class AssetEngineAmber(AssetEngine):
         #~ print(entries.root_path)
         pass
 
+    def update_check(self, uuids):
+        # do nothing for now...
+        for uuid in uuids.uuids:
+            uuid.use_asset_reload = True
+        return True
+
     def sort_filter(self, use_sort, use_filter, params, entries):
 #        print(use_sort, use_filter)
         if use_filter:
diff --git a/source/blender/blenkernel/BKE_asset.h 
b/source/blender/blenkernel/BKE_asset.h
index f0f530b..1f99812 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -68,6 +68,7 @@ typedef float (*ae_progress)(struct AssetEngine *engine, 
const int job_id);
 typedef void (*ae_kill)(struct AssetEngine *engine, const int job_id);
 
 /* ***** All callbacks below shall be non-blocking (i.e. return immediately). 
***** */
+
 /* Those callbacks will be called from a 'fake-job' start *and* update 
functions (i.e. main thread, working one will
  * just sleep).
  * If given id is not null, engine should update from a running job if 
available, otherwise it should start a new one.
@@ -112,16 +113,18 @@ typedef bool (*ae_load_pre)(struct AssetEngine *engine, 
struct AssetUUIDList *uu
  * E.g. allows an advanced engine to make fancy scripted operations over 
loaded items. */
 typedef bool (*ae_load_post)(struct AssetEngine *engine, struct ID *items, 
const int *num_items);
 
+/* Check if given dirpath is valid for current asset engine, it can also 
modify it.
+ * r_dir is assumed to be least FILE_MAX. */
+typedef void (*ae_check_dir)(struct AssetEngine *engine, char *r_dir);
+
 /* 'update' hook, called to prepare updating of given entries (typically after 
a file (re)load).
  * Engine should check whether given assets are still valid, if they should be 
updated, etc.
  * uuids tagged as needing reload will then be reloaded as new ones
- * (ae_load_pre, then actual lib loading, then ae_load_post). */
+ * (ae_load_pre, then actual lib loading, then ae_load_post).
+ * \warning DO NOT add or remove (or alter order of) uuids from the list in 
this callback! */
+/* XXX Should we make this non-blocking too? */
 typedef bool (*ae_update_check)(struct AssetEngine *engine, struct 
AssetUUIDList *uuids);
 
-/* Check if given dirpath is valid for current asset engine, it can also 
modify it.
- * r_dir is assumed to be least FILE_MAX. */
-typedef void (*ae_check_dir)(struct AssetEngine *engine, char *r_dir);
-
 typedef struct AssetEngineType {
        struct AssetEngineType *next, *prev;
 
diff --git a/source/blender/blenkernel/intern/blender.c 
b/source/blender/blenkernel/intern/blender.c
index ed1947e..36f6f63 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -59,10 +59,13 @@
 #include "BLI_utildefines.h"
 #include "BLI_callbacks.h"
 
+#include "RNA_access.h"
+
 #include "IMB_imbuf.h"
 #include "IMB_moviecache.h"
 
 #include "BKE_appdir.h"
+#include "BKE_asset.h"
 #include "BKE_blender.h"
 #include "BKE_bpath.h"
 #include "BKE_brush.h"
@@ -90,8 +93,6 @@
 #include "BLO_readfile.h" 
 #include "BLO_writefile.h" 
 
-#include "RNA_access.h"
-
 #include "WM_api.h" // XXXXX BAD, very BAD dependency (bad level call) - 
remove asap, elubie
 
 #include "IMB_colormanagement.h"
@@ -523,24 +524,95 @@ void BKE_userdef_state(void)
 static void read_file_update_assets(bContext *C)
 {
        Main *bmain = CTX_data_main(C);
-       ListBase *lb_array[MAX_LIBARRAY];
-       int i = set_listbasepointers(bmain, lb_array);
+
+       BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
 
        for (Library *lib = bmain->library.first; lib; lib = lib->id.next) {
                if (lib->asset_repository) {
                        printf("Handling lib file %s (engine %s, ver. %d)\n", 
lib->filepath, lib->asset_repository->asset_engine, 
lib->asset_repository->asset_engine_version);
+
+                       AssetUUIDList uuids = {0};
+                       AssetUUID *uuid;
+                       AssetEngineType *ae_type = 
BKE_asset_engines_find(lib->asset_repository->asset_engine);
+                       AssetEngine *ae = NULL;
+
+                       uuids.asset_engine_version = 
lib->asset_repository->asset_engine_version;
+
+                       printf("Handling lib file %s (engine %s, ver. %d)\n", 
lib->filepath, lib->asset_repository->asset_engine, 
lib->asset_repository->asset_engine_version);
+
+                       if (ae_type == NULL) {
+                               printf("ERROR! Unknown asset engine!\n");
+                       }
+                       else {
+                               ae = BKE_asset_engine_create(ae_type);
+                       }
+
+                       /* Note: we assume update check callback does not add, 
remove or alter order of uuids in that list! */
+
                        for (AssetRef *aref = 
lib->asset_repository->assets.first; aref; aref = aref->next) {
                                for (LinkData *ld = aref->id_list.first; ld; ld 
= ld->next) {
                                        ID *id = ld->data;
 
+                                       if (ae_type == NULL) {
+                                               if (id->uuid) {
+                                                       id->uuid->tag = 
UUID_TAG_ENGINE_MISSING;
+                                               }
+                                               continue;
+                                       }
+
                                        if (id->uuid) {
                                                printf("\tWe need to check for 
updated asset %s...\n", id->name);
+                                               id->uuid->tag = 0;
+
+                                               /* XXX horrible, need to use 
some mempool, stack or something :) */
+                                               uuids.nbr_uuids++;
+                                               if (uuids.uuids) {
+                                                       uuids.uuids = 
MEM_reallocN_id(uuids.uuids, sizeof(*uuids.uuids) * (size_t)uuids.nbr_uuids, 
__func__);
+                                               }
+                                               else {
+                                                       uuids.uuids = 
MEM_mallocN(sizeof(*uuids.uuids) * (size_t)uuids.nbr_uuids, __func__);
+                                               }
+                                               uuids.uuids[uuids.nbr_uuids - 
1] = *id->uuid;
                                        }
                                        else {
                                                printf("\t\tWe need to check 
for updated asset sub-data %s...\n", id->name);
                                        }
+                                       id->tag |= LIB_TAG_DOIT;
+                               }
+                       }
+
+                       if (ae == NULL) {
+                               continue;  /* uuids.uuids has not been 
allocated either, we can skip to next lib safely. */
+                       }
+
+                       const int nbr_uuids = uuids.nbr_uuids;
+                       ae_type->update_check(ae, &uuids);
+
+                       BLI_assert(nbr_uuids == uuids.nbr_uuids);
+
+                       uuid = uuids.uuids;
+                       for (AssetRef *aref = 
lib->asset_repository->assets.first; aref; aref = aref->next) {
+                               for (LinkData *ld = aref->id_list.first; ld; ld 
= ld->next) {
+                                       ID *id = ld->data;
+                                       if (id->uuid) {
+                                               *id->uuid = *uuid;
+                                               uuid++;
+
+                                               if (id->uuid->tag & 
UUID_TAG_ENGINE_MISSING) {
+                                                       printf("\t%s uses a 
currently unknown asset engine!\n", id->name);
+                                               }
+                                               else if (id->uuid->tag & 
UUID_TAG_ASSET_MISSING) {
+                                                       printf("\t%s is 
currently unknown by asset engine!\n", id->name);
+                                               }
+                                               else if (id->uuid->tag & 
UUID_TAG_ASSET_RELOAD) {
+                                                       printf("\t%s needs to 
be reloaded/updated!\n", id->name);
+                                               }
+                                       }
                                }
                        }
+
+                       MEM_freeN(uuids.uuids);
+                       BKE_asset_engine_free(ae);
                }
        }
 }
diff --git a/source/blender/editors/space_file/filelist.c 
b/source/blender/editors/space_file/filelist.c
index 335c71d..fa69dee 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -1715,25 +1715,21 @@ FileDirEntry *filelist_entry_find_uuid(struct FileList 
*filelist, const int uuid
 
                if (engine->type->entries_uuid_get) {
                        FileDirEntryArr r_entries;
-                       AssetUUIDList *uuids = MEM_mallocN(sizeof(*uuids), 
__func__);
-                       AssetUUID *asset_uuid;
+                       AssetUUIDList uuids = {0};
+                       AssetUUID asset_uuid = {0};
                        FileDirEntry *en = NULL;
 
-                       uuids->uuids = MEM_callocN(sizeof(*uuids->uuids), 
__func__);
-                       uuids->nbr_uuids = 1;
-                       uuids->asset_engine_version = engine->type->version;
-                       asset_uuid = &uuids->uuids[0];
+                       uuids.uuids = &asset_uuid;
+                       uuids.nbr_uuids = 1;
+                       uuids.asset_engine_version = engine->type->version;
 
-                       memcpy(asset_uuid->uuid_asset, uuid, 
sizeof(asset_uuid->uuid_asset));
+                       memcpy(asset_uuid.uuid_asset, uuid, 
sizeof(asset_uuid.uuid_asset));
                        /* Variants and revision uuids remain NULL here. */
 
-                       if (engine->type->entries_uuid_get(engine, uuids, 
&r_entries)) {
+                       if (engine->type->entries_uuid_get(engine, &uuids, 
&r_entries)) {
                                en = r_entries.entries.first;
                        }
 
-                       MEM_freeN(uuids->uuids);
-                       MEM_freeN(uuids);
-
                        return en;
                }
        }
diff --git a/source/blender/makesrna/intern/rna_asset.c 
b/source/blender/makesrna/intern/rna_asset.c
index db4d8d3..7dd44f1 100644
--- a/source/blender/makesrna/intern/rna_asset.c
+++ b/source/blender/makesrna/intern/rna_asset.c
@@ -459,6 +459,33 @@ static void rna_ae_check_dir(AssetEngine *engine, char 
*r_dir)
        RNA_parameter_list_free(&list);
 }
 
+static bool rna_ae_update_check(AssetEngine *engine, AssetUUIDList *uuids)
+{
+       extern FunctionRNA rna_AssetEngine_update_check_func;
+       PointerRNA ptr;
+       PropertyRNA *parm;
+       ParameterList list;
+       FunctionRNA *func;
+
+       void *ret;
+       bool ret_success;
+
+       RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
+       func = &rna_AssetEngine_update_check_func;
+
+       RNA_parameter_list_create(&list, &ptr, func);
+       RNA_parameter_set_lookup(&list, "uuids", &uuids);
+       engine->type->ext.call(NULL, &ptr, func, &list);
+
+       parm = RNA_function_find_parameter(NULL, func, "success_return");
+       RNA_parameter_get(&list, parm, &ret);
+       ret_success = ((*(int *)ret) != 0);
+
+       RNA_parameter_list_free(&list);
+
+       return ret_success;
+}
+
 static bool rna_ae_sort_filter(
         AssetEngine *engine, const bool use_sort, const bool use_filter,
         FileSelectParams *params, FileDirEntryArr *entries_r)
@@ -575,7 +602,7 @@ static StructRNA *rna_AssetEngine_register(Main *bmain, 
ReportList *reports, voi
        AssetEngineType *aet, dummyaet = {NULL};
        AssetEngine dummyengine = {NULL};
        PointerRNA dummyptr;
-       int have_function[9];
+       int have_function[10];
 
        /* setup dummy engine & engine type to store static properties in */
        dummyengine.type = &dummyaet;
@@ -618,9 +645,11 @@ static StructRNA *rna_AssetEngine_register(Main *bmain, 
ReportList *reports, voi
 
        aet->check_dir = (have_function[5]) ? rna_ae_check_dir : NULL;
 
-       aet->sort_filter = (have_function[6]) ? rna_ae_sort_filter : NULL;
-       aet->entries_block_get = (have_function[7]) ? rna_ae_entries_block_get 
: NULL;
-       aet->entries_uuid_get = (have_function[8]) ? rna_ae_entries_uuid_get : 
NULL;
+       aet->update_check = (have_function[6]) ? rna_ae_update_check : NULL;
+
+       aet->sort_

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to