Remove insidious F11 fullscreen toggle. That will never work under Windows.
[neverball] / ball / main.c
index 73d137a..f9fb625 100644 (file)
 
 /*---------------------------------------------------------------------------*/
 
-#ifdef WIN32
-#pragma comment(lib, "SDL_ttf.lib")
-#pragma comment(lib, "SDL_mixer.lib")
-#pragma comment(lib, "SDL_image.lib")
-#pragma comment(lib, "SDL.lib")
-#pragma comment(lib, "SDLmain.lib")
-#pragma comment(lib, "opengl32.lib")
-#endif
-
-/*---------------------------------------------------------------------------*/
-
 #include <SDL.h>
-#include <SDL_image.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
@@ -40,6 +28,7 @@
 #include "game.h"
 #include "gui.h"
 #include "set.h"
+#include "text.h"
 
 #include "st_conf.h"
 #include "st_title.h"
@@ -83,16 +72,6 @@ static void toggle_wire(void)
     }
 }
 
-static void toggle_fullscreen(void)
-{
-    int x, y;
-
-    SDL_GetMouseState(&x, &y);
-    config_mode(!config_get_d(CONFIG_FULLSCREEN), config_get_d(CONFIG_WIDTH),
-                config_get_d(CONFIG_HEIGHT));
-    SDL_WarpMouse(x, y);
-}
-
 /*---------------------------------------------------------------------------*/
 
 static int loop(void)
