]> git.itanic.dy.fi Git - sdl-planets/commitdiff
Merge branch 'master' of git://itanic.dy.fi/sdl-planets
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Mon, 5 Apr 2010 16:36:45 +0000 (19:36 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Mon, 5 Apr 2010 16:36:45 +0000 (19:36 +0300)
Makefile
main.c
planet.c

index 86498238846db220ad623486f042f47fe5741c8a..c4c765204c9c14460cdef19c5e2735f4923f533d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ sdl-planet: $(PLANET_OBJS)
        gcc $(LIBS) -o $@ $(PLANET_OBJS)
 
 debug-planets: $(PLANET_DEBUG_OBJS)
-       gcc $(LIBS) -o $@ $(PLANET_DEBUG_OBJS)
+       gcc $(LIBS) -o $@ $(PLANET_DEBUG_OBJS) -DDEBUG
 
 .c.o:
        @echo -e "\tCC\t" $@
diff --git a/main.c b/main.c
index 7256fa48c3bac21ade6972d20b38cf684b2564b0..c383af71e05f7fe7ad52c059000d0c4a3cd20e62 100644 (file)
--- a/main.c
+++ b/main.c
@@ -8,13 +8,23 @@
 
 #define MAX_FPS 60
 
-static void fade_buf(SDL_Surface *screen, int amount)
+static void fade_buf(SDL_Surface *screen, double fade)
 {
        int i;
        unsigned int *buf = screen->pixels;
        unsigned char *b;
+       unsigned char amount;
+       static double threshold;
+       threshold += fade;
+
+       if (threshold > 1) {
+               amount = threshold;
+               threshold -= amount;
+       } else {
+               return;
+       }
 
-       for (i = 0; i < screen->pitch * screen->h / sizeof(*buf); i ++) {
+       for (i = 0; i < screen->pitch * screen->h / sizeof(*buf); i++) {
                if (!buf[i])
                        continue;
                b = (unsigned char *)&buf[i];
@@ -41,7 +51,7 @@ static unsigned long gettime(void)
 {
        struct timespec tp;
        unsigned long ret;
-       static unsigned long start = 0;
+       static unsigned long start;
 
        clock_gettime(CLOCK_MONOTONIC, &tp);
 
@@ -101,6 +111,18 @@ static int poll_events(struct sim_status *status, double time)
                        case SDLK_a:
                                time_scale_rate = 1 / 1.5;
                                break;
+                       case SDLK_1:
+                               status->time_scale = 1;
+                               break;
+                       case SDLK_2:
+                               status->time_scale = 10;
+                               break;
+                       case SDLK_3:
+                               status->time_scale = 20;
+                               break;
+                       case SDLK_4:
+                               status->time_scale = 30;
+                               break;
                        case SDLK_t:
                                status->tracers_enabled =
                                        !status->tracers_enabled;
@@ -141,10 +163,11 @@ static int poll_events(struct sim_status *status, double time)
                        }
                        break;
                case SDL_VIDEORESIZE:
-                       status->screen = SDL_SetVideoMode(event.resize.w,
-                                                         event.resize.h,
-                                                         32,
-                                                         status->screen->flags);
+                       status->screen =
+                               SDL_SetVideoMode(event.resize.w,
+                                                event.resize.h,
+                                                32,
+                                                status->screen->flags);
                        break;
                case SDL_QUIT:
                        goto quit;
@@ -215,7 +238,7 @@ static void loop(SDL_Surface *screen, int num_of_planets, double total_mass,
                step_count++;
 
                /*
-                * Do not draw to the screen more often than MAS_FPS
+                * Do not draw to the screen more often than MAX_FPS
                 * per second
                 */
                if (last_frame_tick + (1000 * 1000) / MAX_FPS > ticks)
index c7b01a05995f91442d0c550df6e259a49c4e2dc4..f72b1b0087a523fe76e0f10979fe5cd8d842d7de 100644 (file)
--- a/planet.c
+++ b/planet.c
@@ -73,7 +73,12 @@ void create_planets(struct planet *p, int num, double total_mass, double radius)
        double sum = 0;
        struct planet *new_planet;
 
-       for (i = 1; i < num; i++) {
+       setup_planet(p,
+                    total_mass / num * 2 * get_random_double(),
+                    total_mass,
+                    radius);
+
+       for (i = 0; i < num; i++) {
                new_planet = malloc(sizeof(*new_planet));
                init_planet(new_planet);
                list_add(&new_planet->list, &p->list);