basic group ready kind of
This commit is contained in:
parent
8fd20e3b42
commit
4cd3d37657
@ -97,7 +97,7 @@ test "BasicGroup creation" {
|
|||||||
std.debug.assert(group.len() == 0);
|
std.debug.assert(group.len() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "BasicGroup exclides" {
|
test "BasicGroup excludes" {
|
||||||
var reg = Registry.init(std.testing.allocator);
|
var reg = Registry.init(std.testing.allocator);
|
||||||
defer reg.deinit();
|
defer reg.deinit();
|
||||||
|
|
||||||
@ -119,3 +119,15 @@ test "BasicGroup exclides" {
|
|||||||
reg.add(e0, @as(u32, 55));
|
reg.add(e0, @as(u32, 55));
|
||||||
std.debug.assert(group.len() == 0);
|
std.debug.assert(group.len() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "BasicGroup create late" {
|
||||||
|
var reg = Registry.init(std.testing.allocator);
|
||||||
|
defer reg.deinit();
|
||||||
|
|
||||||
|
var e0 = reg.create();
|
||||||
|
reg.add(e0, @as(i32, 44));
|
||||||
|
reg.add(e0, @as(u32, 55));
|
||||||
|
|
||||||
|
var group = reg.group(.{}, .{ i32, u32 }, .{});
|
||||||
|
std.testing.expectEqual(group.len(), 1);
|
||||||
|
}
|
@ -417,6 +417,7 @@ pub const Registry = struct {
|
|||||||
|
|
||||||
// we need to create a new GroupData
|
// we need to create a new GroupData
|
||||||
var new_group_data = GroupData.initPtr(self.allocator, self, hash, &[_]u32{}, includes_arr[0..], excludes_arr[0..]);
|
var new_group_data = GroupData.initPtr(self.allocator, self, hash, &[_]u32{}, includes_arr[0..], excludes_arr[0..]);
|
||||||
|
self.groups.append(new_group_data) catch unreachable;
|
||||||
|
|
||||||
// wire up our listeners
|
// wire up our listeners
|
||||||
inline for (owned) |t| self.onConstruct(t).connectBound(new_group_data, "maybeValidIf");
|
inline for (owned) |t| self.onConstruct(t).connectBound(new_group_data, "maybeValidIf");
|
||||||
@ -427,7 +428,17 @@ pub const Registry = struct {
|
|||||||
inline for (includes) |t| self.onDestruct(t).connectBound(new_group_data, "discardIf");
|
inline for (includes) |t| self.onDestruct(t).connectBound(new_group_data, "discardIf");
|
||||||
inline for (excludes) |t| self.onConstruct(t).connectBound(new_group_data, "discardIf");
|
inline for (excludes) |t| self.onConstruct(t).connectBound(new_group_data, "discardIf");
|
||||||
|
|
||||||
self.groups.append(new_group_data) catch unreachable;
|
// pre-fill the GroupData with any existing entitites that match
|
||||||
|
if (owned.len == 0) {
|
||||||
|
var tmp_view = self.view(owned ++ includes, excludes);
|
||||||
|
var view_iter = tmp_view.iterator();
|
||||||
|
while (view_iter.next()) |entity| {
|
||||||
|
new_group_data.entity_set.add(entity);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unreachable;
|
||||||
|
}
|
||||||
|
|
||||||
return BasicGroup(includes.len, excludes.len).init(&new_group_data.entity_set, self, includes_arr, excludes_arr);
|
return BasicGroup(includes.len, excludes.len).init(&new_group_data.entity_set, self, includes_arr, excludes_arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user