Background mode in more working conditions.

What works:
The usual command line options for rendering.
All python scripts are loaded (which includes custom properties)
Render engines are loaded and can be used
-P to run scripts works partially: rna api works ok, not operators.

What doesn't: 
Most operator calls in python. This is a problem with poll functions. (Brecht and Campbell are aware of this already)

Changes:
-d now also applied with -b (it was ignored before)
user file (.B25.blend) now also loaded in bg mode. This helps for custom paths and all.
wm is also initialized (it's needed for a lot of context calls)
Ghost, however, is not initialized.
This commit is contained in:
Martin Poirier
2009-11-11 04:08:09 +00:00
parent f7d7149936
commit e776ecfdde
7 changed files with 64 additions and 32 deletions

View File

@@ -52,6 +52,9 @@ void WM_init (struct bContext *C);
void WM_exit (struct bContext *C);
void WM_main (struct bContext *C);
void WM_check (struct bContext *C);
struct wmWindow *WM_window_open (struct bContext *C, struct rcti *rect);
/* defines for 'type' WM_window_open_temp */

View File

@@ -43,6 +43,7 @@
#include "BKE_main.h"
#include "BKE_screen.h"
#include "BKE_report.h"
#include "BKE_global.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -196,7 +197,7 @@ void WM_keymap_init(bContext *C)
WM_keyconfig_userdef(wm);
}
void wm_check(bContext *C)
void WM_check(bContext *C)
{
wmWindowManager *wm= CTX_wm_manager(C);
@@ -208,19 +209,21 @@ void wm_check(bContext *C)
if(wm==NULL) return;
if(wm->windows.first==NULL) return;
/* case: fileread */
if((wm->initialized & WM_INIT_WINDOW) == 0) {
WM_keymap_init(C);
WM_autosave_init(C);
}
/* case: no open windows at all, for old file reads */
wm_window_add_ghostwindows(wm);
/* case: fileread */
if((wm->initialized & WM_INIT_WINDOW) == 0) {
ED_screens_initialize(wm);
wm->initialized |= WM_INIT_WINDOW;
if (!G.background) {
/* case: fileread */
if((wm->initialized & WM_INIT_WINDOW) == 0) {
WM_keymap_init(C);
WM_autosave_init(C);
}
/* case: no open windows at all, for old file reads */
wm_window_add_ghostwindows(wm);
/* case: fileread */
if((wm->initialized & WM_INIT_WINDOW) == 0) {
ED_screens_initialize(wm);
wm->initialized |= WM_INIT_WINDOW;
}
}
}

View File

@@ -256,8 +256,8 @@ void WM_read_file(bContext *C, char *name, ReportList *reports)
G.save_over = 1;
/* match the read WM with current WM */
wm_window_match_do(C, &wmbase);
wm_check(C); /* opens window(s), checks keymaps */
wm_window_match_do(C, &wmbase);
WM_check(C); /* opens window(s), checks keymaps */
// XXX mainwindow_set_filename_to_title(G.main->name);
@@ -322,7 +322,7 @@ int WM_read_homefile(bContext *C, wmOperator *op)
/* match the read WM with current WM */
wm_window_match_do(C, &wmbase);
wm_check(C); /* opens window(s), checks keymaps */
WM_check(C); /* opens window(s), checks keymaps */
strcpy(G.sce, scestr); /* restore */

View File

@@ -108,8 +108,10 @@ static void wm_free_reports(bContext *C)
void WM_init(bContext *C)
{
wm_ghost_init(C); /* note: it assigns C to ghost! */
wm_init_cursor_data();
if (!G.background) {
wm_ghost_init(C); /* note: it assigns C to ghost! */
wm_init_cursor_data();
}
wm_operatortype_init();
set_free_windowmanager_cb(wm_close_and_free); /* library.c */
@@ -130,10 +132,12 @@ void WM_init(bContext *C)
WM_read_homefile(C, NULL);
wm_init_reports(C); /* reports cant be initialized before the wm */
GPU_extensions_init();
UI_init();
if (!G.background) {
GPU_extensions_init();
UI_init();
}
// clear_matcopybuf(); /* XXX */

View File

@@ -335,7 +335,7 @@ static void wm_window_add_ghostwindow(wmWindowManager *wm, char *title, wmWindow
/* for wmWindows without ghostwin, open these and clear */
/* window size is read from window, if 0 it uses prefsize */
/* called in wm_check, also inits stuff after file read */
/* called in WM_check, also inits stuff after file read */
void wm_window_add_ghostwindows(wmWindowManager *wm)
{
wmKeyMap *keymap;
@@ -403,7 +403,7 @@ wmWindow *WM_window_open(bContext *C, rcti *rect)
win->drawmethod= -1;
win->drawdata= NULL;
wm_check(C);
WM_check(C);
return win;
}
@@ -448,7 +448,7 @@ void WM_window_open_temp(bContext *C, rcti *position, int type)
/* make window active, and validate/resize */
CTX_wm_window_set(C, win);
wm_check(C);
WM_check(C);
/* ensure it shows the right spacetype editor */
sa= win->screen->areabase.first;
@@ -480,7 +480,7 @@ void WM_window_open_temp(bContext *C, rcti *position, int type)
int wm_window_duplicate_op(bContext *C, wmOperator *op)
{
wm_window_copy(C, CTX_wm_window(C));
wm_check(C);
WM_check(C);
return OPERATOR_FINISHED;
}

View File

@@ -44,7 +44,6 @@ extern void wm_close_and_free(bContext *C, wmWindowManager *);
extern void wm_close_and_free_all(bContext *C, ListBase *);
extern void wm_add_default(bContext *C);
extern void wm_check(bContext *C);
extern void wm_clear_default_size(bContext *C);
/* register to windowmanager for redo or macro */

View File

@@ -508,6 +508,27 @@ int main(int argc, char **argv)
#endif
}
else {
for(a=1; a<argc; a++) {
if(argv[a][0] == '-') {
switch(argv[a][1]) {
case 'd':
G.f |= G_DEBUG; /* std output printf's */
printf ("Blender %d.%02d (sub %d) Build\n", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION);
MEM_set_memory_debug();
#ifdef NAN_BUILDINFO
printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type);
#endif // NAN_BUILDINFO
for (i = 0; i < argc; i++) {
printf("argv[%d] = %s\n", i, argv[i]);
}
break;
}
}
}
WM_init(C);
#ifndef DISABLE_PYTHON
BPY_start_python(argc, argv);
#endif
@@ -524,13 +545,11 @@ int main(int argc, char **argv)
*/
BPY_post_start_python();
if(!G.background)
BPY_run_ui_scripts(C, 0); /* dont need to reload the first time */
BPY_run_ui_scripts(C, 0); /* dont need to reload the first time */
#endif
CTX_py_init_set(C, 1);
if(!G.background)
WM_keymap_init(C); /* after BPY_run_ui_scripts() */
WM_keymap_init(C); /* after BPY_run_ui_scripts() */
#ifdef WITH_QUICKTIME
@@ -843,7 +862,11 @@ int main(int argc, char **argv)
/*we successfully loaded a blend file, get sure that
pointcache works */
if (retval!=0) G.relbase_valid = 1;
if (retval!=0) {
CTX_wm_manager_set(C, NULL); /* remove wm to force check */
WM_check(C);
G.relbase_valid = 1;
}
/* happens for the UI on file reading too (huh? (ton))*/
// XXX BKE_reset_undo();