diff --git a/build.zig b/build.zig index 7f7918f..a5c90ac 100644 --- a/build.zig +++ b/build.zig @@ -98,6 +98,7 @@ pub const AddProgramOptions = struct { desc: []const u8, root_source_file: LazyPath, imports: []const Build.Module.Import = &.{}, + staticBuild: bool = false, // ugh.... why is this so hard... }; pub fn addProgram(self: *BuildSystem, opts: AddProgramOptions) *std.Build.Module { @@ -185,12 +186,7 @@ pub fn addExtraModule(self: *BuildSystem, mod: *std.Build.Module, moduleName: [] } pub fn addDependencyInstalls(self: *BuildSystem, b: *std.Build, optimize: std.builtin.OptimizeMode) void { - b.installArtifact(b.dependency("sdl3_lib", .{ .target = self.target, .optimize = optimize }).artifact("SDL3")); - // b.installArtifact(b.dependency("Backlog", .{ .target = self.target, .optimize = optimize }).artifact("backlog_c")); - - //b.installArtifact(b.dependency("spng", .{ .target = self.target, .optimize = optimize }).artifact("spng_c")); - //b.installArtifact(b.dependency("zphysics", .{ .target = self.target, .optimize = optimize }).artifact("joltc")); - //b.installArtifact(b.dependency("ozz", .{ .target = self.target, .optimize = optimize }).artifact("ozz_cpp")); + // b.installArtifact(b.dependency("sdl3_lib", .{ .target = self.target, .optimize = optimize }).artifact("SDL3")); for (cDependencyList) |d| { b.installArtifact(b.dependency( diff --git a/engine/imgui/src/utils/TopBar.zig b/engine/imgui/src/utils/TopBar.zig index b8b5f9e..2c91573 100644 --- a/engine/imgui/src/utils/TopBar.zig +++ b/engine/imgui/src/utils/TopBar.zig @@ -5,7 +5,7 @@ allocator: std.mem.Allocator, arena: std.heap.ArenaAllocator, windowsMenu: std.ArrayListUnmanaged(*MenuEntry) = .{}, entriesByName: std.AutoHashMapUnmanaged(u32, *MenuEntry) = .{}, -menuOpen: bool = true, +menuOpen: bool = false, pub fn create(allocator: std.mem.Allocator) !*@This() { const self = try Slack.create(allocator); diff --git a/engine/rend/src/sgpu/embedded/texture_sample.png b/engine/rend/src/sgpu/embedded/texture_sample.png new file mode 100644 index 0000000..9ff0970 Binary files /dev/null and b/engine/rend/src/sgpu/embedded/texture_sample.png differ diff --git a/engine/rend/src/sgpu/renderer.zig b/engine/rend/src/sgpu/renderer.zig index f0ef7f4..f049491 100644 --- a/engine/rend/src/sgpu/renderer.zig +++ b/engine/rend/src/sgpu/renderer.zig @@ -154,12 +154,15 @@ pub const Renderer = struct { try self.createSamplers(); + _ = try core.fs().installFileBytesMount("embedded:texture_sample.png", @constCast(&texture_sample_png), true); + _ = try core.fs().installFileBytesMount("embedded:primitive_box.obj", @constCast(&primitive_box_obj), true); + // todo... make these embedded try assets.load( assets.MakeImportRefOptions( "Texture", "t_default", - .{ .path = "textures/texture_sample.png" }, + .{ .path = "embedded:texture_sample.png" }, ), ); @@ -167,7 +170,7 @@ pub const Renderer = struct { assets.MakeImportRefOptions( "Mesh", "m_default_cube", - .{ .path = "meshes/primitive_box.obj" }, + .{ .path = "embedded:primitive_box.obj" }, ), ); var defaultTextureName = core.MakeName("t_default"); @@ -1020,6 +1023,8 @@ pub const GPUTextureType = gpu.GPUTexture; const plane_obj align(8) = @embedFile("embedded/plane.obj").*; const screenPlane_obj align(8) = @embedFile("embedded/screenPlane.obj").*; +const texture_sample_png align(8) = @embedFile("embedded/texture_sample.png").*; +const primitive_box_obj align(8) = @embedFile("embedded/primitive_box.obj").*; const tracy = core.tracy; pub const SsaoSystem = @import("ssao.zig"); diff --git a/lib/packer/src/packerfs.zig b/lib/packer/src/packerfs.zig index ed6eec3..11f8845 100644 --- a/lib/packer/src/packerfs.zig +++ b/lib/packer/src/packerfs.zig @@ -156,6 +156,10 @@ pub const PackerFS = struct { pub fn watchPath(self: *@This(), path: []const u8) void { // std.debug.print("self = {x}\n", .{@intFromPtr(self)}); + + // check the path exists before attempting to watch + std.fs.cwd().access(path, .{}) catch return; + const p = self.stringArena.allocator().dupeZ(u8, path) catch return; const watch = watcher.createWatchPoint( p, diff --git a/projects/minimal/.fontcache/bitmap.fontcache b/projects/minimal/.fontcache/bitmap.fontcache new file mode 100644 index 0000000..93a1ff9 Binary files /dev/null and b/projects/minimal/.fontcache/bitmap.fontcache differ diff --git a/projects/minimal/.fontcache/default.fontcache b/projects/minimal/.fontcache/default.fontcache new file mode 100644 index 0000000..ee1eb77 Binary files /dev/null and b/projects/minimal/.fontcache/default.fontcache differ diff --git a/projects/minimal/.fontcache/monospace.fontcache b/projects/minimal/.fontcache/monospace.fontcache new file mode 100644 index 0000000..9956d98 Binary files /dev/null and b/projects/minimal/.fontcache/monospace.fontcache differ diff --git a/projects/minimal/Saved/Session_Log.txt b/projects/minimal/Saved/Session_Log.txt new file mode 100644 index 0000000..f8d41df --- /dev/null +++ b/projects/minimal/Saved/Session_Log.txt @@ -0,0 +1,112 @@ +[ENGINE ]: defining componentScene +[ENGINE ]: Component container created scene.Scene @1c60c524798 +[ENGINE ]: creating lua metatable Scene +[ENGINE ]: module started >>>> core <<<< +[ENGINE ]: platform settings windowing.PlatformParams{ .extent = math.Vector2Type(c_int,"Vector2c"[0..8]){ .x = 1600, .y = 900 }, .windowName = { 66, 97, 99, 107, 108, 111, 103, 32, 69, 110, 103, 105, 110, 101 }, .icon = { 116, 101, 120, 116, 117, 114, 101, 115, 47, 105, 99, 111, 110, 46, 112, 110, 103 }, .hasVideo = true } +[ENGINE ]: module started >>>> platform <<<< +[ENGINE ]: allocated size: 4035286 (3.848 MiB) +[ENGINE ]: peak allocated size size: 4035414 (3.848 MiB) (76 peak allocations) +[ENGINE ]: module started >>>> assets <<<< +[ENGINE ]: sgpu device created, using shader format: .spv +[ENGINE ]: using renderer... scientist +[ENGINE ]: creating shader meshes.vert => _shaders/spv/meshes.vert.spv gpu.GPUShaderStage.shaderstageVertex args: shaderTypes.ShaderLoadArgs{ .num_samplers = 0, .num_storage_textures = 0, .num_storage_buffers = 1, .num_uniform_buffers = 1 } +[ENGINE ]: creating shader lit_mesh.frag => _shaders/spv/lit_mesh.frag.spv gpu.GPUShaderStage.shaderstageFragment args: shaderTypes.ShaderLoadArgs{ .num_samplers = 4, .num_storage_textures = 0, .num_storage_buffers = 1, .num_uniform_buffers = 1 } +[GRAPHICS ]: swapchain format: gpu.GPUTextureFormat.textureformatB8g8r8a8Unorm +[ENGINE ]: creating shader postProc.vert => _shaders/spv/postProc.vert.spv gpu.GPUShaderStage.shaderstageVertex args: shaderTypes.ShaderLoadArgs{ .num_samplers = 0, .num_storage_textures = 0, .num_storage_buffers = 0, .num_uniform_buffers = 0 } +[ENGINE ]: creating shader postProc.frag => _shaders/spv/postProc.frag.spv gpu.GPUShaderStage.shaderstageFragment args: shaderTypes.ShaderLoadArgs{ .num_samplers = 3, .num_storage_textures = 0, .num_storage_buffers = 0, .num_uniform_buffers = 0 } +[GRAPHICS ]: hdr texture format format: gpu.GPUTextureFormat.textureformatR16g16b16a16Float +[GRAPHICS ]: mesh pool created 4000k vertices, 16000k indices +[ENGINE ]: asset loader for asset type (Mesh) registered +[ENGINE ]: Texture List Added +[ENGINE ]: asset loader for asset type (Texture) registered +[ENGINE ]: creating blocky sampler +[ENGINE ]: loading asset t_default (Texture) [embedded:texture_sample.png] +[ENGINE ]: loading texture t_default +[ENGINE ]: creating mipmap level 9 +[ENGINE ]: loading asset m_default_cube (Mesh) [embedded:primitive_box.obj] +[ENGINE ]: loading mesh asset embedded:primitive_box.obj [obj] +[GRAPHICS ]: [embedded:primitive_box.obj] vertex count vertices=24 indices=36 +[ENGINE ]: [DebugDrawSystem] starting up... +[ENGINE ]: loading asset m_debug_box (Mesh) [embedded:debug_box.obj] +[ENGINE ]: loading mesh asset embedded:debug_box.obj [obj] +[GRAPHICS ]: [embedded:debug_box.obj] vertex count vertices=24 indices=36 +[ENGINE ]: loading asset m_debug_line (Mesh) [embedded:debug_line.obj] +[ENGINE ]: loading mesh asset embedded:debug_line.obj [obj] +[GRAPHICS ]: [embedded:debug_line.obj] vertex count vertices=2 indices=3 +[ENGINE ]: loading asset m_debug_sphere (Mesh) [embedded:debug_sphere.obj] +[ENGINE ]: loading mesh asset embedded:debug_sphere.obj [obj] +[GRAPHICS ]: [embedded:debug_sphere.obj] vertex count vertices=240 indices=336 +[ENGINE ]: [DebugDrawSystem] registering to renderer... +[ENGINE ]: creating shader debug.vert => _shaders/spv/debug.vert.spv gpu.GPUShaderStage.shaderstageVertex args: shaderTypes.ShaderLoadArgs{ .num_samplers = 0, .num_storage_textures = 0, .num_storage_buffers = 1, .num_uniform_buffers = 1 } +[ENGINE ]: creating shader debug.frag => _shaders/spv/debug.frag.spv gpu.GPUShaderStage.shaderstageFragment args: shaderTypes.ShaderLoadArgs{ .num_samplers = 0, .num_storage_textures = 0, .num_storage_buffers = 0, .num_uniform_buffers = 0 } +[ENGINE ]: creating shader meshes.vert => _shaders/spv/meshes.vert.spv gpu.GPUShaderStage.shaderstageVertex args: shaderTypes.ShaderLoadArgs{ .num_samplers = 0, .num_storage_textures = 0, .num_storage_buffers = 1, .num_uniform_buffers = 1 } +[ENGINE ]: creating shader depthOnly.frag => _shaders/spv/depthOnly.frag.spv gpu.GPUShaderStage.shaderstageFragment args: shaderTypes.ShaderLoadArgs{ .num_samplers = 0, .num_storage_textures = 0, .num_storage_buffers = 0, .num_uniform_buffers = 0 } +[ENGINE ]: loading asset m_skybox (Mesh) [embedded:skybox_mesh.obj] +[ENGINE ]: loading mesh asset embedded:skybox_mesh.obj [obj] +[GRAPHICS ]: [embedded:skybox_mesh.obj] vertex count vertices=24 indices=36 +[ENGINE ]: creating shader skybox.vert => _shaders/spv/skybox.vert.spv gpu.GPUShaderStage.shaderstageVertex args: shaderTypes.ShaderLoadArgs{ .num_samplers = 0, .num_storage_textures = 0, .num_storage_buffers = 0, .num_uniform_buffers = 1 } +[ENGINE ]: creating shader skybox.frag => _shaders/spv/skybox.frag.spv gpu.GPUShaderStage.shaderstageFragment args: shaderTypes.ShaderLoadArgs{ .num_samplers = 1, .num_storage_textures = 0, .num_storage_buffers = 0, .num_uniform_buffers = 1 } +[ENGINE ]: loading asset m_plane (Mesh) [embedded:plane.obj] +[ENGINE ]: loading mesh asset embedded:plane.obj [obj] +[GRAPHICS ]: [embedded:plane.obj] vertex count vertices=4 indices=6 +[ENGINE ]: loading asset m_screenPlane (Mesh) [embedded:screenPlane.obj] +[ENGINE ]: loading mesh asset embedded:screenPlane.obj [obj] +[GRAPHICS ]: [embedded:screenPlane.obj] vertex count vertices=4 indices=6 +[ENGINE ]: creating ssao pipeline +[ENGINE ]: creating shader postProc.vert => _shaders/spv/postProc.vert.spv gpu.GPUShaderStage.shaderstageVertex args: shaderTypes.ShaderLoadArgs{ .num_samplers = 0, .num_storage_textures = 0, .num_storage_buffers = 0, .num_uniform_buffers = 0 } +[ENGINE ]: creating shader ssao.frag => _shaders/spv/ssao.frag.spv gpu.GPUShaderStage.shaderstageFragment args: shaderTypes.ShaderLoadArgs{ .num_samplers = 3, .num_storage_textures = 0, .num_storage_buffers = 0, .num_uniform_buffers = 1 } +[ENGINE ]: defining component_MeshComponent +[ENGINE ]: Component container created meshes.MeshComponent @24618af28e8 +[ENGINE ]: creating lua metatable Mesh +[ENGINE ]: defining component_CameraComponent +[ENGINE ]: Component container created camera.CameraComponent @1c60e4b9d68 +[ENGINE ]: creating lua metatable Camera +[ENGINE ]: module started >>>> rend <<<< +[GRAPHICS ]: imgui startup +[ENGINE ]: module started >>>> imgui <<<< +[ENGINE ]: UI module started +[ENGINE ]: [Fontcache] loading font cache for default font +[ENGINE ]: [Fontcache] loading font cache for monospace font +[ENGINE ]: [Fontcache] loading font cache for bitmap font +[GRAPHICS ]: imgui startup +[ENGINE ]: module started >>>> ui <<<< +[ENGINE ]: creating Game context +[ENGINE ]: calling gEngine.run +[ENGINE ]: engine loop started +[ENGINE ]: program ready +[ENGINE ]: uploading mesh => m_default_cube +[GRAPHICS ]: uploading 24 vertices and 36 indices +[ENGINE ]: install mesh by name 16 +[ENGINE ]: uploading mesh => m_debug_box +[GRAPHICS ]: uploading 24 vertices and 36 indices +[ENGINE ]: install mesh by name 20 +[ENGINE ]: uploading mesh => m_debug_line +[GRAPHICS ]: uploading 2 vertices and 3 indices +[ENGINE ]: install mesh by name 21 +[ENGINE ]: uploading mesh => m_debug_sphere +[GRAPHICS ]: uploading 240 vertices and 336 indices +[ENGINE ]: install mesh by name 22 +[ENGINE ]: uploading mesh => m_skybox +[GRAPHICS ]: uploading 24 vertices and 36 indices +[ENGINE ]: install mesh by name 30 +[ENGINE ]: uploading mesh => m_plane +[GRAPHICS ]: uploading 4 vertices and 6 indices +[ENGINE ]: install mesh by name 37 +[ENGINE ]: uploading mesh => m_screenPlane +[GRAPHICS ]: uploading 4 vertices and 6 indices +[ENGINE ]: install mesh by name 38 +[ENGINE ]: Processing exit signals +[ENGINE ]: checking everything is ready to exit +[ENGINE ]: checking everything is ready to exit engineObject.InterfaceRef2(engineObject.EngineObjectVTable){ .ptr = anyopaque@1c60c49a9e8, .vtable = engineObject.EngineObjectVTable{ .typeName = { 119, 105, 110, 100, 111, 119, 105, 110, 103, 46, 80, 108, 97, 116, 102, 111, 114, 109, 73, 110, 115, 116, 97, 110, 99, 101 }, .typeSize = 112, .typeAlign = 8, .singletonName = { 112, 108, 97, 116, 102, 111, 114, 109, 46, 73, 110, 115, 116, 97, 110, 99, 101 }, .init_func = fn (mem.Allocator) error{OutOfMemory,UnknownStatePanic,BadInit,UnknownError}!*anyopaque@7ff66491a590, .tick_func = null, .engineDraw_func = null, .preTick_func = null, .deinit_func = fn (*anyopaque) void@7ff66491a7f0, .postInit_func = null, .processEvents = null, .exitSignal_func = fn (*anyopaque) error{OutOfMemory,UnknownStatePanic,BadInit,UnknownError}!void@7ff66491a6d0, .readyToExit_func = fn (*anyopaque) bool@7ff66491a750, .prepare_func = null, .fieldListHash = null, .fieldList = null, .slackSize = null } } +[ENGINE ]: exiting +[ENGINE ]: module shutting down >>>> ui <<<< +[ENGINE ]: module shutting down >>>> imgui <<<< +[ENGINE ]: module shutting down >>>> rend <<<< +[ENGINE ]: undefining component meshes.MeshComponent +[ENGINE ]: undefining component camera.CameraComponent +[ENGINE ]: module shutting down >>>> assets <<<< +[ENGINE ]: module shutting down >>>> platform <<<< +[ENGINE ]: module shutting down >>>> core <<<< +[ENGINE ]: allocated size: 3064738 (2.923 MiB) +[ENGINE ]: peak allocated size size: 9418782 (8.982 MiB) (190 peak allocations) +[ENGINE ]: undefining component scene.Scene diff --git a/projects/minimal/build.zig b/projects/minimal/build.zig new file mode 100644 index 0000000..d00b329 --- /dev/null +++ b/projects/minimal/build.zig @@ -0,0 +1,21 @@ +const std = @import("std"); +const Backlog = @import("Backlog"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + var blbuild = Backlog.init(b, .{ + .target = target, + .optimize = optimize, + .backlogRoot = "../", + }); + + _ = blbuild.addProgram(.{ + .name = "minimal", + .desc = "tool program, no assets", + .root_source_file = b.path("src/main.zig"), + }); + + blbuild.addDependencyInstalls(b, .ReleaseFast); //.ReleaseFast); +} diff --git a/projects/minimal/build.zig.zon b/projects/minimal/build.zig.zon new file mode 100644 index 0000000..f91ce8c --- /dev/null +++ b/projects/minimal/build.zig.zon @@ -0,0 +1,23 @@ +.{ + .name = .MyProjects, + .version = "0.0.0", + .dependencies = .{ + // engine libraries + // you will want to change these paths. + // + // .. theoretically if this is a static build, + .Backlog = .{ .path = "../../" }, + .SpirvReflect = .{ .path = "../../lib/spirv-reflect-zig" }, + + .zphysics = .{.path = "../../lib/zphysics"}, + .spng = .{ .path = "../../lib/spng" }, + .ozz = .{ .path = "../../lib/ozz" }, + .sdl3_lib = .{ .path = "../../lib/sdl3/SDL" }, + .miniaudio = .{ .path = "../../lib/miniaudio" }, + .lua = .{ .path = "../../lib/lua" }, + }, + .paths = .{ + "", + }, + .fingerprint = 0x14099f7390321175 +} diff --git a/projects/minimal/build.zig.zon.template b/projects/minimal/build.zig.zon.template new file mode 100644 index 0000000..975d0ca --- /dev/null +++ b/projects/minimal/build.zig.zon.template @@ -0,0 +1,23 @@ +.{ + .name = .MyProjects, + .version = "0.0.0", + .dependencies = .{ + // engine libraries + // you will want to change these paths. + // + // .. theoretically if this is a static build, + .Backlog = .{ .path = "$RELATIVEPATH/" }, + .SpirvReflect = .{ .path = "$RELATIVEPATH/lib/spirv-reflect-zig" }, + + .zphysics = .{.path = "$RELATIVEPATH/lib/zphysics"}, + .spng = .{ .path = "$RELATIVEPATH/lib/spng" }, + .ozz = .{ .path = "$RELATIVEPATH/lib/ozz" }, + .sdl3_lib = .{ .path = "$RELATIVEPATH/lib/sdl3/SDL" }, + .miniaudio = .{ .path = "$RELATIVEPATH/lib/miniaudio" }, + .lua = .{ .path = "$RELATIVEPATH/lib/lua" }, + }, + .paths = .{ + "", + }, + .fingerprint = 0x14099f7390321175 +} diff --git a/projects/minimal/buildShaders.py b/projects/minimal/buildShaders.py new file mode 100644 index 0000000..9d5bf2c --- /dev/null +++ b/projects/minimal/buildShaders.py @@ -0,0 +1,10 @@ +import os +import sys +import subprocess + +origDir = os.path.abspath(os.path.dirname(__file__)) +backlogEngineDir = os.path.abspath(os.path.join(origDir, "../../")) + +cmd = [sys.executable, os.path.join(backlogEngineDir, "tools/scripts/cookShaders.py")] + +subprocess.run(cmd, cwd=origDir) diff --git a/projects/minimal/src/main.zig b/projects/minimal/src/main.zig new file mode 100644 index 0000000..be23c16 --- /dev/null +++ b/projects/minimal/src/main.zig @@ -0,0 +1,41 @@ +pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "main"); + +allocator: std.mem.Allocator, + +pub fn init(allocator: std.mem.Allocator) !*@This() { + const self = try allocator.create(@This()); + self.* = .{ + .allocator = allocator, + }; + return self; +} + +pub fn prepare(self: *@This()) !void { + _ = self; + core.engine_log("program ready", .{}); +} + +pub fn tick(self: *@This(), dt: f64) void { + _ = self; + _ = dt; +} + +pub fn deinit(self: *@This()) void { + self.allocator.destroy(self); +} + +pub fn main() anyerror!void { + var spec = try bl.createSpecVariant(.{ + .name = "sampleGame", + .imgui = true, + .physics = false, + .audio = false, + }, std.heap.c_allocator); + + _ = bl.initAndRun(&NeonObjectTable, &spec); +} + +const std = @import("std"); +const bl = @import("Backlog"); +// const ig = backlog.imgui.api; // imgui api +const core = bl.core;