2.5 audio cleanup:
[blender.git] / source / creator / creator.c
index 5c10b0c346cf44fec7ffc3f3f86a2452d02fa6e4..8896673b6112767095724ec0894ef3a7baa201e3 100644 (file)
@@ -61,6 +61,7 @@
 #include "BKE_packedFile.h"
 #include "BKE_scene.h"
 #include "BKE_node.h"
+#include "BKE_report.h"
 
 #include "IMB_imbuf.h" // for quicktime_init
 
 #include "RE_pipeline.h"
 
 //XXX #include "playanim_ext.h"
-#include "wm_event_types.h"
-//XXX #include "nla.h"
-//XXX #include "datatoc.h"
+#include "ED_datafiles.h"
+#include "UI_interface.h"
 
 #include "WM_api.h"
 
+#include "RNA_define.h"
+
 #include "GPU_draw.h"
 #include "GPU_extensions.h"
 
@@ -199,17 +201,15 @@ static void print_help(void)
        printf ("\nGame Engine specific options:\n");
        printf ("  -g fixedtime\t\tRun on 50 hertz without dropping frames\n");
        printf ("  -g vertexarrays\tUse Vertex Arrays for rendering (usually faster)\n");
-       printf ("  -g noaudio\t\tNo audio in Game Engine\n");
        printf ("  -g nomipmap\t\tNo Texture Mipmapping\n");
        printf ("  -g linearmipmap\tLinear Texture Mipmapping instead of Nearest (default)\n");
 
        printf ("\nMisc options:\n");
        printf ("  -d\t\tTurn debugging on\n");
-       printf ("  -noaudio\tDisable audio on systems that support audio\n");
        printf ("  -nojoystick\tDisable joystick support\n");
        printf ("  -noglsl\tDisable GLSL shading\n");
        printf ("  -h\t\tPrint this help text\n");
-       printf ("  -y\t\tDisable automatic python script execution (scriptlinks, pydrivers, pyconstraints, pynodes)\n");
+       printf ("  -y\t\tDisable automatic python script execution (pydrivers, pyconstraints, pynodes)\n");
        printf ("  -P <filename>\tRun the given Python script (filename or Blender Text)\n");
 #ifdef WIN32
        printf ("  -R\t\tRegister .blend extension\n");
@@ -265,13 +265,6 @@ int main(int argc, char **argv)
        bContext *C= CTX_create();
        int a, i, stax, stay, sizx, sizy /*XXX, scr_init = 0*/;
 
-#if defined(WIN32) || defined (__linux__)
-       int audio = 1;
-#else
-       int audio = 0;
-#endif
-
-       
 #ifdef WITH_BINRELOC
        br_init( NULL );
 #endif
@@ -310,11 +303,14 @@ int main(int argc, char **argv)
 
        BLI_where_am_i(bprogname, argv[0]);
        
+       RNA_init();
+       RE_engines_init();
+
                /* Hack - force inclusion of the plugin api functions,
                 * see blenpluginapi:pluginapi.c
                 */
        pluginapi_force_ref();
-       
+
        init_nodesystem();
        
        initglobals();  /* blender.c */
@@ -403,7 +399,7 @@ int main(int argc, char **argv)
        if(G.background) signal(SIGINT, blender_esc);   /* ctrl c out bg render */
        
        /* background render uses this font too */
-       //XXX BKE_font_register_builtin(datatoc_Bfont, datatoc_Bfont_size);
+       BKE_font_register_builtin(datatoc_Bfont, datatoc_Bfont_size);
        
        init_def_material();
 
@@ -439,7 +435,9 @@ int main(int argc, char **argv)
                                                printf("argv[%d] = %s\n", i, argv[i]);
                                        }
                                        break;
-            
+                               case 'E':
+                                       G.f |= G_SWAP_EXCHANGE;
+                                       break;
                                case 'w':
                                        /* with borders XXX OLD CRUFT!*/
                                        break;
@@ -455,16 +453,6 @@ int main(int argc, char **argv)
                                        break;
                                case 'n':
                                case 'N':
