From ac17a79631507d6d9560d623104a933fc8c9c25d Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 11 Jun 2020 22:34:25 -0700 Subject: [PATCH] more sorting... --- zig-ecs/src/ecs/utils.zig | 2 +- zig-ecs/src/ecs/views.zig | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/zig-ecs/src/ecs/utils.zig b/zig-ecs/src/ecs/utils.zig index 770ade1..2bdc03d 100644 --- a/zig-ecs/src/ecs/utils.zig +++ b/zig-ecs/src/ecs/utils.zig @@ -49,7 +49,7 @@ pub fn ReverseSliceIterator(comptime T: type) type { } /// sorts items using lessThan and keeps sub_items with the same sort -pub fn sortSub(comptime T1: type, comptime T2: type, items: []T1, sub_items: []T2, lessThan: fn (void, lhs: T1, rhs: T1) bool) void { +pub fn sortSub(comptime T1: type, comptime T2: type, items: []T1, sub_items: []T2, comptime lessThan: fn (void, lhs: T1, rhs: T1) bool) void { var i: usize = 1; while (i < items.len) : (i += 1) { const x = items[i]; diff --git a/zig-ecs/src/ecs/views.zig b/zig-ecs/src/ecs/views.zig index 505973d..65506f4 100644 --- a/zig-ecs/src/ecs/views.zig +++ b/zig-ecs/src/ecs/views.zig @@ -134,7 +134,13 @@ pub fn MultiView(comptime n_includes: usize, comptime n_excludes: usize) type { sub_items[i] = store.len(); } - utils.sortSub(usize, u32, sub_items[0..], self.type_ids[0..], std.sort.asc(usize)); + const asc_usize = struct { + fn sort(ctx: void, a: usize, b: usize) bool { + return a < b; + } + }; + + utils.sortSub(usize, u32, sub_items[0..], self.type_ids[0..], asc_usize.sort); } pub fn iterator(self: *Self) Iterator {