Blender V2.61 - r43446

creator.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #if defined(__linux__) && defined(__GNUC__)
00034 #define _GNU_SOURCE
00035 #include <fenv.h>
00036 #endif
00037 
00038 #if (defined(__APPLE__) && (defined(__i386__) || defined(__x86_64__)))
00039 #define OSX_SSE_FPE
00040 #include <xmmintrin.h>
00041 #endif
00042 
00043 #include <stdlib.h>
00044 #include <stddef.h>
00045 #include <string.h>
00046 
00047 /* This little block needed for linking to Blender... */
00048 
00049 #include "MEM_guardedalloc.h"
00050 
00051 #ifdef WIN32
00052 #include "BLI_winstuff.h"
00053 #endif
00054 
00055 #include "BLI_args.h"
00056 #include "BLI_threads.h"
00057 #include "BLI_scanfill.h" // for BLI_setErrorCallBack, TODO, move elsewhere
00058 #include "BLI_utildefines.h"
00059 #include "BLI_callbacks.h"
00060 
00061 #include "DNA_ID.h"
00062 #include "DNA_scene_types.h"
00063 #include "DNA_userdef_types.h"
00064 
00065 #include "BLI_blenlib.h"
00066 
00067 #include "BKE_utildefines.h"
00068 #include "BKE_blender.h"
00069 #include "BKE_context.h"
00070 #include "BKE_depsgraph.h" // for DAG_on_visible_update
00071 #include "BKE_font.h"
00072 #include "BKE_global.h"
00073 #include "BKE_main.h"
00074 #include "BKE_material.h"
00075 #include "BKE_packedFile.h"
00076 #include "BKE_scene.h"
00077 #include "BKE_node.h"
00078 #include "BKE_report.h"
00079 #include "BKE_sound.h"
00080 #include "BKE_image.h"
00081 
00082 #include "IMB_imbuf.h"  // for IMB_init
00083 
00084 #ifdef WITH_PYTHON
00085 #include "BPY_extern.h"
00086 #endif
00087 
00088 #include "RE_engine.h"
00089 #include "RE_pipeline.h"
00090 
00091 //XXX #include "playanim_ext.h"
00092 #include "ED_datafiles.h"
00093 
00094 #include "WM_api.h"
00095 
00096 #include "RNA_define.h"
00097 
00098 #include "GPU_draw.h"
00099 #include "GPU_extensions.h"
00100 
00101 #ifdef WITH_BUILDINFO_HEADER
00102 #define BUILD_DATE
00103 #endif
00104 
00105 /* for passing information between creator and gameengine */
00106 #ifdef WITH_GAMEENGINE
00107 #include "BL_System.h"
00108 #else /* dummy */
00109 #define SYS_SystemHandle int
00110 #endif
00111 
00112 #include <signal.h>
00113 
00114 #ifdef __FreeBSD__
00115 # include <sys/types.h>
00116 # include <floatingpoint.h>
00117 # include <sys/rtprio.h>
00118 #endif
00119 
00120 #ifdef WITH_BINRELOC
00121 #include "binreloc.h"
00122 #endif
00123 
00124 #ifdef WITH_LIBMV
00125 #include "libmv-capi.h"
00126 #endif
00127 
00128 // from buildinfo.c
00129 #ifdef BUILD_DATE
00130 extern char build_date[];
00131 extern char build_time[];
00132 extern char build_rev[];
00133 extern char build_platform[];
00134 extern char build_type[];
00135 extern char build_cflags[];
00136 extern char build_cxxflags[];
00137 extern char build_linkflags[];
00138 extern char build_system[];
00139 #endif
00140 
00141 /*  Local Function prototypes */
00142 static int print_help(int argc, const char **argv, void *data);
00143 static int print_version(int argc, const char **argv, void *data);
00144 
00145 /* for the callbacks: */
00146 
00147 extern int pluginapi_force_ref(void);  /* from blenpluginapi:pluginapi.c */
00148 
00149 #define BLEND_VERSION_STRING_FMT                                              \
00150     "Blender %d.%02d (sub %d)\n",                                             \
00151     BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION              \
00152 
00153 /* Initialize callbacks for the modules that need them */
00154 static void setCallbacks(void); 
00155 
00156 /* set breakpoints here when running in debug mode, useful to catch floating point errors */
00157 #if defined(__linux__) || defined(_WIN32) || defined(OSX_SSE_FPE)
00158 static void fpe_handler(int UNUSED(sig))
00159 {
00160     // printf("SIGFPE trapped\n");
00161 }
00162 #endif
00163 
00164 #ifndef WITH_PYTHON_MODULE
00165 /* handling ctrl-c event in console */
00166 static void blender_esc(int sig)
00167 {
00168     static int count = 0;
00169     
00170     G.afbreek = 1;  /* forces render loop to read queue, not sure if its needed */
00171     
00172     if (sig == 2) {
00173         if (count) {
00174             printf("\nBlender killed\n");
00175             exit(2);
00176         }
00177         printf("\nSent an internal break event. Press ^C again to kill Blender\n");
00178         count++;
00179     }
00180 }
00181 #endif
00182 
00183 static int print_version(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
00184 {
00185     printf (BLEND_VERSION_STRING_FMT);
00186 #ifdef BUILD_DATE
00187     printf ("\tbuild date: %s\n", build_date);
00188     printf ("\tbuild time: %s\n", build_time);
00189     printf ("\tbuild revision: %s\n", build_rev);
00190     printf ("\tbuild platform: %s\n", build_platform);
00191     printf ("\tbuild type: %s\n", build_type);
00192     printf ("\tbuild c flags: %s\n", build_cflags);
00193     printf ("\tbuild c++ flags: %s\n", build_cxxflags);
00194     printf ("\tbuild link flags: %s\n", build_linkflags);
00195     printf ("\tbuild system: %s\n", build_system);
00196 #endif
00197     exit(0);
00198 
00199     return 0;
00200 }
00201 
00202 static int print_help(int UNUSED(argc), const char **UNUSED(argv), void *data)
00203 {
00204     bArgs *ba = (bArgs*)data;
00205 
00206     printf (BLEND_VERSION_STRING_FMT);
00207     printf ("Usage: blender [args ...] [file] [args ...]\n\n");
00208 
00209     printf ("Render Options:\n");
00210     BLI_argsPrintArgDoc(ba, "--background");
00211     BLI_argsPrintArgDoc(ba, "--render-anim");
00212     BLI_argsPrintArgDoc(ba, "--scene");
00213     BLI_argsPrintArgDoc(ba, "--render-frame");
00214     BLI_argsPrintArgDoc(ba, "--frame-start");
00215     BLI_argsPrintArgDoc(ba, "--frame-end");
00216     BLI_argsPrintArgDoc(ba, "--frame-jump");
00217     BLI_argsPrintArgDoc(ba, "--render-output");
00218     BLI_argsPrintArgDoc(ba, "--engine");
00219     
00220     printf("\n");
00221     printf ("Format Options:\n");
00222     BLI_argsPrintArgDoc(ba, "--render-format");
00223     BLI_argsPrintArgDoc(ba, "--use-extension");
00224     BLI_argsPrintArgDoc(ba, "--threads");
00225 
00226     printf("\n");
00227     printf ("Animation Playback Options:\n");
00228     BLI_argsPrintArgDoc(ba, "-a");
00229                 
00230     printf("\n");
00231     printf ("Window Options:\n");
00232     BLI_argsPrintArgDoc(ba, "--window-border");
00233     BLI_argsPrintArgDoc(ba, "--window-borderless");
00234     BLI_argsPrintArgDoc(ba, "--window-geometry");
00235     BLI_argsPrintArgDoc(ba, "--start-console");
00236 
00237     printf("\n");
00238     printf ("Game Engine Specific Options:\n");
00239     BLI_argsPrintArgDoc(ba, "-g");
00240 
00241     printf("\n");
00242     printf ("Misc Options:\n");
00243     BLI_argsPrintArgDoc(ba, "--debug");
00244     BLI_argsPrintArgDoc(ba, "--debug-fpe");
00245     printf("\n");
00246     BLI_argsPrintArgDoc(ba, "--factory-startup");
00247     printf("\n");
00248     BLI_argsPrintArgDoc(ba, "--env-system-config");
00249     BLI_argsPrintArgDoc(ba, "--env-system-datafiles");
00250     BLI_argsPrintArgDoc(ba, "--env-system-scripts");
00251     BLI_argsPrintArgDoc(ba, "--env-system-plugins");
00252     BLI_argsPrintArgDoc(ba, "--env-system-python");
00253     printf("\n");
00254     BLI_argsPrintArgDoc(ba, "-nojoystick");
00255     BLI_argsPrintArgDoc(ba, "-noglsl");
00256     BLI_argsPrintArgDoc(ba, "-noaudio");
00257     BLI_argsPrintArgDoc(ba, "-setaudio");
00258 
00259     printf("\n");
00260 
00261     BLI_argsPrintArgDoc(ba, "--help");
00262 
00263     printf("\n");
00264 
00265     BLI_argsPrintArgDoc(ba, "--enable-autoexec");
00266     BLI_argsPrintArgDoc(ba, "--disable-autoexec");
00267 
00268     printf("\n");
00269 
00270     BLI_argsPrintArgDoc(ba, "--python");
00271     BLI_argsPrintArgDoc(ba, "--python-console");
00272     BLI_argsPrintArgDoc(ba, "--addons");
00273 
00274 #ifdef WIN32
00275     BLI_argsPrintArgDoc(ba, "-R");
00276     BLI_argsPrintArgDoc(ba, "-r");
00277 #endif
00278     BLI_argsPrintArgDoc(ba, "--version");
00279 
00280     BLI_argsPrintArgDoc(ba, "--");
00281 
00282     printf ("Other Options:\n");
00283     BLI_argsPrintOtherDoc(ba);
00284 
00285     printf ("Argument Parsing:\n");
00286     printf ("\targuments must be separated by white space. eg\n");
00287     printf ("\t\t\"blender -ba test.blend\"\n");
00288     printf ("\t...will ignore the 'a'\n");
00289     printf ("\t\t\"blender -b test.blend -f8\"\n");
00290     printf ("\t...will ignore 8 because there is no space between the -f and the frame value\n\n");
00291 
00292     printf ("Argument Order:\n");
00293     printf ("Arguments are executed in the order they are given. eg\n");
00294     printf ("\t\t\"blender --background test.blend --render-frame 1 --render-output /tmp\"\n");
00295     printf ("\t...will not render to /tmp because '--render-frame 1' renders before the output path is set\n");
00296     printf ("\t\t\"blender --background --render-output /tmp test.blend --render-frame 1\"\n");
00297     printf ("\t...will not render to /tmp because loading the blend file overwrites the render output that was set\n");
00298     printf ("\t\t\"blender --background test.blend --render-output /tmp --render-frame 1\" works as expected.\n\n");
00299 
00300     printf ("\nEnvironment Variables:\n");
00301     printf ("  $BLENDER_USER_CONFIG      Directory for user configuration files.\n");
00302     printf ("  $BLENDER_USER_SCRIPTS     Directory for user scripts.\n");
00303     printf ("  $BLENDER_SYSTEM_SCRIPTS   Directory for system wide scripts.\n");
00304     printf ("  $Directory for user data files (icons, translations, ..).\n");
00305     printf ("  $BLENDER_SYSTEM_DATAFILES Directory for system wide data files.\n");
00306     printf ("  $BLENDER_SYSTEM_PYTHON    Directory for system python libraries.\n");
00307 #ifdef WIN32
00308     printf ("  $TEMP                     Store temporary files here.\n");
00309 #else
00310     printf ("  $TMP or $TMPDIR           Store temporary files here.\n");
00311 #endif
00312 #ifdef WITH_SDL
00313     printf ("  $SDL_AUDIODRIVER          LibSDL audio driver - alsa, esd, dma.\n");
00314 #endif
00315     printf ("  $PYTHONHOME               Path to the python directory, eg. /usr/lib/python.\n\n");
00316 
00317     exit(0);
00318 
00319     return 0;
00320 }
00321 
00322 
00323 double PIL_check_seconds_timer(void);
00324 
00325 static int end_arguments(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
00326 {
00327     return -1;
00328 }
00329 
00330 static int enable_python(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
00331 {
00332     G.f |= G_SCRIPT_AUTOEXEC;
00333     G.f |= G_SCRIPT_OVERRIDE_PREF;
00334     return 0;
00335 }
00336 
00337 static int disable_python(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
00338 {
00339     G.f &= ~G_SCRIPT_AUTOEXEC;
00340     G.f |= G_SCRIPT_OVERRIDE_PREF;
00341     return 0;
00342 }
00343 
00344 static int background_mode(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
00345 {
00346     G.background = 1;
00347     return 0;
00348 }
00349 
00350 static int debug_mode(int UNUSED(argc), const char **UNUSED(argv), void *data)
00351 {
00352     G.f |= G_DEBUG;     /* std output printf's */
00353     printf(BLEND_VERSION_STRING_FMT);
00354     MEM_set_memory_debug();
00355 
00356 #ifdef WITH_BUILDINFO
00357     printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type);
00358 #endif // WITH_BUILDINFO
00359 
00360 #ifdef WITH_LIBMV
00361     libmv_startDebugLogging();
00362 #endif
00363 
00364     BLI_argsPrint(data);
00365     return 0;
00366 }
00367 
00368 static int set_fpe(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
00369 {
00370 #if defined(__linux__) || defined(_WIN32) || defined(OSX_SSE_FPE)
00371     /* zealous but makes float issues a heck of a lot easier to find!
00372      * set breakpoints on fpe_handler */
00373     signal(SIGFPE, fpe_handler);
00374 
00375 # if defined(__linux__) && defined(__GNUC__)
00376     feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
00377 # endif /* defined(__linux__) && defined(__GNUC__) */
00378 # if defined(OSX_SSE_FPE)
00379     /* OSX uses SSE for floating point by default, so here 
00380      * use SSE instructions to throw floating point exceptions */
00381     _MM_SET_EXCEPTION_MASK(_MM_MASK_MASK &~
00382             (_MM_MASK_OVERFLOW|_MM_MASK_INVALID|_MM_MASK_DIV_ZERO));
00383 # endif /* OSX_SSE_FPE */
00384 # if defined(_WIN32) && defined(_MSC_VER)
00385     _controlfp_s(NULL, 0, _MCW_EM); /* enables all fp exceptions */
00386     _controlfp_s(NULL, _EM_DENORMAL | _EM_UNDERFLOW | _EM_INEXACT, _MCW_EM); /* hide the ones we don't care about */
00387 # endif /* _WIN32 && _MSC_VER */
00388 #endif
00389 
00390     return 0;
00391 }
00392 
00393 static int set_factory_startup(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
00394 {
00395     G.factory_startup= 1;
00396     return 0;
00397 }
00398 
00399 static int set_env(int argc, const char **argv, void *UNUSED(data))
00400 {
00401     /* "--env-system-scripts" --> "BLENDER_SYSTEM_SCRIPTS" */
00402 
00403     char env[64]= "BLENDER";
00404     char *ch_dst= env + 7; /* skip BLENDER */
00405     const char *ch_src= argv[0] + 5; /* skip --env */
00406 
00407     if (argc < 2) {
00408         printf("%s requires one argument\n", argv[0]);
00409         exit(1);
00410     }
00411 
00412     for(; *ch_src; ch_src++, ch_dst++) {
00413         *ch_dst= (*ch_src == '-') ? '_' : (*ch_src)-32; /* toupper() */
00414     }
00415 
00416     *ch_dst= '\0';
00417     BLI_setenv(env, argv[1]);
00418     return 1;
00419 }
00420 
00421 static int playback_mode(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
00422 {
00423     /* not if -b was given first */
00424     if (G.background == 0) {
00425 #if 0   /* TODO, bring player back? */
00426         playanim(argc, argv); /* not the same argc and argv as before */
00427 #else
00428         fprintf(stderr, "Playback mode not supported in blender 2.5x\n");
00429         exit(0);
00430 #endif
00431     }
00432 
00433     return -2;
00434 }
00435 
00436 static int prefsize(int argc, const char **argv, void *UNUSED(data))
00437 {
00438     int stax, stay, sizx, sizy;
00439 
00440     if (argc < 5) {
00441         fprintf (stderr, "-p requires four arguments\n");
00442         exit(1);
00443     }
00444 
00445     stax= atoi(argv[1]);
00446     stay= atoi(argv[2]);
00447     sizx= atoi(argv[3]);
00448     sizy= atoi(argv[4]);
00449 
00450     WM_setprefsize(stax, stay, sizx, sizy);
00451 
00452     return 4;
00453 }
00454 
00455 static int with_borders(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
00456 {
00457     WM_setinitialstate_normal();
00458     return 0;
00459 }
00460 
00461 static int without_borders(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
00462 {
00463     WM_setinitialstate_fullscreen();
00464     return 0;
00465 }
00466 
00467 extern int wm_start_with_console; // blender/windowmanager/intern/wm_init_exit.c
00468 static int start_with_console(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
00469 {
00470     wm_start_with_console = 1;
00471     return 0;
00472 }
00473 
00474 static int register_extension(int UNUSED(argc), const char **UNUSED(argv), void *data)
00475 {
00476 #ifdef WIN32
00477     if (data)
00478         G.background = 1;
00479     RegisterBlendExtension();
00480 #else
00481     (void)data; /* unused */
00482 #endif
00483     return 0;
00484 }
00485 
00486 static int no_joystick(int UNUSED(argc), const char **UNUSED(argv), void *data)
00487 {
00488 #ifndef WITH_GAMEENGINE
00489     (void)data;
00490 #else
00491     SYS_SystemHandle *syshandle = data;
00492 
00497     SYS_WriteCommandLineInt(*syshandle, "nojoystick",1);
00498     if (G.f & G_DEBUG) printf("disabling nojoystick\n");
00499 #endif
00500 
00501     return 0;
00502 }
00503 
00504 static int no_glsl(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
00505 {
00506     GPU_extensions_disable();
00507     return 0;
00508 }
00509 
00510 static int no_audio(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
00511 {
00512     sound_force_device(0);
00513     return 0;
00514 }
00515 
00516 static int set_audio(int argc, const char **argv, void *UNUSED(data))
00517 {
00518     if (argc < 1) {
00519         fprintf(stderr, "-setaudio require one argument\n");
00520         exit(1);
00521     }
00522 
00523     sound_force_device(sound_define_from_str(argv[1]));
00524     return 1;
00525 }
00526 
00527 static int set_output(int argc, const char **argv, void *data)
00528 {
00529     bContext *C = data;
00530     if (argc >= 1){
00531         Scene *scene= CTX_data_scene(C);
00532         if (scene) {
00533             BLI_strncpy(scene->r.pic, argv[1], sizeof(scene->r.pic));
00534         } else {
00535             printf("\nError: no blend loaded. cannot use '-o / --render-output'.\n");
00536         }
00537         return 1;
00538     } else {
00539         printf("\nError: you must specify a path after '-o  / --render-output'.\n");
00540         return 0;
00541     }
00542 }
00543 
00544 static int set_engine(int argc, const char **argv, void *data)
00545 {
00546     bContext *C = data;
00547     if (argc >= 2) {
00548         if (!strcmp(argv[1], "help")) {
00549             RenderEngineType *type = NULL;
00550             printf("Blender Engine Listing:\n");
00551             for( type = R_engines.first; type; type = type->next ) {
00552                 printf("\t%s\n", type->idname);
00553             }
00554             exit(0);
00555         }
00556         else {
00557             Scene *scene= CTX_data_scene(C);
00558             if (scene) {
00559                 RenderData *rd = &scene->r;
00560 
00561                 if(BLI_findstring(&R_engines, argv[1], offsetof(RenderEngineType, idname))) {
00562                     BLI_strncpy_utf8(rd->engine, argv[1], sizeof(rd->engine));
00563                 }
00564             }
00565             else {
00566                 printf("\nError: no blend loaded. order the arguments so '-E  / --engine ' is after a blend is loaded.\n");
00567             }
00568         }
00569 
00570         return 1;
00571     }
00572     else
00573     {
00574         printf("\nEngine not specified, give 'help' for a list of available engines.\n");
00575         return 0;
00576     }
00577 }
00578 
00579 static int set_image_type(int argc, const char **argv, void *data)
00580 {
00581     bContext *C = data;
00582     if (argc >= 1){
00583         const char *imtype = argv[1];
00584         Scene *scene= CTX_data_scene(C);
00585         if (scene) {
00586             const char imtype_new= BKE_imtype_from_arg(imtype);
00587 
00588             if (imtype_new == R_IMF_IMTYPE_INVALID) {
00589                 printf("\nError: Format from '-F / --render-format' not known or not compiled in this release.\n");
00590             }
00591             else {
00592                 scene->r.im_format.imtype= imtype_new;
00593             }
00594         }
00595         else {
00596             printf("\nError: no blend loaded. order the arguments so '-F  / --render-format' is after the blend is loaded.\n");
00597         }
00598         return 1;
00599     } else {
00600         printf("\nError: you must specify a format after '-F  / --render-foramt'.\n");
00601         return 0;
00602     }
00603 }
00604 
00605 static int set_threads(int argc, const char **argv, void *UNUSED(data))
00606 {
00607     if (argc >= 1) {
00608         if(G.background) {
00609             RE_set_max_threads(atoi(argv[1]));
00610         } else {
00611             printf("Warning: threads can only be set in background mode\n");
00612         }
00613         return 1;
00614     } else {
00615         printf("\nError: you must specify a number of threads between 0 and 8 '-t  / --threads'.\n");
00616         return 0;
00617     }
00618 }
00619 
00620 static int set_extension(int argc, const char **argv, void *data)
00621 {
00622     bContext *C = data;
00623     if (argc >= 1) {
00624         Scene *scene= CTX_data_scene(C);
00625         if (scene) {
00626             if (argv[1][0] == '0') {
00627                 scene->r.scemode &= ~R_EXTENSION;
00628             } else if (argv[1][0] == '1') {
00629                 scene->r.scemode |= R_EXTENSION;
00630             } else {
00631                 printf("\nError: Use '-x 1 / -x 0' To set the extension option or '--use-extension'\n");
00632             }
00633         } else {
00634             printf("\nError: no blend loaded. order the arguments so '-o ' is after '-x '.\n");
00635         }
00636         return 1;
00637     } else {
00638         printf("\nError: you must specify a path after '- '.\n");
00639         return 0;
00640     }
00641 }
00642 
00643 static int set_ge_parameters(int argc, const char **argv, void *data)
00644 {
00645     int a = 0;
00646 #ifdef WITH_GAMEENGINE
00647     SYS_SystemHandle syshandle = *(SYS_SystemHandle*)data;
00648 #else
00649     (void)data;
00650 #endif
00651 
00661     if(argc >= 1)
00662     {
00663         const char *paramname = argv[a];
00664         /* check for single value versus assignment */
00665         if (a+1 < argc && (*(argv[a+1]) == '='))
00666         {
00667             a++;
00668             if (a+1 < argc)
00669             {
00670                 a++;
00671                 /* assignment */
00672 #ifdef WITH_GAMEENGINE
00673                 SYS_WriteCommandLineString(syshandle,paramname,argv[a]);
00674 #endif
00675             }  else
00676             {
00677                 printf("error: argument assignment (%s) without value.\n",paramname);
00678                 return 0;
00679             }
00680             /* name arg eaten */
00681 
00682         } else {
00683 #ifdef WITH_GAMEENGINE
00684             SYS_WriteCommandLineInt(syshandle,argv[a],1);
00685 #endif
00686             /* doMipMap */
00687             if (!strcmp(argv[a],"nomipmap"))
00688             {
00689                 GPU_set_mipmap(0); //doMipMap = 0;
00690             }
00691             /* linearMipMap */
00692             if (!strcmp(argv[a],"linearmipmap"))
00693             {
00694                 GPU_set_linear_mipmap(1); //linearMipMap = 1;
00695             }
00696 
00697 
00698         } /* if (*(argv[a+1]) == '=') */
00699     }
00700 
00701     return a;
00702 }
00703 
00704 static int render_frame(int argc, const char **argv, void *data)
00705 {
00706     bContext *C = data;
00707     Scene *scene= CTX_data_scene(C);
00708     if (scene) {
00709         Main *bmain= CTX_data_main(C);
00710 
00711         if (argc > 1) {
00712             Render *re = RE_NewRender(scene->id.name);
00713             int frame;
00714             ReportList reports;
00715 
00716             switch(*argv[1]) {
00717             case '+':
00718                 frame= scene->r.sfra + atoi(argv[1]+1);
00719                 break;
00720             case '-':
00721                 frame= (scene->r.efra - atoi(argv[1]+1)) + 1;
00722                 break;
00723             default:
00724                 frame= atoi(argv[1]);
00725                 break;
00726             }
00727 
00728             BKE_reports_init(&reports, RPT_PRINT);
00729 
00730             frame = MIN2(MAXFRAME, MAX2(MINAFRAME, frame));
00731 
00732             RE_SetReports(re, &reports);
00733             RE_BlenderAnim(re, bmain, scene, NULL, scene->lay, frame, frame, scene->r.frame_step);
00734             RE_SetReports(re, NULL);
00735             return 1;
00736         } else {
00737             printf("\nError: frame number must follow '-f / --render-frame'.\n");
00738             return 0;
00739         }
00740     } else {
00741         printf("\nError: no blend loaded. cannot use '-f / --render-frame'.\n");
00742         return 0;
00743     }
00744 }
00745 
00746 static int render_animation(int UNUSED(argc), const char **UNUSED(argv), void *data)
00747 {
00748     bContext *C = data;
00749     Scene *scene= CTX_data_scene(C);
00750     if (scene) {
00751         Main *bmain= CTX_data_main(C);
00752         Render *re= RE_NewRender(scene->id.name);
00753         ReportList reports;
00754         BKE_reports_init(&reports, RPT_PRINT);
00755         RE_SetReports(re, &reports);
00756         RE_BlenderAnim(re, bmain, scene, NULL, scene->lay, scene->r.sfra, scene->r.efra, scene->r.frame_step);
00757         RE_SetReports(re, NULL);
00758     } else {
00759         printf("\nError: no blend loaded. cannot use '-a'.\n");
00760     }
00761     return 0;
00762 }
00763 
00764 static int set_scene(int argc, const char **argv, void *data)
00765 {
00766     if(argc > 1) {
00767         bContext *C= data;
00768         Scene *scene= set_scene_name(CTX_data_main(C), argv[1]);
00769         if(scene) {
00770             CTX_data_scene_set(C, scene);
00771         }
00772         return 1;
00773     } else {
00774         printf("\nError: Scene name must follow '-S / --scene'.\n");
00775         return 0;
00776     }
00777 }
00778 
00779 static int set_start_frame(int argc, const char **argv, void *data)
00780 {
00781     bContext *C = data;
00782     Scene *scene= CTX_data_scene(C);
00783     if (scene) {
00784         if (argc > 1) {
00785             int frame = atoi(argv[1]);
00786             (scene->r.sfra) = CLAMPIS(frame, MINFRAME, MAXFRAME);
00787             return 1;
00788         } else {
00789             printf("\nError: frame number must follow '-s / --frame-start'.\n");
00790             return 0;
00791         }
00792     } else {
00793         printf("\nError: no blend loaded. cannot use '-s / --frame-start'.\n");
00794         return 0;
00795     }
00796 }
00797 
00798 static int set_end_frame(int argc, const char **argv, void *data)
00799 {
00800     bContext *C = data;
00801     Scene *scene= CTX_data_scene(C);
00802     if (scene) {
00803         if (argc > 1) {
00804             int frame = atoi(argv[1]);
00805             (scene->r.efra) = CLAMPIS(frame, MINFRAME, MAXFRAME);
00806             return 1;
00807         } else {
00808             printf("\nError: frame number must follow '-e / --frame-end'.\n");
00809             return 0;
00810         }
00811     } else {
00812         printf("\nError: no blend loaded. cannot use '-e / --frame-end'.\n");
00813         return 0;
00814     }
00815 }
00816 
00817 static int set_skip_frame(int argc, const char **argv, void *data)
00818 {
00819     bContext *C = data;
00820     Scene *scene= CTX_data_scene(C);
00821     if (scene) {
00822         if (argc > 1) {
00823             int frame = atoi(argv[1]);
00824             (scene->r.frame_step) = CLAMPIS(frame, 1, MAXFRAME);
00825             return 1;
00826         } else {
00827             printf("\nError: number of frames to step must follow '-j / --frame-jump'.\n");
00828             return 0;
00829         }
00830     } else {
00831         printf("\nError: no blend loaded. cannot use '-j / --frame-jump'.\n");
00832         return 0;
00833     }
00834 }
00835 
00836 /* macro for ugly context setup/reset */
00837 #ifdef WITH_PYTHON
00838 #define BPY_CTX_SETUP(_cmd)                                                   \
00839 {                                                                             \
00840     wmWindowManager *wm= CTX_wm_manager(C);                                   \
00841     wmWindow *prevwin= CTX_wm_window(C);                                      \
00842     Scene *prevscene= CTX_data_scene(C);                                      \
00843     if(wm->windows.first) {                                                   \
00844         CTX_wm_window_set(C, wm->windows.first);                              \
00845         _cmd;                                                                 \
00846         CTX_wm_window_set(C, prevwin);                                        \
00847     }                                                                         \
00848     else {                                                                    \
00849         fprintf(stderr, "Python script \"%s\" "                               \
00850                         "running with missing context data.\n", argv[1]);     \
00851         _cmd;                                                                 \
00852     }                                                                         \
00853     CTX_data_scene_set(C, prevscene);                                         \
00854 }                                                                             \
00855 
00856 #endif /* WITH_PYTHON */
00857 
00858 static int run_python(int argc, const char **argv, void *data)
00859 {
00860 #ifdef WITH_PYTHON
00861     bContext *C = data;
00862 
00863     /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */
00864     if (argc > 1) {
00865         /* Make the path absolute because its needed for relative linked blends to be found */
00866         char filename[FILE_MAX];
00867         BLI_strncpy(filename, argv[1], sizeof(filename));
00868         BLI_path_cwd(filename);
00869 
00870         BPY_CTX_SETUP(BPY_filepath_exec(C, filename, NULL))
00871 
00872         return 1;
00873     } else {
00874         printf("\nError: you must specify a Python script after '-P / --python'.\n");
00875         return 0;
00876     }
00877 #else
00878     (void)argc; (void)argv; (void)data; /* unused */
00879     printf("This blender was built without python support\n");
00880     return 0;
00881 #endif /* WITH_PYTHON */
00882 }
00883 
00884 static int run_python_console(int UNUSED(argc), const char **argv, void *data)
00885 {
00886 #ifdef WITH_PYTHON
00887     bContext *C = data;
00888 
00889     BPY_CTX_SETUP(BPY_string_exec(C, "__import__('code').interact()"))
00890 
00891     return 0;
00892 #else
00893     (void)argv; (void)data; /* unused */
00894     printf("This blender was built without python support\n");
00895     return 0;
00896 #endif /* WITH_PYTHON */
00897 }
00898 
00899 static int set_addons(int argc, const char **argv, void *data)
00900 {
00901     /* workaround for scripts not getting a bpy.context.scene, causes internal errors elsewhere */
00902     if (argc > 1) {
00903 #ifdef WITH_PYTHON
00904         const int slen= strlen(argv[1]) + 128;
00905         char *str= malloc(slen);
00906         bContext *C= data;
00907         BLI_snprintf(str, slen, "[__import__('addon_utils').enable(i, default_set=False) for i in '%s'.split(',')]", argv[1]);
00908         BPY_CTX_SETUP(BPY_string_exec(C, str));
00909         free(str);
00910 #else
00911         (void)argv; (void)data; /* unused */
00912 #endif /* WITH_PYTHON */
00913         return 1;
00914     }
00915     else {
00916         printf("\nError: you must specify a comma separated list after '--addons'.\n");
00917         return 0;
00918     }
00919 }
00920 
00921 
00922 static int load_file(int UNUSED(argc), const char **argv, void *data)
00923 {
00924     bContext *C = data;
00925 
00926     /* Make the path absolute because its needed for relative linked blends to be found */
00927     char filename[FILE_MAX];
00928 
00929     /* note, we could skip these, but so far we always tried to load these files */
00930     if (argv[0][0] == '-') {
00931         fprintf(stderr, "unknown argument, loading as file: %s\n", argv[0]);
00932     }
00933 
00934     BLI_strncpy(filename, argv[0], sizeof(filename));
00935     BLI_path_cwd(filename);
00936 
00937     if (G.background) {
00938         int retval = BKE_read_file(C, filename, NULL);
00939 
00940         /*we successfully loaded a blend file, get sure that
00941         pointcache works */
00942         if (retval != BKE_READ_FILE_FAIL) {
00943             wmWindowManager *wm= CTX_wm_manager(C);
00944 
00945             /* special case, 2.4x files */
00946             if(wm==NULL && CTX_data_main(C)->wm.first==NULL) {
00947                 extern void wm_add_default(bContext *C);
00948 
00949                 /* wm_add_default() needs the screen to be set. */
00950                 CTX_wm_screen_set(C, CTX_data_main(C)->screen.first);
00951                 wm_add_default(C);
00952             }
00953 
00954             CTX_wm_manager_set(C, NULL); /* remove wm to force check */
00955             WM_check(C);
00956             G.relbase_valid = 1;
00957             if (CTX_wm_manager(C) == NULL) CTX_wm_manager_set(C, wm); /* reset wm */
00958 
00959             DAG_on_visible_update(CTX_data_main(C), TRUE);
00960         }
00961         else {
00962             /* failed to load file, stop processing arguments */
00963             return -1;
00964         }
00965 
00966         /* WM_read_file() runs normally but since we're in background mode do here */
00967 #ifdef WITH_PYTHON
00968         /* run any texts that were loaded in and flagged as modules */
00969         BPY_driver_reset();
00970         BPY_app_handlers_reset(FALSE);
00971         BPY_modules_load_user(C);
00972 #endif
00973 
00974         /* happens for the UI on file reading too (huh? (ton))*/
00975     // XXX          BKE_reset_undo();
00976     //              BKE_write_undo("original"); /* save current state */
00977     } else {
00978         /* we are not running in background mode here, but start blender in UI mode with
00979            a file - this should do everything a 'load file' does */
00980         ReportList reports;
00981         BKE_reports_init(&reports, RPT_PRINT);
00982         WM_read_file(C, filename, &reports);
00983         BKE_reports_clear(&reports);
00984     }
00985 
00986     G.file_loaded = 1;
00987 
00988     return 0;
00989 }
00990 
00991 static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
00992 {
00993     static char output_doc[] = "<path>"
00994         "\n\tSet the render path and file name."
00995         "\n\tUse // at the start of the path to"
00996         "\n\t\trender relative to the blend file."
00997         "\n\tThe # characters are replaced by the frame number, and used to define zero padding."
00998         "\n\t\tani_##_test.png becomes ani_01_test.png"
00999         "\n\t\ttest-######.png becomes test-000001.png"
01000         "\n\t\tWhen the filename does not contain #, The suffix #### is added to the filename"
01001         "\n\tThe frame number will be added at the end of the filename."
01002         "\n\t\teg: blender -b foobar.blend -o //render_ -F PNG -x 1 -a"
01003         "\n\t\t//render_ becomes //render_####, writing frames as //render_0001.png//";
01004 
01005     static char format_doc[] = "<format>"
01006         "\n\tSet the render format, Valid options are..."
01007         "\n\t\tTGA IRIS JPEG MOVIE IRIZ RAWTGA"
01008         "\n\t\tAVIRAW AVIJPEG PNG BMP FRAMESERVER"
01009         "\n\t(formats that can be compiled into blender, not available on all systems)"
01010         "\n\t\tHDR TIFF EXR MULTILAYER MPEG AVICODEC QUICKTIME CINEON DPX DDS";
01011 
01012     static char playback_doc[] = "<options> <file(s)>"
01013         "\n\tPlayback <file(s)>, only operates this way when not running in background."
01014         "\n\t\t-p <sx> <sy>\tOpen with lower left corner at <sx>, <sy>"
01015         "\n\t\t-m\t\tRead from disk (Don't buffer)"
01016         "\n\t\t-f <fps> <fps-base>\t\tSpecify FPS to start with"
01017         "\n\t\t-j <frame>\tSet frame step to <frame>";
01018 
01019     static char game_doc[] = "Game Engine specific options"
01020         "\n\t-g fixedtime\t\tRun on 50 hertz without dropping frames"
01021         "\n\t-g vertexarrays\t\tUse Vertex Arrays for rendering (usually faster)"
01022         "\n\t-g nomipmap\t\tNo Texture Mipmapping"
01023         "\n\t-g linearmipmap\t\tLinear Texture Mipmapping instead of Nearest (default)";
01024 
01025     static char debug_doc[] = "\n\tTurn debugging on\n"
01026         "\n\t* Prints every operator call and their arguments"
01027         "\n\t* Disables mouse grab (to interact with a debugger in some cases)"
01028         "\n\t* Keeps python sys.stdin rather than setting it to None";
01029 
01030     //BLI_argsAdd(ba, pass, short_arg, long_arg, doc, cb, C);
01031 
01032     /* end argument processing after -- */
01033     BLI_argsAdd(ba, -1, "--", NULL, "\n\tEnds option processing, following arguments passed unchanged. Access via python's sys.argv", end_arguments, NULL);
01034 
01035     /* first pass: background mode, disable python and commands that exit after usage */
01036     BLI_argsAdd(ba, 1, "-h", "--help", "\n\tPrint this help text and exit", print_help, ba);
01037     /* Windows only */
01038     BLI_argsAdd(ba, 1, "/?", NULL, "\n\tPrint this help text and exit (windows only)", print_help, ba);
01039 
01040     BLI_argsAdd(ba, 1, "-v", "--version", "\n\tPrint Blender version and exit", print_version, NULL);
01041     
01042     /* only to give help message */
01043 #ifndef WITH_PYTHON_SECURITY /* default */
01044 #  define   PY_ENABLE_AUTO ", (default)"
01045 #  define   PY_DISABLE_AUTO ""
01046 #else
01047 #  define   PY_ENABLE_AUTO ""
01048 #  define   PY_DISABLE_AUTO ", (compiled as non-standard default)"
01049 #endif
01050 
01051     BLI_argsAdd(ba, 1, "-y", "--enable-autoexec", "\n\tEnable automatic python script execution" PY_ENABLE_AUTO, enable_python, NULL);
01052     BLI_argsAdd(ba, 1, "-Y", "--disable-autoexec", "\n\tDisable automatic python script execution (pydrivers, pyconstraints, pynodes)" PY_DISABLE_AUTO, disable_python, NULL);
01053 
01054 #undef PY_ENABLE_AUTO
01055 #undef PY_DISABLE_AUTO
01056     
01057     BLI_argsAdd(ba, 1, "-b", "--background", "<file>\n\tLoad <file> in background (often used for UI-less rendering)", background_mode, NULL);
01058 
01059     BLI_argsAdd(ba, 1, "-a", NULL, playback_doc, playback_mode, NULL);
01060 
01061     BLI_argsAdd(ba, 1, "-d", "--debug", debug_doc, debug_mode, ba);
01062     BLI_argsAdd(ba, 1, NULL, "--debug-fpe", "\n\tEnable floating point exceptions", set_fpe, NULL);
01063 
01064     BLI_argsAdd(ba, 1, NULL, "--factory-startup", "\n\tSkip reading the "STRINGIFY(BLENDER_STARTUP_FILE)" in the users home directory", set_factory_startup, NULL);
01065 
01066     /* TODO, add user env vars? */
01067     BLI_argsAdd(ba, 1, NULL, "--env-system-datafiles",  "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_DATAFILES)" environment variable", set_env, NULL);
01068     BLI_argsAdd(ba, 1, NULL, "--env-system-scripts",    "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_SCRIPTS)" environment variable", set_env, NULL);
01069     BLI_argsAdd(ba, 1, NULL, "--env-system-plugins",    "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_PLUGINS)" environment variable", set_env, NULL);
01070     BLI_argsAdd(ba, 1, NULL, "--env-system-python",     "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_PYTHON)" environment variable", set_env, NULL);
01071 
01072     /* second pass: custom window stuff */
01073     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);
01074     BLI_argsAdd(ba, 2, "-w", "--window-border", "\n\tForce opening with borders (default)", with_borders, NULL);
01075     BLI_argsAdd(ba, 2, "-W", "--window-borderless", "\n\tForce opening without borders", without_borders, NULL);
01076     BLI_argsAdd(ba, 2, "-con", "--start-console", "\n\tStart with the console window open (ignored if -b is set)", start_with_console, NULL);
01077     BLI_argsAdd(ba, 2, "-R", NULL, "\n\tRegister .blend extension, then exit (Windows only)", register_extension, NULL);
01078     BLI_argsAdd(ba, 2, "-r", NULL, "\n\tSilently register .blend extension, then exit (Windows only)", register_extension, ba);
01079 
01080     /* third pass: disabling things and forcing settings */
01081     BLI_argsAddCase(ba, 3, "-nojoystick", 1, NULL, 0, "\n\tDisable joystick support", no_joystick, syshandle);
01082     BLI_argsAddCase(ba, 3, "-noglsl", 1, NULL, 0, "\n\tDisable GLSL shading", no_glsl, NULL);
01083     BLI_argsAddCase(ba, 3, "-noaudio", 1, NULL, 0, "\n\tForce sound system to None", no_audio, NULL);
01084     BLI_argsAddCase(ba, 3, "-setaudio", 1, NULL, 0, "\n\tForce sound system to a specific device\n\tNULL SDL OPENAL JACK", set_audio, NULL);
01085 
01086     /* fourth pass: processing arguments */
01087     BLI_argsAdd(ba, 4, "-g", NULL, game_doc, set_ge_parameters, syshandle);
01088     BLI_argsAdd(ba, 4, "-f", "--render-frame", "<frame>\n\tRender frame <frame> and save it.\n\t+<frame> start frame relative, -<frame> end frame relative.", render_frame, C);
01089     BLI_argsAdd(ba, 4, "-a", "--render-anim", "\n\tRender frames from start to end (inclusive)", render_animation, C);
01090     BLI_argsAdd(ba, 4, "-S", "--scene", "<name>\n\tSet the active scene <name> for rendering", set_scene, C);
01091     BLI_argsAdd(ba, 4, "-s", "--frame-start", "<frame>\n\tSet start to frame <frame> (use before the -a argument)", set_start_frame, C);
01092     BLI_argsAdd(ba, 4, "-e", "--frame-end", "<frame>\n\tSet end to frame <frame> (use before the -a argument)", set_end_frame, C);
01093     BLI_argsAdd(ba, 4, "-j", "--frame-jump", "<frames>\n\tSet number of frames to step forward after each rendered frame", set_skip_frame, C);
01094     BLI_argsAdd(ba, 4, "-P", "--python", "<filename>\n\tRun the given Python script (filename or Blender Text)", run_python, C);
01095     BLI_argsAdd(ba, 4, NULL, "--python-console", "\n\tRun blender with an interactive console", run_python_console, C);
01096     BLI_argsAdd(ba, 4, NULL, "--addons", "\n\tComma separated list of addons (no spaces)", set_addons, C);
01097 
01098     BLI_argsAdd(ba, 4, "-o", "--render-output", output_doc, set_output, C);
01099     BLI_argsAdd(ba, 4, "-E", "--engine", "<engine>\n\tSpecify the render engine\n\tuse -E help to list available engines", set_engine, C);
01100 
01101     BLI_argsAdd(ba, 4, "-F", "--render-format", format_doc, set_image_type, C);
01102     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);
01103     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);
01104 
01105 }
01106 
01107 #ifdef WITH_PYTHON_MODULE
01108 /* allow python module to call main */
01109 #define main main_python_enter
01110 static void *evil_C= NULL;
01111 
01112 #ifdef __APPLE__
01113 /* environ is not available in mac shared libraries */
01114 #include <crt_externs.h>
01115 char **environ = NULL;
01116 #endif
01117 
01118 #endif
01119 
01120 int main(int argc, const char **argv)
01121 {
01122     SYS_SystemHandle syshandle;
01123     bContext *C= CTX_create();
01124     bArgs *ba;
01125 
01126 #ifdef WITH_PYTHON_MODULE
01127 #ifdef __APPLE__
01128     environ = *_NSGetEnviron();
01129 #endif
01130 
01131 #undef main
01132     evil_C= C;
01133 #endif
01134 
01135 #ifdef WITH_BINRELOC
01136     br_init( NULL );
01137 #endif
01138 
01139 #ifdef WITH_LIBMV
01140     libmv_initLogging(argv[0]);
01141 #endif
01142 
01143     setCallbacks();
01144 #if defined(__APPLE__) && !defined(WITH_PYTHON_MODULE)
01145         /* patch to ignore argument finder gives us (pid?) */
01146     if (argc==2 && strncmp(argv[1], "-psn_", 5)==0) {
01147         extern int GHOST_HACK_getFirstFile(char buf[]);
01148         static char firstfilebuf[512];
01149 
01150         argc= 1;
01151 
01152         if (GHOST_HACK_getFirstFile(firstfilebuf)) {
01153             argc= 2;
01154             argv[1]= firstfilebuf;
01155         }
01156     }
01157 
01158 #endif
01159 
01160 #ifdef __FreeBSD__
01161     fpsetmask(0);
01162 #endif
01163 
01164     // initialize path to executable
01165     BLI_init_program_path(argv[0]);
01166 
01167     BLI_threadapi_init();
01168 
01169     RNA_init();
01170     RE_engines_init();
01171 
01172         /* Hack - force inclusion of the plugin api functions,
01173          * see blenpluginapi:pluginapi.c
01174          */
01175     pluginapi_force_ref();
01176 
01177     init_nodesystem();
01178     
01179     initglobals();  /* blender.c */
01180 
01181     IMB_init();
01182 
01183     BLI_cb_init();
01184 
01185 #ifdef WITH_GAMEENGINE
01186     syshandle = SYS_GetSystem();
01187 #else
01188     syshandle= 0;
01189 #endif
01190 
01191     /* first test for background */
01192     ba = BLI_argsInit(argc, argv); /* skip binary path */
01193     setupArguments(C, ba, &syshandle);
01194 
01195     BLI_argsParse(ba, 1, NULL, NULL);
01196 
01197 #if defined(WITH_PYTHON_MODULE) || defined(WITH_HEADLESS)
01198     G.background= 1; /* python module mode ALWAYS runs in background mode (for now) */
01199 #else
01200     /* for all platforms, even windos has it! */
01201     if(G.background) signal(SIGINT, blender_esc);   /* ctrl c out bg render */
01202 #endif
01203 
01204     /* background render uses this font too */
01205     BKE_font_register_builtin(datatoc_Bfont, datatoc_Bfont_size);
01206 
01207     /* Initialiaze ffmpeg if built in, also needed for bg mode if videos are
01208        rendered via ffmpeg */
01209     sound_init_once();
01210     
01211     init_def_material();
01212 
01213     if(G.background==0) {
01214         BLI_argsParse(ba, 2, NULL, NULL);
01215         BLI_argsParse(ba, 3, NULL, NULL);
01216 
01217         WM_init(C, argc, argv);
01218 
01219         /* this is properly initialized with user defs, but this is default */
01220         /* call after loading the startup.blend so we can read U.tempdir */
01221         BLI_init_temporary_dir(U.tempdir);
01222 
01223 #ifdef WITH_SDL
01224     BLI_setenv("SDL_VIDEODRIVER", "dummy");
01225 #endif
01226     }
01227     else {
01228         BLI_argsParse(ba, 3, NULL, NULL);
01229 
01230         WM_init(C, argc, argv);
01231 
01232         /* don't use user preferences temp dir */
01233         BLI_init_temporary_dir(NULL);
01234     }
01235 #ifdef WITH_PYTHON
01236 
01245     // TODO - U.pythondir
01246 #else
01247     printf("\n* WARNING * - Blender compiled without Python!\nthis is not intended for typical usage\n\n");
01248 #endif
01249     
01250     CTX_py_init_set(C, 1);
01251     WM_keymap_init(C);
01252 
01253     /* OK we are ready for it */
01254     BLI_argsParse(ba, 4, load_file, C);
01255 
01256     BLI_argsFree(ba);
01257 
01258 #ifdef WITH_PYTHON_MODULE
01259     return 0; /* keep blender in background mode running */
01260 #endif
01261 
01262     if(G.background) {
01263         /* actually incorrect, but works for now (ton) */
01264         WM_exit(C);
01265     }
01266 
01267     else {
01268         if((G.fileflags & G_FILE_AUTOPLAY) && (G.f & G_SCRIPT_AUTOEXEC))
01269         {
01270             if(WM_init_game(C))
01271                 return 0;
01272         }
01273         else if(!G.file_loaded)
01274             WM_init_splash(C);
01275     }
01276 
01277     WM_main(C);
01278 
01279 
01280     /*XXX if (scr_init==0) {
01281         main_init_screen();
01282     }
01283     
01284     screenmain();*/ /* main display loop */
01285 
01286     return 0;
01287 } /* end of int main(argc,argv) */
01288 
01289 #ifdef WITH_PYTHON_MODULE
01290 void main_python_exit(void)
01291 {
01292     WM_exit((bContext *)evil_C);
01293     evil_C= NULL;
01294 }
01295 #endif
01296 
01297 static void error_cb(const char *err)
01298 {
01299     
01300     printf("%s\n", err);    /* XXX do this in WM too */
01301 }
01302 
01303 static void mem_error_cb(const char *errorStr)
01304 {
01305     fputs(errorStr, stderr);
01306     fflush(stderr);
01307 }
01308 
01309 static void setCallbacks(void)
01310 {
01311     /* Error output from the alloc routines: */
01312     MEM_set_error_callback(mem_error_cb);
01313 
01314 
01315     /* BLI_blenlib: */
01316 
01317     BLI_setErrorCallBack(error_cb); /* */
01318 // XXX  BLI_setInterruptCallBack(blender_test_break);
01319 
01320 }