Set and get user data
This commit is contained in:
13
src/main.zig
13
src/main.zig
@ -17,8 +17,6 @@ const Coords = struct {
|
||||
|
||||
const State = struct {
|
||||
period: f64,
|
||||
bgValue: u8 = 0,
|
||||
increasing: bool = true,
|
||||
timer: mfb.Timer,
|
||||
|
||||
pub fn init(period: f64) !State {
|
||||
@ -97,15 +95,20 @@ pub fn main() !void {
|
||||
var gp_allocator = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const alloc = &gp_allocator.allocator;
|
||||
|
||||
var win = mfb.Window.open("Hello minifb-zig", Width, Height, .{.resizable=true}) catch unreachable;
|
||||
mfb.setTargetFPS(7);
|
||||
|
||||
var state = try State.init(3);
|
||||
defer state.deinit();
|
||||
|
||||
var win = mfb.Window(State).open("Hello minifb-zig", Width, Height, .{.resizable=true}) catch unreachable;
|
||||
mfb.setTargetFPS(7);
|
||||
win.setUserData(&state);
|
||||
|
||||
var buf = try Buffer.init(alloc, Width, Height);
|
||||
defer buf.deinit();
|
||||
|
||||
var aliasedState = win.getUserData();
|
||||
if (aliasedState) |value| {
|
||||
std.log.info("Period: {d}", .{value.*.period});
|
||||
}
|
||||
state.render(buf);
|
||||
while (win.waitSync()) {
|
||||
state.render(buf);
|
||||
|
Reference in New Issue
Block a user