diff --git a/lib/minifb/build.zig b/lib/minifb/build.zig index 64795f5..691cb34 100644 --- a/lib/minifb/build.zig +++ b/lib/minifb/build.zig @@ -12,7 +12,7 @@ pub fn build(b: *std.build.Builder) void { var main_tests = b.addTest("src/minifb.zig"); main_tests.setBuildMode(mode); main_tests.setTarget(target); - link(b, main_test); + link(b, main_tests); const test_step = b.step("test", "Run library tests"); test_step.dependOn(&main_tests.step); diff --git a/lib/minifb/src/minifb.zig b/lib/minifb/src/minifb.zig index f7b923f..48e9093 100644 --- a/lib/minifb/src/minifb.zig +++ b/lib/minifb/src/minifb.zig @@ -44,6 +44,22 @@ pub const Window = struct{ else => return UpdateError.InternalError, } } - - }; + +pub fn getTargetFPS() u32 { + return minifb_c.mfb_get_target_fps(); +} + +pub fn setTargetFPS(fps: u32) void { + minifb_c.mfb_set_target_fps(fps); +} + +// TODO Figure out how to run this once I have Internet access. +test "set and get target FPS" { + const max = 40; + var fps: u32 = 30; + while (fps < max) { + setTargetFPS(fps); + try std.testing.expectEqual(fps, getTargetFPS()); + } +} diff --git a/src/main.zig b/src/main.zig index fd270cf..d497ef6 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,17 +1,18 @@ const std = @import("std"); -const minifb = @import("minifb"); +const mfb = @import("minifb"); const Width = 800; const Height = 600; fn grey(value: u8) u32 { - return minifb.rgb(value, value, value); + return mfb.rgb(value, value, value); } pub fn main() anyerror!void { std.log.info("All your codebase are belong to us.", .{}); - var win = minifb.Window.open("Hello minifb-zig", Width, Height) catch unreachable; + var win = mfb.Window.open("Hello minifb-zig", Width, Height) catch unreachable; + mfb.setTargetFPS(60); var color: u32 = grey(0); const deltaColor = grey(1); @@ -37,7 +38,7 @@ pub fn main() anyerror!void { std.mem.set(u32, buffer, color); var i: u32 = 0; while (i < Width) { - buffer[i] = minifb.rgb(255,0,0); + buffer[i] = mfb.rgb(255,0,0); i += 1; } _ = win.update(buffer) catch unreachable;