From e0bdf5f182e4d0027da22555c3f0c5ec7f2cb89e Mon Sep 17 00:00:00 2001 From: copygirl Date: Tue, 5 Mar 2024 15:58:45 +0100 Subject: [PATCH] Don't use zeroes and zeroInit for C structs --- src/entity.zig | 6 +++--- src/world.zig | 13 ++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/entity.zig b/src/entity.zig index 17ed1c3..6c491be 100644 --- a/src/entity.zig +++ b/src/entity.zig @@ -130,7 +130,7 @@ pub fn Entity(comptime ctx: anytype) type { .name => |n| { const found = c.ecs_lookup_child(world.raw, parent_, n.ptr); if (found == 0) { - var desc = std.mem.zeroInit(c.ecs_entity_desc_t, .{ .sep = "".ptr, .name = n.ptr }); + var desc = c.ecs_entity_desc_t{ .sep = "".ptr, .name = n.ptr }; desc.add[0] = c.ecs_pair(c.EcsChildOf, parent_); scope = c.ecs_entity_init(world.raw, &desc); if (scope == 0) return errors.getLastErrorOrUnknown(); @@ -145,13 +145,13 @@ pub fn Entity(comptime ctx: anytype) type { const previous = if (scope) |s| world.setScope(s) else null; defer _ = if (scope != null) world.setScope(previous); - var desc = std.mem.zeroInit(c.ecs_entity_desc_t, .{ + var desc = c.ecs_entity_desc_t{ .sep = "".ptr, // Disable tokenization. .id = if (id) |i| i else 0, .name = if (name_) |n| n.ptr else null, .symbol = if (config.symbol) |s| s.ptr else null, .use_low_id = config.use_low_id, - }); + }; inline for (ids, 0..) |a, i| desc.add[i] = Context.anyToId(a); diff --git a/src/world.zig b/src/world.zig index a848447..14bd4e4 100644 --- a/src/world.zig +++ b/src/world.zig @@ -107,12 +107,10 @@ pub fn World(comptime ctx: anytype) type { const name = meta.simpleTypeName(T); const entity_ = try self.entity(.{ .name = name, .symbol = name, .use_low_id = true }, .{}); - const desc = std.mem.zeroInit(c.ecs_component_desc_t, .{ + const result = c.ecs_component_init(self.raw, &.{ .entity = entity_.raw, .type = .{ .size = @sizeOf(T), .alignment = @alignOf(T) }, }); - - const result = c.ecs_component_init(self.raw, &desc); if (result == 0) return errors.getLastErrorOrUnknown(); Context.lookupMut(T).* = result; return Entity.fromRaw(self, result); @@ -167,15 +165,13 @@ pub fn World(comptime ctx: anytype) type { self.entity(.{ .name = name }, .{}); const context = try SystemCallbackContext.init(self, callback); - var desc = std.mem.zeroInit(c.ecs_system_desc_t, .{ + const result = c.ecs_system_init(self.raw, &.{ .entity = entity_.raw, .callback = &SystemCallbackContext.invoke, .binding_ctx = context, .binding_ctx_free = &SystemCallbackContext.free, + .query = .{ .filter = .{ .expr = expr } }, }); - desc.query.filter.expr = expr; - - const result = c.ecs_system_init(self.raw, &desc); if (result == 0) return errors.getLastErrorOrUnknown(); return Entity.fromRaw(self, result); } @@ -212,8 +208,7 @@ pub fn World(comptime ctx: anytype) type { /// that have a specific `Id`. This function supports wildcards. pub fn term(self: *Self, id: anytype) TermIterator { const id_ = Context.anyToId(id); - var term_ = std.mem.zeroInit(c.ecs_term_t, .{ .id = id_ }); - const iter = c.ecs_term_iter(self.raw, &term_); + const iter = c.ecs_term_iter(self.raw, &.{ .id = id_ }); return .{ .world = self, .iter = iter }; }