diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-04-27 08:50:07 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-04-27 08:50:07 -0400 |
commit | 174bcd3a415c21fc2c59a3af1b6333faa78b37d0 (patch) | |
tree | d2f9c9fe8a79628fb95557acb2a0bc03aedb07e3 /src/gametime.cpp | |
parent | 88c21e763178856aef0155595d49085919205951 (diff) |
ui fixes, other stuff
Diffstat (limited to 'src/gametime.cpp')
-rw-r--r-- | src/gametime.cpp | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/src/gametime.cpp b/src/gametime.cpp index be63885..598cd4f 100644 --- a/src/gametime.cpp +++ b/src/gametime.cpp @@ -9,42 +9,44 @@ static unsigned int deltaTime = 1; 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; +namespace game { + namespace time { + void setTickCount(unsigned int t) { + tickCount = t; + } + + unsigned int getTickCount(void) { + return tickCount; + } + + unsigned int getDeltaTime(void) { + return (deltaTime > 0) ? deltaTime : 1; + } + + 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; + } } } |