From aa9c20d4b57dbdbdc13d725872aa0abcd96ff718 Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Fri, 7 Aug 2020 21:00:25 +0200 Subject: [PATCH] Update to latest HashMap API .iterator() is deprecated, iterating over the items directly is now supported --- zig-ecs/src/ecs/registry.zig | 6 ++---- zig-ecs/src/ecs/type_store.zig | 3 +-- zig-ecs/src/resources/assets.zig | 3 +-- zig-ecs/src/resources/cache.zig | 3 +-- zig-ecs/src/signals/dispatcher.zig | 3 +-- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/zig-ecs/src/ecs/registry.zig b/zig-ecs/src/ecs/registry.zig index 94d431b..b049414 100644 --- a/zig-ecs/src/ecs/registry.zig +++ b/zig-ecs/src/ecs/registry.zig @@ -195,8 +195,7 @@ pub const Registry = struct { } pub fn deinit(self: *Registry) void { - var it = self.components.iterator(); - while (it.next()) |ptr| { + for (self.components.items()) |ptr| { // HACK: we dont know the Type here but we need to call deinit var storage = @intToPtr(*Storage(u1), ptr.value); storage.deinit(); @@ -343,8 +342,7 @@ pub const Registry = struct { pub fn removeAll(self: *Registry, entity: Entity) void { assert(self.valid(entity)); - var it = self.components.iterator(); - while (it.next()) |ptr| { + for (self.components.items()) |ptr| { // HACK: we dont know the Type here but we need to be able to call methods on the Storage(T) var store = @intToPtr(*Storage(u1), ptr.value); store.removeIfContains(entity); diff --git a/zig-ecs/src/ecs/type_store.zig b/zig-ecs/src/ecs/type_store.zig index a16704d..21db41f 100644 --- a/zig-ecs/src/ecs/type_store.zig +++ b/zig-ecs/src/ecs/type_store.zig @@ -14,8 +14,7 @@ pub const TypeStore = struct { } pub fn deinit(self: *TypeStore) void { - var iter = self.map.iterator(); - while (iter.next()) |kv| { + for (self.map.items()) |kv| { self.allocator.free(kv.value); } self.map.deinit(); diff --git a/zig-ecs/src/resources/assets.zig b/zig-ecs/src/resources/assets.zig index 1c729eb..bb02846 100644 --- a/zig-ecs/src/resources/assets.zig +++ b/zig-ecs/src/resources/assets.zig @@ -14,8 +14,7 @@ pub const Assets = struct { } pub fn deinit(self: *Assets) void { - var it = self.caches.iterator(); - while (it.next()) |ptr| { + for (self.caches.items()) |ptr| { // HACK: we dont know the Type here but we need to call deinit @intToPtr(*Cache(u1), ptr.value).deinit(); } diff --git a/zig-ecs/src/resources/cache.zig b/zig-ecs/src/resources/cache.zig index 6d8c325..576ef9e 100644 --- a/zig-ecs/src/resources/cache.zig +++ b/zig-ecs/src/resources/cache.zig @@ -67,8 +67,7 @@ pub fn Cache(comptime T: type) type { pub fn clear(self: *@This()) void { // optionally deinit any resources that have a deinit method if (@hasDecl(T, "deinit")) { - var iter = self.resources.iterator(); - while (iter.next()) |kv| { + for (self.resources.items()) |kv| { @call(.{ .modifier = .always_inline }, @field(kv.value, "deinit"), .{}); } } diff --git a/zig-ecs/src/signals/dispatcher.zig b/zig-ecs/src/signals/dispatcher.zig index 1bcdb43..15eab06 100644 --- a/zig-ecs/src/signals/dispatcher.zig +++ b/zig-ecs/src/signals/dispatcher.zig @@ -15,8 +15,7 @@ pub const Dispatcher = struct { } pub fn deinit(self: *Dispatcher) void { - var it = self.signals.iterator(); - while (it.next()) |ptr| { + for (self.signals.items()) |ptr| { // HACK: we dont know the Type here but we need to call deinit var signal = @intToPtr(*Signal(void), ptr.value); signal.deinit();