]> git.itanic.dy.fi Git - sdl-planets/commitdiff
main.c: Read some parameters from the command line
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 7 Mar 2010 12:14:58 +0000 (14:14 +0200)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 7 Mar 2010 12:14:58 +0000 (14:14 +0200)
The number of planets and screen resolution can be now changed from
the command line parameters.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
main.c

diff --git a/main.c b/main.c
index 7ff05fe7ffa0eb9704bb5a5c84dace8303f03762..130ffcc2744628bae9c793f0cf27a91572a4d692 100644 (file)
--- a/main.c
+++ b/main.c
@@ -5,9 +5,6 @@
 #include "random.h"
 #include "planet.h"
 
-#define SCREEN_WIDTH   800
-#define SCREEN_HEIGHT  600
-
 static void fade_buf(SDL_Surface *screen, double amount)
 {
        int i;
@@ -26,9 +23,8 @@ static void clear_buf(SDL_Surface *screen)
                buf[i] = 0;
 }
 
-static void loop(SDL_Surface *screen)
+static void loop(SDL_Surface *screen, int num_of_planets)
 {
-       int num_of_planets = 100;
        struct planet *planet, *pl1, *pl2;
        SDL_Event event;
        int i, planets;
@@ -103,10 +99,11 @@ static void loop(SDL_Surface *screen)
        }
 }
 
-int main(void)
+int main(int argc, char *argv[])
 {
        SDL_Surface *screen;
        int flags = SDL_DOUBLEBUF | SDL_HWSURFACE;
+       int planets = 100, xres = 800, yres = 600;
 
        if (SDL_Init(SDL_INIT_VIDEO) != 0) {
                fprintf(stderr, "Unable to initialize SDL: %s\n",
@@ -116,14 +113,23 @@ int main(void)
        }
        atexit(SDL_Quit);
 
-       screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, flags);
+       if (argc >= 2)
+               planets = atoi(argv[1]);
+
+       if (argc >= 3)
+               xres = atoi(argv[2]);
+
+       if (argc >= 4)
+               yres = atoi(argv[3]);
+
+       screen = SDL_SetVideoMode(xres, yres, 32, flags);
        if (screen == NULL) {
                fprintf(stderr, "Unable to set video mode: %s\n",
                        SDL_GetError());
                return 2;
        }
 
-       loop(screen);
+       loop(screen, planets);
 
        return 0;
 }