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