7 bill@newbreedsoftware.com
8 http://www.newbreedsoftware.com/supertux/
10 April 11, 2000 - November 7, 2001
19 #include <SDL_image.h>
23 #include <sys/types.h>
34 /* Local function prototypes: */
37 void usage(char * prog, int ret);
42 void st_directory_setup(void)
45 /* Set SuperTux configuration and save directories */
47 /* Get home directory (from $HOME variable)... if we can't determine it,
48 use the current directory ("."): */
50 if (getenv("HOME") != NULL)
51 home = getenv("HOME");
55 st_dir = (char *) malloc(sizeof(char) * (strlen(home) +
56 strlen("/.supertux") + 1));
58 strcat(st_dir, "/.supertux");
60 st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1));
62 strcpy(st_save_dir,st_dir);
63 strcat(st_save_dir,"/save");
65 /* Create them. In the case they exist it won't destroy anything. */
67 mkdir(st_save_dir, 0755);
70 void st_general_setup(void)
72 /* Seed random number generator: */
74 srand(SDL_GetTicks());
76 /* Load global images: */
78 letters_black = load_image(DATA_PREFIX "/images/status/letters-black.png",
81 letters_gold = load_image(DATA_PREFIX "/images/status/letters-gold.png",
86 letters_blue = load_image(DATA_PREFIX "/images/status/letters-blue.png",
89 letters_red = load_image(DATA_PREFIX "/images/status/letters-red.png",
99 void st_video_setup(void)
102 /* Init SDL Video: */
104 if (SDL_Init(SDL_INIT_VIDEO) < 0)
107 "\nError: I could not initialize video!\n"
108 "The Simple DirectMedia error that occured was:\n"
109 "%s\n\n", SDL_GetError());
115 if (use_fullscreen == YES)
117 screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
121 "\nWarning: I could not set up fullscreen video for "
123 "The Simple DirectMedia error that occured was:\n"
124 "%s\n\n", SDL_GetError());
129 if (use_fullscreen == NO)
131 screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
136 "\nError: I could not set up video for 640x480 mode.\n"
137 "The Simple DirectMedia error that occured was:\n"
138 "%s\n\n", SDL_GetError());
143 /* Set window manager stuff: */
145 SDL_WM_SetCaption("Super Tux", "Super Tux");
149 void st_joystick_setup(void)
157 if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
159 fprintf(stderr, "Warning: I could not initialize joystick!\n"
160 "The Simple DirectMedia error that occured was:\n"
161 "%s\n\n", SDL_GetError());
169 if (SDL_NumJoysticks() <= 0)
171 fprintf(stderr, "Warning: No joysticks are available.\n");
177 js = SDL_JoystickOpen(0);
181 fprintf(stderr, "Warning: Could not open joystick 1.\n"
182 "The Simple DirectMedia error that occured was:\n"
183 "%s\n\n", SDL_GetError());
189 /* Check for proper joystick configuration: */
191 if (SDL_JoystickNumAxes(js) < 2)
194 "Warning: Joystick does not have enough axes!\n");
200 if (SDL_JoystickNumButtons(js) < 2)
204 "Joystick does not have enough buttons!\n");
216 void st_audio_setup(void)
219 /* Init SDL Audio silently even if --disable-sound : */
221 if (audio_device == YES)
223 if (SDL_Init(SDL_INIT_AUDIO) < 0)
225 /* only print out message if sound or music
226 was not disabled at command-line
228 if (use_sound == YES || use_music == YES)
231 "\nWarning: I could not initialize audio!\n"
232 "The Simple DirectMedia error that occured was:\n"
233 "%s\n\n", SDL_GetError());
235 /* keep the programming logic the same :-)
236 because in this case, use_sound & use_music' values are ignored
237 when there's no available audio device
246 /* Open sound silently regarless the value of "use_sound": */
248 if (audio_device == YES)
250 if (open_audio(44100, AUDIO_S16, 2, 512) < 0)
252 /* only print out message if sound or music
253 was not disabled at command-line
255 if ((use_sound == YES) || (use_music == YES))
258 "\nWarning: I could not set up audio for 44100 Hz "
260 "The Simple DirectMedia error that occured was:\n"
261 "%s\n\n", SDL_GetError());
272 /* --- SHUTDOWN --- */
274 void st_shutdown(void)
283 void st_abort(char * reason, char * details)
285 fprintf(stderr, "\nError: %s\n%s\n\n", reason, details);
291 /* Set Icon (private) */
300 /* Load icon into a surface: */
302 icon = IMG_Load(DATA_PREFIX "/images/icon.png");
306 "\nError: I could not load the icon image: %s\n"
307 "The Simple DirectMedia error that occured was:\n"
308 "%s\n\n", DATA_PREFIX "images/icon.png", SDL_GetError());
315 masklen = (((icon -> w) + 7) / 8) * (icon -> h);
316 mask = malloc(masklen * sizeof(Uint8));
317 memset(mask, 0xFF, masklen);
322 SDL_WM_SetIcon(icon, mask);
325 /* Free icon surface & mask: */
328 SDL_FreeSurface(icon);
332 /* Parse command-line arguments: */
334 void parseargs(int argc, char * argv[])
355 /* Parse arguments: */
357 for (i = 1; i < argc; i++)
359 if (strcmp(argv[i], "--fullscreen") == 0 ||
360 strcmp(argv[i], "-f") == 0)
362 /* Use full screen: */
364 use_fullscreen = YES;
366 else if (strcmp(argv[i], "--usage") == 0)
372 else if (strcmp(argv[i], "--version") == 0)
376 printf("Super Tux - version " VERSION "\n");
379 else if (strcmp(argv[i], "--disable-sound") == 0)
381 /* Disable the compiled in sound feature */
383 printf("Sounds disabled \n");
386 printf("Warning: Sounds feature is not compiled in \n");
389 else if (strcmp(argv[i], "--disable-music") == 0)
391 /* Disable the compiled in sound feature */
393 printf("Music disabled \n");
396 printf("Warning: Music feature is not compiled in \n");
399 else if (strcmp(argv[i], "--debug-mode") == 0)
401 /* Enable the debug-mode */
405 else if (strcmp(argv[i], "--help") == 0)
408 printf("Super Tux " VERSION "\n\n");
410 printf("---------- Command-line options ----------\n\n");
412 printf(" --disable-sound - If sound support was compiled in, this will\n disable sound for this session of the game.\n\n");
414 printf(" --disable-music - Like above, but this will disable music.\n\n");
416 printf(" --fullscreen - Run in fullscreen mode.\n\n");
418 printf(" --debug-mode - Enables the debug-mode, which is useful for developers.\n\n");
420 printf(" --help - Display a help message summarizing command-line\n options, license and game controls.\n\n");
422 printf(" --usage - Display a brief message summarizing command-line options.\n\n");
424 printf(" --version - Display the version of SuperTux you're running.\n\n\n");
427 printf("---------- License ----------\n\n");
428 printf(" This program comes with ABSOLUTELY NO WARRANTY.\n");
429 printf(" This is free software, and you are welcome to redistribute\n");
430 printf(" or modify it under certain conditions. See the file \n");
431 printf(" \"COPYING.txt\" for more details.\n\n\n");
433 printf("---------- Game controls ----------\n\n");
434 printf(" Please see the file \"README.txt\"\n\n");
440 /* Unknown - complain! */
450 void usage(char * prog, int ret)
455 /* Determine which stream to write to: */
463 /* Display the usage message: */
465 fprintf(fi, "Usage: %s [--fullscreen] [--disable-sound] [--disable-music] [--debug-mode] | [--usage | --help | --version]\n",