Skip to content

Commit

Permalink
build: Update to latest mach build system update, constants rename
Browse files Browse the repository at this point in the history
  • Loading branch information
foxnne committed Feb 18, 2025
1 parent d2d0a15 commit a379eb6
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 43 deletions.
33 changes: 21 additions & 12 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,24 @@ pub fn build(b: *std.Build) !void {
.root_source_file = b.path("src/pixi.zig"),
});

// Create our Mach pixi module, where all our code lives.
const pixi_mod = b.createModule(.{
.root_source_file = b.path("src/pixi.zig"),
.optimize = optimize,
.target = target,
});

const zstbi = b.dependency("zstbi", .{ .target = target, .optimize = optimize });
const zmath = b.dependency("zmath", .{ .target = target, .optimize = optimize });

const zip_pkg = zip.package(b, .{});

// Add Mach import to our app.
const mach_dep = b.dependency("mach", .{
.target = target,
.optimize = optimize,
.core = true,
});
pixi_mod.addImport("mach", mach_dep.module("mach"));

const zig_imgui_dep = b.dependency("zig_imgui", .{ .target = target, .optimize = optimize });

Expand All @@ -38,12 +46,14 @@ pub fn build(b: *std.Build) !void {
},
});

const exe = b.addExecutable(.{
.name = "pixi",
.root_source_file = b.path("src/pixi.zig"),
// Have Mach create the executable for us
const exe = @import("mach").addExecutable(mach_dep.builder, .{
.name = "Pixi",
.app = pixi_mod,
.target = target,
.optimize = optimize,
});
b.installArtifact(exe);

if (optimize != .Debug) {
switch (target.result.os.tag) {
Expand All @@ -55,16 +65,15 @@ pub fn build(b: *std.Build) !void {
const run_cmd = b.addRunArtifact(exe);
const run_step = b.step("run", "Run the example");

exe.root_module.addImport("mach", mach_dep.module("mach"));
exe.root_module.addImport("zstbi", zstbi.module("root"));
exe.root_module.addImport("zmath", zmath.module("root"));
exe.root_module.addImport("nfd", nfd.getModule(b));
exe.root_module.addImport("zip", zip_pkg.module);
exe.root_module.addImport("zig-imgui", imgui_module);
//exe.root_module.addImport("pixi", module);
pixi_mod.addImport("mach", mach_dep.module("mach"));
pixi_mod.addImport("zstbi", zstbi.module("root"));
pixi_mod.addImport("zmath", zmath.module("root"));
pixi_mod.addImport("nfd", nfd.getModule(b));
pixi_mod.addImport("zip", zip_pkg.module);
pixi_mod.addImport("zig-imgui", imgui_module);

const nfd_lib = nfd.makeLib(b, target, optimize);
exe.root_module.addImport("nfd", nfd_lib);
pixi_mod.addImport("nfd", nfd_lib);

if (target.result.isDarwin()) {
// // MacOS: this must be defined for macOS 13.3 and older.
Expand Down
5 changes: 2 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
.version = "0.0.2",
.dependencies = .{
.mach = .{
//.path = "src/.temp/mach-dev/",
.url = "https://pkg.machengine.org/mach/2410814e916970672a837c2d67a5a0a3f927ca4b.tar.gz",
.hash = "1220a7773e217670fcd702abdbd6a792fa293449334e8245eecfe887c67611660cc3",
.url = "https://pkg.machengine.org/mach/b14f8e69ee8eb834695eb0d0582053e555d10156.tar.gz",
.hash = "12208832468a607cf5da2e724b4386dd41c433b08e98b1ef28302f0f981e96045c1d",
},
.zig_imgui = .{
//.path = "src/.temp/zig-imgui/",
Expand Down
5 changes: 2 additions & 3 deletions src/editor/Constants.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const std = @import("std");
const pixi = @import("../pixi.zig");

pub const layer_name_max_length = 128;
pub const animation_name_max_length = 128;
pub const file_name_max_length = std.fs.max_path_bytes;
pub const max_name_len = 128;
pub const max_path_len = std.fs.max_path_bytes;
3 changes: 1 addition & 2 deletions src/editor/Editor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const pixi = @import("../pixi.zig");

const App = pixi.App;
const Core = mach.Core;
const Editor = @This();

pub const Settings = @import("Settings.zig");
pub const Colors = @import("Colors.zig");
Expand All @@ -20,8 +21,6 @@ const nfd = @import("nfd");
const imgui = @import("zig-imgui");
const zmath = @import("zmath");

pub const Editor = @This();

// Modules
pub const Explorer = @import("explorer/Explorer.zig");
pub const Popups = @import("popups/Popups.zig");
Expand Down
2 changes: 1 addition & 1 deletion src/editor/artboard/Artboard.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn draw(artboard: *Artboard, core: *Core, app: *App, editor: *Editor, packer
.y = app.window_size[1] + 5.0,
}, imgui.Cond_None);

imgui.pushStyleVarImVec2(imgui.StyleVar_WindowPadding, .{ .x = 0.0, .y = 0.5 });
imgui.pushStyleVarImVec2(imgui.StyleVar_WindowPadding, .{ .x = 0.0, .y = 0.0 });
imgui.pushStyleVar(imgui.StyleVar_TabRounding, 0.0);
imgui.pushStyleVar(imgui.StyleVar_ChildBorderSize, 1.0);
defer imgui.popStyleVarEx(3);
Expand Down
2 changes: 1 addition & 1 deletion src/editor/artboard/flipbook/menu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn draw(file: *pixi.Internal.File, mouse_ratio: f32, editor: *Editor) !void
// Apply history of animation state
var change: History.Change = .{ .animation = .{
.index = file.selected_animation_index,
.name = [_:0]u8{0} ** Editor.Constants.animation_name_max_length,
.name = [_:0]u8{0} ** Editor.Constants.max_name_len,
.fps = animation.fps,
.start = animation.start,
.length = animation.length,
Expand Down
6 changes: 3 additions & 3 deletions src/editor/explorer/layers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn draw(editor: *Editor) !void {

imgui.spacing();
if (imgui.smallButton(pixi.fa.plus)) {
editor.popups.layer_setup_name = [_:0]u8{0} ** Editor.Constants.layer_name_max_length;
editor.popups.layer_setup_name = [_:0]u8{0} ** Editor.Constants.max_name_len;
std.mem.copyForwards(u8, &editor.popups.layer_setup_name, "New Layer");
editor.popups.layer_setup_state = .none;
editor.popups.layer_setup = true;
Expand Down Expand Up @@ -133,7 +133,7 @@ pub fn draw(editor: *Editor) !void {
defer imgui.endPopup();

if (imgui.menuItem("Rename...")) {
editor.popups.layer_setup_name = [_:0]u8{0} ** Editor.Constants.layer_name_max_length;
editor.popups.layer_setup_name = [_:0]u8{0} ** Editor.Constants.max_name_len;
@memcpy(editor.popups.layer_setup_name[0..layer.name.len], layer.name);
editor.popups.layer_setup_index = i;
editor.popups.layer_setup_state = .rename;
Expand All @@ -143,7 +143,7 @@ pub fn draw(editor: *Editor) !void {
if (imgui.menuItem("Duplicate...")) {
const new_name = try std.fmt.allocPrint(pixi.app.allocator, "{s}_copy", .{layer.name});
defer pixi.app.allocator.free(new_name);
editor.popups.layer_setup_name = [_:0]u8{0} ** Editor.Constants.layer_name_max_length;
editor.popups.layer_setup_name = [_:0]u8{0} ** Editor.Constants.max_name_len;
@memcpy(editor.popups.layer_setup_name[0..new_name.len], new_name);
editor.popups.layer_setup_index = i;
editor.popups.layer_setup_state = .duplicate;
Expand Down
12 changes: 6 additions & 6 deletions src/editor/popups/Popups.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ pub const popup_references = @import("references.zig");
// Renaming
rename: bool = false,
rename_state: RenameState = .none,
rename_path: [std.fs.max_path_bytes:0]u8 = undefined,
rename_old_path: [std.fs.max_path_bytes:0]u8 = undefined,
rename_path: [Editor.Constants.max_path_len:0]u8 = undefined,
rename_old_path: [Editor.Constants.max_path_len:0]u8 = undefined,
// File setup
file_setup: bool = false,
file_setup_state: SetupState = .none,
file_setup_path: [std.fs.max_path_bytes:0]u8 = undefined,
file_setup_png_path: [std.fs.max_path_bytes:0]u8 = undefined,
file_setup_path: [Editor.Constants.max_path_len:0]u8 = undefined,
file_setup_png_path: [Editor.Constants.max_path_len:0]u8 = undefined,
file_setup_tile_size: [2]i32 = .{ 32, 32 },
file_setup_tiles: [2]i32 = .{ 32, 32 },
file_setup_width: i32 = 0,
Expand All @@ -45,7 +45,7 @@ file_confirm_close_exit: bool = false,
// Layer Setup
layer_setup: bool = false,
layer_setup_state: RenameState = .none,
layer_setup_name: [Editor.Constants.layer_name_max_length:0]u8 = undefined,
layer_setup_name: [Editor.Constants.max_name_len:0]u8 = undefined,
layer_setup_index: usize = 0,
// Export to png
export_to_png: bool = false,
Expand All @@ -58,7 +58,7 @@ animation_index: usize = 0,
animation_state: AnimationState = .none,
animation_start: usize = 0,
animation_length: usize = 0,
animation_name: [Editor.Constants.animation_name_max_length:0]u8 = undefined,
animation_name: [Editor.Constants.max_name_len:0]u8 = undefined,
animation_fps: usize = 0,

heightmap: bool = false,
Expand Down
8 changes: 4 additions & 4 deletions src/internal/File.zig
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ pub fn processAnimationTool(file: *File) !void {
}
if (valid) {
// Create new animation
pixi.editor.popups.animation_name = [_:0]u8{0} ** Editor.Constants.animation_name_max_length;
pixi.editor.popups.animation_name = [_:0]u8{0} ** Editor.Constants.max_name_len;
const new_name = "New_Animation";
@memcpy(pixi.editor.popups.animation_name[0..new_name.len], new_name);
pixi.editor.popups.animation_state = .create;
Expand All @@ -1010,7 +1010,7 @@ pub fn processAnimationTool(file: *File) !void {
// Edit existing animation
var change: History.Change = .{ .animation = .{
.index = file.selected_animation_index,
.name = [_:0]u8{0} ** Editor.Constants.animation_name_max_length,
.name = [_:0]u8{0} ** Editor.Constants.max_name_len,
.fps = animation.fps,
.start = animation.start,
.length = animation.length,
Expand Down Expand Up @@ -2097,7 +2097,7 @@ pub fn createLayer(self: *File, name: [:0]const u8) !void {

pub fn renameLayer(file: *File, name: [:0]const u8, index: usize) !void {
var change: History.Change = .{ .layer_name = .{
.name = [_:0]u8{0} ** Editor.Constants.layer_name_max_length,
.name = [_:0]u8{0} ** Editor.Constants.max_name_len,
.index = index,
} };
@memcpy(change.layer_name.name[0..file.layers.items(.name)[index].len], file.layers.items(.name)[index]);
Expand Down Expand Up @@ -2154,7 +2154,7 @@ pub fn renameAnimation(self: *File, name: []const u8, index: usize) !void {
const animation = self.animations.slice().get(index);
var change: History.Change = .{ .animation = .{
.index = index,
.name = [_:0]u8{0} ** Editor.Constants.animation_name_max_length,
.name = [_:0]u8{0} ** Editor.Constants.max_name_len,
.fps = animation.fps,
.start = animation.start,
.length = animation.length,
Expand Down
14 changes: 7 additions & 7 deletions src/internal/History.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub const Change = union(ChangeType) {

pub const Animation = struct {
index: usize,
name: [Editor.Constants.animation_name_max_length:0]u8,
name: [Editor.Constants.max_name_len:0]u8,
fps: usize,
start: usize,
length: usize,
Expand All @@ -56,7 +56,7 @@ pub const Change = union(ChangeType) {
};
pub const LayerName = struct {
index: usize,
name: [Editor.Constants.layer_name_max_length:0]u8,
name: [Editor.Constants.max_name_len:0]u8,
};
pub const LayerSettings = struct {
index: usize,
Expand Down Expand Up @@ -107,7 +107,7 @@ pub const Change = union(ChangeType) {
.selected = 0,
} },
.layer_name => .{ .layer_name = .{
.name = [_:0]u8{0} ** Editor.Constants.layer_name_max_length,
.name = [_:0]u8{0} ** Editor.Constants.max_name_len,
.index = 0,
} },
else => error.NotSupported,
Expand Down Expand Up @@ -338,9 +338,9 @@ pub fn undoRedo(self: *History, file: *pixi.Internal.File, action: Action) !void
pixi.editor.explorer.pane = .tools;
},
.layer_name => |*layer_name| {
var name = [_:0]u8{0} ** Editor.Constants.layer_name_max_length;
var name = [_:0]u8{0} ** Editor.Constants.max_name_len;
@memcpy(name[0..layer_name.name.len], &layer_name.name);
layer_name.name = [_:0]u8{0} ** Editor.Constants.layer_name_max_length;
layer_name.name = [_:0]u8{0} ** Editor.Constants.max_name_len;
@memcpy(layer_name.name[0..file.layers.items(.name)[layer_name.index].len], file.layers.items(.name)[layer_name.index]);
pixi.app.allocator.free(file.layers.items(.name)[layer_name.index]);
file.layers.items(.name)[layer_name.index] = try pixi.app.allocator.dupeZ(u8, &name);
Expand All @@ -357,9 +357,9 @@ pub fn undoRedo(self: *History, file: *pixi.Internal.File, action: Action) !void
},
.animation => |*animation| {
// Name
var name = [_:0]u8{0} ** Editor.Constants.animation_name_max_length;
var name = [_:0]u8{0} ** Editor.Constants.max_name_len;
@memcpy(name[0..animation.name.len], &animation.name);
animation.name = [_:0]u8{0} ** Editor.Constants.animation_name_max_length;
animation.name = [_:0]u8{0} ** Editor.Constants.max_name_len;
@memcpy(animation.name[0..file.animations.items(.name)[animation.index].len], file.animations.items(.name)[animation.index]);
pixi.app.allocator.free(file.animations.items(.name)[animation.index]);
file.animations.items(.name)[animation.index] = try pixi.app.allocator.dupeZ(u8, std.mem.trimRight(u8, &name, "\u{0}"));
Expand Down
2 changes: 1 addition & 1 deletion src/pixi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub const Sidebar = @import("editor/Sidebar.zig");
pub const Assets = @import("tools/Assets.zig");

// The set of Mach modules our application may use.
const Modules = mach.Modules(.{
pub const Modules = mach.Modules(.{
App,
Artboard,
Core,
Expand Down

0 comments on commit a379eb6

Please sign in to comment.