|
|
@ -1,5 +1,7 @@ |
|
|
|
|
|
|
|
const std = @import("std"); |
|
|
|
|
|
|
|
const Allocator = std.mem.Allocator; |
|
|
|
|
|
|
|
|
|
|
|
const c = @import("./c.zig"); |
|
|
|
const c = @import("./c.zig"); |
|
|
|
const flecszigble = @import("./main.zig"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn Iter(comptime ctx: anytype) type { |
|
|
|
pub fn Iter(comptime ctx: anytype) type { |
|
|
|
return struct { |
|
|
|
return struct { |
|
|
@ -12,21 +14,21 @@ pub fn Iter(comptime ctx: anytype) type { |
|
|
|
|
|
|
|
|
|
|
|
world: *World, |
|
|
|
world: *World, |
|
|
|
raw: *c.ecs_iter_t, |
|
|
|
raw: *c.ecs_iter_t, |
|
|
|
owned: bool, |
|
|
|
allocator: ?Allocator, |
|
|
|
|
|
|
|
|
|
|
|
pub fn fromRawPtr(world: *World, ptr: *c.ecs_iter_t) Self { |
|
|
|
pub fn fromRawPtr(world: *World, ptr: *c.ecs_iter_t) Self { |
|
|
|
return .{ .world = world, .raw = ptr, .owned = false }; |
|
|
|
return .{ .world = world, .raw = ptr, .allocator = null }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn fromRawValue(world: *World, value: c.ecs_iter_t) !Self { |
|
|
|
pub fn fromRawValue(world: *World, value: c.ecs_iter_t, allocator: Allocator) !Self { |
|
|
|
const raw = try flecszigble.allocator.create(c.ecs_iter_t); |
|
|
|
const raw = try allocator.create(c.ecs_iter_t); |
|
|
|
raw.* = value; |
|
|
|
raw.* = value; |
|
|
|
return .{ .world = world, .raw = raw, .owned = true }; |
|
|
|
return .{ .world = world, .raw = raw, .allocator = allocator }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn deinit(self: Self) void { |
|
|
|
pub fn deinit(self: Self) void { |
|
|
|
if (self.isValid()) c.ecs_iter_fini(self.raw); |
|
|
|
if (self.isValid()) c.ecs_iter_fini(self.raw); |
|
|
|
if (self.owned) flecszigble.allocator.destroy(self.raw); |
|
|
|
if (self.allocator) |alloc| alloc.destroy(self.raw); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn isValid(self: Self) bool { |
|
|
|
pub fn isValid(self: Self) bool { |
|
|
|