]> git.itanic.dy.fi Git - sdl-planets/blobdiff - main.c
fade_buf: Optimizations
[sdl-planets] / main.c
diff --git a/main.c b/main.c
index f779cdad8f29b992b31702c65948c893f36cebfd..dfcc14802b7b3ea7e002d38b953133e51d357957 100644 (file)
--- a/main.c
+++ b/main.c
@@ -8,14 +8,22 @@
 
 #define MAX_FPS 60
 
-static void fade_buf(SDL_Surface *screen, double amount)
+static void fade_buf(SDL_Surface *screen, int amount)
 {
        int i;
-       unsigned char *buf = screen->pixels;
+       unsigned int *buf = screen->pixels;
+       unsigned char *b;
 
-       for (i = 0; i < screen->pitch * screen->h; i++)
-               buf[i] = (buf[i] < amount) ? 0 : buf[i] - amount;
-}
+       for (i = 0; i < screen->pitch * screen->h / sizeof(*buf); i ++) {
+               if (!buf[i])
+                       continue;
+               b = (unsigned char *)&buf[i];
+               *b = *b >= amount ? (*b - amount) : *b;
+               b++;
+               *b = *b >= amount ? (*b - amount) : *b;
+               b++;
+               *b = *b >= amount ? (*b - amount) : *b;
+       }}
 
 static void clear_buf(SDL_Surface *screen)
 {