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>
45 #include "screen/screen.h"
46 #include "screen/texture.h"
49 #include "configfile.h"
52 #include "resources.h"
54 #include "sound_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 /* Screen proprities: */
66 /* Don't use this to test for the actual screen sizes. Use screen->w/h instead! */
70 /* Local function prototypes: */
73 void usage(char * prog, int ret);
75 /* Does the given file exist and is it accessible? */
76 int faccessible(const char *filename)
79 if (stat(filename, &filestat) == -1)
85 if(S_ISREG(filestat.st_mode))
92 /* Can we write to this location? */
93 int fwriteable(const char *filename)
96 fi = fopen(filename, "wa");
104 /* Makes sure a directory is created in either the SuperTux home directory or the SuperTux base directory.*/
105 int fcreatedir(const char* relative_dir)
108 snprintf(path, 1024, "%s/%s/", st_dir, relative_dir);
109 if(mkdir(path,0755) != 0)
111 snprintf(path, 1024, "%s/%s/", datadir.c_str(), relative_dir);
112 if(mkdir(path,0755) != 0)
127 FILE * opendata(const char * rel_filename, const char * mode)
129 char * filename = NULL;
132 filename = (char *) malloc(sizeof(char) * (strlen(st_dir) +
133 strlen(rel_filename) + 1));
135 strcpy(filename, st_dir);
136 /* Open the high score file: */
138 strcat(filename, rel_filename);
140 /* Try opening the file: */
141 fi = fopen(filename, mode);
145 fprintf(stderr, "Warning: Unable to open the file \"%s\" ", filename);
147 if (strcmp(mode, "r") == 0)
148 fprintf(stderr, "for read!!!\n");
149 else if (strcmp(mode, "w") == 0)
150 fprintf(stderr, "for write!!!\n");
157 /* Get all names of sub-directories in a certain directory. */
158 /* Returns the number of sub-directories found. */
159 /* Note: The user has to free the allocated space. */
160 string_list_type dsubdirs(const char *rel_path,const char* expected_file)
163 struct dirent *direntp;
164 string_list_type sdirs;
168 string_list_init(&sdirs);
169 sprintf(path,"%s/%s",st_dir,rel_path);
170 if((dirStructP = opendir(path)) != NULL)
172 while((direntp = readdir(dirStructP)) != NULL)
174 char absolute_filename[1024];
177 sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
179 if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode))
181 if(expected_file != NULL)
183 sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file);
184 if(!faccessible(filename))
188 string_list_add_item(&sdirs,direntp->d_name);
191 closedir(dirStructP);
194 sprintf(path,"%s/%s",datadir.c_str(),rel_path);
195 if((dirStructP = opendir(path)) != NULL)
197 while((direntp = readdir(dirStructP)) != NULL)
199 char absolute_filename[1024];
202 sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
204 if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode))
206 if(expected_file != NULL)
208 sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file);
209 if(!faccessible(filename))
215 sprintf(filename,"%s/%s/%s/%s",st_dir,rel_path,direntp->d_name,expected_file);
216 if(faccessible(filename))
221 string_list_add_item(&sdirs,direntp->d_name);
224 closedir(dirStructP);
230 string_list_type dfiles(const char *rel_path, const char* glob, const char* exception_str)
233 struct dirent *direntp;
234 string_list_type sdirs;
237 string_list_init(&sdirs);
238 sprintf(path,"%s/%s",st_dir,rel_path);
239 if((dirStructP = opendir(path)) != NULL)
241 while((direntp = readdir(dirStructP)) != NULL)
243 char absolute_filename[1024];
246 sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
248 if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode))
250 if(exception_str != NULL)
252 if(strstr(direntp->d_name,exception_str) != NULL)
256 if(strstr(direntp->d_name,glob) == NULL)
259 string_list_add_item(&sdirs,direntp->d_name);
262 closedir(dirStructP);
265 sprintf(path,"%s/%s",datadir.c_str(),rel_path);
266 if((dirStructP = opendir(path)) != NULL)
268 while((direntp = readdir(dirStructP)) != NULL)
270 char absolute_filename[1024];
273 sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
275 if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode))
277 if(exception_str != NULL)
279 if(strstr(direntp->d_name,exception_str) != NULL)
283 if(strstr(direntp->d_name,glob) == NULL)
286 string_list_add_item(&sdirs,direntp->d_name);
289 closedir(dirStructP);
295 void free_strings(char **strings, int num)
298 for(i=0; i < num; ++i)
303 /* Set SuperTux configuration and save directories */
304 void st_directory_setup(void)
308 /* Get home directory (from $HOME variable)... if we can't determine it,
309 use the current directory ("."): */
310 if (getenv("HOME") != NULL)
311 home = getenv("HOME");
315 st_dir = (char *) malloc(sizeof(char) * (strlen(home) +
316 strlen("/.supertux") + 1));
317 strcpy(st_dir, home);
318 strcat(st_dir, "/.supertux");
320 /* Remove .supertux config-file from old SuperTux versions */
321 if(faccessible(st_dir))
327 st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1));
329 strcpy(st_save_dir,st_dir);
330 strcat(st_save_dir,"/save");
332 /* Create them. In the case they exist they won't destroy anything. */
334 mkdir(st_save_dir, 0755);
336 sprintf(str, "%s/levels", st_dir);
339 // User has not that a datadir, so we try some magic
344 char exe_file[PATH_MAX];
345 if (readlink("/proc/self/exe", exe_file, PATH_MAX) < 0)
347 puts("Couldn't read /proc/self/exe, using default path: " DATA_PREFIX);
348 datadir = DATA_PREFIX;
352 std::string exedir = std::string(dirname(exe_file)) + "/";
354 datadir = exedir + "../data"; // SuperTux run from source dir
355 if (access(datadir.c_str(), F_OK) != 0)
357 datadir = exedir + "../share/supertux"; // SuperTux run from PATH
358 if (access(datadir.c_str(), F_OK) != 0)
359 { // If all fails, fall back to compiled path
360 datadir = DATA_PREFIX;
365 datadir = DATA_PREFIX;
368 printf("Datadir: %s\n", datadir.c_str());
371 /* Create and setup menus. */
374 main_menu = new Menu();
375 options_menu = new Menu();
376 options_keys_menu = new Menu();
377 options_joystick_menu = new Menu();
378 load_game_menu = new Menu();
379 save_game_menu = new Menu();
380 game_menu = new Menu();
381 highscore_menu = new Menu();
382 contrib_menu = new Menu();
383 contrib_subset_menu = new Menu();
384 worldmap_menu = new Menu();
386 main_menu->set_pos(screen->w/2, 335);
387 main_menu->additem(MN_GOTO, "Start Game",0,load_game_menu, MNID_STARTGAME);
388 main_menu->additem(MN_GOTO, "Contrib Levels",0,contrib_menu, MNID_CONTRIB);
389 main_menu->additem(MN_GOTO, "Options",0,options_menu, MNID_OPTIONMENU);
390 main_menu->additem(MN_ACTION,"Level Editor",0,0, MNID_LEVELEDITOR);
391 main_menu->additem(MN_ACTION,"Credits",0,0, MNID_CREDITS);
392 main_menu->additem(MN_ACTION,"Quit",0,0, MNID_QUITMAINMENU);
394 options_menu->additem(MN_LABEL,"Options",0,0);
395 options_menu->additem(MN_HL,"",0,0);
397 options_menu->additem(MN_TOGGLE,"OpenGL",use_gl,0, MNID_OPENGL);
399 options_menu->additem(MN_DEACTIVE,"OpenGL (not supported)",use_gl, 0, MNID_OPENGL);
401 options_menu->additem(MN_TOGGLE,"Fullscreen",use_fullscreen,0, MNID_FULLSCREEN);
404 options_menu->additem(MN_TOGGLE,"Sound ", use_sound,0, MNID_SOUND);
405 options_menu->additem(MN_TOGGLE,"Music ", use_music,0, MNID_MUSIC);
409 options_menu->additem(MN_DEACTIVE,"Sound ", false,0, MNID_SOUND);
410 options_menu->additem(MN_DEACTIVE,"Music ", false,0, MNID_MUSIC);
412 options_menu->additem(MN_TOGGLE,"Show FPS ",show_fps,0, MNID_SHOWFPS);
413 options_menu->additem(MN_GOTO,"Keyboard Setup",0,options_keys_menu);
416 options_menu->additem(MN_GOTO,"Joystick Setup",0,options_joystick_menu);
418 options_menu->additem(MN_HL,"",0,0);
419 options_menu->additem(MN_BACK,"Back",0,0);
421 options_keys_menu->additem(MN_LABEL,"Key Setup",0,0);
422 options_keys_menu->additem(MN_HL,"",0,0);
423 options_keys_menu->additem(MN_CONTROLFIELD_KB,"Left move", 0,0, 0,&keymap.left);
424 options_keys_menu->additem(MN_CONTROLFIELD_KB,"Right move", 0,0, 0,&keymap.right);
425 options_keys_menu->additem(MN_CONTROLFIELD_KB,"Jump", 0,0, 0,&keymap.jump);
426 options_keys_menu->additem(MN_CONTROLFIELD_KB,"Duck", 0,0, 0,&keymap.duck);
427 options_keys_menu->additem(MN_CONTROLFIELD_KB,"Activate", 0, 0, 0,
429 options_keys_menu->additem(MN_CONTROLFIELD_KB,"Power/Run", 0,0, 0,&keymap.fire);
430 options_keys_menu->additem(MN_HL,"",0,0);
431 options_keys_menu->additem(MN_BACK,"Back",0,0);
435 options_joystick_menu->additem(MN_LABEL,"Joystick Setup",0,0);
436 options_joystick_menu->additem(MN_HL,"",0,0);
437 //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"X axis", 0,0, 0,&joystick_keymap.x_axis);
438 //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"Y axis", 0,0, 0,&joystick_keymap.y_axis);
439 options_joystick_menu->additem(MN_CONTROLFIELD_JS,"A button", 0,0, 0,&joystick_keymap.a_button);
440 options_joystick_menu->additem(MN_CONTROLFIELD_JS,"B button", 0,0, 0,&joystick_keymap.b_button);
441 //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"Start", 0,0, 0,&joystick_keymap.start_button);
442 //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"DeadZone", 0,0, 0,&joystick_keymap.dead_zone);
443 options_joystick_menu->additem(MN_HL,"",0,0);
444 options_joystick_menu->additem(MN_BACK,"Back",0,0);
447 load_game_menu->additem(MN_LABEL,"Start Game",0,0);
448 load_game_menu->additem(MN_HL,"",0,0);
449 load_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0, 1);
450 load_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0, 2);
451 load_game_menu->additem(MN_DEACTIVE,"Slot 3",0,0, 3);
452 load_game_menu->additem(MN_DEACTIVE,"Slot 4",0,0, 4);
453 load_game_menu->additem(MN_DEACTIVE,"Slot 5",0,0, 5);
454 load_game_menu->additem(MN_HL,"",0,0);
455 load_game_menu->additem(MN_BACK,"Back",0,0);
457 save_game_menu->additem(MN_LABEL,"Save Game",0,0);
458 save_game_menu->additem(MN_HL,"",0,0);
459 save_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0, 1);
460 save_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0, 2);
461 save_game_menu->additem(MN_DEACTIVE,"Slot 3",0,0, 3);
462 save_game_menu->additem(MN_DEACTIVE,"Slot 4",0,0, 4);
463 save_game_menu->additem(MN_DEACTIVE,"Slot 5",0,0, 5);
464 save_game_menu->additem(MN_HL,"",0,0);
465 save_game_menu->additem(MN_BACK,"Back",0,0);
467 game_menu->additem(MN_LABEL,"Pause",0,0);
468 game_menu->additem(MN_HL,"",0,0);
469 game_menu->additem(MN_ACTION,"Continue",0,0,MNID_CONTINUE);
470 game_menu->additem(MN_GOTO,"Options",0,options_menu);
471 game_menu->additem(MN_HL,"",0,0);
472 game_menu->additem(MN_ACTION,"Abort Level",0,0,MNID_ABORTLEVEL);
474 worldmap_menu->additem(MN_LABEL,"Pause",0,0);
475 worldmap_menu->additem(MN_HL,"",0,0);
476 worldmap_menu->additem(MN_ACTION,"Continue",0,0,MNID_RETURNWORLDMAP);
477 worldmap_menu->additem(MN_GOTO,"Options",0,options_menu);
478 worldmap_menu->additem(MN_HL,"",0,0);
479 worldmap_menu->additem(MN_ACTION,"Quit Game",0,0,MNID_QUITWORLDMAP);
481 highscore_menu->additem(MN_TEXTFIELD,"Enter your name:",0,0);
484 void update_load_save_game_menu(Menu* pmenu)
486 for(int i = 2; i < 7; ++i)
488 // FIXME: Insert a real savegame struct/class here instead of
489 // doing string vodoo
490 std::string tmp = slotinfo(i - 1);
491 pmenu->item[i].kind = MN_ACTION;
492 pmenu->item[i].change_text(tmp.c_str());
496 bool process_load_game_menu()
498 int slot = load_game_menu->check();
500 if(slot != -1 && load_game_menu->get_item_by_id(slot).kind == MN_ACTION)
503 snprintf(slotfile, 1024, "%s/slot%d.stsg", st_save_dir, slot);
505 if (access(slotfile, F_OK) != 0)
510 // shrink_fade(Point((screen->w/2),(screen->h/2)), 1000);
512 WorldMapNS::WorldMap worldmap;
514 // Load the game or at least set the savegame_file variable
515 worldmap.loadgame(slotfile);
519 Menu::set_current(main_menu);
521 st_pause_ticks_stop();
530 /* Handle changes made to global settings in the options menu. */
531 void process_options_menu(void)
533 switch (options_menu->check())
537 if(use_gl != options_menu->isToggled(MNID_OPENGL))
543 options_menu->get_item_by_id(MNID_OPENGL).toggled = false;
546 case MNID_FULLSCREEN:
547 if(use_fullscreen != options_menu->isToggled(MNID_FULLSCREEN))
549 use_fullscreen = !use_fullscreen;
554 if(use_sound != options_menu->isToggled(MNID_SOUND))
555 use_sound = !use_sound;
558 if(use_music != options_menu->isToggled(MNID_MUSIC))
560 use_music = !use_music;
561 sound_manager->enable_music(use_music);
565 if(show_fps != options_menu->isToggled(MNID_SHOWFPS))
566 show_fps = !show_fps;
571 void st_general_setup(void)
573 /* Seed random number generator: */
575 srand(SDL_GetTicks());
577 /* Set icon image: */
581 /* Unicode needed for input handling: */
583 SDL_EnableUNICODE(1);
585 /* Load global images: */
587 black_text = new Font(datadir + "/images/status/letters-black.png",
589 gold_text = new Font(datadir + "/images/status/letters-gold.png",
591 silver_text = new Font(datadir + "/images/status/letters-silver.png",
593 blue_text = new Font(datadir + "/images/status/letters-blue.png",
594 Font::TEXT, 16, 18, 3);
595 red_text = new Font(datadir + "/images/status/letters-red.png",
597 green_text = new Font(datadir + "/images/status/letters-green.png",
599 white_text = new Font(datadir + "/images/fonts/letters-white.png",
601 white_small_text = new Font(datadir +
602 "/images/status/letters-white-small.png", Font::TEXT, 8,9, 1);
603 white_big_text = new Font(datadir + "/images/fonts/letters-white-big.png",
604 Font::TEXT, 20,22, 3);
605 yellow_nums = new Font(datadir + "/images/status/numbers.png",
608 /* Load GUI/menu images: */
609 checkbox = new Surface(datadir + "/images/status/checkbox.png", USE_ALPHA);
610 checkbox_checked = new Surface(datadir + "/images/status/checkbox-checked.png", USE_ALPHA);
611 back = new Surface(datadir + "/images/status/back.png", USE_ALPHA);
612 arrow_left = new Surface(datadir + "/images/icons/left.png", USE_ALPHA);
613 arrow_right = new Surface(datadir + "/images/icons/right.png", USE_ALPHA);
615 /* Load the mouse-cursor */
616 mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1);
617 MouseCursor::set_current(mouse_cursor);
621 void st_general_free(void)
624 /* Free global images: */
632 delete white_small_text;
633 delete white_big_text;
636 /* Free GUI/menu images: */
638 delete checkbox_checked;
643 /* Free mouse-cursor */
650 delete highscore_menu;
651 delete save_game_menu;
652 delete load_game_menu;
655 void st_video_setup(void)
657 /* Init SDL Video: */
658 if (SDL_Init(SDL_INIT_VIDEO) < 0)
661 "\nError: I could not initialize video!\n"
662 "The Simple DirectMedia error that occured was:\n"
663 "%s\n\n", SDL_GetError());
671 st_video_setup_sdl();
673 Surface::reload_all();
675 /* Set window manager stuff: */
676 SDL_WM_SetCaption("SuperTux " VERSION, "SuperTux");
679 void st_video_setup_sdl(void)
683 screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
687 "\nWarning: I could not set up fullscreen video for "
689 "The Simple DirectMedia error that occured was:\n"
690 "%s\n\n", SDL_GetError());
691 use_fullscreen = false;
696 screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_HWSURFACE | SDL_DOUBLEBUF );
701 "\nError: I could not set up video for 640x480 mode.\n"
702 "The Simple DirectMedia error that occured was:\n"
703 "%s\n\n", SDL_GetError());
709 void st_video_setup_gl(void)
713 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
714 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
715 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
716 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
717 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
721 screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */
725 "\nWarning: I could not set up fullscreen video for "
727 "The Simple DirectMedia error that occured was:\n"
728 "%s\n\n", SDL_GetError());
729 use_fullscreen = false;
734 screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_OPENGL);
739 "\nError: I could not set up video for 640x480 mode.\n"
740 "The Simple DirectMedia error that occured was:\n"
741 "%s\n\n", SDL_GetError());
747 * Set up OpenGL for 2D rendering.
749 glDisable(GL_DEPTH_TEST);
750 glDisable(GL_CULL_FACE);
752 glViewport(0, 0, screen->w, screen->h);
753 glMatrixMode(GL_PROJECTION);
755 glOrtho(0, screen->w, screen->h, 0, -1.0, 1.0);
757 glMatrixMode(GL_MODELVIEW);
759 glTranslatef(0.0f, 0.0f, 0.0f);
765 void st_joystick_setup(void)
772 if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
774 fprintf(stderr, "Warning: I could not initialize joystick!\n"
775 "The Simple DirectMedia error that occured was:\n"
776 "%s\n\n", SDL_GetError());
778 use_joystick = false;
783 if (SDL_NumJoysticks() <= 0)
785 fprintf(stderr, "Warning: No joysticks are available.\n");
787 use_joystick = false;
791 js = SDL_JoystickOpen(joystick_num);
795 fprintf(stderr, "Warning: Could not open joystick %d.\n"
796 "The Simple DirectMedia error that occured was:\n"
797 "%s\n\n", joystick_num, SDL_GetError());
799 use_joystick = false;
803 if (SDL_JoystickNumAxes(js) < 2)
806 "Warning: Joystick does not have enough axes!\n");
808 use_joystick = false;
812 if (SDL_JoystickNumButtons(js) < 2)
816 "Joystick does not have enough buttons!\n");
818 use_joystick = false;
826 void st_audio_setup(void)
829 /* Init SDL Audio silently even if --disable-sound : */
833 if (SDL_Init(SDL_INIT_AUDIO) < 0)
835 /* only print out message if sound or music
836 was not disabled at command-line
838 if (use_sound || use_music)
841 "\nWarning: I could not initialize audio!\n"
842 "The Simple DirectMedia error that occured was:\n"
843 "%s\n\n", SDL_GetError());
845 /* keep the programming logic the same :-)
846 because in this case, use_sound & use_music' values are ignored
847 when there's no available audio device
851 audio_device = false;
856 /* Open sound silently regarless the value of "use_sound": */
860 if (open_audio(44100, AUDIO_S16, 2, 2048) < 0)
862 /* only print out message if sound or music
863 was not disabled at command-line
865 if (use_sound || use_music)
868 "\nWarning: I could not set up audio for 44100 Hz "
870 "The Simple DirectMedia error that occured was:\n"
871 "%s\n\n", SDL_GetError());
875 audio_device = false;
882 /* --- SHUTDOWN --- */
884 void st_shutdown(void)
893 void st_abort(const std::string& reason, const std::string& details)
895 fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str());
900 /* Set Icon (private) */
909 /* Load icon into a surface: */
911 icon = IMG_Load((datadir + "/images/supertux.xpm").c_str());
915 "\nError: I could not load the icon image: %s%s\n"
916 "The Simple DirectMedia error that occured was:\n"
917 "%s\n\n", datadir.c_str(), "/images/supertux.xpm", SDL_GetError());
924 masklen = (((icon -> w) + 7) / 8) * (icon -> h);
925 mask = (Uint8*) malloc(masklen * sizeof(Uint8));
926 memset(mask, 0xFF, masklen);
931 SDL_WM_SetIcon(icon, NULL);//mask);
934 /* Free icon surface & mask: */
937 SDL_FreeSurface(icon);
941 /* Parse command-line arguments: */
943 void parseargs(int argc, char * argv[])
949 /* Parse arguments: */
951 for (i = 1; i < argc; i++)
953 if (strcmp(argv[i], "--fullscreen") == 0 ||
954 strcmp(argv[i], "-f") == 0)
956 /* Use full screen: */
958 use_fullscreen = true;
960 else if (strcmp(argv[i], "--joystick") == 0 || strcmp(argv[i], "-j") == 0)
963 joystick_num = atoi(argv[++i]);
965 else if (strcmp(argv[i], "--joymap") == 0)
968 if (sscanf(argv[++i],
970 &joystick_keymap.x_axis,
971 &joystick_keymap.y_axis,
972 &joystick_keymap.a_button,
973 &joystick_keymap.b_button,
974 &joystick_keymap.start_button) != 5)
976 puts("Warning: Invalid or incomplete joymap, should be: 'XAXIS:YAXIS:A:B:START'");
980 std::cout << "Using new joymap:\n"
981 << " X-Axis: " << joystick_keymap.x_axis << "\n"
982 << " Y-Axis: " << joystick_keymap.y_axis << "\n"
983 << " A-Button: " << joystick_keymap.a_button << "\n"
984 << " B-Button: " << joystick_keymap.b_button << "\n"
985 << " Start-Button: " << joystick_keymap.start_button << std::endl;
988 else if (strcmp(argv[i], "--leveleditor") == 0)
990 launch_leveleditor_mode = true;
992 else if (strcmp(argv[i], "--datadir") == 0
993 || strcmp(argv[i], "-d") == 0 )
998 else if (strcmp(argv[i], "--show-fps") == 0)
1000 /* Use full screen: */
1004 else if (strcmp(argv[i], "--opengl") == 0 ||
1005 strcmp(argv[i], "-gl") == 0)
1013 else if (strcmp(argv[i], "--sdl") == 0)
1017 else if (strcmp(argv[i], "--usage") == 0)
1023 else if (strcmp(argv[i], "--version") == 0)
1026 printf("SuperTux " VERSION "\n");
1029 else if (strcmp(argv[i], "--disable-sound") == 0)
1031 /* Disable the compiled in sound feature */
1032 printf("Sounds disabled \n");
1034 audio_device = false;
1036 else if (strcmp(argv[i], "--disable-music") == 0)
1038 /* Disable the compiled in sound feature */
1039 printf("Music disabled \n");
1042 else if (strcmp(argv[i], "--debug-mode") == 0)
1044 /* Enable the debug-mode */
1048 else if (strcmp(argv[i], "--help") == 0)
1050 puts("Super Tux " VERSION "\n"
1051 " Please see the file \"README.txt\" for more details.\n");
1052 printf("Usage: %s [OPTIONS] FILENAME\n\n", argv[0]);
1053 puts("Display Options:\n"
1054 " --fullscreen Run in fullscreen mode.\n"
1055 " --opengl If opengl support was compiled in, this will enable\n"
1056 " the EXPERIMENTAL OpenGL mode.\n"
1057 " --sdl Use non-opengl renderer\n"
1060 " --disable-sound If sound support was compiled in, this will\n"
1061 " disable sound for this session of the game.\n"
1062 " --disable-music Like above, but this will disable music.\n"
1065 " -j, --joystick NUM Use joystick NUM (default: 0)\n"
1066 " --joymap XAXIS:YAXIS:A:B:START\n"
1067 " Define how joystick buttons and axis should be mapped\n"
1068 " --leveleditor Opens the leveleditor in a file. (Only works when a file is provided.)\n"
1069 " -d, --datadir DIR Load Game data from DIR (default: automatic)\n"
1070 " --debug-mode Enables the debug-mode, which is useful for developers.\n"
1071 " --help Display a help message summarizing command-line\n"
1072 " options, license and game controls.\n"
1073 " --usage Display a brief message summarizing command-line options.\n"
1074 " --version Display the version of SuperTux you're running.\n\n"
1078 else if (argv[i][0] != '-')
1080 level_startup_file = argv[i];
1084 /* Unknown - complain! */
1092 /* Display usage: */
1094 void usage(char * prog, int ret)
1099 /* Determine which stream to write to: */
1107 /* Display the usage message: */
1109 fprintf(fi, "Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug-mode] | [--usage | --help | --version] [--leveleditor] FILENAME\n",