Merge branch 'blender2.7'
[blender.git] / source / creator / creator_args.c
index a7c906b..88476a6 100644 (file)
@@ -14,8 +14,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-/** \file creator/creator_args.c
- *  \ingroup creator
+/** \file
+ * \ingroup creator
  */
 
 #ifndef WITH_PYTHON_MODULE
 #include "BKE_context.h"
 
 #include "BKE_global.h"
+#include "BKE_image.h"
 #include "BKE_library.h"
+#include "BKE_library_override.h"
 #include "BKE_main.h"
-#include "BKE_scene.h"
 #include "BKE_report.h"
+#include "BKE_scene.h"
 #include "BKE_sound.h"
-#include "BKE_image.h"
-
-#include "DNA_screen_types.h"
-
-#include "DEG_depsgraph.h"
 
 #ifdef WITH_FFMPEG
 #include "IMB_imbuf.h"
 
 #include "WM_api.h"
 
-#include "GPU_basic_shader.h"
 #include "GPU_draw.h"
-#include "GPU_extensions.h"
-
-/* for passing information between creator and gameengine */
-#ifdef WITH_GAMEENGINE
-#  include "BL_System.h"
-#else /* dummy */
-#  define SYS_SystemHandle int
-#endif
 
 #ifdef WITH_LIBMV
 #  include "libmv-capi.h"
 #  include "CCL_api.h"
 #endif
 
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_debug.h"
+
 #include "creator_intern.h"  /* own include */
 
 
 /* -------------------------------------------------------------------- */
-
 /** \name Utility String Parsing
  * \{ */
 
