ecs: zig fmt

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-06-10 16:56:12 -07:00
parent 7d7eb807f8
commit 70283bfcb4
2 changed files with 12 additions and 12 deletions

View file

@ -15,4 +15,4 @@ pub const pkg = std.build.Pkg{
.name = "ecs", .name = "ecs",
.source = .{ .path = "src/main.zig" }, .source = .{ .path = "src/main.zig" },
.dependencies = &[_]std.build.Pkg{}, .dependencies = &[_]std.build.Pkg{},
}; };

View file

@ -222,8 +222,8 @@ pub const ArchetypeStorage = struct {
pub fn getRaw(storage: *ArchetypeStorage, row_index: u32, name: []const u8) []u8 { pub fn getRaw(storage: *ArchetypeStorage, row_index: u32, name: []const u8) []u8 {
for (storage.columns) |column| { for (storage.columns) |column| {
if (!std.mem.eql(u8, column.name, name)) continue; if (!std.mem.eql(u8, column.name, name)) continue;
const start = column.offset+(column.size*row_index); const start = column.offset + (column.size * row_index);
return storage.block[start..start+(column.size)]; return storage.block[start .. start + (column.size)];
} }
@panic("no such component"); @panic("no such component");
} }
@ -240,17 +240,17 @@ pub const ArchetypeStorage = struct {
}; };
if (!ok) @panic("setRaw with non-matching column"); if (!ok) @panic("setRaw with non-matching column");
} }
mem.copy(u8, storage.block[column.offset+(row_index*column.size)..], component); mem.copy(u8, storage.block[column.offset + (row_index * column.size) ..], component);
} }
/// Swap-removes the specified row with the last row in the table. /// Swap-removes the specified row with the last row in the table.
pub fn remove(storage: *ArchetypeStorage, row_index: u32) void { pub fn remove(storage: *ArchetypeStorage, row_index: u32) void {
if (storage.len > 1) { if (storage.len > 1) {
for (storage.columns) |column| { for (storage.columns) |column| {
const dstStart = column.offset+(column.size*row_index); const dstStart = column.offset + (column.size * row_index);
const dst = storage.block[dstStart..dstStart+(column.size)]; const dst = storage.block[dstStart .. dstStart + (column.size)];
const srcStart = column.offset+(column.size*(storage.len-1)); const srcStart = column.offset + (column.size * (storage.len - 1));
const src = storage.block[srcStart..srcStart+(column.size)]; const src = storage.block[srcStart .. srcStart + (column.size)];
std.mem.copy(u8, dst, src); std.mem.copy(u8, dst, src);
} }
} }
@ -458,7 +458,7 @@ pub const Entities = struct {
// A swap removal will be performed, update the entity stored in the last row of the // A swap removal will be performed, update the entity stored in the last row of the
// archetype table to point to the row the entity we are removing is currently located. // archetype table to point to the row the entity we are removing is currently located.
if (archetype.len > 1) { if (archetype.len > 1) {
const last_row_entity_id = archetype.get(entities.allocator, archetype.len-1, "id", EntityID).?; const last_row_entity_id = archetype.get(entities.allocator, archetype.len - 1, "id", EntityID).?;
try entities.entities.put(entities.allocator, last_row_entity_id, Pointer{ try entities.entities.put(entities.allocator, last_row_entity_id, Pointer{
.archetype_index = ptr.archetype_index, .archetype_index = ptr.archetype_index,
.row_index = ptr.row_index, .row_index = ptr.row_index,
@ -499,12 +499,12 @@ pub const Entities = struct {
// pointer. Refresh it now: // pointer. Refresh it now:
archetype = entities.archetypeByID(entity); archetype = entities.archetypeByID(entity);
const columns = entities.allocator.alloc(Column, archetype.columns.len+1) catch |err| { const columns = entities.allocator.alloc(Column, archetype.columns.len + 1) catch |err| {
assert(entities.archetypes.swapRemove(new_hash)); assert(entities.archetypes.swapRemove(new_hash));
return err; return err;
}; };
mem.copy(Column, columns, archetype.columns); mem.copy(Column, columns, archetype.columns);
columns[columns.len-1] = .{ columns[columns.len - 1] = .{
.name = name, .name = name,
.typeId = typeId(@TypeOf(component)), .typeId = typeId(@TypeOf(component)),
.size = @sizeOf(@TypeOf(component)), .size = @sizeOf(@TypeOf(component)),
@ -608,7 +608,7 @@ pub const Entities = struct {
// pointer. Refresh it now: // pointer. Refresh it now:
archetype = entities.archetypeByID(entity); archetype = entities.archetypeByID(entity);
const columns = entities.allocator.alloc(Column, archetype.columns.len-1) catch |err| { const columns = entities.allocator.alloc(Column, archetype.columns.len - 1) catch |err| {
assert(entities.archetypes.swapRemove(new_hash)); assert(entities.archetypes.swapRemove(new_hash));
return err; return err;
}; };