chore: improve accuracy of thread sleep in emu thread

This commit is contained in:
2022-03-14 08:54:48 -03:00
parent c538079ad4
commit 3623362f72
3 changed files with 65 additions and 15 deletions

View File

@@ -6,3 +6,30 @@ pub fn sext(comptime bits: comptime_int, value: u32) u32 {
return @bitCast(u32, @bitCast(i32, value << amount) >> amount);
}
pub const FpsAverage = struct {
const Self = @This();
total: u64,
sample_count: u64,
pub fn init() Self {
return .{ .total = 0, .sample_count = 0 };
}
pub fn add(self: *Self, sample: u64) void {
if (self.sample_count == 1000) return self.reset(sample);
self.total += sample;
self.sample_count += 1;
}
pub fn calc(self: *const Self) u64 {
return self.total / self.sample_count;
}
fn reset(self: *Self, sample: u64) void {
self.total = sample;
self.sample_count = 1;
}
};