Get and set frame rate
This commit is contained in:
parent
149cf2a9b4
commit
3778320a3e
@ -12,7 +12,7 @@ pub fn build(b: *std.build.Builder) void {
|
|||||||
var main_tests = b.addTest("src/minifb.zig");
|
var main_tests = b.addTest("src/minifb.zig");
|
||||||
main_tests.setBuildMode(mode);
|
main_tests.setBuildMode(mode);
|
||||||
main_tests.setTarget(target);
|
main_tests.setTarget(target);
|
||||||
link(b, main_test);
|
link(b, main_tests);
|
||||||
|
|
||||||
const test_step = b.step("test", "Run library tests");
|
const test_step = b.step("test", "Run library tests");
|
||||||
test_step.dependOn(&main_tests.step);
|
test_step.dependOn(&main_tests.step);
|
||||||
|
@ -44,6 +44,22 @@ pub const Window = struct{
|
|||||||
else => return UpdateError.InternalError,
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const minifb = @import("minifb");
|
const mfb = @import("minifb");
|
||||||
|
|
||||||
const Width = 800;
|
const Width = 800;
|
||||||
const Height = 600;
|
const Height = 600;
|
||||||
|
|
||||||
fn grey(value: u8) u32 {
|
fn grey(value: u8) u32 {
|
||||||
return minifb.rgb(value, value, value);
|
return mfb.rgb(value, value, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() anyerror!void {
|
pub fn main() anyerror!void {
|
||||||
std.log.info("All your codebase are belong to us.", .{});
|
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);
|
var color: u32 = grey(0);
|
||||||
const deltaColor = grey(1);
|
const deltaColor = grey(1);
|
||||||
@ -37,7 +38,7 @@ pub fn main() anyerror!void {
|
|||||||
std.mem.set(u32, buffer, color);
|
std.mem.set(u32, buffer, color);
|
||||||
var i: u32 = 0;
|
var i: u32 = 0;
|
||||||
while (i < Width) {
|
while (i < Width) {
|
||||||
buffer[i] = minifb.rgb(255,0,0);
|
buffer[i] = mfb.rgb(255,0,0);
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
_ = win.update(buffer) catch unreachable;
|
_ = win.update(buffer) catch unreachable;
|
||||||
|
Loading…
Reference in New Issue
Block a user