Have Entity.get return value instead of pointer

main
copygirl 1 year ago
parent 13936d11bb
commit 2a41366bd8
  1. 5
      src/entity.zig

@ -277,10 +277,11 @@ pub fn Entity(comptime ctx: anytype) type {
c.ecs_remove_id(self.world.raw, self.raw, ecs_id); c.ecs_remove_id(self.world.raw, self.raw, ecs_id);
} }
pub fn get(self: Self, comptime T: type) ?*const T { pub fn get(self: Self, comptime T: type) ?T {
const id = Lookup(ctx, T).id; const id = Lookup(ctx, T).id;
const ptr = c.ecs_get_id(self.world.raw, self.raw, id); const ptr = c.ecs_get_id(self.world.raw, self.raw, id);
return @alignCast(@ptrCast(ptr)); const typed_ptr: ?*const T = @alignCast(@ptrCast(ptr));
return if (typed_ptr) |p| p.* else null;
} }
pub fn get_mut(self: Self, comptime T: type) ?*T { pub fn get_mut(self: Self, comptime T: type) ?*T {

Loading…
Cancel
Save