]> git.itanic.dy.fi Git - sdl-planets/commitdiff
Merge branch 'master' of git://itanic.dy.fi/sdl-planets
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 31 Oct 2010 09:03:36 +0000 (11:03 +0200)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 31 Oct 2010 09:04:15 +0000 (11:04 +0200)
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
main.c

diff --git a/main.c b/main.c
index f2a012cf50d24036580df98f060e70e9c8e776aa..b42f2345d5404ae0e54cc579d6ae4bc39a006f6c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -2,6 +2,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <time.h>
+#include <getopt.h>
 
 #include "random.h"
 #include "planet.h"
@@ -221,23 +222,25 @@ static void loop(SDL_Surface *screen, int num_of_planets, double total_mass,
        while (1) {
                planets = 0;
 
-               list_for_each_entry(pl1, &planet->list, list) {
-                       pl2 = list_to_planet(pl1->list.next);
-                       list_for_each_entry_from(pl2, &planet->list, list) {
-                               struct planet *ptmp;
-                               if (!gravitize_planets(pl1, pl2,
-                                                      step_time))
-                                       continue;
-
-                               ptmp = list_to_planet(pl2->list.prev);
-                               merge_planets(pl1, pl2);
-                               pl2 = ptmp;
+               if (status.time_scale > 0) {
+                       list_for_each_entry(pl1, &planet->list, list) {
+                               pl2 = list_to_planet(pl1->list.next);
+                               list_for_each_entry_from(pl2, &planet->list,
+                                                        list) {
+                                       struct planet *ptmp;
+                                       if (!gravitize_planets(pl1, pl2,
+                                                              step_time))
+                                               continue;
+
+                                       ptmp = list_to_planet(pl2->list.prev);
+                                       merge_planets(pl1, pl2);
+                                       pl2 = ptmp;
+                               }
+
+                               planet_root = move_planet(pl1, step_time);
+                               planets++;
                        }
-
-                       planet_root = move_planet(pl1, step_time);
-                       planets++;
                }
-
                move_camera(&camera, true_time);
 
                if (poll_events(&status, true_time))
@@ -320,6 +323,16 @@ int main(int argc, char *argv[])
        int planets = 100, xres = 800, yres = 600;
        double total_mass = 50000;
        double range = 500;
+       int optind = 0, c;
+       static struct option long_options[] = {
+               { .val = 'x', .name = "xres", .has_arg = 1, },
+               { .val = 'y', .name = "yres", .has_arg = 1, },
+               { .val = 'p', .name = "planets", .has_arg = 1 },
+               { .val = 'm', .name = "total-mass", .has_arg = 1 },
+               { .val = 'r', .name = "range", .has_arg = 1 },
+               {},
+       };
+       char short_options[] = "x:y:p:m:r:";
 
        if (SDL_Init(SDL_INIT_VIDEO) != 0) {
                fprintf(stderr, "Unable to initialize SDL: %s\n",
@@ -329,18 +342,33 @@ int main(int argc, char *argv[])
        }
        atexit(SDL_Quit);
 
-       if (argc >= 2)
-               planets = atoi(argv[1]);
+       while (1) {
+               c = getopt_long(argc, argv, short_options, long_options,
+                               &optind);
+
+               if (c == -1)
+                       break;
+
+               printf("%c: %s\n", c, optarg);
 
-       if (planets < 1)
-               planets = 1;
+               switch (c) {
+               case 'x':
+                       xres = atoi(optarg);
+                       break;
 
+               case 'y':
+                       yres = atoi(optarg);
+                       break;
 
-       if (argc >= 3)
-               total_mass = atof(argv[2]);
+               case 'p':
+                       planets = atoi(optarg);
+                       break;
 
-       if (argc >= 4)
-               range = atof(argv[3]);
+               case 'r':
+                       range = atoi(optarg);
+                       break;
+               }
+       }
 
        screen = SDL_SetVideoMode(xres, yres, 32, flags);
        if (screen == NULL) {