diff --git a/zig-ecs/examples/group_sort.zig b/zig-ecs/examples/group_sort.zig index 16cdeb5..f02a900 100644 --- a/zig-ecs/examples/group_sort.zig +++ b/zig-ecs/examples/group_sort.zig @@ -30,7 +30,7 @@ fn createEntities(reg: *ecs.Registry) void { } var end = timer.lap(); - std.debug.print("create {d} entities: {d}\n", .{ total_entities, @intToFloat(f64, end) / 1000000000 }); + std.debug.print("create {d} entities: {d}\n", .{ total_entities, @as(f64, @floatFromInt(end)) / 1000000000 }); } fn owningGroup(reg: *ecs.Registry) void { @@ -50,12 +50,12 @@ fn owningGroup(reg: *ecs.Registry) void { var timer = std.time.Timer.start() catch unreachable; group.sort(Position, {}, SortContext.sort); var end = timer.lap(); - std.debug.print("group (sort): {d}\n", .{@intToFloat(f64, end) / 1000000000}); + std.debug.print("group (sort): {d}\n", .{@as(f64, @floatFromInt(end)) / 1000000000}); timer.reset(); group.sort(Position, {}, SortContext.sort); end = timer.lap(); - std.debug.print("group (sort 2): {d}\n", .{@intToFloat(f64, end) / 1000000000}); + std.debug.print("group (sort 2): {d}\n", .{@as(f64, @floatFromInt(end)) / 1000000000}); // var group_iter2 = group.iterator(struct { vel: *Velocity, pos: *Position }); // while (group_iter2.next()) |e| { diff --git a/zig-ecs/examples/view_vs_group.zig b/zig-ecs/examples/view_vs_group.zig index d76f48f..cd2e0be 100644 --- a/zig-ecs/examples/view_vs_group.zig +++ b/zig-ecs/examples/view_vs_group.zig @@ -30,7 +30,7 @@ fn createEntities(reg: *ecs.Registry) void { } var end = timer.lap(); - std.debug.print("create entities: \t{d}\n", .{@intToFloat(f64, end) / 1000000000}); + std.debug.print("create entities: \t{d}\n", .{@as(f64, @floatFromInt(end)) / 1000000000}); } fn iterateView(reg: *ecs.Registry) void { @@ -48,7 +48,7 @@ fn iterateView(reg: *ecs.Registry) void { } var end = timer.lap(); - std.debug.print("view (iter): \t{d}\n", .{@intToFloat(f64, end) / 1000000000}); + std.debug.print("view (iter): \t{d}\n", .{@as(f64, @floatFromInt(end)) / 1000000000}); } fn nonOwningGroup(reg: *ecs.Registry) void { @@ -56,7 +56,7 @@ fn nonOwningGroup(reg: *ecs.Registry) void { var timer = std.time.Timer.start() catch unreachable; var group = reg.group(.{}, .{ Velocity, Position }, .{}); var end = timer.lap(); - std.debug.print("group (create): {d}\n", .{@intToFloat(f64, end) / 1000000000}); + std.debug.print("group (create): {d}\n", .{@as(f64, @floatFromInt(end)) / 1000000000}); timer.reset(); var group_iter = group.iterator(); @@ -69,7 +69,7 @@ fn nonOwningGroup(reg: *ecs.Registry) void { } end = timer.lap(); - std.debug.print("group (iter): \t{d}\n", .{@intToFloat(f64, end) / 1000000000}); + std.debug.print("group (iter): \t{d}\n", .{@as(f64, @floatFromInt(end)) / 1000000000}); } fn owningGroup(reg: *ecs.Registry) void { @@ -77,7 +77,7 @@ fn owningGroup(reg: *ecs.Registry) void { var timer = std.time.Timer.start() catch unreachable; var group = reg.group(.{ Velocity, Position }, .{}, .{}); var end = timer.lap(); - std.debug.print("group (create): {d}\n", .{@intToFloat(f64, end) / 1000000000}); + std.debug.print("group (create): {d}\n", .{@as(f64, @floatFromInt(end)) / 1000000000}); timer.reset(); var group_iter = group.iterator(struct { vel: *Velocity, pos: *Position }); @@ -87,12 +87,12 @@ fn owningGroup(reg: *ecs.Registry) void { } end = timer.lap(); - std.debug.print("group (iter): \t{d}\n", .{@intToFloat(f64, end) / 1000000000}); + std.debug.print("group (iter): \t{d}\n", .{@as(f64, @floatFromInt(end)) / 1000000000}); timer.reset(); group.each(each); end = timer.lap(); - std.debug.print("group (each): \t{d}\n", .{@intToFloat(f64, end) / 1000000000}); + std.debug.print("group (each): \t{d}\n", .{@as(f64, @floatFromInt(end)) / 1000000000}); timer.reset(); @@ -110,7 +110,7 @@ fn owningGroup(reg: *ecs.Registry) void { } end = timer.lap(); - std.debug.print("group (direct): {d}\n", .{@intToFloat(f64, end) / 1000000000}); + std.debug.print("group (direct): {d}\n", .{@as(f64, @floatFromInt(end)) / 1000000000}); } fn each(e: struct { vel: *Velocity, pos: *Position }) void { diff --git a/zig-ecs/src/ecs.zig b/zig-ecs/src/ecs.zig index 04ab446..e8ac5aa 100644 --- a/zig-ecs/src/ecs.zig +++ b/zig-ecs/src/ecs.zig @@ -10,6 +10,7 @@ pub const BasicView = @import("ecs/views.zig").BasicView; pub const BasicMultiView = @import("ecs/views.zig").BasicMultiView; pub const BasicGroup = @import("ecs/groups.zig").BasicGroup; pub const OwningGroup = @import("ecs/groups.zig").OwningGroup; +pub const SparseSet = @import("ecs/sparse_set.zig").SparseSet; // signals pub const Signal = @import("signals/signal.zig").Signal; diff --git a/zig-ecs/src/ecs/component_storage.zig b/zig-ecs/src/ecs/component_storage.zig index a681c42..3d36df4 100644 --- a/zig-ecs/src/ecs/component_storage.zig +++ b/zig-ecs/src/ecs/component_storage.zig @@ -393,7 +393,7 @@ test "sort empty component" { const asc_u32 = comptime std.sort.asc(u32); store.sort(u32, {}, asc_u32); for (store.data(), 0..) |e, i| { - try std.testing.expectEqual(@intCast(u32, i), e); + try std.testing.expectEqual(@as(u32, @intCast(i)), e); } const desc_u32 = comptime std.sort.desc(u32); diff --git a/zig-ecs/src/ecs/groups.zig b/zig-ecs/src/ecs/groups.zig index 139e2c6..6ec97c8 100644 --- a/zig-ecs/src/ecs/groups.zig +++ b/zig-ecs/src/ecs/groups.zig @@ -87,7 +87,7 @@ pub const OwningGroup = struct { var component_ptrs: [component_info.fields.len][*]u8 = undefined; inline for (component_info.fields, 0..) |field, i| { const storage = group.registry.assure(@typeInfo(field.type).Pointer.child); - component_ptrs[i] = @ptrCast([*]u8, storage.instances.items.ptr); + component_ptrs[i] = @as([*]u8, @ptrCast(storage.instances.items.ptr)); } return .{ @@ -105,7 +105,7 @@ pub const OwningGroup = struct { // fill and return the struct var comps: Components = undefined; inline for (@typeInfo(Components).Struct.fields, 0..) |field, i| { - const typed_ptr = @ptrCast([*]@typeInfo(field.type).Pointer.child, @alignCast(@alignOf(@typeInfo(field.type).Pointer.child), it.component_ptrs[i])); + const typed_ptr = @as([*]@typeInfo(field.type).Pointer.child, @ptrCast(@alignCast(it.component_ptrs[i]))); @field(comps, field.name) = &typed_ptr[it.index]; } return comps; @@ -138,7 +138,7 @@ pub const OwningGroup = struct { /// grabs an untyped (u1) reference to the first Storage(T) in the owned array fn firstOwnedStorage(self: OwningGroup) *Storage(u1) { const ptr = self.registry.components.get(self.group_data.owned[0]).?; - return @ptrFromInt(*Storage(u1), ptr); + return @as(*Storage(u1), @ptrFromInt(ptr)); } /// total number of entities in the group @@ -175,14 +175,14 @@ pub const OwningGroup = struct { var component_ptrs: [component_info.fields.len][*]u8 = undefined; inline for (component_info.fields, 0..) |field, i| { const storage = self.registry.assure(std.meta.Child(field.type)); - component_ptrs[i] = @ptrCast([*]u8, storage.instances.items.ptr); + component_ptrs[i] = @as([*]u8, @ptrCast(storage.instances.items.ptr)); } // fill the struct const index = self.firstOwnedStorage().set.index(entity); var comps: Components = undefined; inline for (component_info.fields, 0..) |field, i| { - const typed_ptr = @ptrCast([*]std.meta.Child(field.type), @alignCast(@alignOf(std.meta.Child(field.type)), component_ptrs[i])); + const typed_ptr = @as([*]std.meta.Child(field.type), @ptrCast(@alignCast(component_ptrs[i]))); @field(comps, field.name) = &typed_ptr[index]; } @@ -265,7 +265,7 @@ pub const OwningGroup = struct { // skip the first one since its what we are using to sort with for (self.group_data.owned[1..]) |type_id| { var other_ptr = self.registry.components.get(type_id).?; - var storage = @ptrFromInt(*Storage(u1), other_ptr); + var storage = @as(*Storage(u1), @ptrFromInt(other_ptr)); storage.swap(storage.data()[pos], entity); } } diff --git a/zig-ecs/src/ecs/handles.zig b/zig-ecs/src/ecs/handles.zig index 1039b5c..9a614ce 100644 --- a/zig-ecs/src/ecs/handles.zig +++ b/zig-ecs/src/ecs/handles.zig @@ -59,11 +59,11 @@ pub fn Handles(comptime HandleType: type, comptime IndexType: type, comptime Ver } pub fn extractId(_: Self, handle: HandleType) IndexType { - return @truncate(IndexType, handle & registry.entity_traits.entity_mask); + return @as(IndexType, @truncate(handle & registry.entity_traits.entity_mask)); } pub fn extractVersion(_: Self, handle: HandleType) VersionType { - return @truncate(VersionType, handle >> registry.entity_traits.entity_shift); + return @as(VersionType, @truncate(handle >> registry.entity_traits.entity_shift)); } fn forge(id: IndexType, version: VersionType) HandleType { diff --git a/zig-ecs/src/ecs/registry.zig b/zig-ecs/src/ecs/registry.zig index 143e832..1cc554d 100644 --- a/zig-ecs/src/ecs/registry.zig +++ b/zig-ecs/src/ecs/registry.zig @@ -55,7 +55,7 @@ pub const Registry = struct { // std.debug.assert(std.mem.indexOfAny(u32, include, exclude) == null); var group_data = allocator.create(GroupData) catch unreachable; group_data.hash = hash; - group_data.size = @intCast(u8, owned.len + include.len + exclude.len); + group_data.size = @as(u8, @intCast(owned.len + include.len + exclude.len)); if (owned.len == 0) { group_data.entity_set = SparseSet(Entity).init(allocator); } @@ -83,19 +83,19 @@ pub const Registry = struct { const isValid: bool = blk: { for (self.owned) |tid| { const ptr = self.registry.components.get(tid).?; - if (!@ptrFromInt(*Storage(u1), ptr).contains(entity)) + if (!@as(*Storage(u1), @ptrFromInt(ptr)).contains(entity)) break :blk false; } for (self.include) |tid| { const ptr = self.registry.components.get(tid).?; - if (!@ptrFromInt(*Storage(u1), ptr).contains(entity)) + if (!@as(*Storage(u1), @ptrFromInt(ptr)).contains(entity)) break :blk false; } for (self.exclude) |tid| { const ptr = self.registry.components.get(tid).?; - if (@ptrFromInt(*Storage(u1), ptr).contains(entity)) + if (@as(*Storage(u1), @ptrFromInt(ptr)).contains(entity)) break :blk false; } break :blk true; @@ -108,11 +108,11 @@ pub const Registry = struct { } else { if (isValid) { const ptr = self.registry.components.get(self.owned[0]).?; - if (!(@ptrFromInt(*Storage(u1), ptr).set.index(entity) < self.current)) { + if (!(@as(*Storage(u1), @ptrFromInt(ptr)).set.index(entity) < self.current)) { for (self.owned) |tid| { // store.swap hides a safe version that types it correctly const store_ptr = self.registry.components.get(tid).?; - var store = @ptrFromInt(*Storage(u1), store_ptr); + var store = @as(*Storage(u1), @ptrFromInt(store_ptr)); store.swap(store.data()[self.current], entity); } self.current += 1; @@ -129,12 +129,12 @@ pub const Registry = struct { } } else { const ptr = self.registry.components.get(self.owned[0]).?; - var store = @ptrFromInt(*Storage(u1), ptr); + var store = @as(*Storage(u1), @ptrFromInt(ptr)); if (store.contains(entity) and store.set.index(entity) < self.current) { self.current -= 1; for (self.owned) |tid| { const store_ptr = self.registry.components.get(tid).?; - store = @ptrFromInt(*Storage(u1), store_ptr); + store = @as(*Storage(u1), @ptrFromInt(store_ptr)); store.swap(store.data()[self.current], entity); } } @@ -199,7 +199,7 @@ pub const Registry = struct { var iter = self.components.valueIterator(); while (iter.next()) |ptr| { // HACK: we dont know the Type here but we need to call deinit - var storage = @ptrFromInt(*Storage(u1), ptr.*); + var storage = @as(*Storage(u1), @ptrFromInt(ptr.*)); storage.deinit(); } @@ -217,7 +217,7 @@ pub const Registry = struct { pub fn assure(self: *Registry, comptime T: type) *Storage(T) { var type_id = utils.typeId(T); if (self.components.getEntry(type_id)) |kv| { - return @ptrFromInt(*Storage(T), kv.value_ptr.*); + return @as(*Storage(T), @ptrFromInt(kv.value_ptr.*)); } var comp_set = Storage(T).initPtr(self.allocator); @@ -262,7 +262,7 @@ pub const Registry = struct { /// Returns the version stored along with an entity identifier pub fn version(_: *Registry, entity: Entity) entity_traits.version_type { - return @truncate(entity_traits.version_type, entity >> entity_traits.entity_shift); + return @as(entity_traits.version_type, @truncate(entity >> entity_traits.entity_shift)); } /// Creates a new entity and returns it @@ -316,6 +316,7 @@ pub const Registry = struct { const store = self.assure(@TypeOf(value)); if (store.tryGet(entity)) |found| { found.* = value; + store.update.publish(entity); } else { store.add(entity, value); } @@ -347,7 +348,7 @@ pub const Registry = struct { var iter = self.components.valueIterator(); while (iter.next()) |value| { // HACK: we dont know the Type here but we need to be able to call methods on the Storage(T) - var store = @ptrFromInt(*Storage(u1), value.*); + var store = @as(*Storage(u1), @ptrFromInt(value.*)); store.removeIfContains(entity); } } @@ -369,9 +370,10 @@ pub const Registry = struct { /// Returns a reference to the given component for an entity creating it if necessary pub fn getOrAdd(self: *Registry, comptime T: type, entity: Entity) *T { - if (self.has(T, entity)) return self.get(T, entity); - self.add(T, entity, std.mem.zeros(T)); - return self.get(T, type); + if (!self.has(T, entity)) { + self.addTyped(T, entity, .{}); + } + return self.get(T, entity); } pub fn tryGet(self: *Registry, comptime T: type, entity: Entity) ?*T { @@ -412,7 +414,7 @@ pub const Registry = struct { std.debug.assert(@typeInfo(T) != .Pointer); return if (self.contexts.get(utils.typeId(T))) |ptr| - return if (ptr > 0) @ptrFromInt(*T, ptr) else null + return if (ptr > 0) @as(*T, @ptrFromInt(ptr)) else null else null; } diff --git a/zig-ecs/src/ecs/sparse_set.zig b/zig-ecs/src/ecs/sparse_set.zig index 25cc5ae..3e79e35 100644 --- a/zig-ecs/src/ecs/sparse_set.zig +++ b/zig-ecs/src/ecs/sparse_set.zig @@ -142,7 +142,7 @@ pub fn SparseSet(comptime SparseT: type) type { std.debug.assert(!self.contains(sparse)); // assure(page(entt))[offset(entt)] = packed.size() - self.assure(self.page(sparse))[self.offset(sparse)] = @intCast(SparseT, self.dense.items.len); + self.assure(self.page(sparse))[self.offset(sparse)] = @as(SparseT, @intCast(self.dense.items.len)); _ = self.dense.append(sparse) catch unreachable; } @@ -175,8 +175,8 @@ pub fn SparseSet(comptime SparseT: type) type { std_sort_insertionSort_clone(SparseT, self.dense.items, context, lessThan); for (self.dense.items, 0..) |_, i| { - const item = @intCast(SparseT, i); - self.sparse.items[self.page(self.dense.items[self.page(item)])].?[self.offset(self.dense.items[self.page(item)])] = @intCast(SparseT, i); + const item = @as(SparseT, @intCast(i)); + self.sparse.items[self.page(self.dense.items[self.page(item)])].?[self.offset(self.dense.items[self.page(item)])] = @as(SparseT, @intCast(i)); } } @@ -186,7 +186,7 @@ pub fn SparseSet(comptime SparseT: type) type { std_sort_insertionSort_clone(SparseT, self.dense.items[0..length], context, lessThan); for (self.dense.items[0..length], 0..) |_, pos| { - var curr = @intCast(SparseT, pos); + var curr = @as(SparseT, @intCast(pos)); var next = self.index(self.dense.items[curr]); while (curr != next) { @@ -267,7 +267,7 @@ test "grow" { var i = @as(usize, std.math.maxInt(u8)); while (i > 0) : (i -= 1) { - set.add(@intCast(u32, i)); + set.add(@as(u32, @intCast(i))); } try std.testing.expectEqual(set.len(), std.math.maxInt(u8)); @@ -314,7 +314,7 @@ test "iterate" { set.add(2); set.add(3); - var i: u32 = @intCast(u32, set.len()) - 1; + var i: u32 = @as(u32, @intCast(set.len())) - 1; var iter = set.reverseIterator(); while (iter.next()) |entity| { try std.testing.expectEqual(i, entity); diff --git a/zig-ecs/src/ecs/type_store.zig b/zig-ecs/src/ecs/type_store.zig index 96b801c..1adb80b 100644 --- a/zig-ecs/src/ecs/type_store.zig +++ b/zig-ecs/src/ecs/type_store.zig @@ -30,7 +30,7 @@ pub const TypeStore = struct { pub fn get(self: *TypeStore, comptime T: type) *T { if (self.map.get(utils.typeId(T))) |bytes| { - return @ptrCast(*T, @alignCast(@alignOf(T), bytes)); + return @as(*T, @ptrCast(@alignCast(bytes))); } unreachable; } diff --git a/zig-ecs/src/ecs/utils.zig b/zig-ecs/src/ecs/utils.zig index ea0e30b..03c480e 100644 --- a/zig-ecs/src/ecs/utils.zig +++ b/zig-ecs/src/ecs/utils.zig @@ -19,7 +19,7 @@ pub const ErasedPtr = struct { pub fn asPtr(self: ErasedPtr, comptime PtrT: type) PtrT { if (@sizeOf(PtrT) == 0) return @as(PtrT, undefined); - return @ptrFromInt(PtrT, self.ptr); + return @as(PtrT, @ptrFromInt(self.ptr)); } }; @@ -101,7 +101,7 @@ pub fn hashStringFnv(comptime ReturnType: type, comptime str: []const u8) Return const prime = if (ReturnType == u32) @as(u32, 16777619) else @as(u64, 1099511628211); var value = if (ReturnType == u32) @as(u32, 2166136261) else @as(u64, 14695981039346656037); for (str) |c| { - value = (value ^ @intCast(u32, c)) *% prime; + value = (value ^ @as(u32, @intCast(c))) *% prime; } return value; } @@ -110,7 +110,7 @@ pub fn hashStringFnv(comptime ReturnType: type, comptime str: []const u8) Return pub fn hashStringDjb2(comptime str: []const u8) comptime_int { var hash: comptime_int = 5381; for (str) |c| { - hash = ((hash << 5) + hash) + @intCast(comptime_int, c); + hash = ((hash << 5) + hash) + @as(comptime_int, @intCast(c)); } return hash; } diff --git a/zig-ecs/src/ecs/views.zig b/zig-ecs/src/ecs/views.zig index e662def..1afe904 100644 --- a/zig-ecs/src/ecs/views.zig +++ b/zig-ecs/src/ecs/views.zig @@ -68,7 +68,7 @@ pub fn MultiView(comptime n_includes: usize, comptime n_excludes: usize) type { pub fn init(view: *Self) Iterator { const ptr = view.registry.components.get(view.type_ids[0]).?; - const internal_it = @ptrFromInt(*Storage(u8), ptr).set.reverseIterator(); + const internal_it = @as(*Storage(u8), @ptrFromInt(ptr)).set.reverseIterator(); return .{ .view = view, .internal_it = internal_it }; } @@ -77,7 +77,7 @@ pub fn MultiView(comptime n_includes: usize, comptime n_excludes: usize) type { // entity must be in all other Storages for (it.view.type_ids) |tid| { const ptr = it.view.registry.components.get(tid).?; - if (!@ptrFromInt(*Storage(u1), ptr).contains(entity)) { + if (!@as(*Storage(u1), @ptrFromInt(ptr)).contains(entity)) { break :blk; } } @@ -85,7 +85,7 @@ pub fn MultiView(comptime n_includes: usize, comptime n_excludes: usize) type { // entity must not be in all other excluded Storages for (it.view.exclude_type_ids) |tid| { const ptr = it.view.registry.components.get(tid).?; - if (@ptrFromInt(*Storage(u1), ptr).contains(entity)) { + if (@as(*Storage(u1), @ptrFromInt(ptr)).contains(entity)) { break :blk; } } @@ -104,7 +104,7 @@ pub fn MultiView(comptime n_includes: usize, comptime n_excludes: usize) type { fn getInternalIteratorInstance(it: *Iterator) ReverseSliceIterator(Entity) { const ptr = it.view.registry.components.get(it.view.type_ids[0]).?; - return @ptrFromInt(*Storage(u8), ptr).set.reverseIterator(); + return @as(*Storage(u8), @ptrFromInt(ptr)).set.reverseIterator(); } }; @@ -129,7 +129,7 @@ pub fn MultiView(comptime n_includes: usize, comptime n_excludes: usize) type { var sub_items: [n_includes]usize = undefined; for (self.type_ids, 0..) |tid, i| { const ptr = self.registry.components.get(tid).?; - const store = @ptrFromInt(*Storage(u8), ptr); + const store = @as(*Storage(u8), @ptrFromInt(ptr)); sub_items[i] = store.len(); } diff --git a/zig-ecs/src/resources/assets.zig b/zig-ecs/src/resources/assets.zig index ac1e08e..a36e602 100644 --- a/zig-ecs/src/resources/assets.zig +++ b/zig-ecs/src/resources/assets.zig @@ -17,7 +17,7 @@ pub const Assets = struct { var iter = self.caches.iterator(); while (iter.next()) |ptr| { // HACK: we dont know the Type here but we need to call deinit - @ptrFromInt(*Cache(u1), ptr.value_ptr.*).deinit(); + @as(*Cache(u1), @ptrFromInt(ptr.value_ptr.*)).deinit(); } self.caches.deinit(); @@ -25,7 +25,7 @@ pub const Assets = struct { pub fn get(self: *Assets, comptime AssetT: type) *Cache(AssetT) { if (self.caches.get(utils.typeId(AssetT))) |tid| { - return @ptrFromInt(*Cache(AssetT), tid); + return @as(*Cache(AssetT), @ptrFromInt(tid)); } var cache = Cache(AssetT).initPtr(self.allocator); diff --git a/zig-ecs/src/signals/delegate.zig b/zig-ecs/src/signals/delegate.zig index f69d879..f9f463b 100644 --- a/zig-ecs/src/signals/delegate.zig +++ b/zig-ecs/src/signals/delegate.zig @@ -23,7 +23,7 @@ pub fn Delegate(comptime Event: type) type { .callback = .{ .bound = struct { fn cb(self: usize, param: Event) void { - @call(.always_inline, @field(BaseT, fn_name), .{ @ptrFromInt(T, self), param }); + @call(.always_inline, @field(BaseT, fn_name), .{ @as(T, @ptrFromInt(self)), param }); } }.cb, }, diff --git a/zig-ecs/src/signals/dispatcher.zig b/zig-ecs/src/signals/dispatcher.zig index 5a839c4..c950680 100644 --- a/zig-ecs/src/signals/dispatcher.zig +++ b/zig-ecs/src/signals/dispatcher.zig @@ -18,7 +18,7 @@ pub const Dispatcher = struct { var iter = self.signals.iterator(); while (iter.next()) |ptr| { // HACK: we dont know the Type here but we need to call deinit - var signal = @ptrFromInt(*Signal(void), ptr.value_ptr.*); + var signal = @as(*Signal(void), @ptrFromInt(ptr.value_ptr.*)); signal.deinit(); } @@ -28,7 +28,7 @@ pub const Dispatcher = struct { fn assure(self: *Dispatcher, comptime T: type) *Signal(T) { var type_id = utils.typeId(T); if (self.signals.get(type_id)) |value| { - return @ptrFromInt(*Signal(T), value); + return @as(*Signal(T), @ptrFromInt(value)); } var signal = Signal(T).create(self.allocator); diff --git a/zig-ecs/tests/groups_test.zig b/zig-ecs/tests/groups_test.zig index d5aa392..f7cdf7d 100644 --- a/zig-ecs/tests/groups_test.zig +++ b/zig-ecs/tests/groups_test.zig @@ -30,8 +30,8 @@ test "sort BasicGroup by Entity" { var i: usize = 0; while (i < 5) : (i += 1) { var e = reg.create(); - reg.add(e, Sprite{ .x = @floatFromInt(f32, i) }); - reg.add(e, Renderable{ .x = @floatFromInt(f32, i) }); + reg.add(e, Sprite{ .x = @as(f32, @floatFromInt(i)) }); + reg.add(e, Renderable{ .x = @as(f32, @floatFromInt(i)) }); } const SortContext = struct { @@ -64,8 +64,8 @@ test "sort BasicGroup by Component" { var i: usize = 0; while (i < 5) : (i += 1) { var e = reg.create(); - reg.add(e, Sprite{ .x = @floatFromInt(f32, i) }); - reg.add(e, Renderable{ .x = @floatFromInt(f32, i) }); + reg.add(e, Sprite{ .x = @as(f32, @floatFromInt(i)) }); + reg.add(e, Renderable{ .x = @as(f32, @floatFromInt(i)) }); } const SortContext = struct { @@ -92,8 +92,8 @@ test "sort OwningGroup by Entity" { var i: usize = 0; while (i < 5) : (i += 1) { var e = reg.create(); - reg.add(e, Sprite{ .x = @floatFromInt(f32, i) }); - reg.add(e, Renderable{ .x = @floatFromInt(f32, i) }); + reg.add(e, Sprite{ .x = @as(f32, @floatFromInt(i)) }); + reg.add(e, Renderable{ .x = @as(f32, @floatFromInt(i)) }); } const SortContext = struct { @@ -125,8 +125,8 @@ test "sort OwningGroup by Component" { var i: usize = 0; while (i < 5) : (i += 1) { var e = reg.create(); - reg.add(e, Sprite{ .x = @floatFromInt(f32, i) }); - reg.add(e, Renderable{ .x = @floatFromInt(f32, i) }); + reg.add(e, Sprite{ .x = @as(f32, @floatFromInt(i)) }); + reg.add(e, Renderable{ .x = @as(f32, @floatFromInt(i)) }); } const SortContext = struct { @@ -153,11 +153,11 @@ test "sort OwningGroup by Component ensure unsorted non-matches" { var i: usize = 0; while (i < 5) : (i += 1) { var e = reg.create(); - reg.add(e, Sprite{ .x = @floatFromInt(f32, i) }); - reg.add(e, Renderable{ .x = @floatFromInt(f32, i) }); + reg.add(e, Sprite{ .x = @as(f32, @floatFromInt(i)) }); + reg.add(e, Renderable{ .x = @as(f32, @floatFromInt(i)) }); var e2 = reg.create(); - reg.add(e2, Sprite{ .x = @floatFromInt(f32, i + 1 * 50) }); + reg.add(e2, Sprite{ .x = @as(f32, @floatFromInt(i + 1 * 50)) }); } try std.testing.expectEqual(group.len(), 5); @@ -223,8 +223,8 @@ test "nested OwningGroups entity order" { var i: usize = 0; while (i < 5) : (i += 1) { var e = reg.create(); - reg.add(e, Sprite{ .x = @floatFromInt(f32, i) }); - reg.add(e, Renderable{ .x = @floatFromInt(f32, i) }); + reg.add(e, Sprite{ .x = @as(f32, @floatFromInt(i)) }); + reg.add(e, Renderable{ .x = @as(f32, @floatFromInt(i)) }); } try std.testing.expectEqual(group1.len(), 5); diff --git a/zig-ecs/tests/registry_test.zig b/zig-ecs/tests/registry_test.zig index 8f1553b..407d8e6 100644 --- a/zig-ecs/tests/registry_test.zig +++ b/zig-ecs/tests/registry_test.zig @@ -97,7 +97,7 @@ test "destroy" { var i = @as(u8, 0); while (i < 255) : (i += 1) { const e = reg.create(); - reg.add(e, Position{ .x = @floatFromInt(f32, i), .y = @floatFromInt(f32, i) }); + reg.add(e, Position{ .x = @as(f32, @floatFromInt(i)), .y = @as(f32, @floatFromInt(i)) }); } reg.destroy(3); @@ -106,7 +106,7 @@ test "destroy" { i = 0; while (i < 6) : (i += 1) { if (i != 3 and i != 4) - try std.testing.expectEqual(Position{ .x = @floatFromInt(f32, i), .y = @floatFromInt(f32, i) }, reg.getConst(Position, i)); + try std.testing.expectEqual(Position{ .x = @as(f32, @floatFromInt(i)), .y = @as(f32, @floatFromInt(i)) }, reg.getConst(Position, i)); } }