Skip to content

Commit 4294dd3

Browse files
authored
Merge pull request #23 from zig-gamedev/fix-each
Fixed binding of ecs_each and usage in test.
2 parents 5310f5f + f71c096 commit 4294dd3

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/tests.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ test "zflecs.entities.basics" {
7474
const ptr = ecs.get(world, bob, Position).?;
7575
print("({d}, {d})\n", .{ ptr.x, ptr.y });
7676

77-
_ = ecs.set(world, bob, Position, .{ .x = 20, .y = 30 });
77+
_ = ecs.set(world, bob, Position, .{ .x = 10, .y = 30 });
7878

7979
const alice = ecs.set_name(world, 0, "Alice");
80-
_ = ecs.set(world, alice, Position, .{ .x = 10, .y = 20 });
80+
_ = ecs.set(world, alice, Position, .{ .x = 10, .y = 50 });
8181
ecs.add(world, alice, Walking);
8282

8383
const str = ecs.type_str(world, ecs.get_type(world, alice)).?;
@@ -87,11 +87,11 @@ test "zflecs.entities.basics" {
8787
ecs.remove(world, alice, Walking);
8888

8989
{
90-
var term = ecs.term_t{ .id = ecs.id(Position) };
91-
var it = ecs.each(world, &term);
90+
var it = ecs.each(world, Position);
9291
while (ecs.each_next(&it)) {
9392
if (ecs.field(&it, Position, 0)) |positions| {
9493
for (positions, it.entities()) |p, e| {
94+
try std.testing.expectEqual(p.x, 10);
9595
print(
9696
"Term loop: {s}: ({d}, {d})\n",
9797
.{ ecs.get_name(world, e).?, p.x, p.y },

src/zflecs.zig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,9 +2087,14 @@ extern fn ecs_id_from_str(world: *const world_t, expr: [*:0]const u8) id_t;
20872087
// Functions for working with `term_t` and `query_t`.
20882088
//
20892089
//--------------------------------------------------------------------------------------------------
2090-
/// `pub fn term_iter(world: *const world_t, term: *term_t) iter_t`
2091-
pub const each = ecs_each_id;
2092-
extern fn ecs_each_id(world: *const world_t, term: *term_t) iter_t;
2090+
2091+
pub fn each(world: *const world_t, comptime T: type) iter_t {
2092+
return each_id(world, id(T));
2093+
}
2094+
2095+
/// `pub fn ecs_each_id(world: *const world_t, id: id_t) iter_t`
2096+
pub const each_id = ecs_each_id;
2097+
extern fn ecs_each_id(world: *const world_t, id: id_t) iter_t;
20932098

20942099
/// `pub fn term_chain_iter(world: *const world_t, term: *term_t) iter_t`
20952100
pub const term_chain_iter = ecs_term_chain_iter;

0 commit comments

Comments
 (0)