[Bf-blender-cvs] [892644a] alembic: Preliminary fix for bad level calls to WM job functions from BKE.

Lukas Tönne noreply at git.blender.org
Mon Mar 30 12:39:55 CEST 2015


Commit: 892644a44c4b53f873c9b99f07e2e20f09dd3c3d
Author: Lukas Tönne
Date:   Mon Mar 30 12:36:05 2015 +0200
Branches: alembic
https://developer.blender.org/rB892644a44c4b53f873c9b99f07e2e20f09dd3c3d

Preliminary fix for bad level calls to WM job functions from BKE.

The job invocation should happen only in editors/. Also it makes sense
to modify the bake operator such that it supports both the basic cache
library and an optional modifier output.

The design for this area is in progress anyway, probably the cache
library archive paths will be changed so that there is always one input
and optionally an output path, with all the modifiers working in
sequence.

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

M	source/blender/blenkernel/BKE_cache_library.h
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/editors/io/io_cache_library.c
M	source/blender/editors/io/io_cache_library.h
M	source/blender/editors/io/io_ops.c

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

diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index eebade4..50c69fb 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -95,9 +95,8 @@ void BKE_cache_library_group_update(struct Main *bmain, struct CacheLibrary *cac
 
 /* ========================================================================= */
 
-bool BKE_cache_archive_path_test(const char *path, Library *lib);
-void BKE_cache_library_archive_path(struct CacheLibrary *cachelib, char *result, int max);
-void BKE_cache_modifier_archive_path(struct CacheLibrary *cachelib, struct CacheModifier *md, char *result, int max);
+bool BKE_cache_archive_path_test(struct CacheLibrary *cachelib, struct CacheModifier *md);
+void BKE_cache_archive_path(struct CacheLibrary *cachelib, struct CacheModifier *md, char *result, int max);
 
 void BKE_cache_library_dag_recalc_tag(struct EvaluationContext *eval_ctx, struct Main *bmain);
 
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index c6a1c12..636124a 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -63,9 +63,6 @@
 
 #include "PTC_api.h"
 
-#include "WM_api.h"
-#include "WM_types.h"
-
 CacheLibrary *BKE_cache_library_add(Main *bmain, const char *name)
 {
 	CacheLibrary *cachelib;
@@ -549,10 +546,12 @@ BLI_INLINE bool path_is_dirpath(const char *path)
 	return *(BLI_last_slash(path) + 1) == '\0';
 }
 
-bool BKE_cache_archive_path_test(const char *path, Library *lib)
+bool BKE_cache_archive_path_test(CacheLibrary *cachelib, CacheModifier *cachemd)
 {
+	const char *path = cachemd ? cachemd->filepath : cachelib->filepath;
+	
 	if (BLI_path_is_rel(path)) {
-		if (!(G.relbase_valid || lib))
+		if (!(G.relbase_valid || cachelib->id.lib))
 			return false;
 	}
 	
@@ -560,7 +559,7 @@ bool BKE_cache_archive_path_test(const char *path, Library *lib)
 	
 }
 
-static void cache_archive_path(const char *path, Library *lib, char *result, int max, const char *default_filename)
+static void cache_archive_path_ex(const char *path, Library *lib, char *result, int max, const char *default_filename)
 {
 	char abspath[FILE_MAX];
 	
@@ -593,14 +592,12 @@ static void cache_archive_path(const char *path, Library *lib, char *result, int
 	}
 }
 
-void BKE_cache_library_archive_path(struct CacheLibrary *cachelib, char *result, int max)
-{
-	cache_archive_path(cachelib->filepath, cachelib->id.lib, result, max, cachelib->id.name+2);
-}
-
-void BKE_cache_modifier_archive_path(struct CacheLibrary *cachelib, struct CacheModifier *md, char *result, int max)
+void BKE_cache_archive_path(CacheLibrary *cachelib, CacheModifier *cachemd, char *result, int max)
 {
-	cache_archive_path(md->filepath, cachelib->id.lib, result, max, md->name);
+	if (cachemd)
+		cache_archive_path_ex(cachemd->filepath, cachelib->id.lib, result, max, cachemd->name);
+	else
+		cache_archive_path_ex(cachelib->filepath, cachelib->id.lib, result, max, cachelib->id.name+2);
 }
 
 
@@ -612,14 +609,14 @@ static struct PTCReaderArchive *find_active_cache(Scene *scene, CacheLibrary *ca
 	
 	/* look for last valid modifier output */
 	for (md = cachelib->modifiers.last; md; md = md->prev) {
-		BKE_cache_modifier_archive_path(cachelib, md, filename, sizeof(filename));
+		BKE_cache_archive_path(cachelib, md, filename, sizeof(filename));
 		archive = PTC_open_reader_archive(scene, filename);
 		if (archive)
 			return archive;
 	}
 	
 	/* if no modifier has a valid output, try the base cache */
-	BKE_cache_library_archive_path(cachelib, filename, sizeof(filename));
+	BKE_cache_archive_path(cachelib, NULL, filename, sizeof(filename));
 	archive = PTC_open_reader_archive(scene, filename);
 	if (archive)
 		return archive;
@@ -830,6 +827,7 @@ void BKE_cache_modifier_foreachIDLink(struct CacheLibrary *cachelib, struct Cach
 		mti->foreachIDLink(md, cachelib, walk, userdata);
 }
 
+#if 0
 /* Warning! Deletes existing files if possible, operator should show confirm dialog! */
 static bool cache_modifier_bake_ensure_file_target(CacheLibrary *cachelib, CacheModifier *md)
 {
@@ -886,9 +884,11 @@ static void cache_modifier_bake_endjob(void *UNUSED(customdata))
 	G.is_rendering = false;
 	BKE_spacedata_draw_locks(false);
 }
+#endif
 
 void BKE_cache_modifier_bake(const bContext *C, Group *group, CacheLibrary *cachelib, CacheModifier *md, Scene *scene, int startframe, int endframe)
 {
+#if 0
 	CacheBakeContext *ctx;
 	wmJob *wm_job;
 	
@@ -923,6 +923,7 @@ void BKE_cache_modifier_bake(const bContext *C, Group *group, CacheLibrary *cach
 	WM_jobs_callbacks(wm_job, cache_modifier_bake_startjob, NULL, NULL, cache_modifier_bake_endjob);
 	
 	WM_jobs_start(CTX_wm_manager(C), wm_job);
+#endif
 }
 
 /* ------------------------------------------------------------------------- */
@@ -967,7 +968,7 @@ static void hairsim_bake(HairSimCacheModifier *hsmd, CacheLibrary *cachelib, Cac
 	
 	scene->r.framelen = 1.0f;
 	
-	BKE_cache_modifier_archive_path(cachelib, &hsmd->modifier, filename, sizeof(filename));
+	BKE_cache_archive_path(cachelib, &hsmd->modifier, filename, sizeof(filename));
 	archive = PTC_open_writer_archive(scene, filename);
 	
 	if (archive) {
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index 3cc1c28..c533608 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -255,6 +255,7 @@ typedef struct CacheLibraryBakeJob {
 	struct Scene *scene;
 	EvaluationContext eval_ctx;
 	struct CacheLibrary *cachelib;
+	struct CacheModifier *cachemd; /* optional */
 	struct Group *group;
 	
 	struct PTCWriterArchive *archive;
@@ -306,7 +307,7 @@ static void cache_library_bake_startjob(void *customdata, short *stop, short *do
 	data->origframelen = scene->r.framelen;
 	scene->r.framelen = 1.0f;
 	
-	BKE_cache_library_archive_path(data->cachelib, filename, sizeof(filename));
+	BKE_cache_archive_path(data->cachelib, data->cachemd, filename, sizeof(filename));
 	data->archive = PTC_open_writer_archive(scene, filename);
 	
 	if (data->archive) {
@@ -351,11 +352,11 @@ static void cache_library_bake_endjob(void *customdata)
 }
 
 /* Warning! Deletes existing files if possible, operator should show confirm dialog! */
-static bool cache_library_bake_ensure_file_target(CacheLibrary *cachelib)
+static bool cache_library_bake_ensure_file_target(CacheLibrary *cachelib, CacheModifier *cachemd)
 {
 	char filename[FILE_MAX];
 	
-	BKE_cache_library_archive_path(cachelib, filename, sizeof(filename));
+	BKE_cache_archive_path(cachelib, cachemd, filename, sizeof(filename));
 	
 	if (BLI_exists(filename)) {
 		if (BLI_is_dir(filename)) {
@@ -380,13 +381,15 @@ static bool cache_library_bake_ensure_file_target(CacheLibrary *cachelib)
 static int cache_library_bake_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	Object *ob = CTX_data_active_object(C);
+	CacheLibrary *cachelib = ob->cache_library;
+	CacheModifier *cachemd = CTX_data_pointer_get_type(C, "cache_modifier", &RNA_CacheLibraryModifier).data;
 	Main *bmain = CTX_data_main(C);
 	Scene *scene = CTX_data_scene(C);
 	CacheLibraryBakeJob *data;
 	wmJob *wm_job;
 	
 	/* make sure we can write */
-	cache_library_bake_ensure_file_target(ob->cache_library);
+	cache_library_bake_ensure_file_target(cachelib, cachemd);
 	
 	/* XXX annoying hack: needed to prevent data corruption when changing
 	 * scene frame in separate threads
@@ -405,7 +408,8 @@ static int cache_library_bake_exec(bContext *C, wmOperator *UNUSED(op))
 	data = MEM_callocN(sizeof(CacheLibraryBakeJob), "Cache Library Bake Job");
 	data->bmain = bmain;
 	data->scene = scene;
-	data->cachelib = ob->cache_library;
+	data->cachelib = cachelib;
+	data->cachemd = cachemd;
 	data->group = ob->dup_group;
 	
 	WM_jobs_customdata_set(wm_job, data, cache_library_bake_freejob);
@@ -421,18 +425,20 @@ static int cache_library_bake_invoke(bContext *C, wmOperator *op, const wmEvent
 {
 	Object *ob = CTX_data_active_object(C);
 	CacheLibrary *cachelib = ob->cache_library;
+	CacheModifier *cachemd = CTX_data_pointer_get_type(C, "cache_modifier", &RNA_CacheLibraryModifier).data;
 	
 	char filename[FILE_MAX];
 	
 	if (!cachelib)
 		return OPERATOR_CANCELLED;
-	if (!BKE_cache_archive_path_test(cachelib->filepath, cachelib->id.lib)) {
+	
+	BKE_cache_archive_path(cachelib, cachemd, filename, sizeof(filename));
+	
+	if (!BKE_cache_archive_path_test(cachelib, cachemd)) {
 		BKE_reportf(op->reports, RPT_ERROR, "Cannot create file path for cache library %200s", cachelib->id.name+2);
 		return OPERATOR_CANCELLED;
 	}
 	
-	BKE_cache_library_archive_path(cachelib, filename, sizeof(filename));
-	
 	if (BLI_exists(filename)) {
 		if (BLI_is_dir(filename)) {
 			BKE_reportf(op->reports, RPT_ERROR, "Cache Library target is a directory: %200s", filename);
@@ -537,7 +543,7 @@ static int cache_library_archive_info_exec(bContext *C, wmOperator *op)
 	struct PTCReaderArchive *archive;
 	char *info;
 	
-	BKE_cache_library_archive_path(cachelib, filename, sizeof(filename));
+	BKE_cache_archive_path(cachelib, NULL, filename, sizeof(filename));
 	archive = PTC_open_reader_archive(scene, filename);
 	if (!archive) {
 		BKE_reportf(op->reports, RPT_ERROR, "Cannot open cache file at '%s'", cachelib->filepath);
@@ -648,38 +654,3 @@ void CACHELIBRARY_OT_remove_modifier(struct wmOperatorType *ot)
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
-
-static int cache_library_modifier_bake_exec(bContext *C, wmOperator *UNUSED(op))
-{
-	Scene *scene = CTX_data_scene(C);
-	Object *ob = CTX_data_active_object(C);
-	PointerRNA md_ptr = CTX_data_pointer_get_type(C, "cache_modifier", &RNA_CacheLibraryModifier);
-	CacheModifier *md = md_ptr.data;
-	CacheLibrary *cachelib = md_ptr.id.data;
-	int startframe, endframe;
-	
-	if (!md)
-		return OPERATOR_CANCELLED;
-	
-	startframe = scene->r.sfra;
-	endframe = scene->r.efra;
-	
-	BKE_cache_modifier_bake(C, ob->dup_group, cachelib, md, scene, startframe, endframe);
-	
-	return OPERATOR_FINISHED;
-}
-
-void CACHELIBRARY_OT_modifier_bake(struct wmOperatorType *ot)
-{
-	/* identifiers */
-	ot->name = "Bake Cac

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list