|
|
|
@ -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 }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|