Backlog/engine/modulelaunch.zig

79 lines
2.5 KiB
Zig

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;
}
var shutdownList: std.ArrayListUnmanaged(*const fn (std.mem.Allocator) void) = .{};
var shutdownModuleNames: std.ArrayListUnmanaged([]const u8) = .{};
var gAllocator: std.mem.Allocator = undefined;
pub export fn startup_module(p_allocator: *anyopaque, p_a: ?*anyopaque) bool {
const allocator = core.modulePreamble(p_allocator, p_a) catch return false;
gAllocator = allocator;
core.engine_log("module started {s}", .{backlog.moduleName});
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;
if (core.MemoryTracker.MTGet()) |_| {
core.MemoryTracker.MTPrintStatsDelta();
}
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);
return true;
}
pub export fn shutdown_module() void {
var i: usize = shutdownList.items.len;
while (i > 0) {
const j = i - 1;
shutdownList.items[j](gAllocator);
i -= 1;
}
shutdownList.deinit(gAllocator);
shutdownModuleNames.deinit(gAllocator);
core.shutdown_module(gAllocator);
}
const gamespec = @import("gamespec");
const backlog = @import("backlog");
const core = backlog.core;
const std = @import("std");