diff --git a/build/program.zig b/build/program.zig index 3bb7595..f340486 100644 --- a/build/program.zig +++ b/build/program.zig @@ -54,6 +54,16 @@ pub const Program = struct { exe.root_module.addImport("trampoline", trampoline); exe.root_module.addOptions("BacklogOptions", self.buildSystem.options); + { + const runArtifact = b.addRunArtifact(exe); + if (b.args) |args| { + runArtifact.addArgs(args); + } + + const run_exe = b.step(b.fmt("run-{s}", .{self.name}), "runs the program"); + run_exe.dependOn(&runArtifact.step); + } + // link core // 2. create the actual library that the loader will try to load diff --git a/engine/core/api/coreApi.zig b/engine/core/api/coreApi.zig new file mode 100644 index 0000000..dea005c --- /dev/null +++ b/engine/core/api/coreApi.zig @@ -0,0 +1,7 @@ +pub const std = @import("std"); +const core = @import("core"); +const impl = core; + +pub const inputs = struct { + pub const getInputStack = inputs.getInputStack; +}; diff --git a/engine/main2.zig b/engine/main2.zig index 829b39d..834c1a4 100644 --- a/engine/main2.zig +++ b/engine/main2.zig @@ -4,12 +4,12 @@ const panickers = core.panickers; // const realMain = @import("main"); +// pub const gametree = @import("gametree"); + pub const trampoline = @import("trampoline"); - pub const options = @import("BacklogOptions"); - pub const std_options = std.Options{ - .enable_segfault_handler = false, + .enable_segfault_handler = true, }; //pub const build_options = @import("build_options"); @@ -21,11 +21,107 @@ pub const std_options = std.Options{ // std.debug.defaultPanic(error_return_trace, x, msg); // } +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; +} + fn fileExists(path: []const u8) bool { std.fs.cwd().access(path, .{}) catch return false; return true; } +// this should be provided by gametree, +pub fn getSpec(comptime name: []const u8) !*core.SpecVariantMap { + const spec = try std.heap.smp_allocator.create(core.SpecVariantMap); + spec.* = try core.createSpecVariant(.{ + .useGPA = true, + .name = name, + // placeholder module list. + .core = true, + .platform = true, + .assets = true, + }, std.heap.smp_allocator); + + return spec; +} + +pub fn run() !void { + 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 startEngine(spec: *core.SpecVariantMap) bool { + const args = getArgs() catch return false; + + var backingAllocator: std.mem.Allocator = std.heap.smp_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(); + + _ = core.createNameRegistry(allocator) catch return false; + core.maybeInitPackerFs(allocator) catch return false; + + if (core.BuildOption("static_build")) { + core.engine_log("static build, using embedded shaders", .{}); + // const loader = @import("staticShaderLoader"); + // loader.installStaticResources() catch return false; + } + + core.start_module(spec, args, allocator) catch return false; + + const programName = spec.get("name").?.string; + + core.loadModule(programName, true) catch return false; + + // load the shared object and call startup() + // core.beginLoading(""); + + // if (!start_modules(spec, args, allocator)) return false; + // defer shutdown_modules(allocator); + + run() catch return false; + + core.shutdown_module(allocator); + + return true; +} + pub fn main() !void { if (!core.BuildOption("RootDeploymentOnly")) { // if we don't see a content/ folder or a @@ -48,7 +144,9 @@ pub fn main() !void { core.engine_log("Working Dir set: {s}", .{try std.fs.cwd().realpath(".", &BUFFER)}); } - trampoline.launch(); + const spec = try getSpec("sampleGame"); + _ = startEngine(spec); + // panickers.attachSegfaultHandler(); // try realMain.main(); } diff --git a/engine/modulelaunch.zig b/engine/modulelaunch.zig new file mode 100644 index 0000000..e69de29 diff --git a/engine/trampoline.zig b/engine/trampoline.zig new file mode 100644 index 0000000..9d823fd --- /dev/null +++ b/engine/trampoline.zig @@ -0,0 +1,9 @@ +const core = @import("core"); + +const modules = @import("modtree"); + +pub fn launch() void {} + +pub fn shutdown() void {} + +pub fn loadModule() void {} diff --git a/todo.txt b/todo.txt index 435ec56..11ac402 100644 --- a/todo.txt +++ b/todo.txt @@ -1,7 +1,7 @@ -I think before i can do anything else -I need to clean up build.zig -engineDepList should be discovered from the filesystem +What is thisthis +this is going to be an exercise in craftsmanship + +1. start with a simple main program that starts the core's loop. -many functions should be moved into build/ scripts