ecs: improve compatibility with self-hosted compiler
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
9a759c55c5
commit
0a1ff43ce5
2 changed files with 7 additions and 7 deletions
|
|
@ -78,7 +78,7 @@ pub const ArchetypeStorage = struct {
|
||||||
gpa.free(storage.columns);
|
gpa.free(storage.columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debugValidateRow(storage: *ArchetypeStorage, gpa: Allocator, row: anytype) void {
|
fn debugValidateRow(storage: *ArchetypeStorage, gpa: Allocator, comptime 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.typeId) {
|
||||||
|
|
@ -102,7 +102,7 @@ pub const ArchetypeStorage = struct {
|
||||||
return row_index;
|
return row_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append(storage: *ArchetypeStorage, gpa: Allocator, row: anytype) !u32 {
|
pub fn append(storage: *ArchetypeStorage, gpa: Allocator, comptime row: anytype) !u32 {
|
||||||
if (is_debug) storage.debugValidateRow(gpa, row);
|
if (is_debug) storage.debugValidateRow(gpa, row);
|
||||||
|
|
||||||
try storage.ensureUnusedCapacity(gpa, 1);
|
try storage.ensureUnusedCapacity(gpa, 1);
|
||||||
|
|
@ -174,7 +174,7 @@ pub const ArchetypeStorage = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the entire row's values in the table.
|
/// Sets the entire row's values in the table.
|
||||||
pub fn setRow(storage: *ArchetypeStorage, gpa: Allocator, row_index: u32, row: anytype) void {
|
pub fn setRow(storage: *ArchetypeStorage, gpa: Allocator, row_index: u32, comptime row: anytype) void {
|
||||||
if (is_debug) storage.debugValidateRow(gpa, row);
|
if (is_debug) storage.debugValidateRow(gpa, row);
|
||||||
|
|
||||||
const fields = std.meta.fields(@TypeOf(row));
|
const fields = std.meta.fields(@TypeOf(row));
|
||||||
|
|
@ -188,7 +188,7 @@ pub const ArchetypeStorage = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the value of the named components (columns) for the given row in the table.
|
/// Sets the value of the named components (columns) for the given row in the table.
|
||||||
pub fn set(storage: *ArchetypeStorage, gpa: Allocator, row_index: u32, name: []const u8, component: anytype) void {
|
pub fn set(storage: *ArchetypeStorage, gpa: Allocator, row_index: u32, name: []const u8, comptime component: anytype) void {
|
||||||
const ColumnType = @TypeOf(component);
|
const ColumnType = @TypeOf(component);
|
||||||
if (@sizeOf(ColumnType) == 0) return;
|
if (@sizeOf(ColumnType) == 0) return;
|
||||||
for (storage.columns) |column| {
|
for (storage.columns) |column| {
|
||||||
|
|
@ -340,7 +340,7 @@ pub const void_archetype_hash = std.math.maxInt(u64);
|
||||||
/// row index, enabling entities to "move" from one archetype table to another seamlessly and
|
/// row index, enabling entities to "move" from one archetype table to another seamlessly and
|
||||||
/// making lookup by entity ID a few cheap array indexing operations.
|
/// making lookup by entity ID a few cheap array indexing operations.
|
||||||
/// * ComponentStorage(T) is a column of data within a table for a single type of component `T`.
|
/// * ComponentStorage(T) is a column of data within a table for a single type of component `T`.
|
||||||
pub fn Entities(all_components: anytype) type {
|
pub fn Entities(comptime all_components: anytype) type {
|
||||||
// TODO: validate all_components is a namespaced component set in the form we expect
|
// TODO: validate all_components is a namespaced component set in the form we expect
|
||||||
_ = all_components;
|
_ = all_components;
|
||||||
return struct {
|
return struct {
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ pub fn Module(comptime Params: anytype) @TypeOf(Params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Describes a set of ECS modules, each of which can provide components, systems, and more.
|
/// Describes a set of ECS modules, each of which can provide components, systems, and more.
|
||||||
pub fn Modules(modules: anytype) @TypeOf(modules) {
|
pub fn Modules(comptime modules: anytype) @TypeOf(modules) {
|
||||||
// TODO: validate the type
|
// TODO: validate the type
|
||||||
return modules;
|
return modules;
|
||||||
}
|
}
|
||||||
|
|
@ -251,7 +251,7 @@ pub fn World(comptime modules: anytype) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a global value called `.global_tag` from the module named `.module_tag`
|
/// Gets a global value called `.global_tag` from the module named `.module_tag`
|
||||||
pub fn get(world: *Self, module_tag: anytype, global_tag: anytype) @TypeOf(@field(
|
pub fn get(world: *Self, comptime module_tag: anytype, comptime global_tag: anytype) @TypeOf(@field(
|
||||||
@field(world.globals, @tagName(module_tag)),
|
@field(world.globals, @tagName(module_tag)),
|
||||||
@tagName(global_tag),
|
@tagName(global_tag),
|
||||||
)) {
|
)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue