From 231f41f38e3e7db24fafd34beec1b3be9a546adb Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 16 Dec 2023 23:04:54 -0700 Subject: [PATCH] all: update ECS Mod(.module_tag) -> Mod(ModuleType) Signed-off-by: Stephen Gutekanst --- build.zig.zon | 4 ++-- examples/custom-renderer/Game.zig | 14 ++++++++------ examples/custom-renderer/Renderer.zig | 11 ++++++----- examples/glyphs/Game.zig | 21 ++++++++++++--------- examples/glyphs/Text.zig | 13 +++++++------ examples/sprite/Game.zig | 15 ++++++++------- examples/text/Game.zig | 15 ++++++++------- 7 files changed, 51 insertions(+), 42 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index ac178025..fb8bede1 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -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", diff --git a/examples/custom-renderer/Game.zig b/examples/custom-renderer/Game.zig index d53f2974..a94a2c2d 100644 --- a/examples/custom-renderer/Game.zig +++ b/examples/custom-renderer/Game.zig @@ -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; @@ -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!"); @@ -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(); diff --git a/examples/custom-renderer/Renderer.zig b/examples/custom-renderer/Renderer.zig index 299cf933..f998edff 100644 --- a/examples/custom-renderer/Renderer.zig +++ b/examples/custom-renderer/Renderer.zig @@ -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; @@ -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")); @@ -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(); @@ -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; diff --git a/examples/glyphs/Game.zig b/examples/glyphs/Game.zig index 11358362..40c6302b 100644 --- a/examples/glyphs/Game.zig +++ b/examples/glyphs/Game.zig @@ -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), @@ -36,6 +38,7 @@ const d0 = 0.000001; // unique. // pub const name = .game; +pub const Mod = mach.Mod(@This()); pub const Pipeline = enum(u32) { default, @@ -43,10 +46,10 @@ pub const Pipeline = enum(u32) { }; 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"); @@ -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('?').?; @@ -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(); diff --git a/examples/glyphs/Text.zig b/examples/glyphs/Text.zig index fa017ff0..70d3f022 100644 --- a/examples/glyphs/Text.zig +++ b/examples/glyphs/Text.zig @@ -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); @@ -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(); @@ -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; @@ -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; diff --git a/examples/sprite/Game.zig b/examples/sprite/Game.zig index 92502a66..35db304e 100644 --- a/examples/sprite/Game.zig +++ b/examples/sprite/Game.zig @@ -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"); @@ -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(); @@ -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(); diff --git a/examples/text/Game.zig b/examples/text/Game.zig index f99a9042..5b2f3d3a 100644 --- a/examples/text/Game.zig +++ b/examples/text/Game.zig @@ -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, @@ -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"); @@ -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();