clean up stopwatch code

* SDL_GetTicks() returns uint
* there's no need to make a fuss about "starting" and "stopping" the clock
* instead of stopping the clock, we can now just get the elapsed time
This commit is contained in:
ac-stef
2015-02-08 17:39:15 +01:00
parent 685dbb8326
commit b76413ddc2
2 changed files with 12 additions and 14 deletions
+4 -6
View File
@@ -808,9 +808,9 @@ template <class T, int SIZE> struct ringbuf
// ease time measurement
struct stopwatch
{
int millis;
uint millis; // SDL_GetTicks() returns an uint value
stopwatch() : millis(-1) {}
stopwatch() : millis(0) {}
void start()
{
@@ -818,11 +818,9 @@ struct stopwatch
}
// returns elapsed time
int stop()
int elapsed()
{
ASSERT(millis >= 0);
int time = SDL_GetTicks() - millis;
millis = -1;
uint time = SDL_GetTicks() - millis; // subtraction also works in case of timer wraparounds
return time;
}
};