Background mode in more working conditions.
authorMartin Poirier <theeth@yahoo.com>
Wed, 11 Nov 2009 04:08:09 +0000 (04:08 +0000)
committerMartin Poirier <theeth@yahoo.com>
Wed, 11 Nov 2009 04:08:09 +0000 (04:08 +0000)
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.

source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm.c
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_init_exit.c
source/blender/windowmanager/intern/wm_window.c
source/blender/windowmanager/wm.h
source/creator/creator.c

index f9732b9c929c300ab11158657b2b7fcca79aaa3c..a784a1d560aa1117543931939649c90b461d1bde 100644 (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 */
index 1d173005d85e47ed9448432b276c0b179f033b63..d455c8b2bc19371c8c78e2389bc77580cc54f5d9 100644 (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;
+               }
        }
 }
 
index b2e55c8532e2291aa06969edf73f394b297bb850..79c718ea5d6fae0a21feb981b6ffe74a8abdb593 100644 (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 */
        
index 8097822acbcab16c0e404c662596b23aed5fe6bb..06227086006da6780afe86f5bd893d93f7a71341 100644 (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 */
        
index 70d40df453274e896d13052f13c70390e6017bd1..ae6d9ddb4255138b6bccc3c8dfb34576d23c7230 100644 (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;
 }
index c476b7efa1e2d28558d4f4f910aec0434ceb3782..9b888a0e34744b324177d793ad4e501ab2af44b6 100644 (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 */
index 84e6eed9278810f902440129424e0443e9f9e569..b4c962cbfc893e9d105ef1ee5f4bd2e364d9b0ac 100644 (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();