@@ -142,13 +121,12 @@ static int loop(void)
 
             else switch (c)
             {
-            case SDLK_F11:   toggle_fullscreen();       break;
             case SDLK_F10:   shot();                    break;
             case SDLK_F9:    config_tgl_d(CONFIG_FPS);  break;
             case SDLK_F8:    config_tgl_d(CONFIG_NICE); break;
 
             case SDLK_F7:
-                if (config_get_d(CONFIG_CHEAT))
+                if (config_cheat())
                     toggle_wire();
                 break;
 
@@ -221,72 +199,94 @@ static int loop(void)
 
 /*---------------------------------------------------------------------------*/
 
-/* Option values */
-
-static char *data_path    = NULL;
-static char *replay_path  = NULL;
-static int   display_info = 0;
-
-/* Option handling */
+static char *data_path = NULL;
+static char *demo_path = NULL;
+
+static unsigned int display_info = 0;
+static unsigned int replay_demo  = 0;
+
+#define usage \
+    L_(                                                                   \
+        "Usage: %s [options ...]\n"                                       \
+        "Options:\n"                                                      \
+        "  -h, --help                show this usage message.\n"          \
+        "  -v, --version             show version.\n"                     \
+        "  -d, --data <dir>          use 'dir' as game data directory.\n" \
+        "  -r, --replay <file>       play the replay 'file'.\n"           \
+        "  -i, --info                display info about a replay.\n"      \
+    )
+
+#define argument_error(option) { \
+    fprintf(stderr, L_("Option '%s' requires an argument.\n"),  option); \
+}
 
 static void parse_args(int argc, char **argv)
 {
-    char *exec = *(argv++);
-    int missing;
-
-    const char *usage = _(
-        "Usage: %s [options ...]\n"
-        "-r, --replay file         play the replay 'file'.\n"
-        "-i, --info                display info about a replay.\n"
-        "    --data dir            use 'dir' as game data directory.\n"
-        "-v, --version             show version.\n"
-        "-h, -?, --help            show this usage message.\n"
-    );
-
-#   define CASE(x) (strcmp(*argv, (x)) == 0)       /* Check current option */
-#   define MAND    !(missing = (argv[1] == NULL))  /* Argument is mandatory */
-
-    while (*argv != NULL)
+    int i;
+
+    /* Scan argument list. */
+
+    for (i = 1; i < argc; i++)
     {
-        missing = 0;
-        if (CASE("-h") || CASE("-?") || CASE("--help"))
+        if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help")    == 0)
         {
-            printf(usage, exec);
-            exit(0);
+            printf(usage, argv[0]);
+            exit(EXIT_SUCCESS);
         }
-        else if (CASE("-v") || CASE("--version"))
+
+        if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
         {
             printf("%s\n", VERSION);
-            exit(0);
+            exit(EXIT_SUCCESS);
         }
-        else if (CASE("--data") && MAND)
-            data_path = *(++argv);
-        else if ((CASE("-r") || CASE("--replay")) && MAND)
-            replay_path = *(++argv);
-        else if ((CASE("-i") || CASE("--info")))
-            display_info = 1;
-        else if (!missing)
+
+        if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--data")    == 0)
         {
-            fprintf(stderr, _("%s: unknown option %s\n"), exec, *argv);
-            fprintf(stderr, usage, exec);
-            exit(1);
+            if (i + 1 == argc)
+            {
+                argument_error(argv[i]);
+                exit(EXIT_FAILURE);
+            }
+            data_path = argv[++i];
+            continue;
         }
-        else
+
+        if (strcmp(argv[i], "-r") == 0 || strcmp(argv[i], "--replay")  == 0)
         {
-            fprintf(stderr, _("%s: option %s requires an argument\n"), exec,
-                    *argv);
-            fprintf(stderr, usage, exec);
-            exit(1);
+            if (i + 1 == argc)
+            {
+                argument_error(argv[i]);
+                exit(EXIT_FAILURE);
+            }
+            demo_path = argv[++i];
+            continue;
+        }
+
+        if (strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--info")    == 0)
+        {
+            display_info = 1;
+            continue;
         }
-        argv++;
     }
 
-#   undef CASE
-#   undef MAND
+    /* Resolve conflicts. */
 
-    return;
+    if (demo_path)
+        replay_demo = display_info ? 0 : 1;
+    else
+        if (display_info)
+        {
+            /* FIXME, I'm a required option. */
+            fputs(L_("Option '--info' requires '--replay'.\n"), stderr);
+            exit(EXIT_FAILURE);
+        }
 }
 
+#undef usage
+#undef argument_error
+
+/*---------------------------------------------------------------------------*/
+
 int main(int argc, char *argv[])
 {
     SDL_Joystick *joy = NULL;
@@ -296,17 +296,19 @@ int main(int argc, char *argv[])
 
     lang_init("neverball", CONFIG_LOCALE);
 
+    text_init();
+
     parse_args(argc, argv);
 
     if (!config_data_path(data_path, SET_FILE))
     {
-        fprintf(stderr, _("Failure to establish game data directory\n"));
+        fputs(L_("Failure to establish game data directory\n"), stderr);
         return 1;
     }
 
     if (!config_user_path(NULL))
     {
-        fprintf(stderr, _("Failure to establish config directory\n"));
+        fputs(L_("Failure to establish config directory\n"), stderr);
         return 1;
     }
 
@@ -323,28 +325,17 @@ int main(int argc, char *argv[])
     config_init();
     config_load();
 
-    /* Prepare run without GUI */
-
-    if (replay_path)
-    {
-        if (!level_replay(replay_path))
-        {
-            fprintf(stderr, _("Replay file '%s': %s\n"), replay_path,
-                    errno ? strerror(errno) : _("Not a replay file"));
-            return 1;
-        }
-        else if (display_info)
-            demo_replay_dump_info();
-    }
+    /* Dump replay information and exit. */
 
     if (display_info)
     {
-        if (replay_path == NULL)
+        if (!level_replay(demo_path))
         {
-            fprintf(stderr, _("%s: --info requires --replay\n"),
-                    argv[0]);
+            fprintf(stderr, L_("Replay file '%s': %s\n"), demo_path,
+                    errno ?  strerror(errno) : L_("Not a replay file"));
             return 1;
         }
+        demo_replay_dump_info();
         return 0;
     }
 
@@ -359,28 +350,6 @@ int main(int argc, char *argv[])
 
     /* Initialize the audio. */
 
-    audio_bind(AUD_MENU,   3, "snd/menu.wav");
-    audio_bind(AUD_START,  1, _("snd/select.ogg"));
-    audio_bind(AUD_READY,  1, _("snd/ready.ogg"));
-    audio_bind(AUD_SET,    1, _("snd/set.ogg"));
-    audio_bind(AUD_GO,     1, _("snd/go.ogg"));
-    audio_bind(AUD_BALL,   2, "snd/ball.ogg");
-    audio_bind(AUD_BUMPS,  3, "snd/bumplil.ogg");
-    audio_bind(AUD_BUMPM,  3, "snd/bump.ogg");
-    audio_bind(AUD_BUMPL,  3, "snd/bumpbig.ogg");
-    audio_bind(AUD_COIN,   2, "snd/coin.wav");
-    audio_bind(AUD_TICK,   4, "snd/tick.ogg");
-    audio_bind(AUD_TOCK,   4, "snd/tock.ogg");
-    audio_bind(AUD_SWITCH, 5, "snd/switch.wav");
-    audio_bind(AUD_JUMP,   5, "snd/jump.ogg");
-    audio_bind(AUD_GOAL,   5, "snd/goal.wav");
-    audio_bind(AUD_SCORE,  1, _("snd/record.ogg"));
-    audio_bind(AUD_FALL,   1, _("snd/fall.ogg"));
-    audio_bind(AUD_TIME,   1, _("snd/time.ogg"));
-    audio_bind(AUD_OVER,   1, _("snd/over.ogg"));
-    audio_bind(AUD_GROW,   5, "snd/grow.ogg");
-    audio_bind(AUD_SHRINK, 5, "snd/shrink.ogg");
-
     audio_init();
 
     /* Require 16-bit double buffer with 16-bit depth buffer. */
@@ -392,16 +361,13 @@ int main(int argc, char *argv[])
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
 
 #ifndef __APPLE__
-    /* Set the WM icon */
-
-    icon = IMG_Load(config_data("icon/neverball.png"));
-
-    if (icon)
+    if ((icon = load_surface("icon/neverball.png")))
     {
         SDL_WM_SetIcon(icon, NULL);
+        free(icon->pixels);
         SDL_FreeSurface(icon);
     }
-#endif // __APPLE__
+#endif /* __APPLE__ */
 
     /* Initialize the video. */
 
@@ -414,13 +380,13 @@ int main(int argc, char *argv[])
 
     SDL_WM_SetCaption(TITLE, TITLE);
 
-    /* Initialize the run state. */
-
     init_state(&st_null);
 
-    if (replay_path)
+    /* Initialise demo playback. */
+
+    if (replay_demo)
     {
-        level_replay(replay_path);
+        level_replay(demo_path);
         demo_play_goto(1);
         goto_state(&st_demo_play);
     }
@@ -452,6 +418,8 @@ int main(int argc, char *argv[])
 
     config_save();
 
+    text_quit();
+
     return 0;
 }