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.

40 lines
956 B

5 years ago
const std = @import("std");
const Dispatcher = @import("ecs").Dispatcher;
fn tester(param: u32) void {
std.testing.expectEqual(@as(u32, 666), param) catch unreachable;
5 years ago
}
fn tester2(param: i32) void {
std.testing.expectEqual(@as(i32, -543), param) catch unreachable;
5 years ago
}
const Thing = struct {
field: f32 = 0,
pub fn testU32(_: *Thing, param: u32) void {
std.testing.expectEqual(@as(u32, 666), param) catch unreachable;
5 years ago
}
pub fn testI32(_: *Thing, param: i32) void {
std.testing.expectEqual(@as(i32, -543), param) catch unreachable;
5 years ago
}
};
test "Dispatcher" {
var thing = Thing{};
var d = Dispatcher.init(std.testing.allocator);
defer d.deinit();
var sink = d.sink(u32);
sink.connect(tester);
sink.connectBound(&thing, "testU32");
d.trigger(u32, 666);
var sink2 = d.sink(i32);
sink2.connect(tester2);
sink2.connectBound(&thing, "testI32");
d.trigger(i32, -543);
}