core: make Core.pollEvents return an iterator, remove Core.hasEvent
After this change: * `Core.pollEvents` returns an iterator. At the time of polling events, Mach core will perform work to poll for events, handle resizing of the framebuffer, etc. and the iterator allows the caller to consume all available events. * The event queue is now baced by a `std.fifo.LinearFifo`, which removes the need for dynamic allocation of each event. Instead, the event queue starts with a generous size suitable for most high-end gaming setups (high-precision mouse, etc.) and can grow, but never shrink, up to the maximum event queue size experienced by the app within any given frame. Effectively, this means we find the maximum capacity needed to store events and avoid runtime allocations. * `Core.hasEvent` is removed. Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
b497a1bbeb
commit
40351f85ba
4 changed files with 142 additions and 134 deletions
|
|
@ -24,12 +24,16 @@ pub fn deinit(core: *Core) void {
|
|||
return core.internal.deinit();
|
||||
}
|
||||
|
||||
pub fn hasEvent(core: *Core) bool {
|
||||
return core.internal.hasEvent();
|
||||
}
|
||||
pub const EventIterator = struct {
|
||||
internal: platform.Core.EventIterator,
|
||||
|
||||
pub fn pollEvents(core: *Core) ?Event {
|
||||
return core.internal.pollEvents();
|
||||
pub inline fn next(self: *EventIterator) ?Event {
|
||||
return self.internal.next();
|
||||
}
|
||||
};
|
||||
|
||||
pub inline fn pollEvents(core: *Core) EventIterator {
|
||||
return .{ .internal = core.internal.pollEvents() };
|
||||
}
|
||||
|
||||
/// Returns the framebuffer size, in subpixel units.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue