aboutsummaryrefslogtreecommitdiffstats
path: root/src/gametime.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gametime.cpp')
-rw-r--r--src/gametime.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/gametime.cpp b/src/gametime.cpp
new file mode 100644
index 0000000..be63885
--- /dev/null
+++ b/src/gametime.cpp
@@ -0,0 +1,50 @@
+#include <gametime.hpp>
+
+#include <common.hpp>
+
+static unsigned int tickCount = 0;
+static unsigned int deltaTime = 1;
+
+// millisecond timers
+static unsigned int currentTime = 0;
+static unsigned int prevTime, prevPrevTime;
+
+namespace gtime {
+ void setTickCount(unsigned int t) {
+ tickCount = t;
+ }
+
+ unsigned int getTickCount(void) {
+ return tickCount;
+ }
+
+ unsigned int getDeltaTime(void) {
+ return deltaTime;
+ }
+
+ void tick(void) {
+ tickCount++;
+ }
+
+ void tick(unsigned int ticks) {
+ tickCount += ticks;
+ }
+
+ void mainLoopHandler(void) {
+ if (!currentTime)
+ currentTime = prevTime = millis();
+
+ currentTime = millis();
+ deltaTime = currentTime - prevTime;
+ prevTime = currentTime;
+ }
+
+ bool tickHasPassed(void) {
+ if (prevPrevTime + MSEC_PER_TICK <= currentTime) {
+ prevPrevTime = currentTime;
+ return true;
+ }
+
+ return false;
+ }
+}