High-level wrapper around Flecs, a powerful ECS (Entity Component System) library, written in Zig language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

const c = @import("./c.zig");
const Lookup = @import("./main.zig").Lookup;
const World = @import("./world.zig").World;
pub fn Entity(comptime ctx: anytype) type {
return struct {
world: *World(ctx),
raw: c.ecs_entity_t,
const Self = @This();
pub fn fromRaw(world: *World(ctx), raw: c.ecs_entity_t) Self {
return .{ .world = world, .raw = raw };
}
pub fn isValid(self: Self) bool {
return c.ecs_is_valid(self.world.raw, self.raw);
}
pub fn isAlive(self: Self) bool {
return c.ecs_is_alive(self.world.raw, self.raw);
}
pub fn get(self: Self, comptime T: type) ?*const T {
const id = Lookup(ctx, T).id;
return @alignCast(@ptrCast(c.ecs_get_id(self.world.raw, self.raw, id)));
}
pub fn set(self: Self, comptime T: type, value: T) void {
const id = Lookup(ctx, T).id;
_ = c.ecs_set_id(self.world.raw, self.raw, id, @sizeOf(T), &value);
}
};
}