moving engine setup away from prepare, and everything can be done in start module now
This commit is contained in:
parent
9d3190f78d
commit
0ca5592b40
|
|
@ -90,9 +90,12 @@ pub fn run_everything(comptime GameContext: type) !void {
|
||||||
if (@hasDecl(GameContext, "tick")) {
|
if (@hasDecl(GameContext, "tick")) {
|
||||||
canTick = true;
|
canTick = true;
|
||||||
}
|
}
|
||||||
|
core.engine_logs("creating Game context");
|
||||||
|
|
||||||
_ = try core.createObject(GameContext, .{ .can_tick = canTick });
|
_ = try core.createObject(GameContext, .{ .can_tick = canTick });
|
||||||
|
|
||||||
|
core.engine_logs("calling gEngine.run");
|
||||||
|
|
||||||
try core.gEngine.run();
|
try core.gEngine.run();
|
||||||
|
|
||||||
while (!core.gEngine.exitFinished()) {
|
while (!core.gEngine.exitFinished()) {
|
||||||
|
|
|
||||||
|
|
@ -174,10 +174,9 @@ pub fn registerRendererSetup(ctx: *anyopaque, setup: engine.SetupFuncFn) void {
|
||||||
gEngine.rendererSetupFunc = setup;
|
gEngine.rendererSetupFunc = setup;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setupEnginePlatform(ctx: *anyopaque, setup: engine.SetupFuncFn, poll: engine.PollFuncFn, proc: engine.ProcEventsFn) void {
|
pub fn setupEnginePlatform(ctx: *anyopaque, poll: engine.PollFuncFn, proc: engine.ProcEventsFn) void {
|
||||||
gEngine.platformCtx = ctx;
|
gEngine.platformCtx = ctx;
|
||||||
|
|
||||||
gEngine.platformSetupFunc = setup;
|
|
||||||
gEngine.platformPollFunc = poll;
|
gEngine.platformPollFunc = poll;
|
||||||
gEngine.platformProcEventsFunc = proc;
|
gEngine.platformProcEventsFunc = proc;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ pub const Engine = struct {
|
||||||
|
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
|
|
||||||
|
createObjectLock: bool = false,
|
||||||
|
|
||||||
// better name for these engineObject objects is actually 'engine object'
|
// better name for these engineObject objects is actually 'engine object'
|
||||||
engineObjects: ArrayListUnmanaged(EngineObjectRef),
|
engineObjects: ArrayListUnmanaged(EngineObjectRef),
|
||||||
eventors: ArrayListUnmanaged(EngineObjectRef),
|
eventors: ArrayListUnmanaged(EngineObjectRef),
|
||||||
|
|
@ -69,7 +71,6 @@ pub const Engine = struct {
|
||||||
|
|
||||||
platformCtx: *anyopaque = undefined,
|
platformCtx: *anyopaque = undefined,
|
||||||
platformPollFunc: ?PollFuncFn = null,
|
platformPollFunc: ?PollFuncFn = null,
|
||||||
platformSetupFunc: ?PollFuncFn = null,
|
|
||||||
platformProcEventsFunc: ?ProcEventsFn = null,
|
platformProcEventsFunc: ?ProcEventsFn = null,
|
||||||
|
|
||||||
rendererCtx: *anyopaque = undefined,
|
rendererCtx: *anyopaque = undefined,
|
||||||
|
|
@ -142,6 +143,12 @@ pub const Engine = struct {
|
||||||
|
|
||||||
// creates an engine object using the engine's allocator.
|
// creates an engine object using the engine's allocator.
|
||||||
pub fn createObject(self: *@This(), comptime T: type, params: NeonObjectParams) !*T {
|
pub fn createObject(self: *@This(), comptime T: type, params: NeonObjectParams) !*T {
|
||||||
|
if (self.createObjectLock) {
|
||||||
|
core.engine_err("RECURSIVE OBJECT CREATION NOT ALLOWED", .{});
|
||||||
|
return error.BadInit;
|
||||||
|
}
|
||||||
|
self.createObjectLock = true;
|
||||||
|
defer self.createObjectLock = false;
|
||||||
const newIndex = self.engineObjects.items.len;
|
const newIndex = self.engineObjects.items.len;
|
||||||
const vtable = &@field(T, "NeonObjectTable");
|
const vtable = &@field(T, "NeonObjectTable");
|
||||||
const newObjectPtr = try vtable.init_func(self.allocator);
|
const newObjectPtr = try vtable.init_func(self.allocator);
|
||||||
|
|
@ -276,6 +283,7 @@ pub const Engine = struct {
|
||||||
|
|
||||||
pub fn run(self: *@This()) !void {
|
pub fn run(self: *@This()) !void {
|
||||||
core.engine_logs("engine loop started");
|
core.engine_logs("engine loop started");
|
||||||
|
|
||||||
const SystemsThread = struct {
|
const SystemsThread = struct {
|
||||||
engine: *Engine,
|
engine: *Engine,
|
||||||
|
|
||||||
|
|
@ -308,14 +316,7 @@ pub const Engine = struct {
|
||||||
self.dependentsDestroyed.store(true, .seq_cst);
|
self.dependentsDestroyed.store(true, .seq_cst);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mainLoop(self: *@This()) !void {
|
pub fn runPrepares(self: *@This()) !void {
|
||||||
var exitSignaled: bool = false;
|
|
||||||
|
|
||||||
if (self.platformSetupFunc) |setupFunc| {
|
|
||||||
setupFunc(self.platformCtx) catch unreachable;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
var z = core.tracy.Zone(@src());
|
var z = core.tracy.Zone(@src());
|
||||||
for (self.prepares.items) |prep| {
|
for (self.prepares.items) |prep| {
|
||||||
var z1 = core.tracy.ZoneN(@src(), "Preparing game");
|
var z1 = core.tracy.ZoneN(@src(), "Preparing game");
|
||||||
|
|
@ -326,6 +327,11 @@ pub const Engine = struct {
|
||||||
z.End();
|
z.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn mainLoop(self: *@This()) !void {
|
||||||
|
var exitSignaled: bool = false;
|
||||||
|
|
||||||
|
try self.runPrepares();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
self.tick() catch unreachable;
|
self.tick() catch unreachable;
|
||||||
self.jobManager.bump();
|
self.jobManager.bump();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ pub const list = [_][]const u8{
|
||||||
"physics",
|
"physics",
|
||||||
|
|
||||||
"rend",
|
"rend",
|
||||||
"imgui",
|
// "imgui",
|
||||||
// to be implemented
|
// to be implemented
|
||||||
// "graphics",
|
// "graphics",
|
||||||
// "ui",
|
// "ui",
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,9 @@ pub fn start_module(comptime programSpec: anytype, args: anytype, allocator: std
|
||||||
gPlatformInstance = try allocator.create(windowing.PlatformInstance);
|
gPlatformInstance = try allocator.create(windowing.PlatformInstance);
|
||||||
gPlatformInstance.* = try windowing.PlatformInstance.init(allocator, gStartupParams);
|
gPlatformInstance.* = try windowing.PlatformInstance.init(allocator, gStartupParams);
|
||||||
|
|
||||||
try gPlatformInstance.registerSetupFuncs();
|
try gPlatformInstance.setupWindow();
|
||||||
|
|
||||||
|
try gPlatformInstance.registerFuncs();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getInstance() *windowing.PlatformInstance {
|
pub fn getInstance() *windowing.PlatformInstance {
|
||||||
|
|
|
||||||
|
|
@ -105,15 +105,13 @@ pub const PlatformInstance = struct {
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setupWindow(opaqueSelf: *anyopaque) core.EngineDataEventError!void {
|
pub fn setupWindow(self: *@This()) core.EngineDataEventError!void {
|
||||||
const self: *@This() = @alignCast(@ptrCast(opaqueSelf));
|
|
||||||
|
|
||||||
sdl3.init(.{ .video = true, .gamepad = true }) catch return error.BadInit;
|
sdl3.init(.{ .video = true, .gamepad = true }) catch return error.BadInit;
|
||||||
self.window = sdl3.c.SDL_CreateWindow(self.windowName, self.windowExtent.x, self.windowExtent.y, 0).?; // resizeable
|
self.window = sdl3.c.SDL_CreateWindow(self.windowName, self.windowExtent.x, self.windowExtent.y, 0).?; // resizeable
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn registerSetupFuncs(self: *@This()) !void {
|
pub fn registerFuncs(self: *@This()) !void {
|
||||||
core.setupEnginePlatform(self, setupWindow, enginePoll, processEvents);
|
core.setupEnginePlatform(self, enginePoll, processEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
// runs pinned on io thread.
|
// runs pinned on io thread.
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,9 @@ pub const Module: core.ModuleDescription = .{
|
||||||
pub fn start_module(comptime programSpec: anytype, args: anytype, allocator: std.mem.Allocator) !void {
|
pub fn start_module(comptime programSpec: anytype, args: anytype, allocator: std.mem.Allocator) !void {
|
||||||
_ = args;
|
_ = args;
|
||||||
_ = programSpec;
|
_ = programSpec;
|
||||||
core.engine_log("starting up renderer interface", .{});
|
|
||||||
rendAllocator = allocator;
|
rendAllocator = allocator;
|
||||||
|
try renderer.createInstance();
|
||||||
try renderer.start();
|
try renderer.start();
|
||||||
|
|
||||||
try core.defineComponent(MeshComponent, allocator);
|
|
||||||
try core.defineComponent(CameraComponent, allocator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn shutdown_module(allocator: std.mem.Allocator) void {
|
pub fn shutdown_module(allocator: std.mem.Allocator) void {
|
||||||
|
|
|
||||||
|
|
@ -45,12 +45,10 @@ pub const Renderer = struct {
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
};
|
};
|
||||||
|
|
||||||
return self;
|
try core.defineComponent(rend.MeshComponent, allocator);
|
||||||
}
|
try core.defineComponent(rend.CameraComponent, allocator);
|
||||||
|
|
||||||
pub fn prepare(self: *@This()) core.EngineDataEventError!void {
|
return self;
|
||||||
core.engine_log("starting up renderer interface", .{});
|
|
||||||
self.startRenderer() catch return error.BadInit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn registerRendererObject(self: *@This(), T: type) !*T {
|
pub fn registerRendererObject(self: *@This(), T: type) !*T {
|
||||||
|
|
@ -448,11 +446,15 @@ pub fn reloadShaders() !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====== renderer API =======
|
// ====== renderer API =======
|
||||||
pub fn start() !void {
|
pub fn createInstance() !void {
|
||||||
gRenderer = try core.createObject(Renderer, .{ .can_tick = true, .isCore = true });
|
gRenderer = try core.createObject(Renderer, .{ .can_tick = true, .isCore = true });
|
||||||
gAllocator = gRenderer.allocator;
|
gAllocator = gRenderer.allocator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn start() !void {
|
||||||
|
try gRenderer.startRenderer();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn shutdown() void {}
|
pub fn shutdown() void {}
|
||||||
|
|
||||||
pub fn context() *Renderer {
|
pub fn context() *Renderer {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue