Added timers

This commit is contained in:
2021-11-24 18:11:43 -07:00
parent efba4456e7
commit 5346d16aba
2 changed files with 71 additions and 30 deletions

View File

@ -63,3 +63,40 @@ test "set and get target FPS" {
try std.testing.expectEqual(fps, getTargetFPS());
}
}
pub const Timer = struct {
ctimer: *minifb_c.mfb_timer,
pub fn init() !Timer {
const ctimer: ?*minifb_c.mfb_timer = minifb_c.mfb_timer_create();
if (ctimer) |value| {
return Timer {.ctimer=value};
} else {
return error.ItBroke;
}
}
pub fn deinit(self: Timer) void {
minifb_c.mfb_timer_destroy(self.ctimer);
}
pub fn reset(self: Timer) void {
minifb_c.mfb_timer_reset(self.ctimer);
}
pub fn now(self: Timer) f64 {
return minifb_c.mfb_timer_now(self.ctimer);
}
pub fn delta(self: Timer) f64 {
return minifb_c.mfb_timer_delta(self.ctimer);
}
pub fn getFrequency() f64 {
return minifb_c.mfb_timer_get_frequency();
}
pub fn getResolution() f64 {
return minifb_c.mfb_timer_get_resolution();
}
};