Beispiel #1
0
void initialize_SDL(void)
{
    //NOTE - SDL_Init() and friends now in InitT4KCommon()

    // Audio parameters
    int frequency, channels, n_timesopened;
    Uint16 format;

    /* Init common library */
    if(!InitT4KCommon(debug_status))
    {
        fprintf(stderr, "InitT4KCommon() failed - exiting.\n");
        cleanup_on_error();
        exit(1);
    }

    /* Init SDL Video: */
    screen = NULL;


    /* Init SDL Audio: */
    Opts_SetSoundHWAvailable(0);  // By default no sound HW
#ifndef NOSOUND
    if (Opts_GetGlobalOpt(USE_SOUND))
    {
        if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, AUDIO_S16SYS, 2, 2048) < 0)
        {
            fprintf(stderr,
                    "\nWarning: I could not set up audio for 44100 Hz "
                    "16-bit stereo.\n"
                    "The Simple DirectMedia error that occured was:\n"
                    "%s\n\n", SDL_GetError());

        }
        n_timesopened = Mix_QuerySpec(&frequency,&format,&channels);
        if (n_timesopened > 0)
            Opts_SetSoundHWAvailable(1);
        else
            frequency = format = channels = 0; //more helpful than garbage
        DEBUGMSG(debug_setup, "Sound mixer: frequency = %d, "
                "format = %x, "
                "channels = %d, "
                "n_timesopened = %d\n",
                frequency,format,channels,n_timesopened);
    }
