module forwarding optionals and apigen
This commit is contained in:
parent
4d57518bc0
commit
67883be7fb
160
build.zig
160
build.zig
|
|
@ -16,6 +16,9 @@ reflectShaderPathList: [][]u8 = undefined,
|
||||||
|
|
||||||
staticBuild: bool = false,
|
staticBuild: bool = false,
|
||||||
|
|
||||||
|
nwdep: *std.Build.Dependency,
|
||||||
|
apigen: *std.Build.Step.Compile,
|
||||||
|
|
||||||
const engineDepList = [_][]const u8{
|
const engineDepList = [_][]const u8{
|
||||||
"assets",
|
"assets",
|
||||||
"audio",
|
"audio",
|
||||||
|
|
@ -59,7 +62,7 @@ pub fn init(b: *std.Build, opts: InitOptions) BuildSystem {
|
||||||
.static_build = buildOpts.static_build,
|
.static_build = buildOpts.static_build,
|
||||||
});
|
});
|
||||||
|
|
||||||
const self = BuildSystem{
|
var self = BuildSystem{
|
||||||
.b = b,
|
.b = b,
|
||||||
.nw_builder = nwdep.builder,
|
.nw_builder = nwdep.builder,
|
||||||
.target = opts.target,
|
.target = opts.target,
|
||||||
|
|
@ -72,6 +75,8 @@ pub fn init(b: *std.Build, opts: InitOptions) BuildSystem {
|
||||||
.cookShaders = b.option(bool, "cookShaders", "generates shaders and updates .json files before running the build. (needs to be done whenever shaders are updated, this just runs tools/scripts/cook-shaders.py)") orelse false,
|
.cookShaders = b.option(bool, "cookShaders", "generates shaders and updates .json files before running the build. (needs to be done whenever shaders are updated, this just runs tools/scripts/cook-shaders.py)") orelse false,
|
||||||
|
|
||||||
.staticBuild = buildOpts.static_build,
|
.staticBuild = buildOpts.static_build,
|
||||||
|
.nwdep = nwdep,
|
||||||
|
.apigen = nwdep.artifact("backlog-apigen"),
|
||||||
};
|
};
|
||||||
|
|
||||||
const exeList = [2]*std.Build.Step.Compile{ self.gltf2ozz.exe, self.spirvReflect.reflect };
|
const exeList = [2]*std.Build.Step.Compile{ self.gltf2ozz.exe, self.spirvReflect.reflect };
|
||||||
|
|
@ -104,6 +109,8 @@ pub fn init(b: *std.Build, opts: InitOptions) BuildSystem {
|
||||||
run_exe.dependOn(&runArtifact.step);
|
run_exe.dependOn(&runArtifact.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.addDependencyInstalls(self.b, .ReleaseFast);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,7 +119,6 @@ pub const AddProgramOptions = struct {
|
||||||
desc: []const u8,
|
desc: []const u8,
|
||||||
root_source_file: LazyPath,
|
root_source_file: LazyPath,
|
||||||
imports: []const Build.Module.Import = &.{},
|
imports: []const Build.Module.Import = &.{},
|
||||||
staticBuild: bool = false, // ugh.... why is this so hard...
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn addProgram(self: *BuildSystem, opts: AddProgramOptions) *std.Build.Module {
|
pub fn addProgram(self: *BuildSystem, opts: AddProgramOptions) *std.Build.Module {
|
||||||
|
|
@ -223,19 +229,21 @@ pub fn addDependencyInstalls(self: *BuildSystem, b: *std.Build, optimize: std.bu
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline for (cDependencyList) |d| {
|
inline for (DynamicDepList) |d| {
|
||||||
b.installArtifact(b.dependency(
|
b.installArtifact(b.dependency(
|
||||||
d.dep,
|
d.dep,
|
||||||
.{ .target = self.target, .optimize = optimize, .static_build = self.staticBuild },
|
.{ .target = self.target, .optimize = optimize, .static_build = self.staticBuild },
|
||||||
).artifact(d.artifact));
|
).artifact(d.artifact));
|
||||||
}
|
}
|
||||||
b.installArtifact(b.dependency(
|
|
||||||
"sdl3_lib",
|
// b.installArtifact(b.dependency(
|
||||||
.{ .target = self.target, .optimize = optimize, .static_build = self.staticBuild, .preferred_linkage = .dynamic },
|
// "sdl3",
|
||||||
).artifact("SDL3"));
|
// .{ .target = self.target, .optimize = optimize, .static_build = self.staticBuild },
|
||||||
|
// ).artifact("SDL3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
const cDependencyList: []const struct { dep: []const u8, artifact: []const u8 } = &.{
|
const DynamicDepList: []const struct { dep: []const u8, artifact: []const u8 } = &.{
|
||||||
|
.{ .dep = "sdl3", .artifact = "SDL3" },
|
||||||
.{ .dep = "spng", .artifact = "spng_c" },
|
.{ .dep = "spng", .artifact = "spng_c" },
|
||||||
.{ .dep = "lua", .artifact = "luac" },
|
.{ .dep = "lua", .artifact = "luac" },
|
||||||
.{ .dep = "miniaudio", .artifact = "miniaudio_c" },
|
.{ .dep = "miniaudio", .artifact = "miniaudio_c" },
|
||||||
|
|
@ -243,8 +251,87 @@ const cDependencyList: []const struct { dep: []const u8, artifact: []const u8 }
|
||||||
.{ .dep = "ozz", .artifact = "ozz_cpp" },
|
.{ .dep = "ozz", .artifact = "ozz_cpp" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// all other modules are disabled by default
|
||||||
|
pub const defaultEnabledModules: []const []const u8 = &.{
|
||||||
|
"core",
|
||||||
|
"assets",
|
||||||
|
"platform",
|
||||||
|
"rend",
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const moduleOrder: []const []const u8 = &.{
|
||||||
|
"core",
|
||||||
|
"assets",
|
||||||
|
"platform",
|
||||||
|
"physics",
|
||||||
|
"audio",
|
||||||
|
"rend",
|
||||||
|
"imgui",
|
||||||
|
"papyrus",
|
||||||
|
"ui",
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const GameModule = struct {
|
||||||
|
name: []const u8,
|
||||||
|
enabled: bool = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const Program = struct {
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
|
opts: AddProgramOptions,
|
||||||
|
gameModules: std.ArrayListUnmanaged(GameModule) = .{},
|
||||||
|
buildSystem: *BuildSystem,
|
||||||
|
|
||||||
|
pub fn setModuleEnabled(self: *@This(), module: []const u8, enable: bool) void {
|
||||||
|
for (self.gameModules.items) |*m| {
|
||||||
|
if (std.mem.eql(u8, m.name, module)) {
|
||||||
|
m.enabled = enable;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// module not found, add it here.
|
||||||
|
self.gameModules.append(self.allocator, .{ .name = module, .enabled = enable }) catch unreachable;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn compileInstall(self: *@This()) *std.Build.Module {
|
||||||
|
const exe = self.buildSystem.addProgram(self.opts);
|
||||||
|
var modlist = std.ArrayList([]const u8).init(self.buildSystem.b.allocator);
|
||||||
|
|
||||||
|
for (self.gameModules.items) |mod| {
|
||||||
|
if (mod.enabled) {
|
||||||
|
modlist.append(mod.name) catch unreachable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exe.addImport("backlog", self.buildSystem.generateApi(self.opts.name, modlist.items));
|
||||||
|
|
||||||
|
return exe;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn program(self: *BuildSystem, opts: AddProgramOptions) *Program {
|
||||||
|
const prog = self.b.allocator.create(Program) catch unreachable;
|
||||||
|
|
||||||
|
prog.* = .{
|
||||||
|
.allocator = self.b.allocator,
|
||||||
|
.opts = opts,
|
||||||
|
.buildSystem = self,
|
||||||
|
};
|
||||||
|
|
||||||
|
for (moduleOrder) |module| {
|
||||||
|
prog.setModuleEnabled(module, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (defaultEnabledModules) |module| {
|
||||||
|
prog.setModuleEnabled(module, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return prog;
|
||||||
|
}
|
||||||
|
|
||||||
// ========= standalone build instance =======
|
// ========= standalone build instance =======
|
||||||
// maybe it should be an engine launcher or something..
|
// maybe the default should be like an engine launcher/project launcher or something
|
||||||
pub fn build(b: *std.Build) void {
|
pub fn build(b: *std.Build) void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
@ -257,6 +344,22 @@ pub fn build(b: *std.Build) void {
|
||||||
});
|
});
|
||||||
_ = spirvDep;
|
_ = spirvDep;
|
||||||
|
|
||||||
|
const fwdGeneratorExe = b.addExecutable(.{
|
||||||
|
.name = "backlog-generate-fwd",
|
||||||
|
.target = b.graph.host,
|
||||||
|
.optimize = .Debug,
|
||||||
|
.root_source_file = b.path("build/generateFwd.zig"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const generateExe = b.addExecutable(.{
|
||||||
|
.name = "backlog-apigen",
|
||||||
|
.target = b.graph.host,
|
||||||
|
.optimize = .Debug,
|
||||||
|
.root_source_file = b.path("build/generateApi.zig"),
|
||||||
|
});
|
||||||
|
|
||||||
|
b.installArtifact(generateExe);
|
||||||
|
|
||||||
{
|
{
|
||||||
const mod = b.addModule("Backlog", .{
|
const mod = b.addModule("Backlog", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
|
|
@ -273,19 +376,52 @@ pub fn build(b: *std.Build) void {
|
||||||
.static_build = static_build,
|
.static_build = static_build,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
mod.addImport(depName, dep.module(depName));
|
|
||||||
|
const run = b.addRunArtifact(fwdGeneratorExe);
|
||||||
|
const output = run.addOutputFileArg(b.fmt("{s}_fwd.zig", .{depName}));
|
||||||
|
|
||||||
|
const modFwd = b.addModule(depName, .{
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
.root_source_file = output,
|
||||||
|
});
|
||||||
|
|
||||||
|
mod.addImport(b.fmt("{s}", .{depName}), modFwd);
|
||||||
|
modFwd.addImport("module", dep.module(depName));
|
||||||
|
|
||||||
|
// mod.addImport(depName, dep.module(depName));
|
||||||
}
|
}
|
||||||
|
|
||||||
// link in large platform support functions
|
// link in large platform support functions... special case.
|
||||||
{
|
{
|
||||||
const dep = b.dependency("sdl3", .{
|
const dep = b.dependency("sdl3", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.static_build = static_build,
|
.static_build = static_build,
|
||||||
});
|
});
|
||||||
const lib = dep.module("sdl3_lib");
|
const lib = dep.module("SDL3");
|
||||||
|
|
||||||
mod.addImport("sdl3_fwd", lib);
|
mod.addImport("sdl3_fwd", lib);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn generateApi(self: *@This(), programName: []const u8, moduleList: []const []const u8) *std.Build.Module {
|
||||||
|
const run = self.b.addRunArtifact(self.apigen);
|
||||||
|
const pfile = self.b.fmt("{s}Api.zig", .{programName});
|
||||||
|
const output = run.addOutputFileArg(pfile);
|
||||||
|
for (moduleList) |modName| {
|
||||||
|
run.addArg(modName);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mod = self.b.addModule(pfile, .{
|
||||||
|
.target = self.target,
|
||||||
|
.optimize = self.optimize,
|
||||||
|
.root_source_file = output,
|
||||||
|
});
|
||||||
|
for (moduleList) |modName| {
|
||||||
|
mod.addImport(modName, self.nwdep.module(modName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return mod;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
.zphysics = .{ .path = "lib/zphysics" },
|
.zphysics = .{ .path = "lib/zphysics" },
|
||||||
|
|
||||||
.sdl3 = .{ .path = "lib/sdl3" },
|
.sdl3 = .{ .path = "lib/sdl3" },
|
||||||
.sdl3_lib = .{ .path = "lib/sdl3/SDL" },
|
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
"",
|
"",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,167 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||||
|
defer arena.deinit();
|
||||||
|
const allocator = arena.allocator();
|
||||||
|
|
||||||
|
// Get output filename from build system
|
||||||
|
const args = try std.process.argsAlloc(allocator);
|
||||||
|
if (args.len < 3) @panic("Missing output filename");
|
||||||
|
const out_path = args[1];
|
||||||
|
|
||||||
|
// Generate a startup module function that invokes
|
||||||
|
// startup module for each zig function
|
||||||
|
// and generates an api
|
||||||
|
var content = std.ArrayList(u8).init(allocator);
|
||||||
|
var writer = content.writer();
|
||||||
|
const moduleList = args[2..];
|
||||||
|
|
||||||
|
for (moduleList) |mod| {
|
||||||
|
try writer.print("pub const {s} = @import(\"{s}\").module;\n", .{ mod, mod });
|
||||||
|
}
|
||||||
|
|
||||||
|
try writer.print("pub const moduleList:[]const []const u8 = &.{{\n", .{});
|
||||||
|
for (moduleList) |mod| {
|
||||||
|
try writer.print("\"{s}\",\n", .{mod});
|
||||||
|
}
|
||||||
|
try writer.print("}};\n", .{});
|
||||||
|
|
||||||
|
try writer.print(
|
||||||
|
\\var shutdownList: std.ArrayListUnmanaged(*const fn (std.mem.Allocator) void) = .{{}};
|
||||||
|
\\var shutdownModuleNames: std.ArrayListUnmanaged([]const u8) = .{{}};
|
||||||
|
\\
|
||||||
|
\\ pub const NwArgs = struct {{
|
||||||
|
\\ useGPA: bool = false, // slower zig based memory allocator, provides detailed tracking of leaks and memory violations
|
||||||
|
\\ vulkanValidation: bool = true,
|
||||||
|
\\ fastTest: bool = false,
|
||||||
|
\\ dmt: bool = false, // detailed memory tracking, implements a timeline for tracking all memory allocations
|
||||||
|
\\ fatDump: bool = false, // takes a full fat minidump on crash, very large files are produced
|
||||||
|
\\ }};
|
||||||
|
\\
|
||||||
|
\\ pub fn getArgs() !NwArgs {{
|
||||||
|
\\ const a = try core.ParseArgs(NwArgs);
|
||||||
|
\\
|
||||||
|
\\ return a;
|
||||||
|
\\ }}
|
||||||
|
, .{});
|
||||||
|
try writer.print("pub fn start_modules_(spec: *core.SpecVariantMap, maybeArgs: ?NwArgs, allocator: std.mem.Allocator) !void {{", .{});
|
||||||
|
|
||||||
|
try writer.print(
|
||||||
|
\\
|
||||||
|
\\ var z = core.tracy.ZoneN(@src(), "Starting all Modules");
|
||||||
|
\\ defer z.End();
|
||||||
|
\\ inline for (moduleList) |feature| {{
|
||||||
|
\\ if (@hasDecl(@This(), feature)) {{
|
||||||
|
\\ const Struct = @field(@This(), 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);
|
||||||
|
\\ if (maybeArgs) |args| {{
|
||||||
|
\\ try Struct.start_module(spec, args, allocator);
|
||||||
|
\\ }} else {{
|
||||||
|
\\ try Struct.start_module(spec, NwArgs{{}}, allocator);
|
||||||
|
\\ }}
|
||||||
|
\\ try shutdownList.append(allocator, Struct.shutdown_module);
|
||||||
|
\\ try shutdownModuleNames.append(allocator, feature);
|
||||||
|
\\ core.engine_logs("module started >>>> " ++ feature ++ " <<<<");
|
||||||
|
\\ }}
|
||||||
|
\\ }}
|
||||||
|
\\ }} }}
|
||||||
|
\\pub fn start_modules(spec: *core.SpecVariantMap, maybeArgs: ?NwArgs, allocator: std.mem.Allocator) bool {{ start_modules_(spec, maybeArgs, allocator) catch return false; return true;}}
|
||||||
|
\\
|
||||||
|
\\ pub fn shutdown_modules(allocator: std.mem.Allocator) void {{
|
||||||
|
\\ var i: isize = @intCast(shutdownList.items.len - 1);
|
||||||
|
\\ while (i >= 0) : (i -= 1) {{
|
||||||
|
\\ core.engine_log("module shutting down >>>> {{s}} <<<<", .{{shutdownModuleNames.items[@intCast(i)]}});
|
||||||
|
\\ shutdownList.items[@intCast(i)](allocator);
|
||||||
|
\\ }}
|
||||||
|
\\ shutdownList.deinit(allocator);
|
||||||
|
\\ shutdownModuleNames.deinit(allocator);
|
||||||
|
\\ }}
|
||||||
|
\\
|
||||||
|
, .{});
|
||||||
|
|
||||||
|
_ = try writer.write(
|
||||||
|
\\ pub fn startEngine(vtable: *core.EngineObjectVTable, spec: *core.SpecVariantMap) bool {
|
||||||
|
\\ const args = getArgs() catch return false;
|
||||||
|
\\
|
||||||
|
\\ var backingAllocator: std.mem.Allocator = std.heap.c_allocator;
|
||||||
|
\\ var gpa: std.heap.GeneralPurposeAllocator(.{
|
||||||
|
\\ .stack_trace_frames = 20,
|
||||||
|
\\ }) = .{};
|
||||||
|
\\
|
||||||
|
\\ defer {
|
||||||
|
\\ const cleanupStatus = gpa.deinit();
|
||||||
|
\\ if (cleanupStatus == .leak) {
|
||||||
|
\\ std.debug.print("gpa cleanup leaked memory\n", .{});
|
||||||
|
\\ }
|
||||||
|
\\ }
|
||||||
|
\\
|
||||||
|
\\ if (spec.get("useGPA")) |arg| {
|
||||||
|
\\ if (arg.boolean == true) {
|
||||||
|
\\ backingAllocator = gpa.allocator();
|
||||||
|
\\ }
|
||||||
|
\\ }
|
||||||
|
\\
|
||||||
|
\\ const memory = core.MemoryTracker;
|
||||||
|
\\ memory.MTSetup(backingAllocator, .{ .timeline = args.dmt });
|
||||||
|
\\ defer memory.MTShutdown();
|
||||||
|
\\
|
||||||
|
\\ var tracker = memory.MTGet().?;
|
||||||
|
\\ const allocator = tracker.allocator();
|
||||||
|
\\
|
||||||
|
\\ if (!start_modules(spec, args, allocator)) return false;
|
||||||
|
\\ defer shutdown_modules(allocator);
|
||||||
|
\\
|
||||||
|
\\ run_everything_vtable(vtable) catch return false;
|
||||||
|
\\
|
||||||
|
\\ return true;
|
||||||
|
\\ }
|
||||||
|
\\
|
||||||
|
\\
|
||||||
|
\\ pub fn run_everything_vtable(gameVtable: *core.EngineObjectVTable) !void {
|
||||||
|
\\ core.engine_logs("creating Game context");
|
||||||
|
\\
|
||||||
|
\\ //_ = try core.createObject(GameContext, .{});
|
||||||
|
\\ _ = try core.createObjectVTable(gameVtable, .{});
|
||||||
|
\\
|
||||||
|
\\ core.engine_logs("calling gEngine.run");
|
||||||
|
\\
|
||||||
|
\\ try core.getEngine().run();
|
||||||
|
\\
|
||||||
|
\\ while (!core.getEngine().exitFinished()) {
|
||||||
|
\\ const z = core.tracy.ZoneN(@src(), "shutdown poll");
|
||||||
|
\\ z.End();
|
||||||
|
\\ }
|
||||||
|
\\ }
|
||||||
|
\\
|
||||||
|
\\ pub fn getSpec(comptime name:[]const u8) !core.SpecVariantMap {
|
||||||
|
\\ return try core.createSpecVariant(.{
|
||||||
|
\\ .name = name,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (moduleList) |mod| {
|
||||||
|
try writer.print(".{s} = true,\n", .{mod});
|
||||||
|
}
|
||||||
|
|
||||||
|
try writer.print("}}, std.heap.c_allocator); }}\n", .{});
|
||||||
|
|
||||||
|
try writer.print("const std = @import(\"std\");\n", .{});
|
||||||
|
|
||||||
|
// Write to specified output file
|
||||||
|
// Open or create the file for writing (overwrites if it exists)
|
||||||
|
const file = try std.fs.cwd().createFile(out_path, .{});
|
||||||
|
defer file.close();
|
||||||
|
|
||||||
|
try content.append(0);
|
||||||
|
|
||||||
|
var ast = try std.zig.Ast.parse(allocator, @as([:0]const u8, @ptrCast(content.items[0 .. content.items.len - 1])), .zig);
|
||||||
|
std.debug.print("output={s}", .{content.items[0 .. content.items.len - 1]});
|
||||||
|
defer ast.deinit(allocator);
|
||||||
|
const out = try ast.render(allocator);
|
||||||
|
|
||||||
|
// Write the content to the file
|
||||||
|
try file.writeAll(out);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||||
|
defer arena.deinit();
|
||||||
|
const allocator = arena.allocator();
|
||||||
|
|
||||||
|
// Get output filename from build system
|
||||||
|
const args = try std.process.argsAlloc(allocator);
|
||||||
|
if (args.len < 2) @panic("Missing output filename");
|
||||||
|
const out_path = args[1];
|
||||||
|
|
||||||
|
// Generate Zig code content
|
||||||
|
const content =
|
||||||
|
\\pub const module = @import("module");
|
||||||
|
;
|
||||||
|
|
||||||
|
// Write to specified output file
|
||||||
|
// Open or create the file for writing (overwrites if it exists)
|
||||||
|
const file = try std.fs.cwd().createFile(out_path, .{});
|
||||||
|
defer file.close();
|
||||||
|
|
||||||
|
// Write the content to the file
|
||||||
|
try file.writeAll(content);
|
||||||
|
}
|
||||||
Binary file not shown.
|
|
@ -1,14 +1,22 @@
|
||||||
pub const core = @import("core");
|
//pub const core = @import("core");
|
||||||
pub const platform = @import("platform");
|
//pub const platform = @import("platform");
|
||||||
pub const assets = @import("assets");
|
//pub const assets = @import("assets");
|
||||||
pub const rend = @import("rend");
|
//pub const rend = @import("rend");
|
||||||
pub const audio = @import("audio");
|
//pub const audio = @import("audio");
|
||||||
// pub const graphics = @import("graphics");
|
//pub const ui = @import("ui");
|
||||||
// pub const vkImgui = @import("vkImgui");
|
//pub const papyrus = @import("papyrus");
|
||||||
pub const ui = @import("ui");
|
//pub const physics = @import("physics");
|
||||||
pub const papyrus = @import("papyrus");
|
//pub const imgui = @import("imgui");
|
||||||
pub const physics = @import("physics");
|
|
||||||
pub const imgui = @import("imgui");
|
pub const core = @import("core").module;
|
||||||
|
pub const platform = @import("platform").module;
|
||||||
|
pub const assets = @import("assets").module;
|
||||||
|
pub const rend = @import("rend").module;
|
||||||
|
pub const audio = @import("audio").module;
|
||||||
|
pub const ui = @import("ui").module;
|
||||||
|
pub const papyrus = @import("papyrus").module;
|
||||||
|
pub const physics = @import("physics").module;
|
||||||
|
pub const imgui = @import("imgui").module;
|
||||||
|
|
||||||
const modulelist = @import("modulelist.zig").list;
|
const modulelist = @import("modulelist.zig").list;
|
||||||
|
|
||||||
|
|
@ -62,6 +70,30 @@ pub fn start_modules(spec: *core.SpecVariantMap, maybeArgs: ?NwArgs, allocator:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const ModuleStartup = struct {
|
||||||
|
name: []const u8,
|
||||||
|
startupFunc: *const fn (map: *core.SpecVariantMap, args: anytype, allocator: std.mem.Allocator) core.ModuleStartupError!void,
|
||||||
|
shutdownFunc: *const fn (*const fn (std.mem.Allocator) void) void,
|
||||||
|
};
|
||||||
|
|
||||||
|
// read moduleList from root
|
||||||
|
pub fn start_modules_list(list: []const ModuleStartup, spec: *core.SpecVariantMap, maybeArgs: ?NwArgs, allocator: std.mem.Allocator) !void {
|
||||||
|
var z = core.tracy.ZoneN(@src(), "Starting all Modules");
|
||||||
|
defer z.End();
|
||||||
|
|
||||||
|
for (list) |feature| {
|
||||||
|
//if (@hasDecl(Backlog, feature)) {
|
||||||
|
core.engine_logs("starting module >> {s}", .{feature.name});
|
||||||
|
|
||||||
|
try feature.startupFunc(spec, maybeArgs orelse NwArgs{}, allocator);
|
||||||
|
try shutdownList.append(allocator, feature.shutdownFunc);
|
||||||
|
try shutdownModuleNames.append(allocator, feature.name);
|
||||||
|
|
||||||
|
core.engine_logs("module started {s}! ", .{feature.name});
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn shutdown_modules(allocator: std.mem.Allocator) void {
|
pub fn shutdown_modules(allocator: std.mem.Allocator) void {
|
||||||
var i: isize = @intCast(shutdownList.items.len - 1);
|
var i: isize = @intCast(shutdownList.items.len - 1);
|
||||||
while (i >= 0) : (i -= 1) {
|
while (i >= 0) : (i -= 1) {
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,13 @@ pub const ComponentList = struct {
|
||||||
pub const Scene = scene.Scene;
|
pub const Scene = scene.Scene;
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn start_module(map: *SpecVariantMap, args: anytype, allocator: std.mem.Allocator) !void {
|
pub const ModuleStartupError = error{StartupFailed};
|
||||||
|
|
||||||
|
pub fn start_module(map: *SpecVariantMap, args: anytype, allocator: std.mem.Allocator) ModuleStartupError!void {
|
||||||
|
start_module_(map, args, allocator) catch return error.StartupFailed;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn start_module_(map: *SpecVariantMap, args: anytype, allocator: std.mem.Allocator) !void {
|
||||||
staticsInitialized = true;
|
staticsInitialized = true;
|
||||||
|
|
||||||
if (map.get("utility")) |x| {
|
if (map.get("utility")) |x| {
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ pub const ModuleLoader = struct {
|
||||||
pub fn addModule(self: *@This(), moduleName: []const u8) !void {
|
pub fn addModule(self: *@This(), moduleName: []const u8) !void {
|
||||||
// modules are always looked for under zig-out/modules
|
// modules are always looked for under zig-out/modules
|
||||||
if (core.BuildOption("static_build")) {
|
if (core.BuildOption("static_build")) {
|
||||||
core.engine_log("[ModuleLoader]: skipping dynamic load, hot loading is not available", .{moduleName});
|
core.engine_log("[ModuleLoader]: skipping dynamic load, hot loading is not available", .{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
pub const module = @import("module");
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
pub const SpecVariantMap = std.StringHashMap(SpecVariant);
|
||||||
|
|
||||||
|
pub const SpecVariant = union(enum(u8)) {
|
||||||
|
boolean: bool,
|
||||||
|
string: []const u8,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn start_module(map: *SpecVariantMap, args: anytype, allocator: std.mem.Allocator) !void {
|
||||||
|
_ = map;
|
||||||
|
_ = args;
|
||||||
|
_ = allocator;
|
||||||
|
|
||||||
|
std.debug.print("Module init stub. this should never be called");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn shutdown_module(_: std.mem.Allocator) void {}
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
|
|
@ -3,6 +3,7 @@ const std = @import("std");
|
||||||
pub fn build(b: *std.Build) void {
|
pub fn build(b: *std.Build) void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
|
||||||
|
|
||||||
const mod = b.addModule("bsp", .{
|
const mod = b.addModule("bsp", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
|
|
@ -11,7 +12,7 @@ pub fn build(b: *std.Build) void {
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize });
|
const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize, .static_build = static_build });
|
||||||
mod.addImport("Backlog", dep.module("Backlog"));
|
mod.addImport("Backlog", dep.module("Backlog"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ const std = @import("std");
|
||||||
pub fn build(b: *std.Build) void {
|
pub fn build(b: *std.Build) void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
|
||||||
|
|
||||||
const mod = b.addModule("doomplayer", .{
|
const mod = b.addModule("doomplayer", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
|
|
@ -19,7 +20,7 @@ pub fn build(b: *std.Build) void {
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize });
|
const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize, .static_build = static_build });
|
||||||
mod.addImport("Backlog", dep.module("Backlog"));
|
mod.addImport("Backlog", dep.module("Backlog"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@ pub fn build(b: *std.Build) void {
|
||||||
.root_source_file = b.path("src/gameExtras.zig"),
|
.root_source_file = b.path("src/gameExtras.zig"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize });
|
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
|
||||||
|
|
||||||
|
const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize, .static_build = static_build });
|
||||||
|
|
||||||
mod.addImport("Backlog", dep.module("Backlog"));
|
mod.addImport("Backlog", dep.module("Backlog"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ const std = @import("std");
|
||||||
pub fn build(b: *std.Build) void {
|
pub fn build(b: *std.Build) void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
const static_build = b.option(bool, "static_build", "builds backlog dependencies for static linking") orelse false;
|
||||||
|
|
||||||
const mod = b.addModule("videoplayer", .{
|
const mod = b.addModule("videoplayer", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
|
|
@ -11,7 +12,7 @@ pub fn build(b: *std.Build) void {
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize });
|
const dep = b.dependency("Backlog", .{ .target = target, .optimize = optimize, .static_build = static_build });
|
||||||
mod.addImport("Backlog", dep.module("Backlog"));
|
mod.addImport("Backlog", dep.module("Backlog"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,8 @@ pub fn build(b: *std.Build) void {
|
||||||
});
|
});
|
||||||
|
|
||||||
const sdl3_lib = sdl_dep.artifact("SDL3");
|
const sdl3_lib = sdl_dep.artifact("SDL3");
|
||||||
const sdl3_fwd = b.addModule("sdl3_lib", .{
|
|
||||||
|
const sdl3_fwd = b.addModule("SDL3", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.root_source_file = b.path("src/sdl3_lib_fwd.zig"),
|
.root_source_file = b.path("src/sdl3_lib_fwd.zig"),
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
.zphysics = .{.path = "../lib/zphysics"},
|
.zphysics = .{.path = "../lib/zphysics"},
|
||||||
.spng = .{ .path = "../lib/spng" },
|
.spng = .{ .path = "../lib/spng" },
|
||||||
.ozz = .{ .path = "../lib/ozz" },
|
.ozz = .{ .path = "../lib/ozz" },
|
||||||
.sdl3_lib = .{ .path = "../lib/sdl3/SDL" },
|
.sdl3 = .{ .path = "../lib/sdl3" },
|
||||||
.miniaudio = .{ .path = "../lib/miniaudio" },
|
.miniaudio = .{ .path = "../lib/miniaudio" },
|
||||||
.lua = .{ .path = "../lib/lua" },
|
.lua = .{ .path = "../lib/lua" },
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,40 @@ pub fn build(b: *std.Build) void {
|
||||||
.backlogRoot = "../",
|
.backlogRoot = "../",
|
||||||
});
|
});
|
||||||
|
|
||||||
_ = blbuild.addProgram(.{
|
// const minimalExe = blbuild.addProgram(.{
|
||||||
|
// .name = "minimal",
|
||||||
|
// .desc = "tool program, no assets",
|
||||||
|
// .root_source_file = b.path("src/main.zig"),
|
||||||
|
// });
|
||||||
|
|
||||||
|
// minimalExe.addImport("backlog_api", blbuild.generateApi("minimal", &.{
|
||||||
|
// "core",
|
||||||
|
// "platform",
|
||||||
|
// "assets",
|
||||||
|
// "audio",
|
||||||
|
// "physics",
|
||||||
|
// "rend",
|
||||||
|
// "imgui",
|
||||||
|
// "ui",
|
||||||
|
// }));
|
||||||
|
|
||||||
|
// // minimalExe.addImport("core", blbuild.nwdep.module("core"));
|
||||||
|
|
||||||
|
// blbuild.addDependencyInstalls(b, .ReleaseFast); //.ReleaseFast);
|
||||||
|
const minimal = blbuild.program(.{
|
||||||
.name = "minimal",
|
.name = "minimal",
|
||||||
.desc = "tool program, no assets",
|
.desc = "simple program built with backlog",
|
||||||
.root_source_file = b.path("src/main.zig"),
|
.root_source_file = b.path("src/main.zig"),
|
||||||
});
|
});
|
||||||
|
|
||||||
blbuild.addDependencyInstalls(b, .ReleaseFast); //.ReleaseFast);
|
//// each one here corresponds to a different module under engine/
|
||||||
|
////
|
||||||
|
//// new build system should make a new 'backlog'
|
||||||
|
//// that doesn't even get these modules linked in
|
||||||
|
//
|
||||||
|
// these are already disabled at the start
|
||||||
|
minimal.setModuleEnabled("imgui", true);
|
||||||
|
|
||||||
|
_ = minimal.compileInstall();
|
||||||
|
////minimal.addExtraModule();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,12 @@
|
||||||
//
|
//
|
||||||
// .. theoretically if this is a static build,
|
// .. theoretically if this is a static build,
|
||||||
.Backlog = .{ .path = "../../" },
|
.Backlog = .{ .path = "../../" },
|
||||||
.SpirvReflect = .{ .path = "../../lib/spirv-reflect-zig" },
|
|
||||||
|
|
||||||
|
.SpirvReflect = .{ .path = "../../lib/spirv-reflect-zig" },
|
||||||
.zphysics = .{.path = "../../lib/zphysics"},
|
.zphysics = .{.path = "../../lib/zphysics"},
|
||||||
.spng = .{ .path = "../../lib/spng" },
|
.spng = .{ .path = "../../lib/spng" },
|
||||||
.ozz = .{ .path = "../../lib/ozz" },
|
.ozz = .{ .path = "../../lib/ozz" },
|
||||||
.sdl3_lib = .{ .path = "../../lib/sdl3/SDL" },
|
.sdl3 = .{ .path = "../../lib/sdl3" },
|
||||||
.miniaudio = .{ .path = "../../lib/miniaudio" },
|
.miniaudio = .{ .path = "../../lib/miniaudio" },
|
||||||
.lua = .{ .path = "../../lib/lua" },
|
.lua = .{ .path = "../../lib/lua" },
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -26,17 +26,12 @@ pub fn deinit(self: *@This()) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() anyerror!void {
|
pub fn main() anyerror!void {
|
||||||
var spec = try bl.createSpecVariant(.{
|
var spec = try api.getSpec("minimal");
|
||||||
.name = "sampleGame",
|
_ = api.startEngine(&NeonObjectTable, &spec);
|
||||||
.imgui = true,
|
|
||||||
.physics = false,
|
|
||||||
.audio = false,
|
|
||||||
}, std.heap.c_allocator);
|
|
||||||
|
|
||||||
_ = bl.initAndRun(&NeonObjectTable, &spec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const bl = @import("Backlog");
|
const api = @import("backlog");
|
||||||
const ig = bl.imgui.api; // imgui api
|
// const bl = @import("Backlog");
|
||||||
const core = bl.core;
|
const ig = api.imgui.api;
|
||||||
|
const core = api.core;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue