From c5ca08a610257a291d8c46f207b6d5e4642e5ca0 Mon Sep 17 00:00:00 2001 From: RedStealthDev Date: Mon, 19 Feb 2024 15:17:48 +0100 Subject: [PATCH] added register and get --- src/EntitySystem.zig | 20 +++++++++++++++++--- src/EntitySystemTypes.zig | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/EntitySystem.zig b/src/EntitySystem.zig index c26e81c..e369b3c 100644 --- a/src/EntitySystem.zig +++ b/src/EntitySystem.zig @@ -40,8 +40,22 @@ pub fn GetSignature(entity: Etyp.entity) Etyp.signature { return Signatures[entity]; } -//Component Manager +//Component Manager variables -pub fn RegisterComponent() void { - +const ComponentTypeList: std.StringArrayHashMap(Etyp.Component) = std.StringArrayHashMap(Etyp.Component); + +const ComponentArrays: std.StringArrayHashMap(Etyp.ComponentArray) = std.StringArrayHashMap(Etyp.ComponentArray); + +var NextComponent: Etyp.Component = 0; + +//component manager + +pub fn RegisterComponent(in: type) void { + var name = @typeName(in); + ComponentTypeList.put(name, NextComponent); + ComponentArrays.put(name, ComponentArrays{}); +} + +fn GetComponentArray(in: type) Etyp.ComponentArray { + return ComponentArrays[@typeName(in)]; } \ No newline at end of file diff --git a/src/EntitySystemTypes.zig b/src/EntitySystemTypes.zig index a212abf..ee99e91 100644 --- a/src/EntitySystemTypes.zig +++ b/src/EntitySystemTypes.zig @@ -16,7 +16,7 @@ pub const Signature = std.bit_set.IntegerBitSet(MAXComponents); //Component array type -const ComponentArray = struct { +pub const ComponentArray = struct { Components: [MAXEntitys]type, Entity2Array: [usize]Entity, Array2Entity: [Entity]usize,