[Super-tux-commit] supertux/lib/app defines.h,NONE,1.1 gettext.h,NONE,1.1 globals.cpp,NONE,1.1 globa
Brought to you by:
wkendrick
From: Tobias G. <to...@us...> - 2004-07-20 17:51:45
|
Update of /cvsroot/super-tux/supertux/lib/app In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19557/lib/app Added Files: defines.h gettext.h globals.cpp globals.h setup.cpp setup.h Log Message: Generated SuperTux libtool library containing more general source, that could prove useful for other applications/games. Caution: It's not yet SuperTux independed, more work on this will follow, that's just the first step. The file structure isn't fixed, better ideas will surely find there way in it! --- NEW FILE: defines.h --- // $Id: defines.h,v 1.1 2004/07/20 17:51:34 tobgle Exp $ // // SuperTux // Copyright (C) 2000 Bill Kendrick <bi...@ne...> // Copyright (C) 2004 Tobias Glaesser <tob...@gm...> // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. #ifndef SUPERTUX_DEFINES_H #define SUPERTUX_DEFINES_H 1 #include <config.h> /* Version: */ #ifndef VERSION #define VERSION "0.1.1" #endif enum Direction { LEFT = 0, RIGHT = 1 }; /* Direction (keyboard/joystick) states: */ #define UP 0 #define DOWN 1 /* Dying types: */ /* ---- NO 0 */ enum DyingType { DYING_NOT = 0, DYING_SQUISHED = 1, DYING_FALLING = 2 }; /* Screen-related stuff */ // +1 is needed because when tiles are wrapping around the screen there // are two partial tiles on the screen #define VISIBLE_TILES_X (25 +1) #define VISIBLE_TILES_Y (19 +1) /* Speed constraints: */ #define MAX_WALK_XM 2.3 #define MAX_RUN_XM 3.2 #define MAX_YM 20.0 #define MAX_JUMP_TIME 375 #define MAX_LIVES 99 #define WALK_SPEED 1.0 #define RUN_SPEED 1.5 #define JUMP_SPEED 1.2 /* gameplay related defines */ #define START_LIVES 4 #define MAX_FIRE_BULLETS 2 #define MAX_ICE_BULLETS 1 #define FROZEN_TIME 3000 #define YM_FOR_JUMP 6.0 #define WALK_ACCELERATION_X 0.03 #define RUN_ACCELERATION_X 0.04 #define KILL_BOUNCE_YM 8.0 #define SKID_XM 2.0 #define SKID_TIME 200 /* Size constraints: */ #define X_OFFSCREEN_DISTANCE (screen->w/2) #define Y_OFFSCREEN_DISTANCE (screen->h/2) /* Debugging */ #ifdef DEBUG #define DEBUG_MSG( msg ) { \ printf( msg ); printf("\n"); \ } #else #define DEBUG_MSG( msg ) {} #endif #define UNUSED_ARG(a) do {/* null */} while (&a == 0) #endif /*SUPERTUX_DEFINES_H*/ --- NEW FILE: setup.cpp --- // $Id: setup.cpp,v 1.1 2004/07/20 17:51:34 tobgle Exp $ // // SuperTux - A Jump'n Run // Copyright (C) 2000 Bill Kendrick <bi...@ne...> // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <cassert> #include <cstdio> #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cerrno> #include <unistd.h> #include "SDL.h" #include "SDL_image.h" #ifndef NOOPENGL #include "SDL_opengl.h" #endif #include <sys/stat.h> #include <sys/types.h> #include <dirent.h> #ifndef WIN32 #include <libgen.h> #endif #include <cctype> #include "app/globals.h" #include "app/defines.h" #include "app/setup.h" #include "video/screen.h" #include "video/surface.h" #include "gui/menu.h" #include "utils/configfile.h" #include "audio/sound_manager.h" #include "app/gettext.h" #ifdef WIN32 #define mkdir(dir, mode) mkdir(dir) // on win32 we typically don't want LFS paths #undef DATA_PREFIX #define DATA_PREFIX "./data/" #endif /* Screen proprities: */ /* Don't use this to test for the actual screen sizes. Use screen->w/h instead! */ #define SCREEN_W 800 #define SCREEN_H 600 /* Local function prototypes: */ void seticon(void); void usage(char * prog, int ret); /* Does the given file exist and is it accessible? */ int faccessible(const char *filename) { struct stat filestat; if (stat(filename, &filestat) == -1) { return false; } else { if(S_ISREG(filestat.st_mode)) return true; else return false; } } /* Can we write to this location? */ int fwriteable(const char *filename) { FILE* fi; fi = fopen(filename, "wa"); if (fi == NULL) { return false; } return true; } /* Makes sure a directory is created in either the SuperTux home directory or the SuperTux base directory.*/ int fcreatedir(const char* relative_dir) { char path[1024]; snprintf(path, 1024, "%s/%s/", st_dir, relative_dir); if(mkdir(path,0755) != 0) { snprintf(path, 1024, "%s/%s/", datadir.c_str(), relative_dir); if(mkdir(path,0755) != 0) { return false; } else { return true; } } else { return true; } } FILE * opendata(const char * rel_filename, const char * mode) { char * filename = NULL; FILE * fi; filename = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen(rel_filename) + 1)); strcpy(filename, st_dir); /* Open the high score file: */ strcat(filename, rel_filename); /* Try opening the file: */ fi = fopen(filename, mode); if (fi == NULL) { fprintf(stderr, "Warning: Unable to open the file \"%s\" ", filename); if (strcmp(mode, "r") == 0) fprintf(stderr, "for read!!!\n"); else if (strcmp(mode, "w") == 0) fprintf(stderr, "for write!!!\n"); } free( filename ); return(fi); } /* Get all names of sub-directories in a certain directory. */ /* Returns the number of sub-directories found. */ /* Note: The user has to free the allocated space. */ string_list_type dsubdirs(const char *rel_path,const char* expected_file) { DIR *dirStructP; struct dirent *direntp; string_list_type sdirs; char filename[1024]; char path[1024]; string_list_init(&sdirs); sprintf(path,"%s/%s",st_dir,rel_path); if((dirStructP = opendir(path)) != NULL) { while((direntp = readdir(dirStructP)) != NULL) { char absolute_filename[1024]; struct stat buf; sprintf(absolute_filename, "%s/%s", path, direntp->d_name); if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode)) { if(expected_file != NULL) { sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file); if(!faccessible(filename)) continue; } string_list_add_item(&sdirs,direntp->d_name); } } closedir(dirStructP); } sprintf(path,"%s/%s",datadir.c_str(),rel_path); if((dirStructP = opendir(path)) != NULL) { while((direntp = readdir(dirStructP)) != NULL) { char absolute_filename[1024]; struct stat buf; sprintf(absolute_filename, "%s/%s", path, direntp->d_name); if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode)) { if(expected_file != NULL) { sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file); if(!faccessible(filename)) { continue; } else { sprintf(filename,"%s/%s/%s/%s",st_dir,rel_path,direntp->d_name,expected_file); if(faccessible(filename)) continue; } } string_list_add_item(&sdirs,direntp->d_name); } } closedir(dirStructP); } return sdirs; } string_list_type dfiles(const char *rel_path, const char* glob, const char* exception_str) { DIR *dirStructP; struct dirent *direntp; string_list_type sdirs; char path[1024]; string_list_init(&sdirs); sprintf(path,"%s/%s",st_dir,rel_path); if((dirStructP = opendir(path)) != NULL) { while((direntp = readdir(dirStructP)) != NULL) { char absolute_filename[1024]; struct stat buf; sprintf(absolute_filename, "%s/%s", path, direntp->d_name); if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode)) { if(exception_str != NULL) { if(strstr(direntp->d_name,exception_str) != NULL) continue; } if(glob != NULL) if(strstr(direntp->d_name,glob) == NULL) continue; string_list_add_item(&sdirs,direntp->d_name); } } closedir(dirStructP); } sprintf(path,"%s/%s",datadir.c_str(),rel_path); if((dirStructP = opendir(path)) != NULL) { while((direntp = readdir(dirStructP)) != NULL) { char absolute_filename[1024]; struct stat buf; sprintf(absolute_filename, "%s/%s", path, direntp->d_name); if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode)) { if(exception_str != NULL) { if(strstr(direntp->d_name,exception_str) != NULL) continue; } if(glob != NULL) if(strstr(direntp->d_name,glob) == NULL) continue; string_list_add_item(&sdirs,direntp->d_name); } } closedir(dirStructP); } return sdirs; } void free_strings(char **strings, int num) { int i; for(i=0; i < num; ++i) free(strings[i]); } /* --- SETUP --- */ /* Set SuperTux configuration and save directories */ void st_directory_setup(void) { char *home; char str[1024]; /* Get home directory (from $HOME variable)... if we can't determine it, use the current directory ("."): */ if (getenv("HOME") != NULL) home = getenv("HOME"); else home = "."; st_dir = (char *) malloc(sizeof(char) * (strlen(home) + strlen("/.supertux") + 1)); strcpy(st_dir, home); strcat(st_dir, "/.supertux"); /* Remove .supertux config-file from old SuperTux versions */ if(faccessible(st_dir)) { remove (st_dir); } st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1)); strcpy(st_save_dir,st_dir); strcat(st_save_dir,"/save"); /* Create them. In the case they exist they won't destroy anything. */ mkdir(st_dir, 0755); mkdir(st_save_dir, 0755); sprintf(str, "%s/levels", st_dir); mkdir(str, 0755); // User has not that a datadir, so we try some magic if (datadir.empty()) { #ifndef WIN32 // Detect datadir char exe_file[PATH_MAX]; if (readlink("/proc/self/exe", exe_file, PATH_MAX) < 0) { puts("Couldn't read /proc/self/exe, using default path: " DATA_PREFIX); datadir = DATA_PREFIX; } else { std::string exedir = std::string(dirname(exe_file)) + "/"; datadir = exedir + "../data"; // SuperTux run from source dir if (access(datadir.c_str(), F_OK) != 0) { datadir = exedir + "../share/supertux"; // SuperTux run from PATH if (access(datadir.c_str(), F_OK) != 0) { // If all fails, fall back to compiled path datadir = DATA_PREFIX; } } } #else datadir = DATA_PREFIX; #endif } printf("Datadir: %s\n", datadir.c_str()); } void st_general_setup(void) { /* Seed random number generator: */ srand(SDL_GetTicks()); /* Set icon image: */ seticon(); /* Unicode needed for input handling: */ SDL_EnableUNICODE(1); /* Load global images: */ gold_text = new Font(datadir + "/images/fonts/gold.png", Font::TEXT, 16,18); blue_text = new Font(datadir + "/images/fonts/blue.png", Font::TEXT, 16,18,3); white_text = new Font(datadir + "/images/fonts/white.png", Font::TEXT, 16,18); gray_text = new Font(datadir + "/images/fonts/gray.png", Font::TEXT, 16,18); white_small_text = new Font(datadir + "/images/fonts/white-small.png", Font::TEXT, 8,9, 1); white_big_text = new Font(datadir + "/images/fonts/white-big.png", Font::TEXT, 20,22, 3); yellow_nums = new Font(datadir + "/images/fonts/numbers.png", Font::NUM, 32,32); /* Load GUI/menu images: */ checkbox = new Surface(datadir + "/images/status/checkbox.png", true); checkbox_checked = new Surface(datadir + "/images/status/checkbox-checked.png", true); back = new Surface(datadir + "/images/status/back.png", true); arrow_left = new Surface(datadir + "/images/icons/left.png", true); arrow_right = new Surface(datadir + "/images/icons/right.png", true); /* Load the mouse-cursor */ mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1); MouseCursor::set_current(mouse_cursor); } void st_general_free(void) { /* Free global images: */ delete gold_text; delete white_text; delete blue_text; delete gray_text; delete white_small_text; delete white_big_text; delete yellow_nums; /* Free GUI/menu images: */ delete checkbox; delete checkbox_checked; delete back; delete arrow_left; delete arrow_right; /* Free mouse-cursor */ delete mouse_cursor; /* Free menus */ delete main_menu; delete game_menu; delete options_menu; delete options_keys_menu; delete options_joystick_menu; delete highscore_menu; delete contrib_menu; delete contrib_subset_menu; delete save_game_menu; delete load_game_menu; } void st_video_setup(void) { /* Init SDL Video: */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "\nError: I could not initialize video!\n" "The Simple DirectMedia error that occured was:\n" "%s\n\n", SDL_GetError()); exit(1); } /* Open display: */ if(use_gl) st_video_setup_gl(); else st_video_setup_sdl(); Surface::reload_all(); /* Set window manager stuff: */ SDL_WM_SetCaption("SuperTux " VERSION, "SuperTux"); } void st_video_setup_sdl(void) { if (use_fullscreen) { screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */ if (screen == NULL) { fprintf(stderr, "\nWarning: I could not set up fullscreen video for " "800x600 mode.\n" "The Simple DirectMedia error that occured was:\n" "%s\n\n", SDL_GetError()); use_fullscreen = false; } } else { screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_HWSURFACE | SDL_DOUBLEBUF ); if (screen == NULL) { fprintf(stderr, "\nError: I could not set up video for 800x600 mode.\n" "The Simple DirectMedia error that occured was:\n" "%s\n\n", SDL_GetError()); exit(1); } } } void st_video_setup_gl(void) { #ifndef NOOPENGL SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); if (use_fullscreen) { screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */ if (screen == NULL) { fprintf(stderr, "\nWarning: I could not set up fullscreen video for " "640x480 mode.\n" "The Simple DirectMedia error that occured was:\n" "%s\n\n", SDL_GetError()); use_fullscreen = false; } } else { screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_OPENGL); if (screen == NULL) { fprintf(stderr, "\nError: I could not set up video for 640x480 mode.\n" "The Simple DirectMedia error that occured was:\n" "%s\n\n", SDL_GetError()); exit(1); } } /* * Set up OpenGL for 2D rendering. */ glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glViewport(0, 0, screen->w, screen->h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, screen->w, screen->h, 0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, 0.0f); #endif } void st_joystick_setup(void) { /* Init Joystick: */ use_joystick = true; if (SDL_Init(SDL_INIT_JOYSTICK) < 0) { fprintf(stderr, "Warning: I could not initialize joystick!\n" "The Simple DirectMedia error that occured was:\n" "%s\n\n", SDL_GetError()); use_joystick = false; } else { /* Open joystick: */ if (SDL_NumJoysticks() <= 0) { fprintf(stderr, "Info: No joysticks were found.\n"); use_joystick = false; } else { js = SDL_JoystickOpen(joystick_num); if (js == NULL) { fprintf(stderr, "Warning: Could not open joystick %d.\n" "The Simple DirectMedia error that occured was:\n" "%s\n\n", joystick_num, SDL_GetError()); use_joystick = false; } else { if (SDL_JoystickNumAxes(js) < 2) { fprintf(stderr, "Warning: Joystick does not have enough axes!\n"); use_joystick = false; } else { if (SDL_JoystickNumButtons(js) < 2) { fprintf(stderr, "Warning: " "Joystick does not have enough buttons!\n"); use_joystick = false; } } } } } } void st_audio_setup(void) { /* Init SDL Audio silently even if --disable-sound : */ if (audio_device) { if (SDL_Init(SDL_INIT_AUDIO) < 0) { /* only print out message if sound or music was not disabled at command-line */ if (use_sound || use_music) { fprintf(stderr, "\nWarning: I could not initialize audio!\n" "The Simple DirectMedia error that occured was:\n" "%s\n\n", SDL_GetError()); } /* keep the programming logic the same :-) because in this case, use_sound & use_music' values are ignored when there's no available audio device */ use_sound = false; use_music = false; audio_device = false; } } /* Open sound silently regarless the value of "use_sound": */ if (audio_device) { if (open_audio(44100, AUDIO_S16, 2, 2048) < 0) { /* only print out message if sound or music was not disabled at command-line */ if (use_sound || use_music) { 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()); } use_sound = false; use_music = false; audio_device = false; } } } /* --- SHUTDOWN --- */ void st_shutdown(void) { close_audio(); SDL_Quit(); config->save(); } /* --- ABORT! --- */ void st_abort(const std::string& reason, const std::string& details) { fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str()); st_shutdown(); abort(); } /* Set Icon (private) */ void seticon(void) { // int masklen; // Uint8 * mask; SDL_Surface * icon; /* Load icon into a surface: */ icon = IMG_Load((datadir + "/images/supertux.xpm").c_str()); if (icon == NULL) { fprintf(stderr, "\nError: I could not load the icon image: %s%s\n" "The Simple DirectMedia error that occured was:\n" "%s\n\n", datadir.c_str(), "/images/supertux.xpm", SDL_GetError()); exit(1); } /* Create mask: */ /* masklen = (((icon -> w) + 7) / 8) * (icon -> h); mask = (Uint8*) malloc(masklen * sizeof(Uint8)); memset(mask, 0xFF, masklen); */ /* Set icon: */ SDL_WM_SetIcon(icon, NULL);//mask); /* Free icon surface & mask: */ // free(mask); SDL_FreeSurface(icon); } /* Parse command-line arguments: */ void parseargs(int argc, char * argv[]) { int i; config->load(); /* Parse arguments: */ for (i = 1; i < argc; i++) { if (strcmp(argv[i], "--fullscreen") == 0 || strcmp(argv[i], "-f") == 0) { use_fullscreen = true; } else if (strcmp(argv[i], "--window") == 0 || strcmp(argv[i], "-w") == 0) { use_fullscreen = false; } else if (strcmp(argv[i], "--joystick") == 0 || strcmp(argv[i], "-j") == 0) { assert(i+1 < argc); joystick_num = atoi(argv[++i]); } else if (strcmp(argv[i], "--joymap") == 0) { assert(i+1 < argc); if (sscanf(argv[++i], "%d:%d:%d:%d:%d", &joystick_keymap.x_axis, &joystick_keymap.y_axis, &joystick_keymap.a_button, &joystick_keymap.b_button, &joystick_keymap.start_button) != 5) { puts("Warning: Invalid or incomplete joymap, should be: 'XAXIS:YAXIS:A:B:START'"); } else { std::cout << "Using new joymap:\n" << " X-Axis: " << joystick_keymap.x_axis << "\n" << " Y-Axis: " << joystick_keymap.y_axis << "\n" << " A-Button: " << joystick_keymap.a_button << "\n" << " B-Button: " << joystick_keymap.b_button << "\n" << " Start-Button: " << joystick_keymap.start_button << std::endl; } } else if (strcmp(argv[i], "--leveleditor") == 0) { launch_leveleditor_mode = true; } else if (strcmp(argv[i], "--worldmap") == 0) { launch_worldmap_mode = true; } else if (strcmp(argv[i], "--datadir") == 0 || strcmp(argv[i], "-d") == 0 ) { assert(i+1 < argc); datadir = argv[++i]; } else if (strcmp(argv[i], "--show-fps") == 0) { /* Use full screen: */ show_fps = true; } else if (strcmp(argv[i], "--opengl") == 0 || strcmp(argv[i], "-gl") == 0) { #ifndef NOOPENGL /* Use OpengGL: */ use_gl = true; #endif } else if (strcmp(argv[i], "--sdl") == 0) { use_gl = false; } else if (strcmp(argv[i], "--usage") == 0) { /* Show usage: */ usage(argv[0], 0); } else if (strcmp(argv[i], "--version") == 0) { /* Show version: */ printf("SuperTux " VERSION "\n"); exit(0); } else if (strcmp(argv[i], "--disable-sound") == 0) { /* Disable the compiled in sound feature */ printf("Sounds disabled \n"); use_sound = false; audio_device = false; } else if (strcmp(argv[i], "--disable-music") == 0) { /* Disable the compiled in sound feature */ printf("Music disabled \n"); use_music = false; } else if (strcmp(argv[i], "--debug") == 0) { /* Enable the debug-mode */ debug_mode = true; } else if (strcmp(argv[i], "--help") == 0) { /* Show help: */ puts(_(" SuperTux " VERSION "\n" " Please see the file \"README.txt\" for more details.\n")); printf(_("Usage: %s [OPTIONS] FILENAME\n\n"), argv[0]); puts(_("Display Options:\n" " -f, --fullscreen Run in fullscreen mode.\n" " -w, --window Run in window mode.\n" " --opengl If OpenGL support was compiled in, this will tell\n" " SuperTux to make use of it.\n" " --sdl Use the SDL software graphical renderer\n" "\n" "Sound Options:\n" " --disable-sound If sound support was compiled in, this will\n" " disable sound for this session of the game.\n" " --disable-music Like above, but this will disable music.\n" "\n" "Misc Options:\n" " -j, --joystick NUM Use joystick NUM (default: 0)\n" " --joymap XAXIS:YAXIS:A:B:START\n" " Define how joystick buttons and axis should be mapped\n" " --leveleditor Opens the leveleditor in a file.\n" " --worldmap Opens the specified worldmap file.\n" " -d, --datadir DIR Load Game data from DIR (default: automatic)\n" " --debug Enables the debug mode, which is useful for developers.\n" " --help Display a help message summarizing command-line\n" " options, license and game controls.\n" " --usage Display a brief message summarizing command-line options.\n" " --version Display the version of SuperTux you're running.\n\n" )); exit(0); } else if (argv[i][0] != '-') { level_startup_file = argv[i]; } else { /* Unknown - complain! */ usage(argv[0], 1); } } } /* Display usage: */ void usage(char * prog, int ret) { FILE * fi; /* Determine which stream to write to: */ if (ret == 0) fi = stdout; else fi = stderr; /* Display the usage message: */ fprintf(fi, _("Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug] | [--usage | --help | --version] [--leveleditor] [--worldmap] FILENAME\n"), prog); /* Quit! */ exit(ret); } std::vector<std::string> read_directory(const std::string& pathname) { std::vector<std::string> dirnames; DIR* dir = opendir(pathname.c_str()); if (dir) { struct dirent *direntp; while((direntp = readdir(dir))) { dirnames.push_back(direntp->d_name); } closedir(dir); } return dirnames; } /* EOF */ --- NEW FILE: setup.h --- // $Id: setup.h,v 1.1 2004/07/20 17:51:34 tobgle Exp $ // // SuperTux - A Jump'n Run // Copyright (C) 2000 Bill Kendrick <bi...@ne...> // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef SUPERTUX_SETUP_H #define SUPERTUX_SETUP_H #include <vector> #include <string> #include "gui/menu.h" #include "audio/sound.h" #include "special/base.h" int faccessible(const char *filename); int fcreatedir(const char* relative_dir); int fwriteable(const char *filename); std::vector<std::string> read_directory(const std::string& pathname); FILE * opendata(const char * filename, const char * mode); string_list_type dsubdirs(const char *rel_path, const char* expected_file); string_list_type dfiles(const char *rel_path, const char* glob, const char* exception_str); void free_strings(char **strings, int num); void st_directory_setup(void); void st_general_setup(void); void st_general_free(); void st_video_setup_sdl(void); void st_video_setup_gl(void); void st_video_setup(void); void st_audio_setup(void); void st_joystick_setup(void); void st_shutdown(void); void st_abort(const std::string& reason, const std::string& details); void parseargs(int argc, char * argv[]); #endif /*SUPERTUX_SETUP_H*/ --- NEW FILE: globals.cpp --- // $Id: globals.cpp,v 1.1 2004/07/20 17:51:34 tobgle Exp $ // // SuperTux // Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. #include "app/globals.h" /** The datadir prefix prepended when loading game data file */ std::string datadir; JoystickKeymap::JoystickKeymap() { a_button = 0; b_button = 1; start_button = 2; x_axis = 0; y_axis = 1; dead_zone = 4096; } JoystickKeymap joystick_keymap; SDL_Surface * screen; Font* gold_text; Font* blue_text; Font* gray_text; Font* yellow_nums; Font* white_text; Font* white_small_text; Font* white_big_text; MouseCursor * mouse_cursor; bool use_gl; bool use_joystick; bool use_fullscreen; bool debug_mode; bool show_fps; float game_speed = 1.0f; int joystick_num = 0; char* level_startup_file = 0; bool launch_leveleditor_mode = false; bool launch_worldmap_mode = false; /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */ char *st_dir, *st_save_dir; SDL_Joystick * js; /* Returns 1 for every button event, 2 for a quit event and 0 for no event. */ int wait_for_event(SDL_Event& event,unsigned int min_delay, unsigned int max_delay, bool empty_events) { int i; Timer maxdelay; Timer mindelay; maxdelay.init(false); mindelay.init(false); if(max_delay < min_delay) max_delay = min_delay; maxdelay.start(max_delay); mindelay.start(min_delay); if(empty_events) while (SDL_PollEvent(&event)) {} /* Handle events: */ for(i = 0; maxdelay.check() || !i; ++i) { while (SDL_PollEvent(&event)) { if(!mindelay.check()) { if (event.type == SDL_QUIT) { /* Quit event - quit: */ return 2; } else if (event.type == SDL_KEYDOWN) { /* Keypress - skip intro: */ return 1; } else if (event.type == SDL_JOYBUTTONDOWN) { /* Fire button - skip intro: */ return 1; } else if (event.type == SDL_MOUSEBUTTONDOWN) { /* Mouse button - skip intro: */ return 1; } } } SDL_Delay(10); } return 0; } --- NEW FILE: globals.h --- // $Id: globals.h,v 1.1 2004/07/20 17:51:34 tobgle Exp $ // // SuperTux // Copyright (C) 2004 Bill Kendrick <bi...@ne...> // Tobias Glaesser <tob...@gm...> // Ingo Ruhnke <gr...@gm...> // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef SUPERTUX_GLOBALS_H #define SUPERTUX_GLOBALS_H #include <string> #include "SDL.h" #include "video/font.h" #include "gui/menu.h" #include "gui/mousecursor.h" extern std::string datadir; struct JoystickKeymap { int a_button; int b_button; int start_button; int x_axis; int y_axis; int dead_zone; JoystickKeymap(); }; extern JoystickKeymap joystick_keymap; extern SDL_Surface* screen; extern Font* gold_text; extern Font* white_text; extern Font* blue_text; extern Font* gray_text; extern Font* white_small_text; extern Font* white_big_text; extern Font* yellow_nums; extern MouseCursor * mouse_cursor; extern bool use_gl; extern bool use_joystick; extern bool use_fullscreen; extern bool debug_mode; extern bool show_fps; /** The number of the joystick that will be use in the game */ extern int joystick_num; extern char* level_startup_file; extern bool launch_leveleditor_mode; extern bool launch_worldmap_mode; /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */ extern char* st_dir; extern char* st_save_dir; extern float game_speed; extern SDL_Joystick * js; int wait_for_event(SDL_Event& event,unsigned int min_delay = 0, unsigned int max_delay = 0, bool empty_events = false); #endif /* SUPERTUX_GLOBALS_H */ --- NEW FILE: gettext.h --- /* Convenience header for conditional use of GNU <libintl.h>. Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _LIBGETTEXT_H #define _LIBGETTEXT_H 1 #ifdef HAVE_GETTEXT # define _(String) gettext(String) # define N_(String) gettext_noop(String) #else # define _(String) String # define N_(String) String #endif /* NLS can be disabled through the configure --disable-nls option. */ #if ENABLE_NLS /* Get declarations of GNU message catalog functions. */ #include <libintl.h> #else /* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which chokes if dcgettext is defined as a macro. So include it now, to make later inclusions of <locale.h> a NOP. We don't include <libintl.h> as well because people using "gettext.h" will not include <libintl.h>, and also including <libintl.h> would fail on SunOS 4, whereas <locale.h> is OK. */ #if defined(__sun) # include <locale.h> #endif #ifndef gettext /* Disabled NLS. The casts to 'const char *' serve the purpose of producing warnings for invalid uses of the value returned from these functions. On pre-ANSI systems without 'const', the config.h file is supposed to contain "#define const". */ # define gettext(Msgid) ((const char *) (Msgid)) # define dgettext(Domainname, Msgid) ((const char *) (Msgid)) # define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) # define ngettext(Msgid1, Msgid2, N) \ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) # define dngettext(Domainname, Msgid1, Msgid2, N) \ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) # define textdomain(Domainname) ((const char *) (Domainname)) # define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) # define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset)) #endif #endif /* A pseudo function call that serves as a marker for the automated extraction of messages, but does not call gettext(). The run-time translation is done at a different place in the code. The argument, String, should be a literal string. Concatenated strings and other string expressions won't work. The macro's expansion is not parenthesized, so that it is suitable as initializer for static 'char[]' or 'const char[]' variables. */ #define gettext_noop(String) String #endif /* _LIBGETTEXT_H */ |