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))