]> git.lizzy.rs Git - dungeon_game.git/commitdiff
Public calculate_dtime function
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 13 Jun 2021 18:41:37 +0000 (20:41 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 13 Jun 2021 18:41:37 +0000 (20:41 +0200)
plugins/game/game.c
plugins/game/game.h

index 5d5c31ae6f98fa8f210a163e5c0f7164a43405d0..152a5c97200e75578a3139877929e6b03277fa75 100644 (file)
@@ -3,7 +3,6 @@
 #include <unistd.h>
 #include <assert.h>
 #include <ctype.h>
-#include <time.h>
 #include <signal.h>
 #include <termios.h>
 #include <math.h>
@@ -125,6 +124,11 @@ void *make_buffer(void *ptr, size_t size)
        return buf;
 }
 
+double calculate_dtime(struct timespec from, struct timespec to)
+{
+       return (double) (to.tv_sec - from.tv_sec) + (double) (to.tv_nsec - from.tv_nsec) / 1000000000.0;
+}
+
 /* Game-related utility functions */
 
 void quit()
@@ -517,7 +521,7 @@ void game()
 
        while (running) {
                clock_gettime(CLOCK_REALTIME, &ts);
-               double dtime = (double) (ts.tv_sec - ts_old.tv_sec) + (double) (ts.tv_nsec - ts_old.tv_nsec) / 1000000000.0;
+               double dtime = calculate_dtime(ts_old, ts);
                ts_old = ts;
 
                bool dead = player_dead();
index 7ae93448e743513429deacb41663579db029b510..60c1d615c0a1bac664dd4e537d03adcde0f234f9 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdbool.h>
 #include <sys/ioctl.h>
 #include <stddef.h>
+#include <time.h>
 #define MAP_HEIGHT 1000
 #define MAP_WIDTH 1000
 #define LIGHT 10
@@ -111,6 +112,7 @@ int clamp(int v, int max, int min);
 int max(int a, int b);
 int min(int a, int b);
 void *make_buffer(void *ptr, size_t size);
+double calculate_dtime(struct timespec from, struct timespec to);
 
 void quit();
 bool player_dead();