Fixed SDL_Delay.
[crow/jumpnbump.git] / sdl / interrpt.c
index bb0d7e2..8577c8f 100644 (file)
@@ -104,7 +104,8 @@ int intr_sysupdate()
 {
        SDL_Event e;
        int i = 0;
-       static Uint32 now, then = 0;
+       static int last_time = 0;
+       int now, time_diff;
 
        while (SDL_PollEvent(&e)) {
                switch (e.type) {
@@ -144,8 +145,22 @@ int intr_sysupdate()
                }
                i++;
        }
-       //SDL_Delay(4);
+       SDL_Delay(1);
        now = SDL_GetTicks();
+       time_diff = now - last_time;
+       if (time_diff>0) {
+               i = time_diff / (1000 / 60);
+               if (i) {
+                       last_time = now;
+               } else {
+                       int tmp;
+
+                       tmp = (1000/60) - i - 10;
+                       if (tmp>0)
+                               SDL_Delay(tmp);
+               }
+       }
+/*
        if (!then)
                SDL_Delay(1);
        else {
@@ -154,6 +169,7 @@ int intr_sysupdate()
                        SDL_Delay(then);
        }
        then = now;
+*/
 
        return i;
 }