src/core: move mach-core@9a4d09707d9f1cb6ea5602bdf58caeefc46146be package to here

Helps hexops/mach#1165

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-03-04 23:25:11 -07:00 committed by Stephen Gutekanst
parent fa3f6161ad
commit 38f296ecce
157 changed files with 28383 additions and 0 deletions

38
src/core/Timer.zig Normal file
View file

@ -0,0 +1,38 @@
const std = @import("std");
const platform = @import("platform.zig");
pub const Timer = @This();
internal: platform.Timer,
/// Initialize the timer.
pub fn start() !Timer {
return Timer{
.internal = try platform.Timer.start(),
};
}
/// Reads the timer value since start or the last reset in nanoseconds.
pub inline fn readPrecise(timer: *Timer) u64 {
return timer.internal.read();
}
/// Reads the timer value since start or the last reset in seconds.
pub inline fn read(timer: *Timer) f32 {
return @as(f32, @floatFromInt(timer.readPrecise())) / @as(f32, @floatFromInt(std.time.ns_per_s));
}
/// Resets the timer value to 0/now.
pub inline fn reset(timer: *Timer) void {
timer.internal.reset();
}
/// Returns the current value of the timer in nanoseconds, then resets it.
pub inline fn lapPrecise(timer: *Timer) u64 {
return timer.internal.lap();
}
/// Returns the current value of the timer in seconds, then resets it.
pub inline fn lap(timer: *Timer) f32 {
return @as(f32, @floatFromInt(timer.lapPrecise())) / @as(f32, @floatFromInt(std.time.ns_per_s));
}