]> 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)
1  2 
main.c

diff --combined main.c
index 7256fa48c3bac21ade6972d20b38cf684b2564b0,2241d42b6e1f52ee4a3ec849e4e6f8b47b4a5448..c383af71e05f7fe7ad52c059000d0c4a3cd20e62
--- 1/main.c
--- 2/main.c
+++ b/main.c
@@@ -8,13 -8,23 +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 +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 +111,18 @@@ static int poll_events(struct sim_statu
                        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;
                        }
                        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;
@@@ -168,7 -191,7 +191,7 @@@ static void loop(SDL_Surface *screen, i
        int last_framecount = 0, last_step_count = 0;
        unsigned long old_ticks, ticks = 0, last_frame_tick = 0;
        unsigned long step_count = 0;
 -      double last_fps = 0, last_sps = 0;
 +      double last_fps = 0, last_sps = 0, fade_amount;
        double step_time = 0, true_time = 0;
  
        init_camera(&camera);
                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)
                        continue;
  
 -              last_frame_tick = ticks;
 -
                SDL_LockSurface(screen);
  
                if (status.tracers_enabled &&
                    !camera.speed.x && !camera.speed.y &&
                    camera.zoom_rate == 1) {
 -                      fade_buf(screen, 10 * true_time);
 +                      fade_amount = (ticks - last_frame_tick) /
 +                              (1000 * 1000.0) * 20;
 +                      fade_buf(screen, fade_amount);
                } else {
                        clear_buf(screen);
                }
  
                SDL_Flip(screen);
  
 +              last_frame_tick = ticks;
 +
                if (last_fps_time + (500 * 1000) < ticks) {
                        last_framecount = framecount - last_framecount;
                        last_fps = last_framecount * 1000 * 1000 /