|
|
@ -302,10 +302,13 @@ pub fn Entity(comptime ctx: anytype) type { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn get(self: Self, comptime T: type) ?T { |
|
|
|
pub fn get(self: Self, comptime T: type) ?T { |
|
|
|
|
|
|
|
return if (getRef(self, T)) |p| p.* else null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn getRef(self: Self, comptime T: type) ?*const T { |
|
|
|
const id = Context.lookup(T).*; |
|
|
|
const id = Context.lookup(T).*; |
|
|
|
const ptr = c.ecs_get_id(self.world.raw, self.raw, id); |
|
|
|
const ptr = c.ecs_get_id(self.world.raw, self.raw, id); |
|
|
|
const typed_ptr: ?*const T = @alignCast(@ptrCast(ptr)); |
|
|
|
return @alignCast(@ptrCast(ptr)); |
|
|
|
return if (typed_ptr) |p| p.* else null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn getMut(self: Self, comptime T: type) ?*T { |
|
|
|
pub fn getMut(self: Self, comptime T: type) ?*T { |
|
|
|