diff options
Diffstat (limited to 'source/creator/creator.c')
-rw-r--r-- | source/creator/creator.c | 244 |
1 files changed, 179 insertions, 65 deletions
diff --git a/source/creator/creator.c b/source/creator/creator.c index 4066d16186b..730563dfc63 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -57,8 +57,8 @@ #include "BLI_args.h" #include "BLI_threads.h" - -#include "GEN_messaging.h" +#include "BLI_scanfill.h" // for BLI_setErrorCallBack, TODO, move elsewhere +#include "BLI_utildefines.h" #include "DNA_ID.h" #include "DNA_scene_types.h" @@ -68,6 +68,7 @@ #include "BKE_utildefines.h" #include "BKE_blender.h" #include "BKE_context.h" +#include "BKE_depsgraph.h" // for DAG_on_load_update #include "BKE_font.h" #include "BKE_global.h" #include "BKE_main.h" @@ -80,7 +81,7 @@ #include "IMB_imbuf.h" // for IMB_init -#ifndef DISABLE_PYTHON +#ifdef WITH_PYTHON #include "BPY_extern.h" #endif @@ -97,7 +98,12 @@ #include "GPU_extensions.h" /* for passing information between creator and gameengine */ +#ifdef WITH_GAMEENGINE +#include "GEN_messaging.h" #include "SYS_System.h" +#else /* dummy */ +#define SYS_SystemHandle int +#endif #include <signal.h> @@ -118,6 +124,10 @@ extern char build_time[]; extern char build_rev[]; extern char build_platform[]; extern char build_type[]; +extern char build_cflags[]; +extern char build_cxxflags[]; +extern char build_linkflags[]; +extern char build_system[]; #endif /* Local Function prototypes */ @@ -138,7 +148,7 @@ static void setCallbacks(void); /* set breakpoints here when running in debug mode, useful to catch floating point errors */ #if defined(__sgi) || defined(__linux__) || defined(_WIN32) || OSX_SSE_FPE -static void fpe_handler(int sig) +static void fpe_handler(int UNUSED(sig)) { // printf("SIGFPE trapped\n"); } @@ -175,7 +185,7 @@ static void strip_quotes(char *str) } #endif -static int print_version(int argc, char **argv, void *data) +static int print_version(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) { printf (BLEND_VERSION_STRING_FMT); #ifdef BUILD_DATE @@ -184,13 +194,17 @@ static int print_version(int argc, char **argv, void *data) printf ("\tbuild revision: %s\n", build_rev); printf ("\tbuild platform: %s\n", build_platform); printf ("\tbuild type: %s\n", build_type); + printf ("\tbuild c flags: %s\n", build_cflags); + printf ("\tbuild c++ flags: %s\n", build_cxxflags); + printf ("\tbuild link flags: %s\n", build_linkflags); + printf ("\tbuild system: %s\n", build_system); #endif exit(0); return 0; } -static int print_help(int argc, char **argv, void *data) +static int print_help(int UNUSED(argc), char **UNUSED(argv), void *data) { bArgs *ba = (bArgs*)data; @@ -232,9 +246,15 @@ static int print_help(int argc, char **argv, void *data) printf ("Misc Options:\n"); BLI_argsPrintArgDoc(ba, "--debug"); BLI_argsPrintArgDoc(ba, "--debug-fpe"); - printf("\n"); - + BLI_argsPrintArgDoc(ba, "--factory-startup"); + printf("\n"); + BLI_argsPrintArgDoc(ba, "--env-system-config"); + BLI_argsPrintArgDoc(ba, "--env-system-datafiles"); + BLI_argsPrintArgDoc(ba, "--env-system-scripts"); + BLI_argsPrintArgDoc(ba, "--env-system-plugins"); + BLI_argsPrintArgDoc(ba, "--env-system-python"); + printf("\n"); BLI_argsPrintArgDoc(ba, "-nojoystick"); BLI_argsPrintArgDoc(ba, "-noglsl"); BLI_argsPrintArgDoc(ba, "-noaudio"); @@ -253,6 +273,7 @@ static int print_help(int argc, char **argv, void *data) BLI_argsPrintArgDoc(ba, "--python"); BLI_argsPrintArgDoc(ba, "--python-console"); + BLI_argsPrintArgDoc(ba, "--addons"); #ifdef WIN32 BLI_argsPrintArgDoc(ba, "-R"); @@ -317,30 +338,30 @@ double PIL_check_seconds_timer(void); } }*/ -static int end_arguments(int argc, char **argv, void *data) +static int end_arguments(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) { return -1; } -static int enable_python(int argc, char **argv, void *data) +static int enable_python(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) { G.f |= G_SCRIPT_AUTOEXEC; return 0; } -static int disable_python(int argc, char **argv, void *data) +static int disable_python(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) { G.f &= ~G_SCRIPT_AUTOEXEC; return 0; } -static int background_mode(int argc, char **argv, void *data) +static int background_mode(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) { G.background = 1; return 0; } -static int debug_mode(int argc, char **argv, void *data) +static int debug_mode(int UNUSED(argc), char **UNUSED(argv), void *data) { G.f |= G_DEBUG; /* std output printf's */ printf(BLEND_VERSION_STRING_FMT); @@ -354,7 +375,7 @@ static int debug_mode(int argc, char **argv, void *data) return 0; } -static int set_fpe(int argc, char **argv, void *data) +static int set_fpe(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) { #if defined(__sgi) || defined(__linux__) || defined(_WIN32) || OSX_SSE_FPE /* zealous but makes float issues a heck of a lot easier to find! @@ -379,7 +400,35 @@ static int set_fpe(int argc, char **argv, void *data) return 0; } -static int playback_mode(int argc, char **argv, void *data) +static int set_factory_startup(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) +{ + G.factory_startup= 1; + return 0; +} + +static int set_env(int argc, char **argv, void *UNUSED(data)) +{ + /* "--env-system-scripts" --> "BLENDER_SYSTEM_SCRIPTS" */ + + char env[64]= "BLENDER"; + char *ch_dst= env + 7; /* skip BLENDER */ + char *ch_src= argv[0] + 5; /* skip --env */ + + if (argc < 2) { + printf("%s requires one argument\n", argv[0]); + exit(1); + } + + for(; *ch_src; ch_src++, ch_dst++) { + *ch_dst= (*ch_src == '-') ? '_' : (*ch_src)-32; /* toupper() */ + } + + *ch_dst= '\0'; + BLI_setenv(env, argv[1]); + return 1; +} + +static int playback_mode(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) { /* not if -b was given first */ if (G.background == 0) { @@ -391,7 +440,7 @@ static int playback_mode(int argc, char **argv, void *data) return -2; } -static int prefsize(int argc, char **argv, void *data) +static int prefsize(int argc, char **argv, void *UNUSED(data)) { int stax, stay, sizx, sizy; @@ -410,30 +459,35 @@ static int prefsize(int argc, char **argv, void *data) return 4; } -static int with_borders(int argc, char **argv, void *data) +static int with_borders(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) { WM_setinitialstate_normal(); return 0; } -static int without_borders(int argc, char **argv, void *data) +static int without_borders(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) { WM_setinitialstate_fullscreen(); return 0; } -static int register_extension(int argc, char **argv, void *data) +static int register_extension(int UNUSED(argc), char **UNUSED(argv), void *data) { #ifdef WIN32 char *path = BLI_argsArgv(data)[0]; RegisterBlendExtension(path); +#else + (void)data; /* unused */ #endif return 0; } -static int no_joystick(int argc, char **argv, void *data) +static int no_joystick(int UNUSED(argc), char **UNUSED(argv), void *data) { +#ifndef WITH_GAMEENGINE + (void)data; +#else SYS_SystemHandle *syshandle = data; /** @@ -442,23 +496,24 @@ static int no_joystick(int argc, char **argv, void *data) */ SYS_WriteCommandLineInt(*syshandle, "nojoystick",1); if (G.f & G_DEBUG) printf("disabling nojoystick\n"); +#endif return 0; } -static int no_glsl(int argc, char **argv, void *data) +static int no_glsl(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) { GPU_extensions_disable(); return 0; } -static int no_audio(int argc, char **argv, void *data) +static int no_audio(int UNUSED(argc), char **UNUSED(argv), void *UNUSED(data)) { sound_force_device(0); return 0; } -static int set_audio(int argc, char **argv, void *data) +static int set_audio(int argc, char **argv, void *UNUSED(data)) { if (argc < 1) { printf("-setaudio require one argument\n"); @@ -583,7 +638,7 @@ static int set_image_type(int argc, char **argv, void *data) } } -static int set_threads(int argc, char **argv, void *data) +static int set_threads(int argc, char **argv, void *UNUSED(data)) { if (argc >= 1) { if(G.background) { @@ -623,8 +678,13 @@ static int set_extension(int argc, char **argv, void *data) static int set_ge_parameters(int argc, char **argv, void *data) { - SYS_SystemHandle syshandle = *(SYS_SystemHandle*)data; int a = 0; +#ifdef WITH_GAMEENGINE + SYS_SystemHandle syshandle = *(SYS_SystemHandle*)data; +#else + (void)data; +#endif + /** gameengine parameters are automaticly put into system -g [paramname = value] @@ -645,7 +705,9 @@ example: { a++; /* assignment */ +#ifdef WITH_GAMEENGINE SYS_WriteCommandLineString(syshandle,paramname,argv[a]); +#endif } else { printf("error: argument assignment (%s) without value.\n",paramname); @@ -654,8 +716,9 @@ example: /* name arg eaten */ } else { +#ifdef WITH_GAMEENGINE SYS_WriteCommandLineInt(syshandle,argv[a],1); - +#endif /* doMipMap */ if (!strcmp(argv[a],"nomipmap")) { @@ -714,7 +777,7 @@ static int render_frame(int argc, char **argv, void *data) } } -static int render_animation(int argc, char **argv, void *data) +static int render_animation(int UNUSED(argc), char **UNUSED(argv), void *data) { bContext *C = data; if (CTX_data_scene(C)) { @@ -803,7 +866,7 @@ static int set_skip_frame(int argc, char **argv, void *data) } /* macro for ugly context setup/reset */ -#ifndef DISABLE_PYTHON +#ifdef WITH_PYTHON #define BPY_CTX_SETUP(_cmd) \ { \ wmWindowManager *wm= CTX_wm_manager(C); \ @@ -821,11 +884,11 @@ static int set_skip_frame(int argc, char **argv, void *data) CTX_data_scene_set(C, prevscene); \ } \ -#endif /* DISABLE_PYTHON */ +#endif /* WITH_PYTHON */ static int run_python(int argc, char **argv, void *data) { -#ifndef DISABLE_PYTHON +#ifdef WITH_PYTHON bContext *C = data; /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */ @@ -835,7 +898,7 @@ static int run_python(int argc, char **argv, void *data) BLI_strncpy(filename, argv[1], sizeof(filename)); BLI_path_cwd(filename); - BPY_CTX_SETUP( BPY_run_python_script(C, filename, NULL, NULL) ) + BPY_CTX_SETUP(BPY_filepath_exec(C, filename, NULL)) return 1; } else { @@ -843,27 +906,50 @@ static int run_python(int argc, char **argv, void *data) return 0; } #else + (void)argc; (void)argv; (void)data; /* unused */ printf("This blender was built without python support\n"); return 0; -#endif /* DISABLE_PYTHON */ +#endif /* WITH_PYTHON */ } -static int run_python_console(int argc, char **argv, void *data) +static int run_python_console(int UNUSED(argc), char **argv, void *data) { -#ifndef DISABLE_PYTHON - bContext *C = data; - const char *expr= "__import__('code').interact()"; +#ifdef WITH_PYTHON + bContext *C = data; - BPY_CTX_SETUP( BPY_eval_string(C, expr) ) + BPY_CTX_SETUP(BPY_string_exec(C, "__import__('code').interact()")) return 0; #else + (void)argv; (void)data; /* unused */ printf("This blender was built without python support\n"); return 0; -#endif /* DISABLE_PYTHON */ +#endif /* WITH_PYTHON */ +} + +static int set_addons(int argc, char **argv, void *data) +{ + /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */ + if (argc > 1) { +#ifdef WITH_PYTHON + char *str= malloc(strlen(argv[1]) + 100); + bContext *C= data; + sprintf(str, "[__import__('bpy').utils.addon_enable(i) for i in '%s'.split(',')]", argv[1]); + BPY_CTX_SETUP(BPY_string_exec(C, str)); + free(str); +#else + (void)argv; (void)data; /* unused */ +#endif /* WITH_PYTHON */ + return 1; + } + else { + printf("\nError: you must specify a comma separated list after '--addons'.\n"); + return 0; + } } -static int load_file(int argc, char **argv, void *data) + +static int load_file(int UNUSED(argc), char **argv, void *data) { bContext *C = data; @@ -873,22 +959,35 @@ static int load_file(int argc, char **argv, void *data) BLI_path_cwd(filename); if (G.background) { - int retval = BKE_read_file(C, filename, NULL, NULL); + int retval = BKE_read_file(C, filename, NULL); /*we successfully loaded a blend file, get sure that pointcache works */ - if (retval!=0) { + if (retval != BKE_READ_FILE_FAIL) { wmWindowManager *wm= CTX_wm_manager(C); + + /* special case, 2.4x files */ + if(wm==NULL && CTX_data_main(C)->wm.first==NULL) { + extern void wm_add_default(bContext *C); + + /* wm_add_default() needs the screen to be set. */ + CTX_wm_screen_set(C, CTX_data_main(C)->screen.first); + wm_add_default(C); + } + CTX_wm_manager_set(C, NULL); /* remove wm to force check */ WM_check(C); G.relbase_valid = 1; if (CTX_wm_manager(C) == NULL) CTX_wm_manager_set(C, wm); /* reset wm */ + + DAG_on_load_update(CTX_data_main(C), TRUE); } /* WM_read_file() runs normally but since we're in background mode do here */ -#ifndef DISABLE_PYTHON +#ifdef WITH_PYTHON /* run any texts that were loaded in and flagged as modules */ - BPY_load_user_modules(C); + BPY_driver_reset(); + BPY_modules_load_user(C); #endif /* happens for the UI on file reading too (huh? (ton))*/ @@ -897,7 +996,10 @@ static int load_file(int argc, char **argv, void *data) } else { /* we are not running in background mode here, but start blender in UI mode with a file - this should do everything a 'load file' does */ - WM_read_file(C, filename, NULL); + ReportList reports; + BKE_reports_init(&reports, RPT_PRINT); + WM_read_file(C, filename, &reports); + BKE_reports_clear(&reports); } G.file_loaded = 1; @@ -935,9 +1037,9 @@ void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle) static char game_doc[] = "Game Engine specific options" "\n\t-g fixedtime\t\tRun on 50 hertz without dropping frames" - "\n\t-g vertexarrays\tUse Vertex Arrays for rendering (usually faster)" + "\n\t-g vertexarrays\t\tUse Vertex Arrays for rendering (usually faster)" "\n\t-g nomipmap\t\tNo Texture Mipmapping" - "\n\t-g linearmipmap\tLinear Texture Mipmapping instead of Nearest (default)"; + "\n\t-g linearmipmap\t\tLinear Texture Mipmapping instead of Nearest (default)"; static char debug_doc[] = "\n\tTurn debugging on\n" "\n\t* Prints every operator call and their arguments" @@ -964,12 +1066,21 @@ void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle) BLI_argsAdd(ba, 1, "-a", NULL, playback_doc, playback_mode, NULL); BLI_argsAdd(ba, 1, "-d", "--debug", debug_doc, debug_mode, ba); - BLI_argsAdd(ba, 1, NULL, "--debug-fpe", "\n\tEnable floating point exceptions", set_fpe, NULL); + BLI_argsAdd(ba, 1, NULL, "--debug-fpe", "\n\tEnable floating point exceptions", set_fpe, NULL); + + BLI_argsAdd(ba, 1, NULL, "--factory-startup", "\n\tSkip reading the "STRINGIFY(BLENDER_STARTUP_FILE)" in the users home directory", set_factory_startup, NULL); + + /* TODO, add user env vars? */ + BLI_argsAdd(ba, 1, NULL, "--env-system-config", "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_CONFIG)" environment variable", set_env, NULL); + BLI_argsAdd(ba, 1, NULL, "--env-system-datafiles", "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_DATAFILES)" environment variable", set_env, NULL); + BLI_argsAdd(ba, 1, NULL, "--env-system-scripts", "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_SCRIPTS)" environment variable", set_env, NULL); + BLI_argsAdd(ba, 1, NULL, "--env-system-plugins", "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_PLUGINS)" environment variable", set_env, NULL); + BLI_argsAdd(ba, 1, NULL, "--env-system-python", "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_PYTHON)" environment variable", set_env, NULL); /* second pass: custom window stuff */ BLI_argsAdd(ba, 2, "-p", "--window-geometry", "<sx> <sy> <w> <h>\n\tOpen with lower left corner at <sx>, <sy> and width and height as <w>, <h>", prefsize, NULL); BLI_argsAdd(ba, 2, "-w", "--window-border", "\n\tForce opening with borders (default)", with_borders, NULL); - BLI_argsAdd(ba, 2, "-W", "--window-borderless", "\n\tForce opening with without borders", without_borders, NULL); + BLI_argsAdd(ba, 2, "-W", "--window-borderless", "\n\tForce opening without borders", without_borders, NULL); BLI_argsAdd(ba, 2, "-R", NULL, "\n\tRegister .blend extension (windows only)", register_extension, ba); /* third pass: disabling things and forcing settings */ @@ -988,12 +1099,13 @@ void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle) BLI_argsAdd(ba, 4, "-j", "--frame-jump", "<frames>\n\tSet number of frames to step forward after each rendered frame", set_skip_frame, C); BLI_argsAdd(ba, 4, "-P", "--python", "<filename>\n\tRun the given Python script (filename or Blender Text)", run_python, C); BLI_argsAdd(ba, 4, NULL, "--python-console", "\n\tRun blender with an interactive console", run_python_console, C); + BLI_argsAdd(ba, 4, NULL, "--addons", "\n\tComma separated list of addons (no spaces)", set_addons, C); BLI_argsAdd(ba, 4, "-o", "--render-output", output_doc, set_output, C); BLI_argsAdd(ba, 4, "-E", "--engine", "<engine>\n\tSpecify the render engine\n\tuse -E help to list available engines", set_engine, C); BLI_argsAdd(ba, 4, "-F", "--render-format", format_doc, set_image_type, C); - BLI_argsAdd(ba, 4, "-t", "--threads", "<threads>\n\tUse amount of <threads> for rendering in background\n\t[1-" QUOTE(BLENDER_MAX_THREADS) "], 0 for systems processor count.", set_threads, NULL); + BLI_argsAdd(ba, 4, "-t", "--threads", "<threads>\n\tUse amount of <threads> for rendering in background\n\t[1-" STRINGIFY(BLENDER_MAX_THREADS) "], 0 for systems processor count.", set_threads, NULL); BLI_argsAdd(ba, 4, "-x", "--use-extension", "<bool>\n\tSet option to add the file extension to the end of the file", set_extension, C); } @@ -1035,11 +1147,15 @@ int main(int argc, char **argv) BLI_where_am_i(bprogname, argv[0]); #ifdef BUILD_DATE - strip_quotes(build_date); - strip_quotes(build_time); - strip_quotes(build_rev); - strip_quotes(build_platform); - strip_quotes(build_type); + strip_quotes(build_date); + strip_quotes(build_time); + strip_quotes(build_rev); + strip_quotes(build_platform); + strip_quotes(build_type); + strip_quotes(build_cflags); + strip_quotes(build_cxxflags); + strip_quotes(build_linkflags); + strip_quotes(build_system); #endif BLI_threadapi_init(); @@ -1058,8 +1174,12 @@ int main(int argc, char **argv) IMB_init(); +#ifdef WITH_GAMEENGINE syshandle = SYS_GetSystem(); GEN_init_messaging_system(); +#else + syshandle= 0; +#endif /* first test for background */ ba = BLI_argsInit(argc, argv); /* skip binary path */ @@ -1089,19 +1209,12 @@ int main(int argc, char **argv) BLI_argsParse(ba, 3, NULL, NULL); WM_init(C, argc, argv); - + /* this is properly initialized with user defs, but this is default */ BLI_where_is_temp( btempdir, 1 ); /* call after loading the startup.blend so we can read U.tempdir */ #ifndef DISABLE_SDL BLI_setenv("SDL_VIDEODRIVER", "dummy"); -/* I think this is not necessary anymore (04-24-2010 neXyon) -#ifdef __linux__ - // On linux the default SDL driver dma often would not play - // use alsa if none is set - setenv("SDL_AUDIODRIVER", "alsa", 0); -#endif -*/ #endif } else { @@ -1111,18 +1224,19 @@ int main(int argc, char **argv) BLI_where_is_temp( btempdir, 0 ); /* call after loading the startup.blend so we can read U.tempdir */ } -#ifndef DISABLE_PYTHON +#ifdef WITH_PYTHON /** * NOTE: the U.pythondir string is NULL until WM_init() is executed, * so we provide the BPY_ function below to append the user defined * pythondir to Python's sys.path at this point. Simply putting - * WM_init() before BPY_start_python() crashes Blender at startup. + * WM_init() before BPY_python_start() crashes Blender at startup. * Update: now this function also inits the bpymenus, which also depend * on U.pythondir. */ // TODO - U.pythondir - +#else + printf("\n* WARNING * - Blender compiled without Python!\nthis is not intended for typical usage\n\n"); #endif CTX_py_init_set(C, 1); |