|
|
|
@ -26,9 +26,9 @@ pub fn ComponentStorage(comptime Component: type, comptime Entity: type) type {
|
|
|
|
|
allocator: ?std.mem.Allocator,
|
|
|
|
|
/// doesnt really belong here...used to denote group ownership
|
|
|
|
|
super: usize = 0,
|
|
|
|
|
safeDeinit: fn (*Self) void,
|
|
|
|
|
safeSwap: fn (*Self, Entity, Entity, bool) void,
|
|
|
|
|
safeRemoveIfContains: fn (*Self, Entity) void,
|
|
|
|
|
safeDeinit: *const fn (*Self) void,
|
|
|
|
|
safeSwap: *const fn (*Self, Entity, Entity, bool) void,
|
|
|
|
|
safeRemoveIfContains: *const fn (*Self, Entity) void,
|
|
|
|
|
construction: Signal(Entity),
|
|
|
|
|
update: Signal(Entity),
|
|
|
|
|
destruction: Signal(Entity),
|
|
|
|
@ -187,7 +187,7 @@ pub fn ComponentStorage(comptime Component: type, comptime Entity: type) type {
|
|
|
|
|
struct {
|
|
|
|
|
/// Sort Entities according to the given comparison function. Only T == Entity is allowed. The constraint param only exists for
|
|
|
|
|
/// parity with non-empty Components
|
|
|
|
|
pub fn sort(self: Self, comptime T: type, context: anytype, comptime lessThan: fn (@TypeOf(context), T, T) bool) void {
|
|
|
|
|
pub fn sort(self: Self, comptime T: type, context: anytype, comptime lessThan: *const fn (@TypeOf(context), T, T) bool) void {
|
|
|
|
|
std.debug.assert(T == Entity);
|
|
|
|
|
self.set.sort(context, lessThan);
|
|
|
|
|
}
|
|
|
|
@ -225,7 +225,7 @@ pub fn ComponentStorage(comptime Component: type, comptime Entity: type) type {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Sort Entities or Components according to the given comparison function. Valid types for T are Entity or Component.
|
|
|
|
|
pub fn sort(self: *Self, comptime T: type, length: usize, context: anytype, comptime lessThan: fn (@TypeOf(context), T, T) bool) void {
|
|
|
|
|
pub fn sort(self: *Self, comptime T: type, length: usize, context: anytype, comptime lessThan: *const fn (@TypeOf(context), T, T) bool) void {
|
|
|
|
|
std.debug.assert(T == Entity or T == Component);
|
|
|
|
|
|
|
|
|
|
// we have to perform a swap after the sort for all moved entities so we make a helper struct for that. In the
|
|
|
|
@ -245,7 +245,7 @@ pub fn ComponentStorage(comptime Component: type, comptime Entity: type) type {
|
|
|
|
|
const SortContext = struct {
|
|
|
|
|
storage: *Self,
|
|
|
|
|
wrapped_context: @TypeOf(context),
|
|
|
|
|
lessThan: fn (@TypeOf(context), T, T) bool,
|
|
|
|
|
lessThan: *const fn (@TypeOf(context), T, T) bool,
|
|
|
|
|
|
|
|
|
|
fn sort(this: @This(), a: Entity, b: Entity) bool {
|
|
|
|
|
const real_a = this.storage.getConst(a);
|
|
|
|
|