From a294babecc89453755bb4f3622f950654cceb68f Mon Sep 17 00:00:00 2001 From: Victor carvalho Date: Thu, 6 Jan 2022 16:21:08 +0000 Subject: [PATCH] mod(registry.zig): rename singletons field, return pointer *TypeStore. Renaming the field `singletons` to `type_store` fixes the following error in Zig master (0.10.0-dev.193+1d55e4cae): `error: type '.ecs.type_store.TypeStore' not a function` Returning a pointer makes the API a bit more ergonomic to consume, allowing multiple calls to add and get to the singletons. For example: ```zig var singletons = registry.singletons(); singletons.add(State.init(allocator)); var state = singletons.get(State); ``` --- zig-ecs/src/ecs/registry.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/zig-ecs/src/ecs/registry.zig b/zig-ecs/src/ecs/registry.zig index 8ff9942..64487b1 100644 --- a/zig-ecs/src/ecs/registry.zig +++ b/zig-ecs/src/ecs/registry.zig @@ -34,7 +34,7 @@ pub const Registry = struct { components: std.AutoHashMap(u32, usize), contexts: std.AutoHashMap(u32, usize), groups: std.ArrayList(*GroupData), - singletons: TypeStore, + type_store: TypeStore, allocator: std.mem.Allocator, /// internal, persistant data structure to manage the entities in a group @@ -190,7 +190,7 @@ pub const Registry = struct { .components = std.AutoHashMap(u32, usize).init(allocator), .contexts = std.AutoHashMap(u32, usize).init(allocator), .groups = std.ArrayList(*GroupData).init(allocator), - .singletons = TypeStore.init(allocator), + .type_store = TypeStore.init(allocator), .allocator = allocator, }; } @@ -210,7 +210,7 @@ pub const Registry = struct { self.components.deinit(); self.contexts.deinit(); self.groups.deinit(); - self.singletons.deinit(); + self.type_store.deinit(); self.handles.deinit(); } @@ -418,8 +418,8 @@ pub const Registry = struct { } /// provides access to a TypeStore letting you add singleton components to the registry - pub fn singletons(self: Registry) TypeStore { - return self.singletons; + pub fn singletons(self: *Registry) *TypeStore { + return &self.type_store; } pub fn sort(self: *Registry, comptime T: type, comptime lessThan: fn (void, T, T) bool) void {