diff --git a/zig-ecs/src/ecs/component_storage.zig b/zig-ecs/src/ecs/component_storage.zig index a2eb783..c92dbc0 100644 --- a/zig-ecs/src/ecs/component_storage.zig +++ b/zig-ecs/src/ecs/component_storage.zig @@ -24,7 +24,7 @@ pub fn ComponentStorage(comptime Component: type, comptime Entity: type) type { set: *SparseSet(Entity), instances: std.ArrayList(ComponentOrDummy), - allocator: ?*std.mem.Allocator, + allocator: ?std.mem.Allocator, /// doesnt really belong here...used to denote group ownership super: usize = 0, safeDeinit: fn (*Self) void, @@ -34,7 +34,7 @@ pub fn ComponentStorage(comptime Component: type, comptime Entity: type) type { update: Signal(Entity), destruction: Signal(Entity), - pub fn init(allocator: *std.mem.Allocator) Self { + pub fn init(allocator: std.mem.Allocator) Self { var store = Self{ .set = SparseSet(Entity).initPtr(allocator), .instances = undefined, @@ -73,7 +73,7 @@ pub fn ComponentStorage(comptime Component: type, comptime Entity: type) type { return store; } - pub fn initPtr(allocator: *std.mem.Allocator) *Self { + pub fn initPtr(allocator: std.mem.Allocator) *Self { var store = allocator.create(Self) catch unreachable; store.set = SparseSet(Entity).initPtr(allocator); if (!is_empty_struct) { diff --git a/zig-ecs/src/ecs/handles.zig b/zig-ecs/src/ecs/handles.zig index 67d1609..1039b5c 100644 --- a/zig-ecs/src/ecs/handles.zig +++ b/zig-ecs/src/ecs/handles.zig @@ -18,7 +18,7 @@ pub fn Handles(comptime HandleType: type, comptime IndexType: type, comptime Ver handles: []HandleType, append_cursor: IndexType = 0, last_destroyed: ?IndexType = null, - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, const invalid_id = std.math.maxInt(IndexType); @@ -43,11 +43,11 @@ pub fn Handles(comptime HandleType: type, comptime IndexType: type, comptime Ver } }; - pub fn init(allocator: *std.mem.Allocator) Self { + pub fn init(allocator: std.mem.Allocator) Self { return initWithCapacity(allocator, 32); } - pub fn initWithCapacity(allocator: *std.mem.Allocator, capacity: usize) Self { + pub fn initWithCapacity(allocator: std.mem.Allocator, capacity: usize) Self { return Self{ .handles = allocator.alloc(HandleType, capacity) catch unreachable, .allocator = allocator, diff --git a/zig-ecs/src/ecs/registry.zig b/zig-ecs/src/ecs/registry.zig index d982658..2ce4895 100644 --- a/zig-ecs/src/ecs/registry.zig +++ b/zig-ecs/src/ecs/registry.zig @@ -35,7 +35,7 @@ pub const Registry = struct { contexts: std.AutoHashMap(u32, usize), groups: std.ArrayList(*GroupData), singletons: TypeStore, - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, /// internal, persistant data structure to manage the entities in a group pub const GroupData = struct { @@ -49,7 +49,7 @@ pub const Registry = struct { registry: *Registry, current: usize, - pub fn initPtr(allocator: *std.mem.Allocator, registry: *Registry, hash: u64, owned: []u32, include: []u32, exclude: []u32) *GroupData { + pub fn initPtr(allocator: std.mem.Allocator, registry: *Registry, hash: u64, owned: []u32, include: []u32, exclude: []u32) *GroupData { // std.debug.assert(std.mem.indexOfAny(u32, owned, include) == null); // std.debug.assert(std.mem.indexOfAny(u32, owned, exclude) == null); // std.debug.assert(std.mem.indexOfAny(u32, include, exclude) == null); @@ -68,7 +68,7 @@ pub const Registry = struct { return group_data; } - pub fn deinit(self: *GroupData, allocator: *std.mem.Allocator) void { + pub fn deinit(self: *GroupData, allocator: std.mem.Allocator) void { // only deinit th SparseSet for non-owning groups if (self.owned.len == 0) { self.entity_set.deinit(); @@ -184,7 +184,7 @@ pub const Registry = struct { } }; - pub fn init(allocator: *std.mem.Allocator) Registry { + pub fn init(allocator: std.mem.Allocator) Registry { return Registry{ .handles = EntityHandles.init(allocator), .components = std.AutoHashMap(u32, usize).init(allocator), diff --git a/zig-ecs/src/ecs/sparse_set.zig b/zig-ecs/src/ecs/sparse_set.zig index 3d2e3f9..e414528 100644 --- a/zig-ecs/src/ecs/sparse_set.zig +++ b/zig-ecs/src/ecs/sparse_set.zig @@ -13,9 +13,9 @@ pub fn SparseSet(comptime SparseT: type) type { sparse: std.ArrayList(?[]SparseT), dense: std.ArrayList(SparseT), entity_mask: SparseT, - allocator: ?*std.mem.Allocator, + allocator: ?std.mem.Allocator, - pub fn initPtr(allocator: *std.mem.Allocator) *Self { + pub fn initPtr(allocator: std.mem.Allocator) *Self { var set = allocator.create(Self) catch unreachable; set.sparse = std.ArrayList(?[]SparseT).initCapacity(allocator, 16) catch unreachable; set.dense = std.ArrayList(SparseT).initCapacity(allocator, 16) catch unreachable; @@ -24,7 +24,7 @@ pub fn SparseSet(comptime SparseT: type) type { return set; } - pub fn init(allocator: *std.mem.Allocator) Self { + pub fn init(allocator: std.mem.Allocator) Self { return Self{ .sparse = std.ArrayList(?[]SparseT).init(allocator), .dense = std.ArrayList(SparseT).init(allocator), @@ -104,8 +104,8 @@ pub fn SparseSet(comptime SparseT: type) type { pub fn contains(self: Self, sparse: SparseT) bool { const curr = self.page(sparse); return curr < self.sparse.items.len and - self.sparse.items[curr] != null and - self.sparse.items[curr].?[self.offset(sparse)] != std.math.maxInt(SparseT); + self.sparse.items[curr] != null and + self.sparse.items[curr].?[self.offset(sparse)] != std.math.maxInt(SparseT); } /// Returns the position of an entity in a sparse set diff --git a/zig-ecs/src/ecs/type_store.zig b/zig-ecs/src/ecs/type_store.zig index 8a78929..96b801c 100644 --- a/zig-ecs/src/ecs/type_store.zig +++ b/zig-ecs/src/ecs/type_store.zig @@ -4,9 +4,9 @@ const utils = @import("utils.zig"); /// stores a single object of type T for each T added pub const TypeStore = struct { map: std.AutoHashMap(u32, []u8), - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, - pub fn init(allocator: *std.mem.Allocator) TypeStore { + pub fn init(allocator: std.mem.Allocator) TypeStore { return TypeStore{ .map = std.AutoHashMap(u32, []u8).init(allocator), .allocator = allocator, diff --git a/zig-ecs/src/process/process.zig b/zig-ecs/src/process/process.zig index d4ab365..46d7dda 100644 --- a/zig-ecs/src/process/process.zig +++ b/zig-ecs/src/process/process.zig @@ -3,16 +3,14 @@ const std = @import("std"); /// Processes are run by the Scheduler. They use a similar pattern to Allocators in that they are created and /// added as fields in a parent struct, your actual process that will be run. pub const Process = struct { - const State = enum(u8) { - uninitialized, running, paused, succeeded, failed, aborted, finished - }; + const State = enum(u8) { uninitialized, running, paused, succeeded, failed, aborted, finished }; updateFn: fn (self: *Process) void, startFn: ?fn (self: *Process) void = null, abortedFn: ?fn (self: *Process) void = null, failedFn: ?fn (self: *Process) void = null, succeededFn: ?fn (self: *Process) void = null, - deinit: fn (self: *Process, allocator: *std.mem.Allocator) void = undefined, + deinit: fn (self: *Process, allocator: std.mem.Allocator) void = undefined, state: State = .uninitialized, stopped: bool = false, diff --git a/zig-ecs/src/process/scheduler.zig b/zig-ecs/src/process/scheduler.zig index d0ebca2..9d316e7 100644 --- a/zig-ecs/src/process/scheduler.zig +++ b/zig-ecs/src/process/scheduler.zig @@ -12,16 +12,16 @@ const Process = @import("process.zig").Process; /// - in any callback you can get your oiginal struct back via `process.getParent(@This())` pub const Scheduler = struct { processes: std.ArrayList(*Process), - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, /// helper to create and prepare a process - fn createProcessHandler(comptime T: type, data: anytype, allocator: *std.mem.Allocator) *Process { + fn createProcessHandler(comptime T: type, data: anytype, allocator: std.mem.Allocator) *Process { var proc = allocator.create(T) catch unreachable; proc.initialize(data); // get a closure so that we can safely deinit this later proc.process.deinit = struct { - fn deinit(process: *Process, alloc: *std.mem.Allocator) void { + fn deinit(process: *Process, alloc: std.mem.Allocator) void { if (process.next) |next_process| { next_process.deinit(next_process, alloc); } @@ -35,9 +35,9 @@ pub const Scheduler = struct { /// returned when appending a process so that sub-processes can be added to the process const Continuation = struct { process: *Process, - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, - pub fn init(process: *Process, allocator: *std.mem.Allocator) Continuation { + pub fn init(process: *Process, allocator: std.mem.Allocator) Continuation { return .{ .process = process, .allocator = allocator }; } @@ -48,7 +48,7 @@ pub const Scheduler = struct { } }; - pub fn init(allocator: *std.mem.Allocator) Scheduler { + pub fn init(allocator: std.mem.Allocator) Scheduler { return .{ .processes = std.ArrayList(*Process).init(allocator), .allocator = allocator, @@ -72,7 +72,7 @@ pub const Scheduler = struct { return Continuation.init(process, self.allocator); } - fn updateProcess(process: **Process, allocator: *std.mem.Allocator) bool { + fn updateProcess(process: **Process, allocator: std.mem.Allocator) bool { const current_process = process.*; current_process.tick(); diff --git a/zig-ecs/src/resources/assets.zig b/zig-ecs/src/resources/assets.zig index 1502e7b..19121b6 100644 --- a/zig-ecs/src/resources/assets.zig +++ b/zig-ecs/src/resources/assets.zig @@ -4,9 +4,9 @@ const Cache = @import("cache.zig").Cache; pub const Assets = struct { caches: std.AutoHashMap(u32, usize), - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, - pub fn init(allocator: *std.mem.Allocator) Assets { + pub fn init(allocator: std.mem.Allocator) Assets { return Assets{ .caches = std.AutoHashMap(u32, usize).init(allocator), .allocator = allocator, diff --git a/zig-ecs/src/resources/cache.zig b/zig-ecs/src/resources/cache.zig index 802f104..f1ad407 100644 --- a/zig-ecs/src/resources/cache.zig +++ b/zig-ecs/src/resources/cache.zig @@ -10,9 +10,9 @@ pub fn Cache(comptime T: type) type { safe_deinit: fn (*@This()) void, resources: std.AutoHashMap(u32, *T), - allocator: ?*std.mem.Allocator = null, + allocator: ?std.mem.Allocator = null, - pub fn initPtr(allocator: *std.mem.Allocator) *@This() { + pub fn initPtr(allocator: std.mem.Allocator) *@This() { var cache = allocator.create(@This()) catch unreachable; cache.safe_deinit = struct { fn deinit(self: *Self) void { @@ -26,7 +26,7 @@ pub fn Cache(comptime T: type) type { return cache; } - pub fn init(allocator: *std.mem.Allocator) @This() { + pub fn init(allocator: std.mem.Allocator) @This() { return .{ .safe_deinit = struct { fn deinit(self: *Self) void { diff --git a/zig-ecs/src/signals/dispatcher.zig b/zig-ecs/src/signals/dispatcher.zig index 15d3daf..265fff9 100644 --- a/zig-ecs/src/signals/dispatcher.zig +++ b/zig-ecs/src/signals/dispatcher.zig @@ -5,9 +5,9 @@ const utils = @import("../ecs/utils.zig"); pub const Dispatcher = struct { signals: std.AutoHashMap(u32, usize), - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, - pub fn init(allocator: *std.mem.Allocator) Dispatcher { + pub fn init(allocator: std.mem.Allocator) Dispatcher { return Dispatcher{ .signals = std.AutoHashMap(u32, usize).init(allocator), .allocator = allocator, diff --git a/zig-ecs/src/signals/signal.zig b/zig-ecs/src/signals/signal.zig index 4f51c55..2349f89 100644 --- a/zig-ecs/src/signals/signal.zig +++ b/zig-ecs/src/signals/signal.zig @@ -7,9 +7,9 @@ pub fn Signal(comptime Event: type) type { const Self = @This(); calls: std.ArrayList(Delegate(Event)), - allocator: ?*std.mem.Allocator = null, + allocator: ?std.mem.Allocator = null, - pub fn init(allocator: *std.mem.Allocator) Self { + pub fn init(allocator: std.mem.Allocator) Self { // we purposely do not store the allocator locally in this case so we know not to destroy ourself in deint! return Self{ .calls = std.ArrayList(Delegate(Event)).init(allocator), @@ -17,7 +17,7 @@ pub fn Signal(comptime Event: type) type { } /// heap allocates a Signal - pub fn create(allocator: *std.mem.Allocator) *Self { + pub fn create(allocator: std.mem.Allocator) *Self { var signal = allocator.create(Self) catch unreachable; signal.calls = std.ArrayList(Delegate(Event)).init(allocator); signal.allocator = allocator;