[Bf-blender-cvs] [1d40cfa] asset-engine: Move core of update check to BKE's asset area, add an operator for that too.
Bastien Montagne
noreply at git.blender.org
Sat Apr 16 15:06:37 CEST 2016
Commit: 1d40cfafea0e3d77112a65e78623032e947dd69a
Author: Bastien Montagne
Date: Fri Apr 15 10:38:49 2016 +0200
Branches: asset-engine
https://developer.blender.org/rB1d40cfafea0e3d77112a65e78623032e947dd69a
Move core of update check to BKE's asset area, add an operator for that too.
===================================================================
M source/blender/blenkernel/BKE_asset.h
M source/blender/blenkernel/intern/asset.c
M source/blender/blenkernel/intern/blender.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 043cfd7..82dee54 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -49,6 +49,7 @@ struct ExtensionRNA;
struct ID;
struct IDProperty;
struct ListBase;
+struct Main;
struct ReportList;
struct uiLayout;
@@ -200,6 +201,8 @@ void BKE_asset_engine_free(AssetEngine *engine);
AssetUUIDList *BKE_asset_engine_load_pre(AssetEngine *engine, struct FileDirEntryArr *r_entries);
+void BKE_assets_update_check(struct Main *bmain);
+
/* File listing utils... */
typedef enum FileCheckType {
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index 0fb85a8..d0dc664 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -46,10 +46,14 @@
#include "BLI_string.h"
#include "BLI_utildefines.h"
+#include "PIL_time.h"
+
+#include "BKE_asset.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
#include "BKE_report.h"
-#include "BKE_asset.h"
#include "IMB_imbuf.h"
@@ -232,6 +236,102 @@ AssetUUIDList *BKE_asset_engine_load_pre(AssetEngine *engine, FileDirEntryArr *r
}
+void BKE_assets_update_check(Main *bmain)
+{
+ 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, NULL);
+ }
+
+ 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 job_id = ae_type->update_check(ae, AE_JOB_ID_UNSET, &uuids);
+ if (job_id != AE_JOB_ID_INVALID) {
+ while (ae_type->status(ae, job_id) & AE_STATUS_RUNNING) PIL_sleep_ms(50);
+ ae_type->kill(ae, job_id);
+ }
+
+ /* Note: UUIDs list itself is not editable from py (adding/removing/reordering items), so we can use mere
+ * order to map returned uuid data to their IDs. */
+
+ 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);
+ }
+ }
+}
+
/* FileDirxxx handling. */
void BKE_filedir_revision_free(FileDirEntryRevision *rev)
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index e3b03a6..73c306c 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -521,104 +521,6 @@ void BKE_userdef_state(void)
}
-static void read_file_update_assets(bContext *C)
-{
- Main *bmain = CTX_data_main(C);
-
- 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, NULL);
- }
-
- 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 job_id = ae_type->update_check(ae, AE_JOB_ID_UNSET, &uuids);
- if (job_id != AE_JOB_ID_INVALID) {
- while (ae_type->status(ae, job_id) & AE_STATUS_RUNNING);
- ae_type->kill(ae, job_id);
- }
-
- /* Note: UUIDs list itself is not editable from py (adding/removing/reordering items), so we can use mere
- * order to map returned uuid data to their IDs. */
-
- 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);
- }
- }
-}
-
int BKE_read_file(bContext *C, const char *filepath, ReportList *reports)
{
BlendFileData *bfd;
@@ -641,7 +543,7 @@ int BKE_read_file(bContext *C, const char *filepath, ReportList *reports)
setup_app_data(C, bfd, filepath, reports);
printf("Updating assets for: %s\n", filepath);
- read_file_update_assets(C);
+ BKE_assets_update_check(CTX_data_main(C));
}
}
else
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 4bb5b18..6f0afda 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -2388,6 +2388,29 @@ static void WM_OT_revert_mainfile(wmOperatorType *ot)
ot->poll = wm_revert_mainfile_poll;
}
+/* ****************** assets ****************** */
+
+static int wm_assets_update_check_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Main *bmain = CTX_data_main(C);
+
+ BKE_assets_update_check(bmain);
+
+ return OPERATOR_FINISHED;
+}
+
+static void WM_OT_assets_update_check(wmOperatorType *ot)
+{
+ ot->name = "Check Assets Update";
+ ot->idname = "WM_OT_assets_update_check";
+ ot->description = "Check/refresh status of assets (in a background job)";
+
+// RNA_def_boolean(ot->srna, "use_scripts", true, "Trusted Source",
+// "Allow .blend file to execute scripts automatically, default available from system preferences");
+
+ ot->exec = wm_assets_update_check_exec;
+}
+
/* **************** link/append *************** */
static int wm_link_append_poll(bContext *C)
@@ -5179,6 +5202,7 @@ void wm_operatortype_init(void)
WM_operatortype_append(WM_OT_quit_blender);
WM_operatortype_append(WM_OT_open_mainfile);
WM_operatortype_append(WM_OT_revert_mainfile);
+ WM_operatortype_append(WM_OT_assets_update_check);
WM_operatortype_append(WM_OT_link);
WM_operatortype_append(WM_OT_append);
WM_operatortype_append(WM_OT_recover_last_session);
More information about the Bf-blender-cvs
mailing list