core: centralize EventQueue and EventIterator declaration
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
1fab277bf7
commit
2eac60caf1
4 changed files with 17 additions and 43 deletions
22
src/Core.zig
22
src/Core.zig
|
|
@ -7,9 +7,7 @@ const gpu = mach.gpu;
|
||||||
const log = std.log.scoped(.mach);
|
const log = std.log.scoped(.mach);
|
||||||
const gamemode_log = std.log.scoped(.gamemode);
|
const gamemode_log = std.log.scoped(.gamemode);
|
||||||
|
|
||||||
pub const sysgpu = @import("../main.zig").sysgpu;
|
const Platform = switch (build_options.core_platform) {
|
||||||
|
|
||||||
pub const Platform = switch (build_options.core_platform) {
|
|
||||||
.wasm => @panic("TODO: support mach.Core WASM platform"),
|
.wasm => @panic("TODO: support mach.Core WASM platform"),
|
||||||
.windows => @import("core/Windows.zig"),
|
.windows => @import("core/Windows.zig"),
|
||||||
.darwin => @import("core/Darwin.zig"),
|
.darwin => @import("core/Darwin.zig"),
|
||||||
|
|
@ -25,6 +23,16 @@ pub const supports_non_blocking = switch (build_options.core_platform) {
|
||||||
.null => true,
|
.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.
|
/// 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.
|
/// A panic will occur if `supports_non_blocking == false` for the platform.
|
||||||
|
|
@ -148,14 +156,6 @@ surface: *gpu.Surface,
|
||||||
swap_chain: *gpu.SwapChain,
|
swap_chain: *gpu.SwapChain,
|
||||||
descriptor: gpu.SwapChain.Descriptor,
|
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.
|
// TODO: this needs to be removed.
|
||||||
pub const InitOptions = struct {
|
pub const InitOptions = struct {
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
|
|
|
||||||
|
|
@ -19,21 +19,12 @@ const objc = @import("objc");
|
||||||
|
|
||||||
const log = std.log.scoped(.mach);
|
const log = std.log.scoped(.mach);
|
||||||
|
|
||||||
const EventQueue = std.fifo.LinearFifo(Event, .Dynamic);
|
|
||||||
pub const EventIterator = struct {
|
|
||||||
queue: *EventQueue,
|
|
||||||
|
|
||||||
pub inline fn next(self: *EventIterator) ?Event {
|
|
||||||
return self.queue.readItem();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const Darwin = @This();
|
pub const Darwin = @This();
|
||||||
|
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
core: *Core,
|
core: *Core,
|
||||||
|
|
||||||
events: EventQueue,
|
events: Core.EventQueue,
|
||||||
input_state: Core.InputState,
|
input_state: Core.InputState,
|
||||||
// modifiers: KeyMods,
|
// modifiers: KeyMods,
|
||||||
|
|
||||||
|
|
@ -148,8 +139,8 @@ pub fn update(_: *Darwin) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// May be called from any thread.
|
// May be called from any thread.
|
||||||
pub inline fn pollEvents(n: *Darwin) EventIterator {
|
pub inline fn pollEvents(n: *Darwin) Core.EventIterator {
|
||||||
return EventIterator{ .queue = &n.events };
|
return .{ .queue = &n.events };
|
||||||
}
|
}
|
||||||
|
|
||||||
// May be called from any thread.
|
// May be called from any thread.
|
||||||
|
|
|
||||||
|
|
@ -21,21 +21,12 @@ const KeyMods = Core.KeyMods;
|
||||||
|
|
||||||
const log = std.log.scoped(.mach);
|
const log = std.log.scoped(.mach);
|
||||||
|
|
||||||
const EventQueue = std.fifo.LinearFifo(Event, .Dynamic);
|
|
||||||
pub const EventIterator = struct {
|
|
||||||
queue: *EventQueue,
|
|
||||||
|
|
||||||
pub inline fn next(self: *EventIterator) ?Event {
|
|
||||||
return self.queue.readItem();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const Null = @This();
|
pub const Null = @This();
|
||||||
|
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
core: *Core,
|
core: *Core,
|
||||||
|
|
||||||
events: EventQueue,
|
events: Core.EventQueue,
|
||||||
input_state: Core.InputState,
|
input_state: Core.InputState,
|
||||||
modifiers: KeyMods,
|
modifiers: KeyMods,
|
||||||
|
|
||||||
|
|
@ -65,8 +56,8 @@ pub fn update(_: *Null) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// May be called from any thread.
|
// May be called from any thread.
|
||||||
pub inline fn pollEvents(n: *Null) EventIterator {
|
pub inline fn pollEvents(n: *Null) Core.EventIterator {
|
||||||
return EventIterator{ .queue = &n.events };
|
return .{ .queue = &n.events };
|
||||||
}
|
}
|
||||||
|
|
||||||
// May be called from any thread.
|
// May be called from any thread.
|
||||||
|
|
|
||||||
|
|
@ -151,14 +151,6 @@ pub fn update(self: *Win32) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const EventIterator = struct {
|
|
||||||
queue: *EventQueue,
|
|
||||||
|
|
||||||
pub fn next(self: *EventIterator) ?Event {
|
|
||||||
return self.queue.readItem();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn pollEvents(self: *Win32) EventIterator {
|
pub fn pollEvents(self: *Win32) EventIterator {
|
||||||
return .{ .queue = &self.events };
|
return .{ .queue = &self.events };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue