コード例 #1
0
static int reloadtranslation_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
{
	BLF_lang_init();
	BLF_cache_clear();
	BLF_lang_set(NULL);
	UI_reinit_font();
	return OPERATOR_FINISHED;
}
コード例 #2
0
ファイル: wm_init_exit.c プロジェクト: jinjoh/NOOR
/* only called once, for startup */
void WM_init(bContext *C)
{
	
	wm_ghost_init(C);	/* note: it assigns C to ghost! */
	wm_init_cursor_data();
	wm_operatortype_init();
	
	set_free_windowmanager_cb(wm_close_and_free);	/* library.c */
	set_blender_test_break_cb(wm_window_testbreak); /* blender.c */
	DAG_editors_update_cb(ED_render_id_flush_update); /* depsgraph.c */
	
	ED_spacetypes_init();	/* editors/space_api/spacetype.c */
	
	ED_file_init();			/* for fsmenu */
	ED_init_node_butfuncs();	
	
	BLF_init(11, U.dpi);
	BLF_lang_init();
	
	init_builtin_keyingsets(); /* editors/animation/keyframing.c */
	
	/* get the default database, plus a wm */
	WM_read_homefile(C, NULL);
	
	wm_init_reports(C); /* reports cant be initialized before the wm */
	
	GPU_extensions_init();

	UI_init();
	
	//	clear_matcopybuf(); /* XXX */
	
	//	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	
//	init_node_butfuncs();
	
	ED_preview_init_dbase();
	
	G.ndofdevice = -1;	/* XXX bad initializer, needs set otherwise buttons show! */
	
	read_Blog();
	BLI_strncpy(G.lib, G.sce, FILE_MAX);
}
コード例 #3
0
ファイル: GPG_ghost.cpp プロジェクト: akonneker/blensor
int main(int argc, char** argv)
{
    int i;
    int argc_py_clamped= argc; /* use this so python args can be added after ' - ' */
    bool error = false;
    SYS_SystemHandle syshandle = SYS_GetSystem();
    bool fullScreen = false;
    bool fullScreenParFound = false;
    bool windowParFound = false;
#ifdef WIN32
    bool closeConsole = true;
#endif
    RAS_IRasterizer::StereoMode stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
    bool stereoWindow = false;
    bool stereoParFound = false;
    int stereoFlag = STEREO_NOSTEREO;
    int domeFov = -1;
    int domeTilt = -200;
    int domeMode = 0;
    char* domeWarp = NULL;
    Text *domeText  = NULL;
    int windowLeft = 100;
    int windowTop = 100;
    int windowWidth = 640;
    int windowHeight = 480;
    GHOST_TUns32 fullScreenWidth = 0;
    GHOST_TUns32 fullScreenHeight= 0;
    int fullScreenBpp = 32;
    int fullScreenFrequency = 60;
    GHOST_TEmbedderWindowID parentWindow = 0;
    bool isBlenderPlayer = false; //true when lauching from blender or command line. false for bundled player
    int validArguments=0;
    bool samplesParFound = false;
    GHOST_TUns16 aasamples = 0;

#ifdef __linux__
#ifdef __alpha__
    signal (SIGFPE, SIG_IGN);
#endif /* __alpha__ */
#endif /* __linux__ */

#ifdef WITH_SDL_DYNLOAD
    sdlewInit();
#endif

    BKE_appdir_program_path_init(argv[0]);
    BKE_tempdir_init(NULL);

    // We don't use threads directly in the BGE, but we need to call this so things like
    // freeing up GPU_Textures works correctly.
    BLI_threadapi_init();

    RNA_init();

    init_nodesystem();

    initglobals();

    U.gameflags |= USER_DISABLE_VBO;
    // We load our own G.main, so free the one that initglobals() gives us
    BKE_main_free(G.main);
    G.main = NULL;

    MEM_CacheLimiter_set_disabled(true);
    IMB_init();
    BKE_images_init();
    BKE_modifier_init();
    DAG_init();

#ifdef WITH_FFMPEG
    IMB_ffmpeg_init();
#endif

    // Setup builtin font for BLF (mostly copied from creator.c, wm_init_exit.c and interface_style.c)
    BLF_init(11, U.dpi);
    BLF_lang_init();
    BLF_lang_set("");

    BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size);
    if (blf_mono_font == -1)
        blf_mono_font = BLF_load_mem_unique("monospace", (unsigned char*)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);

    // Parse command line options
#if defined(DEBUG)
    printf("argv[0] = '%s'\n", argv[0]);
#endif

#ifdef WIN32
    if (scr_saver_init(argc, argv))
    {
        switch (scr_saver_mode)
        {
        case SCREEN_SAVER_MODE_CONFIGURATION:
            MessageBox(scr_saver_hwnd, "This screen saver has no options that you can set", "Screen Saver", MB_OK);
            break;
        case SCREEN_SAVER_MODE_PASSWORD:
        /* This is W95 only, which we currently do not support.
         * Fall-back to normal screen saver behavior in that case... */
        case SCREEN_SAVER_MODE_SAVER:
            fullScreen = true;
            fullScreenParFound = true;
            break;

        case SCREEN_SAVER_MODE_PREVIEW:
            /* This will actually be handled somewhere below... */
            break;
        }
    }
