const std = @import("std"); const expect = std.testing.expect; const expectEql = std.testing.expectEqual; const expectStrEql = std.testing.expectEqualStrings; const flecs = @import("../src/main.zig"); const c = flecs.c; const context = flecs.Context(void); const Entity = context.Entity; const Iter = context.Iter; const Id = context.Id; pub const MAX_SYS_COLUMNS = 20; pub const MAX_ENTITIES = 256; pub const MAX_INVOCATIONS = 1024; pub const Probe = struct { system: c.ecs_entity_t, event: c.ecs_entity_t, eventId: c.ecs_id_t, offset: usize, count: usize, invoked: usize, termCount: usize, termIndex: usize, e: [MAX_ENTITIES]c.ecs_entity_t, c: [MAX_SYS_COLUMNS][MAX_INVOCATIONS]c.ecs_entity_t, s: [MAX_SYS_COLUMNS][MAX_INVOCATIONS]c.ecs_entity_t, param: ?*anyopaque, pub fn init() Probe { return std.mem.zeroes(Probe); } pub fn probeSystemWithContext(ctx: *Probe, it: Iter) !void { ctx.param = it.raw.param; ctx.system = it.raw.system; ctx.event = it.raw.event; ctx.eventId = it.raw.event_id; ctx.offset = 0; ctx.termCount = @intCast(it.raw.field_count); ctx.termIndex = @intCast(it.raw.term_index); for (0..ctx.termCount) |i| { ctx.c[ctx.invoked][i] = it.raw.ids[i]; ctx.s[ctx.invoked][i] = it.fieldSource(i + 1).raw; const e = it.fieldId(i + 1).raw; try expect(e != 0); } for (0..it.getCount()) |i| { if (i + ctx.count < 256) { ctx.e[i + ctx.count] = it.raw.entities[i]; } else { // Can't store more than that, tests shouldn't // rely on getting back more than 256 results. unreachable; } } ctx.count += it.getCount(); ctx.invoked += 1; } pub fn probeIter(it: Iter) !void { var ctx = c.ecs_get_context(it.world.raw); if (ctx == null) ctx = it.raw.ctx; if (ctx) |ct| { var p: *Probe = @alignCast(@ptrCast(ct)); try p.probeSystemWithContext(it); } } };