Skip to content

Commit

Permalink
build: Clean up and add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
foxnne committed Feb 18, 2025
1 parent 3842a5a commit f639716
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 49 deletions.
9 changes: 5 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

// Create our Mach pixi module, where all our code lives.
// Create our pixi module, where our Modules declaration lives
const pixi_mod = b.createModule(.{
.root_source_file = b.path("src/pixi.zig"),
.optimize = optimize,
Expand All @@ -26,12 +26,11 @@ pub fn build(b: *std.Build) !void {

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

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

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

Expand All @@ -43,7 +42,9 @@ pub fn build(b: *std.Build) !void {
});

// Have Mach create the executable for us
const exe = @import("mach").addExecutable(mach_dep.builder, .{
// The mod we pass as .app must contain the Modules definition
// And the Modules must include an App containing the main schedule
const exe = mach.addExecutable(mach_dep.builder, .{
.name = "Pixi",
.app = pixi_mod,
.target = target,
Expand Down
2 changes: 1 addition & 1 deletion src/App.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Assets = pixi.Assets;
pub const mach_module = .app;
pub const mach_systems = .{ .main, .init, .lateInit, .tick, .deinit };

// pixi.zig `main()` runs this schedule
// mach entrypoint module runs this schedule
pub const main = mach.schedule(.{
.{ Core, .init },
.{ App, .init },
Expand Down
76 changes: 32 additions & 44 deletions src/pixi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@ pub const gfx = @import("gfx/gfx.zig");
pub const input = @import("input/input.zig");
pub const math = @import("math/math.zig");

// Modules

/// App contains the main schedule, which is run by the mach entrypoint
pub const App = @import("App.zig");
pub const Artboard = @import("editor/artboard/Artboard.zig");
pub const Assets = @import("tools/Assets.zig");
pub const Editor = @import("editor/Editor.zig");
pub const Explorer = @import("editor/explorer/Explorer.zig");
pub const Packer = @import("tools/Packer.zig");
pub const Popups = @import("editor/popups/Popups.zig");
pub const Sidebar = @import("editor/Sidebar.zig");

// The set of Mach modules our application may use.
pub const Modules = mach.Modules(.{
App,
Artboard,
Assets,
Core,
Editor,
Explorer,
Packer,
Popups,
Sidebar,
});

// Global pointers
pub var core: *Core = undefined;
pub var app: *App = undefined;
pub var editor: *Editor = undefined;
pub var packer: *Packer = undefined;
pub var assets: *Assets = undefined;

/// Internal types
/// These types contain additional data to support the editor
/// An example of this is File. pixi.File matches the file type to read from JSON,
Expand Down Expand Up @@ -56,47 +88,3 @@ pub const Layer = @import("Layer.zig");

/// Source location within the atlas texture, and origin location
pub const Sprite = @import("Sprite.zig");

// Global pointers
pub var core: *Core = undefined;
pub var app: *App = undefined;
pub var editor: *Editor = undefined;
pub var packer: *Packer = undefined;
pub var assets: *Assets = undefined;

// Modules
pub const App = @import("App.zig");
pub const Editor = @import("editor/Editor.zig");
pub const Packer = @import("tools/Packer.zig");
pub const Popups = @import("editor/popups/Popups.zig");
pub const Explorer = @import("editor/explorer/Explorer.zig");
pub const Artboard = @import("editor/artboard/Artboard.zig");
pub const Sidebar = @import("editor/Sidebar.zig");
pub const Assets = @import("tools/Assets.zig");

// The set of Mach modules our application may use.
pub const Modules = mach.Modules(.{
App,
Artboard,
Core,
Editor,
Explorer,
Packer,
Popups,
Sidebar,
Assets,
});

// TODO: move this to a mach "entrypoint" zig module which handles nuances like WASM requires.
pub fn main() !void {
const allocator = std.heap.c_allocator;

// The set of Mach modules our application may use.
var mods: Modules = undefined;
try mods.init(allocator);
// TODO: enable mods.deinit(allocator); for allocator leak detection
defer mods.deinit(allocator);

const application = mods.get(.app);
application.run(.main);
}

0 comments on commit f639716

Please sign in to comment.