diff --git a/build.zig b/build.zig index d059f76..fa02ae1 100644 --- a/build.zig +++ b/build.zig @@ -61,7 +61,6 @@ pub fn build(b: *std.Build) void { options.addOption(bool, "has_tracy", has_tracy); mod_main.addOptions("build_options", options); - // from here on different handling for native vs wasm builds if (target.result.cpu.arch.isWasm()) { try buildWasm(b, .{ @@ -73,8 +72,8 @@ pub fn build(b: *std.Build) void { } else { try buildNative(b, "sokol_template", mod_main, has_console); } - } + fn buildNative(b: *std.Build, name: []const u8, mod: *std.Build.Module, has_console: bool) !void { const exe = b.addExecutable(.{ .name = name, @@ -170,18 +169,18 @@ fn patchWasmIncludeDirs( // C compilation is attempted (since the sokol C library depends on the // Emscripten SDK setup step) lib.step.dependOn(depend_step); - - std.debug.print("{s}\n", .{lib.name}); } patchWasmIncludeDirs(lib.root_module, path, depend_step); } } fn buildWasm(b: *std.Build, opts: BuildWasmOptions) !void { + opts.mod_main.sanitize_c = .off; + // build the main file into a library, this is because the WASM 'exe' // needs to be linked in a separate build step with the Emscripten linker const main_lib = b.addLibrary(.{ - .name = opts.name, + .name = "index", .root_module = opts.mod_main, }); @@ -202,14 +201,16 @@ fn buildWasm(b: *std.Build, opts: BuildWasmOptions) !void { .use_webgl2 = true, .use_emmalloc = true, .use_filesystem = false, - .shell_file_path = opts.dep_sokol.path("src/sokol/web/shell.html"), + .shell_file_path = b.path("src/engine/shell.html"), }); // attach to default target b.getInstallStep().dependOn(&link_step.step); // ...and a special run step to start the web build output via 'emrun' - const run = sokol.emRunStep(b, .{ .name = opts.name, .emsdk = dep_emsdk }); + const run = sokol.emRunStep(b, .{ .name = "index", .emsdk = dep_emsdk }); run.step.dependOn(&link_step.step); b.step("run", "Run game").dependOn(&run.step); + + // TODO: Create a zip archive of all of the files. Would be useful for easier itch.io upload } const AddExecutableIcon = struct { diff --git a/build.zig.zon b/build.zig.zon index 58ff91d..ffdd935 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -9,8 +9,8 @@ .hash = "sokol-0.1.0-pb1HK4iDNgCom5dkY66eUBm_bYBHEl8KWFDAiqwWgpEy", }, .cimgui = .{ - .url = "git+https://github.com/floooh/dcimgui.git#6c2c7f0452d9f44c95094c3f7dc2969c2c6a5e1a", - .hash = "cimgui-0.1.0-44ClkQYjlQCl0iQX5wlquJ-mFZMqSxXA3hE2MG_3i1BT", + .url = "git+https://github.com/floooh/dcimgui.git#33c99ef426b68030412b5a4b11487a23da9d4f13", + .hash = "cimgui-0.1.0-44ClkQRJlABdFMKRqIG8KDD6jy1eQbgPO335NziPYjmL", .lazy = true }, .tracy = .{ diff --git a/libs/stb_image/build.zig b/libs/stb_image/build.zig index 3b928c0..970e6ca 100644 --- a/libs/stb_image/build.zig +++ b/libs/stb_image/build.zig @@ -8,7 +8,7 @@ pub fn build(b: *std.Build) void { .target = target, .optimize = optimize, .root_source_file = b.path("src/root.zig"), - .link_libc = true + .link_libc = true, }); const stb_dependency = b.dependency("stb", .{}); @@ -18,7 +18,6 @@ pub fn build(b: *std.Build) void { .flags = &.{} }); - { const tests = b.addTest(.{ .root_module = mod diff --git a/libs/tiled/src/xml.zig b/libs/tiled/src/xml.zig index e6c7f0c..661c065 100644 --- a/libs/tiled/src/xml.zig +++ b/libs/tiled/src/xml.zig @@ -520,7 +520,6 @@ pub const Lexer = struct { try self.skipWhiteSpace(); if (try self.takeByte() != '=') { - std.debug.print("{s}\n", .{self.buffers.text.items[self.cursor..]}); return error.MissingAttributeEquals; } try self.skipWhiteSpace(); diff --git a/src/engine/graphics.zig b/src/engine/graphics.zig index ac28294..c1c30d7 100644 --- a/src/engine/graphics.zig +++ b/src/engine/graphics.zig @@ -27,8 +27,14 @@ const tracy = @import("tracy"); // * https://github.com/nimgl/nimgl/issues/59 const Options = struct { + const ImguiFont = struct { + ttf_data: []const u8, + size: f32 = 16 + }; + allocator: std.mem.Allocator, logger: sg.Logger = .{}, + imgui_font: ?ImguiFont = null }; const DrawFrame = struct { @@ -88,6 +94,7 @@ pub fn init(options: Options) !void { .func = options.logger.func, .user_data = options.logger.user_data }, + .no_default_font = options.imgui_font != null, // TODO: Figure out a way to make imgui play nicely with UI // Ideally when mouse is inside a Imgui window, then the imgui cursor should be used. @@ -95,6 +102,10 @@ pub fn init(options: Options) !void { .disable_set_mouse_cursor = true }); + if (options.imgui_font) |imgui_font| { + imgui.addFont(imgui_font.ttf_data, imgui_font.size); + } + linear_sampler = sg.makeSampler(.{ .min_filter = .LINEAR, .mag_filter = .LINEAR, diff --git a/src/engine/root.zig b/src/engine/root.zig index a4f1b7d..6f12647 100644 --- a/src/engine/root.zig +++ b/src/engine/root.zig @@ -142,7 +142,10 @@ fn sokolInit(self: *Engine) !void { try Gfx.init(.{ .allocator = self.allocator, - .logger = .{ .func = sokolLogCallback } + .logger = .{ .func = sokolLogCallback }, + .imgui_font = .{ + .ttf_data = @embedFile("../assets/roboto-font/Roboto-Regular.ttf"), + } }); self.assets = try Assets.init(); diff --git a/src/engine/shell.html b/src/engine/shell.html new file mode 100644 index 0000000..5b3aae6 --- /dev/null +++ b/src/engine/shell.html @@ -0,0 +1,53 @@ + + + + + + Sokol + + + + + + {{{ SCRIPT }}} + +