Use query for systems
Avokadoen opened this issue · comments
Description
Replace component arguments for queries. Keep special arguments as is.
Example
const SimpleQueryA = World.Query(
.exclude_entity,
.{query.include("a", *Component.A)},
.{Component.B}, // exclude
);
const SimpleQueryB = World.Query(
.exclude_entity,
.{query.include("b", *Component.B)},
.{Component.A}, // exclude
);
const SystemStruct = struct {
pub fn example_simple(query: SimpleQueryA) void {
while (query.next()) |item| {
item.a.value += 1;
}
}
pub fn example_zip (query_a: SimpleQueryA, query_b: SimpleQueryB) void {
while (query_a.next()) |item_a| {
while (query_b.next()) |item_b| {
item.a.value += @intCast(item_b.value);
}
query_b.reset();
}
}
};
var world = try WorldStub.WithEvents(.{Event("onFoo", .{SystemStruct}, .{})}).init(testing.allocator, .{});
defer world.deinit();
// create entities
world.triggerEvent(.onFoo, .{}, .{});
world.waitEvent(.onFoo);
Pros & cons
Pros:
- Simplify the implementation
- Zip will "just work" (#123)
- Unified queries
- Improvements to queries are also improvements to system dispatch
- More user control/flexibility
Cons: