more gameplay improvements. level-editor is getting closer to a useable state . etc.
[supertux.git] / src / setup.c
1 /*
2   setup.c
3   
4   Super Tux - Setup
5   
6   by Bill Kendrick
7   bill@newbreedsoftware.com
8   http://www.newbreedsoftware.com/supertux/
9   
10   April 11, 2000 - February 1st, 2004
11 */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <errno.h>
17 #include <unistd.h>
18 #include <SDL.h>
19 #include <SDL_image.h>
20 #ifndef NOOPENGL
21 #include <SDL_opengl.h>
22 #endif
23
24 #ifdef LINUX
25 #include <pwd.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <dirent.h>
29 #include <ctype.h>
30 #endif
31
32 #include "defines.h"
33 #include "globals.h"
34 #include "setup.h"
35 #include "screen.h"
36 #include "texture.h"
37 #include "menu.h"
38 #include "gameloop.h"
39
40 /* Local function prototypes: */
41
42 void seticon(void);
43 void usage(char * prog, int ret);
44
45 /* Does the given file exist and is it accessible? */
46 int faccessible(char *filename)
47 {
48   struct stat filestat;
49   if (stat(filename, &filestat) == -1)
50     return NO;
51   else
52     return YES;
53 }
54
55 /* Can we write to this location? */
56 int fwriteable(char *filename)
57 {
58   FILE* fi;
59   fi = fopen(filename, "wa");
60   if (fi == NULL)
61     {
62       return NO;
63     }
64   return YES;
65 }
66
67 /* Makes sure a directory is created in either the SuperTux base directory or the SuperTux base directory.*/
68 int fcreatedir(char* relative_dir)
69 {
70   char path[1024];
71   snprintf(path, 1024, "%s/%s/", st_dir, relative_dir);
72   if(mkdir(path,0755) != 0)
73     {
74       snprintf(path, 1024, "%s/%s/", DATA_PREFIX, relative_dir);
75       if(mkdir(path,0755) != 0)
76         {
77           return NO;
78         }
79       else
80         {
81           return YES;
82         }
83     }
84   else
85     {
86       return YES;
87     }
88 }
89
90 /* Get all names of sub-directories in a certain directory. */
91 /* Returns the number of sub-directories found. */
92 /* Note: The user has to free the allocated space. */
93 char ** dsubdirs(char *rel_path, char* expected_file, int* num)
94 {
95   DIR *dirStructP;
96   struct dirent *direntp;
97   int i = 0;
98   char ** sdirs= NULL;
99   char filename[1024];
100   char path[1024];
101
102   sprintf(path,"%s/%s",st_dir,rel_path);
103   if((dirStructP = opendir(path)) != NULL)
104     {
105       while((direntp = readdir(dirStructP)) != NULL)
106         {
107           char absolute_filename[1024];
108           struct stat buf;
109
110           sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
111
112           if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode))
113             {
114               if(expected_file != NULL)
115                 {
116                   sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file);
117                   if(!faccessible(filename))
118                     continue;
119                 }
120
121               sdirs = (char**) realloc(sdirs, sizeof(char*) * (i+1));
122               sdirs[i] = (char*) malloc(sizeof(char) * strlen(direntp->d_name) + 1 );
123               strcpy(sdirs[i],direntp->d_name);
124               ++i;
125             }
126         }
127       closedir(dirStructP);
128     }
129
130   sprintf(path,"%s/%s",DATA_PREFIX,rel_path);
131   if((dirStructP = opendir(path)) != NULL)
132     {
133       while((direntp = readdir(dirStructP)) != NULL)
134         {
135           char absolute_filename[1024];
136           struct stat buf;
137
138           sprintf(absolute_filename, "%s/%s", path, direntp->d_name);
139
140           if (stat(absolute_filename, &buf) == 0 && S_ISDIR(buf.st_mode))
141             {
142               if(expected_file != NULL)
143                 {
144                   sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file);
145                   if(!faccessible(filename))
146                     {
147                       continue;
148                     }
149                   else
150                     {
151                       sprintf(filename,"%s/%s/%s/%s",st_dir,rel_path,direntp->d_name,expected_file);
152                       if(faccessible(filename))
153                         continue;
154                     }
155                 }
156
157               sdirs = (char**) realloc(sdirs, sizeof(char*) * (i+1));
158               sdirs[i] = (char*) malloc(sizeof(char) * strlen(direntp->d_name) + 1 );
159               strcpy(sdirs[i],direntp->d_name);
160               ++i;
161             }
162         }
163       closedir(dirStructP);
164     }
165
166   *num = i;
167   return sdirs;
168 }
169
170 void free_strings(char **strings, int num)
171 {
172   int i;
173   for(i=0; i < num; ++i)
174     free(strings[i]);
175 }
176
177 /* --- SETUP --- */
178 /* Set SuperTux configuration and save directories */
179 void st_directory_setup(void)
180 {
181   char *home;
182   char str[1024];
183   /* Get home directory (from $HOME variable)... if we can't determine it,
184      use the current directory ("."): */
185   if (getenv("HOME") != NULL)
186     home = getenv("HOME");
187   else
188     home = ".";
189
190   st_dir = (char *) malloc(sizeof(char) * (strlen(home) +
191                            strlen("/.supertux") + 1));
192   strcpy(st_dir, home);
193   strcat(st_dir, "/.supertux");
194
195   st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1));
196
197   strcpy(st_save_dir,st_dir);
198   strcat(st_save_dir,"/save");
199
200   /* Create them. In the case they exist they won't destroy anything. */
201 #ifdef LINUX
202
203   mkdir(st_dir, 0755);
204   mkdir(st_save_dir, 0755);
205
206   sprintf(str, "%s/levels", st_dir);
207   mkdir(str, 0755);
208 #else
209   #ifdef WIN32
210
211   mkdir(st_dir);
212   mkdir(st_save_dir);
213   sprintf(str, "%s/levels", st_dir);
214   mkdir(str);
215 #endif
216 #endif
217
218 }
219
220 /* Create and setup menus. */
221 void st_menu(void)
222 {
223   menu_init(&main_menu);
224   menu_additem(&main_menu,menu_item_create(MN_LABEL,"Main Menu",0,0));
225   menu_additem(&main_menu,menu_item_create(MN_HL,"",0,0));
226   menu_additem(&main_menu,menu_item_create(MN_ACTION,"Start Game",0,0));
227   menu_additem(&main_menu,menu_item_create(MN_GOTO,"Load Game",0,&load_game_menu));
228   menu_additem(&main_menu,menu_item_create(MN_GOTO,"Options",0,&options_menu));
229   menu_additem(&main_menu,menu_item_create(MN_ACTION,"Level editor",0,0));
230   menu_additem(&main_menu,menu_item_create(MN_HL,"",0,0));
231   menu_additem(&main_menu,menu_item_create(MN_ACTION,"Quit",0,0));
232
233   menu_init(&options_menu);
234   menu_additem(&options_menu,menu_item_create(MN_LABEL,"Options",0,0));
235   menu_additem(&options_menu,menu_item_create(MN_HL,"",0,0));
236   menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Fullscreen",use_fullscreen,0));
237   if(audio_device == YES)
238     {
239       menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Sound     ",use_sound,0));
240       menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Music     ",use_music,0));
241     }
242   else
243     {
244       menu_additem(&options_menu,menu_item_create(MN_DEACTIVE,"Sound     ",use_sound,0));
245       menu_additem(&options_menu,menu_item_create(MN_DEACTIVE,"Music     ",use_music,0));
246     }
247   menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Show FPS  ",show_fps,0));
248   menu_additem(&options_menu,menu_item_create(MN_HL,"",0,0));
249   menu_additem(&options_menu,menu_item_create(MN_BACK,"Back",0,0));
250
251   menu_init(&load_game_menu);
252   menu_additem(&load_game_menu,menu_item_create(MN_LABEL,"Load Game",0,0));
253   menu_additem(&load_game_menu,menu_item_create(MN_HL,"",0,0));
254   menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 1",0,0));
255   menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 2",0,0));
256   menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 3",0,0));
257   menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 4",0,0));
258   menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 5",0,0));
259   menu_additem(&load_game_menu,menu_item_create(MN_HL,"",0,0));
260   menu_additem(&load_game_menu,menu_item_create(MN_BACK,"Back",0,0));
261
262   menu_init(&save_game_menu);
263   menu_additem(&save_game_menu,menu_item_create(MN_LABEL,"Save Game",0,0));
264   menu_additem(&save_game_menu,menu_item_create(MN_HL,"",0,0));
265   menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 1",0,0));
266   menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 2",0,0));
267   menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 3",0,0));
268   menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 4",0,0));
269   menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 5",0,0));
270   menu_additem(&save_game_menu,menu_item_create(MN_HL,"",0,0));
271   menu_additem(&save_game_menu,menu_item_create(MN_BACK,"Back",0,0));
272
273   menu_init(&game_menu);
274   menu_additem(&game_menu,menu_item_create(MN_LABEL,"InGame Menu",0,0));
275   menu_additem(&game_menu,menu_item_create(MN_HL,"",0,0));
276   menu_additem(&game_menu,menu_item_create(MN_ACTION,"Return To Game",0,0));
277   menu_additem(&game_menu,menu_item_create(MN_GOTO,"Save Game",0,&save_game_menu));
278   menu_additem(&game_menu,menu_item_create(MN_GOTO,"Load Game",0,&load_game_menu));
279   menu_additem(&game_menu,menu_item_create(MN_GOTO,"Options",0,&options_menu));
280   menu_additem(&game_menu,menu_item_create(MN_HL,"",0,0));
281   menu_additem(&game_menu,menu_item_create(MN_ACTION,"Quit Game",0,0));
282
283   menu_init(&highscore_menu);
284   menu_additem(&highscore_menu,menu_item_create(MN_TEXTFIELD,"Enter your name:",0,0));
285
286 }
287
288 void update_load_save_game_menu(menu_type* pmenu, int load)
289 {
290   int i;
291
292   for(i = 2; i < 7; ++i)
293     {
294       char *tmp;
295       slotinfo(&tmp,i-1);
296       if(load && strlen(tmp) == strlen("Slot X - Free") )
297         pmenu->item[i].kind = MN_DEACTIVE;
298       else
299         pmenu->item[i].kind = MN_ACTION;
300       menu_item_change_text(&pmenu->item[i],tmp);
301       free(tmp);
302     }
303 }
304
305 void process_save_load_game_menu(int save)
306 {
307   int slot;
308   switch (slot = menu_check(save ? &save_game_menu : &load_game_menu))
309     {
310     default:
311       if(slot != -1)
312         {
313           if(save == YES)
314             {
315               savegame(slot);
316             }
317           else
318             {
319               if(game_started == NO)
320                 gameloop("whatever",slot,ST_GL_LOAD_GAME);
321               else
322                 loadgame(slot);
323             }
324           st_pause_ticks_stop();
325         }
326       break;
327     }
328 }
329
330 /* Handle changes made to global settings in the options menu. */
331 void process_options_menu(void)
332 {
333   switch (menu_check(&options_menu))
334     {
335     case 2:
336       if(use_fullscreen != options_menu.item[2].toggled)
337         {
338           use_fullscreen = !use_fullscreen;
339           st_video_setup();
340         }
341       break;
342     case 3:
343       if(use_sound != options_menu.item[3].toggled)
344         use_sound = !use_sound;
345       break;
346     case 4:
347       if(use_music != options_menu.item[4].toggled)
348         {
349           if(use_music == YES)
350             {
351               if(playing_music())
352                 {
353                   halt_music();
354                 }
355               use_music = NO;
356             }
357           else
358             {
359               use_music = YES;
360               if (!playing_music())
361                 {
362                   play_current_music();
363                 }
364             }
365         }
366       break;
367     case 5:
368       if(show_fps != options_menu.item[5].toggled)
369         show_fps = !show_fps;
370       break;
371     }
372 }
373
374 void st_general_setup(void)
375 {
376   /* Seed random number generator: */
377
378   srand(SDL_GetTicks());
379
380   /* Load global images: */
381
382   text_load(&black_text,DATA_PREFIX "/images/status/letters-black.png", TEXT_TEXT, 16,18);
383   text_load(&gold_text,DATA_PREFIX "/images/status/letters-gold.png", TEXT_TEXT, 16,18);
384   text_load(&blue_text,DATA_PREFIX "/images/status/letters-blue.png", TEXT_TEXT, 16,18);
385   text_load(&red_text,DATA_PREFIX "/images/status/letters-red.png", TEXT_TEXT, 16,18);
386   text_load(&white_text,DATA_PREFIX "/images/status/letters-white.png", TEXT_TEXT, 16,18);
387   text_load(&white_small_text,DATA_PREFIX "/images/status/letters-white-small.png", TEXT_TEXT, 8,9);
388   text_load(&white_big_text,DATA_PREFIX "/images/status/letters-white-big.png", TEXT_TEXT, 24,27);
389   text_load(&yellow_nums,DATA_PREFIX "/images/status/numbers.png", TEXT_NUM, 32,32);
390
391   /* Load GUI/menu images: */
392   texture_load(&checkbox, DATA_PREFIX "/images/status/checkbox.png", USE_ALPHA);
393   texture_load(&checkbox_checked, DATA_PREFIX "/images/status/checkbox-checked.png", USE_ALPHA);
394   texture_load(&back, DATA_PREFIX "/images/status/back.png", USE_ALPHA);
395   texture_load(&arrow_left, DATA_PREFIX "/images/icons/left.png", USE_ALPHA);
396   texture_load(&arrow_right, DATA_PREFIX "/images/icons/right.png", USE_ALPHA);
397
398   /* Set icon image: */
399
400   seticon();
401   SDL_EnableUNICODE(1);
402
403 }
404
405 void st_general_free(void)
406 {
407
408   /* Free global images: */
409
410   text_free(&black_text);
411   text_free(&gold_text);
412   text_free(&white_text);
413   text_free(&blue_text);
414   text_free(&red_text);
415   text_free(&white_small_text);
416
417   /* Free GUI/menu images: */
418   texture_free(&checkbox);
419   texture_free(&checkbox_checked);
420   texture_free(&back);
421
422   /* Free menus */
423
424   menu_free(&main_menu);
425   menu_free(&game_menu);
426   menu_free(&options_menu);
427   menu_free(&highscore_menu);
428
429 }
430
431 void st_video_setup(void)
432 {
433
434   if(screen != NULL)
435     SDL_FreeSurface(screen);
436
437   /* Init SDL Video: */
438
439   if (SDL_Init(SDL_INIT_VIDEO) < 0)
440     {
441       fprintf(stderr,
442               "\nError: I could not initialize video!\n"
443               "The Simple DirectMedia error that occured was:\n"
444               "%s\n\n", SDL_GetError());
445       exit(1);
446     }
447
448   /* Open display: */
449
450   if(use_gl)
451     st_video_setup_gl();
452   else
453     st_video_setup_sdl();
454
455   texture_setup();
456
457   /* Set window manager stuff: */
458
459   SDL_WM_SetCaption("Super Tux", "Super Tux");
460
461 }
462
463 void st_video_setup_sdl(void)
464 {
465   SDL_FreeSurface(screen);
466
467   if (use_fullscreen == YES)
468     {
469       screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
470       if (screen == NULL)
471         {
472           fprintf(stderr,
473                   "\nWarning: I could not set up fullscreen video for "
474                   "640x480 mode.\n"
475                   "The Simple DirectMedia error that occured was:\n"
476                   "%s\n\n", SDL_GetError());
477           use_fullscreen = NO;
478         }
479     }
480   else
481     {
482       screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF );
483
484       if (screen == NULL)
485         {
486           fprintf(stderr,
487                   "\nError: I could not set up video for 640x480 mode.\n"
488                   "The Simple DirectMedia error that occured was:\n"
489                   "%s\n\n", SDL_GetError());
490           exit(1);
491         }
492     }
493 }
494
495 void st_video_setup_gl(void)
496 {
497 #ifndef NOOPENGL
498
499   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
500   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
501   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
502   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
503   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
504
505   if (use_fullscreen == YES)
506     {
507       screen = SDL_SetVideoMode(640, 480, 32, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */
508       if (screen == NULL)
509         {
510           fprintf(stderr,
511                   "\nWarning: I could not set up fullscreen video for "
512                   "640x480 mode.\n"
513                   "The Simple DirectMedia error that occured was:\n"
514                   "%s\n\n", SDL_GetError());
515           use_fullscreen = NO;
516         }
517     }
518   else
519     {
520       screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
521
522       if (screen == NULL)
523         {
524           fprintf(stderr,
525                   "\nError: I could not set up video for 640x480 mode.\n"
526                   "The Simple DirectMedia error that occured was:\n"
527                   "%s\n\n", SDL_GetError());
528           exit(1);
529         }
530     }
531
532   /*
533    * Set up OpenGL for 2D rendering.
534    */
535   glDisable(GL_DEPTH_TEST);
536   glDisable(GL_CULL_FACE);
537
538   glViewport(0, 0, screen->w, screen->h);
539   glMatrixMode(GL_PROJECTION);
540   glLoadIdentity();
541   glOrtho(0, screen->w, screen->h, 0, -1.0, 1.0);
542
543   glMatrixMode(GL_MODELVIEW);
544   glLoadIdentity();
545   glTranslatef(0.0f, 0.0f, 0.0f);
546
547 #endif
548
549 }
550
551 void st_joystick_setup(void)
552 {
553
554   /* Init Joystick: */
555
556 #ifdef JOY_YES
557   use_joystick = YES;
558
559   if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
560     {
561       fprintf(stderr, "Warning: I could not initialize joystick!\n"
562               "The Simple DirectMedia error that occured was:\n"
563               "%s\n\n", SDL_GetError());
564
565       use_joystick = NO;
566     }
567   else
568     {
569       /* Open joystick: */
570
571       if (SDL_NumJoysticks() <= 0)
572         {
573           fprintf(stderr, "Warning: No joysticks are available.\n");
574
575           use_joystick = NO;
576         }
577       else
578         {
579           js = SDL_JoystickOpen(0);
580
581           if (js == NULL)
582             {
583               fprintf(stderr, "Warning: Could not open joystick 1.\n"
584                       "The Simple DirectMedia error that occured was:\n"
585                       "%s\n\n", SDL_GetError());
586
587               use_joystick = NO;
588             }
589           else
590             {
591               /* Check for proper joystick configuration: */
592
593               if (SDL_JoystickNumAxes(js) < 2)
594                 {
595                   fprintf(stderr,
596                           "Warning: Joystick does not have enough axes!\n");
597
598                   use_joystick = NO;
599                 }
600               else
601                 {
602                   if (SDL_JoystickNumButtons(js) < 2)
603                     {
604                       fprintf(stderr,
605                               "Warning: "
606                               "Joystick does not have enough buttons!\n");
607
608                       use_joystick = NO;
609                     }
610                 }
611             }
612         }
613     }
614 #endif
615
616 }
617
618 void st_audio_setup(void)
619 {
620
621   /* Init SDL Audio silently even if --disable-sound : */
622
623   if (audio_device == YES)
624     {
625       if (SDL_Init(SDL_INIT_AUDIO) < 0)
626         {
627           /* only print out message if sound or music
628              was not disabled at command-line
629            */
630           if (use_sound == YES || use_music == YES)
631             {
632               fprintf(stderr,
633                       "\nWarning: I could not initialize audio!\n"
634                       "The Simple DirectMedia error that occured was:\n"
635                       "%s\n\n", SDL_GetError());
636             }
637           /* keep the programming logic the same :-)
638              because in this case, use_sound & use_music' values are ignored
639              when there's no available audio device
640           */
641           use_sound = NO;
642           use_music = NO;
643           audio_device = NO;
644         }
645     }
646
647
648   /* Open sound silently regarless the value of "use_sound": */
649
650   if (audio_device == YES)
651     {
652       if (open_audio(44100, AUDIO_S16, 2, 2048) < 0)
653         {
654           /* only print out message if sound or music
655              was not disabled at command-line
656            */
657           if ((use_sound == YES) || (use_music == YES))
658             {
659               fprintf(stderr,
660                       "\nWarning: I could not set up audio for 44100 Hz "
661                       "16-bit stereo.\n"
662                       "The Simple DirectMedia error that occured was:\n"
663                       "%s\n\n", SDL_GetError());
664             }
665           use_sound = NO;
666           use_music = NO;
667           audio_device = NO;
668         }
669     }
670
671 }
672
673
674 /* --- SHUTDOWN --- */
675
676 void st_shutdown(void)
677 {
678   close_audio();
679   SDL_Quit();
680 }
681
682
683 /* --- ABORT! --- */
684
685 void st_abort(char * reason, char * details)
686 {
687   fprintf(stderr, "\nError: %s\n%s\n\n", reason, details);
688   st_shutdown();
689   exit(1);
690 }
691
692
693 /* Set Icon (private) */
694
695 void seticon(void)
696 {
697   int masklen;
698   Uint8 * mask;
699   SDL_Surface * icon;
700
701
702   /* Load icon into a surface: */
703
704   icon = IMG_Load(DATA_PREFIX "/images/icon.png");
705   if (icon == NULL)
706     {
707       fprintf(stderr,
708               "\nError: I could not load the icon image: %s\n"
709               "The Simple DirectMedia error that occured was:\n"
710               "%s\n\n", DATA_PREFIX "images/icon.png", SDL_GetError());
711       exit(1);
712     }
713
714
715   /* Create mask: */
716
717   masklen = (((icon -> w) + 7) / 8) * (icon -> h);
718   mask = (Uint8*) malloc(masklen * sizeof(Uint8));
719   memset(mask, 0xFF, masklen);
720
721
722   /* Set icon: */
723
724   SDL_WM_SetIcon(icon, mask);
725
726
727   /* Free icon surface & mask: */
728
729   free(mask);
730   SDL_FreeSurface(icon);
731 }
732
733
734 /* Parse command-line arguments: */
735
736 void parseargs(int argc, char * argv[])
737 {
738   int i;
739
740   /* Set defaults: */
741
742
743   debug_mode = NO;
744   use_fullscreen = NO;
745   show_fps = NO;
746   use_gl = NO;
747
748 #ifndef NOSOUND
749
750   use_sound = YES;
751   use_music = YES;
752   audio_device = YES;
753 #else
754
755   use_sound = NO;
756   use_music = NO;
757   audio_device = NO;
758 #endif
759
760   /* Parse arguments: */
761
762   for (i = 1; i < argc; i++)
763     {
764       if (strcmp(argv[i], "--fullscreen") == 0 ||
765           strcmp(argv[i], "-f") == 0)
766         {
767           /* Use full screen: */
768
769           use_fullscreen = YES;
770         }
771       else if (strcmp(argv[i], "--show-fps") == 0)
772         {
773           /* Use full screen: */
774
775           show_fps = YES;
776         }
777       else if (strcmp(argv[i], "--opengl") == 0 ||
778                strcmp(argv[i], "-gl") == 0)
779         {
780 #ifndef NOOPENGL
781           /* Use OpengGL: */
782
783           use_gl = YES;
784 #endif
785
786         }
787       else if (strcmp(argv[i], "--usage") == 0)
788         {
789           /* Show usage: */
790
791           usage(argv[0], 0);
792         }
793       else if (strcmp(argv[i], "--version") == 0)
794         {
795           /* Show version: */
796
797           printf("Super Tux - version " VERSION "\n");
798           exit(0);
799         }
800       else if (strcmp(argv[i], "--disable-sound") == 0)
801         {
802           /* Disable the compiled in sound feature */
803 #ifndef NOSOUND
804           printf("Sounds disabled \n");
805           use_sound = NO;
806 #else
807
808           printf("Warning: Sounds feature is not compiled in \n");
809 #endif
810
811         }
812       else if (strcmp(argv[i], "--disable-music") == 0)
813         {
814           /* Disable the compiled in sound feature */
815 #ifndef NOSOUND
816           printf("Music disabled \n");
817           use_music = NO;
818 #else
819
820           printf("Warning: Music feature is not compiled in \n");
821 #endif
822
823         }
824       else if (strcmp(argv[i], "--debug-mode") == 0)
825         {
826           /* Enable the debug-mode */
827           debug_mode = YES;
828
829         }
830       else if (strcmp(argv[i], "--help") == 0)
831         {         /* Show help: */
832
833           printf("Super Tux " VERSION "\n\n");
834
835           printf("----------  Command-line options  ----------\n\n");
836
837           printf("  --opengl            - If opengl support was compiled in, this will enable the EXPERIMENTAL OpenGL mode.\n\n");
838
839           printf("  --disable-sound     - If sound support was compiled in,  this will\n                        disable sound for this session of the game.\n\n");
840
841           printf("  --disable-music     - Like above, but this will disable music.\n\n");
842
843           printf("  --fullscreen        - Run in fullscreen mode.\n\n");
844
845           printf("  --debug-mode        - Enables the debug-mode, which is useful for developers.\n\n");
846
847           printf("  --help              - Display a help message summarizing command-line\n                        options, license and game controls.\n\n");
848
849           printf("  --usage             - Display a brief message summarizing command-line options.\n\n");
850
851           printf("  --version           - Display the version of SuperTux you're running.\n\n\n");
852
853
854           printf("----------          License       ----------\n\n");
855           printf("  This program comes with ABSOLUTELY NO WARRANTY.\n");
856           printf("  This is free software, and you are welcome to redistribute\n");
857           printf("  or modify it under certain conditions. See the file \n");
858           printf("  \"COPYING.txt\" for more details.\n\n\n");
859
860           printf("----------      Game controls     ----------\n\n");
861           printf("  Please see the file \"README.txt\"\n\n");
862
863           exit(0);
864         }
865       else
866         {
867           /* Unknown - complain! */
868
869           usage(argv[0], 1);
870         }
871     }
872 }
873
874
875 /* Display usage: */
876
877 void usage(char * prog, int ret)
878 {
879   FILE * fi;
880
881
882   /* Determine which stream to write to: */
883
884   if (ret == 0)
885     fi = stdout;
886   else
887     fi = stderr;
888
889
890   /* Display the usage message: */
891
892   fprintf(fi, "Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug-mode] | [--usage | --help | --version]\n",
893           prog);
894
895
896   /* Quit! */
897
898   exit(ret);
899 }
900