mach: comptime interface-like implementation of engine cores

This commit is contained in:
iddev5 2022-04-30 18:29:28 +05:30 committed by Stephen Gutekanst
parent 2b978a6883
commit 8904536632
3 changed files with 210 additions and 162 deletions

View file

@ -45,6 +45,8 @@ pub const Options = struct {
power_preference: gpu.PowerPreference = .none,
};
const Engine = @This();
/// Window, events, inputs etc.
core: Core,
@ -53,6 +55,8 @@ gpu_driver: GpuDriver,
allocator: Allocator,
options: Options,
/// The amount of time (in seconds) that has passed since the last frame was rendered.
///
/// For example, if you are animating a cube which should rotate 360 degrees every second,
@ -63,19 +67,41 @@ delta_time_ns: u64 = 0,
timer: std.time.Timer,
pub const Core = struct {
internal: union {
window: glfw.Window,
},
internal: GetCoreInternalType(),
};
pub const GpuDriver = struct {
internal: GetGpuDriverInternalType(),
device: gpu.Device,
backend_type: gpu.Adapter.BackendType,
swap_chain: ?gpu.SwapChain,
swap_chain_format: gpu.Texture.Format,
native_instance: gpu.NativeInstance,
surface: ?gpu.Surface,
current_desc: gpu.SwapChain.Descriptor,
target_desc: gpu.SwapChain.Descriptor,
};
pub fn init(allocator: std.mem.Allocator, options: Options) !Engine {
var engine = Engine{
.allocator = allocator,
.options = options,
.timer = try std.time.Timer.start(),
.core = undefined,
.gpu_driver = undefined,
};
engine.core.internal = try GetCoreInternalType().init(allocator, &engine);
engine.gpu_driver.internal = try GetGpuDriverInternalType().init(allocator, &engine);
return engine;
}
fn GetCoreInternalType() type {
return @import("native.zig").CoreGlfw;
}
fn GetGpuDriverInternalType() type {
return @import("native.zig").GpuDriverNative;
}