]> git.itanic.dy.fi Git - sdl-planets/commitdiff
fade_buf: Allow fading with very small increments
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 4 Apr 2010 07:37:42 +0000 (10:37 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 4 Apr 2010 07:37:42 +0000 (10:37 +0300)
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
main.c

diff --git a/main.c b/main.c
index 66272cbc63c7b6cacd92145e7924daa920edd243..d2f408abe1d050151594d31368965e68852be1b6 100644 (file)
--- a/main.c
+++ b/main.c
@@ -8,11 +8,21 @@
 
 #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 = 0;
+       threshold += fade;
+
+       if (threshold > 1) {
+               amount = threshold;
+               threshold -= amount;
+       } else {
+               return;
+       }
 
        for (i = 0; i < screen->pitch * screen->h / sizeof(*buf); i ++) {
                if (!buf[i])