Bringing back "Auto Start" option in the Game Menu.
authorDalai Felinto <dfelinto@gmail.com>
Fri, 5 Mar 2010 10:37:55 +0000 (10:37 +0000)
committerDalai Felinto <dfelinto@gmail.com>
Fri, 5 Mar 2010 10:37:55 +0000 (10:37 +0000)
It's (still) not working since the pool in the operator will not allow this operator to run without context.
For the window/area/screen has to be created somewhere (maybe in WM_init_game ).

I have no idea on what should be done to initialize it here, so if anyone knows how to proceed, please help here.
* side note: should we also have it as a command line option?

release/scripts/ui/space_info.py
source/blender/makesrna/intern/rna_scene.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_init_exit.c
source/creator/creator.c

index e1bc8f2b226e5fcd5751c70fbf83a65629291b59..780884591b0efcd60f3f32cd30afc8b8e8f287ae 100644 (file)
@@ -263,6 +263,8 @@ class INFO_MT_game(bpy.types.Menu):
         layout.prop(gs, "show_physics_visualization")
         layout.prop(gs, "use_deprecation_warnings")
         layout.prop(gs, "use_animation_record")
+        layout.separator()
+        layout.prop(gs, "auto_start")
 
 
 class INFO_MT_render(bpy.types.Menu):
index f4efb01589330387bccfd678d20961da548165d0..ea7a81e80187991cb8d221b8a0bd0c038871beab 100644 (file)
@@ -730,6 +730,22 @@ static void rna_Scene_sync_mode_set(PointerRNA *ptr, int value)
        }
 }
 
+static int rna_GameSettings_auto_start_get(PointerRNA *ptr)
+{
+       if (G.fileflags & G_FILE_AUTOPLAY)
+               return 1;
+
+       return 0;
+}
+
+static void rna_GameSettings_auto_start_set(PointerRNA *ptr, int value)
+{
+       if(value)
+               G.fileflags |= G_FILE_AUTOPLAY;
+       else
+               G.fileflags &= ~G_FILE_AUTOPLAY;
+}
+
 #else
 
 static void rna_def_transform_orientation(BlenderRNA *brna)
@@ -1542,6 +1558,10 @@ static void rna_def_scene_game_data(BlenderRNA *brna)
        RNA_def_property_boolean_sdna(prop, NULL, "flag", GAME_ENABLE_ANIMATION_RECORD);
        RNA_def_property_ui_text(prop, "Record Animation", "Record animation to fcurves");
 
+       prop= RNA_def_property(srna, "auto_start", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_funcs(prop, "rna_GameSettings_auto_start_get", "rna_GameSettings_auto_start_set");
+       RNA_def_property_ui_text(prop, "Auto Start", "Automatically start game at load time");
+       
        /* materials */
        prop= RNA_def_property(srna, "material_mode", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "matmode");
index 82788dc962ba4d3813b7cf038fd32a8a2e50aea4..7a1a14b645d4371f0b5e692b5d58b126f65a5e09 100644 (file)
@@ -57,6 +57,7 @@ void          WM_init                         (struct bContext *C, int argc, char **argv);
 void           WM_exit                         (struct bContext *C);
 void           WM_main                         (struct bContext *C);
 
+void           WM_init_game            (struct bContext *C);
 void           WM_init_splash          (struct bContext *C);
 
 
index 2ab6f78daa5c0d94a205d255f89d5524bb7fdc57..2a8091c1aa2c39c85d6912e02029fb0cb08c4faf 100644 (file)
@@ -523,6 +523,9 @@ void WM_write_file(bContext *C, char *target, int fileflags, ReportList *reports
                if(fileflags & G_FILE_COMPRESS) G.fileflags |= G_FILE_COMPRESS;
                else G.fileflags &= ~G_FILE_COMPRESS;
                
+               if(fileflags & G_FILE_AUTOPLAY) G.fileflags |= G_FILE_AUTOPLAY;
+               else G.fileflags &= ~G_FILE_AUTOPLAY;
+
                writeBlog();
        }
 
@@ -544,7 +547,7 @@ int WM_write_homefile(bContext *C, wmOperator *op)
        BLI_make_file_string("/", tstr, BLI_gethome(), ".B25.blend");
        
        /*  force save as regular blend file */
-       fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_LOCK | G_FILE_SIGN);
+       fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_AUTOPLAY | G_FILE_LOCK | G_FILE_SIGN);
 
        BLO_write_file(CTX_data_main(C), tstr, fileflags, op->reports);
        
@@ -612,7 +615,7 @@ void wm_autosave_timer(const bContext *C, wmWindowManager *wm, wmTimer *wt)
        wm_autosave_location(filename);
 
        /*  force save as regular blend file */
-       fileflags = G.fileflags & ~(G_FILE_COMPRESS|G_FILE_LOCK|G_FILE_SIGN);
+       fileflags = G.fileflags & ~(G_FILE_COMPRESS|G_FILE_AUTOPLAY |G_FILE_LOCK|G_FILE_SIGN);
 
        /* no error reporting to console */
        BLO_write_file(CTX_data_main(C), filename, fileflags, NULL);
index dadc6b6061611b5e9a0fdf4e77ccdeb79cfeb29d..449c586c1784c25d84937ab7f7010314d885b185 100644 (file)
@@ -181,6 +181,20 @@ void WM_init_splash(bContext *C)
        }
 }
 
+void WM_init_game(bContext *C)
+{
+       //XXX copied from WM_init_splash we may not even need those "window" related code
+       //XXX not working yet, it fails at the game_start_operator pool (it needs an area)
+       wmWindowManager *wm= CTX_wm_manager(C);
+       wmWindow *prevwin= CTX_wm_window(C);
+       
+       if(wm->windows.first) {
+               CTX_wm_window_set(C, wm->windows.first);
+               WM_operator_name_call(C, "VIEW3D_OT_game_start", WM_OP_EXEC_DEFAULT, NULL);
+               CTX_wm_window_set(C, prevwin);
+       }
+}
+
 /* free strings of open recent files */
 static void free_openrecent(void)
 {
index 3b9bac2ccd5ec25b9361cf14326eb45f43b0bcbf..1d811ba61f34c01a8eccd11eb0ed5c3b33c266b7 100644 (file)
@@ -1037,8 +1037,14 @@ int main(int argc, char **argv)
                WM_exit(C);
        }
 
-       if(!G.background && !G.file_loaded)
-               WM_init_splash(C);
+       else {
+               if(G.fileflags & G_FILE_AUTOPLAY){
+                       WM_init_game(C);
+               }
+
+               else if(!G.file_loaded)
+                       WM_init_splash(C);
+       }
 
        WM_main(C);