ecs: improve formatting (#643)
This commit is contained in:
parent
c9793a4666
commit
8aa2c97079
1 changed files with 13 additions and 13 deletions
|
|
@ -22,7 +22,7 @@ fn typeId(comptime T: type) TypeId {
|
||||||
|
|
||||||
const Column = struct {
|
const Column = struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
typeId: TypeId,
|
type_id: TypeId,
|
||||||
size: u32,
|
size: u32,
|
||||||
alignment: u16,
|
alignment: u16,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
|
|
@ -81,7 +81,7 @@ pub const ArchetypeStorage = struct {
|
||||||
fn debugValidateRow(storage: *ArchetypeStorage, gpa: Allocator, row: anytype) void {
|
fn debugValidateRow(storage: *ArchetypeStorage, gpa: Allocator, row: anytype) void {
|
||||||
inline for (std.meta.fields(@TypeOf(row))) |field, index| {
|
inline for (std.meta.fields(@TypeOf(row))) |field, index| {
|
||||||
const column = storage.columns[index];
|
const column = storage.columns[index];
|
||||||
if (typeId(field.field_type) != column.typeId) {
|
if (typeId(field.field_type) != column.type_id) {
|
||||||
const msg = std.mem.concat(gpa, u8, &.{
|
const msg = std.mem.concat(gpa, u8, &.{
|
||||||
"unexpected type: ",
|
"unexpected type: ",
|
||||||
@typeName(field.field_type),
|
@typeName(field.field_type),
|
||||||
|
|
@ -182,8 +182,8 @@ pub const ArchetypeStorage = struct {
|
||||||
const ColumnType = field.field_type;
|
const ColumnType = field.field_type;
|
||||||
if (@sizeOf(ColumnType) == 0) continue;
|
if (@sizeOf(ColumnType) == 0) continue;
|
||||||
const column = storage.columns[index];
|
const column = storage.columns[index];
|
||||||
const columnValues = @ptrCast([*]ColumnType, @alignCast(@alignOf(ColumnType), &storage.block[column.offset]));
|
const column_values = @ptrCast([*]ColumnType, @alignCast(@alignOf(ColumnType), &storage.block[column.offset]));
|
||||||
columnValues[row_index] = @field(row, field.name);
|
column_values[row_index] = @field(row, field.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,7 +194,7 @@ pub const ArchetypeStorage = struct {
|
||||||
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;
|
||||||
if (is_debug) {
|
if (is_debug) {
|
||||||
if (typeId(ColumnType) != column.typeId) {
|
if (typeId(ColumnType) != column.type_id) {
|
||||||
const msg = std.mem.concat(gpa, u8, &.{
|
const msg = std.mem.concat(gpa, u8, &.{
|
||||||
"unexpected type: ",
|
"unexpected type: ",
|
||||||
@typeName(ColumnType),
|
@typeName(ColumnType),
|
||||||
|
|
@ -204,8 +204,8 @@ pub const ArchetypeStorage = struct {
|
||||||
@panic(msg);
|
@panic(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const columnValues = @ptrCast([*]ColumnType, @alignCast(@alignOf(ColumnType), &storage.block[column.offset]));
|
const column_values = @ptrCast([*]ColumnType, @alignCast(@alignOf(ColumnType), &storage.block[column.offset]));
|
||||||
columnValues[row_index] = component;
|
column_values[row_index] = component;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@panic("no such component");
|
@panic("no such component");
|
||||||
|
|
@ -216,7 +216,7 @@ pub const ArchetypeStorage = struct {
|
||||||
if (!std.mem.eql(u8, column.name, name)) continue;
|
if (!std.mem.eql(u8, column.name, name)) continue;
|
||||||
if (@sizeOf(ColumnType) == 0) return {};
|
if (@sizeOf(ColumnType) == 0) return {};
|
||||||
if (is_debug) {
|
if (is_debug) {
|
||||||
if (typeId(ColumnType) != column.typeId) {
|
if (typeId(ColumnType) != column.type_id) {
|
||||||
const msg = std.mem.concat(gpa, u8, &.{
|
const msg = std.mem.concat(gpa, u8, &.{
|
||||||
"unexpected type: ",
|
"unexpected type: ",
|
||||||
@typeName(ColumnType),
|
@typeName(ColumnType),
|
||||||
|
|
@ -226,8 +226,8 @@ pub const ArchetypeStorage = struct {
|
||||||
@panic(msg);
|
@panic(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const columnValues = @ptrCast([*]ColumnType, @alignCast(@alignOf(ColumnType), &storage.block[column.offset]));
|
const column_values = @ptrCast([*]ColumnType, @alignCast(@alignOf(ColumnType), &storage.block[column.offset]));
|
||||||
return columnValues[row_index];
|
return column_values[row_index];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -459,7 +459,7 @@ pub fn Entities(comptime all_components: anytype) type {
|
||||||
const columns = try allocator.alloc(Column, 1);
|
const columns = try allocator.alloc(Column, 1);
|
||||||
columns[0] = .{
|
columns[0] = .{
|
||||||
.name = "id",
|
.name = "id",
|
||||||
.typeId = typeId(EntityID),
|
.type_id = typeId(EntityID),
|
||||||
.size = @sizeOf(EntityID),
|
.size = @sizeOf(EntityID),
|
||||||
.alignment = @alignOf(EntityID),
|
.alignment = @alignOf(EntityID),
|
||||||
.offset = undefined,
|
.offset = undefined,
|
||||||
|
|
@ -575,7 +575,7 @@ pub fn Entities(comptime all_components: anytype) type {
|
||||||
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)),
|
.type_id = typeId(@TypeOf(component)),
|
||||||
.size = @sizeOf(@TypeOf(component)),
|
.size = @sizeOf(@TypeOf(component)),
|
||||||
.alignment = if (@sizeOf(@TypeOf(component)) == 0) 1 else @alignOf(@TypeOf(component)),
|
.alignment = if (@sizeOf(@TypeOf(component)) == 0) 1 else @alignOf(@TypeOf(component)),
|
||||||
.offset = undefined,
|
.offset = undefined,
|
||||||
|
|
@ -874,4 +874,4 @@ test "empty_world" {
|
||||||
var world = try Entities(.{}).init(allocator);
|
var world = try Entities(.{}).init(allocator);
|
||||||
// Create a world.
|
// Create a world.
|
||||||
defer world.deinit();
|
defer world.deinit();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue