ecs: fix padding and data copy in setCapacity()
This commit is contained in:
parent
390b8bd922
commit
f6d29e7669
1 changed files with 10 additions and 5 deletions
|
|
@ -151,17 +151,22 @@ pub const ArchetypeStorage = struct {
|
|||
new_capacity_bytes += new_capacity * column.size;
|
||||
}
|
||||
const new_block = try gpa.alloc(u8, new_capacity_bytes);
|
||||
if (storage.capacity > 0) mem.copy(u8, new_block, storage.block);
|
||||
storage.block = new_block;
|
||||
storage.capacity = @intCast(u32, new_capacity);
|
||||
|
||||
var offset: usize = 0;
|
||||
for (storage.columns) |*column| {
|
||||
const padding = column.alignment - (@ptrToInt(&storage.block[offset]) % column.alignment);
|
||||
const align_mod = @ptrToInt(&new_block[offset]) % column.alignment;
|
||||
const padding = if (align_mod == 0) 0 else column.alignment - align_mod;
|
||||
offset += padding;
|
||||
column.offset = offset;
|
||||
offset += storage.capacity * column.size;
|
||||
if (storage.capacity > 0) {
|
||||
const slice = storage.block[column.offset .. column.offset + storage.capacity * column.size];
|
||||
mem.copy(u8, new_block[offset..], slice);
|
||||
}
|
||||
column.offset = offset;
|
||||
offset += new_capacity * column.size;
|
||||
}
|
||||
|
||||
storage.block = new_block;
|
||||
storage.capacity = @intCast(u32, new_capacity);
|
||||
}
|
||||
|
||||
/// Sets the entire row's values in the table.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue