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.
76 lines
2.1 KiB
76 lines
2.1 KiB
1 year ago
|
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: i32,
|
||
|
count: i32,
|
||
|
invoked: i32,
|
||
|
termCount: i32,
|
||
|
termIndex: i32,
|
||
|
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.*.param;
|
||
|
ctx.*.system = it.*.system;
|
||
|
ctx.*.event = it.*.event;
|
||
|
ctx.*.eventId = it.*.eventId;
|
||
|
ctx.*.offset = 0;
|
||
|
ctx.*.termCount = it.*.fieldCount;
|
||
|
ctx.*.termIndex = it.*.termIndex;
|
||
|
|
||
|
for (0..ctx.*.term_count) |i| {
|
||
|
ctx.*.c[ctx.*.invoked][i] = it.*.ids[i];
|
||
|
ctx.*.s[ctx.*.invoked][i] = it.fieldSource(i + 1);
|
||
|
|
||
|
const e = it.fieldId(i + 1);
|
||
|
try expect(e != 0);
|
||
|
}
|
||
|
|
||
|
for (0..it.*.count) |i| {
|
||
|
if (i + ctx.*.count < 256) {
|
||
|
ctx.*.e[i + ctx.*.count] = it.*.entities[i];
|
||
|
} else {
|
||
|
// Can't store more than that, tests shouldn't
|
||
|
// rely on getting back more than 256 results.
|
||
|
unreachable;
|
||
|
}
|
||
|
}
|
||
|
ctx.*.count += it.*.count;
|
||
|
|
||
|
ctx.*.invoked += 1;
|
||
|
}
|
||
|
|
||
|
pub fn probeIter(it: *Iter) !void {
|
||
|
var ctx = c.ecs_get_context(it.*.world);
|
||
|
if (ctx == null) ctx = it.*.ctx;
|
||
|
if (ctx) |ct| {
|
||
|
var p: *Probe = @ptrCast(ct);
|
||
|
p.probeSystemWithContext(it);
|
||
|
}
|
||
|
}
|
||
|
};
|