Use builtin Flecs types

main
copygirl 2 months ago
parent d9882bf86e
commit 2cf56693e2
  1. 2
      README.md
  2. 5
      src/entity.zig
  3. 7
      src/test/flecs/entity.zig
  4. 7
      src/test/flecs/world.zig
  5. 5
      src/world.zig

@ -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 });

@ -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

@ -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);

@ -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);

@ -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 }, .{});

Loading…
Cancel
Save