3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include <SDL_image.h>
31 #include <SDL_opengl.h>
35 #include <sys/types.h>
49 #include "configfile.h"
52 #include "resources.h"
54 #include "music_manager.h"
59 #define mkdir(dir, mode) mkdir(dir)
60 // on win32 we typically don't want LFS paths
62 #define DATA_PREFIX "./data/"
65 /* Local function prototypes: */
68 void usage(char * prog, int ret);
70 /* Does the given file exist and is it accessible? */
71 int faccessible(const char *filename)
74 if (stat(filename, &filestat) == -1)
80 if(S_ISREG(filestat.st_mode))
87 /* Can we write to this location? */
88 int fwriteable(const char *filename)
91 fi = fopen(filename, "wa");
99 /* Makes sure a directory is created in either the SuperTux home directory or the SuperTux base directory.*/
100 int fcreatedir(const char* relative_dir)
103 snprintf(path, 1024, "%s/%s/", st_dir, relative_dir);
104 if(mkdir(path,0755) != 0)
106 snprintf(path, 1024, "%s/%s/", datadir.c_str(), relative_dir);
107 if(mkdir(path,0755) != 0)
122 FILE * opendata(const char * rel_filename, const char * mode)
124 char * filename = NULL;
127 filename = (char *) malloc(sizeof(char) * (strlen(st_dir) +
128 strlen(rel_filename) + 1));
130 strcpy(filename, st_dir);
131 /* Open the high score file: */
133 strcat(filename, rel_filename);
135 /* Try opening the file: */
136 fi = fopen(filename, mode);
140 fprintf(stderr, "Warning: Unable to open the file \"%s\" ", filename);
142 if (strcmp(mode, "r") == 0)
143 fprintf(stderr, "for read!!!\n");
144 else if (strcmp(mode, "w") == 0)
145 fprintf(stderr, "for write!!!\n");
152 /* Get all names of sub-directories in a certain directory. */
153 /* Returns the number of sub-directories found. */
154 /* Note: The user has to free the allocated space. */
155 string_list_type dsubdirs(const char *rel_path,const char* expected_file)
158 struct dirent *direntp;
159 string_list_type sdirs;
163 string_list_init(&sdirs);
164 sprintf(path,"%s/%s",st_dir,rel_path);
165 if((dirStructP = opendir(path)) != NULL)
167 while((direntp = readdir(dirStructP)) != NULL)
169 char absolute_filename[1024];
172 sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
174 if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode))
176 if(expected_file != NULL)
178 sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file);
179 if(!faccessible(filename))
183 string_list_add_item(&sdirs,direntp->d_name);
186 closedir(dirStructP);
189 sprintf(path,"%s/%s",datadir.c_str(),rel_path);
190 if((dirStructP = opendir(path)) != NULL)
192 while((direntp = readdir(dirStructP)) != NULL)
194 char absolute_filename[1024];
197 sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
199 if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode))
201 if(expected_file != NULL)
203 sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file);
204 if(!faccessible(filename))
210 sprintf(filename,"%s/%s/%s/%s",st_dir,rel_path,direntp->d_name,expected_file);
211 if(faccessible(filename))
216 string_list_add_item(&sdirs,direntp->d_name);
219 closedir(dirStructP);
225 string_list_type dfiles(const char *rel_path, const char* glob, const char* exception_str)
228 struct dirent *direntp;
229 string_list_type sdirs;
232 string_list_init(&sdirs);
233 sprintf(path,"%s/%s",st_dir,rel_path);
234 if((dirStructP = opendir(path)) != NULL)
236 while((direntp = readdir(dirStructP)) != NULL)
238 char absolute_filename[1024];
241 sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
243 if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode))
245 if(exception_str != NULL)
247 if(strstr(direntp->d_name,exception_str) != NULL)
251 if(strstr(direntp->d_name,glob) == NULL)
254 string_list_add_item(&sdirs,direntp->d_name);
257 closedir(dirStructP);
260 sprintf(path,"%s/%s",datadir.c_str(),rel_path);
261 if((dirStructP = opendir(path)) != NULL)
263 while((direntp = readdir(dirStructP)) != NULL)
265 char absolute_filename[1024];
268 sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
270 if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode))
272 if(exception_str != NULL)
274 if(strstr(direntp->d_name,exception_str) != NULL)
278 if(strstr(direntp->d_name,glob) == NULL)
281 string_list_add_item(&sdirs,direntp->d_name);
284 closedir(dirStructP);
290 void free_strings(char **strings, int num)
293 for(i=0; i < num; ++i)
298 /* Set SuperTux configuration and save directories */
299 void st_directory_setup(void)
303 /* Get home directory (from $HOME variable)... if we can't determine it,
304 use the current directory ("."): */
305 if (getenv("HOME") != NULL)
306 home = getenv("HOME");
310 st_dir = (char *) malloc(sizeof(char) * (strlen(home) +
311 strlen("/.supertux") + 1));
312 strcpy(st_dir, home);
313 strcat(st_dir, "/.supertux");
315 /* Remove .supertux config-file from old SuperTux versions */
316 if(faccessible(st_dir))
322 st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1));
324 strcpy(st_save_dir,st_dir);
325 strcat(st_save_dir,"/save");
327 /* Create them. In the case they exist they won't destroy anything. */
329 mkdir(st_save_dir, 0755);
331 sprintf(str, "%s/levels", st_dir);
334 // User has not that a datadir, so we try some magic
339 char exe_file[PATH_MAX];
340 if (readlink("/proc/self/exe", exe_file, PATH_MAX) < 0)
342 puts("Couldn't read /proc/self/exe, using default path: " DATA_PREFIX);
343 datadir = DATA_PREFIX;
347 std::string exedir = std::string(dirname(exe_file)) + "/";
349 datadir = exedir + "../data"; // SuperTux run from source dir
350 if (access(datadir.c_str(), F_OK) != 0)
352 datadir = exedir + "../share/supertux"; // SuperTux run from PATH
353 if (access(datadir.c_str(), F_OK) != 0)
354 { // If all fails, fall back to compiled path
355 datadir = DATA_PREFIX;
360 datadir = DATA_PREFIX;
363 printf("Datadir: %s\n", datadir.c_str());
366 /* Create and setup menus. */
369 main_menu = new Menu();
370 options_menu = new Menu();
371 options_keys_menu = new Menu();
372 options_joystick_menu = new Menu();
373 load_game_menu = new Menu();
374 save_game_menu = new Menu();
375 game_menu = new Menu();
376 highscore_menu = new Menu();
377 contrib_menu = new Menu();
378 contrib_subset_menu = new Menu();
379 worldmap_menu = new Menu();
381 main_menu->set_pos(screen->w/2, 335);
382 main_menu->additem(MN_GOTO, "Start Game",0,load_game_menu, MNID_STARTGAME);
383 main_menu->additem(MN_GOTO, "Contrib Levels",0,contrib_menu, MNID_CONTRIB);
384 main_menu->additem(MN_GOTO, "Options",0,options_menu, MNID_OPTIONMENU);
385 main_menu->additem(MN_ACTION,"Level editor",0,0, MNID_LEVELEDITOR);
386 main_menu->additem(MN_ACTION,"Credits",0,0, MNID_CREDITS);
387 main_menu->additem(MN_ACTION,"Quit",0,0, MNID_QUITMAINMENU);
389 options_menu->additem(MN_LABEL,"Options",0,0);
390 options_menu->additem(MN_HL,"",0,0);
392 options_menu->additem(MN_TOGGLE,"OpenGL",use_gl,0, MNID_OPENGL);
394 options_menu->additem(MN_DEACTIVE,"OpenGL (not supported)",use_gl,MNID_OPENGL);
396 options_menu->additem(MN_TOGGLE,"Fullscreen",use_fullscreen,0, MNID_FULLSCREEN);
399 options_menu->additem(MN_TOGGLE,"Sound ", use_sound,0, MNID_SOUND);
400 options_menu->additem(MN_TOGGLE,"Music ", use_music,0, MNID_MUSIC);
404 options_menu->additem(MN_DEACTIVE,"Sound ", false,0, MNID_SOUND);
405 options_menu->additem(MN_DEACTIVE,"Music ", false,0, MNID_MUSIC);
407 options_menu->additem(MN_TOGGLE,"Show FPS ",show_fps,0, MNID_SHOWFPS);
408 options_menu->additem(MN_GOTO,"Key Setup",0,options_keys_menu);
410 options_menu->additem(MN_GOTO,"Joystick Setup",0,options_joystick_menu);
411 options_menu->additem(MN_HL,"",0,0);
412 options_menu->additem(MN_BACK,"Back",0,0);
414 options_keys_menu->additem(MN_LABEL,"Key Setup",0,0);
415 options_keys_menu->additem(MN_HL,"",0,0);
416 options_keys_menu->additem(MN_CONTROLFIELD,"Left move", 0,0, 0,&keymap.left);
417 options_keys_menu->additem(MN_CONTROLFIELD,"Right move", 0,0, 0,&keymap.right);
418 options_keys_menu->additem(MN_CONTROLFIELD,"Jump", 0,0, 0,&keymap.jump);
419 options_keys_menu->additem(MN_CONTROLFIELD,"Duck", 0,0, 0,&keymap.duck);
420 options_keys_menu->additem(MN_CONTROLFIELD,"Power", 0,0, 0,&keymap.fire);
421 options_keys_menu->additem(MN_HL,"",0,0);
422 options_keys_menu->additem(MN_BACK,"Back",0,0);
426 options_joystick_menu->additem(MN_LABEL,"Joystick Setup",0,0);
427 options_joystick_menu->additem(MN_HL,"",0,0);
428 options_joystick_menu->additem(MN_CONTROLFIELD,"X axis", 0,0, 0,&joystick_keymap.x_axis);
429 options_joystick_menu->additem(MN_CONTROLFIELD,"Y axis", 0,0, 0,&joystick_keymap.y_axis);
430 options_joystick_menu->additem(MN_CONTROLFIELD,"A button", 0,0, 0,&joystick_keymap.a_button);
431 options_joystick_menu->additem(MN_CONTROLFIELD,"B button", 0,0, 0,&joystick_keymap.b_button);
432 options_joystick_menu->additem(MN_CONTROLFIELD,"Start", 0,0, 0,&joystick_keymap.start_button);
433 options_joystick_menu->additem(MN_CONTROLFIELD,"DeadZone", 0,0, 0,&joystick_keymap.dead_zone);
434 options_joystick_menu->additem(MN_HL,"",0,0);
435 options_joystick_menu->additem(MN_BACK,"Back",0,0);
438 load_game_menu->additem(MN_LABEL,"Start Game",0,0);
439 load_game_menu->additem(MN_HL,"",0,0);
440 load_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0, 1);
441 load_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0, 2);
442 load_game_menu->additem(MN_DEACTIVE,"Slot 3",0,0, 3);
443 load_game_menu->additem(MN_DEACTIVE,"Slot 4",0,0, 4);
444 load_game_menu->additem(MN_DEACTIVE,"Slot 5",0,0, 5);
445 load_game_menu->additem(MN_HL,"",0,0);
446 load_game_menu->additem(MN_BACK,"Back",0,0);
448 save_game_menu->additem(MN_LABEL,"Save Game",0,0);
449 save_game_menu->additem(MN_HL,"",0,0);
450 save_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0, 1);
451 save_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0, 2);
452 save_game_menu->additem(MN_DEACTIVE,"Slot 3",0,0, 3);
453 save_game_menu->additem(MN_DEACTIVE,"Slot 4",0,0, 4);
454 save_game_menu->additem(MN_DEACTIVE,"Slot 5",0,0, 5);
455 save_game_menu->additem(MN_HL,"",0,0);
456 save_game_menu->additem(MN_BACK,"Back",0,0);
458 game_menu->additem(MN_LABEL,"Pause",0,0);
459 game_menu->additem(MN_HL,"",0,0);
460 game_menu->additem(MN_ACTION,"Continue",0,0,MNID_CONTINUE);
461 game_menu->additem(MN_GOTO,"Options",0,options_menu);
462 game_menu->additem(MN_HL,"",0,0);
463 game_menu->additem(MN_ACTION,"Abort Level",0,0,MNID_ABORTLEVEL);
465 worldmap_menu->additem(MN_LABEL,"Pause",0,0);
466 worldmap_menu->additem(MN_HL,"",0,0);
467 worldmap_menu->additem(MN_ACTION,"Continue",0,0,MNID_RETURNWORLDMAP);
468 worldmap_menu->additem(MN_ACTION,"Save",0,0,MNID_SAVEGAME);
469 worldmap_menu->additem(MN_GOTO,"Options",0,options_menu);
470 worldmap_menu->additem(MN_HL,"",0,0);
471 worldmap_menu->additem(MN_ACTION,"Quit Game",0,0,MNID_QUITWORLDMAP);
473 highscore_menu->additem(MN_TEXTFIELD,"Enter your name:",0,0);
476 void update_load_save_game_menu(Menu* pmenu)
478 for(int i = 2; i < 7; ++i)
480 // FIXME: Insert a real savegame struct/class here instead of
481 // doing string vodoo
482 std::string tmp = slotinfo(i - 1);
483 pmenu->item[i].kind = MN_ACTION;
484 pmenu->item[i].change_text(tmp.c_str());
488 bool process_load_game_menu()
490 int slot = load_game_menu->check();
492 if(slot != -1 && load_game_menu->get_item_by_id(slot).kind == MN_ACTION)
495 snprintf(slotfile, 1024, "%s/slot%d.stsg", st_save_dir, slot);
497 if (access(slotfile, F_OK) != 0)
503 WorldMapNS::WorldMap worldmap;
505 // Load the game or at least set the savegame_file variable
506 worldmap.loadgame(slotfile);
510 Menu::set_current(main_menu);
512 st_pause_ticks_stop();
521 /* Handle changes made to global settings in the options menu. */
522 void process_options_menu(void)
524 switch (options_menu->check())
528 if(use_gl != options_menu->isToggled(MNID_OPENGL))
534 options_menu->get_item_by_id(MNID_OPENGL).toggled = false;
537 case MNID_FULLSCREEN:
538 if(use_fullscreen != options_menu->isToggled(MNID_FULLSCREEN))
540 use_fullscreen = !use_fullscreen;
545 if(use_sound != options_menu->isToggled(MNID_SOUND))
546 use_sound = !use_sound;
549 if(use_music != options_menu->isToggled(MNID_MUSIC))
551 use_music = !use_music;
552 music_manager->enable_music(use_music);
556 if(show_fps != options_menu->isToggled(MNID_SHOWFPS))
557 show_fps = !show_fps;
562 void st_general_setup(void)
564 /* Seed random number generator: */
566 srand(SDL_GetTicks());
568 /* Set icon image: */
572 /* Unicode needed for input handling: */
574 SDL_EnableUNICODE(1);
576 /* Load global images: */
578 black_text = new Text(datadir + "/images/status/letters-black.png", TEXT_TEXT, 16,18);
579 gold_text = new Text(datadir + "/images/status/letters-gold.png", TEXT_TEXT, 16,18);
580 blue_text = new Text(datadir + "/images/status/letters-blue.png", TEXT_TEXT, 16,18);
581 red_text = new Text(datadir + "/images/status/letters-red.png", TEXT_TEXT, 16,18);
582 white_text = new Text(datadir + "/images/status/letters-white.png", TEXT_TEXT, 16,18);
583 white_small_text = new Text(datadir + "/images/status/letters-white-small.png", TEXT_TEXT, 8,9);
584 white_big_text = new Text(datadir + "/images/status/letters-white-big.png", TEXT_TEXT, 20,23);
585 yellow_nums = new Text(datadir + "/images/status/numbers.png", TEXT_NUM, 32,32);
587 /* Load GUI/menu images: */
588 checkbox = new Surface(datadir + "/images/status/checkbox.png", USE_ALPHA);
589 checkbox_checked = new Surface(datadir + "/images/status/checkbox-checked.png", USE_ALPHA);
590 back = new Surface(datadir + "/images/status/back.png", USE_ALPHA);
591 arrow_left = new Surface(datadir + "/images/icons/left.png", USE_ALPHA);
592 arrow_right = new Surface(datadir + "/images/icons/right.png", USE_ALPHA);
594 /* Load the mouse-cursor */
595 mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1);
599 void st_general_free(void)
602 /* Free global images: */
609 delete white_small_text;
610 delete white_big_text;
612 /* Free GUI/menu images: */
614 delete checkbox_checked;
619 /* Free mouse-cursor */
626 delete highscore_menu;
627 delete save_game_menu;
628 delete load_game_menu;
631 void st_video_setup(void)
634 SDL_FreeSurface(screen);
636 /* Init SDL Video: */
638 if (SDL_Init(SDL_INIT_VIDEO) < 0)
641 "\nError: I could not initialize video!\n"
642 "The Simple DirectMedia error that occured was:\n"
643 "%s\n\n", SDL_GetError());
651 st_video_setup_sdl();
653 Surface::reload_all();
655 /* Set window manager stuff: */
656 SDL_WM_SetCaption("SuperTux " VERSION, "SuperTux");
659 void st_video_setup_sdl(void)
661 SDL_FreeSurface(screen);
665 screen = SDL_SetVideoMode(640, 480, 0, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
669 "\nWarning: I could not set up fullscreen video for "
671 "The Simple DirectMedia error that occured was:\n"
672 "%s\n\n", SDL_GetError());
673 use_fullscreen = false;
678 screen = SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE | SDL_DOUBLEBUF );
683 "\nError: I could not set up video for 640x480 mode.\n"
684 "The Simple DirectMedia error that occured was:\n"
685 "%s\n\n", SDL_GetError());
691 void st_video_setup_gl(void)
695 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
696 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
697 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
698 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
699 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
703 screen = SDL_SetVideoMode(640, 480, 0, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */
707 "\nWarning: I could not set up fullscreen video for "
709 "The Simple DirectMedia error that occured was:\n"
710 "%s\n\n", SDL_GetError());
711 use_fullscreen = false;
716 screen = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
721 "\nError: I could not set up video for 640x480 mode.\n"
722 "The Simple DirectMedia error that occured was:\n"
723 "%s\n\n", SDL_GetError());
729 * Set up OpenGL for 2D rendering.
731 glDisable(GL_DEPTH_TEST);
732 glDisable(GL_CULL_FACE);
734 glViewport(0, 0, screen->w, screen->h);
735 glMatrixMode(GL_PROJECTION);
737 glOrtho(0, screen->w, screen->h, 0, -1.0, 1.0);
739 glMatrixMode(GL_MODELVIEW);
741 glTranslatef(0.0f, 0.0f, 0.0f);
747 void st_joystick_setup(void)
754 if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
756 fprintf(stderr, "Warning: I could not initialize joystick!\n"
757 "The Simple DirectMedia error that occured was:\n"
758 "%s\n\n", SDL_GetError());
760 use_joystick = false;
765 if (SDL_NumJoysticks() <= 0)
767 fprintf(stderr, "Warning: No joysticks are available.\n");
769 use_joystick = false;
773 js = SDL_JoystickOpen(joystick_num);
777 fprintf(stderr, "Warning: Could not open joystick %d.\n"
778 "The Simple DirectMedia error that occured was:\n"
779 "%s\n\n", joystick_num, SDL_GetError());
781 use_joystick = false;
785 if (SDL_JoystickNumAxes(js) < 2)
788 "Warning: Joystick does not have enough axes!\n");
790 use_joystick = false;
794 if (SDL_JoystickNumButtons(js) < 2)
798 "Joystick does not have enough buttons!\n");
800 use_joystick = false;
808 void st_audio_setup(void)
811 /* Init SDL Audio silently even if --disable-sound : */
815 if (SDL_Init(SDL_INIT_AUDIO) < 0)
817 /* only print out message if sound or music
818 was not disabled at command-line
820 if (use_sound || use_music)
823 "\nWarning: I could not initialize audio!\n"
824 "The Simple DirectMedia error that occured was:\n"
825 "%s\n\n", SDL_GetError());
827 /* keep the programming logic the same :-)
828 because in this case, use_sound & use_music' values are ignored
829 when there's no available audio device
833 audio_device = false;
838 /* Open sound silently regarless the value of "use_sound": */
842 if (open_audio(44100, AUDIO_S16, 2, 2048) < 0)
844 /* only print out message if sound or music
845 was not disabled at command-line
847 if (use_sound || use_music)
850 "\nWarning: I could not set up audio for 44100 Hz "
852 "The Simple DirectMedia error that occured was:\n"
853 "%s\n\n", SDL_GetError());
857 audio_device = false;
864 /* --- SHUTDOWN --- */
866 void st_shutdown(void)
875 void st_abort(const std::string& reason, const std::string& details)
877 fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str());
882 /* Set Icon (private) */
891 /* Load icon into a surface: */
893 icon = IMG_Load((datadir + "/images/icon.xpm").c_str());
897 "\nError: I could not load the icon image: %s%s\n"
898 "The Simple DirectMedia error that occured was:\n"
899 "%s\n\n", datadir.c_str(), "/images/icon.xpm", SDL_GetError());
906 masklen = (((icon -> w) + 7) / 8) * (icon -> h);
907 mask = (Uint8*) malloc(masklen * sizeof(Uint8));
908 memset(mask, 0xFF, masklen);
913 SDL_WM_SetIcon(icon, NULL);//mask);
916 /* Free icon surface & mask: */
919 SDL_FreeSurface(icon);
923 /* Parse command-line arguments: */
925 void parseargs(int argc, char * argv[])
931 /* Parse arguments: */
933 for (i = 1; i < argc; i++)
935 if (strcmp(argv[i], "--fullscreen") == 0 ||
936 strcmp(argv[i], "-f") == 0)
938 /* Use full screen: */
940 use_fullscreen = true;
942 else if (strcmp(argv[i], "--joystick") == 0 || strcmp(argv[i], "-j") == 0)
945 joystick_num = atoi(argv[++i]);
947 else if (strcmp(argv[i], "--joymap") == 0)
950 if (sscanf(argv[++i],
952 &joystick_keymap.x_axis,
953 &joystick_keymap.y_axis,
954 &joystick_keymap.a_button,
955 &joystick_keymap.b_button,
956 &joystick_keymap.start_button) != 5)
958 puts("Warning: Invalid or incomplete joymap, should be: 'XAXIS:YAXIS:A:B:START'");
962 std::cout << "Using new joymap:\n"
963 << " X-Axis: " << joystick_keymap.x_axis << "\n"
964 << " Y-Axis: " << joystick_keymap.y_axis << "\n"
965 << " A-Button: " << joystick_keymap.a_button << "\n"
966 << " B-Button: " << joystick_keymap.b_button << "\n"
967 << " Start-Button: " << joystick_keymap.start_button << std::endl;
970 else if (strcmp(argv[i], "--worldmap") == 0)
972 launch_worldmap_mode = true;
974 else if (strcmp(argv[i], "--datadir") == 0
975 || strcmp(argv[i], "-d") == 0 )
980 else if (strcmp(argv[i], "--show-fps") == 0)
982 /* Use full screen: */
986 else if (strcmp(argv[i], "--opengl") == 0 ||
987 strcmp(argv[i], "-gl") == 0)
995 else if (strcmp(argv[i], "--sdl") == 0)
999 else if (strcmp(argv[i], "--usage") == 0)
1005 else if (strcmp(argv[i], "--version") == 0)
1008 printf("SuperTux " VERSION "\n");
1011 else if (strcmp(argv[i], "--disable-sound") == 0)
1013 /* Disable the compiled in sound feature */
1014 printf("Sounds disabled \n");
1016 audio_device = false;
1018 else if (strcmp(argv[i], "--disable-music") == 0)
1020 /* Disable the compiled in sound feature */
1021 printf("Music disabled \n");
1024 else if (strcmp(argv[i], "--debug-mode") == 0)
1026 /* Enable the debug-mode */
1030 else if (strcmp(argv[i], "--help") == 0)
1032 puts("Super Tux " VERSION "\n"
1033 " Please see the file \"README.txt\" for more details.\n");
1034 printf("Usage: %s [OPTIONS] FILENAME\n\n", argv[0]);
1035 puts("Display Options:\n"
1036 " --fullscreen Run in fullscreen mode.\n"
1037 " --opengl If opengl support was compiled in, this will enable\n"
1038 " the EXPERIMENTAL OpenGL mode.\n"
1039 " --sdl Use non-opengl renderer\n"
1042 " --disable-sound If sound support was compiled in, this will\n"
1043 " disable sound for this session of the game.\n"
1044 " --disable-music Like above, but this will disable music.\n"
1047 " -j, --joystick NUM Use joystick NUM (default: 0)\n"
1048 " --joymap XAXIS:YAXIS:A:B:START\n"
1049 " Define how joystick buttons and axis should be mapped\n"
1050 " --worldmap Start in worldmap-mode (EXPERIMENTAL)\n"
1051 " -d, --datadir DIR Load Game data from DIR (default: automatic)\n"
1052 " --debug-mode Enables the debug-mode, which is useful for developers.\n"
1053 " --help Display a help message summarizing command-line\n"
1054 " options, license and game controls.\n"
1055 " --usage Display a brief message summarizing command-line options.\n"
1056 " --version Display the version of SuperTux you're running.\n\n"
1060 else if (argv[i][0] != '-')
1062 level_startup_file = argv[i];
1066 /* Unknown - complain! */
1074 /* Display usage: */
1076 void usage(char * prog, int ret)
1081 /* Determine which stream to write to: */
1089 /* Display the usage message: */
1091 fprintf(fi, "Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug-mode] | [--usage | --help | --version] [--worldmap] FILENAME\n",