Use "flecszigble" name when important this lib

main
copygirl 9 months ago
parent deb1104944
commit 2bc8f54a83
  1. 6
      README.md
  2. 24
      src/entity.zig
  3. 6
      src/id.zig
  4. 10
      src/iter.zig
  5. 6
      src/pair.zig
  6. 112
      src/test/flecs/entity.zig
  7. 10
      src/test/flecs/world.zig
  8. 6
      src/test/util.zig
  9. 31
      src/world.zig

@ -12,8 +12,8 @@ This library is still very much work-in-progress and not ready for use. It's ava
```zig
const std = @import("std");
const flecs = @import("flecs-zig-ble");
const Context = flecs.Context(void);
const flecszigble = @import("flecs-zig-ble");
const Context = flecszigble.Context(void);
const World = Context.World;
const Iter = Context.Iter;
@ -22,7 +22,7 @@ const Velocity = struct { x: f32, y: f32 };
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
flecs.init(gpa.allocator());
flecszigble.init(gpa.allocator());
const world = try World.init();
defer world.deinit();

@ -2,9 +2,9 @@ const std = @import("std");
const Allocator = std.mem.Allocator;
const meta = @import("./meta.zig");
const flecs = @import("./main.zig");
const Path = flecs.Path;
const c = flecs.c;
const flecszigble = @import("./main.zig");
const Path = flecszigble.Path;
const c = flecszigble.c;
pub const EntityError = error{
/// Id is `0`.
@ -39,7 +39,7 @@ pub fn Entity(comptime ctx: anytype) type {
return struct {
const Self = @This();
const Context = flecs.Context(ctx);
const Context = flecszigble.Context(ctx);
const World = Context.World;
const Id = Context.Id;
@ -133,7 +133,7 @@ pub fn Entity(comptime ctx: anytype) type {
var desc = std.mem.zeroInit(c.ecs_entity_desc_t, .{ .sep = "".ptr, .name = n.ptr });
desc.add[0] = c.ecs_pair(c.EcsChildOf, parent_);
scope = c.ecs_entity_init(world.raw, &desc);
if (scope == 0) return flecs.getLastErrorOrUnknown();
if (scope == 0) return flecszigble.getLastErrorOrUnknown();
} else scope = found;
},
}
@ -162,7 +162,7 @@ pub fn Entity(comptime ctx: anytype) type {
return error.FoundChildOf;
const result = c.ecs_entity_init(world.raw, &desc);
if (result == 0) return flecs.getLastErrorOrUnknown();
if (result == 0) return flecszigble.getLastErrorOrUnknown();
return Self.fromRaw(world, result);
}
@ -346,8 +346,8 @@ pub fn Entity(comptime ctx: anytype) type {
const expect = @import("./test/expect.zig");
test "Entity get and set" {
flecs.init(std.testing.allocator);
var world = try flecs.World(void).initMinimal();
flecszigble.init(std.testing.allocator);
var world = try flecszigble.World(void).initMinimal();
defer world.deinit();
const Position = struct { x: f32, y: f32 };
@ -369,8 +369,8 @@ test "Entity get and set" {
}
test "Entity getMut" {
flecs.init(std.testing.allocator);
var world = try flecs.World(void).initMinimal();
flecszigble.init(std.testing.allocator);
var world = try flecszigble.World(void).initMinimal();
defer world.deinit();
const Position = struct { x: f32, y: f32 };
@ -396,8 +396,8 @@ test "Entity getMut" {
}
test "Entity set and get with pair type" {
flecs.init(std.testing.allocator);
var world = try flecs.World(void).initMinimal();
flecszigble.init(std.testing.allocator);
var world = try flecszigble.World(void).initMinimal();
defer world.deinit();
const Position = struct { x: f32, y: f32 };

@ -1,5 +1,5 @@
const flecs = @import("./main.zig");
const c = flecs.c;
const flecszigble = @import("./main.zig");
const c = flecszigble.c;
pub const IdError = error{
/// Id is `0`.
@ -16,7 +16,7 @@ pub fn Id(comptime ctx: anytype) type {
return struct {
const Self = @This();
const Context = flecs.Context(ctx);
const Context = flecszigble.Context(ctx);
const World = Context.World;
const Entity = Context.Entity;
const Pair = Context.Pair;

@ -1,11 +1,11 @@
const flecs = @import("./main.zig");
const c = flecs.c;
const flecszigble = @import("./main.zig");
const c = flecszigble.c;
pub fn Iter(comptime ctx: anytype) type {
return struct {
const Self = @This();
const Context = flecs.Context(ctx);
const Context = flecszigble.Context(ctx);
const World = Context.World;
const Entity = Context.Entity;
const Id = Context.Id;
@ -19,14 +19,14 @@ pub fn Iter(comptime ctx: anytype) type {
}
pub fn fromRawValue(world: *World, value: c.ecs_iter_t) !Self {
const raw = try flecs.allocator.create(c.ecs_iter_t);
const raw = try flecszigble.allocator.create(c.ecs_iter_t);
raw.* = value;
return .{ .world = world, .raw = raw, .owned = true };
}
pub fn deinit(self: Self) void {
if (self.isValid()) c.ecs_iter_fini(self.raw);
if (self.owned) flecs.allocator.destroy(self.raw);
if (self.owned) flecszigble.allocator.destroy(self.raw);
}
pub fn isValid(self: Self) bool {

@ -1,5 +1,5 @@
const flecs = @import("./main.zig");
const c = flecs.c;
const flecszigble = @import("./main.zig");
const c = flecszigble.c;
pub const PairError = error{
/// Id is `0`.
@ -24,7 +24,7 @@ pub fn Pair(comptime ctx: anytype) type {
return struct {
const Self = @This();
const Context = flecs.Context(ctx);
const Context = flecszigble.Context(ctx);
const World = Context.World;
const Entity = Context.Entity;
const Id = Context.Id;

@ -7,17 +7,17 @@ const alloc = std.testing.allocator;
const expect = @import("../expect.zig");
const util = @import("../util.zig");
const flecs = @import("../../main.zig");
const FlecsError = flecs.FlecsError;
const Path = flecs.Path;
const c = flecs.c;
const flecszigble = @import("../../main.zig");
const FlecsError = flecszigble.FlecsError;
const Path = flecszigble.Path;
const c = flecszigble.c;
const Context = flecs.Context(void);
const Context = flecszigble.Context(void);
const Entity = Context.Entity;
const World = Context.World;
test "Entity_init_id" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -26,20 +26,20 @@ test "Entity_init_id" {
}
test "Entity_init_id_name" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
const e = try world.entity(.{ .name = "foo" }, .{});
try expect.equal("foo", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("foo", "{}", .{path});
}
test "Entity_init_id_path" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -48,7 +48,7 @@ test "Entity_init_id_path" {
const e = try world.entity(.{ .path = e_path }, .{});
try expect.equal("child", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("parent.child", "{}", .{path});
}
@ -56,7 +56,7 @@ test "Entity_init_id_path" {
test "Entity_init_id_add_1_comp" {
const TagA = struct {};
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -70,7 +70,7 @@ test "Entity_init_id_add_2_comp" {
const TagA = struct {};
const TagB = struct {};
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -83,7 +83,7 @@ test "Entity_init_id_add_2_comp" {
}
test "Entity_init_id_w_scope" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -98,7 +98,7 @@ test "Entity_init_id_w_scope" {
}
test "Entity_init_id_name_w_scope" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -113,13 +113,13 @@ test "Entity_init_id_name_w_scope" {
try expect.true(e.has(.{ c.EcsChildOf, scope }));
try expect.equal("child", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("parent.child", "{}", .{path});
}
test "Entity_init_id_path_w_scope" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -135,13 +135,13 @@ test "Entity_init_id_path_w_scope" {
try expect.equal("grandchild", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("parent.child.grandchild", "{}", .{path});
}
test "Entity_init_id_fullpath_w_scope" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -151,19 +151,19 @@ test "Entity_init_id_fullpath_w_scope" {
_ = world.setScope(scope);
try expect.equal(scope, world.scope());
const p = try Path.fromString("::parent.child.grandchild", .{ .root_sep = "::", .sep = "." }, flecs.allocator);
const p = try Path.fromString("::parent.child.grandchild", .{ .root_sep = "::", .sep = "." }, flecszigble.allocator);
defer p.deinit();
const e = try world.entity(.{ .path = p }, .{});
try expect.equal("grandchild", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("parent.child.grandchild", "{}", .{path});
}
test "Entity_init_id_fullpath_w_scope_existing" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -173,7 +173,7 @@ test "Entity_init_id_fullpath_w_scope_existing" {
_ = world.setScope(scope);
try expect.equal(scope, world.scope());
const p = try Path.fromString("::parent.child.grandchild", .{ .root_sep = "::", .sep = "." }, flecs.allocator);
const p = try Path.fromString("::parent.child.grandchild", .{ .root_sep = "::", .sep = "." }, flecszigble.allocator);
defer p.deinit();
const e = try world.entity(.{ .path = p }, .{});
@ -182,7 +182,7 @@ test "Entity_init_id_fullpath_w_scope_existing" {
try expect.equal("grandchild", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("parent.child.grandchild", "{}", .{path});
}
@ -190,7 +190,7 @@ test "Entity_init_id_fullpath_w_scope_existing" {
test "Entity_init_id_name_1_comp" {
const TagA = struct {};
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -200,7 +200,7 @@ test "Entity_init_id_name_1_comp" {
try expect.true(e.has(TagA));
try expect.equal("foo", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("foo", "{}", .{path});
}
@ -209,7 +209,7 @@ test "Entity_init_id_name_2_comp" {
const TagA = struct {};
const TagB = struct {};
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -220,7 +220,7 @@ test "Entity_init_id_name_2_comp" {
try expect.true(e.has(TagA));
try expect.equal("foo", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("foo", "{}", .{path});
}
@ -229,7 +229,7 @@ test "Entity_init_id_name_2_comp_w_scope" {
const TagA = struct {};
const TagB = struct {};
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -246,7 +246,7 @@ test "Entity_init_id_name_2_comp_w_scope" {
try expect.true(e.has(TagA));
try expect.equal("child", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("parent.child", "{}", .{path});
}
@ -254,7 +254,7 @@ test "Entity_init_id_name_2_comp_w_scope" {
test "Entity_id_add_1_comp" {
const TagA = struct {};
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -270,7 +270,7 @@ test "Entity_id_add_2_comp" {
const TagA = struct {};
const TagB = struct {};
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -285,22 +285,22 @@ test "Entity_id_add_2_comp" {
}
test "Entity_init_id_path_w_sep" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
const p = try Path.fromString("parent::child", .{ .root_sep = null, .sep = "::" }, flecs.allocator);
const p = try Path.fromString("parent::child", .{ .root_sep = null, .sep = "::" }, flecszigble.allocator);
defer p.deinit();
const e = try world.entity(.{ .path = p }, .{});
try expect.equal("child", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("parent.child", "{}", .{path});
}
test "Entity_find_id_name" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -312,7 +312,7 @@ test "Entity_find_id_name" {
}
test "Entity_find_w_existing_id_name" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -327,7 +327,7 @@ test "Entity_find_w_existing_id_name" {
}
test "Entity_find_id_name_w_scope" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -340,7 +340,7 @@ test "Entity_find_id_name_w_scope" {
const e = try world.entity(.{ .name = "child" }, .{});
try expect.equal("child", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("parent.child", "{}", .{path});
@ -349,7 +349,7 @@ test "Entity_find_id_name_w_scope" {
}
test "Entity_find_id_path" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -358,7 +358,7 @@ test "Entity_find_id_path" {
const e = try world.entity(.{ .path = e_path }, .{});
try expect.equal("child", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("parent.child", "{}", .{path});
@ -367,7 +367,7 @@ test "Entity_find_id_path" {
}
test "Entity_find_id_path_w_scope" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -382,7 +382,7 @@ test "Entity_find_id_path_w_scope" {
const e = try world.entity(.{ .path = e_path }, .{});
try expect.equal("grandchild", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("parent.child.grandchild", "{}", .{path});
@ -391,7 +391,7 @@ test "Entity_find_id_path_w_scope" {
}
test "Entity_find_id_name_match" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -403,7 +403,7 @@ test "Entity_find_id_name_match" {
}
test "Entity_find_id_name_match_w_scope" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -416,7 +416,7 @@ test "Entity_find_id_name_match_w_scope" {
const e = try world.entity(.{ .name = "child" }, .{});
try expect.equal("child", e.name());
const path = try e.path(flecs.allocator);
const path = try e.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("parent.child", "{}", .{path});
@ -432,7 +432,7 @@ test "Entity_find_id_name_match_w_scope" {
}
test "Entity_find_id_path_match" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -446,7 +446,7 @@ test "Entity_find_id_path_match" {
}
test "Entity_find_id_path_match_w_scope" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -473,7 +473,7 @@ test "Entity_find_id_path_match_w_scope" {
}
test "Entity_find_id_name_mismatch" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -490,7 +490,7 @@ test "Entity_find_id_name_mismatch" {
}
test "Entity_find_id_name_mismatch_w_scope" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -511,7 +511,7 @@ test "Entity_find_id_name_mismatch_w_scope" {
}
test "Entity_find_id_path_mismatch" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -530,7 +530,7 @@ test "Entity_find_id_path_mismatch" {
}
test "Entity_find_id_path_mismatch_w_scope" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -559,7 +559,7 @@ test "Entity_find_id_path_mismatch_w_scope" {
test "Entity_find_id_add_1_comp" {
const TagA = struct {};
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -577,7 +577,7 @@ test "Entity_find_id_add_2_comp" {
const TagA = struct {};
const TagB = struct {};
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -594,7 +594,7 @@ test "Entity_find_id_add_2_comp" {
}
test "Entity_init_w_scope_name" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();
@ -609,13 +609,13 @@ test "Entity_init_w_scope_name" {
const child = try world.entity(.{ .name = "foo" }, .{});
try expect.equal("foo", child.name());
const path = try child.path(flecs.allocator);
const path = try child.path(flecszigble.allocator);
defer path.deinit();
try expect.fmt("parent.foo.foo", "{}", .{path});
}
test "Entity_init_w_core_name" {
flecs.init(alloc);
flecszigble.init(alloc);
var world = try World.initMinimal();
defer world.deinit();

@ -7,10 +7,10 @@ const alloc = std.testing.allocator;
const expect = @import("./../expect.zig");
const util = @import("./../util.zig");
const flecs = @import("../../main.zig");
const c = flecs.c;
const flecszigble = @import("../../main.zig");
const c = flecszigble.c;
const Context = flecs.Context(void);
const Context = flecszigble.Context(void);
const World = Context.World;
const Iter = Context.Iter;
const Entity = Context.Entity;
@ -30,7 +30,7 @@ fn move(it: Iter) void {
}
test "World_progress_w_0" {
flecs.init(std.testing.allocator);
flecszigble.init(std.testing.allocator);
var world = try World.init();
defer world.deinit();
@ -67,7 +67,7 @@ test "World_progress_w_0" {
}
test "World_progress_w_t" {
flecs.init(std.testing.allocator);
flecszigble.init(std.testing.allocator);
var world = try World.init();
defer world.deinit();

@ -3,10 +3,10 @@ const expect = std.testing.expect;
const expectEql = std.testing.expectEqual;
const expectStrEql = std.testing.expectEqualStrings;
const flecs = @import("../main.zig");
const c = flecs.c;
const flecszigble = @import("../main.zig");
const c = flecszigble.c;
const context = flecs.Context(void);
const context = flecszigble.Context(void);
const Entity = context.Entity;
const Iter = context.Iter;
const Id = context.Id;

@ -2,45 +2,44 @@ const std = @import("std");
const Allocator = std.mem.Allocator;
const meta = @import("./meta.zig");
const flecs = @import("./main.zig");
const EntityError = flecs.EntityError;
const Path = flecs.Path;
const c = flecs.c;
const flecszigble = @import("./main.zig");
const Path = flecszigble.Path;
const c = flecszigble.c;
pub fn World(comptime ctx: anytype) type {
return struct {
const Self = @This();
const Context = flecs.Context(ctx);
const Context = flecszigble.Context(ctx);
const Entity = Context.Entity;
const Iter = Context.Iter;
raw: *c.ecs_world_t,
pub fn init() !*Self {
std.debug.assert(flecs.is_initialized);
var result = try flecs.allocator.create(Self);
std.debug.assert(flecszigble.is_initialized);
var result = try flecszigble.allocator.create(Self);
result.raw = c.ecs_init().?;
return result;
}
pub fn initWithArgs(args: [][*:0]const u8) !*Self {
std.debug.assert(flecs.is_initialized);
var result = try flecs.allocator.create(Self);
std.debug.assert(flecszigble.is_initialized);
var result = try flecszigble.allocator.create(Self);
result.raw = c.ecs_init_w_args(args.len, args.ptr).?;
return result;
}
pub fn initMinimal() !*Self {
std.debug.assert(flecs.is_initialized);
var result = try flecs.allocator.create(Self);
std.debug.assert(flecszigble.is_initialized);
var result = try flecszigble.allocator.create(Self);
result.raw = c.ecs_mini().?;
return result;
}
pub fn deinit(self: *Self) void {
_ = c.ecs_fini(self.raw);
flecs.allocator.destroy(self);
flecszigble.allocator.destroy(self);
}
pub fn progress(self: *Self, delta_time: f32) bool {
@ -113,7 +112,7 @@ pub fn World(comptime ctx: anytype) type {
});
const result = c.ecs_component_init(self.raw, &desc);
if (result == 0) return flecs.getLastErrorOrUnknown();
if (result == 0) return flecszigble.getLastErrorOrUnknown();
Context.lookupMut(T).* = result;
return Entity.fromRaw(self, result);
}
@ -176,7 +175,7 @@ pub fn World(comptime ctx: anytype) type {
desc.query.filter.expr = expr;
const result = c.ecs_system_init(self.raw, &desc);
if (result == 0) return flecs.getLastErrorOrUnknown();
if (result == 0) return flecszigble.getLastErrorOrUnknown();
return Entity.fromRaw(self, result);
}
@ -186,7 +185,7 @@ pub fn World(comptime ctx: anytype) type {
func: SystemCallback,
pub fn init(world: *Self, callback: SystemCallback) !*SystemCallbackContext {
var result = try flecs.allocator.create(SystemCallbackContext);
var result = try flecszigble.allocator.create(SystemCallbackContext);
result.world = world;
result.func = callback;
return result;
@ -194,7 +193,7 @@ pub fn World(comptime ctx: anytype) type {
fn free(context: ?*anyopaque) callconv(.C) void {
const self: *SystemCallbackContext = @alignCast(@ptrCast(context));
flecs.allocator.destroy(self);
flecszigble.allocator.destroy(self);
}
// FIXME: Dependency loop.

Loading…
Cancel
Save