From 491adbb8c5a5f948420bbfee9aeb3225f970e43b Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 12 Jun 2020 13:48:16 -0700 Subject: [PATCH] fake commit to hold the sort context code --- zig-ecs/src/ecs/component_storage.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/zig-ecs/src/ecs/component_storage.zig b/zig-ecs/src/ecs/component_storage.zig index ede1bb6..e16ca46 100644 --- a/zig-ecs/src/ecs/component_storage.zig +++ b/zig-ecs/src/ecs/component_storage.zig @@ -205,6 +205,19 @@ pub fn ComponentStorage(comptime CompT: type, comptime EntityT: type) type { if (T == EntityT) { self.set.sortSub(lessThan, CompT, self.instances.items); } else if (T == CompT) { + const Context = struct{ + self: *Self, + lessThan: fn (void, T, T) bool, + + fn sort(this: @This(), a: EntityT, b: EntityT) bool { + const real_a = this.self.getConst(a); + const real_b = this.self.getConst(b); + std.debug.warn("-- a: {}, b: {} -- ae: {}, be: {} a < b {}\n", .{real_a, real_b, a, b, this.lessThan({}, real_a, real_b)}); + return this.lessThan({}, real_a, real_b); + } + }; + const context = Context{.self = self, .lessThan = lessThan}; + self.set.sortSubSub({}, CompT, lessThan, self.instances.items); // fn sorter(self: Self, a: T, b: T, sortFn) bool { // return sortFn(self.instances[a], self.instances[b]);