module: support merging module lists

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-05-04 18:08:04 -07:00
parent b37ece1b9a
commit 95c9ae5278
9 changed files with 130 additions and 34 deletions

View file

@ -7,6 +7,8 @@ const query_mod = @import("query.zig");
const Archetype = @import("Archetype.zig");
const StringTable = @import("StringTable.zig");
const ComponentTypesByName = @import("module.zig").ComponentTypesByName;
const merge = @import("main.zig").merge;
const builtin_modules = @import("main.zig").builtin_modules;
/// An entity ID uniquely identifies an entity globally within an Entities set.
pub const EntityID = u64;
@ -699,7 +701,10 @@ pub fn ArchetypeIterator(comptime component_types_by_name: anytype) type {
}
test {
std.testing.refAllDeclsRecursive(Entities(.{}));
const modules = ComponentTypesByName(merge(.{
builtin_modules,
})){};
std.testing.refAllDeclsRecursive(Entities(modules));
}
// TODO: require "one big registration of components" even when using dynamic API? Would alleviate
@ -749,7 +754,8 @@ test "example" {
const Rotation = struct { degrees: f32 };
const component_types_by_name = ComponentTypesByName(.{
const component_types_by_name = ComponentTypesByName(merge(.{
builtin_modules,
struct {
pub const name = .game;
pub const components = .{
@ -758,7 +764,7 @@ test "example" {
.rotation = .{ .type = Rotation },
};
},
}){};
})){};
//-------------------------------------------------------------------------
// Create a world.