Skip to content

Commit

Permalink
all: update ECS Mod(.module_tag) -> Mod(ModuleType)
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
  • Loading branch information
Stephen Gutekanst committed Dec 17, 2023
1 parent b1364d0 commit 231f41f
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 42 deletions.
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
.hash = "12207d0872fdffc8f6755638a7a997f8ac77685df742366e88710e3b7ca0e3756f8b",
},
.mach = .{
.url = "https://pkg.machengine.org/mach/8ff30c931f16d24e8801e5aa56c4974411427799.tar.gz",
.hash = "122023c305c28c287ddaf370cb0b5f1399d3554a7a5d9a44d35c7cf5a7356663f098",
.url = "https://pkg.machengine.org/mach/260802f7771c651246930455dfd7de7a75c9869a.tar.gz",
.hash = "1220a2351f6f6f261a9a1f7c17a412acc77bdaa2204daabb0b0dde03f768981a0044",
},
.mach_freetype = .{
.url = "https://pkg.machengine.org/mach-freetype/a6d971285dfe731e49f82e81c81da2b7f5c6a442.tar.gz",
Expand Down
14 changes: 8 additions & 6 deletions examples/custom-renderer/Game.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const mach = @import("mach");
const ecs = mach.ecs;
const core = mach.core;
const math = mach.math;
const Renderer = @import("Renderer.zig");

const vec3 = math.vec3;
const vec2 = math.vec2;
Expand Down Expand Up @@ -30,11 +31,12 @@ pub const components = struct {
// unique.
//
pub const name = .game;
pub const Mod = mach.Mod(@This());

pub fn init(
engine: *mach.Mod(.engine),
renderer: *mach.Mod(.renderer),
game: *mach.Mod(.game),
engine: *mach.Engine.Mod,
renderer: *Renderer.Mod,
game: *Mod,
) !void {
// The Mach .core is where we set window options, etc.
core.setTitle("Hello, ECS!");
Expand All @@ -55,9 +57,9 @@ pub fn init(
}

pub fn tick(
engine: *mach.Mod(.engine),
renderer: *mach.Mod(.renderer),
game: *mach.Mod(.game),
engine: *mach.Engine.Mod,
renderer: *Renderer.Mod,
game: *Mod,
) !void {
// TODO(engine): event polling should occur in mach.Engine module and get fired as ECS events.
var iter = core.pollEvents();
Expand Down
11 changes: 6 additions & 5 deletions examples/custom-renderer/Renderer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bind_groups: [num_bind_groups]*gpu.BindGroup,
uniform_buffer: *gpu.Buffer,

pub const name = .renderer;
pub const Mod = mach.Mod(@This());

pub const components = struct {
pub const location = Vec3;
Expand All @@ -32,8 +33,8 @@ const UniformBufferObject = packed struct {
};

pub fn init(
engine: *mach.Mod(.engine),
renderer: *mach.Mod(.renderer),
engine: *mach.Engine.Mod,
renderer: *Mod,
) !void {
const device = engine.state.device;
const shader_module = device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl"));
Expand Down Expand Up @@ -97,7 +98,7 @@ pub fn init(
}

pub fn deinit(
renderer: *mach.Mod(.renderer),
renderer: *Mod,
) !void {
renderer.state.pipeline.release();
renderer.state.queue.release();
Expand All @@ -106,8 +107,8 @@ pub fn deinit(
}

pub fn tick(
engine: *mach.Mod(.engine),
renderer: *mach.Mod(.renderer),
engine: *mach.Engine.Mod,
renderer: *Mod,
) !void {
const device = engine.state.device;

Expand Down
21 changes: 12 additions & 9 deletions examples/glyphs/Game.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const Vec3 = math.Vec3;
const Mat3x3 = math.Mat3x3;
const Mat4x4 = math.Mat4x4;

const Text = @import("Text.zig");

timer: mach.Timer,
player: mach.ecs.EntityID,
direction: Vec2 = vec2(0, 0),
Expand All @@ -36,17 +38,18 @@ const d0 = 0.000001;
// unique.
//
pub const name = .game;
pub const Mod = mach.Mod(@This());

pub const Pipeline = enum(u32) {
default,
text,
};

pub fn init(
engine: *mach.Mod(.engine),
sprite_mod: *mach.Mod(.mach_gfx_sprite),
text_mod: *mach.Mod(.game_text),
game: *mach.Mod(.game),
engine: *mach.Engine.Mod,
sprite_mod: *Sprite.Mod,
text_mod: *Text.Mod,
game: *Mod,
) !void {
// The Mach .core is where we set window options, etc.
core.setTitle("gfx.Sprite example");
Expand All @@ -62,7 +65,7 @@ pub fn init(
}});

// We can create entities, and set components on them. Note that components live in a module
// namespace, e.g. the `.mach_gfx_sprite` module could have a 3D `.location` component with a different
// namespace, e.g. the `Sprite` module could have a 3D `.location` component with a different
// type than the `.physics2d` module's `.location` component if you desire.

const r = text_mod.state.regions.get('?').?;
Expand All @@ -86,10 +89,10 @@ pub fn init(
}

pub fn tick(
engine: *mach.Mod(.engine),
sprite_mod: *mach.Mod(.mach_gfx_sprite),
text_mod: *mach.Mod(.game_text),
game: *mach.Mod(.game),
engine: *mach.Engine.Mod,
sprite_mod: *Sprite.Mod,
text_mod: *Text.Mod,
game: *Mod,
) !void {
// TODO(engine): event polling should occur in mach.Engine module and get fired as ECS events.
var iter = core.pollEvents();
Expand Down
13 changes: 7 additions & 6 deletions examples/glyphs/Text.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const std = @import("std");
const assets = @import("assets");

pub const name = .game_text;
pub const Mod = mach.Mod(@This());

const RegionMap = std.AutoArrayHashMapUnmanaged(u21, mach.gfx.Atlas.Region);

Expand All @@ -16,8 +17,8 @@ face: ft.Face,
regions: RegionMap = .{},

pub fn deinit(
engine: *mach.Mod(.engine),
text_mod: *mach.Mod(.game_text),
engine: *mach.Engine.Mod,
text_mod: *Mod,
) !void {
text_mod.state.texture_atlas.deinit(engine.allocator);
text_mod.state.texture.release();
Expand All @@ -28,8 +29,8 @@ pub fn deinit(

pub const local = struct {
pub fn init(
engine: *mach.Mod(.engine),
text_mod: *mach.Mod(.game_text),
engine: *mach.Engine.Mod,
text_mod: *Mod,
) !void {
const device = engine.state.device;

Expand Down Expand Up @@ -65,8 +66,8 @@ pub const local = struct {
}

pub fn prepare(
engine: *mach.Mod(.engine),
text_mod: *mach.Mod(.game_text),
engine: *mach.Engine.Mod,
text_mod: *Mod,
codepoints: []const u21,
) !void {
const device = engine.state.device;
Expand Down
15 changes: 8 additions & 7 deletions examples/sprite/Game.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ const d0 = 0.000001;
// unique.
//
pub const name = .game;
pub const Mod = mach.Mod(@This());

pub const Pipeline = enum(u32) {
default,
};

pub fn init(
engine: *mach.Mod(.engine),
sprite_mod: *mach.Mod(.mach_gfx_sprite),
game: *mach.Mod(.game),
engine: *mach.Engine.Mod,
sprite_mod: *Sprite.Mod,
game: *Mod,
) !void {
// The Mach .core is where we set window options, etc.
core.setTitle("gfx.Sprite example");
Expand Down Expand Up @@ -82,9 +83,9 @@ pub fn init(
}

pub fn tick(
engine: *mach.Mod(.engine),
sprite_mod: *mach.Mod(.mach_gfx_sprite),
game: *mach.Mod(.game),
engine: *mach.Engine.Mod,
sprite_mod: *Sprite.Mod,
game: *Mod,
) !void {
// TODO(engine): event polling should occur in mach.Engine module and get fired as ECS events.
var iter = core.pollEvents();
Expand Down Expand Up @@ -194,7 +195,7 @@ pub fn tick(

// TODO: move this helper into gfx module
fn loadTexture(
engine: *mach.Mod(.engine),
engine: *mach.Engine.Mod,
) !*gpu.Texture {
const device = engine.state.device;
const queue = device.getQueue();
Expand Down
15 changes: 8 additions & 7 deletions examples/text/Game.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const d0 = 0.000001;
// unique.
//
pub const name = .game;
pub const Mod = mach.Mod(@This());

pub const Pipeline = enum(u32) {
default,
Expand All @@ -49,9 +50,9 @@ pub const Pipeline = enum(u32) {
const upscale = 1.0;

pub fn init(
engine: *mach.Mod(.engine),
text_mod: *mach.Mod(.mach_gfx_text),
game: *mach.Mod(.game),
engine: *mach.Engine.Mod,
text_mod: *Text.Mod,
game: *Mod,
) !void {
// The Mach .core is where we set window options, etc.
core.setTitle("gfx.Text example");
Expand Down Expand Up @@ -104,14 +105,14 @@ pub fn init(
};
}

pub fn deinit(engine: *mach.Mod(.engine)) !void {
pub fn deinit(engine: *mach.Engine.Mod) !void {
_ = engine;
}

pub fn tick(
engine: *mach.Mod(.engine),
text_mod: *mach.Mod(.mach_gfx_text),
game: *mach.Mod(.game),
engine: *mach.Engine.Mod,
text_mod: *Text.Mod,
game: *Mod,
) !void {
// TODO(engine): event polling should occur in mach.Engine module and get fired as ECS events.
var iter = core.pollEvents();
Expand Down

0 comments on commit 231f41f

Please sign in to comment.