examples: update to new event-based input method

This commit is contained in:
iddev5 2022-05-20 18:34:30 +05:30 committed by Stephen Gutekanst
parent f1e7c10fbb
commit 02b9048734
7 changed files with 96 additions and 99 deletions

View file

@ -26,16 +26,6 @@ const App = @This();
pub fn init(app: *App, engine: *mach.Engine) !void {
timer = try mach.Timer.start();
engine.core.setKeyCallback(struct {
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.space => eng.core.setShouldClose(true),
else => {},
}
}
}
}.callback);
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const vs_module = engine.gpu_driver.device.createShaderModule(&.{
@ -186,6 +176,16 @@ pub fn deinit(app: *App, _: *mach.Engine) void {
}
pub fn update(app: *App, engine: *mach.Engine) !bool {
while (engine.core.pollEvent()) |event| {
switch (event) {
.key_press => |ev| {
if (ev.key == .space)
engine.core.setShouldClose(true);
},
else => {},
}
}
const back_buffer_view = engine.gpu_driver.swap_chain.?.getCurrentTextureView();
const color_attachment = gpu.RenderPassColorAttachment{
.view = back_buffer_view,