more work on variant engine
This commit is contained in:
parent
3648615829
commit
b248573930
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
106
engine/main2.zig
106
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
const core = @import("core");
|
||||
|
||||
const modules = @import("modtree");
|
||||
|
||||
pub fn launch() void {}
|
||||
|
||||
pub fn shutdown() void {}
|
||||
|
||||
pub fn loadModule() void {}
|
||||
8
todo.txt
8
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue