100 lines
2.5 KiB
Zig
100 lines
2.5 KiB
Zig
|
|
// --- LIBS ---
|
||
|
|
const std = @import("std");
|
||
|
|
const root = @import("root");
|
||
|
|
pub const event = @import("event/root.zig");
|
||
|
|
pub const plugin = @import("plugin/root.zig");
|
||
|
|
pub const resource = @import("resource/root.zig");
|
||
|
|
pub const scheduler = @import("scheduler/root.zig");
|
||
|
|
pub const template = @import("template/root.zig");
|
||
|
|
pub const ecs = @import("world/root.zig");
|
||
|
|
const Self = @This();
|
||
|
|
|
||
|
|
pub const stage = struct {
|
||
|
|
pub const Init = struct {};
|
||
|
|
pub const Deinit = struct {};
|
||
|
|
pub const Inputs = struct {};
|
||
|
|
pub const Update = struct {};
|
||
|
|
pub const Draw = struct {};
|
||
|
|
};
|
||
|
|
|
||
|
|
/// ----------------------------------------------------
|
||
|
|
/// ----------------------------------------------------
|
||
|
|
pub const Options = struct {
|
||
|
|
seed: u64 = 8490694,
|
||
|
|
};
|
||
|
|
pub const options: Options = if (@hasDecl(
|
||
|
|
root,
|
||
|
|
"app_options",
|
||
|
|
)) root.app_options else .{};
|
||
|
|
|
||
|
|
//
|
||
|
|
// FIELDS
|
||
|
|
//
|
||
|
|
|
||
|
|
events: event.Storage,
|
||
|
|
plugins: plugin.Storage,
|
||
|
|
resources: resource.Storage,
|
||
|
|
schedules: scheduler.Storage,
|
||
|
|
world: ecs.World,
|
||
|
|
alloc: std.mem.Allocator,
|
||
|
|
|
||
|
|
/// ----------------------------------------------------
|
||
|
|
/// ----------------------------------------------------
|
||
|
|
pub fn init(alloc: std.mem.Allocator) Self {
|
||
|
|
return .{
|
||
|
|
.events = .init(alloc),
|
||
|
|
.plugins = .init(alloc),
|
||
|
|
.resources = .init(alloc),
|
||
|
|
.schedules = .init(alloc),
|
||
|
|
.world = .init(alloc),
|
||
|
|
.alloc = alloc,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
/// ----------------------------------------------------
|
||
|
|
/// ----------------------------------------------------
|
||
|
|
pub fn deinit(self: *Self) void {
|
||
|
|
self.world.deinit();
|
||
|
|
self.events.deinit();
|
||
|
|
self.plugins.deinit();
|
||
|
|
self.resources.deinit();
|
||
|
|
self.schedules.deinit();
|
||
|
|
}
|
||
|
|
|
||
|
|
//
|
||
|
|
// EXAMPLES
|
||
|
|
//
|
||
|
|
|
||
|
|
const example = @import("example/root.zig");
|
||
|
|
|
||
|
|
// ----------------------------------------------------
|
||
|
|
// ----------------------------------------------------
|
||
|
|
test "Main" {
|
||
|
|
// --- APP ---
|
||
|
|
var app: Self = .init(std.testing.allocator);
|
||
|
|
defer app.deinit();
|
||
|
|
|
||
|
|
{ // PLUGINS
|
||
|
|
// --- ADD PLUGINS ---
|
||
|
|
try app.plugins.addMany(&.{
|
||
|
|
example.simple.plugin,
|
||
|
|
});
|
||
|
|
|
||
|
|
// --- BUILD PLUGINS ---
|
||
|
|
try app.plugins.build(.{
|
||
|
|
.app = &app,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
{ // SYSTEMS
|
||
|
|
try app.schedules.runMany(&.{
|
||
|
|
example.simple.stage.Init,
|
||
|
|
example.simple.stage.Inputs,
|
||
|
|
example.simple.stage.Update,
|
||
|
|
example.simple.stage.Draw,
|
||
|
|
example.simple.stage.Deinit,
|
||
|
|
}, .{
|
||
|
|
.app = &app,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|