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.
30 #include "SDL_image.h"
32 #include "SDL_opengl.h"
36 #include <sys/types.h>
47 #include "screen/screen.h"
48 #include "screen/surface.h"
51 #include "configfile.h"
54 #include "resources.h"
56 #include "sound_manager.h"
62 #define mkdir(dir, mode) mkdir(dir)
63 // on win32 we typically don't want LFS paths
65 #define DATA_PREFIX "./data/"
68 /* Screen proprities: */
69 /* Don't use this to test for the actual screen sizes. Use screen->w/h instead! */
73 /* Local function prototypes: */
76 void usage(char * prog, int ret);
78 /* Does the given file exist and is it accessible? */
79 int faccessible(const char *filename)
82 if (stat(filename, &filestat) == -1)
88 if(S_ISREG(filestat.st_mode))
95 /* Can we write to this location? */
96 int fwriteable(const char *filename)
99 fi = fopen(filename, "wa");
107 /* Makes sure a directory is created in either the SuperTux home directory or the SuperTux base directory.*/
108 int fcreatedir(const char* relative_dir)
111 snprintf(path, 1024, "%s/%s/", st_dir, relative_dir);
112 if(mkdir(path,0755) != 0)
114 snprintf(path, 1024, "%s/%s/", datadir.c_str(), relative_dir);
115 if(mkdir(path,0755) != 0)
130 FILE * opendata(const char * rel_filename, const char * mode)
132 char * filename = NULL;
135 filename = (char *) malloc(sizeof(char) * (strlen(st_dir) +
136 strlen(rel_filename) + 1));
138 strcpy(filename, st_dir);
139 /* Open the high score file: */
141 strcat(filename, rel_filename);
143 /* Try opening the file: */
144 fi = fopen(filename, mode);
148 fprintf(stderr, "Warning: Unable to open the file \"%s\" ", filename);
150 if (strcmp(mode, "r") == 0)
151 fprintf(stderr, "for read!!!\n");
152 else if (strcmp(mode, "w") == 0)
153 fprintf(stderr, "for write!!!\n");
160 /* Get all names of sub-directories in a certain directory. */
161 /* Returns the number of sub-directories found. */
162 /* Note: The user has to free the allocated space. */
163 string_list_type dsubdirs(const char *rel_path,const char* expected_file)
166 struct dirent *direntp;
167 string_list_type sdirs;
171 string_list_init(&sdirs);
172 sprintf(path,"%s/%s",st_dir,rel_path);
173 if((dirStructP = opendir(path)) != NULL)
175 while((direntp = readdir(dirStructP)) != NULL)
177 char absolute_filename[1024];
180 sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
182 if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode))
184 if(expected_file != NULL)
186 sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file);
187 if(!faccessible(filename))
191 string_list_add_item(&sdirs,direntp->d_name);
194 closedir(dirStructP);
197 sprintf(path,"%s/%s",datadir.c_str(),rel_path);
198 if((dirStructP = opendir(path)) != NULL)
200 while((direntp = readdir(dirStructP)) != NULL)
202 char absolute_filename[1024];
205 sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
207 if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode))
209 if(expected_file != NULL)
211 sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file);
212 if(!faccessible(filename))
218 sprintf(filename,"%s/%s/%s/%s",st_dir,rel_path,direntp->d_name,expected_file);
219 if(faccessible(filename))
224 string_list_add_item(&sdirs,direntp->d_name);
227 closedir(dirStructP);
233 string_list_type dfiles(const char *rel_path, const char* glob, const char* exception_str)
236 struct dirent *direntp;
237 string_list_type sdirs;
240 string_list_init(&sdirs);
241 sprintf(path,"%s/%s",st_dir,rel_path);
242 if((dirStructP = opendir(path)) != NULL)
244 while((direntp = readdir(dirStructP)) != NULL)
246 char absolute_filename[1024];
249 sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
251 if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode))
253 if(exception_str != NULL)
255 if(strstr(direntp->d_name,exception_str) != NULL)
259 if(strstr(direntp->d_name,glob) == NULL)
262 string_list_add_item(&sdirs,direntp->d_name);
265 closedir(dirStructP);
268 sprintf(path,"%s/%s",datadir.c_str(),rel_path);
269 if((dirStructP = opendir(path)) != NULL)
271 while((direntp = readdir(dirStructP)) != NULL)
273 char absolute_filename[1024];
276 sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
278 if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode))
280 if(exception_str != NULL)
282 if(strstr(direntp->d_name,exception_str) != NULL)
286 if(strstr(direntp->d_name,glob) == NULL)
289 string_list_add_item(&sdirs,direntp->d_name);
292 closedir(dirStructP);
298 void free_strings(char **strings, int num)
301 for(i=0; i < num; ++i)
306 /* Set SuperTux configuration and save directories */
307 void st_directory_setup(void)
311 /* Get home directory (from $HOME variable)... if we can't determine it,
312 use the current directory ("."): */
313 if (getenv("HOME") != NULL)
314 home = getenv("HOME");
318 st_dir = (char *) malloc(sizeof(char) * (strlen(home) +
319 strlen("/.supertux") + 1));
320 strcpy(st_dir, home);
321 strcat(st_dir, "/.supertux");
323 /* Remove .supertux config-file from old SuperTux versions */
324 if(faccessible(st_dir))
330 st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1));
332 strcpy(st_save_dir,st_dir);
333 strcat(st_save_dir,"/save");
335 /* Create them. In the case they exist they won't destroy anything. */
337 mkdir(st_save_dir, 0755);
339 sprintf(str, "%s/levels", st_dir);
342 // User has not that a datadir, so we try some magic
347 char exe_file[PATH_MAX];
348 if (readlink("/proc/self/exe", exe_file, PATH_MAX) < 0)
350 puts("Couldn't read /proc/self/exe, using default path: " DATA_PREFIX);
351 datadir = DATA_PREFIX;
355 std::string exedir = std::string(dirname(exe_file)) + "/";
357 datadir = exedir + "../data"; // SuperTux run from source dir
358 if (access(datadir.c_str(), F_OK) != 0)
360 datadir = exedir + "../share/supertux"; // SuperTux run from PATH
361 if (access(datadir.c_str(), F_OK) != 0)
362 { // If all fails, fall back to compiled path
363 datadir = DATA_PREFIX;
368 datadir = DATA_PREFIX;
371 printf("Datadir: %s\n", datadir.c_str());
374 /* Create and setup menus. */
377 main_menu = new Menu();
378 options_menu = new Menu();
379 options_keys_menu = new Menu();
380 options_joystick_menu = new Menu();
381 load_game_menu = new Menu();
382 save_game_menu = new Menu();
383 game_menu = new Menu();
384 highscore_menu = new Menu();
385 contrib_menu = new Menu();
386 contrib_subset_menu = new Menu();
387 worldmap_menu = new Menu();
389 main_menu->set_pos(screen->w/2, 335);
390 main_menu->additem(MN_GOTO, _("Start Game"),0,load_game_menu, MNID_STARTGAME);
391 main_menu->additem(MN_GOTO, _("Contrib Levels"),0,contrib_menu, MNID_CONTRIB);
392 main_menu->additem(MN_GOTO, _("Options"),0,options_menu, MNID_OPTIONMENU);
393 main_menu->additem(MN_ACTION, _("Level Editor"),0,0, MNID_LEVELEDITOR);
394 main_menu->additem(MN_ACTION, _("Credits"),0,0, MNID_CREDITS);
395 main_menu->additem(MN_ACTION, _("Quit"),0,0, MNID_QUITMAINMENU);
397 options_menu->additem(MN_LABEL,_("Options"),0,0);
398 options_menu->additem(MN_HL,"",0,0);
400 options_menu->additem(MN_TOGGLE,_("OpenGL "),use_gl,0, MNID_OPENGL);
402 options_menu->additem(MN_DEACTIVE,_("OpenGL (not supported)"),use_gl, 0, MNID_OPENGL);
404 options_menu->additem(MN_TOGGLE,_("Fullscreen"),use_fullscreen,0, MNID_FULLSCREEN);
407 options_menu->additem(MN_TOGGLE,_("Sound "), use_sound,0, MNID_SOUND);
408 options_menu->additem(MN_TOGGLE,_("Music "), use_music,0, MNID_MUSIC);
412 options_menu->additem(MN_DEACTIVE,_("Sound "), false,0, MNID_SOUND);
413 options_menu->additem(MN_DEACTIVE,_("Music "), false,0, MNID_MUSIC);
415 options_menu->additem(MN_TOGGLE,_("Show FPS "),show_fps,0, MNID_SHOWFPS);
416 options_menu->additem(MN_GOTO,_("Setup Keys"),0,options_keys_menu);
419 options_menu->additem(MN_GOTO,_("Setup Joystick"),0,options_joystick_menu);
421 options_menu->additem(MN_HL,"",0,0);
422 options_menu->additem(MN_BACK,_("Back"),0,0);
424 options_keys_menu->additem(MN_LABEL,_("Keyboard Setup"),0,0);
425 options_keys_menu->additem(MN_HL,"",0,0);
426 options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Left move"), 0,0, 0,&keymap.left);
427 options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Right move"), 0,0, 0,&keymap.right);
428 options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Jump"), 0,0, 0,&keymap.jump);
429 options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Duck"), 0,0, 0,&keymap.duck);
430 options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Activate"), 0, 0, 0,
432 options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Power/Run"), 0,0, 0,&keymap.fire);
433 options_keys_menu->additem(MN_HL,"",0,0);
434 options_keys_menu->additem(MN_BACK,_("Back"),0,0);
438 options_joystick_menu->additem(MN_LABEL,_("Joystick Setup"),0,0);
439 options_joystick_menu->additem(MN_HL,"",0,0);
440 //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"X axis", 0,0, 0,&joystick_keymap.x_axis);
441 //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"Y axis", 0,0, 0,&joystick_keymap.y_axis);
442 options_joystick_menu->additem(MN_CONTROLFIELD_JS,_("A button"), 0,0, 0,&joystick_keymap.a_button);
443 options_joystick_menu->additem(MN_CONTROLFIELD_JS,_("B button"), 0,0, 0,&joystick_keymap.b_button);
444 //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"Start", 0,0, 0,&joystick_keymap.start_button);
445 //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"DeadZone", 0,0, 0,&joystick_keymap.dead_zone);
446 options_joystick_menu->additem(MN_HL,"",0,0);
447 options_joystick_menu->additem(MN_BACK,_("Back"),0,0);
450 load_game_menu->additem(MN_LABEL,_("Start Game"),0,0);
451 load_game_menu->additem(MN_HL,"",0,0);
452 load_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0, 1);
453 load_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0, 2);
454 load_game_menu->additem(MN_DEACTIVE,"Slot 3",0,0, 3);
455 load_game_menu->additem(MN_DEACTIVE,"Slot 4",0,0, 4);
456 load_game_menu->additem(MN_DEACTIVE,"Slot 5",0,0, 5);
457 load_game_menu->additem(MN_HL,"",0,0);
458 load_game_menu->additem(MN_BACK,_("Back"),0,0);
460 save_game_menu->additem(MN_LABEL,_("Save Game"),0,0);
461 save_game_menu->additem(MN_HL,"",0,0);
462 save_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0, 1);
463 save_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0, 2);
464 save_game_menu->additem(MN_DEACTIVE,"Slot 3",0,0, 3);
465 save_game_menu->additem(MN_DEACTIVE,"Slot 4",0,0, 4);
466 save_game_menu->additem(MN_DEACTIVE,"Slot 5",0,0, 5);
467 save_game_menu->additem(MN_HL,"",0,0);
468 save_game_menu->additem(MN_BACK,"Back",0,0);
470 game_menu->additem(MN_LABEL,_("Pause"),0,0);
471 game_menu->additem(MN_HL,"",0,0);
472 game_menu->additem(MN_ACTION,_("Continue"),0,0,MNID_CONTINUE);
473 game_menu->additem(MN_GOTO,_("Options"),0,options_menu);
474 game_menu->additem(MN_HL,"",0,0);
475 game_menu->additem(MN_ACTION,_("Abort Level"),0,0,MNID_ABORTLEVEL);
477 worldmap_menu->additem(MN_LABEL,_("Pause"),0,0);
478 worldmap_menu->additem(MN_HL,"",0,0);
479 worldmap_menu->additem(MN_ACTION,_("Continue"),0,0,MNID_RETURNWORLDMAP);
480 worldmap_menu->additem(MN_GOTO,_("Options"),0,options_menu);
481 worldmap_menu->additem(MN_HL,"",0,0);
482 worldmap_menu->additem(MN_ACTION,_("Quit Game"),0,0,MNID_QUITWORLDMAP);
484 highscore_menu->additem(MN_TEXTFIELD,_("Enter your name:"),0,0);
487 void update_load_save_game_menu(Menu* pmenu)
489 for(int i = 2; i < 7; ++i)
491 // FIXME: Insert a real savegame struct/class here instead of
492 // doing string vodoo
493 std::string tmp = slotinfo(i - 1);
494 pmenu->item[i].kind = MN_ACTION;
495 pmenu->item[i].change_text(tmp.c_str());
499 bool process_load_game_menu()
501 int slot = load_game_menu->check();
503 if(slot != -1 && load_game_menu->get_item_by_id(slot).kind == MN_ACTION)
506 snprintf(slotfile, 1024, "%s/slot%d.stsg", st_save_dir, slot);
508 if (access(slotfile, F_OK) != 0)
513 // shrink_fade(Point((screen->w/2),(screen->h/2)), 1000);
515 WorldMapNS::WorldMap worldmap;
517 // Load the game or at least set the savegame_file variable
518 worldmap.loadgame(slotfile);
522 Menu::set_current(main_menu);
524 st_pause_ticks_stop();
533 /* Handle changes made to global settings in the options menu. */
534 void process_options_menu(void)
536 switch (options_menu->check())
540 if(use_gl != options_menu->isToggled(MNID_OPENGL))
546 options_menu->get_item_by_id(MNID_OPENGL).toggled = false;
549 case MNID_FULLSCREEN:
550 if(use_fullscreen != options_menu->isToggled(MNID_FULLSCREEN))
552 use_fullscreen = !use_fullscreen;
557 if(use_sound != options_menu->isToggled(MNID_SOUND))
558 use_sound = !use_sound;
561 if(use_music != options_menu->isToggled(MNID_MUSIC))
563 use_music = !use_music;
564 sound_manager->enable_music(use_music);
568 if(show_fps != options_menu->isToggled(MNID_SHOWFPS))
569 show_fps = !show_fps;
574 void st_general_setup(void)
576 /* Seed random number generator: */
578 srand(SDL_GetTicks());
580 /* Set icon image: */
584 /* Unicode needed for input handling: */
586 SDL_EnableUNICODE(1);
588 /* Load global images: */
589 gold_text = new Font(datadir + "/images/fonts/gold.png", Font::TEXT, 16,18);
590 blue_text = new Font(datadir + "/images/fonts/blue.png", Font::TEXT, 16,18,3);
591 white_text = new Font(datadir + "/images/fonts/white.png",
593 white_small_text = new Font(datadir + "/images/fonts/white-small.png",
595 white_big_text = new Font(datadir + "/images/fonts/white-big.png",
596 Font::TEXT, 20,22, 3);
597 yellow_nums = new Font(datadir + "/images/fonts/numbers.png",
600 /* Load GUI/menu images: */
601 checkbox = new Surface(datadir + "/images/status/checkbox.png", USE_ALPHA);
602 checkbox_checked = new Surface(datadir + "/images/status/checkbox-checked.png", USE_ALPHA);
603 back = new Surface(datadir + "/images/status/back.png", USE_ALPHA);
604 arrow_left = new Surface(datadir + "/images/icons/left.png", USE_ALPHA);
605 arrow_right = new Surface(datadir + "/images/icons/right.png", USE_ALPHA);
607 /* Load the mouse-cursor */
608 mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1);
609 MouseCursor::set_current(mouse_cursor);
613 void st_general_free(void)
616 /* Free global images: */
620 delete white_small_text;
621 delete white_big_text;
624 /* Free GUI/menu images: */
626 delete checkbox_checked;
631 /* Free mouse-cursor */
638 delete options_keys_menu;
639 delete options_joystick_menu;
640 delete highscore_menu;
642 delete contrib_subset_menu;
643 delete worldmap_menu;
644 delete save_game_menu;
645 delete load_game_menu;
648 void st_video_setup(void)
650 /* Init SDL Video: */
651 if (SDL_Init(SDL_INIT_VIDEO) < 0)
654 "\nError: I could not initialize video!\n"
655 "The Simple DirectMedia error that occured was:\n"
656 "%s\n\n", SDL_GetError());
664 st_video_setup_sdl();
666 Surface::reload_all();
668 /* Set window manager stuff: */
669 SDL_WM_SetCaption("SuperTux " VERSION, "SuperTux");
672 void st_video_setup_sdl(void)
676 screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
680 "\nWarning: I could not set up fullscreen video for "
682 "The Simple DirectMedia error that occured was:\n"
683 "%s\n\n", SDL_GetError());
684 use_fullscreen = false;
689 screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_HWSURFACE | SDL_DOUBLEBUF );
694 "\nError: I could not set up video for 800x600 mode.\n"
695 "The Simple DirectMedia error that occured was:\n"
696 "%s\n\n", SDL_GetError());
702 void st_video_setup_gl(void)
706 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
707 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
708 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
709 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
710 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
714 screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */
718 "\nWarning: I could not set up fullscreen video for "
720 "The Simple DirectMedia error that occured was:\n"
721 "%s\n\n", SDL_GetError());
722 use_fullscreen = false;
727 screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 0, SDL_OPENGL);
732 "\nError: I could not set up video for 640x480 mode.\n"
733 "The Simple DirectMedia error that occured was:\n"
734 "%s\n\n", SDL_GetError());
740 * Set up OpenGL for 2D rendering.
742 glDisable(GL_DEPTH_TEST);
743 glDisable(GL_CULL_FACE);
745 glViewport(0, 0, screen->w, screen->h);
746 glMatrixMode(GL_PROJECTION);
748 glOrtho(0, screen->w, screen->h, 0, -1.0, 1.0);
750 glMatrixMode(GL_MODELVIEW);
752 glTranslatef(0.0f, 0.0f, 0.0f);
758 void st_joystick_setup(void)
765 if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
767 fprintf(stderr, "Warning: I could not initialize joystick!\n"
768 "The Simple DirectMedia error that occured was:\n"
769 "%s\n\n", SDL_GetError());
771 use_joystick = false;
776 if (SDL_NumJoysticks() <= 0)
778 fprintf(stderr, "Info: No joysticks were found.\n");
780 use_joystick = false;
784 js = SDL_JoystickOpen(joystick_num);
788 fprintf(stderr, "Warning: Could not open joystick %d.\n"
789 "The Simple DirectMedia error that occured was:\n"
790 "%s\n\n", joystick_num, SDL_GetError());
792 use_joystick = false;
796 if (SDL_JoystickNumAxes(js) < 2)
799 "Warning: Joystick does not have enough axes!\n");
801 use_joystick = false;
805 if (SDL_JoystickNumButtons(js) < 2)
809 "Joystick does not have enough buttons!\n");
811 use_joystick = false;
819 void st_audio_setup(void)
822 /* Init SDL Audio silently even if --disable-sound : */
826 if (SDL_Init(SDL_INIT_AUDIO) < 0)
828 /* only print out message if sound or music
829 was not disabled at command-line
831 if (use_sound || use_music)
834 "\nWarning: I could not initialize audio!\n"
835 "The Simple DirectMedia error that occured was:\n"
836 "%s\n\n", SDL_GetError());
838 /* keep the programming logic the same :-)
839 because in this case, use_sound & use_music' values are ignored
840 when there's no available audio device
844 audio_device = false;
849 /* Open sound silently regarless the value of "use_sound": */
853 if (open_audio(44100, AUDIO_S16, 2, 2048) < 0)
855 /* only print out message if sound or music
856 was not disabled at command-line
858 if (use_sound || use_music)
861 "\nWarning: I could not set up audio for 44100 Hz "
863 "The Simple DirectMedia error that occured was:\n"
864 "%s\n\n", SDL_GetError());
868 audio_device = false;
875 /* --- SHUTDOWN --- */
877 void st_shutdown(void)
886 void st_abort(const std::string& reason, const std::string& details)
888 fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str());
893 /* Set Icon (private) */
902 /* Load icon into a surface: */
904 icon = IMG_Load((datadir + "/images/supertux.xpm").c_str());
908 "\nError: I could not load the icon image: %s%s\n"
909 "The Simple DirectMedia error that occured was:\n"
910 "%s\n\n", datadir.c_str(), "/images/supertux.xpm", SDL_GetError());
917 masklen = (((icon -> w) + 7) / 8) * (icon -> h);
918 mask = (Uint8*) malloc(masklen * sizeof(Uint8));
919 memset(mask, 0xFF, masklen);
924 SDL_WM_SetIcon(icon, NULL);//mask);
927 /* Free icon surface & mask: */
930 SDL_FreeSurface(icon);
934 /* Parse command-line arguments: */
936 void parseargs(int argc, char * argv[])
942 /* Parse arguments: */
944 for (i = 1; i < argc; i++)
946 if (strcmp(argv[i], "--fullscreen") == 0 ||
947 strcmp(argv[i], "-f") == 0)
949 use_fullscreen = true;
951 else if (strcmp(argv[i], "--window") == 0 ||
952 strcmp(argv[i], "-w") == 0)
954 use_fullscreen = false;
956 else if (strcmp(argv[i], "--joystick") == 0 || strcmp(argv[i], "-j") == 0)
959 joystick_num = atoi(argv[++i]);
961 else if (strcmp(argv[i], "--joymap") == 0)
964 if (sscanf(argv[++i],
966 &joystick_keymap.x_axis,
967 &joystick_keymap.y_axis,
968 &joystick_keymap.a_button,
969 &joystick_keymap.b_button,
970 &joystick_keymap.start_button) != 5)
972 puts("Warning: Invalid or incomplete joymap, should be: 'XAXIS:YAXIS:A:B:START'");
976 std::cout << "Using new joymap:\n"
977 << " X-Axis: " << joystick_keymap.x_axis << "\n"
978 << " Y-Axis: " << joystick_keymap.y_axis << "\n"
979 << " A-Button: " << joystick_keymap.a_button << "\n"
980 << " B-Button: " << joystick_keymap.b_button << "\n"
981 << " Start-Button: " << joystick_keymap.start_button << std::endl;
984 else if (strcmp(argv[i], "--leveleditor") == 0)
986 launch_leveleditor_mode = true;
988 else if (strcmp(argv[i], "--datadir") == 0
989 || strcmp(argv[i], "-d") == 0 )
994 else if (strcmp(argv[i], "--show-fps") == 0)
996 /* Use full screen: */
1000 else if (strcmp(argv[i], "--opengl") == 0 ||
1001 strcmp(argv[i], "-gl") == 0)
1009 else if (strcmp(argv[i], "--sdl") == 0)
1013 else if (strcmp(argv[i], "--usage") == 0)
1019 else if (strcmp(argv[i], "--version") == 0)
1022 printf("SuperTux " VERSION "\n");
1025 else if (strcmp(argv[i], "--disable-sound") == 0)
1027 /* Disable the compiled in sound feature */
1028 printf("Sounds disabled \n");
1030 audio_device = false;
1032 else if (strcmp(argv[i], "--disable-music") == 0)
1034 /* Disable the compiled in sound feature */
1035 printf("Music disabled \n");
1038 else if (strcmp(argv[i], "--debug-mode") == 0)
1040 /* Enable the debug-mode */
1044 else if (strcmp(argv[i], "--help") == 0)
1046 puts(_(" SuperTux " VERSION "\n"
1047 " Please see the file \"README.txt\" for more details.\n"));
1048 printf(_("Usage: %s [OPTIONS] FILENAME\n\n"), argv[0]);
1049 puts(_("Display Options:\n"
1050 " -f, --fullscreen Run in fullscreen mode.\n"
1051 " -w, --window Run in window mode.\n"
1052 " --opengl If OpenGL support was compiled in, this will tell\n"
1053 " SuperTux to make use of it.\n"
1054 " --sdl Use the SDL software graphical renderer\n"
1057 " --disable-sound If sound support was compiled in, this will\n"
1058 " disable sound for this session of the game.\n"
1059 " --disable-music Like above, but this will disable music.\n"
1062 " -j, --joystick NUM Use joystick NUM (default: 0)\n"
1063 " --joymap XAXIS:YAXIS:A:B:START\n"
1064 " Define how joystick buttons and axis should be mapped\n"
1065 " --leveleditor Opens the leveleditor in a file. (Only works when a file is provided.)\n"
1066 " -d, --datadir DIR Load Game data from DIR (default: automatic)\n"
1067 " --debug-mode Enables the debug-mode, which is useful for developers.\n"
1068 " --help Display a help message summarizing command-line\n"
1069 " options, license and game controls.\n"
1070 " --usage Display a brief message summarizing command-line options.\n"
1071 " --version Display the version of SuperTux you're running.\n\n"
1075 else if (argv[i][0] != '-')
1077 level_startup_file = argv[i];
1081 /* Unknown - complain! */
1089 /* Display usage: */
1091 void usage(char * prog, int ret)
1096 /* Determine which stream to write to: */
1104 /* Display the usage message: */
1106 fprintf(fi, _("Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug-mode] | [--usage | --help | --version] [--leveleditor] FILENAME\n"),
1115 std::vector<std::string> read_directory(const std::string& pathname)
1117 std::vector<std::string> dirnames;
1119 DIR* dir = opendir(pathname.c_str());
1122 struct dirent *direntp;
1124 while((direntp = readdir(dir)))
1126 dirnames.push_back(direntp->d_name);