core: centralize EventQueue and EventIterator declaration

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-08-25 16:04:25 -07:00
parent 1fab277bf7
commit 2eac60caf1
4 changed files with 17 additions and 43 deletions

View file

@ -7,9 +7,7 @@ const gpu = mach.gpu;
const log = std.log.scoped(.mach);
const gamemode_log = std.log.scoped(.gamemode);
pub const sysgpu = @import("../main.zig").sysgpu;
pub const Platform = switch (build_options.core_platform) {
const Platform = switch (build_options.core_platform) {
.wasm => @panic("TODO: support mach.Core WASM platform"),
.windows => @import("core/Windows.zig"),
.darwin => @import("core/Darwin.zig"),
@ -25,6 +23,16 @@ pub const supports_non_blocking = switch (build_options.core_platform) {
.null => true,
};
pub const EventQueue = std.fifo.LinearFifo(Event, .Dynamic);
pub const EventIterator = struct {
queue: *EventQueue,
pub fn next(self: *EventIterator) ?Event {
return self.queue.readItem();
}
};
/// Set this to true if you intend to drive the main loop yourself.
///
/// A panic will occur if `supports_non_blocking == false` for the platform.
@ -148,14 +156,6 @@ surface: *gpu.Surface,
swap_chain: *gpu.SwapChain,
descriptor: gpu.SwapChain.Descriptor,
pub const EventIterator = struct {
platform: Platform.EventIterator,
pub inline fn next(iter: *EventIterator) ?Event {
return iter.platform.next();
}
};
// TODO: this needs to be removed.
pub const InitOptions = struct {
allocator: std.mem.Allocator,