core: more code refactoring / improvements
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
de1275dc0a
commit
470a84909b
6 changed files with 7 additions and 35 deletions
|
|
@ -267,14 +267,14 @@ pub fn build(b: *std.Build) !void {
|
||||||
|
|
||||||
pub const Platform = enum {
|
pub const Platform = enum {
|
||||||
wasm,
|
wasm,
|
||||||
win32,
|
windows,
|
||||||
darwin,
|
darwin,
|
||||||
null,
|
null,
|
||||||
|
|
||||||
pub fn fromTarget(target: std.Target) Platform {
|
pub fn fromTarget(target: std.Target) Platform {
|
||||||
if (target.cpu.arch == .wasm32) return .wasm;
|
if (target.cpu.arch == .wasm32) return .wasm;
|
||||||
if (target.os.tag.isDarwin()) return .darwin;
|
if (target.os.tag.isDarwin()) return .darwin;
|
||||||
if (target.os.tag == .windows) return .win32;
|
if (target.os.tag == .windows) return .windows;
|
||||||
return .null;
|
return .null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ pub const sysgpu = @import("../main.zig").sysgpu;
|
||||||
|
|
||||||
pub 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"),
|
||||||
.win32 => @import("core/win32.zig"),
|
.windows => @import("core/Windows.zig"),
|
||||||
.darwin => @import("core/Darwin.zig"),
|
.darwin => @import("core/Darwin.zig"),
|
||||||
.null => @import("core/Null.zig"),
|
.null => @import("core/Null.zig"),
|
||||||
};
|
};
|
||||||
|
|
@ -19,7 +19,7 @@ pub const Platform = switch (build_options.core_platform) {
|
||||||
// Whether or not you can drive the main loop in a non-blocking fashion, or if the underlying
|
// Whether or not you can drive the main loop in a non-blocking fashion, or if the underlying
|
||||||
// platform must take control and drive the main loop itself.
|
// platform must take control and drive the main loop itself.
|
||||||
pub const supports_non_blocking = switch (build_options.core_platform) {
|
pub const supports_non_blocking = switch (build_options.core_platform) {
|
||||||
.win32 => true,
|
.windows => true,
|
||||||
.wasm => false,
|
.wasm => false,
|
||||||
.darwin => false,
|
.darwin => false,
|
||||||
.null => true,
|
.null => true,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const mach = @import("../main.zig");
|
const mach = @import("../main.zig");
|
||||||
const Core = @import("../Core.zig");
|
const Core = @import("../Core.zig");
|
||||||
const InputState = @import("InputState.zig");
|
|
||||||
const gpu = mach.gpu;
|
const gpu = mach.gpu;
|
||||||
const InitOptions = Core.InitOptions;
|
const InitOptions = Core.InitOptions;
|
||||||
const Event = Core.Event;
|
const Event = Core.Event;
|
||||||
|
|
@ -36,7 +35,7 @@ allocator: std.mem.Allocator,
|
||||||
core: *Core,
|
core: *Core,
|
||||||
|
|
||||||
events: EventQueue,
|
events: EventQueue,
|
||||||
input_state: InputState,
|
input_state: Core.InputState,
|
||||||
// modifiers: KeyMods,
|
// modifiers: KeyMods,
|
||||||
|
|
||||||
title: [:0]const u8,
|
title: [:0]const u8,
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
const std = @import("std");
|
|
||||||
const Core = @import("../Core.zig");
|
|
||||||
const KeyBitSet = std.StaticBitSet(@intFromEnum(Core.Key.max) + 1);
|
|
||||||
const MouseButtonSet = std.StaticBitSet(@as(u4, @intFromEnum(Core.MouseButton.max)) + 1);
|
|
||||||
const InputState = @This();
|
|
||||||
|
|
||||||
keys: KeyBitSet = KeyBitSet.initEmpty(),
|
|
||||||
mouse_buttons: MouseButtonSet = MouseButtonSet.initEmpty(),
|
|
||||||
mouse_position: Core.Position = .{ .x = 0, .y = 0 },
|
|
||||||
|
|
||||||
pub inline fn isKeyPressed(self: InputState, key: Core.Key) bool {
|
|
||||||
return self.keys.isSet(@intFromEnum(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub inline fn isKeyReleased(self: InputState, key: Core.Key) bool {
|
|
||||||
return !self.isKeyPressed(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub inline fn isMouseButtonPressed(self: InputState, button: Core.MouseButton) bool {
|
|
||||||
return self.mouse_buttons.isSet(@intFromEnum(button));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub inline fn isMouseButtonReleased(self: InputState, button: Core.MouseButton) bool {
|
|
||||||
return !self.isMouseButtonPressed(button);
|
|
||||||
}
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const mach = @import("../main.zig");
|
const mach = @import("../main.zig");
|
||||||
const Core = @import("../Core.zig");
|
const Core = @import("../Core.zig");
|
||||||
const InputState = @import("InputState.zig");
|
|
||||||
const gpu = mach.gpu;
|
const gpu = mach.gpu;
|
||||||
const InitOptions = Core.InitOptions;
|
const InitOptions = Core.InitOptions;
|
||||||
const Event = Core.Event;
|
const Event = Core.Event;
|
||||||
|
|
@ -38,7 +37,7 @@ allocator: std.mem.Allocator,
|
||||||
core: *Core,
|
core: *Core,
|
||||||
|
|
||||||
events: EventQueue,
|
events: EventQueue,
|
||||||
input_state: InputState,
|
input_state: Core.InputState,
|
||||||
modifiers: KeyMods,
|
modifiers: KeyMods,
|
||||||
|
|
||||||
title: [:0]u8,
|
title: [:0]u8,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ const std = @import("std");
|
||||||
const w = @import("../win32.zig");
|
const w = @import("../win32.zig");
|
||||||
const mach = @import("../main.zig");
|
const mach = @import("../main.zig");
|
||||||
const Core = @import("../Core.zig");
|
const Core = @import("../Core.zig");
|
||||||
const InputState = @import("InputState.zig");
|
|
||||||
|
|
||||||
const gpu = mach.gpu;
|
const gpu = mach.gpu;
|
||||||
const InitOptions = Core.InitOptions;
|
const InitOptions = Core.InitOptions;
|
||||||
|
|
@ -47,7 +46,7 @@ dinput: *w.IDirectInput8W,
|
||||||
saved_window_rect: w.RECT,
|
saved_window_rect: w.RECT,
|
||||||
surface_descriptor_from_hwnd: gpu.Surface.DescriptorFromWindowsHWND,
|
surface_descriptor_from_hwnd: gpu.Surface.DescriptorFromWindowsHWND,
|
||||||
events: EventQueue,
|
events: EventQueue,
|
||||||
input_state: InputState,
|
input_state: Core.InputState,
|
||||||
oom: std.Thread.ResetEvent = .{},
|
oom: std.Thread.ResetEvent = .{},
|
||||||
|
|
||||||
// ------------------------------
|
// ------------------------------
|
||||||
Loading…
Add table
Add a link
Reference in a new issue