-                                       if (BLI_strcasecmp(argv[a], "-noaudio") == 0|| BLI_strcasecmp(argv[a], "-nosound") == 0) {
-                                               /**
-                                                       notify the gameengine that no audio is wanted, even if the user didn't give
-                                                       the flag -g noaudio.
-                                               */
-
-                                               SYS_WriteCommandLineInt(syshandle,"noaudio",1);
-                                               audio = 0;
-                                               if (G.f & G_DEBUG) printf("setting audio to: %d\n", audio);
-                                       }
                                        if (BLI_strcasecmp(argv[a], "-nojoystick") == 0) {
                                                /**
                                                        don't initialize joysticks if user doesn't want to use joysticks
@@ -483,11 +471,6 @@ int main(int argc, char **argv)
 #ifndef DISABLE_PYTHON         
                BPY_start_python(argc, argv);
 #endif         
-               /**
-                * NOTE: sound_init_audio() *must be* after start_python,
-                * at least on FreeBSD.
-                * added note (ton): i removed it altogether
-                */
 
                WM_init(C);
                
@@ -495,12 +478,11 @@ int main(int argc, char **argv)
                BLI_where_is_temp( btempdir, 1 ); /* call after loading the .B.blend so we can read U.tempdir */
 
 #ifndef DISABLE_SDL
+       BLI_setenv("SDL_VIDEODRIVER", "dummy");
 #ifdef __linux__
-               /* On linux the default SDL driver dma often would not play
-                * use alsa if none is set */
-               if ( getenv("SDL_AUDIODRIVER") == NULL) {
-                       setenv("SDL_AUDIODRIVER", "alsa", 1);
-               }
+       /* On linux the default SDL driver dma often would not play
+        * use alsa if none is set */
+       setenv("SDL_AUDIODRIVER", "alsa", 0);
 #endif
 #endif
        }
@@ -509,12 +491,6 @@ int main(int argc, char **argv)
                BPY_start_python(argc, argv);
 #endif         
                BLI_where_is_temp( btempdir, 0 ); /* call after loading the .B.blend so we can read U.tempdir */
-               
-               // (ton) Commented out. I have no idea whats thisfor... will mail around!
-               // SYS_WriteCommandLineInt(syshandle,"noaudio",1);
-        // audio = 0;
-        // sound_init_audio();
-        // if (G.f & G_DEBUG) printf("setting audio to: %d\n", audio);
        }
 #ifndef DISABLE_PYTHON
        /**
@@ -526,8 +502,13 @@ int main(int argc, char **argv)
         * on U.pythondir.
         */
        BPY_post_start_python();
+
+       BPY_run_ui_scripts(C, 0); /* dont need to reload the first time */
 #endif
        
+       CTX_py_init_set(C, 1);
+       WM_keymap_init(C); /* after BPY_run_ui_scripts() */
+
 #ifdef WITH_QUICKTIME
 
        quicktime_init();
@@ -608,35 +589,26 @@ int main(int argc, char **argv)
                                }
                        case 'f':
                                a++;
-                               if (G.scene) {
+                               if (CTX_data_scene(C)) {
+                                       Scene *scene= CTX_data_scene(C);
+                                       
                                        if (a < argc) {
-                                               int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a])));
-                                               Render *re= RE_NewRender(G.scene->id.name);
-#ifndef DISABLE_PYTHON
-                                               if (G.f & G_DOSCRIPTLINKS)
-                                                       BPY_do_all_scripts(SCRIPT_RENDER, 0);
-#endif
-                                               RE_BlenderAnim(re, G.scene, frame, frame, G.scene->frame_step);
-#ifndef DISABLE_PYTHON
-                                               BPY_do_all_scripts(SCRIPT_POSTRENDER, 0);
-#endif
+                                               int frame = atoi(argv[a]);
+                                               Render *re = RE_NewRender(scene->id.name);
+
+                                               frame = MIN2(MAXFRAME, MAX2(1, frame));
+                                               
+                                               RE_BlenderAnim(re, scene, frame, frame, scene->frame_step);
                                        }
                                } else {
                                        printf("\nError: no blend loaded. cannot use '-f'.\n");
                                }
                                break;
                        case 'a':
-                               if (G.scene) {
-                                       Render *re= RE_NewRender(G.scene->id.name);
-#ifndef DISABLE_PYTHON
-                                       if (G.f & G_DOSCRIPTLINKS)
-                                               BPY_do_all_scripts(SCRIPT_RENDER, 1);
-#endif
-                                       RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra, G.scene->frame_step);
-#ifndef DISABLE_PYTHON
-                                       if (G.f & G_DOSCRIPTLINKS)
-                                               BPY_do_all_scripts(SCRIPT_POSTRENDER, 1);
-#endif
+                               if (CTX_data_scene(C)) {
+                                       Scene *scene= CTX_data_scene(C);
+                                       Render *re= RE_NewRender(scene->id.name);
+                                       RE_BlenderAnim(re, scene, scene->r.sfra, scene->r.efra, scene->frame_step);
                                } else {
                                        printf("\nError: no blend loaded. cannot use '-a'.\n");
                                }
@@ -648,27 +620,36 @@ int main(int argc, char **argv)
                                break;
                        case 's':
                                a++;
-                               if(G.scene) {
-                                       int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a])));
-                                       if (a < argc) (G.scene->r.sfra) = frame;
+                               if (CTX_data_scene(C)) {
+                                       Scene *scene= CTX_data_scene(C);
+                                       if (a < argc) {
+                                               int frame = atoi(argv[a]);
+                                               (scene->r.sfra) = MIN2(MAXFRAME, MAX2(1, frame));
+                                       }
                                } else {
                                        printf("\nError: no blend loaded. cannot use '-s'.\n");
                                }
                                break;
                        case 'e':
                                a++;
-                               if(G.scene) {
-                                       int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a])));
-                                       if (a < argc) (G.scene->r.efra) = frame;
+                               if (CTX_data_scene(C)) {
+                                       Scene *scene= CTX_data_scene(C);
+                                       if (a < argc) {
+                                               int frame = atoi(argv[a]);
+                                               (scene->r.efra) = MIN2(MAXFRAME, MAX2(1, frame));
+                                       }
                                } else {
                                        printf("\nError: no blend loaded. cannot use '-e'.\n");
                                }
                                break;
                        case 'j':
                                a++;
-                               if(G.scene) {
-                                       int fstep= MIN2(MAXFRAME, MAX2(1, atoi(argv[a])));
-                                       if (a < argc) (G.scene->frame_step) = fstep;
+                               if (CTX_data_scene(C)) {
+                                       Scene *scene= CTX_data_scene(C);
+                                       if (a < argc) {
+                                               int frame = atoi(argv[a]);
+                                               (scene->frame_step) = MIN2(MAXFRAME, MAX2(1, frame));
+                                       }
                                } else {
                                        printf("\nError: no blend loaded. cannot use '-j'.\n");
                                }
@@ -679,7 +660,7 @@ int main(int argc, char **argv)
                                //XXX 
                                // FOR TESTING ONLY
                                a++;
-                               BPY_run_python_script(C, argv[a]);
+                               BPY_run_python_script(C, argv[a], NULL, NULL); // use reports?
 #if 0
                                a++;
                                if (a < argc) {
@@ -688,7 +669,7 @@ int main(int argc, char **argv)
                                                main_init_screen();
                                                scr_init = 1;
                                        }
-                                       BPY_run_python_script(C, argv[a]);
+                                       BPY_run_python_script(C, argv[a], NULL, NULL); // use reports?
                                }
                                else printf("\nError: you must specify a Python script after '-P '.\n");
 #endif
