From 02ccc3d1a5810f1da07e89f2e23c158d1b24df78 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 9 Feb 2023 10:50:25 -0800 Subject: [PATCH] add World.Relate + Spawner object --- src/Spawner.cs | 16 ++++++++++++++++ src/System.cs | 8 +------- src/World.cs | 8 ++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 src/Spawner.cs diff --git a/src/Spawner.cs b/src/Spawner.cs new file mode 100644 index 0000000..babb1f6 --- /dev/null +++ b/src/Spawner.cs @@ -0,0 +1,16 @@ +namespace MoonTools.ECS +{ + public abstract class Spawner + { + private World World; + + public Spawner(World world) + { + World = world; + } + + protected Entity CreateEntity() => World.CreateEntity(); + protected void Set(in Entity entity, in TComponent component) where TComponent : unmanaged => World.Set(entity, component); + protected void Relate(in Entity entityA, in Entity entityB, TRelationKind relationData) where TRelationKind : unmanaged => World.Relate(entityA, entityB, relationData); + } +} diff --git a/src/System.cs b/src/System.cs index 6d1d4dd..ea59464 100644 --- a/src/System.cs +++ b/src/System.cs @@ -69,13 +69,7 @@ namespace MoonTools.ECS MessageDepot.Add(entity.ID, message); } - protected void Relate(in Entity entityA, in Entity entityB, TRelationKind relationData) where TRelationKind : unmanaged - { - RelationDepot.Set(entityA, entityB, relationData); - var relationTypeIndex = RelationTypeIndices.GetIndex(); - EntityStorage.AddRelationKind(entityA.ID, relationTypeIndex); - EntityStorage.AddRelationKind(entityB.ID, relationTypeIndex); - } + protected void Relate(in Entity entityA, in Entity entityB, TRelationKind relationData) where TRelationKind : unmanaged => World.Relate(entityA, entityB, relationData); protected void Unrelate(in Entity entityA, in Entity entityB) where TRelationKind : unmanaged { diff --git a/src/World.cs b/src/World.cs index 481900e..7e3b067 100644 --- a/src/World.cs +++ b/src/World.cs @@ -78,6 +78,14 @@ namespace MoonTools.ECS MessageDepot.Add(message); } + public void Relate(in Entity entityA, in Entity entityB, TRelationKind relationData) where TRelationKind : unmanaged + { + RelationDepot.Set(entityA, entityB, relationData); + var relationTypeIndex = RelationTypeIndices.GetIndex(); + EntityStorage.AddRelationKind(entityA.ID, relationTypeIndex); + EntityStorage.AddRelationKind(entityB.ID, relationTypeIndex); + } + public void Destroy(in Entity entity) { foreach (var componentTypeIndex in EntityStorage.ComponentTypeIndices(entity.ID))