High-level wrapper around Flecs, a powerful ECS (Entity Component System) library, written in Zig language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.0 KiB

// Reimplementations of the following tests from Flecs:
// https://github.com/SanderMertens/flecs/blob/master/test/api/src/World.c
const std = @import("std");
const expect = std.testing.expect;
const expectEql = std.testing.expectEqual;
const expectStrEql = std.testing.expectEqualStrings;
const util = @import("./util.zig");
const flecs = @import("../src/main.zig");
const c = flecs.c;
const context = flecs.Context(void);
const Lookup = context.Lookup;
const World = context.World;
const Iter = context.Iter;
const Entity = context.Entity;
const Position = struct { x: f32, y: f32 };
const Velocity = struct { x: f32, y: f32 };
fn move(it: *Iter) void {
var pos = it.field(Position, 1);
var vel = it.field(Velocity, 2);
util.Probe.probeIter(it);
for (0..it.count) |row| {
var p = &pos[row];
var v = &vel[row];
p.*.x += v.*.x * it.delta_time;
p.*.y += v.*.y * it.delta_time;
}
}
test "World_progress_w_0" {
var world = try World.init(std.testing.allocator);
defer world.deinit();
_ = world.component(Position);
_ = world.component(Velocity);
// const e1 = world.entity(&.{ Position, Velocity });
// // const phase = Entity.fromRaw(world, c.EcsOnUpdate);
// // const move_system = world.system("move", move, phase, "Position, Velocity");
// var ctx = util.Probe.init();
// c.ecs_set_context(world.raw, &ctx);
// // e1.set(Position, .{ 0, 0 });
// // e1.set(Velocity, .{ 1, 2 });
// _ = world.progress(0);
// try expectEql(ctx.count, 1);
// try expectEql(ctx.invoked, 1);
// // try expectEql(ctx.system, move_system);
// try expectEql(ctx.termCount, 2);
// try expectEql(ctx.param, null);
// try expectEql(ctx.e[0], e1.raw);
// try expectEql(ctx.c[0][0], Lookup(Position).id);
// try expectEql(ctx.c[0][1], Lookup(Velocity).id);
// try expectEql(ctx.s[0][0], 0);
// try expectEql(ctx.s[0][1], 0);
// // const p = try e1.get(Position);
// // try expect(p.x != 0);
// // try expect(p.y != 0);
}