@@ -699,8 +680,9 @@ int main(int argc, char **argv)
                        case 'o':
                                a++;
                                if (a < argc){
-                                       if(G.scene) {
-                                               BLI_strncpy(G.scene->r.pic, argv[a], FILE_MAXDIR);
+                                       if (CTX_data_scene(C)) {
+                                               Scene *scene= CTX_data_scene(C);
+                                               BLI_strncpy(scene->r.pic, argv[a], FILE_MAXDIR);
                                        } else {
                                                printf("\nError: no blend loaded. cannot use '-o'.\n");
                                        }
@@ -711,35 +693,39 @@ int main(int argc, char **argv)
                        case 'F':
                                a++;
                                if (a < argc){
-                                       if(!G.scene) {
+                                       if (CTX_data_scene(C)==NULL) {
                                                printf("\nError: no blend loaded. order the arguments so '-F ' is after the blend is loaded.\n");
                                        } else {
-                                               if      (!strcmp(argv[a],"TGA")) G.scene->r.imtype = R_TARGA;
-                                               else if (!strcmp(argv[a],"IRIS")) G.scene->r.imtype = R_IRIS;
-                                               else if (!strcmp(argv[a],"HAMX")) G.scene->r.imtype = R_HAMX;
+                                               Scene *scene= CTX_data_scene(C);
+                                               if      (!strcmp(argv[a],"TGA")) scene->r.imtype = R_TARGA;
+                                               else if (!strcmp(argv[a],"IRIS")) scene->r.imtype = R_IRIS;
+                                               else if (!strcmp(argv[a],"HAMX")) scene->r.imtype = R_HAMX;
 #ifdef WITH_DDS
-                                               else if (!strcmp(argv[a],"DDS")) G.scene->r.imtype = R_DDS;
+                                               else if (!strcmp(argv[a],"DDS")) scene->r.imtype = R_DDS;
 #endif
-                                               else if (!strcmp(argv[a],"JPEG")) G.scene->r.imtype = R_JPEG90;
-                                               else if (!strcmp(argv[a],"MOVIE")) G.scene->r.imtype = R_MOVIE;
-                                               else if (!strcmp(argv[a],"IRIZ")) G.scene->r.imtype = R_IRIZ;
-                                               else if (!strcmp(argv[a],"RAWTGA")) G.scene->r.imtype = R_RAWTGA;
-                                               else if (!strcmp(argv[a],"AVIRAW")) G.scene->r.imtype = R_AVIRAW;
-                                               else if (!strcmp(argv[a],"AVIJPEG")) G.scene->r.imtype = R_AVIJPEG;
-                                               else if (!strcmp(argv[a],"PNG")) G.scene->r.imtype = R_PNG;
-                                               else if (!strcmp(argv[a],"AVICODEC")) G.scene->r.imtype = R_AVICODEC;
-                                               else if (!strcmp(argv[a],"QUICKTIME")) G.scene->r.imtype = R_QUICKTIME;
-                                               else if (!strcmp(argv[a],"BMP")) G.scene->r.imtype = R_BMP;
-                                               else if (!strcmp(argv[a],"HDR")) G.scene->r.imtype = R_RADHDR;
-                                               else if (!strcmp(argv[a],"TIFF")) G.scene->r.imtype = R_TIFF;
+                                               else if (!strcmp(argv[a],"JPEG")) scene->r.imtype = R_JPEG90;
+                                               else if (!strcmp(argv[a],"MOVIE")) scene->r.imtype = R_MOVIE;
+                                               else if (!strcmp(argv[a],"IRIZ")) scene->r.imtype = R_IRIZ;
+                                               else if (!strcmp(argv[a],"RAWTGA")) scene->r.imtype = R_RAWTGA;
+                                               else if (!strcmp(argv[a],"AVIRAW")) scene->r.imtype = R_AVIRAW;
+                                               else if (!strcmp(argv[a],"AVIJPEG")) scene->r.imtype = R_AVIJPEG;
+                                               else if (!strcmp(argv[a],"PNG")) scene->r.imtype = R_PNG;
+                                               else if (!strcmp(argv[a],"AVICODEC")) scene->r.imtype = R_AVICODEC;
+                                               else if (!strcmp(argv[a],"QUICKTIME")) scene->r.imtype = R_QUICKTIME;
+                                               else if (!strcmp(argv[a],"BMP")) scene->r.imtype = R_BMP;
+                                               else if (!strcmp(argv[a],"HDR")) scene->r.imtype = R_RADHDR;
+                                               else if (!strcmp(argv[a],"TIFF")) scene->r.imtype = R_TIFF;
 #ifdef WITH_OPENEXR
-                                               else if (!strcmp(argv[a],"EXR")) G.scene->r.imtype = R_OPENEXR;
-                                               else if (!strcmp(argv[a],"MULTILAYER")) G.scene->r.imtype = R_MULTILAYER;
+                                               else if (!strcmp(argv[a],"EXR")) scene->r.imtype = R_OPENEXR;
+                                               else if (!strcmp(argv[a],"MULTILAYER")) scene->r.imtype = R_MULTILAYER;
+#endif
+                                               else if (!strcmp(argv[a],"MPEG")) scene->r.imtype = R_FFMPEG;
+                                               else if (!strcmp(argv[a],"FRAMESERVER")) scene->r.imtype = R_FRAMESERVER;
+                                               else if (!strcmp(argv[a],"CINEON")) scene->r.imtype = R_CINEON;
+                                               else if (!strcmp(argv[a],"DPX")) scene->r.imtype = R_DPX;
+#if WITH_OPENJPEG
+                                               else if (!strcmp(argv[a],"JP2")) scene->r.imtype = R_JP2;
 #endif
-                                               else if (!strcmp(argv[a],"MPEG")) G.scene->r.imtype = R_FFMPEG;
-                                               else if (!strcmp(argv[a],"FRAMESERVER")) G.scene->r.imtype = R_FRAMESERVER;
-                                               else if (!strcmp(argv[a],"CINEON")) G.scene->r.imtype = R_CINEON;
-                                               else if (!strcmp(argv[a],"DPX")) G.scene->r.imtype = R_DPX;
                                                else printf("\nError: Format from '-F' not known or not compiled in this release.\n");
                                        }
                                } else {
@@ -749,20 +735,25 @@ int main(int argc, char **argv)
                                
                        case 't':
                                a++;
-                               if(G.background) {
-                                       RE_set_max_threads(atoi(argv[a]));
+                               if (a < argc) {
+                                       if(G.background) {
+                                               RE_set_max_threads(atoi(argv[a]));
+                                       } else {
+                                               printf("Warning: threads can only be set in background mode\n");
+                                       }
                                } else {
-                                       printf("Warning: threads can only be set in background mode\n");
+                                       printf("\nError: you must specify a number of threads between 0 and 8 '-t '.\n");
                                }
                                break;
                        case 'x': /* extension */
                                a++;
                                if (a < argc) {
-                                       if(G.scene) {
+                                       if (CTX_data_scene(C)) {
+                                               Scene *scene= CTX_data_scene(C);
                                                if (argv[a][0] == '0') {
-                                                       G.scene->r.scemode &= ~R_EXTENSION;
+                                                       scene->r.scemode &= ~R_EXTENSION;
                                                } else if (argv[a][0] == '1') {
-                                                       G.scene->r.scemode |= R_EXTENSION;
+                                                       scene->r.scemode |= R_EXTENSION;
                                                } else {
                                                        printf("\nError: Use '-x 1' or '-x 0' To set the extension option.\n");
                                                }
@@ -784,7 +775,7 @@ int main(int argc, char **argv)
                        BLI_convertstringcwd(filename);
                        
                        if (G.background) {
-                               int retval = BKE_read_file(C, argv[a], NULL);
+                               int retval = BKE_read_file(C, argv[a], NULL, NULL);
 // XXX                 sound_initialize_sounds();
                                
                                /*we successfully loaded a blend file, get sure that
@@ -797,7 +788,7 @@ int main(int argc, char **argv)
                        } 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);
+                               WM_read_file(C, filename, NULL);
                        }
                }
        }
@@ -827,7 +818,7 @@ static void error_cb(char *err)
 
 static void mem_error_cb(char *errorStr)
 {
-       fprintf(stderr, errorStr);
+       fputs(errorStr, stderr);
        fflush(stderr);
 }