Add Timers

This commit is contained in:
Dusk 2022-07-10 18:25:38 +02:00
parent 0fdf0accb2
commit 46cab832ed
1 changed files with 38 additions and 0 deletions

38
src/timer.zig Normal file
View File

@ -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;
}