added some more non-45 degree triangle modes
[supertux.git] / lib / app / setup.cpp
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 //
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.
10 //
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.
15 //
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.
19
20 #include <config.h>
21
22 #include <cassert>
23 #include <cstdio>
24 #include <iostream>
25 #include <cstdio>
26 #include <cstdlib>
27 #include <cstring>
28 #include <cerrno>
29 #include <unistd.h>
30
31 #include "SDL.h"
32 #include "SDL_image.h"
33 #ifndef NOOPENGL
34 #include "SDL_opengl.h"
35 #endif
36
37 #include <sys/stat.h>
38 #include <sys/types.h>
39 #include <dirent.h>
40 #ifndef WIN32
41 #include <libgen.h>
42 #endif
43
44 #include <cctype>
45
46 #include "globals.h"
47 #include "setup.h"
48 #include "video/screen.h"
49 #include "video/surface.h"
50 #include "gui/menu.h"
51 #include "utils/configfile.h"
52 #include "audio/sound_manager.h"
53 #include "gettext.h"
54
55 using namespace SuperTux;
56
57 #ifdef WIN32
58 #define mkdir(dir, mode)    mkdir(dir)
59 // on win32 we typically don't want LFS paths
60 #undef DATA_PREFIX
61 #define DATA_PREFIX "./data/"
62 #endif
63
64 /* Local function prototypes: */
65
66 void seticon(void);
67 void usage(char * prog, int ret);
68
69 /* Does the given file exist and is it accessible? */
70 int FileSystem::faccessible(const std::string& filename)
71 {
72   struct stat filestat;
73   if (stat(filename.c_str(), &filestat) == -1)
74     {
75       return false;
76     }
77   else
78     {
79       if(S_ISREG(filestat.st_mode))
80         return true;
81       else
82         return false;
83     }
84 }
85
86 /* Can we write to this location? */
87 int FileSystem::fwriteable(const std::string& filename)
88 {
89   FILE* fi;
90   fi = fopen(filename.c_str(), "wa");
91   if (fi == NULL)
92     {
93       return false;
94     }
95   fclose(fi);
96   return true;
97 }
98
99 /* Makes sure a directory is created in either the SuperTux home directory or the SuperTux base directory.*/
100 int FileSystem::fcreatedir(const std::string& relative_dir)
101 {
102   std::string path = st_dir + "/" + relative_dir + "/";
103   if(mkdir(path.c_str(),0755) != 0)
104     {
105       path = datadir + "/" + relative_dir + "/";
106       if(mkdir(path.c_str(),0755) != 0)
107         {
108           return false;
109         }
110       else
111         {
112           return true;
113         }
114     }
115   else
116     {
117       return true;
118     }
119 }
120
121 /* Get all names of sub-directories in a certain directory. */
122 /* Returns the number of sub-directories found. */
123 /* Note: The user has to free the allocated space. */
124 std::set<std::string> FileSystem::dsubdirs(const std::string &rel_path,const  std::string& expected_file)
125 {
126   DIR *dirStructP;
127   struct dirent *direntp;
128   std::set<std::string> sdirs;
129   std::string filename;
130   std::string path = st_dir + "/" + rel_path;
131
132   if((dirStructP = opendir(path.c_str())) != NULL)
133     {
134       while((direntp = readdir(dirStructP)) != NULL)
135         {
136           std::string absolute_filename;
137           struct stat buf;
138
139           absolute_filename = path + "/" + direntp->d_name;
140
141           if (stat(absolute_filename.c_str(), &buf) == 0 && S_ISDIR(buf.st_mode))
142             {
143               if(!expected_file.empty())
144                 {
145                   filename = path + "/" + direntp->d_name + "/" + expected_file;
146                   if(!faccessible(filename))
147                     continue;
148                 }
149
150               sdirs.insert(direntp->d_name);
151             }
152         }
153       closedir(dirStructP);
154     }
155
156   path = datadir + "/" + rel_path;
157   if((dirStructP = opendir(path.c_str())) != NULL)
158     {
159       while((direntp = readdir(dirStructP)) != NULL)
160         {
161           std::string absolute_filename;
162           struct stat buf;
163
164           absolute_filename = path + "/" + direntp->d_name;
165
166           if (stat(absolute_filename.c_str(), &buf) == 0 && S_ISDIR(buf.st_mode))
167             {
168               if(!expected_file.empty())
169                 {
170                   filename = path + "/" + direntp->d_name + "/" + expected_file;
171                   if(!faccessible(filename.c_str()))
172                     {
173                       continue;
174                     }
175                   else
176                     {
177                       filename = st_dir + "/" + rel_path + "/" + direntp->d_name + "/" + expected_file;
178                       if(faccessible(filename.c_str()))
179                         continue;
180                     }
181                 }
182
183               sdirs.insert(direntp->d_name);
184             }
185         }
186       closedir(dirStructP);
187     }
188
189   return sdirs;
190 }
191
192 std::set<std::string> FileSystem::dfiles(const std::string& rel_path, const  std::string& glob, const  std::string& exception_str)
193 {
194   DIR *dirStructP;
195   struct dirent *direntp;
196   std::set<std::string> sdirs;
197   std::string path = st_dir + "/" + rel_path;
198
199   if((dirStructP = opendir(path.c_str())) != NULL)
200     {
201       while((direntp = readdir(dirStructP)) != NULL)
202         {
203           std::string absolute_filename;
204           struct stat buf;
205
206           absolute_filename = path + "/" + direntp->d_name;
207
208           if (stat(absolute_filename.c_str(), &buf) == 0 && S_ISREG(buf.st_mode))
209             {
210               if(!exception_str.empty())
211                 {
212                   if(strstr(direntp->d_name,exception_str.c_str()) != NULL)
213                     continue;
214                 }
215               if(!glob.empty())
216                 if(strstr(direntp->d_name,glob.c_str()) == NULL)
217                   continue;
218
219               sdirs.insert(direntp->d_name);
220             }
221         }
222       closedir(dirStructP);
223     }
224
225   path = datadir + "/" + rel_path;
226   if((dirStructP = opendir(path.c_str())) != NULL)
227     {
228       while((direntp = readdir(dirStructP)) != NULL)
229         {
230           std::string absolute_filename;
231           struct stat buf;
232
233           absolute_filename = path + "/" + direntp->d_name;
234
235           if (stat(absolute_filename.c_str(), &buf) == 0 && S_ISREG(buf.st_mode))
236             {
237               if(!exception_str.empty())
238                 {
239                   if(strstr(direntp->d_name,exception_str.c_str()) != NULL)
240                     continue;
241                 }
242               if(!glob.empty())
243                 if(strstr(direntp->d_name,glob.c_str()) == NULL)
244                   continue;
245
246               sdirs.insert(direntp->d_name);
247             }
248         }
249       closedir(dirStructP);
250     }
251
252   return sdirs;
253 }
254
255 void Setup::init(const std::string& _package_name,
256         const std::string& _package_symbol_name,
257         const std::string& _package_version)
258 {
259   package_name = _package_name;
260   package_symbol_name = _package_symbol_name;    
261   package_version = _package_version;
262     
263   directories();
264   dictionary_manager.add_directory(datadir + "/locale");
265   dictionary_manager.set_charset("iso8859-1");
266 }
267
268 /* --- SETUP --- */
269 /* Set SuperTux configuration and save directories */
270 void Setup::directories()
271 {
272   std::string home;
273   /* Get home directory (from $HOME variable)... if we can't determine it,
274      use the current directory ("."): */
275   if (getenv("HOME") != NULL)
276     home = getenv("HOME");
277   else
278     home = ".";
279
280   st_dir = home + "/." + package_symbol_name;
281
282   /* Remove .supertux config-file from old SuperTux versions */
283   if(FileSystem::faccessible(st_dir))
284     {
285       remove(st_dir.c_str());
286     }
287
288   st_save_dir = st_dir + "/save";
289
290   /* Create them. In the case they exist they won't destroy anything. */
291   mkdir(st_dir.c_str(), 0755);
292   mkdir(st_save_dir.c_str(), 0755);
293
294   mkdir((st_dir + "/levels").c_str(), 0755);
295
296   // try current directory as datadir
297   if(datadir.empty()) {
298       if(FileSystem::faccessible("./data/intro.txt"))
299           datadir = "./data";
300   }
301
302   // User has not that a datadir, so we try some magic
303   if (datadir.empty())
304     {
305 #ifndef WIN32
306       // Detect datadir
307       char exe_file[PATH_MAX];
308       if (readlink("/proc/self/exe", exe_file, PATH_MAX) < 0)
309         {
310           puts("Couldn't read /proc/self/exe, using default path: " DATA_PREFIX);
311           datadir = DATA_PREFIX;
312         }
313       else
314         {
315           std::string exedir = std::string(dirname(exe_file)) + "/";
316           
317           datadir = exedir + "../data"; // SuperTux run from source dir
318           if (access(datadir.c_str(), F_OK) != 0)
319             {
320               datadir = exedir + "../../data";  //SuperTux run from source dir (with libtool script)
321               
322               if (access(datadir.c_str(), F_OK) != 0)
323               {
324               datadir = exedir + "../share/" + package_symbol_name; // SuperTux run from PATH
325               if (access(datadir.c_str(), F_OK) != 0) 
326                 { // If all fails, fall back to compiled path
327                   datadir = DATA_PREFIX; 
328                 }
329               }
330             }
331         }
332 #else
333   datadir = DATA_PREFIX;
334 #endif
335     }
336   printf("Datadir: %s\n", datadir.c_str());
337 }
338
339 void Setup::general(void)
340 {
341   /* Seed random number generator: */
342
343   srand(SDL_GetTicks());
344
345   /* Set icon image: */
346
347   seticon();
348
349   /* Unicode needed for input handling: */
350
351   SDL_EnableUNICODE(1);
352
353   /* Load GUI/menu images: */
354   checkbox = new Surface(datadir + "/images/status/checkbox.png", true);
355   checkbox_checked = new Surface(datadir + "/images/status/checkbox-checked.png", true);
356   back = new Surface(datadir + "/images/status/back.png", true);
357   arrow_left = new Surface(datadir + "/images/icons/left.png", true);
358   arrow_right = new Surface(datadir + "/images/icons/right.png", true);
359
360   /* Load the mouse-cursor */
361   mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1);
362   MouseCursor::set_current(mouse_cursor);
363   
364 }
365
366 void Setup::general_free(void)
367 {
368
369   /* Free GUI/menu images: */
370   delete checkbox;
371   delete checkbox_checked;
372   delete back;
373   delete arrow_left;
374   delete arrow_right;
375
376   /* Free mouse-cursor */
377   delete mouse_cursor;
378   
379 }
380
381 void Setup::video(unsigned int screen_w, unsigned int screen_h)
382 {
383   /* Init SDL Video: */
384   if (SDL_Init(SDL_INIT_VIDEO) < 0)
385     {
386       fprintf(stderr,
387               "\nError: I could not initialize video!\n"
388               "The Simple DirectMedia error that occured was:\n"
389               "%s\n\n", SDL_GetError());
390       exit(1);
391     }
392
393   /* Open display: */
394   if(use_gl)
395     video_gl(screen_w, screen_h);
396   else
397     video_sdl(screen_w, screen_h);
398
399   Surface::reload_all();
400
401   /* Set window manager stuff: */
402   SDL_WM_SetCaption((package_name + " " + package_version).c_str(), package_name.c_str());
403 }
404
405 void Setup::video_sdl(unsigned int screen_w, unsigned int screen_h)
406 {
407   if (use_fullscreen)
408     {
409       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
410       if (screen == NULL)
411         {
412           fprintf(stderr,
413                   "\nWarning: I could not set up fullscreen video for "
414                   "800x600 mode.\n"
415                   "The Simple DirectMedia error that occured was:\n"
416                   "%s\n\n", SDL_GetError());
417           use_fullscreen = false;
418         }
419     }
420   else
421     {
422       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_HWSURFACE | SDL_DOUBLEBUF );
423
424       if (screen == NULL)
425         {
426           fprintf(stderr,
427                   "\nError: I could not set up video for 800x600 mode.\n"
428                   "The Simple DirectMedia error that occured was:\n"
429                   "%s\n\n", SDL_GetError());
430           exit(1);
431         }
432     }
433 }
434
435 void Setup::video_gl(unsigned int screen_w, unsigned int screen_h)
436 {
437 #ifndef NOOPENGL
438
439   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
440   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
441   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
442   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
443   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
444
445   if (use_fullscreen)
446     {
447       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */
448       if (screen == NULL)
449         {
450           fprintf(stderr,
451                   "\nWarning: I could not set up fullscreen video for "
452                   "640x480 mode.\n"
453                   "The Simple DirectMedia error that occured was:\n"
454                   "%s\n\n", SDL_GetError());
455           use_fullscreen = false;
456         }
457     }
458   else
459     {
460       screen = SDL_SetVideoMode(screen_w, screen_h, 0, SDL_OPENGL);
461
462       if (screen == NULL)
463         {
464           fprintf(stderr,
465                   "\nError: I could not set up video for 640x480 mode.\n"
466                   "The Simple DirectMedia error that occured was:\n"
467                   "%s\n\n", SDL_GetError());
468           exit(1);
469         }
470     }
471
472   /*
473    * Set up OpenGL for 2D rendering.
474    */
475   glDisable(GL_DEPTH_TEST);
476   glDisable(GL_CULL_FACE);
477
478   glViewport(0, 0, screen->w, screen->h);
479   glMatrixMode(GL_PROJECTION);
480   glLoadIdentity();
481   glOrtho(0, screen->w, screen->h, 0, -1.0, 1.0);
482
483   glMatrixMode(GL_MODELVIEW);
484   glLoadIdentity();
485   glTranslatef(0.0f, 0.0f, 0.0f);
486
487 #endif
488
489 }
490
491 void Setup::joystick(void)
492 {
493
494   /* Init Joystick: */
495
496   use_joystick = true;
497
498   if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
499     {
500       fprintf(stderr, "Warning: I could not initialize joystick!\n"
501               "The Simple DirectMedia error that occured was:\n"
502               "%s\n\n", SDL_GetError());
503
504       use_joystick = false;
505     }
506   else
507     {
508       /* Open joystick: */
509       if (SDL_NumJoysticks() <= 0)
510         {
511           fprintf(stderr, "Info: No joysticks were found.\n");
512
513           use_joystick = false;
514         }
515       else
516         {
517           js = SDL_JoystickOpen(joystick_num);
518
519           if (js == NULL)
520             {
521               fprintf(stderr, "Warning: Could not open joystick %d.\n"
522                       "The Simple DirectMedia error that occured was:\n"
523                       "%s\n\n", joystick_num, SDL_GetError());
524
525               use_joystick = false;
526             }
527           else
528             {
529               if (SDL_JoystickNumAxes(js) < 2)
530                 {
531                   fprintf(stderr,
532                           "Warning: Joystick does not have enough axes!\n");
533
534                   use_joystick = false;
535                 }
536               else
537                 {
538                   if (SDL_JoystickNumButtons(js) < 2)
539                     {
540                       fprintf(stderr,
541                               "Warning: "
542                               "Joystick does not have enough buttons!\n");
543
544                       use_joystick = false;
545                     }
546                 }
547             }
548         }
549     }
550 }
551
552 void Setup::audio(void)
553 {
554
555   /* Init SDL Audio silently even if --disable-sound : */
556
557   if (SoundManager::get()->audio_device_available())
558     {
559       if (SDL_Init(SDL_INIT_AUDIO) < 0)
560         {
561           /* only print out message if sound or music
562              was not disabled at command-line
563            */
564           if (SoundManager::get()->sound_enabled() || SoundManager::get()->music_enabled())
565             {
566               fprintf(stderr,
567                       "\nWarning: I could not initialize audio!\n"
568                       "The Simple DirectMedia error that occured was:\n"
569                       "%s\n\n", SDL_GetError());
570             }
571           /* keep the programming logic the same :-)
572              because in this case, use_sound & use_music' values are ignored
573              when there's no available audio device
574           */
575           SoundManager::get()->enable_sound(false);
576           SoundManager::get()->enable_music(false);
577           SoundManager::get()->set_audio_device_available(false);
578         }
579     }
580
581
582   /* Open sound silently regarless the value of "use_sound": */
583
584   if (SoundManager::get()->audio_device_available())
585     {
586       if (SoundManager::get()->open_audio(44100, AUDIO_S16, 2, 2048) < 0)
587         {
588           /* only print out message if sound or music
589              was not disabled at command-line
590            */
591           if (SoundManager::get()->sound_enabled() || SoundManager::get()->music_enabled())
592             {
593               fprintf(stderr,
594                       "\nWarning: I could not set up audio for 44100 Hz "
595                       "16-bit stereo.\n"
596                       "The Simple DirectMedia error that occured was:\n"
597                       "%s\n\n", SDL_GetError());
598             }
599           SoundManager::get()->enable_sound(false);
600           SoundManager::get()->enable_music(false);
601           SoundManager::get()->set_audio_device_available(false);
602         }
603     }
604
605 }
606
607
608 /* --- SHUTDOWN --- */
609
610 void Termination::shutdown(void)
611 {
612   config->save();
613   SoundManager::get()->close_audio();
614   SDL_Quit();
615 }
616
617 /* --- ABORT! --- */
618
619 void Termination::abort(const std::string& reason, const std::string& details)
620 {
621   fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str());
622   shutdown();
623   ::abort();
624 }
625
626 /* Set Icon (private) */
627
628 void seticon(void)
629 {
630 //  int masklen;
631 //  Uint8 * mask;
632   SDL_Surface * icon;
633
634
635   /* Load icon into a surface: */
636
637   icon = IMG_Load((datadir + "/images/" + package_symbol_name + ".xpm").c_str());
638   if (icon == NULL)
639     {
640       fprintf(stderr,
641               "\nError: I could not load the icon image: %s%s\n"
642               "The Simple DirectMedia error that occured was:\n"
643               "%s\n\n", datadir.c_str(), ("/images/" + package_symbol_name + ".xpm").c_str(), SDL_GetError());
644       exit(1);
645     }
646
647
648   /* Create mask: */
649 /*
650   masklen = (((icon -> w) + 7) / 8) * (icon -> h);
651   mask = (Uint8*) malloc(masklen * sizeof(Uint8));
652   memset(mask, 0xFF, masklen);
653 */
654
655   /* Set icon: */
656
657   SDL_WM_SetIcon(icon, NULL);//mask);
658
659
660   /* Free icon surface & mask: */
661
662 //  free(mask);
663   SDL_FreeSurface(icon);
664 }
665
666
667 /* Parse command-line arguments: */
668
669 void Setup::parseargs(int argc, char * argv[])
670 {
671   int i;
672
673   config->load();
674
675   /* Parse arguments: */
676
677   for (i = 1; i < argc; i++)
678     {
679       if (strcmp(argv[i], "--fullscreen") == 0 ||
680           strcmp(argv[i], "-f") == 0)
681         {
682           use_fullscreen = true;
683         }
684       else if (strcmp(argv[i], "--window") == 0 ||
685                strcmp(argv[i], "-w") == 0)
686         {
687           use_fullscreen = false;
688         }
689       else if (strcmp(argv[i], "--joystick") == 0 || strcmp(argv[i], "-j") == 0)
690         {
691           assert(i+1 < argc);
692           joystick_num = atoi(argv[++i]);
693         }
694       else if (strcmp(argv[i], "--joymap") == 0)
695         {
696           assert(i+1 < argc);
697           if (sscanf(argv[++i],
698                      "%d:%d:%d:%d:%d", 
699                      &joystick_keymap.x_axis, 
700                      &joystick_keymap.y_axis, 
701                      &joystick_keymap.a_button, 
702                      &joystick_keymap.b_button, 
703                      &joystick_keymap.start_button) != 5)
704             {
705               puts("Warning: Invalid or incomplete joymap, should be: 'XAXIS:YAXIS:A:B:START'");
706             }
707           else
708             {
709               std::cout << "Using new joymap:\n"
710                         << "  X-Axis:       " << joystick_keymap.x_axis << "\n"
711                         << "  Y-Axis:       " << joystick_keymap.y_axis << "\n"
712                         << "  A-Button:     " << joystick_keymap.a_button << "\n"
713                         << "  B-Button:     " << joystick_keymap.b_button << "\n"
714                         << "  Start-Button: " << joystick_keymap.start_button << std::endl;
715             }
716         }
717       else if (strcmp(argv[i], "--leveleditor") == 0)
718         {
719           launch_leveleditor_mode = true;
720         }
721       else if (strcmp(argv[i], "--worldmap") == 0)
722         {
723           launch_worldmap_mode = true;
724         }
725       else if (strcmp(argv[i], "--flip-levels") == 0)
726         {
727           flip_levels_mode = true;
728         }
729       else if (strcmp(argv[i], "--datadir") == 0 
730                || strcmp(argv[i], "-d") == 0 )
731         {
732           assert(i+1 < argc);
733           datadir = argv[++i];
734         }
735       else if (strcmp(argv[i], "--show-fps") == 0)
736         {
737           /* Use full screen: */
738
739           show_fps = true;
740         }
741       else if (strcmp(argv[i], "--opengl") == 0 ||
742                strcmp(argv[i], "-gl") == 0)
743         {
744 #ifndef NOOPENGL
745           /* Use OpengGL: */
746
747           use_gl = true;
748 #endif
749         }
750       else if (strcmp(argv[i], "--sdl") == 0)
751           {
752             use_gl = false;
753           }
754       else if (strcmp(argv[i], "--usage") == 0)
755         {
756           /* Show usage: */
757
758           usage(argv[0], 0);
759         }
760       else if (strcmp(argv[i], "--version") == 0)
761         {
762           /* Show version: */
763           printf((package_name + " " + package_version + "\n").c_str() );
764           exit(0);
765         }
766       else if (strcmp(argv[i], "--disable-sound") == 0)
767         {
768           /* Disable the compiled in sound feature */
769           printf("Sounds disabled \n");
770           SoundManager::get()->enable_sound(false); 
771         }
772       else if (strcmp(argv[i], "--disable-music") == 0)
773         {
774           /* Disable the compiled in sound feature */
775           printf("Music disabled \n");
776           SoundManager::get()->enable_music(false); 
777         }
778       else if (strcmp(argv[i], "--debug") == 0)
779         {
780           /* Enable the debug-mode */
781           debug_mode = true;
782
783         }
784       else if (strcmp(argv[i], "--help") == 0)
785         {     /* Show help: */
786           puts(_(("  SuperTux  " + package_version + "\n"
787                "  Please see the file \"README.txt\" for more details.\n").c_str()));
788           printf(_("Usage: %s [OPTIONS] FILENAME\n\n"), argv[0]);
789           puts(_("Display Options:\n"
790                "  -f, --fullscreen    Run in fullscreen mode.\n"
791                "  -w, --window        Run in window mode.\n"
792                "  --opengl            If OpenGL support was compiled in, this will tell\n"
793                "                      SuperTux to make use of it.\n"
794                "  --sdl               Use the SDL software graphical renderer\n"
795                "\n"
796                "Sound Options:\n"
797                "  --disable-sound     If sound support was compiled in,  this will\n"
798                "                      disable sound for this session of the game.\n"
799                "  --disable-music     Like above, but this will disable music.\n"
800                "\n"
801                "Misc Options:\n"
802                "  -j, --joystick NUM  Use joystick NUM (default: 0)\n" 
803                "  --joymap XAXIS:YAXIS:A:B:START\n"
804                "                      Define how joystick buttons and axis should be mapped\n"
805                "  --leveleditor       Opens the leveleditor in a file.\n"
806                "  --worldmap          Opens the specified worldmap file.\n"
807                "  --flip-levels       Flip levels upside-down.\n"
808                "  -d, --datadir DIR   Load Game data from DIR (default: automatic)\n"
809                "  --debug             Enables the debug mode, which is useful for developers.\n"
810                "  --help              Display a help message summarizing command-line\n"
811                "                      options, license and game controls.\n"
812                "  --usage             Display a brief message summarizing command-line options.\n"
813                "  --version           Display the version of SuperTux you're running.\n\n"
814                ));
815           exit(0);
816         }
817       else if (argv[i][0] != '-')
818         {
819           level_startup_file = argv[i];
820         }
821       else
822         {
823           /* Unknown - complain! */
824
825           usage(argv[0], 1);
826         }
827     }
828 }
829
830
831 /* Display usage: */
832
833 void usage(char * prog, int ret)
834 {
835   FILE * fi;
836
837
838   /* Determine which stream to write to: */
839
840   if (ret == 0)
841     fi = stdout;
842   else
843     fi = stderr;
844
845
846   /* Display the usage message: */
847
848   fprintf(fi, _("Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug] | [--usage | --help | --version] [--leveleditor] [--worldmap] [--flip-levels] FILENAME\n"),
849           prog);
850
851
852   /* Quit! */
853
854   exit(ret);
855 }
856
857 std::set<std::string> FileSystem::read_directory(const std::string& pathname)
858 {
859   std::set<std::string> dirnames;
860   
861   DIR* dir = opendir(pathname.c_str());
862   if (dir)
863     {
864       struct dirent *direntp;
865       
866       while((direntp = readdir(dir)))
867         {
868           dirnames.insert(direntp->d_name);
869         }
870       
871       closedir(dir);
872     }
873
874   return dirnames;
875 }
876
877 /* EOF */