mach: finish splitting Core and Engine
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
603dc4c17f
commit
3ff4bcc2a3
3 changed files with 205 additions and 8 deletions
55
src/engine.zig
Normal file
55
src/engine.zig
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
const Core = @import("core").Core;
|
||||
const gpu = @import("core").gpu;
|
||||
|
||||
const std = @import("std");
|
||||
const ecs = @import("ecs");
|
||||
|
||||
/// The Mach engine ECS module. This enables access to `engine.get(.mach, .core)` `*Core` APIs, as
|
||||
/// to for example `.setOptions(.{.title = "foobar"})`, or to access the GPU device via
|
||||
/// `engine.get(.mach, .device)`
|
||||
pub const module = ecs.Module(.{
|
||||
.globals = struct {
|
||||
core: *Core,
|
||||
device: *gpu.Device,
|
||||
},
|
||||
});
|
||||
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
pub fn App(
|
||||
comptime modules: anytype,
|
||||
comptime app_init: anytype, // fn (engine: *ecs.World(modules)) !void
|
||||
) type {
|
||||
// TODO: validate modules.mach is the expected type.
|
||||
// TODO: validate init has the right function signature
|
||||
|
||||
return struct {
|
||||
engine: ecs.World(modules),
|
||||
core: Core,
|
||||
|
||||
pub fn init(app: *@This()) !void {
|
||||
try app.core.init(allocator, .{});
|
||||
app.* = .{
|
||||
.core = app.core,
|
||||
.engine = try ecs.World(modules).init(allocator),
|
||||
};
|
||||
app.engine.set(.mach, .core, &app.core);
|
||||
app.engine.set(.mach, .device, app.core.device());
|
||||
try app_init(&app.engine);
|
||||
}
|
||||
|
||||
pub fn deinit(app: *@This()) void {
|
||||
const core = app.engine.get(.mach, .core);
|
||||
core.deinit();
|
||||
allocator.destroy(core);
|
||||
app.engine.deinit();
|
||||
_ = gpa.deinit();
|
||||
}
|
||||
|
||||
pub fn update(app: *@This()) !bool {
|
||||
app.engine.tick();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
14
src/main.zig
14
src/main.zig
|
|
@ -1,10 +1,14 @@
|
|||
pub usingnamespace @import("entry.zig");
|
||||
pub const Core = @import("Core.zig");
|
||||
pub const Timer = @import("Timer.zig");
|
||||
pub const gpu = @import("gpu");
|
||||
const core = @import("core");
|
||||
pub const GPUInterface = core.GPUInterface;
|
||||
pub const scope_levels = core.scope_levels;
|
||||
pub const log_level = core.log_level;
|
||||
pub const Core = core.Core;
|
||||
pub const Timer = core.Timer;
|
||||
pub const gpu = core.gpu;
|
||||
pub const sysjs = core.sysjs;
|
||||
|
||||
pub const ecs = @import("ecs");
|
||||
pub const sysaudio = @import("sysaudio");
|
||||
pub const sysjs = @import("sysjs");
|
||||
pub const earcut = @import("earcut");
|
||||
pub const gfx = @import("gfx/util.zig");
|
||||
pub const ResourceManager = @import("resource/ResourceManager.zig");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue