]> git.itanic.dy.fi Git - sdl-planets/commitdiff
main.c: Change the command line parameter usage
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 20 Mar 2010 13:19:23 +0000 (15:19 +0200)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 20 Mar 2010 13:19:23 +0000 (15:19 +0200)
Allow total mass and the range of the system to be defined from the
command line.

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

diff --git a/main.c b/main.c
index e18621b844ba441e983b551db9a72cba0651a252..556fad065cc0b7454584c49ac56bf80b3a9f3412 100644 (file)
--- a/main.c
+++ b/main.c
@@ -92,7 +92,8 @@ static int poll_events(SDL_Surface **screen, struct camera *cam)
        return 0;
 }
 
-static void loop(SDL_Surface *screen, int num_of_planets)
+static void loop(SDL_Surface *screen, int num_of_planets, double total_mass,
+                double range)
 {
        struct planet *planet, *pl1, *pl2;
        struct camera camera;
@@ -105,7 +106,7 @@ static void loop(SDL_Surface *screen, int num_of_planets)
 
        planet = malloc(sizeof(*planet));
        init_planet(planet);
-       create_planets(planet, num_of_planets, 50000, 500);
+       create_planets(planet, num_of_planets, total_mass, range);
 
        ticks = SDL_GetTicks();
        while (1) {
@@ -165,6 +166,8 @@ int main(int argc, char *argv[])
        SDL_Surface *screen;
        int flags = SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_RESIZABLE;
        int planets = 100, xres = 800, yres = 600;
+       double total_mass = 50000;
+       double range = 500;
 
        if (SDL_Init(SDL_INIT_VIDEO) != 0) {
                fprintf(stderr, "Unable to initialize SDL: %s\n",
@@ -178,10 +181,10 @@ int main(int argc, char *argv[])
                planets = atoi(argv[1]);
 
        if (argc >= 3)
-               xres = atoi(argv[2]);
+               total_mass = atof(argv[2]);
 
        if (argc >= 4)
-               yres = atoi(argv[3]);
+               range = atof(argv[3]);
 
        screen = SDL_SetVideoMode(xres, yres, 32, flags);
        if (screen == NULL) {
@@ -190,7 +193,7 @@ int main(int argc, char *argv[])
                return 2;
        }
 
-       loop(screen, planets);
+       loop(screen, planets, total_mass, range);
 
        return 0;
 }