From 2cf56693e23d5b5285305fc30f4496cb7942659c Mon Sep 17 00:00:00 2001 From: copygirl Date: Wed, 6 Mar 2024 12:19:29 +0100 Subject: [PATCH] Use builtin Flecs types --- README.md | 2 +- src/entity.zig | 5 ++++- src/test/flecs/entity.zig | 7 +++++-- src/test/flecs/world.zig | 7 +++++-- src/world.zig | 5 ++++- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index fd40743..5f11514 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ pub fn main() !void { _ = try world.component(Velocity); // Register a system that moves any entity that has a `Position` by `Velocity` each update. - _ = try world.system("Move", move, flecs.c.EcsOnUpdate, "Position, [in] Velocity"); + _ = try world.system("Move", move, null, "Position, [in] Velocity"); // Create an entity with both `Position` and `Velocity` already pre-added. const e = try world.entity(.{ .name = "Wroom" }, .{ Position, Velocity }); diff --git a/src/entity.zig b/src/entity.zig index 006cb97..91aeaca 100644 --- a/src/entity.zig +++ b/src/entity.zig @@ -6,6 +6,9 @@ const errors = @import("./errors.zig"); const meta = @import("./meta.zig"); const Path = @import("./path.zig"); +const flecs = @import("./builtin/flecs.zig"); +const ChildOf = flecs.core.ChildOf; + pub const EntityError = error{ /// Id is `0`. IsNone, @@ -261,7 +264,7 @@ pub fn Entity(comptime ctx: anytype) type { /// Returns an iterator that yields each of this `Entity`s children. pub fn children(self: Self) World.TermIterator { - return self.world.term(.{ c.EcsChildOf, self }); + return self.world.term(.{ ChildOf, self }); } /// Returns an iterator that yields each of the targets of the diff --git a/src/test/flecs/entity.zig b/src/test/flecs/entity.zig index cccf644..cd18b7b 100644 --- a/src/test/flecs/entity.zig +++ b/src/test/flecs/entity.zig @@ -12,6 +12,9 @@ const FlecsError = flecszigble.FlecsError; const Path = flecszigble.Path; const c = flecszigble.c; +const flecs = flecszigble.flecs; +const ChildOf = flecs.core.ChildOf; + const Context = flecszigble.Context(void); const Entity = Context.Entity; const World = Context.World; @@ -94,7 +97,7 @@ test "Entity_init_id_w_scope" { const e = try world.entity(.{}, .{}); - try expect.true(e.has(.{ c.EcsChildOf, scope })); + try expect.true(e.has(.{ ChildOf, scope })); } test "Entity_init_id_name_w_scope" { @@ -110,7 +113,7 @@ test "Entity_init_id_name_w_scope" { const e = try world.entity(.{ .name = "child" }, .{}); - try expect.true(e.has(.{ c.EcsChildOf, scope })); + try expect.true(e.has(.{ ChildOf, scope })); try expect.equal("child", e.name()); const path = try e.path(flecszigble.allocator); diff --git a/src/test/flecs/world.zig b/src/test/flecs/world.zig index 62ddba0..8578b3d 100644 --- a/src/test/flecs/world.zig +++ b/src/test/flecs/world.zig @@ -10,6 +10,9 @@ const util = @import("./../util.zig"); const flecszigble = @import("../../main.zig"); const c = flecszigble.c; +const flecs = @import("../../builtin/flecs.zig"); +const OnUpdate = flecs.pipeline.OnUpdate; + const Context = flecszigble.Context(void); const World = Context.World; const Iter = Context.Iter; @@ -39,7 +42,7 @@ test "World_progress_w_0" { const e1 = try world.entity(.{}, .{ Position, Velocity }); - const move_system = try world.system("move", move, c.EcsOnUpdate, "Position, Velocity"); + const move_system = try world.system("move", move, OnUpdate, "Position, Velocity"); var ctx = util.Probe{}; c.ecs_set_ctx(world.raw, &ctx, null); @@ -76,7 +79,7 @@ test "World_progress_w_t" { const e1 = try world.entity(.{}, .{ Position, Velocity }); - const move_system = try world.system("move", move, c.EcsOnUpdate, "Position, Velocity"); + const move_system = try world.system("move", move, OnUpdate, "Position, Velocity"); var ctx = util.Probe{}; c.ecs_set_ctx(world.raw, &ctx, null); diff --git a/src/world.zig b/src/world.zig index 451c67a..8d5926e 100644 --- a/src/world.zig +++ b/src/world.zig @@ -7,6 +7,9 @@ const errors = @import("./errors.zig"); const meta = @import("./meta.zig"); const Path = @import("./path.zig"); +const flecs = @import("./builtin/flecs.zig"); +const DependsOn = flecs.core.DependsOn; + pub fn World(comptime ctx: anytype) type { return struct { const Self = @This(); @@ -183,7 +186,7 @@ pub fn World(comptime ctx: anytype) type { ) !Entity { const phase_ = Context.anyToEntity(phase); const entity_ = try if (phase_ != 0) - self.entity(.{ .name = name }, .{ .{ c.EcsDependsOn, phase_ }, phase_ }) + self.entity(.{ .name = name }, .{ .{ DependsOn, phase_ }, phase_ }) else self.entity(.{ .name = name }, .{});