WorldBuilder
parent
b27cbcb50a
commit
229a0651bd
|
@ -5,11 +5,6 @@ public abstract class System : EntityComponentReader
|
|||
internal MessageDepot MessageDepot;
|
||||
public FilterBuilder FilterBuilder => new FilterBuilder(ComponentDepot);
|
||||
|
||||
public System(World world)
|
||||
{
|
||||
world.AddSystem(this);
|
||||
}
|
||||
|
||||
internal void RegisterMessageDepot(MessageDepot messageDepot)
|
||||
{
|
||||
MessageDepot = messageDepot;
|
||||
|
@ -42,6 +37,11 @@ public abstract class System : EntityComponentReader
|
|||
return MessageDepot.Some<TMessage>();
|
||||
}
|
||||
|
||||
protected void Send<TMessage>(in TMessage message) where TMessage : struct
|
||||
{
|
||||
MessageDepot.Add(message);
|
||||
}
|
||||
|
||||
protected void Destroy(in Entity entity)
|
||||
{
|
||||
ComponentDepot.OnEntityDestroy(entity.ID);
|
||||
|
|
34
src/World.cs
34
src/World.cs
|
@ -2,25 +2,25 @@
|
|||
|
||||
public class World
|
||||
{
|
||||
private readonly List<System> Systems = new List<System>();
|
||||
private readonly List<Renderer> Renderers = new List<Renderer>();
|
||||
private EntityStorage EntityStorage { get; } = new EntityStorage();
|
||||
private ComponentDepot ComponentDepot { get; } = new ComponentDepot();
|
||||
private MessageDepot MessageDepot { get; } = new MessageDepot();
|
||||
private readonly List<System> Systems;
|
||||
private readonly List<Renderer> Renderers;
|
||||
private readonly EntityStorage EntityStorage;
|
||||
private readonly ComponentDepot ComponentDepot;
|
||||
private MessageDepot MessageDepot;
|
||||
|
||||
internal void AddSystem(System system)
|
||||
internal World(
|
||||
List<System> systems,
|
||||
List<Renderer> renderers,
|
||||
ComponentDepot componentDepot,
|
||||
EntityStorage entityStorage,
|
||||
MessageDepot messageDepot
|
||||
)
|
||||
{
|
||||
system.RegisterEntityStorage(EntityStorage);
|
||||
system.RegisterComponentDepot(ComponentDepot);
|
||||
system.RegisterMessageDepot(MessageDepot);
|
||||
Systems.Add(system);
|
||||
}
|
||||
|
||||
internal void AddRenderer(Renderer renderer)
|
||||
{
|
||||
renderer.RegisterEntityStorage(EntityStorage);
|
||||
renderer.RegisterComponentDepot(ComponentDepot);
|
||||
Renderers.Add(renderer);
|
||||
Systems = systems;
|
||||
Renderers = renderers;
|
||||
ComponentDepot = componentDepot;
|
||||
EntityStorage = entityStorage;
|
||||
MessageDepot = messageDepot;
|
||||
}
|
||||
|
||||
public void Update(TimeSpan delta)
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
namespace MoonTools.ECS;
|
||||
|
||||
public class WorldBuilder
|
||||
{
|
||||
private ComponentDepot componentDepot;
|
||||
private EntityStorage entityStorage;
|
||||
private MessageDepot messageDepot;
|
||||
|
||||
private readonly List<System> systems = new List<System>();
|
||||
private readonly List<Renderer> renderers = new List<Renderer>();
|
||||
|
||||
public WorldBuilder()
|
||||
{
|
||||
componentDepot = new ComponentDepot();
|
||||
entityStorage = new EntityStorage();
|
||||
messageDepot = new MessageDepot();
|
||||
}
|
||||
|
||||
public void AddSystem(System system)
|
||||
{
|
||||
system.RegisterEntityStorage(entityStorage);
|
||||
system.RegisterComponentDepot(componentDepot);
|
||||
system.RegisterMessageDepot(messageDepot);
|
||||
systems.Add(system);
|
||||
}
|
||||
|
||||
public void AddRenderer(Renderer renderer)
|
||||
{
|
||||
renderer.RegisterEntityStorage(entityStorage);
|
||||
renderer.RegisterComponentDepot(componentDepot);
|
||||
renderers.Add(renderer);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
messageDepot.Add(message);
|
||||
}
|
||||
|
||||
public World Build()
|
||||
{
|
||||
return new World(
|
||||
systems,
|
||||
renderers,
|
||||
componentDepot,
|
||||
entityStorage,
|
||||
messageDepot
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue