]> git.itanic.dy.fi Git - sdl-planets/commitdiff
gettime fixes
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 31 Mar 2010 16:42:41 +0000 (19:42 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 31 Mar 2010 16:42:41 +0000 (19:42 +0300)
Return microseconds instead of nanoseconds. Also return value is now
delta from the first call to gettime instead of the absolute value of
the monotonic clock.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
main.c

diff --git a/main.c b/main.c
index 11912512b7913e21de205f9cdf2eb90c017e1f32..84b180e6e2b535ec4d7eb313dc2889f8bca03286 100644 (file)
--- a/main.c
+++ b/main.c
@@ -26,17 +26,21 @@ static void clear_buf(SDL_Surface *screen)
 
 /* Return time in microseconds */
 
-static unsigned long long gettime(void)
+static unsigned long gettime(void)
 {
        struct timespec tp;
-       unsigned long long ret;
+       unsigned long ret;
+       static unsigned long start = 0;
 
        clock_gettime(CLOCK_MONOTONIC, &tp);
 
        ret = tp.tv_sec * 1000 * 1000;
-       ret += tp.tv_nsec;
+       ret += tp.tv_nsec / 1000;
 
-       return ret;
+       if (!start)
+               start = ret;
+
+       return ret - start;
 }
 
 static int poll_events(SDL_Surface **screen, struct camera *cam,