Make error sets explicit

This commit is contained in:
2022-01-10 16:45:04 -07:00
parent ed2445e623
commit b734196410
2 changed files with 11 additions and 13 deletions

View File

@ -31,7 +31,7 @@ const FCoords = struct {
const State = struct {
period: f64,
timer: *mfb.Timer,
timer: mfb.Timer,
active: bool = true,
alloc: std.mem.Allocator,
cursor_pos: Coords = undefined,
@ -45,19 +45,16 @@ const State = struct {
cheat_code: []const u8 = "rave",
cheat_code_progress: usize = 0,
pub fn init(alloc: std.mem.Allocator, period: f64) !State {
var timer = try alloc.create(mfb.Timer);
timer.* = try mfb.Timer.init();
pub fn init(alloc: std.mem.Allocator, period: f64) std.mem.Allocator.Error!State {
return State{
.period = period,
.timer = timer,
.timer = try mfb.Timer.init(),
.alloc = alloc,
};
}
pub fn deinit(self: State) void {
self.timer.*.deinit();
self.alloc.destroy(self.timer);
self.timer.deinit();
}
pub fn cheatInput(self: *State, char: u32) void {
@ -77,7 +74,7 @@ const State = struct {
pub fn render(self: State, buf: Buffer) void {
const period = if (!self.isCheating()) self.period else self.period / 10;
var bgValue = @rem(self.timer.*.now(), period) / period * 512;
var bgValue = @rem(self.timer.now(), period) / period * 512;
if (bgValue >= 256) {
bgValue = 512 - bgValue;
}
@ -112,7 +109,7 @@ const Buffer = struct {
width: u32,
height: u32,
pub fn init(alloc: std.mem.Allocator, width: u32, height: u32) !Buffer {
pub fn init(alloc: std.mem.Allocator, width: u32, height: u32) std.mem.Allocator.Error!Buffer {
const slice = try alloc.alloc(mfb.Rgb, width * height);
return Buffer{
.alloc = alloc,