#endif
    // XXX add the ability to change this values to the command line parsing.
    U.mixbufsize = 2048;
    U.audiodevice = 2;
    U.audiorate = 44100;
    U.audioformat = 0x24;
    U.audiochannels = 2;

    // XXX this one too
    U.anisotropic_filter = 2;
    // enable fast mipmap generation
    U.use_gpu_mipmap = 1;

    sound_init_once();

    set_free_windowmanager_cb(wm_free);

    /* if running blenderplayer the last argument can't be parsed since it has to be the filename. else it is bundled */
    isBlenderPlayer = !BLO_is_a_runtime(argv[0]);
    if (isBlenderPlayer)
        validArguments = argc - 1;
    else
        validArguments = argc;


    /* Parsing command line arguments (can be set from WM_OT_blenderplayer_start) */
#if defined(DEBUG)
    printf("Parsing command line arguments...\n");
    printf("Num of arguments is: %i\n", validArguments-1); //-1 because i starts at 1
#endif

    for (i = 1; (i < validArguments) && !error
#ifdef WIN32
            && scr_saver_mode == SCREEN_SAVER_MODE_NONE
#endif
            ;)

    {
#if defined(DEBUG)
        printf("argv[%d] = '%s'\n", i, argv[i]);
#endif
        if (argv[i][0] == '-')
        {
            /* ignore all args after " - ", allow python to have own args */
            if (argv[i][1]=='\0') {
                argc_py_clamped= i;
                break;
            }

            switch (argv[i][1])
            {
            case 'g': //game engine options (show_framerate, fixedtime, etc)
            {
                i++;
                if (i <= validArguments)
                {
                    char* paramname = argv[i];
                    // Check for single value versus assignment
                    if (i+1 <= validArguments && (*(argv[i+1]) == '='))
                    {
                        i++;
                        if (i + 1 <= validArguments)
                        {
                            i++;
                            // Assignment
                            SYS_WriteCommandLineInt(syshandle, paramname, atoi(argv[i]));
                            SYS_WriteCommandLineFloat(syshandle, paramname, atof(argv[i]));
                            SYS_WriteCommandLineString(syshandle, paramname, argv[i]);
#if defined(DEBUG)
                            printf("%s = '%s'\n", paramname, argv[i]);
#endif
                            i++;
                        }
                        else
                        {
                            error = true;
                            printf("error: argument assignment %s without value.\n", paramname);
                        }
                    }
                    else
                    {
//						SYS_WriteCommandLineInt(syshandle, argv[i++], 1);
                    }
                }
                break;
            }
            case 'd': //debug on
            {
                i++;
                G.debug |= G_DEBUG;
                MEM_set_memory_debug();
#ifdef DEBUG
                BLI_mempool_set_memory_debug();
#endif
                break;
            }
            case 'f': //fullscreen mode
            {
                i++;
                fullScreen = true;
                fullScreenParFound = true;
                if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
                {
                    fullScreenWidth = atoi(argv[i++]);
                    fullScreenHeight = atoi(argv[i++]);
                    if ((i + 1) <= validArguments && argv[i][0] != '-')
                    {
                        fullScreenBpp = atoi(argv[i++]);
                        if ((i + 1) <= validArguments && argv[i][0] != '-')
                            fullScreenFrequency = atoi(argv[i++]);
                    }
                }
                else if ((i + 1) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
                {
                    error = true;
                    printf("error: to define fullscreen width or height, both options must be used.\n");
                }
                break;
            }
            case 'w': //display in a window
            {
                i++;
                fullScreen = false;
                windowParFound = true;

                // Parse window position and size options
                if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
                {
                    windowWidth = atoi(argv[i++]);
                    windowHeight = atoi(argv[i++]);

                    if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
                    {
                        windowLeft = atoi(argv[i++]);
                        windowTop = atoi(argv[i++]);
                    }
                    else if ((i + 1) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
                    {
                        error = true;
                        printf("error: to define the window left or right coordinates, both options must be used.\n");
                    }
                }
                else if ((i + 1) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
                {
                    error = true;
                    printf("error: to define the window's width or height, both options must be used.\n");
                }
                break;
            }
            case 'h': //display help
            {
                usage(argv[0], isBlenderPlayer);
                return 0;
                break;
            }
            case 'i': //parent window ID
            {
                i++;
                if ( (i + 1) <= validArguments )
                    parentWindow = atoi(argv[i++]);
                else {
                    error = true;
                    printf("error: too few options for parent window argument.\n");
                }
#if defined(DEBUG)
                printf("XWindows ID = %d\n", parentWindow);
#endif // defined(DEBUG)
                break;
            }
            case 'm': //maximum anti-aliasing (eg. 2,4,8,16)
            {
                i++;
                samplesParFound = true;
                if ((i+1) <= validArguments )
                    aasamples = atoi(argv[i++]);
                else
                {
                    error = true;
                    printf("error: No argument supplied for -m");
                }
                break;
            }
            case 'c': //keep console (windows only)
            {
                i++;
#ifdef WIN32
                closeConsole = false;
#endif
                break;
            }
            case 's': //stereo mode
            {
                i++;
                if ((i + 1) <= validArguments)
                {
                    stereoParFound = true;
                    stereoFlag = STEREO_ENABLED;

                    if (!strcmp(argv[i], "nostereo"))  // may not be redundant if the file has different setting
                    {
                        stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
                        stereoFlag = STEREO_NOSTEREO;
                    }

                    // only the hardware pageflip method needs a stereo window
                    else if (!strcmp(argv[i], "hwpageflip")) {
                        stereomode = RAS_IRasterizer::RAS_STEREO_QUADBUFFERED;
                        stereoWindow = true;
                    }
                    else if (!strcmp(argv[i], "syncdoubling"))
                        stereomode = RAS_IRasterizer::RAS_STEREO_ABOVEBELOW;

                    else if (!strcmp(argv[i], "3dtvtopbottom"))
                        stereomode = RAS_IRasterizer::RAS_STEREO_3DTVTOPBOTTOM;

                    else if (!strcmp(argv[i], "anaglyph"))
                        stereomode = RAS_IRasterizer::RAS_STEREO_ANAGLYPH;

                    else if (!strcmp(argv[i], "sidebyside"))
                        stereomode = RAS_IRasterizer::RAS_STEREO_SIDEBYSIDE;

                    else if (!strcmp(argv[i], "interlace"))
                        stereomode = RAS_IRasterizer::RAS_STEREO_INTERLACED;

                    else if (!strcmp(argv[i], "vinterlace"))
                        stereomode = RAS_IRasterizer::RAS_STEREO_VINTERLACE;

#if 0
//					// future stuff
//					else if (!strcmp(argv[i], "stencil")
//						stereomode = RAS_STEREO_STENCIL;
#endif
                    else
                    {
                        error = true;
                        printf("error: stereomode '%s' unrecognized.\n", argv[i]);
                    }

                    i++;
                }
                else
                {
                    error = true;
                    printf("error: too few options for stereo argument.\n");
                }
                break;
            }
            case 'D': //dome mode
            {
                stereoFlag = STEREO_DOME;
                stereomode = RAS_IRasterizer::RAS_STEREO_DOME;
                i++;
                if ((i + 1) <= validArguments)
                {
                    if (!strcmp(argv[i], "angle")) {
                        i++;
                        domeFov = atoi(argv[i++]);
                    }
                    if (!strcmp(argv[i], "tilt")) {
                        i++;
                        domeTilt = atoi(argv[i++]);
                    }
                    if (!strcmp(argv[i], "warpdata")) {
                        i++;
                        domeWarp = argv[i++];
                    }
                    if (!strcmp(argv[i], "mode")) {
                        i++;
                        if (!strcmp(argv[i], "fisheye"))
                            domeMode = DOME_FISHEYE;

                        else if (!strcmp(argv[i], "truncatedfront"))
                            domeMode = DOME_TRUNCATED_FRONT;

                        else if (!strcmp(argv[i], "truncatedrear"))
                            domeMode = DOME_TRUNCATED_REAR;

                        else if (!strcmp(argv[i], "cubemap"))
                            domeMode = DOME_ENVMAP;

                        else if (!strcmp(argv[i], "sphericalpanoramic"))
                            domeMode = DOME_PANORAM_SPH;

                        else
                            printf("error: %s is not a valid dome mode.\n", argv[i]);
                    }
                    i++;
                }
                break;
            }
            default:  //not recognized
            {
                printf("Unknown argument: %s\n", argv[i++]);
                break;
            }
            }
        }
        else
        {
            i++;
        }
    }

    if ((windowWidth < kMinWindowWidth) || (windowHeight < kMinWindowHeight))
    {
        error = true;
        printf("error: window size too small.\n");
    }

    if (error )
    {
        usage(argv[0], isBlenderPlayer);
        return 0;
    }

#ifdef WIN32
    if (scr_saver_mode != SCREEN_SAVER_MODE_CONFIGURATION)
#endif
    {
        // Create the system
        if (GHOST_ISystem::createSystem() == GHOST_kSuccess) {
            GHOST_ISystem* system = GHOST_ISystem::getSystem();
            assertd(system);

            if (!fullScreenWidth || !fullScreenHeight)
                system->getMainDisplayDimensions(fullScreenWidth, fullScreenHeight);
            // process first batch of events. If the user
            // drops a file on top off the blenderplayer icon, we
            // receive an event with the filename

            system->processEvents(0);

            // this bracket is needed for app (see below) to get out
            // of scope before GHOST_ISystem::disposeSystem() is called.
            {
                int exitcode = KX_EXIT_REQUEST_NO_REQUEST;
                STR_String exitstring = "";
                GPG_Application app(system);
                bool firstTimeRunning = true;
                char filename[FILE_MAX];
                char pathname[FILE_MAX];
                char *titlename;

                get_filename(argc_py_clamped, argv, filename);
                if (filename[0])
                    BLI_path_cwd(filename);


                // fill the GlobalSettings with the first scene files
                // those may change during the game and persist after using Game Actuator
                GlobalSettings gs;

                do {
                    // Read the Blender file
                    BlendFileData *bfd;

                    // if we got an exitcode 3 (KX_EXIT_REQUEST_START_OTHER_GAME) load a different file
                    if (exitcode == KX_EXIT_REQUEST_START_OTHER_GAME)
                    {
                        char basedpath[FILE_MAX];

                        // base the actuator filename relative to the last file
                        BLI_strncpy(basedpath, exitstring.Ptr(), sizeof(basedpath));
                        BLI_path_abs(basedpath, pathname);

                        bfd = load_game_data(basedpath);

                        if (!bfd) {
                            // just add "//" in front of it
                            char temppath[FILE_MAX] = "//";
                            BLI_strncpy(temppath + 2, basedpath, FILE_MAX - 2);

                            BLI_path_abs(temppath, pathname);
                            bfd = load_game_data(temppath);
                        }
                    }
                    else {
                        bfd = load_game_data(BKE_appdir_program_path(), filename[0]? filename: NULL);
                    }

#if defined(DEBUG)
                    printf("Game data loaded from %s\n", filename);
#endif

                    if (!bfd) {
                        usage(argv[0], isBlenderPlayer);
                        error = true;
                        exitcode = KX_EXIT_REQUEST_QUIT_GAME;
                    }
                    else {
                        /* Setting options according to the blend file if not overriden in the command line */
#ifdef WIN32
#if !defined(DEBUG)
                        if (closeConsole) {
                            system->toggleConsole(0); // Close a console window
                        }
#endif // !defined(DEBUG)
#endif // WIN32
                        Main *maggie = bfd->main;
                        Scene *scene = bfd->curscene;
                        G.main = maggie;

                        if (firstTimeRunning) {
                            G.fileflags  = bfd->fileflags;

                            gs.matmode= scene->gm.matmode;
                            gs.glslflag= scene->gm.flag;
                        }

                        //Seg Fault; icon.c gIcons == 0
                        BKE_icons_init(1);

                        titlename = maggie->name;

                        // Check whether the game should be displayed full-screen
                        if ((!fullScreenParFound) && (!windowParFound)) {
                            // Only use file settings when command line did not override
                            if ((scene->gm.playerflag & GAME_PLAYER_FULLSCREEN)) {
                                //printf("fullscreen option found in Blender file\n");
                                fullScreen = true;
                                fullScreenWidth= scene->gm.xplay;
                                fullScreenHeight= scene->gm.yplay;
                                fullScreenFrequency= scene->gm.freqplay;
                                fullScreenBpp = scene->gm.depth;
                            }
                            else
                            {
                                fullScreen = false;
                                windowWidth = scene->gm.xplay;
                                windowHeight = scene->gm.yplay;
                            }
                        }


                        // Check whether the game should be displayed in stereo (dome included)
                        if (!stereoParFound) {
                            // Only use file settings when command line did not override
                            if (scene->gm.stereoflag == STEREO_ENABLED) {
                                stereomode = (RAS_IRasterizer::StereoMode) scene->gm.stereomode;
                                if (stereomode == RAS_IRasterizer::RAS_STEREO_QUADBUFFERED)
                                    stereoWindow = true;
                            }
                        }
                        else {
                            scene->gm.stereoflag = STEREO_ENABLED;
                        }

                        if (!samplesParFound)
                            aasamples = scene->gm.aasamples;

                        // Dome specific settings
                        if (stereoFlag == STEREO_DOME) {
                            stereomode = RAS_IRasterizer::RAS_STEREO_DOME;
                            scene->gm.stereoflag = STEREO_DOME;
                            if (domeFov > 89)
                                scene->gm.dome.angle = domeFov;
                            if (domeTilt > -180)
                                scene->gm.dome.tilt = domeTilt;
                            if (domeMode > 0)
                                scene->gm.dome.mode = domeMode;
                            if (domeWarp) {
                                //XXX to do: convert relative to absolute path
                                domeText= BKE_text_load(G.main, domeWarp, "");
                                if (!domeText)
                                    printf("error: invalid warpdata text file - %s\n", domeWarp);
                                else
                                    scene->gm.dome.warptext = domeText;
                            }
                        }

                        //					GPG_Application app (system, maggie, startscenename);
                        app.SetGameEngineData(maggie, scene, &gs, argc, argv); /* this argc cant be argc_py_clamped, since python uses it */
                        BLI_strncpy(pathname, maggie->name, sizeof(pathname));
                        if (G.main != maggie) {
                            BLI_strncpy(G.main->name, maggie->name, sizeof(G.main->name));
                        }
#ifdef WITH_PYTHON
                        setGamePythonPath(G.main->name);
#endif
                        if (firstTimeRunning) {
                            firstTimeRunning = false;

                            if (fullScreen) {
#ifdef WIN32
                                if (scr_saver_mode == SCREEN_SAVER_MODE_SAVER)
                                {
                                    app.startScreenSaverFullScreen(fullScreenWidth, fullScreenHeight, fullScreenBpp, fullScreenFrequency,
                                                                   stereoWindow, stereomode, aasamples);
                                }
                                else
#endif
                                {
                                    app.startFullScreen(fullScreenWidth, fullScreenHeight, fullScreenBpp, fullScreenFrequency,
                                                        stereoWindow, stereomode, aasamples, (scene->gm.playerflag & GAME_PLAYER_DESKTOP_RESOLUTION));
                                }
                            }
                            else
                            {
#ifdef __APPLE__
                                // on Mac's we'll show the executable name instead of the 'game.blend' name
                                char tempname[1024], *appstring;
                                ::strcpy(tempname, titlename);

                                appstring = strstr(tempname, ".app/");
                                if (appstring) {
                                    appstring[2] = 0;
                                    titlename = &tempname[0];
                                }
#endif
                                // Strip the path so that we have the name of the game file
                                STR_String path = titlename;
#ifndef WIN32
                                vector<STR_String> parts = path.Explode('/');
#else  // WIN32
                                vector<STR_String> parts = path.Explode('\\');
#endif // WIN32                        
                                STR_String title;
                                if (parts.size()) {
                                    title = parts[parts.size()-1];
                                    parts = title.Explode('.');
                                    if (parts.size() > 1)
                                    {
                                        title = parts[0];
                                    }
                                }
                                else {
                                    title = "blenderplayer";
                                }
#ifdef WIN32
                                if (scr_saver_mode == SCREEN_SAVER_MODE_PREVIEW)
                                {
                                    app.startScreenSaverPreview(scr_saver_hwnd, stereoWindow, stereomode, aasamples);
                                }
                                else
#endif
                                {
                                    if (parentWindow != 0)
                                        app.startEmbeddedWindow(title, parentWindow, stereoWindow, stereomode, aasamples);
                                    else
                                        app.startWindow(title, windowLeft, windowTop, windowWidth, windowHeight,
                                                        stereoWindow, stereomode, aasamples);

                                    if (SYS_GetCommandLineInt(syshandle, "nomipmap", 0)) {
                                        GPU_set_mipmap(0);
                                    }

                                    GPU_set_anisotropic(U.anisotropic_filter);
                                    GPU_set_gpu_mipmapping(U.use_gpu_mipmap);
                                }
                            }
                        }
                        else {
                            app.StartGameEngine(stereomode);
                            exitcode = KX_EXIT_REQUEST_NO_REQUEST;
                        }

                        // Add the application as event consumer
                        system->addEventConsumer(&app);

                        // Enter main loop
                        bool run = true;
                        char *python_main = NULL;
                        pynextframestate.state = NULL;
                        pynextframestate.func = NULL;
#ifdef WITH_PYTHON
                        python_main = KX_GetPythonMain(scene);
#endif // WITH_PYTHON
                        if (python_main) {
                            char *python_code = KX_GetPythonCode(maggie, python_main);
                            if (python_code) {
#ifdef WITH_PYTHON
                                gpg_nextframestate.system = system;
                                gpg_nextframestate.app = &app;
                                gpg_nextframestate.gs = &gs;
                                pynextframestate.state = &gpg_nextframestate;
                                pynextframestate.func = &GPG_PyNextFrame;

                                printf("Yielding control to Python script '%s'...\n", python_main);
                                PyRun_SimpleString(python_code);
                                printf("Exit Python script '%s'\n", python_main);
#endif // WITH_PYTHON
                                MEM_freeN(python_code);
                            }
                            else {
                                fprintf(stderr, "ERROR: cannot yield control to Python: no Python text data block named '%s'\n", python_main);
                            }
                        }
                        else {
                            while (run) {
                                run = GPG_NextFrame(system, &app, exitcode, exitstring, &gs);
                            }
                        }
                        app.StopGameEngine();

                        /* 'app' is freed automatic when out of scope.
                         * removal is needed else the system will free an already freed value */
                        system->removeEventConsumer(&app);

                        BLO_blendfiledata_free(bfd);
                        /* G.main == bfd->main, it gets referenced in free_nodesystem so we can't have a dangling pointer */
                        G.main = NULL;
                        if (python_main) MEM_freeN(python_main);
                    }
                } while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME);
            }

            // Seg Fault; icon.c gIcons == 0
            BKE_icons_free();

            // Dispose the system
            GHOST_ISystem::disposeSystem();
        }
        else {
            error = true;
            printf("error: couldn't create a system.\n");
        }
    }

    /* refer to WM_exit_ext() and free_blender(),
     * these are not called in the player but we need to match some of there behavior here,
     * if the order of function calls or blenders state isn't matching that of blender proper,
     * we may get troubles later on */

    free_nodesystem();

    // Cleanup
    RNA_exit();
    BLF_exit();

#ifdef WITH_INTERNATIONAL
    BLF_free_unifont();
    BLF_free_unifont_mono();
    BLF_lang_free();
#endif

    IMB_exit();
    BKE_images_exit();
    DAG_exit();
    IMB_moviecache_destruct();

    SYS_DeleteSystem(syshandle);

    int totblock= MEM_get_memory_blocks_in_use();
    if (totblock!=0) {
        printf("Error Totblock: %d\n",totblock);
        MEM_set_error_callback(mem_error_cb);
        MEM_printmemlist();
    }

    BKE_tempdir_session_purge();

    return error ? -1 : 0;
}
コード例 #4
0
ファイル: GPG_ghost.cpp プロジェクト: rexbron/blender-ocio
int main(int argc, char** argv)
{
    int i;
    int argc_py_clamped= argc; /* use this so python args can be added after ' - ' */
    bool error = false;
    SYS_SystemHandle syshandle = SYS_GetSystem();
    bool fullScreen = false;
    bool fullScreenParFound = false;
    bool windowParFound = false;
#ifdef WIN32
    bool closeConsole = true;
#endif
    RAS_IRasterizer::StereoMode stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
    bool stereoWindow = false;
    bool stereoParFound = false;
    int stereoFlag = STEREO_NOSTEREO;
    int domeFov = -1;
    int domeTilt = -200;
    int domeMode = 0;
    char* domeWarp = NULL;
    Text *domeText  = NULL;
    int windowLeft = 100;
    int windowTop = 100;
    int windowWidth = 640;
    int windowHeight = 480;
    GHOST_TUns32 fullScreenWidth = 0;
    GHOST_TUns32 fullScreenHeight= 0;
    int fullScreenBpp = 32;
    int fullScreenFrequency = 60;
    GHOST_TEmbedderWindowID parentWindow = 0;
    bool isBlenderPlayer = false;
    int validArguments=0;
    GHOST_TUns16 aasamples = 0;

#ifdef __linux__
#ifdef __alpha__
    signal (SIGFPE, SIG_IGN);
#endif /* __alpha__ */
#endif /* __linux__ */
    BLI_where_am_i(bprogname, sizeof(bprogname), argv[0]);
#ifdef __APPLE__
    // Can't use Carbon right now because of double defined type ID (In Carbon.h and DNA_ID.h, sigh)
    /*
    IBNibRef 		nibRef;
    WindowRef 		window;
    OSStatus		err;

      // Create a Nib reference passing the name of the nib file (without the .nib extension)
      // CreateNibReference only searches into the application bundle.
      err = ::CreateNibReference(CFSTR("main"), &nibRef);
      if (err) return -1;

    	// Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar
    	// object. This name is set in InterfaceBuilder when the nib is created.
    	err = ::SetMenuBarFromNib(nibRef, CFSTR("MenuBar"));
    	if (err) return -1;

    	  // We don't need the nib reference anymore.
    	  ::DisposeNibReference(nibRef);
    */
#endif // __APPLE__

    // We don't use threads directly in the BGE, but we need to call this so things like
    // freeing up GPU_Textures works correctly.
    BLI_threadapi_init();

    RNA_init();

    init_nodesystem();

    initglobals();

    // We load our own G.main, so free the one that initglobals() gives us
    free_main(G.main);
    G.main = NULL;

    IMB_init();

    // Setup builtin font for BLF (mostly copied from creator.c, wm_init_exit.c and interface_style.c)
    BLF_init(11, U.dpi);
    BLF_lang_init();
    BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size);

    // Parse command line options
#if defined(DEBUG)
    printf("argv[0] = '%s'\n", argv[0]);
#endif

#ifdef WIN32
    if (scr_saver_init(argc, argv))
    {
        switch (scr_saver_mode)
        {
        case SCREEN_SAVER_MODE_CONFIGURATION:
            MessageBox(scr_saver_hwnd, "This screen saver has no options that you can set", "Screen Saver", MB_OK);
            break;
        case SCREEN_SAVER_MODE_PASSWORD:
        /* This is W95 only, which we currently do not support.
           Fall-back to normal screen saver behaviour in that case... */
        case SCREEN_SAVER_MODE_SAVER:
            fullScreen = true;
            fullScreenParFound = true;
            break;

        case SCREEN_SAVER_MODE_PREVIEW:
            /* This will actually be handled somewhere below... */
            break;
        }
    }
#endif
    // XXX add the ability to change this values to the command line parsing.
    U.mixbufsize = 2048;
    U.audiodevice = 2;
    U.audiorate = 44100;
    U.audioformat = 0x24;
    U.audiochannels = 2;

    // XXX this one too
    U.anisotropic_filter = 2;

    sound_init_once();

    /* if running blenderplayer the last argument can't be parsed since it has to be the filename. */
    isBlenderPlayer = !BLO_is_a_runtime(argv[0]);
    if (isBlenderPlayer)
        validArguments = argc - 1;
    else
        validArguments = argc;

    for (i = 1; (i < validArguments) && !error
#ifdef WIN32
            && scr_saver_mode == SCREEN_SAVER_MODE_NONE
#endif
            ;)

    {
#if defined(DEBUG)
        printf("argv[%d] = '%s'   , %i\n", i, argv[i],argc);
#endif
        if (argv[i][0] == '-')
        {
            /* ignore all args after " - ", allow python to have own args */
            if (argv[i][1]=='\0') {
                argc_py_clamped= i;
                break;
            }

            switch (argv[i][1])
            {
            case 'g':
                // Parse game options
            {
                i++;
                if (i <= validArguments)
                {
                    char* paramname = argv[i];
                    // Check for single value versus assignment
                    if (i+1 <= validArguments && (*(argv[i+1]) == '='))
                    {
                        i++;
                        if (i + 1 <= validArguments)
                        {
                            i++;
                            // Assignment
                            SYS_WriteCommandLineInt(syshandle, paramname, atoi(argv[i]));
                            SYS_WriteCommandLineFloat(syshandle, paramname, atof(argv[i]));
                            SYS_WriteCommandLineString(syshandle, paramname, argv[i]);
#if defined(DEBUG)
                            printf("%s = '%s'\n", paramname, argv[i]);
#endif
                            i++;
                        }
                        else
                        {
                            error = true;
                            printf("error: argument assignment %s without value.\n", paramname);
                        }
                    }
                    else
                    {
//							SYS_WriteCommandLineInt(syshandle, argv[i++], 1);
                    }
                }
            }
            break;

            case 'd':
                i++;
                G.f |= G_DEBUG;     /* std output printf's */
                MEM_set_memory_debug();
                break;

            case 'f':
                i++;
                fullScreen = true;
                fullScreenParFound = true;
                if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
                {
                    fullScreenWidth = atoi(argv[i++]);
                    fullScreenHeight = atoi(argv[i++]);
                    if ((i + 1) <= validArguments && argv[i][0] != '-')
                    {
                        fullScreenBpp = atoi(argv[i++]);
                        if ((i + 1) <= validArguments && argv[i][0] != '-')
                            fullScreenFrequency = atoi(argv[i++]);
                    }
                }
                break;
            case 'w':
                // Parse window position and size options
                i++;
                fullScreen = false;
                windowParFound = true;

                if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
                {
                    windowWidth = atoi(argv[i++]);
                    windowHeight = atoi(argv[i++]);
                    if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
                    {
                        windowLeft = atoi(argv[i++]);
                        windowTop = atoi(argv[i++]);
                    }
                }
                break;

            case 'h':
                usage(argv[0], isBlenderPlayer);
                return 0;
                break;
            case 'i':
                i++;
                if ( (i + 1) <= validArguments )
                    parentWindow = atoi(argv[i++]);
                else {
                    error = true;
                    printf("error: too few options for parent window argument.\n");
                }
#if defined(DEBUG)
                printf("XWindows ID = %d\n", parentWindow);
#endif // defined(DEBUG)
                break;
            case 'm':
                i++;
                if ((i+1) <= validArguments )
                    aasamples = atoi(argv[i++]);
                break;
            case 'c':
                i++;
#ifdef WIN32
                closeConsole = false;
#endif
                break;
            case 's':  // stereo
                i++;
                if ((i + 1) <= validArguments)
                {
                    stereomode = (RAS_IRasterizer::StereoMode) atoi(argv[i]);
                    if (stereomode < RAS_IRasterizer::RAS_STEREO_NOSTEREO || stereomode >= RAS_IRasterizer::RAS_STEREO_MAXSTEREO)
                        stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;

                    if(!strcmp(argv[i], "nostereo"))  // ok, redundant but clear
                        stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;

                    // only the hardware pageflip method needs a stereo window
                    else if(!strcmp(argv[i], "hwpageflip")) {
                        stereomode = RAS_IRasterizer::RAS_STEREO_QUADBUFFERED;
                        stereoWindow = true;
                    }
                    else if(!strcmp(argv[i], "syncdoubling"))
                        stereomode = RAS_IRasterizer::RAS_STEREO_ABOVEBELOW;

                    else if(!strcmp(argv[i], "anaglyph"))
                        stereomode = RAS_IRasterizer::RAS_STEREO_ANAGLYPH;

                    else if(!strcmp(argv[i], "sidebyside"))
                        stereomode = RAS_IRasterizer::RAS_STEREO_SIDEBYSIDE;

                    else if(!strcmp(argv[i], "vinterlace"))
                        stereomode = RAS_IRasterizer::RAS_STEREO_VINTERLACE;

#if 0
                    // future stuff
                    else if(!strcmp(argv[i], "stencil")
                            stereomode = RAS_STEREO_STENCIL;
#endif

                            i++;
                            stereoParFound = true;
                            stereoFlag = STEREO_ENABLED;
                }
            else
            {
                error = true;
                printf("error: too few options for stereo argument.\n");
                }
                break;
            case 'D':
                stereoFlag = STEREO_DOME;
                stereomode = RAS_IRasterizer::RAS_STEREO_DOME;
                i++;
                if ((i + 1) <= validArguments)
                {
                    if(!strcmp(argv[i], "angle")) {
                        i++;
                        domeFov = atoi(argv[i++]);
                    }
                    if(!strcmp(argv[i], "tilt")) {
                        i++;
                        domeTilt = atoi(argv[i++]);
                    }
                    if(!strcmp(argv[i], "warpdata")) {
                        i++;
                        domeWarp = argv[i++];
                    }
                    if(!strcmp(argv[i], "mode")) {
                        i++;
                        if(!strcmp(argv[i], "fisheye"))
                            domeMode = DOME_FISHEYE;

                        else if(!strcmp(argv[i], "truncatedfront"))
                            domeMode = DOME_TRUNCATED_FRONT;

                        else if(!strcmp(argv[i], "truncatedrear"))
                            domeMode = DOME_TRUNCATED_REAR;

                        else if(!strcmp(argv[i], "cubemap"))
                            domeMode = DOME_ENVMAP;

                        else if(!strcmp(argv[i], "sphericalpanoramic"))
                            domeMode = DOME_PANORAM_SPH;

                        else
                            printf("error: %s is not a valid dome mode.\n", argv[i]);
                    }
                    i++;
                }
                break;
            default:
                printf("Unknown argument: %s\n", argv[i++]);
                break;
            }
        }
コード例 #5
0
ファイル: wm_init_exit.c プロジェクト: 244xiao/blender
/* only called once, for startup */
void WM_init(bContext *C, int argc, const char **argv)
{
	
	if (!G.background) {
		wm_ghost_init(C);   /* note: it assigns C to ghost! */
		wm_init_cursor_data();
	}
	GHOST_CreateSystemPaths();

	BKE_addon_pref_type_init();

	wm_operatortype_init();
	WM_menutype_init();
	WM_uilisttype_init();

	set_free_windowmanager_cb(wm_close_and_free);   /* library.c */
	set_free_notifier_reference_cb(WM_main_remove_notifier_reference);   /* library.c */
	set_blender_test_break_cb(wm_window_testbreak); /* blender.c */
	DAG_editors_update_cb(ED_render_id_flush_update, ED_render_scene_update); /* depsgraph.c */
	
	ED_spacetypes_init();   /* editors/space_api/spacetype.c */
	
	ED_file_init();         /* for fsmenu */
	ED_node_init_butfuncs();
	
	BLF_init(11, U.dpi); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */
	BLF_lang_init();

	/* get the default database, plus a wm */
	wm_homefile_read(C, NULL, G.factory_startup);
	
	BLF_lang_set(NULL);

	/* note: there is a bug where python needs initializing before loading the
	 * startup.blend because it may contain PyDrivers. It also needs to be after
	 * initializing space types and other internal data.
	 *
	 * However cant redo this at the moment. Solution is to load python
	 * before wm_homefile_read() or make py-drivers check if python is running.
	 * Will try fix when the crash can be repeated. - campbell. */

#ifdef WITH_PYTHON
	BPY_context_set(C); /* necessary evil */
	BPY_python_start(argc, argv);

	BPY_python_reset(C);
#else
	(void)argc; /* unused */
	(void)argv; /* unused */
#endif

	if (!G.background && !wm_start_with_console)
		GHOST_toggleConsole(3);

	wm_init_reports(C); /* reports cant be initialized before the wm */

	if (!G.background) {
		GPU_extensions_init();
		GPU_set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
		GPU_set_anisotropic(U.anisotropic_filter);
		GPU_set_gpu_mipmapping(U.use_gpu_mipmap);

		UI_init();
	}
	
	clear_matcopybuf();
	ED_render_clear_mtex_copybuf();

	// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		
	ED_preview_init_dbase();
	
	wm_read_history();

	/* allow a path of "", this is what happens when making a new file */
#if 0
	if (G.main->name[0] == 0)
		BLI_make_file_string("/", G.main->name, BLI_getDefaultDocumentFolder(), "untitled.blend");
#endif

	BLI_strncpy(G.lib, G.main->name, FILE_MAX);

#ifdef WITH_COMPOSITOR
	if (1) {
		extern void *COM_linker_hack;
		COM_linker_hack = COM_execute;
	}
#endif
	
	/* load last session, uses regular file reading so it has to be in end (after init py etc) */
	if (U.uiflag2 & USER_KEEP_SESSION) {
		/* calling WM_recover_last_session(C, NULL) has been moved to creator.c */
		/* that prevents loading both the kept session, and the file on the command line */
	}
	else {
		/* normally 'wm_homefile_read' will do this,
		 * however python is not initialized when called from this function.
		 *
		 * unlikely any handlers are set but its possible,
		 * note that recovering the last session does its own callbacks. */
		BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_POST);
	}
}
コード例 #6
0
/* only called once, for startup */
void WM_init(bContext *C, int argc, const char **argv)
{
	if (!G.background) {
		wm_ghost_init(C);	/* note: it assigns C to ghost! */
		wm_init_cursor_data();
	}
	GHOST_CreateSystemPaths();
	wm_operatortype_init();
	WM_menutype_init();

	set_free_windowmanager_cb(wm_close_and_free);	/* library.c */
	set_blender_test_break_cb(wm_window_testbreak); /* blender.c */
	DAG_editors_update_cb(ED_render_id_flush_update); /* depsgraph.c */
	
	ED_spacetypes_init();	/* editors/space_api/spacetype.c */
	
	ED_file_init();			/* for fsmenu */
	ED_init_node_butfuncs();	
	
	BLF_init(11, U.dpi); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */
	BLF_lang_init();
	/* get the default database, plus a wm */
	WM_read_homefile(C, NULL, G.factory_startup);

	BLF_lang_set(NULL);

	/* note: there is a bug where python needs initializing before loading the
	 * startup.blend because it may contain PyDrivers. It also needs to be after
	 * initializing space types and other internal data.
	 *
	 * However cant redo this at the moment. Solution is to load python
	 * before WM_read_homefile() or make py-drivers check if python is running.
	 * Will try fix when the crash can be repeated. - campbell. */

#ifdef WITH_PYTHON
	BPY_context_set(C); /* necessary evil */
	BPY_python_start(argc, argv);

	BPY_driver_reset();
	BPY_app_handlers_reset(); /* causes addon callbacks to be freed [#28068],
	                           * but this is actually what we want. */
	BPY_modules_load_user(C);
#else
	(void)argc; /* unused */
	(void)argv; /* unused */
#endif

	if (!G.background && !wm_start_with_console)
		GHOST_toggleConsole(3);

	wm_init_reports(C); /* reports cant be initialized before the wm */

	if (!G.background) {
		GPU_extensions_init();
		GPU_set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
		GPU_set_anisotropic(U.anisotropic_filter);
	
		UI_init();
	}
	
	clear_matcopybuf();
	ED_render_clear_mtex_copybuf();

	//	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
		
	ED_preview_init_dbase();
	
	WM_read_history();

	/* allow a path of "", this is what happens when making a new file */
	/*
	if(G.main->name[0] == 0)
		BLI_make_file_string("/", G.main->name, BLI_getDefaultDocumentFolder(), "untitled.blend");
	*/

	BLI_strncpy(G.lib, G.main->name, FILE_MAX);
}