diff --git a/build/program.zig b/build/program.zig index 4c2b1a4..e5ffa3a 100644 --- a/build/program.zig +++ b/build/program.zig @@ -180,6 +180,11 @@ pub const Program = struct { exe.root_module.addImport("core", core); exe.root_module.addOptions("BacklogOptions", self.buildSystem.options); + if (!self.opts.static_build) { + const platform = self.buildSystem.nwdep.module("platform"); + exe.root_module.addImport("platform", platform); + } + const gameModule = self.makeGameModule(); const gameApi = self.makeGameApi(); gameModule.root_module.addImport("backlog", gameApi); @@ -189,7 +194,7 @@ pub const Program = struct { exe.root_module.addImport("backlog", gameApi); } - self.buildSystem.b.installArtifact(exe); + // self.buildSystem.b.installArtifact(exe); const installed = self.buildSystem.b.addInstallArtifact(exe, .{}); { @@ -204,11 +209,6 @@ pub const Program = struct { run_exe.dependOn(&run.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 - - // return the actual library not the loader return exe; } }; diff --git a/engine/core/src/extern/externModule.zig b/engine/core/src/extern/externModule.zig index 634a2bd..5948313 100644 --- a/engine/core/src/extern/externModule.zig +++ b/engine/core/src/extern/externModule.zig @@ -170,6 +170,7 @@ pub const ModuleLoader = struct { } try core.fs().addFileChangedCallback(libFileName, dllChangedCallback, loaded); + core.engine_log("[ModuleLoader]: addFileChangedCallback '{s}'", .{libFileName}); try self.loadedModules.append(self.arena.allocator(), loaded); } diff --git a/engine/main2.zig b/engine/main2.zig index e20e2f9..b1aebf9 100644 --- a/engine/main2.zig +++ b/engine/main2.zig @@ -97,6 +97,12 @@ pub fn startEngine(spec: *core.SpecVariantMap) bool { var modalloc = allocator; _ = modlaunch.startup_module(&modalloc, &modargs); } else { + const platform = @import("platform").module; + platform.watchModules(); + + //if (comptime @hasDecl(backlog, "platform")) { + //backlog.platform.watchModules(); + // } core.loadModule(moduleName, true) catch return false; } diff --git a/engine/modulelaunch.zig b/engine/modulelaunch.zig index 0de1dc4..4ada2ea 100644 --- a/engine/modulelaunch.zig +++ b/engine/modulelaunch.zig @@ -25,35 +25,48 @@ pub export fn startup_module(p_allocator: *anyopaque, p_a: ?*anyopaque) bool { const spec = gamespec.getSpec() catch return false; - for (backlog.moduleList) |li| { - core.engine_log("mod: {s}", .{li}); - } - const args = getArgs() catch NwArgs{}; - inline for (backlog.moduleList) |feature| { - if (@hasDecl(backlog, feature) and !std.mem.eql(u8, "core", feature)) { - const Struct = @field(backlog, feature); - if (core.isModuleEnabled(Struct.Module, spec)) { - var z1 = core.tracy.ZoneN(@src(), @ptrCast("Initializing Module")); - defer z1.End(); - core.tracy.Message(Struct.Module.name); - Struct.start_module(spec, args, allocator) catch return false; + const moduleArgs = core.startup_getArgs(p_a.?); - if (core.MemoryTracker.MTGet()) |_| { - core.MemoryTracker.MTPrintStatsDelta(); + // firstLoad: bool, + // engine: *core.Engine, + // nameRegistry: *p2.NameRegistry, + // packerFS: *core.PackerFS, + // // luaState: *anyopaque, + // // luaAllocator: *anyopaque, + // debugDrawInterface: ?*debug.DebugDrawInterface, + + if (moduleArgs.firstLoad) { + inline for (backlog.moduleList) |feature| { + if (@hasDecl(backlog, feature) and !std.mem.eql(u8, "core", feature)) { + const Struct = @field(backlog, feature); + if (core.isModuleEnabled(Struct.Module, spec)) { + var z1 = core.tracy.ZoneN(@src(), @ptrCast("Initializing Module")); + defer z1.End(); + core.engine_logs("starting module >>>> " ++ feature ++ " <<<<"); + core.tracy.Message(Struct.Module.name); + Struct.start_module(spec, args, allocator) catch return false; + + if (core.MemoryTracker.MTGet()) |_| { + core.MemoryTracker.MTPrintStatsDelta(); + } + + shutdownList.append(allocator, Struct.shutdown_module) catch return false; + shutdownModuleNames.append(allocator, feature) catch return false; } + } + } - shutdownList.append(allocator, Struct.shutdown_module) catch return false; - shutdownModuleNames.append(allocator, feature) catch return false; - - core.engine_logs("module started >>>> " ++ feature ++ " <<<<"); + core.setShutdownModule(shutdown_module); + } else { + inline for (backlog.moduleList) |feature| { + if (@hasDecl(backlog, feature)) { + core.engine_log("reloading module: {s}", .{feature}); } } } - core.setShutdownModule(shutdown_module); - return true; } diff --git a/engine/platform/src/platform.zig b/engine/platform/src/platform.zig index 5bf018b..32dc90b 100644 --- a/engine/platform/src/platform.zig +++ b/engine/platform/src/platform.zig @@ -89,7 +89,7 @@ pub fn start_module(spec: *core.SpecVariantMap, args: anytype, allocator: std.me return; } - core.getModuleLoader().watchInitializeFn = watchModules; + // core.getModuleLoader().watchInitializeFn = watchModules; const parameters = windowing.PlatformParams.init(); diff --git a/lib/packer/src/packerfs.zig b/lib/packer/src/packerfs.zig index fc96657..e7589fe 100644 --- a/lib/packer/src/packerfs.zig +++ b/lib/packer/src/packerfs.zig @@ -166,14 +166,15 @@ pub const PackerFS = struct { const self: *@This() = @ptrCast(@alignCast(ctx)); for (self.fileWatchCallbacks.items) |*watch| { - // std.debug.print("checking {s} {s}\n", .{ watch.path, path }); + std.debug.print("checking {s} {s}\n", .{ watch.path, path }); if (std.mem.eql(u8, watch.path, std.mem.span(path))) { watch.call(std.mem.span(path)); } - // std.debug.print("registered callback: {s}\n", .{watch.path}); + std.debug.print("registered callback: {s}\n", .{watch.path}); } for (self.anyWatchCallbacks.items) |*watch| { + // std.debug.print("anywatch callback: {s}\n", .{watch.path}); watch.call(std.mem.span(path)); } }