saving
This commit is contained in:
parent
550deb0c62
commit
b35d5405cb
189
build.zig
189
build.zig
|
|
@ -19,6 +19,8 @@ staticBuild: bool = false,
|
||||||
nwdep: *std.Build.Dependency,
|
nwdep: *std.Build.Dependency,
|
||||||
apigen: *std.Build.Step.Compile,
|
apigen: *std.Build.Step.Compile,
|
||||||
shaderEmbedGen: *std.Build.Step.Compile,
|
shaderEmbedGen: *std.Build.Step.Compile,
|
||||||
|
loadDynamicsGen: *std.Build.Step.Compile,
|
||||||
|
generatedApis: std.StringHashMapUnmanaged(*std.Build.Module) = .{},
|
||||||
|
|
||||||
const engineDepList = [_][]const u8{
|
const engineDepList = [_][]const u8{
|
||||||
"assets",
|
"assets",
|
||||||
|
|
@ -78,6 +80,7 @@ pub fn init(b: *std.Build, opts: InitOptions) BuildSystem {
|
||||||
.staticBuild = buildOpts.static_build,
|
.staticBuild = buildOpts.static_build,
|
||||||
.nwdep = nwdep,
|
.nwdep = nwdep,
|
||||||
.apigen = nwdep.artifact("backlog-apigen"),
|
.apigen = nwdep.artifact("backlog-apigen"),
|
||||||
|
.loadDynamicsGen = nwdep.artifact("backlog-generate-loadDynamics"),
|
||||||
.shaderEmbedGen = nwdep.artifact("backlog-shaderEmbedGen"),
|
.shaderEmbedGen = nwdep.artifact("backlog-shaderEmbedGen"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -150,8 +153,9 @@ pub fn addProgram(self: *BuildSystem, opts: AddProgramOptions) *std.Build.Module
|
||||||
});
|
});
|
||||||
|
|
||||||
exe.root_module.addImport("main", mod);
|
exe.root_module.addImport("main", mod);
|
||||||
exe.root_module.addImport("Backlog", self.nw_mod);
|
// todo.. remove this one and see what happens
|
||||||
mod.addImport("Backlog", self.nw_mod);
|
exe.root_module.addImport("core", self.nwdep.module("core"));
|
||||||
|
// mod.addImport("Backlog", self.nw_mod);
|
||||||
exe.root_module.addOptions("BacklogOptions", self.options);
|
exe.root_module.addOptions("BacklogOptions", self.options);
|
||||||
|
|
||||||
if (self.cookShaders) {
|
if (self.cookShaders) {
|
||||||
|
|
@ -273,6 +277,96 @@ pub const moduleOrder: []const []const u8 = &.{
|
||||||
"ui",
|
"ui",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const DynamicModule = struct {
|
||||||
|
name: []const u8,
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
|
buildSystem: *BuildSystem,
|
||||||
|
programName: []const u8,
|
||||||
|
opts: AddProgramOptions,
|
||||||
|
|
||||||
|
extras: std.ArrayListUnmanaged(GameModule) = .{},
|
||||||
|
gameModules: std.ArrayListUnmanaged(GameModule) = .{},
|
||||||
|
|
||||||
|
library: ?*std.Build.Step.Compile = null,
|
||||||
|
|
||||||
|
pub fn addExtraModule(self: *@This(), module: []const u8) void {
|
||||||
|
self.extras.append(self.allocator, .{ .name = module, .enabled = true }) catch @panic("out of memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(name: []const u8, p: *Program) *@This() {
|
||||||
|
var self: *@This() = p.allocator.create(@This()) catch @panic("out of memory");
|
||||||
|
|
||||||
|
self.* = .{
|
||||||
|
.opts = p.opts,
|
||||||
|
.programName = p.opts.name,
|
||||||
|
.buildSystem = p.buildSystem,
|
||||||
|
.allocator = p.allocator,
|
||||||
|
.name = name,
|
||||||
|
};
|
||||||
|
|
||||||
|
for (p.gameModules.items) |module| {
|
||||||
|
self.gameModules.append(self.allocator, module) catch @panic("out of memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (p.extras.items) |module| {
|
||||||
|
self.extras.append(self.allocator, module) catch @panic("out of memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn compileInstall(self: *@This()) *std.Build.Step.Compile {
|
||||||
|
if (self.library) |lib| {
|
||||||
|
return lib;
|
||||||
|
}
|
||||||
|
|
||||||
|
const b = self.buildSystem.b;
|
||||||
|
const static = self.buildSystem.staticBuild;
|
||||||
|
const shared = if (static)
|
||||||
|
b.addStaticLibrary(.{
|
||||||
|
.root_source_file = self.opts.root_source_file,
|
||||||
|
.link_libc = true,
|
||||||
|
.optimize = self.buildSystem.optimize,
|
||||||
|
.target = self.buildSystem.target,
|
||||||
|
.name = self.name,
|
||||||
|
})
|
||||||
|
else
|
||||||
|
b.addSharedLibrary(.{
|
||||||
|
.root_source_file = self.opts.root_source_file,
|
||||||
|
.link_libc = true,
|
||||||
|
.optimize = self.buildSystem.optimize,
|
||||||
|
.target = self.buildSystem.target,
|
||||||
|
.name = self.name,
|
||||||
|
});
|
||||||
|
|
||||||
|
var modlist = std.ArrayList([]const u8).init(self.buildSystem.b.allocator);
|
||||||
|
|
||||||
|
for (self.gameModules.items) |mod| {
|
||||||
|
if (mod.enabled) {
|
||||||
|
modlist.append(mod.name) catch @panic("out of memory");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (self.extras.items) |extra| {
|
||||||
|
self.buildSystem.addExtraModule(shared.root_module, extra.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
shared.root_module.addImport("backlog", self.buildSystem.generateApi(self.name, modlist.items, null));
|
||||||
|
shared.root_module.addOptions("BacklogOptions", self.buildSystem.options);
|
||||||
|
|
||||||
|
if (static) {
|
||||||
|
// generateApi should create static callers for the main program
|
||||||
|
} else {
|
||||||
|
const installExtern = b.addInstallArtifact(shared, .{
|
||||||
|
.dest_dir = .{ .override = .{ .custom = "modules" } },
|
||||||
|
});
|
||||||
|
b.getInstallStep().dependOn(&installExtern.step);
|
||||||
|
}
|
||||||
|
|
||||||
|
return shared;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
pub const GameModule = struct {
|
pub const GameModule = struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
enabled: bool = true,
|
enabled: bool = true,
|
||||||
|
|
@ -282,6 +376,8 @@ pub const Program = struct {
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
opts: AddProgramOptions,
|
opts: AddProgramOptions,
|
||||||
gameModules: std.ArrayListUnmanaged(GameModule) = .{},
|
gameModules: std.ArrayListUnmanaged(GameModule) = .{},
|
||||||
|
extras: std.ArrayListUnmanaged(GameModule) = .{},
|
||||||
|
dynamicModules: std.ArrayListUnmanaged(*DynamicModule) = .{},
|
||||||
buildSystem: *BuildSystem,
|
buildSystem: *BuildSystem,
|
||||||
|
|
||||||
pub fn setModuleEnabled(self: *@This(), module: []const u8, enable: bool) void {
|
pub fn setModuleEnabled(self: *@This(), module: []const u8, enable: bool) void {
|
||||||
|
|
@ -293,7 +389,19 @@ pub const Program = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// module not found, add it here.
|
// module not found, add it here.
|
||||||
self.gameModules.append(self.allocator, .{ .name = module, .enabled = enable }) catch unreachable;
|
self.gameModules.append(self.allocator, .{ .name = module, .enabled = enable }) catch @panic("out of memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn addExtraModule(self: *@This(), module: []const u8) void {
|
||||||
|
self.extras.append(self.allocator, .{ .name = module, .enabled = true }) catch @panic("out of memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn addDynamicModule(self: *@This(), module: []const u8, root_source_file: std.Build.LazyPath) *DynamicModule {
|
||||||
|
const dynamicModule = DynamicModule.init(module, self);
|
||||||
|
dynamicModule.opts.root_source_file = root_source_file;
|
||||||
|
self.dynamicModules.append(self.allocator, dynamicModule) catch @panic("out of memory");
|
||||||
|
|
||||||
|
return dynamicModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compileInstall(self: *@This()) *std.Build.Module {
|
pub fn compileInstall(self: *@This()) *std.Build.Module {
|
||||||
|
|
@ -302,11 +410,15 @@ pub const Program = struct {
|
||||||
|
|
||||||
for (self.gameModules.items) |mod| {
|
for (self.gameModules.items) |mod| {
|
||||||
if (mod.enabled) {
|
if (mod.enabled) {
|
||||||
modlist.append(mod.name) catch unreachable;
|
modlist.append(mod.name) catch @panic("out of memory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exe.addImport("backlog", self.buildSystem.generateApi(self.opts.name, modlist.items));
|
for (self.extras.items) |extra| {
|
||||||
|
self.buildSystem.addExtraModule(exe, extra.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
exe.addImport("backlog", self.buildSystem.generateApi(self.opts.name, modlist.items, self.dynamicModules.items));
|
||||||
|
|
||||||
return exe;
|
return exe;
|
||||||
}
|
}
|
||||||
|
|
@ -367,10 +479,26 @@ pub fn build(b: *std.Build) void {
|
||||||
.root_source_file = b.path("build/generateEmbeddedShaders.zig"),
|
.root_source_file = b.path("build/generateEmbeddedShaders.zig"),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const generateLoadDynamicsExe = b.addExecutable(.{
|
||||||
|
.name = "backlog-generate-loadDynamics",
|
||||||
|
.target = b.graph.host,
|
||||||
|
.optimize = .Debug,
|
||||||
|
.root_source_file = b.path("build/generateLoadDynamics.zig"),
|
||||||
|
});
|
||||||
|
|
||||||
|
b.installArtifact(generateLoadDynamicsExe);
|
||||||
b.installArtifact(generateExe);
|
b.installArtifact(generateExe);
|
||||||
b.installArtifact(generateShaders);
|
b.installArtifact(generateShaders);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
const loadDynamicsStub = b.addModule("loadDynamicsStub", .{
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
.root_source_file = b.path("engine/loadDynamicsStub.zig"),
|
||||||
|
});
|
||||||
|
|
||||||
|
_ = loadDynamicsStub;
|
||||||
|
|
||||||
const mod = b.addModule("Backlog", .{
|
const mod = b.addModule("Backlog", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
|
|
@ -416,7 +544,12 @@ pub fn build(b: *std.Build) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generateApi(self: *@This(), programName: []const u8, moduleList: []const []const u8) *std.Build.Module {
|
pub fn generateApi(self: *@This(), programName: []const u8, moduleList: []const []const u8, dynamicModules: ?[]const *DynamicModule) *std.Build.Module {
|
||||||
|
std.debug.print("GENERATE API:: {s}\n\n", .{programName});
|
||||||
|
if (self.generatedApis.get(programName)) |m| {
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
const run = self.b.addRunArtifact(self.apigen);
|
const run = self.b.addRunArtifact(self.apigen);
|
||||||
const pfile = self.b.fmt("{s}Api.zig", .{programName});
|
const pfile = self.b.fmt("{s}Api.zig", .{programName});
|
||||||
const output = run.addOutputFileArg(pfile);
|
const output = run.addOutputFileArg(pfile);
|
||||||
|
|
@ -433,14 +566,52 @@ pub fn generateApi(self: *@This(), programName: []const u8, moduleList: []const
|
||||||
mod.addImport(modName, self.nwdep.module(modName));
|
mod.addImport(modName, self.nwdep.module(modName));
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadStatics = self.generateLoadStatics(programName, "content/_shaders") catch unreachable;
|
const loadStatics = self.generateInstallStaticResources(programName, "content/_shaders") catch unreachable;
|
||||||
mod.addImport("staticShaderLoader", loadStatics);
|
mod.addImport("staticShaderLoader", loadStatics);
|
||||||
// load each shader file recursively under content/_shaders
|
|
||||||
|
// deal with dynamics
|
||||||
|
if (dynamicModules) |dynamics| {
|
||||||
|
const loadDynamics = self.generateLoadDynamics(programName, dynamics) catch @panic("unknown");
|
||||||
|
mod.addImport("loadDynamics", loadDynamics);
|
||||||
|
} else {
|
||||||
|
mod.addImport("loadDynamics", self.nwdep.module("loadDynamicsStub"));
|
||||||
|
}
|
||||||
|
|
||||||
|
self.generatedApis.put(self.b.allocator, programName, mod) catch @panic("out of memory");
|
||||||
|
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generateLoadStatics(self: *@This(), programName: []const u8, shadersPath: []const u8) !*std.Build.Module {
|
pub fn generateLoadDynamics(self: *@This(), programName: []const u8, dynamics: []const *DynamicModule) !*std.Build.Module {
|
||||||
|
const run = self.b.addRunArtifact(self.loadDynamicsGen);
|
||||||
|
const pfile = self.b.fmt("{s}LoadDynamics.zig", .{programName});
|
||||||
|
const output = run.addOutputFileArg(pfile);
|
||||||
|
if (self.staticBuild) {
|
||||||
|
run.addArg("static");
|
||||||
|
} else {
|
||||||
|
run.addArg("dynamic");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (dynamics) |dyn| {
|
||||||
|
run.addArg(dyn.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mod = self.b.addModule(pfile, .{
|
||||||
|
.target = self.target,
|
||||||
|
.optimize = self.optimize,
|
||||||
|
.root_source_file = output,
|
||||||
|
});
|
||||||
|
|
||||||
|
mod.addImport("core", self.nwdep.module("core"));
|
||||||
|
for (dynamics) |dyn| {
|
||||||
|
const dynmod = dyn.compileInstall();
|
||||||
|
mod.addImport(dyn.name, dynmod.root_module);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generateInstallStaticResources(self: *@This(), programName: []const u8, shadersPath: []const u8) !*std.Build.Module {
|
||||||
const run = self.b.addRunArtifact(self.shaderEmbedGen);
|
const run = self.b.addRunArtifact(self.shaderEmbedGen);
|
||||||
const pfile = self.b.fmt("{s}ShaderGen.zig", .{programName});
|
const pfile = self.b.fmt("{s}ShaderGen.zig", .{programName});
|
||||||
const output = run.addOutputFileArg(pfile);
|
const output = run.addOutputFileArg(pfile);
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,8 @@ pub fn main() !void {
|
||||||
\\ }
|
\\ }
|
||||||
\\
|
\\
|
||||||
\\
|
\\
|
||||||
|
\\ pub const loadDynamicModules = @import("loadDynamics").loadDynamicModules;
|
||||||
|
\\
|
||||||
\\ pub fn run_everything_vtable(gameVtable: *core.EngineObjectVTable) !void {
|
\\ pub fn run_everything_vtable(gameVtable: *core.EngineObjectVTable) !void {
|
||||||
\\ core.engine_logs("creating Game context");
|
\\ core.engine_logs("creating Game context");
|
||||||
\\
|
\\
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
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("invalid args");
|
||||||
|
const out_path = args[1];
|
||||||
|
const static = std.mem.eql(u8, args[2], "static");
|
||||||
|
const modlist: []const []const u8 = if (args.len > 3) args[3..args.len] else &.{};
|
||||||
|
// exe <outputpath> <static/dynamic> [extern module list ...]
|
||||||
|
|
||||||
|
// 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 content_path = args[2];
|
||||||
|
// std.debug.print("content path: {s}\n", .{content_path});
|
||||||
|
|
||||||
|
// check the content directory and search for all _spv files
|
||||||
|
|
||||||
|
_ = try writer.write(
|
||||||
|
\\ pub const core = @import("core").module;
|
||||||
|
\\
|
||||||
|
\\ pub fn loadDynamicModules() !void {
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!static) {
|
||||||
|
for (modlist) |mod| {
|
||||||
|
try writer.print("try core.loadModule(\"{s}\", true);\n", .{mod});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (static) {
|
||||||
|
_ = try writer.write(
|
||||||
|
\\ const args = core.externModule.getModuleLoaderArgs(true);
|
||||||
|
);
|
||||||
|
|
||||||
|
for (modlist) |mod| {
|
||||||
|
try writer.print("try {s}.start_module(args);\n", .{mod});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = try writer.write("}\n");
|
||||||
|
|
||||||
|
if (static) {
|
||||||
|
for (modlist) |mod| {
|
||||||
|
try writer.print("const {s} = @import(\"{s}\");\n", .{ mod, mod });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try writer.print("const std = @import(\"std\");", .{});
|
||||||
|
|
||||||
|
// 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=\n{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);
|
||||||
|
}
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
// This is used to generate module function loaders
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
@ -183,15 +183,7 @@ pub const ModuleLoader = struct {
|
||||||
if (loaded.startOnLoad) {
|
if (loaded.startOnLoad) {
|
||||||
if (!loaded.started) {
|
if (!loaded.started) {
|
||||||
var a = self.backingAllocator;
|
var a = self.backingAllocator;
|
||||||
var args = ModuleLoaderArgs{
|
var args = getModuleLoaderArgs(loaded.loaded.items.len == 1);
|
||||||
.firstLoad = loaded.loaded.items.len == 1,
|
|
||||||
.engine = core.getEngine(),
|
|
||||||
.nameRegistry = core.names.gRegistry,
|
|
||||||
.packerFS = core.fs(),
|
|
||||||
.luaState = @ptrCast(core.script.gLuaState.l),
|
|
||||||
.luaAllocator = &core.script.gLuaAllocator,
|
|
||||||
.debugDrawInterface = debug.gDebugDrawInterface.?,
|
|
||||||
};
|
|
||||||
if (interface.startup(&a, &args)) {
|
if (interface.startup(&a, &args)) {
|
||||||
core.engine_log("[ModuleLoader] module startup done", .{});
|
core.engine_log("[ModuleLoader] module startup done", .{});
|
||||||
}
|
}
|
||||||
|
|
@ -209,6 +201,18 @@ pub const ModuleLoader = struct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn getModuleLoaderArgs(first: bool) ModuleLoaderArgs {
|
||||||
|
return .{
|
||||||
|
.firstLoad = first,
|
||||||
|
.engine = core.getEngine(),
|
||||||
|
.nameRegistry = core.names.gRegistry,
|
||||||
|
.packerFS = core.fs(),
|
||||||
|
.luaState = @ptrCast(core.script.gLuaState.l),
|
||||||
|
.luaAllocator = &core.script.gLuaAllocator,
|
||||||
|
.debugDrawInterface = debug.gDebugDrawInterface.?,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const core = @import("../core.zig");
|
const core = @import("../core.zig");
|
||||||
const p2 = @import("p2");
|
const p2 = @import("p2");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
pub fn loadDynamicModules() !void {}
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Backlog = @import("Backlog");
|
const core = @import("core").module;
|
||||||
const core = Backlog.core;
|
|
||||||
const panickers = core.panickers;
|
const panickers = core.panickers;
|
||||||
|
|
||||||
const realMain = @import("main");
|
const realMain = @import("main");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
// workaround forwarder
|
||||||
|
|
||||||
|
pub const core = @import("core").module;
|
||||||
|
pub const rend = @import("rend").module;
|
||||||
|
pub const imgui = @import("imgui").module;
|
||||||
|
|
@ -20,31 +20,36 @@ pub fn build(b: *std.Build) void {
|
||||||
sampleGame.setModuleEnabled("imgui", true);
|
sampleGame.setModuleEnabled("imgui", true);
|
||||||
sampleGame.setModuleEnabled("audio", true);
|
sampleGame.setModuleEnabled("audio", true);
|
||||||
sampleGame.setModuleEnabled("physics", true);
|
sampleGame.setModuleEnabled("physics", true);
|
||||||
|
sampleGame.addExtraModule("gameExtras");
|
||||||
|
sampleGame.addExtraModule("videoplayer");
|
||||||
|
sampleGame.addExtraModule("doomplayer");
|
||||||
|
sampleGame.addExtraModule("bsp");
|
||||||
|
|
||||||
const mod = sampleGame.compileInstall();
|
{ // extern game
|
||||||
|
const externGame = sampleGame.addDynamicModule("externGame", b.path("sampleGame/externGame/externGame.zig"));
|
||||||
|
|
||||||
blbuild.addExtraModule(mod, "gameExtras");
|
_ = externGame.compileInstall();
|
||||||
blbuild.addExtraModule(mod, "videoplayer");
|
}
|
||||||
blbuild.addExtraModule(mod, "doomplayer");
|
|
||||||
blbuild.addExtraModule(mod, "bsp");
|
_ = sampleGame.compileInstall();
|
||||||
|
|
||||||
// external reload modules
|
// external reload modules
|
||||||
const sampleGameExtern = b.addSharedLibrary(.{
|
// const sampleGameExtern = b.addSharedLibrary(.{
|
||||||
.root_source_file = b.path("sampleGame/externGame/externGame.zig"),
|
// .root_source_file = b.path("sampleGame/externGame/externGame.zig"),
|
||||||
.link_libc = true,
|
// .link_libc = true,
|
||||||
.optimize = optimize,
|
// .optimize = optimize,
|
||||||
.target = target,
|
// .target = target,
|
||||||
.name = "externGame",
|
// .name = "externGame",
|
||||||
});
|
// });
|
||||||
|
|
||||||
blbuild.addExtraModule(sampleGameExtern.root_module, "gameExtras");
|
// blbuild.addExtraModule(sampleGameExtern.root_module, "gameExtras");
|
||||||
blbuild.addExtraModule(sampleGameExtern.root_module, "bsp");
|
// blbuild.addExtraModule(sampleGameExtern.root_module, "bsp");
|
||||||
sampleGameExtern.root_module.addImport("backlog", blbuild.nw_mod);
|
// sampleGameExtern.root_module.addImport("backlog", blbuild.nw_mod);
|
||||||
|
|
||||||
const installExtern = b.addInstallArtifact(sampleGameExtern, .{
|
// const installExtern = b.addInstallArtifact(sampleGameExtern, .{
|
||||||
.dest_dir = .{ .override = .{ .custom = "modules" } },
|
// .dest_dir = .{ .override = .{ .custom = "modules" } },
|
||||||
});
|
// });
|
||||||
b.getInstallStep().dependOn(&installExtern.step);
|
// b.getInstallStep().dependOn(&installExtern.step);
|
||||||
|
|
||||||
blbuild.addDependencyInstalls(b, .ReleaseFast); //.ReleaseFast);
|
blbuild.addDependencyInstalls(b, .ReleaseFast); //.ReleaseFast);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ pub fn destroy(self: *@This()) void {
|
||||||
self.data.release(self);
|
self.data.release(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
const backlog = @import("Backlog");
|
const backlog = @import("backlog");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const rend = backlog.rend;
|
const rend = backlog.rend;
|
||||||
const core = backlog.core;
|
const core = backlog.core;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ pub export fn subtract(a: i32, b: i32) i32 {
|
||||||
|
|
||||||
var gAllocator: std.mem.Allocator = undefined;
|
var gAllocator: std.mem.Allocator = undefined;
|
||||||
|
|
||||||
fn start_module(args: core.ModuleLoaderArgs) !void {
|
pub fn start_module(args: core.ModuleLoaderArgs) !void {
|
||||||
if (args.firstLoad) {
|
if (args.firstLoad) {
|
||||||
_ = core.createObject(ExternGameObject, .{}) catch {};
|
_ = core.createObject(ExternGameObject, .{}) catch {};
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ const assetReferences = [_]assets.AssetImportReference{
|
||||||
assets.MakeImportRefOptions(
|
assets.MakeImportRefOptions(
|
||||||
"Mesh",
|
"Mesh",
|
||||||
"m_crate",
|
"m_crate",
|
||||||
.{ .path = "meshes/crate.obj" },
|
.{ .path = "meshes/Crate.obj" },
|
||||||
),
|
),
|
||||||
assets.MakeImportRefOptions(
|
assets.MakeImportRefOptions(
|
||||||
"Texture",
|
"Texture",
|
||||||
|
|
@ -162,7 +162,9 @@ pub fn prepare(self: *@This()) !void {
|
||||||
defer z.End();
|
defer z.End();
|
||||||
try core.fs().addContentPath("sampleGame");
|
try core.fs().addContentPath("sampleGame");
|
||||||
|
|
||||||
try core.loadModule("externGame", true);
|
// try core.loadModule("externGame", true);
|
||||||
|
|
||||||
|
try backlog.loadDynamicModules();
|
||||||
|
|
||||||
self.engineTool = try extras.EngineTool.create(self.allocator);
|
self.engineTool = try extras.EngineTool.create(self.allocator);
|
||||||
|
|
||||||
|
|
@ -304,7 +306,9 @@ fn onShaderReload(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
||||||
_ = action;
|
_ = action;
|
||||||
|
|
||||||
core.engine_log("reloading shaders, this is gonna cause some leaks but thats ok", .{});
|
core.engine_log("reloading shaders, this is gonna cause some leaks but thats ok", .{});
|
||||||
rend.renderer.reloadShaders() catch unreachable;
|
rend.renderer.reloadShaders() catch {
|
||||||
|
core.engine_log("unable to reload shaders", .{});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn slowDown(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
fn slowDown(ctx: ?*anyopaque, action: core.ActionEvent) void {
|
||||||
|
|
@ -377,32 +381,11 @@ pub fn tryLoadExtern(self: *@This(), gameName: []const u8) !void {
|
||||||
pub fn tick(self: *@This(), dt: f64) void {
|
pub fn tick(self: *@This(), dt: f64) void {
|
||||||
const fdt: f32 = @floatCast(dt);
|
const fdt: f32 = @floatCast(dt);
|
||||||
|
|
||||||
// self.loadMap2() catch unreachable;
|
|
||||||
|
|
||||||
core.loopDelay(@src(), 1.0, dt, struct {
|
|
||||||
s: @TypeOf(self),
|
|
||||||
|
|
||||||
pub fn func(c: @This()) void {
|
|
||||||
_ = c;
|
|
||||||
// c.s.tryLoadExtern("externGame") catch unreachable;
|
|
||||||
}
|
|
||||||
}, .{ .s = self });
|
|
||||||
|
|
||||||
const z1 = tracy.ZoneN(@src(), "inputDebugger");
|
|
||||||
z1.End();
|
|
||||||
|
|
||||||
const z2 = tracy.ZoneN(@src(), "inputDebugger");
|
|
||||||
z2.End();
|
|
||||||
|
|
||||||
const z3 = tracy.ZoneN(@src(), "VideoPlayer");
|
|
||||||
//self.videoplayer.tick(dt);
|
|
||||||
z3.End();
|
|
||||||
|
|
||||||
const z4 = tracy.ZoneN(@src(), "fpCamera");
|
const z4 = tracy.ZoneN(@src(), "fpCamera");
|
||||||
self.fpcamera.tick(dt);
|
self.fpcamera.tick(dt);
|
||||||
z4.End();
|
z4.End();
|
||||||
|
|
||||||
const z5 = tracy.ZoneN(@src(), "");
|
const z5 = tracy.ZoneN(@src(), "doomplayer");
|
||||||
DoomPlayer.maybeTick(dt);
|
DoomPlayer.maybeTick(dt);
|
||||||
z5.End();
|
z5.End();
|
||||||
|
|
||||||
|
|
@ -424,81 +407,7 @@ pub fn tick(self: *@This(), dt: f64) void {
|
||||||
self.objectSpawner.spawnPosition = debugCenter;
|
self.objectSpawner.spawnPosition = debugCenter;
|
||||||
self.objectSpawner.spawnRotation = core.Rotation.eulerY(core.radians(self.fpcamera.yaw));
|
self.objectSpawner.spawnRotation = core.Rotation.eulerY(core.radians(self.fpcamera.yaw));
|
||||||
|
|
||||||
//if (self.moveLight) {
|
|
||||||
// core.debugSphere(debugCenter, 0.3, .{});
|
|
||||||
// core.debugSphere(debugCenter, 0.1, .{ .color = .{ .x = 1.0 } });
|
|
||||||
// rend.context().lightPosition = debugCenter;
|
|
||||||
//}
|
|
||||||
|
|
||||||
// self.loadMap2() catch unreachable;
|
|
||||||
// show a window with the current camera's position
|
|
||||||
|
|
||||||
self.objectSpawner.windowOpen = !self.mouseLook;
|
self.objectSpawner.windowOpen = !self.mouseLook;
|
||||||
if (!self.mouseLook) {
|
|
||||||
// self.engineTool.tick();
|
|
||||||
//if (ig.begin("meh", null, .{})) {
|
|
||||||
//if (ig.checkbox("move lights ", &self.moveLight)) {}
|
|
||||||
//}
|
|
||||||
//ig.end();
|
|
||||||
// self.objectSpawner.tick(dt);
|
|
||||||
// self.rendererDebugger.tick(dt);
|
|
||||||
// if (ig.begin("meh", null, .{})) {
|
|
||||||
// ig.textFmt("x:{d:.03} y:{d:.03} z:{d:.03}", .{ pos.x, pos.y, pos.z }) catch return;
|
|
||||||
// // if (ig.checkbox("video fullbright", &self.videoFullbright)) {
|
|
||||||
// // //if (self.videoplayerObject.fetch(rend.MeshComponent)) |mesh| {
|
|
||||||
// // // mesh.textureMode.fullbright = self.videoFullbright;
|
|
||||||
// // //}
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// ig.textFmt("info: - WASD to move, mouse to look,\n- Q and E to go up and down", .{}) catch return;
|
|
||||||
// ig.textFmt("- shift to slow down camera speed", .{}) catch return;
|
|
||||||
// ig.textFmt("- T to enable/disable mouse cursor", .{}) catch return;
|
|
||||||
// ig.textFmt("- f2 to route all inputs to the doom player", .{}) catch return;
|
|
||||||
// ig.textFmt("- movingLight checkbox makes the light stop moving with you", .{}) catch return;
|
|
||||||
|
|
||||||
// //ig.textf("1 + 2 = {d}", .{self.addFunc.?(1, 2)});
|
|
||||||
|
|
||||||
// {
|
|
||||||
// ig.textf("modules dirty: ", .{});
|
|
||||||
// var i = self.modules.iterator();
|
|
||||||
// while (i.next()) |n| {
|
|
||||||
// ig.textf("{s} pending reload", .{n.value_ptr.*});
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (ig.smallButton("reload map")) {
|
|
||||||
// self.loadMap2() catch unreachable;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (ig.smallButton("destroy map")) {
|
|
||||||
// if (self.tbMap) |tbMap| {
|
|
||||||
// core.engine_log("killing the map", .{});
|
|
||||||
// tbMap.destroy();
|
|
||||||
// self.tbMap = null;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// ig.end();
|
|
||||||
|
|
||||||
// if (ig.begin("mesh components", null, .{})) {
|
|
||||||
// for (rend.MeshComponent.BaseContainer.dense.items) |*v| {
|
|
||||||
// ig.textFmt("mesh: {s}", .{v.value.meshName.utf8()}) catch unreachable;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// ig.end();
|
|
||||||
|
|
||||||
// if (ig.begin("scene components", null, .{})) {
|
|
||||||
// for (core.Scene.BaseContainer.dense.items) |*v| {
|
|
||||||
// ig.textFmt("scene entity: {d}", .{v.value.handle.index}) catch unreachable;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ig.textf("window at 0x{x}", .{@intFromPtr(backlog.platform.context().window)});
|
|
||||||
// if (ig.smallButton("click to show sdl messagebox")) {
|
|
||||||
// // _ = backlog.platform.windowing.sdl3.c.SDL_ShowSimpleMessageBox(0, "lmao", "you lmaoed your last uwu", backlog.platform.context().window);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// ig.end();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *@This()) void {
|
pub fn deinit(self: *@This()) void {
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue