module: begin making Mod unaware of all namespaced components
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
df263685ab
commit
e847d46ff9
2 changed files with 5 additions and 5 deletions
|
|
@ -8,10 +8,10 @@ const EntityID = @import("entities.zig").EntityID;
|
||||||
const comp = @import("comptime.zig");
|
const comp = @import("comptime.zig");
|
||||||
const Module = @import("../module.zig").Module;
|
const Module = @import("../module.zig").Module;
|
||||||
const NamespacedComponents = @import("../module.zig").NamespacedComponents;
|
const NamespacedComponents = @import("../module.zig").NamespacedComponents;
|
||||||
|
const MComponents = @import("../module.zig").MComponents;
|
||||||
|
|
||||||
pub fn World(comptime mods: anytype) type {
|
pub fn World(comptime mods: anytype) type {
|
||||||
const StateT = NamespacedState(mods);
|
const StateT = NamespacedState(mods);
|
||||||
const ns_components = NamespacedComponents(mods){};
|
|
||||||
return struct {
|
return struct {
|
||||||
allocator: mem.Allocator,
|
allocator: mem.Allocator,
|
||||||
entities: Entities(NamespacedComponents(mods){}),
|
entities: Entities(NamespacedComponents(mods){}),
|
||||||
|
|
@ -24,10 +24,10 @@ pub fn World(comptime mods: anytype) type {
|
||||||
pub fn Mod(comptime M: anytype) type {
|
pub fn Mod(comptime M: anytype) type {
|
||||||
const module_tag = M.name;
|
const module_tag = M.name;
|
||||||
const State = @TypeOf(@field(@as(StateT, undefined), @tagName(module_tag)));
|
const State = @TypeOf(@field(@as(StateT, undefined), @tagName(module_tag)));
|
||||||
const components = @field(ns_components, @tagName(module_tag));
|
const components = MComponents(M){};
|
||||||
return struct {
|
return struct {
|
||||||
state: State,
|
state: State,
|
||||||
entities: *Entities(ns_components),
|
entities: *Entities(NamespacedComponents(mods){}),
|
||||||
allocator: mem.Allocator,
|
allocator: mem.Allocator,
|
||||||
|
|
||||||
pub const IsInjectedArgument = void;
|
pub const IsInjectedArgument = void;
|
||||||
|
|
@ -160,7 +160,7 @@ pub fn World(comptime mods: anytype) type {
|
||||||
|
|
||||||
pub fn init(world: *@This(), allocator: mem.Allocator) !void {
|
pub fn init(world: *@This(), allocator: mem.Allocator) !void {
|
||||||
// TODO: switch Entities to stack allocation like Modules and World
|
// TODO: switch Entities to stack allocation like Modules and World
|
||||||
var entities = try Entities(ns_components).init(allocator);
|
var entities = try Entities(NamespacedComponents(mods){}).init(allocator);
|
||||||
errdefer entities.deinit();
|
errdefer entities.deinit();
|
||||||
world.* = @This(){
|
world.* = @This(){
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
|
|
|
||||||
|
|
@ -590,7 +590,7 @@ pub fn NamespacedComponents(comptime modules: anytype) type {
|
||||||
/// rotation: @TypeOf() = .{ .type = Vec2, .description = "rotation component" },
|
/// rotation: @TypeOf() = .{ .type = Vec2, .description = "rotation component" },
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn MComponents(comptime M: anytype) type {
|
pub fn MComponents(comptime M: anytype) type {
|
||||||
const error_prefix = "mach: module ." ++ @tagName(M.name) ++ " .components ";
|
const error_prefix = "mach: module ." ++ @tagName(M.name) ++ " .components ";
|
||||||
if (!@hasDecl(M, "components")) {
|
if (!@hasDecl(M, "components")) {
|
||||||
return struct {};
|
return struct {};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue