mach: initial support for high-level ECS applications
Adds experimental support for high-level ECS-based applications following hexops/mach#349 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
167f2d3a4f
commit
6ec27861b4
2 changed files with 56 additions and 0 deletions
50
src/engine.zig
Normal file
50
src/engine.zig
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
pub const Core = @import("Core.zig");
|
||||||
|
pub const gpu = @import("gpu");
|
||||||
|
pub 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,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
pub fn App(
|
||||||
|
modules: anytype,
|
||||||
|
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),
|
||||||
|
|
||||||
|
pub fn init(app: *@This(), core: *Core) !void {
|
||||||
|
app.* = .{
|
||||||
|
.engine = try ecs.World(modules).init(core.allocator),
|
||||||
|
};
|
||||||
|
app.*.engine.set(.mach, .core, core);
|
||||||
|
app.*.engine.set(.mach, .device, core.device);
|
||||||
|
try init(&app.engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(app: *@This(), _: *Core) void {
|
||||||
|
app.engine.deinit();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update(app: *@This(), _: *Core) !void {
|
||||||
|
app.engine.tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn resize(app: *@This(), core: *Core, width: u32, height: u32) !void {
|
||||||
|
_ = app;
|
||||||
|
_ = core;
|
||||||
|
_ = width;
|
||||||
|
_ = height;
|
||||||
|
// TODO: send resize messages to ECS modules
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -3,3 +3,9 @@ pub usingnamespace @import("enums.zig");
|
||||||
pub const Core = @import("Core.zig");
|
pub const Core = @import("Core.zig");
|
||||||
pub const Timer = @import("Timer.zig");
|
pub const Timer = @import("Timer.zig");
|
||||||
pub const ResourceManager = @import("resource/ResourceManager.zig");
|
pub const ResourceManager = @import("resource/ResourceManager.zig");
|
||||||
|
pub const gpu = @import("gpu");
|
||||||
|
pub const ecs = @import("ecs");
|
||||||
|
|
||||||
|
// Engine exports
|
||||||
|
pub const App = @import("engine.zig").App;
|
||||||
|
pub const module = @import("engine.zig").module;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue