From 17b3a4c23d32ca95e357e1558cc0976e3541e6d3 Mon Sep 17 00:00:00 2001 From: peterino2 Date: Thu, 1 Jan 2026 16:10:54 -0800 Subject: [PATCH] trampoline loading is now working for coreTest... now onto hot reloading --- build/program.zig | 23 ++++++++++++++++++----- engine/core/src/core.zig | 2 ++ engine/core/src/engine.zig | 1 + engine/main2.zig | 10 ++++++++-- engine/modulelaunch.zig | 2 ++ lib/p2/src/structures/string-pool.zig | 2 +- projects/build.zig | 10 +++++----- 7 files changed, 37 insertions(+), 13 deletions(-) diff --git a/build/program.zig b/build/program.zig index 7d31285..47d92ff 100644 --- a/build/program.zig +++ b/build/program.zig @@ -189,22 +189,35 @@ pub const Program = struct { exe.root_module.addImport("backlog", gameApi); } + const installed = self.buildSystem.b.addInstallArtifact(exe, .{}); + { - const runArtifact = b.addRunArtifact(exe); + const run = b.addSystemCommand(&.{b.fmt("zig-out/bin/{s}", .{self.name})}); + run.step.dependOn(&installed.step); + if (b.args) |args| { - runArtifact.addArgs(args); + run.addArgs(args); } const run_exe = b.step(b.fmt("run-{s}", .{self.name}), "runs the program"); - run_exe.dependOn(&runArtifact.step); + run_exe.dependOn(&run.step); + + // const runArtifact = b.addRunArtifact(exe); + // if (b.args) |args| { + // runArtifact.addArgs(args); + // } + + // // Set CWD to the build.zig directory so the exe can find zig-out/modules/ + // runArtifact.setCwd(b.path(".")); + + // const run_exe = b.step(b.fmt("run-{s}", .{self.name}), "runs the program"); + // run_exe.dependOn(&runArtifact.step); } // 2. create the actual library that the loader will try to load // 3. set up linking, if static then we will link against the loader - self.buildSystem.b.installArtifact(exe); - // return the actual library not the loader return exe; } diff --git a/engine/core/src/core.zig b/engine/core/src/core.zig index 448258d..142ee64 100644 --- a/engine/core/src/core.zig +++ b/engine/core/src/core.zig @@ -314,6 +314,7 @@ pub fn start_module_(map: *SpecVariantMap, args: anytype, allocator: std.mem.All _ = try gEngine.createObject(scene.SceneSystem, .{ .can_tick = true }); try algorithm.string_pool.setup(allocator); + gEngine.stringContext = algorithm.string_pool.gStringContext; _ = try createObject(GameObjectSystem, .{ .can_tick = true }); _ = try inputs.initInputStack(); @@ -328,6 +329,7 @@ pub fn setupFromModule(__args: ModuleLoaderArgs) !void { gEngine = __args.engine; gPackerFS = __args.packerFS; algorithm.names.gRegistry = __args.nameRegistry; + algorithm.string_pool.gStringContext = gEngine.stringContext; logging.setupLoggingFromModule(); staticsInitialized = true; diff --git a/engine/core/src/engine.zig b/engine/core/src/engine.zig index 01b0830..cc82f4e 100644 --- a/engine/core/src/engine.zig +++ b/engine/core/src/engine.zig @@ -92,6 +92,7 @@ pub const Engine = struct { first: bool = true, shutdownModuleFunction: ?*const fn () callconv(.c) void = null, + stringContext: *core.algorithm.string_pool.StringContext = undefined, pub fn init(allocator: std.mem.Allocator) !@This() { const rv = Engine{ diff --git a/engine/main2.zig b/engine/main2.zig index 99518fd..aca091c 100644 --- a/engine/main2.zig +++ b/engine/main2.zig @@ -110,10 +110,10 @@ pub fn startEngine(spec: *core.SpecVariantMap) bool { if (core.getEngine().shutdownModuleFunction) |f| { f(); + } else { + core.shutdown_module(allocator); } - core.shutdown_module(allocator); - return true; } @@ -144,4 +144,10 @@ pub fn main() !void { // panickers.attachSegfaultHandler(); // try realMain.main(); + + shutdown_hook(); +} + +pub fn shutdown_hook() void { + std.debug.print("[engine] shutting down now! goodbye!", .{}); } diff --git a/engine/modulelaunch.zig b/engine/modulelaunch.zig index c7a0d7c..0de1dc4 100644 --- a/engine/modulelaunch.zig +++ b/engine/modulelaunch.zig @@ -67,6 +67,8 @@ pub export fn shutdown_module() void { shutdownList.deinit(gAllocator); shutdownModuleNames.deinit(gAllocator); + + core.shutdown_module(gAllocator); } const gamespec = @import("gamespec"); diff --git a/lib/p2/src/structures/string-pool.zig b/lib/p2/src/structures/string-pool.zig index 5e1c4ce..97afd3e 100644 --- a/lib/p2/src/structures/string-pool.zig +++ b/lib/p2/src/structures/string-pool.zig @@ -17,7 +17,7 @@ const std = @import("std"); // main purpose of this string-pool is to provide an RC-ableinterface for interface // with GC'ed systems such as lua -var gStringContext: *StringContext = undefined; +pub var gStringContext: *StringContext = undefined; pub const String = struct { index: u24, diff --git a/projects/build.zig b/projects/build.zig index 03b190e..6ecc4bb 100644 --- a/projects/build.zig +++ b/projects/build.zig @@ -15,10 +15,10 @@ pub fn build(b: *std.Build) void { "coreTest", ); coreTest.setIconPath("projects/content/icons/icon.ico"); - coreTest.setModuleEnabled("audio", true); - coreTest.setModuleEnabled("imgui", true); - coreTest.setModuleEnabled("net", true); - coreTest.setModuleEnabled("physics", true); - coreTest.setModuleEnabled("ui", true); + // coreTest.setModuleEnabled("audio", true); + // coreTest.setModuleEnabled("imgui", true); + // coreTest.setModuleEnabled("net", true); + // coreTest.setModuleEnabled("physics", true); + // coreTest.setModuleEnabled("ui", true); _ = coreTest.compileInstall(); }