MoonTools.ECS/src/World.cs

50 lines
1.2 KiB
C#
Raw Normal View History

2022-04-06 19:53:50 +00:00
namespace MoonTools.ECS;
2022-03-05 02:01:44 +00:00
public class World
{
2022-03-07 19:46:17 +00:00
private readonly EntityStorage EntityStorage = new EntityStorage();
private readonly ComponentDepot ComponentDepot = new ComponentDepot();
2022-04-06 19:53:50 +00:00
private readonly MessageDepot MessageDepot = new MessageDepot();
private readonly RelationDepot RelationDepot = new RelationDepot();
2022-03-07 19:46:17 +00:00
internal void AddSystem(System system)
{
system.RegisterEntityStorage(EntityStorage);
system.RegisterComponentDepot(ComponentDepot);
system.RegisterMessageDepot(MessageDepot);
2022-04-06 19:53:50 +00:00
system.RegisterRelationDepot(RelationDepot);
2022-03-07 19:46:17 +00:00
}
internal void AddRenderer(Renderer renderer)
{
renderer.RegisterEntityStorage(EntityStorage);
renderer.RegisterComponentDepot(ComponentDepot);
2022-04-06 19:53:50 +00:00
renderer.RegisterRelationDepot(RelationDepot);
}
public void AddRelationKind<TRelationKind>()
{
RelationDepot.Register<TRelationKind>();
2022-03-07 19:46:17 +00:00
}
public Entity CreateEntity()
{
return EntityStorage.Create();
}
public void Set<TComponent>(Entity entity, in TComponent component) where TComponent : struct
{
ComponentDepot.Set(entity.ID, component);
}
public void Send<TMessage>(in TMessage message) where TMessage : struct
2022-03-05 02:01:44 +00:00
{
2022-03-07 19:46:17 +00:00
MessageDepot.Add(message);
2022-03-05 02:01:44 +00:00
}
public void FinishUpdate()
2022-03-05 02:01:44 +00:00
{
2022-03-07 07:26:54 +00:00
MessageDepot.Clear();
2022-03-05 02:01:44 +00:00
}
}