@@ -429,9 +420,7 @@ static void arg_py_context_restore(
 
 /** \} */
 
-
 /* -------------------------------------------------------------------- */
-
 /** \name Handle Argument Callbacks
  *
  * \note Doc strings here are used in differently:
@@ -524,15 +513,11 @@ static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), vo
        BLI_argsPrintArgDoc(ba, "--window-border");
        BLI_argsPrintArgDoc(ba, "--window-fullscreen");
        BLI_argsPrintArgDoc(ba, "--window-geometry");
+       BLI_argsPrintArgDoc(ba, "--window-maximized");
        BLI_argsPrintArgDoc(ba, "--start-console");
        BLI_argsPrintArgDoc(ba, "--no-native-pixels");
        BLI_argsPrintArgDoc(ba, "--no-window-focus");
 
-
-       printf("\n");
-       printf("Game Engine Specific Options:\n");
-       BLI_argsPrintArgDoc(ba, "-g");
-
        printf("\n");
        printf("Python Options:\n");
        BLI_argsPrintArgDoc(ba, "--enable-autoexec");
@@ -553,6 +538,7 @@ static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), vo
        BLI_argsPrintArgDoc(ba, "--log-level");
        BLI_argsPrintArgDoc(ba, "--log-show-basename");
        BLI_argsPrintArgDoc(ba, "--log-show-backtrace");
+       BLI_argsPrintArgDoc(ba, "--log-show-timestamp");
        BLI_argsPrintArgDoc(ba, "--log-file");
 
        printf("\n");
@@ -595,13 +581,13 @@ static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), vo
        printf("Misc Options:\n");
        BLI_argsPrintArgDoc(ba, "--app-template");
        BLI_argsPrintArgDoc(ba, "--factory-startup");
+       BLI_argsPrintArgDoc(ba, "--enable-static-override");
+       BLI_argsPrintArgDoc(ba, "--enable-event-simulate");
        printf("\n");
        BLI_argsPrintArgDoc(ba, "--env-system-datafiles");
        BLI_argsPrintArgDoc(ba, "--env-system-scripts");
        BLI_argsPrintArgDoc(ba, "--env-system-python");
        printf("\n");
-       BLI_argsPrintArgDoc(ba, "-nojoystick");
-       BLI_argsPrintArgDoc(ba, "-noglsl");
        BLI_argsPrintArgDoc(ba, "-noaudio");
        BLI_argsPrintArgDoc(ba, "-setaudio");
 
@@ -617,10 +603,8 @@ static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), vo
 
        BLI_argsPrintArgDoc(ba, "--");
 
-       printf("\n");
-       printf("Experimental Features:\n");
-       BLI_argsPrintArgDoc(ba, "--enable-new-depsgraph");
-       BLI_argsPrintArgDoc(ba, "--enable-new-basic-shader-glsl");
+       //printf("\n");
+       //printf("Experimental Features:\n");
 
        /* Other options _must_ be last (anything not handled will show here) */
        printf("\n");
@@ -695,12 +679,12 @@ static const char arg_handle_python_set_doc_disable[] =
 static int arg_handle_python_set(int UNUSED(argc), const char **UNUSED(argv), void *data)
 {
        if ((bool)data) {
-               G.f |= G_SCRIPT_AUTOEXEC;
+               G.f |= G_FLAG_SCRIPT_AUTOEXEC;
        }
        else {
-               G.f &= ~G_SCRIPT_AUTOEXEC;
+               G.f &= ~G_FLAG_SCRIPT_AUTOEXEC;
        }
-       G.f |= G_SCRIPT_OVERRIDE_PREF;
+       G.f |= G_FLAG_SCRIPT_OVERRIDE_PREF;
        return 0;
 }
 
@@ -779,6 +763,15 @@ static int arg_handle_log_show_backtrace_set(int UNUSED(argc), const char **UNUS
        return 0;
 }
 
+static const char arg_handle_log_show_timestamp_set_doc[] =
+"\n\tShow a timestamp for each log message in seconds since start."
+;
+static int arg_handle_log_show_timestamp_set(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
+{
+       CLG_output_use_timestamp_set(true);
+       return 0;
+}
+
 static const char arg_handle_log_file_set_doc[] =
 "<filename>\n"
 "\n"
@@ -892,7 +885,7 @@ static const char arg_handle_debug_mode_generic_set_doc_events[] =
 static const char arg_handle_debug_mode_generic_set_doc_handlers[] =
 "\n\tEnable debug messages for event handling.";
 static const char arg_handle_debug_mode_generic_set_doc_wm[] =
-"\n\tEnable debug messages for the window manager, also prints every operator call.";
+"\n\tEnable debug messages for the window manager, shows all operators in search, shows keymap errors.";
 static const char arg_handle_debug_mode_generic_set_doc_jobs[] =
 "\n\tEnable time profiling for background jobs.";
 static const char arg_handle_debug_mode_generic_set_doc_gpu[] =
@@ -1033,6 +1026,24 @@ static int arg_handle_factory_startup_set(int UNUSED(argc), const char **UNUSED(
        return 0;
 }
 
+static const char arg_handle_enable_static_override_doc[] =
+"\n\tEnable Static Override features in the UI."
+;
+static int arg_handle_enable_static_override(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
+{
+       BKE_override_static_enable(true);
+       return 0;
+}
+
+static const char arg_handle_enable_event_simulate_doc[] =
+"\n\tEnable event simulation testing feature 'bpy.types.Window.event_simulate'."
+;
+static int arg_handle_enable_event_simulate(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
+{
+       G.f |= G_FLAG_EVENT_SIMULATE;
+       return 0;
+}
+
 static const char arg_handle_env_system_set_doc_datafiles[] =
 "\n\tSet the "STRINGIFY_ARG (BLENDER_SYSTEM_DATAFILES)" environment variable.";
 static const char arg_handle_env_system_set_doc_scripts[] =
@@ -1148,6 +1159,15 @@ static int arg_handle_without_borders(int UNUSED(argc), const char **UNUSED(argv
        return 0;
 }
 
+static const char arg_handle_window_maximized_doc[] =
+"\n\tForce opening maximized."
+;
+static int arg_handle_window_maximized(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
+{
+       WM_init_state_maximized_set();
+       return 0;
+}
+
 static const char arg_handle_no_window_focus_doc[] =
 "\n\tOpen behind other windows and without taking focus."
 ;
@@ -1186,36 +1206,6 @@ static int arg_handle_register_extension(int UNUSED(argc), const char **UNUSED(a
        return 0;
 }
 
-static const char arg_handle_joystick_disable_doc[] =
-"\n\tDisable joystick support."
-;
-static int arg_handle_joystick_disable(int UNUSED(argc), const char **UNUSED(argv), void *data)
-{
-#ifndef WITH_GAMEENGINE
-       (void)data;
-#else
-       SYS_SystemHandle *syshandle = data;
-
-       /**
-        * don't initialize joysticks if user doesn't want to use joysticks
-        * failed joystick initialization delays over 5 seconds, before game engine start
-        */
-       SYS_WriteCommandLineInt(*syshandle, "nojoystick", 1);
-       if (G.debug & G_DEBUG) printf("disabling nojoystick\n");
-#endif
-
-       return 0;
-}
-
-static const char arg_handle_glsl_disable_doc[] =
-"\n\tDisable GLSL shading."
-;
-static int arg_handle_glsl_disable(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
-{
-       GPU_extensions_disable();
-       return 0;
-}
-
 static const char arg_handle_audio_disable_doc[] =
 "\n\tForce sound system to None."
 ;
@@ -1293,10 +1283,8 @@ static int arg_handle_engine_set(int argc, const char **argv, void *data)
                else {
                        Scene *scene = CTX_data_scene(C);
                        if (scene) {
-                               RenderData *rd = &scene->r;
-
                                if (BLI_findstring(&R_engines, argv[1], offsetof(RenderEngineType, idname))) {
-                                       BLI_strncpy_utf8(rd->engine, argv[1], sizeof(rd->engine));
+                                       BLI_strncpy_utf8(scene->r.engine, argv[1], sizeof(scene->r.engine));
                                }
                                else {
                                        printf("\nError: engine not found '%s'\n", argv[1]);
@@ -1323,7 +1311,7 @@ static const char arg_handle_image_type_set_doc[] =
 "\tValid options are 'TGA' 'RAWTGA' 'JPEG' 'IRIS' 'IRIZ' 'AVIRAW' 'AVIJPEG' 'PNG' 'BMP'\n"
 "\n"
 "\tFormats that can be compiled into Blender, not available on all systems: 'HDR' 'TIFF' 'EXR' 'MULTILAYER'\n"
-"\t'MPEG' 'FRAMESERVER' 'CINEON' 'DPX' 'DDS' 'JP2'"
+"\t'MPEG' 'CINEON' 'DPX' 'DDS' 'JP2'"
 ;
 static int arg_handle_image_type_set(int argc, const char **argv, void *data)
 {
@@ -1379,26 +1367,6 @@ static int arg_handle_threads_set(int argc, const char **argv, void *UNUSED(data
        }
 }
 
-static const char arg_handle_depsgraph_use_new_doc[] =
-"\n\tUse new dependency graph."
-;
-static int arg_handle_depsgraph_use_new(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
-{
-       printf("Using new dependency graph.\n");
-       DEG_depsgraph_switch_to_new();
-       return 0;
-}
-
-static const char arg_handle_basic_shader_glsl_use_new_doc[] =
-"\n\tUse new GLSL basic shader."
-;
-static int arg_handle_basic_shader_glsl_use_new(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
-{
-       printf("Using new GLSL basic shader.\n");
-       GPU_basic_shader_use_glsl_set(true);
-       return 0;
-}
-
 static const char arg_handle_verbosity_set_doc[] =
 "<verbose>\n"
 "\tSet logging verbosity level."
@@ -1461,76 +1429,6 @@ static int arg_handle_extension_set(int argc, const char **argv, void *data)
        }
 }
 
-static const char arg_handle_ge_parameters_set_doc[] =
-"Game Engine specific options\n"
-"\n"
-"\t'fixedtime'\n"
-"\t\tRun on 50 hertz without dropping frames.\n"
-"\t'vertexarrays'\n"
-"\t\tUse Vertex Arrays for rendering (usually faster).\n"
-"\t'nomipmap'\n"
-"\t\tNo Texture Mipmapping.\n"
-"\t'linearmipmap'\n"
-"\t\tLinear Texture Mipmapping instead of Nearest (default)."
-;
-static int arg_handle_ge_parameters_set(int argc, const char **argv, void *data)
-{
-       int a = 0;
-#ifdef WITH_GAMEENGINE
-       SYS_SystemHandle syshandle = *(SYS_SystemHandle *)data;
-#else
-       (void)data;
-#endif
-
-       /**
-        * gameengine parameters are automatically put into system
-        * -g [paramname = value]
-        * -g [boolparamname]
-        * example:
-        * -g novertexarrays
-        * -g maxvertexarraysize = 512
-        */
-
-       if (argc >= 1) {
-               const char *paramname = argv[a];
-               /* check for single value versus assignment */
-               if (a + 1 < argc && (*(argv[a + 1]) == '=')) {
-                       a++;
-                       if (a + 1 < argc) {
-                               a++;
-                               /* assignment */
-#ifdef WITH_GAMEENGINE
-                               SYS_WriteCommandLineString(syshandle, paramname, argv[a]);
-#endif
-                       }
-                       else {
-                               printf("Error: argument assignment (%s) without value.\n", paramname);
-                               return 0;
-                       }
-                       /* name arg eaten */
-
-               }
-               else {
-#ifdef WITH_GAMEENGINE
-                       SYS_WriteCommandLineInt(syshandle, argv[a], 1);
-#endif
-                       /* doMipMap */
-                       if (STREQ(argv[a], "nomipmap")) {
-                               GPU_set_mipmap(G_MAIN, 0); //doMipMap = 0;
-                       }
-                       /* linearMipMap */
-                       if (STREQ(argv[a], "linearmipmap")) {
-                               GPU_set_mipmap(G_MAIN, 1);
-                               GPU_set_linear_mipmap(1); //linearMipMap = 1;
-                       }
-
-
-               } /* if (*(argv[a + 1]) == '=') */
-       }
-
-       return a;
-}
-
 static const char arg_handle_render_frame_doc[] =
 "<frame>\n"
 "\tRender frame <frame> and save it.\n"
@@ -1564,7 +1462,6 @@ static int arg_handle_render_frame(int argc, const char **argv, void *data)
                        re = RE_NewSceneRender(scene);
                        BLI_threaded_malloc_begin();
                        BKE_reports_init(&reports, RPT_STORE);
-
                        RE_SetReports(re, &reports);
                        for (int i = 0; i < frames_range_len; i++) {
                                /* We could pass in frame ranges,
@@ -1574,7 +1471,7 @@ static int arg_handle_render_frame(int argc, const char **argv, void *data)
                                }
 
                                for (int frame = frame_range_arr[i][0]; frame <= frame_range_arr[i][1]; frame++) {
-                                       RE_BlenderAnim(re, bmain, scene, NULL, scene->lay, frame, frame, scene->r.frame_step);
+                                       RE_BlenderAnim(re, bmain, scene, NULL, NULL, frame, frame, scene->r.frame_step);
                                }
                        }
                        RE_SetReports(re, NULL);
@@ -1608,7 +1505,7 @@ static int arg_handle_render_animation(int UNUSED(argc), const char **UNUSED(arg
                BLI_threaded_malloc_begin();
                BKE_reports_init(&reports, RPT_STORE);
                RE_SetReports(re, &reports);
-               RE_BlenderAnim(re, bmain, scene, NULL, scene->lay, scene->r.sfra, scene->r.efra, scene->r.frame_step);
+               RE_BlenderAnim(re, bmain, scene, NULL, NULL, scene->r.sfra, scene->r.efra, scene->r.frame_step);
                RE_SetReports(re, NULL);
                BKE_reports_clear(&reports);
                BLI_threaded_malloc_end();
@@ -1638,7 +1535,7 @@ static int arg_handle_scene_set(int argc, const char **argv, void *data)
                                win = CTX_wm_manager(C)->windows.first;
                        }
                        if (win != NULL) {
-                               win->screen->scene = scene;
+                               WM_window_set_active_scene(CTX_data_main(C), C, win, scene);
                        }
                }
                return 1;
@@ -1759,6 +1656,7 @@ static int arg_handle_python_file_run(int argc, const char **argv, void *data)
                BPY_CTX_SETUP(ok = BPY_execute_filepath(C, filename, NULL));
                if (!ok && app_state.exit_code_on_error.python) {
                        printf("\nError: script failed, file: '%s', exiting.\n", argv[1]);
+                       BPY_python_end();
                        exit(app_state.exit_code_on_error.python);
                }
                return 1;
@@ -1800,6 +1698,7 @@ static int arg_handle_python_text_run(int argc, const char **argv, void *data)
 
                if (!ok && app_state.exit_code_on_error.python) {
                        printf("\nError: script failed, text: '%s', exiting.\n", argv[1]);
+                       BPY_python_end();
                        exit(app_state.exit_code_on_error.python);
                }
 
@@ -1831,6 +1730,7 @@ static int arg_handle_python_expr_run(int argc, const char **argv, void *data)
                BPY_CTX_SETUP(ok = BPY_execute_string_ex(C, NULL, argv[1], false));
                if (!ok && app_state.exit_code_on_error.python) {
                        printf("\nError: script failed, expr: '%s', exiting.\n", argv[1]);
+                       BPY_python_end();
                        exit(app_state.exit_code_on_error.python);
                }
                return 1;
@@ -1985,7 +1885,7 @@ static int arg_handle_load_file(int UNUSED(argc), const char **argv, void *data)
 }
 
 
-void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
+void main_args_setup(bContext *C, bArgs *ba)
 {
 
 #define CB(a) a##_doc, a
@@ -2017,6 +1917,7 @@ void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
        BLI_argsAdd(ba, 1, NULL, "--log-level", CB(arg_handle_log_level_set), ba);
        BLI_argsAdd(ba, 1, NULL, "--log-show-basename", CB(arg_handle_log_show_basename_set), ba);
        BLI_argsAdd(ba, 1, NULL, "--log-show-backtrace", CB(arg_handle_log_show_backtrace_set), ba);
+       BLI_argsAdd(ba, 1, NULL, "--log-show-timestamp", CB(arg_handle_log_show_timestamp_set), ba);
        BLI_argsAdd(ba, 1, NULL, "--log-file", CB(arg_handle_log_file_set), ba);
 
        BLI_argsAdd(ba, 1, "-d", "--debug", CB(arg_handle_debug_mode_set), ba);
@@ -2078,14 +1979,15 @@ void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
                    CB_EX(arg_handle_debug_mode_generic_set, gpumem), (void *)G_DEBUG_GPU_MEM);
        BLI_argsAdd(ba, 1, NULL, "--debug-gpu-shaders",
                    CB_EX(arg_handle_debug_mode_generic_set, gpumem), (void *)G_DEBUG_GPU_SHADERS);
-
-       BLI_argsAdd(ba, 1, NULL, "--enable-new-depsgraph", CB(arg_handle_depsgraph_use_new), NULL);
-       BLI_argsAdd(ba, 1, NULL, "--enable-new-basic-shader-glsl", CB(arg_handle_basic_shader_glsl_use_new), NULL);
+       BLI_argsAdd(ba, 1, NULL, "--debug-gpu-force-workarounds",
+                   CB_EX(arg_handle_debug_mode_generic_set, gpumem), (void *)G_DEBUG_GPU_FORCE_WORKAROUNDS);
 
        BLI_argsAdd(ba, 1, NULL, "--verbose", CB(arg_handle_verbosity_set), NULL);
 
        BLI_argsAdd(ba, 1, NULL, "--app-template", CB(arg_handle_app_template), NULL);
        BLI_argsAdd(ba, 1, NULL, "--factory-startup", CB(arg_handle_factory_startup_set), NULL);
+       BLI_argsAdd(ba, 1, NULL, "--enable-static-override", CB(arg_handle_enable_static_override), NULL);
+       BLI_argsAdd(ba, 1, NULL, "--enable-event-simulate", CB(arg_handle_enable_event_simulate), NULL);
 
        /* TODO, add user env vars? */
        BLI_argsAdd(ba, 1, NULL, "--env-system-datafiles", CB_EX(arg_handle_env_system_set, datafiles), NULL);
@@ -2096,6 +1998,7 @@ void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
        BLI_argsAdd(ba, 2, "-p", "--window-geometry", CB(arg_handle_window_geometry), NULL);
        BLI_argsAdd(ba, 2, "-w", "--window-border", CB(arg_handle_with_borders), NULL);
        BLI_argsAdd(ba, 2, "-W", "--window-fullscreen", CB(arg_handle_without_borders), NULL);
+       BLI_argsAdd(ba, 2, "-M", "--window-maximized", CB(arg_handle_window_maximized), NULL);
        BLI_argsAdd(ba, 2, NULL, "--no-window-focus", CB(arg_handle_no_window_focus), NULL);
        BLI_argsAdd(ba, 2, "-con", "--start-console", CB(arg_handle_start_with_console), NULL);
        BLI_argsAdd(ba, 2, "-R", NULL, CB(arg_handle_register_extension), NULL);
@@ -2103,13 +2006,10 @@ void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
        BLI_argsAdd(ba, 2, NULL, "--no-native-pixels", CB(arg_handle_native_pixels_set), ba);
 
        /* third pass: disabling things and forcing settings */
-       BLI_argsAddCase(ba, 3, "-nojoystick", 1, NULL, 0, CB(arg_handle_joystick_disable), syshandle);
-       BLI_argsAddCase(ba, 3, "-noglsl", 1, NULL, 0, CB(arg_handle_glsl_disable), NULL);
        BLI_argsAddCase(ba, 3, "-noaudio", 1, NULL, 0, CB(arg_handle_audio_disable), NULL);
        BLI_argsAddCase(ba, 3, "-setaudio", 1, NULL, 0, CB(arg_handle_audio_set), NULL);
 
        /* fourth pass: processing arguments */
-       BLI_argsAdd(ba, 4, "-g", NULL, CB(arg_handle_ge_parameters_set), syshandle);
        BLI_argsAdd(ba, 4, "-f", "--render-frame", CB(arg_handle_render_frame), C);
        BLI_argsAdd(ba, 4, "-a", "--render-anim", CB(arg_handle_render_animation), C);
        BLI_argsAdd(ba, 4, "-S", "--scene", CB(arg_handle_scene_set), C);