#endif
    /* If couldn't set up sound, deselect sound options: */
    if(!Opts_SoundHWAvailable())
    {
        DEBUGMSG(debug_setup, "Sound setup failed - deselecting sound options\n");        
        Opts_SetGlobalOpt(USE_SOUND, 0);
        Opts_SetGlobalOpt(MENU_SOUND, 0);
        Opts_SetGlobalOpt(MENU_MUSIC, 0);
    }



    {
        const SDL_VideoInfo *videoInfo;
        Uint32 surfaceMode;
        videoInfo = SDL_GetVideoInfo();
        if (videoInfo->hw_available)
        {
            surfaceMode = SDL_HWSURFACE;
            DEBUGMSG(debug_setup, "HW mode\n");
        }
        else
        {
            surfaceMode = SDL_SWSURFACE;
            DEBUGMSG(debug_setup, "SW mode\n");
        }

        // Determine the current resolution: this will be used as the
        // fullscreen resolution, if the user wants fullscreen.
        DEBUGMSG(debug_setup, "Current resolution: w %d, h %d.\n",videoInfo->current_w,videoInfo->current_h);
        if (Opts_GetGlobalOpt(FULLSCREEN) && Opts_CustomRes()) {
          fs_res_x = Opts_WindowWidth();
          fs_res_y = Opts_WindowHeight();
          DEBUGMSG(debug_setup, "Full screen mode custom resolution: w %d, h %d.\n",fs_res_x,fs_res_y);
        } else {
          fs_res_x = videoInfo->current_w;
          fs_res_y = videoInfo->current_h;
        }

        if (Opts_GetGlobalOpt(FULLSCREEN))
        {
            screen = SDL_SetVideoMode(fs_res_x, fs_res_y, PIXEL_BITS, SDL_FULLSCREEN | surfaceMode);
            if (screen == NULL)
            {
                fprintf(stderr,
                        "\nWarning: I could not open the display in fullscreen mode.\n"
                        "The Simple DirectMedia error that occured was:\n"
                        "%s\n\n", SDL_GetError());
                Opts_SetGlobalOpt(FULLSCREEN, 0);
            }
        }

        if (!Opts_GetGlobalOpt(FULLSCREEN))
        {
            screen = SDL_SetVideoMode(Opts_WindowWidth(), Opts_WindowHeight(), PIXEL_BITS, surfaceMode);
        }

        if (screen == NULL)
        {
            fprintf(stderr,
                    "\nError: I could not open the display.\n"
                    "The Simple DirectMedia error that occured was:\n"
                    "%s\n\n", SDL_GetError());
            cleanup_on_error();
            exit(1);
        }

        seticon();

        SDL_WM_SetCaption("Tux, of Math Command", "TuxMath");


    }
}
Beispiel #2
0
void Opts_SetGlobalOp(const char* text, int val)
{
    int index = Opts_MapTextToIndex(text);
    if (index < NUM_GLOBAL_OPTS)
        Opts_SetGlobalOpt(index, val);
}
Beispiel #3
0
/* for debug flags which we already have dealt with.     */
void handle_command_args(int argc, char* argv[])
{
    DIR *dirp;
    int i;

    for (i = 1; i < argc; i++)
    {
        if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)
        {
            /* Display help message: */

            fprintf(stderr, "\nTux, of Math Command\n\n"
                    "Use the number keys on the keyboard to answer math equations,\n"
                    "and then hit the space bar or enter.\n"
                    "If you don't answer a comet's math equation before it hits\n"
                    "one of your igloos, the igloo will be damaged.\n"
                    "If an igloo is hit twice, the penguin inside walks away.\n"
                    "When you lose all of your igloos, the game ends.\n\n");

            fprintf(stderr, "There is also a \"factoroids\" game in which a ship\n"
                    "destroys asteroids if you type a valid factor of the number\n"
                    "for a particular asteroid.  Use the number keys to steer.\n\n");

            fprintf(stderr, "Note: most settings are now stored in a config file named 'options' in\n"
                    "a hidden directory named './tuxmath' within the user's home directory.\n"
                    "The file consists of simple name/value pairs. It is much easier\n"
                    "to edit this file to set game parameters than to use the command-line\n"
                    "arguments listed below. Also, many options are not selectable from the\n"
                    "command line. The config file contains extensive comments detailing how\n"
                    "to configure the behavior of Tuxmath.\n\n");

            fprintf(stderr, "Run the game with:\n"
                    "--homedir dirname      - seek for user home director(ies) in the specified\n"
                    "                         location, rather than the user's actual home\n"
                    "                         directory.  You can set up a user directory tree in\n"
                    "                         this location (see README).  This option is\n"
                    "                         especially useful for schools where all students log\n"
                    "                         in with a single user name.\n"
                    "--optionfile filename  - read config settings from named file. The locations\n"
                    "                         searched for a file with a matching name are the\n"
                    "                         current working directory, the absolute path of the\n"
                    "                         filename, tuxmath's missions directory, the user's\n"
                    "                         tuxmath directory, and the user's home.\n"
                    "--playthroughlist      - to ask each question only once, allowing player to\n"
                    "                         win game if all questions successfully answered\n"
                    "--language {language}  - set the language named {language}, if it exists\n"
                    
                    "--answersfirst   - to ask questions in format: ? + num2 = num3\n"
                    "                   instead of default format: num1 + num2 = ?\n"
                    "--answersmiddle  - to ask questions in format: num1 + ? = num3\n"
                    "                   instead of default format: num1 + num2 = ?\n"
                    "--nosound        - to disable sound/music\n"
                    "--nobackground   - to disable background photos (for slower systems)\n"
                    "--fullscreen     - to run in fullscreen, if possible (vs. windowed)\n"
                    "--windowed       - to run in a window rather than fullscreen\n"
                    "--resolution WxH - window resolution (windowed mode only)\n"
                    "--keypad         - to enable the on-sceen numeric keypad\n"
                    "--demo           - to run the program as a cycling demonstration\n"
                    "--tts 			  - Enable in game accessibility\n"
                    "--notts 		  - Disable in game accessibility\n"
                    "--speed S        - set initial speed of the game\n"
                    "                   (S may be fractional, default is 1.0)\n"
                    "--allownegatives - to allow answers to be less than zero\n"
                    "--debug-X        - prints debug information on command line\n"
                    "                   X may be one of the following:\n"
                    "                     setup: debug messages only during initialization \n"
                    "                     fileops: file operations (loading and saving data)\n"
                    "                     loaders: loading of mulitmedia (images and sounds)\n"
                    "                     titlescreen\n"
                    "                     menu: most operations dealing with menus\n"
                    "                     menu-parser: subset of operations dealing with menus\n"
                    "                     game: the comets game\n"
                    "                     factoroids: the factoroids game\n"
                    "                     lan: anything dealing with networking\n"
                    "                     mathcards: generation of math problems\n"
                    "                     sdl: the general graphical system\n"
                    "                     lessons: parsing pre-prepared lessons\n"
                    "                     highscore: loading and saving high scores\n"
                    "                     options: loading and saving options files\n"
                    "                     text-and-intl: text and internationalization\n"
                    "                     all: everything!\n"
                    );

            fprintf(stderr, "\n");

            cleanup_on_error();
            exit(0);
        }
        else if (strcmp(argv[i], "--copyright") == 0 ||
                strcmp(argv[i], "-c") == 0)
        {
            printf(
                    "\n\"Tux, of Math Command\" version " VERSION ", Copyright (C) 2001-2011,\n"
                    "Bill Kendrick, David Bruce, Tim Holy, and the Tux4Kids Project.\n"
                    "This program is free software; you can redistribute it and/or\n"
                    "modify it under the terms of the GNU General Public License\n"
                    "as published by the Free Software Foundation.  See COPYING.txt\n"
                    "\n"
                    "This program is distributed in the hope that it will be useful,\n"
                    "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
                    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
                    "\n");

            cleanup_on_error();
            exit(0);
        }
        else if (strcmp(argv[i], "--usage") == 0 ||
                strcmp(argv[i], "-u") == 0)
        {
            /* Display (happy) usage: */

            usage(0, argv[0]);
        }
        else if (0 == strcmp(argv[i], "--homedir"))
        {
            // Parse the user choice of a non-default home directory
            if (i >= argc -1)
            {
                fprintf(stderr, "%s option requires an argument (dirname)\n", argv[i]);
                usage(1, argv[0]);
            }
            else // see whether the specified name is a directory
            {
                if ((dirp = opendir(argv[i+1])) == NULL)
                    fprintf(stderr,"homedir: %s is not a directory, or it could not be read\n", argv[i+1]);
                else {
                    set_user_data_dir(argv[i+1]);  // copy the homedir setting
                    closedir(dirp);
                }
                i++;   // to pass over the next argument, so remaining options parsed
            }
        }
        else if (0 == strcmp(argv[i], "--optionfile"))
        {
            if (i >= argc - 1)
            {
                fprintf(stderr, "%s option requires an argument (filename)\n", argv[i]);
                usage(1, argv[0]);
            }
            else /* try to read file named in following arg: */
            {
                if (!read_named_config_file(local_game, argv[i + 1]))
                {
                    fprintf(stderr, "Could not read config file: %s\n", argv[i + 1]);
                }
            }
            i++; /* so program doesn't barf on next arg (the filename) */
        }
        else if (strcmp(argv[i], "--fullscreen") == 0 ||
                strcmp(argv[i], "-f") == 0)
        {
            Opts_SetGlobalOpt(FULLSCREEN, 1);
        }
        else if (strcmp(argv[i], "--resolution") == 0 ||
                strcmp(argv[i], "-r") == 0)
        {
            if (i >= argc - 1)
            {
                fprintf(stderr, "%s option requires an argument\n", argv[i]);
                usage(1, argv[0]);
            }
            else
            {
                int w=0, h=0;
                sscanf(argv[i+1], "%dx%d", &w, &h);

                if(w>0 && h>0)
                {
                    Opts_SetWindowWidth(w);
                    Opts_SetWindowHeight(h);
                }
            }
            ++i;
        }
        else if (strcmp(argv[i], "--windowed") == 0 ||
                strcmp(argv[i], "-w") == 0)
        {
            Opts_SetGlobalOpt(FULLSCREEN, 0);
        }

        else if (strcmp(argv[i], "--tts") == 0 ||
                strcmp(argv[i], "-t") == 0)
        {
            Opts_SetGlobalOpt(USE_TTS, 1);
        }

        else if (strcmp(argv[i], "--notts") == 0 ||
                strcmp(argv[i], "-nt") == 0)
        {
            Opts_SetGlobalOpt(USE_TTS, 0);
        }
        

        else if (strcmp(argv[i], "--nosound") == 0 ||
                strcmp(argv[i], "-s") == 0 ||
                strcmp(argv[i], "--quiet") == 0 ||
                strcmp(argv[i], "-q") == 0)
        {
            Opts_SetGlobalOpt(USE_SOUND, -1);  // prevent options files from overwriting
        }
        else if (strcmp(argv[i], "--version") == 0 ||
                strcmp(argv[i], "-v") == 0)
        {
            fprintf(stderr, "Tux, of Math Command (\"tuxmath\")\n"
                    "Version " VERSION "\n");
            cleanup_on_error();
            exit(0);
        }
        else if (strcmp(argv[i], "--nobackground") == 0 ||
                strcmp(argv[i], "-b") == 0)
        {
            Opts_SetUseBkgd(0);
        }
        else if (strcmp(argv[i], "--demo") == 0 ||
                strcmp(argv[i], "-d") == 0)
        {
            Opts_SetDemoMode(1);
        }
        else if (strcmp(argv[i], "--keypad") == 0 ||
                strcmp(argv[i], "-k") == 0)
        {
            Opts_SetGlobalOpt(USE_KEYPAD, 1);
        }
        else if (strcmp(argv[i], "--allownegatives") == 0 ||
                strcmp(argv[i], "-n") == 0)
        {
            MC_SetOpt(local_game, ALLOW_NEGATIVES, 1);
        }
        else if (strcmp(argv[i], "--playthroughlist") == 0 ||
                strcmp(argv[i], "-l") == 0)
        {
            MC_SetOpt(local_game, PLAY_THROUGH_LIST, 1);
        }
        else if (strcmp(argv[i], "--answersfirst") == 0)
        {
            MC_SetOpt(local_game, FORMAT_ANSWER_LAST, 0);
            MC_SetOpt(local_game, FORMAT_ANSWER_FIRST, 1);
            MC_SetOpt(local_game, FORMAT_ANSWER_MIDDLE, 0);
        }
        else if (strcmp(argv[i], "--answersmiddle") == 0)
        {
            MC_SetOpt(local_game, FORMAT_ANSWER_LAST, 0);
            MC_SetOpt(local_game, FORMAT_ANSWER_FIRST, 0);
            MC_SetOpt(local_game, FORMAT_ANSWER_MIDDLE, 1);
        }

        else if (strcmp(argv[i], "--language") == 0 ||
                strcmp(argv[i], "-l") == 0)
        {
			++i;
			my_setenv("LANGUAGE",argv[i]);
			/* initialize Tts */
			T4K_Tts_init();
			T4K_Tts_set_voice(argv[i]);
        }

        else if (strcmp(argv[i], "--speed") == 0 ||
                strcmp(argv[i], "-s") == 0)
        {
            if (i >= argc - 1)
            {
                fprintf(stderr, "%s option requires an argument\n", argv[i]);
                usage(1, argv[0]);
            }

            Opts_SetSpeed(strtod(argv[i + 1], (char **) NULL));
            i++;
        }
        else /* Warn for unknown option, except debug flags */
            /* that we deal with separately:               */
        {
            if(strncmp(argv[i], "--debug", strlen("--debug")) != 0)         
                fprintf(stderr, "Unknown option: %s\n", argv[i]);
        }
    }/* end of command-line args */


    if (Opts_DemoMode() && Opts_GetGlobalOpt(USE_KEYPAD))
    {
        fprintf(stderr, "No use for keypad in demo mode!\n");
        Opts_SetGlobalOpt(USE_KEYPAD, 0);
    }
}