2026-07-09 22:30:04 +01:00
|
|
|
// --- 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 ecs = @import("world/root.zig");
|
2026-07-12 20:04:35 +01:00
|
|
|
const template = @import("template/root.zig");
|
2026-07-09 22:30:04 +01:00
|
|
|
const Self = @This();
|
|
|
|
|
|
2026-07-10 16:36:30 +01:00
|
|
|
/// ----------------------------------------------------
|
|
|
|
|
/// Default app stages
|
|
|
|
|
/// ----------------------------------------------------
|
2026-07-09 22:30:04 +01:00
|
|
|
pub const stage = struct {
|
2026-07-14 15:48:44 +01:00
|
|
|
// --- LIFETIME ---
|
2026-07-10 16:36:30 +01:00
|
|
|
pub const init = struct {};
|
|
|
|
|
pub const deinit = struct {};
|
|
|
|
|
|
2026-07-14 15:48:44 +01:00
|
|
|
// --- FRAME ---
|
2026-07-12 20:04:35 +01:00
|
|
|
pub const begin_frame = struct {};
|
|
|
|
|
pub const end_frame = struct {};
|
|
|
|
|
|
2026-07-26 12:47:49 +00:00
|
|
|
// --- CORE ---
|
2026-07-10 16:36:30 +01:00
|
|
|
pub const inputs = struct {};
|
|
|
|
|
pub const fixed_update = struct {};
|
|
|
|
|
pub const update = struct {};
|
|
|
|
|
pub const draw = struct {};
|
2026-07-09 22:30:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// ----------------------------------------------------
|
|
|
|
|
/// ----------------------------------------------------
|
|
|
|
|
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();
|
|
|
|
|
|
2026-07-10 22:41:36 +01:00
|
|
|
// --- SEND MANY EVENTS ---
|
|
|
|
|
try app.events.sendMany(&.{
|
|
|
|
|
event.AppExit{
|
|
|
|
|
.reason = "Yes",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// --- MAIN GAME LOOP ---
|
|
|
|
|
while (true) {
|
|
|
|
|
// --- USE AND EAT EVENT ---
|
|
|
|
|
if (app.events.consume(event.AppExit)) |app_exit| {
|
|
|
|
|
std.debug.print("| {s}\n", .{
|
|
|
|
|
app_exit.reason,
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-09 22:30:04 +01:00
|
|
|
{ // PLUGINS
|
|
|
|
|
// --- ADD PLUGINS ---
|
|
|
|
|
try app.plugins.addMany(&.{
|
|
|
|
|
example.simple.plugin,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// --- BUILD PLUGINS ---
|
|
|
|
|
try app.plugins.build(.{
|
|
|
|
|
.app = &app,
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-07-10 22:27:43 +01:00
|
|
|
|
2026-07-09 22:30:04 +01:00
|
|
|
{ // SYSTEMS
|
2026-07-14 15:48:44 +01:00
|
|
|
try app.schedules.runAll(.{
|
2026-07-09 22:30:04 +01:00
|
|
|
.app = &app,
|
|
|
|
|
});
|
2026-07-14 15:48:44 +01:00
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
|
// });
|
2026-07-09 22:30:04 +01:00
|
|
|
}
|
|
|
|
|
}
|