#include <unistd.h>
#include <stdio.h>
#include <time.h>
+#include <getopt.h>
#include "random.h"
#include "planet.h"
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))
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",
}
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) {