Merge pull request #5 from codehz/fix

fix iterate hashmap
master
prime31 4 years ago committed by GitHub
commit 6477d18a1a

@ -14,9 +14,9 @@ pub fn EntityTraitsType(comptime size: EntityTraitsSize) type {
}
fn EntityTraitsDefinition(comptime EntityType: type, comptime IndexType: type, comptime VersionType: type) type {
std.debug.assert(@typeInfo(EntityType) == .Int and !EntityType.is_signed);
std.debug.assert(@typeInfo(IndexType) == .Int and !IndexType.is_signed);
std.debug.assert(@typeInfo(VersionType) == .Int and !VersionType.is_signed);
std.debug.assert(@typeInfo(EntityType) == .Int and !@typeInfo(EntityType).Int.is_signed);
std.debug.assert(@typeInfo(IndexType) == .Int and !@typeInfo(IndexType).Int.is_signed);
std.debug.assert(@typeInfo(VersionType) == .Int and !@typeInfo(VersionType).Int.is_signed);
if (@bitSizeOf(IndexType) + @bitSizeOf(VersionType) != @bitSizeOf(EntityType))
@compileError("IndexType and VersionType must sum to EntityType's bit count");

@ -85,7 +85,7 @@ pub const OwningGroup = struct {
var component_ptrs: [component_info.fields.len][*]u8 = undefined;
inline for (component_info.fields) |field, i| {
const storage = group.registry.assure(field.field_type.Child);
const storage = group.registry.assure(@typeInfo(field.field_type).Pointer.child);
component_ptrs[i] = @ptrCast([*]u8, storage.instances.items.ptr);
}
@ -104,7 +104,7 @@ pub const OwningGroup = struct {
// fill and return the struct
var comps: Components = undefined;
inline for (@typeInfo(Components).Struct.fields) |field, i| {
const typed_ptr = @ptrCast([*]field.field_type.Child, @alignCast(@alignOf(field.field_type.Child), it.component_ptrs[i]));
const typed_ptr = @ptrCast([*]@typeInfo(field.field_type).Pointer.child, @alignCast(@alignOf(@typeInfo(field.field_type).Pointer.child), it.component_ptrs[i]));
@field(comps, field.name) = &typed_ptr[it.index];
}
return comps;

@ -4,9 +4,9 @@ const std = @import("std");
/// you choose the type of the handle (aka its size) and how much of that goes to the index and the version.
/// the bitsize of version + id must equal the handle size.
pub fn Handles(comptime HandleType: type, comptime IndexType: type, comptime VersionType: type) type {
std.debug.assert(@typeInfo(HandleType) == .Int and !HandleType.is_signed);
std.debug.assert(@typeInfo(IndexType) == .Int and !IndexType.is_signed);
std.debug.assert(@typeInfo(VersionType) == .Int and !VersionType.is_signed);
std.debug.assert(@typeInfo(HandleType) == .Int and !@typeInfo(HandleType).Int.is_signed);
std.debug.assert(@typeInfo(IndexType) == .Int and !@typeInfo(IndexType).Int.is_signed);
std.debug.assert(@typeInfo(VersionType) == .Int and !@typeInfo(VersionType).Int.is_signed);
if (@bitSizeOf(IndexType) + @bitSizeOf(VersionType) != @bitSizeOf(HandleType))
@compileError("IndexType and VersionType must sum to HandleType's bit count");

@ -195,7 +195,8 @@ pub const Registry = struct {
}
pub fn deinit(self: *Registry) void {
for (self.components.items()) |ptr| {
var iter = self.components.iterator();
while (iter.next()) |ptr| {
// HACK: we dont know the Type here but we need to call deinit
var storage = @intToPtr(*Storage(u1), ptr.value);
storage.deinit();

@ -14,7 +14,8 @@ pub const TypeStore = struct {
}
pub fn deinit(self: *TypeStore) void {
for (self.map.items()) |kv| {
var iter = self.map.iterator();
while (iter.next()) |kv| {
self.allocator.free(kv.value);
}
self.map.deinit();

Loading…
Cancel
Save