core: simplify event iterator
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
8b8489b3e2
commit
09d39fb694
13 changed files with 46 additions and 74 deletions
|
|
@ -23,11 +23,7 @@ pub const Darwin = @This();
|
|||
|
||||
allocator: std.mem.Allocator,
|
||||
core: *Core,
|
||||
|
||||
events: Core.EventQueue,
|
||||
input_state: Core.InputState,
|
||||
// modifiers: KeyMods,
|
||||
|
||||
title: [:0]const u8,
|
||||
display_mode: DisplayMode,
|
||||
vsync_mode: VSyncMode,
|
||||
|
|
@ -72,7 +68,12 @@ pub fn run(comptime on_each_update_fn: anytype, args_tuple: std.meta.ArgsTuple(@
|
|||
}
|
||||
|
||||
// Called on the main thread
|
||||
pub fn init(darwin: *Darwin, options: InitOptions) !void {
|
||||
pub fn init(
|
||||
darwin: *Darwin,
|
||||
core: *Core.Mod,
|
||||
options: InitOptions,
|
||||
) !void {
|
||||
_ = core;
|
||||
var surface_descriptor = gpu.Surface.Descriptor{};
|
||||
|
||||
// TODO: support UIKit.
|
||||
|
|
@ -106,13 +107,9 @@ pub fn init(darwin: *Darwin, options: InitOptions) !void {
|
|||
window.?.makeKeyAndOrderFront(null);
|
||||
}
|
||||
|
||||
var events = EventQueue.init(options.allocator);
|
||||
try events.ensureTotalCapacity(2048);
|
||||
|
||||
darwin.* = .{
|
||||
.allocator = options.allocator,
|
||||
.core = @fieldParentPtr("platform", darwin),
|
||||
.events = events,
|
||||
.input_state = .{},
|
||||
.title = options.title,
|
||||
.display_mode = options.display_mode,
|
||||
|
|
@ -138,11 +135,6 @@ pub fn update(_: *Darwin) !void {
|
|||
return;
|
||||
}
|
||||
|
||||
// May be called from any thread.
|
||||
pub inline fn pollEvents(n: *Darwin) Core.EventIterator {
|
||||
return .{ .queue = &n.events };
|
||||
}
|
||||
|
||||
// May be called from any thread.
|
||||
pub fn setTitle(_: *Darwin, _: [:0]const u8) void {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -25,11 +25,8 @@ pub const Null = @This();
|
|||
|
||||
allocator: std.mem.Allocator,
|
||||
core: *Core,
|
||||
|
||||
events: Core.EventQueue,
|
||||
input_state: Core.InputState,
|
||||
modifiers: KeyMods,
|
||||
|
||||
title: [:0]u8,
|
||||
display_mode: DisplayMode,
|
||||
vsync_mode: VSyncMode,
|
||||
|
|
@ -42,7 +39,14 @@ size: Size,
|
|||
surface_descriptor: gpu.Surface.Descriptor,
|
||||
|
||||
// Called on the main thread
|
||||
pub fn init(_: *Null, _: InitOptions) !void {
|
||||
pub fn init(
|
||||
nul: *Null,
|
||||
core: *Core.Mod,
|
||||
options: InitOptions,
|
||||
) !void {
|
||||
_ = nul;
|
||||
_ = options;
|
||||
_ = core;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -55,11 +59,6 @@ pub fn update(_: *Null) !void {
|
|||
return;
|
||||
}
|
||||
|
||||
// May be called from any thread.
|
||||
pub inline fn pollEvents(n: *Null) Core.EventIterator {
|
||||
return .{ .queue = &n.events };
|
||||
}
|
||||
|
||||
// May be called from any thread.
|
||||
pub fn setTitle(_: *Null, _: [:0]const u8) void {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ surrogate: u16 = 0,
|
|||
dinput: *w.IDirectInput8W,
|
||||
saved_window_rect: w.RECT,
|
||||
surface_descriptor_from_hwnd: gpu.Surface.DescriptorFromWindowsHWND,
|
||||
events: EventQueue,
|
||||
state: *Core,
|
||||
input_state: Core.InputState,
|
||||
oom: std.Thread.ResetEvent = .{},
|
||||
|
||||
|
|
@ -53,11 +53,12 @@ oom: std.Thread.ResetEvent = .{},
|
|||
// ------------------------------
|
||||
pub fn init(
|
||||
self: *Win32,
|
||||
core: *Core.Mod,
|
||||
options: InitOptions,
|
||||
) !void {
|
||||
self.state = core.state();
|
||||
self.allocator = options.allocator;
|
||||
self.core = @fieldParentPtr("platform", self);
|
||||
self.events = EventQueue.init(self.allocator);
|
||||
self.size = options.size;
|
||||
self.input_state = .{};
|
||||
self.saved_window_rect = .{ .top = 0, .left = 0, .right = 0, .bottom = 0 };
|
||||
|
|
@ -138,7 +139,6 @@ pub fn init(
|
|||
}
|
||||
|
||||
pub fn deinit(self: *Win32) void {
|
||||
self.events.deinit();
|
||||
_ = self.dinput.IUnknown_Release();
|
||||
}
|
||||
|
||||
|
|
@ -151,10 +151,6 @@ pub fn update(self: *Win32) !void {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn pollEvents(self: *Win32) EventIterator {
|
||||
return .{ .queue = &self.events };
|
||||
}
|
||||
|
||||
pub fn setTitle(self: *Win32, title: [:0]const u8) void {
|
||||
const wtitle = std.unicode.utf8ToUtf16LeAllocZ(self.allocator, title) catch {
|
||||
self.oom.set();
|
||||
|
|
@ -316,7 +312,7 @@ pub fn outOfMemory(self: *Win32) bool {
|
|||
}
|
||||
|
||||
fn pushEvent(self: *Win32, event: Event) void {
|
||||
self.events.writeItem(event) catch self.oom.set();
|
||||
self.state.events.writeItem(event) catch self.oom.set();
|
||||
}
|
||||
|
||||
fn getKeyboardModifiers() mach.Core.KeyMods {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue