Add Timers
This commit is contained in:
parent
0fdf0accb2
commit
46cab832ed
|
@ -0,0 +1,38 @@
|
|||
const SDL = @import("sdl2");
|
||||
|
||||
const Self = @This();
|
||||
|
||||
started: bool,
|
||||
initial: u64,
|
||||
progress: u64,
|
||||
target: u64,
|
||||
|
||||
pub fn init(target: u64) Self {
|
||||
return Self{
|
||||
.started = false,
|
||||
.initial = 0,
|
||||
.progress = 0,
|
||||
.target = target,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn start(self: *Self) void {
|
||||
self.started = true;
|
||||
self.progress = 0;
|
||||
self.initial = SDL.SDL_GetTicks64();
|
||||
}
|
||||
|
||||
pub fn finished(self: *Self) bool {
|
||||
if (self.started) {
|
||||
self.progress = SDL.SDL_GetTicks64() - self.initial;
|
||||
if (self.progress >= self.target) {
|
||||
return true;
|
||||
} else return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop(self: *Self) void {
|
||||
self.started = false;
|
||||
}
|
Loading…
Reference in New Issue