mach: Implement key input handling as event loop

This commit changes the former callback based design to handle key input
(GLFW-like) to an event loop based design (SDL-like). This uses a
TailQueue to store the events from inside of standard glfw callbacks.
This Queue is then popped while polling, thereby emulating event loop.

Removes from Engine the function: ``setKeyCallback`` and adds the
function: ``pollEvent`` which may return an event or null.

This change was done for two reasons:
1) Removing dependence of Engine on App. This was a circular dependency
   and a genuine bad design.
2) Solve the recent regression due to the same which was (i) preventing
   using types declared in Engine.zig and (ii) preventing usage of
   multiple source files in an application.

Currently only key press and release events are implemented as these are
the ones currently used in examples.
This commit is contained in:
iddev5 2022-05-18 18:16:26 +05:30 committed by Stephen Gutekanst
parent 92028a11ef
commit 7486b0ebea
3 changed files with 56 additions and 21 deletions

View file

@ -2,7 +2,6 @@ const std = @import("std");
const Allocator = std.mem.Allocator;
const glfw = @import("glfw");
const gpu = @import("gpu");
const App = @import("app");
const structs = @import("structs.zig");
const enums = @import("enums.zig");
const Timer = @import("Timer.zig");
@ -43,8 +42,8 @@ pub const Core = struct {
return core.internal.setSizeLimits(min, max);
}
pub fn setKeyCallback(core: *Core, comptime cb: fn (app: *App, engine: *Engine, key: enums.Key, action: enums.Action) void) void {
core.internal.setKeyCallback(cb);
pub fn pollEvent(core: *Core) ?structs.Event {
return core.internal.pollEvent();
}
};