diff --git a/build.zig b/build.zig index 096274c..7bbded8 100644 --- a/build.zig +++ b/build.zig @@ -34,78 +34,86 @@ pub fn build(b: *std.Build) !void { .optimize = optimize, }); - const build_options = b.addOptions(); - build_options.addOption(bool, "has_imgui", has_imgui); - build_options.addOption(?[]const u8, "assets_dir", if (assets_from_filesystem) asset_dir_realpath else null); - exe_mod.addOptions("build_options", build_options); - - exe_mod.addImport("embedded_assets", try createEmbeddedAssets(b, assets_dir, &asset_files)); - - const math_mod = b.createModule(.{ - .root_source_file = b.path("src/platform/math.zig") - }); - exe_mod.addImport("math", math_mod); - const dep_tiled = b.dependency("tiled", .{}); exe_mod.addImport("tiled", dep_tiled.module("tiled")); - const dep_sokol = b.dependency("sokol", .{ - .target = target, - .optimize = optimize, - .with_sokol_imgui = has_imgui - }); - const mod_sokol = dep_sokol.module("sokol"); - exe_mod.linkLibrary(dep_sokol.artifact("sokol_clib")); - exe_mod.addImport("sokol", mod_sokol); - - const dep_shdc = dep_sokol.builder.dependency("shdc", .{}); - - var slang = sokol.shdc.Slang{}; - if (is_wasm) { - slang.wgsl = true; - } else { - slang.glsl410 = true; - slang.hlsl4 = true; - slang.metal_macos = true; - slang.glsl300es = true; - } - const mod_shader = try sokol.shdc.createModule(b, "shader", mod_sokol, .{ - .shdc_dep = dep_shdc, - .input = "src/platform/shader.glsl", - .output = "src/platform/shader.zig", - .slang = slang - }); - mod_shader.addImport("math", math_mod); - exe_mod.addImport("shader", mod_shader); - - if (has_imgui) { - if (b.lazyDependency("cimgui", .{ - .target = target, - .optimize = optimize, - })) |dep_cimgui| { - const cimgui = b.lazyImport(@This(), "cimgui").?; - const cimgui_conf = cimgui.getConfig(true); - exe_mod.addImport("cimgui", dep_cimgui.module(cimgui_conf.module_name)); - dep_sokol.artifact("sokol_clib").root_module.addIncludePath(dep_cimgui.path(cimgui_conf.include_dir)); - } - } - const dep_stb = b.dependency("stb", .{}); exe_mod.addImport("stb_image", dep_stb.module("stb_image")); - exe_mod.addImport("stb_vorbis", dep_stb.module("stb_vorbis")); - exe_mod.addImport("stb_rect_pack", dep_stb.module("stb_rect_pack")); exe_mod.addImport("stb_truetype", dep_stb.module("stb_truetype")); - const dep_tracy = b.dependency("tracy", .{ - .target = target, - .optimize = optimize, - .tracy_enable = has_tracy, - .tracy_only_localhost = true + const platform_mod = b.createModule(.{ + .root_source_file = b.path("src/platform/root.zig") }); - if (has_tracy) { - exe_mod.linkLibrary(dep_tracy.artifact("tracy")); + exe_mod.addImport("platform", platform_mod); + { + const build_options = b.addOptions(); + build_options.addOption(bool, "has_imgui", has_imgui); + build_options.addOption(?[]const u8, "assets_dir", if (assets_from_filesystem) asset_dir_realpath else null); + platform_mod.addOptions("build_options", build_options); + + platform_mod.addImport("embedded_assets", try createEmbeddedAssets(b, assets_dir, &asset_files)); + + const math_mod = b.createModule(.{ + .root_source_file = b.path("src/platform/math.zig") + }); + platform_mod.addImport("math", math_mod); + + const dep_sokol = b.dependency("sokol", .{ + .target = target, + .optimize = optimize, + .with_sokol_imgui = has_imgui + }); + const mod_sokol = dep_sokol.module("sokol"); + platform_mod.linkLibrary(dep_sokol.artifact("sokol_clib")); + platform_mod.addImport("sokol", mod_sokol); + + const dep_shdc = dep_sokol.builder.dependency("shdc", .{}); + + var slang = sokol.shdc.Slang{}; + if (is_wasm) { + slang.wgsl = true; + } else { + slang.glsl410 = true; + slang.hlsl4 = true; + slang.metal_macos = true; + slang.glsl300es = true; + } + const mod_shader = try sokol.shdc.createModule(b, "shader", mod_sokol, .{ + .shdc_dep = dep_shdc, + .input = "src/platform/shader.glsl", + .output = "src/platform/shader.zig", + .slang = slang + }); + mod_shader.addImport("math", math_mod); + platform_mod.addImport("shader", mod_shader); + + if (has_imgui) { + if (b.lazyDependency("cimgui", .{ + .target = target, + .optimize = optimize, + })) |dep_cimgui| { + const cimgui = b.lazyImport(@This(), "cimgui").?; + const cimgui_conf = cimgui.getConfig(true); + platform_mod.addImport("cimgui", dep_cimgui.module(cimgui_conf.module_name)); + dep_sokol.artifact("sokol_clib").root_module.addIncludePath(dep_cimgui.path(cimgui_conf.include_dir)); + } + } + + platform_mod.addImport("stb_vorbis", dep_stb.module("stb_vorbis")); + platform_mod.addImport("stb_rect_pack", dep_stb.module("stb_rect_pack")); + + const dep_tracy = b.dependency("tracy", .{ + .target = target, + .optimize = optimize, + .tracy_enable = has_tracy, + .tracy_only_localhost = true + }); + if (has_tracy) { + platform_mod.linkLibrary(dep_tracy.artifact("tracy")); + } + platform_mod.addImport("tracy", dep_tracy.module("tracy")); } - exe_mod.addImport("tracy", dep_tracy.module("tracy")); + var run_cmd_step: *std.Build.Step = undefined; if (is_wasm) { @@ -113,17 +121,18 @@ pub fn build(b: *std.Build) !void { @panic("TODO: test in 0.17"); } - const build_step = buildWasm(b, .{ - .name = "index", - .root_module = exe_mod, - .dep_sokol = dep_sokol, - }); - b.getInstallStep().dependOn(build_step); - - const dep_emsdk = dep_sokol.builder.dependency("emsdk", .{}); - const emrun_step = sokol.emRunStep(b, .{ .name = "index", .emsdk = dep_emsdk }); - emrun_step.step.dependOn(build_step); - run_cmd_step = &emrun_step.step; + // TODO: + // const build_step = buildWasm(b, .{ + // .name = "index", + // .root_module = exe_mod, + // .dep_sokol = dep_sokol, + // }); + // b.getInstallStep().dependOn(build_step); + // + // const dep_emsdk = dep_sokol.builder.dependency("emsdk", .{}); + // const emrun_step = sokol.emRunStep(b, .{ .name = "index", .emsdk = dep_emsdk }); + // emrun_step.step.dependOn(build_step); + // run_cmd_step = &emrun_step.step; // TODO: Create a zip archive of all of the files. Would be useful for easier itch.io upload } else { diff --git a/build.zig.zon b/build.zig.zon index bf65b84..eec3410 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -5,8 +5,8 @@ .minimum_zig_version = "0.16.0", .dependencies = .{ .sokol = .{ - .url = "git+https://github.com/floooh/sokol-zig.git#ba97ac4e82e36a0f6c62f7fad5dc9c2d82beadd8", - .hash = "sokol-0.1.0-pb1HK4prNwDGx2RJFyv7VtYJubDahi19XKioPzPeMCxv", + .url = "git+https://github.com/floooh/sokol-zig.git#d4adaef70dd68d2ca8e8c3b6a392ab455181ab4a", + .hash = "sokol-0.1.0-pb1HK0EaQQDC6r1jTWJbUWiXbjxfpWuWEK3tz0z4K1aY", }, .stb = .{ .path = "./libs/stb", diff --git a/src/app.zig b/src/app.zig index f32b673..5eac963 100644 --- a/src/app.zig +++ b/src/app.zig @@ -7,7 +7,7 @@ const STBImage = @import("stb_image"); const STBTrueType = @import("stb_truetype"); const Tiled = @import("tiled"); -const Platform = @import("platform/root.zig"); +const Platform = @import("platform"); const Gfx = Platform.Gfx; const Vec2 = Platform.Vec2; const Audio = Platform.Audio; diff --git a/src/canvas_scaler.zig b/src/canvas_scaler.zig index 4af4568..caa53c6 100644 --- a/src/canvas_scaler.zig +++ b/src/canvas_scaler.zig @@ -1,10 +1,9 @@ -const Math = @import("math"); -const Vec2 = Math.Vec2; - -const Platform = @import("platform/root.zig"); +const Platform = @import("platform"); const Gfx = Platform.Gfx; const Color = Platform.Color; +const Vec2 = Platform.Math.Vec2; + const Canvas = @This(); size: Vec2, diff --git a/src/font.zig b/src/font.zig index 2ddc6d9..91673ec 100644 --- a/src/font.zig +++ b/src/font.zig @@ -4,7 +4,7 @@ const assert = std.debug.assert; const Allocator = std.mem.Allocator; const Io = std.Io; -const Platform = @import("platform/root.zig"); +const Platform = @import("platform"); const Gfx = Platform.Gfx; const SlotMapType = Platform.SlotMapType; const Vec2 = Platform.Vec2; diff --git a/src/main.zig b/src/main.zig index 7c2c5f3..b2d7c49 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,6 +1,6 @@ const std = @import("std"); -const Platform = @import("platform/root.zig"); +const Platform = @import("platform"); const App = @import("app.zig"); pub const std_options: std.Options = .{ @@ -21,5 +21,5 @@ pub fn main(init: std.process.Init) void { test { std.testing.refAllDecls(@This()); - _ = @import("./platform/slot_map.zig"); + _ = Platform; } diff --git a/src/platform/graphics.zig b/src/platform/graphics.zig index c2e28a1..c3b13c8 100644 --- a/src/platform/graphics.zig +++ b/src/platform/graphics.zig @@ -15,7 +15,6 @@ const Mat4 = Math.Mat4; const Rect = Math.Rect; const STBRectPack = @import("stb_rect_pack"); -const STBTrueType = @import("stb_truetype"); const ImGUI = @import("imgui.zig"); pub const Color = @import("./color.zig"); const shd = @import("shader"); @@ -126,7 +125,7 @@ pub fn init(gpa: std.mem.Allocator, logger: sg.Logger) !void { bindings.vertex_buffers[0] = sg.makeBuffer(.{ .size = @sizeOf(VertexQuad) * max_quads, - .usage = .{ .vertex_buffer = true, .stream_update = true }, + .usage = .{ .vertex_buffer = true, .dynamic_update = true }, .label = "quad-vertices" }); diff --git a/src/tilesheet.zig b/src/tilesheet.zig index 138abe2..f099d25 100644 --- a/src/tilesheet.zig +++ b/src/tilesheet.zig @@ -2,7 +2,7 @@ const std = @import("std"); const log = std.log.scoped(.app); const Allocator = std.mem.Allocator; -const Platform = @import("platform/root.zig"); +const Platform = @import("platform"); const Gfx = Platform.Gfx; const Vec2 = Platform.Vec2; const Rect = Platform.Rect;