remove WorldBuilder
parent
229a0651bd
commit
1d7db58d43
|
@ -55,16 +55,19 @@ internal class ComponentDepot
|
||||||
entityComponentMap.Add(entityID, new HashSet<Type>());
|
entityComponentMap.Add(entityID, new HashSet<Type>());
|
||||||
}
|
}
|
||||||
|
|
||||||
var alreadyExists = entityComponentMap[entityID].Add(typeof(TComponent));
|
var notFound = entityComponentMap[entityID].Add(typeof(TComponent));
|
||||||
|
|
||||||
// update filters
|
// update filters
|
||||||
if (!alreadyExists)
|
if (notFound)
|
||||||
{
|
{
|
||||||
if (typeToFilterSignatures.TryGetValue(typeof(TComponent), out var filterSignatures))
|
if (typeToFilterSignatures.TryGetValue(typeof(TComponent), out var filterSignatures))
|
||||||
{
|
{
|
||||||
foreach (var filterSignature in filterSignatures)
|
foreach (var filterSignature in filterSignatures)
|
||||||
{
|
{
|
||||||
CheckFilter(filterSignature, entityID);
|
if (CheckFilter(filterSignature, entityID))
|
||||||
|
{
|
||||||
|
filterSignatureToEntityIDs[filterSignature].Add(entityID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +96,10 @@ internal class ComponentDepot
|
||||||
{
|
{
|
||||||
foreach (var filterSignature in filterSignatures)
|
foreach (var filterSignature in filterSignatures)
|
||||||
{
|
{
|
||||||
CheckFilter(filterSignature, entityID);
|
if (!CheckFilter(filterSignature, entityID))
|
||||||
|
{
|
||||||
|
filterSignatureToEntityIDs[filterSignature].Remove(entityID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,18 @@ public abstract class System : EntityComponentReader
|
||||||
MessageDepot = messageDepot;
|
MessageDepot = messageDepot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public System(World world)
|
||||||
|
{
|
||||||
|
world.AddSystem(this);
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void Update(TimeSpan delta);
|
public abstract void Update(TimeSpan delta);
|
||||||
|
|
||||||
|
public virtual void InitializeFilters()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected Entity CreateEntity()
|
protected Entity CreateEntity()
|
||||||
{
|
{
|
||||||
return EntityStorage.Create();
|
return EntityStorage.Create();
|
||||||
|
|
49
src/World.cs
49
src/World.cs
|
@ -2,25 +2,40 @@
|
||||||
|
|
||||||
public class World
|
public class World
|
||||||
{
|
{
|
||||||
private readonly List<System> Systems;
|
private readonly List<System> Systems = new List<System>();
|
||||||
private readonly List<Renderer> Renderers;
|
private readonly List<Renderer> Renderers = new List<Renderer>();
|
||||||
private readonly EntityStorage EntityStorage;
|
private readonly EntityStorage EntityStorage = new EntityStorage();
|
||||||
private readonly ComponentDepot ComponentDepot;
|
private readonly ComponentDepot ComponentDepot = new ComponentDepot();
|
||||||
private MessageDepot MessageDepot;
|
private MessageDepot MessageDepot = new MessageDepot();
|
||||||
|
|
||||||
internal World(
|
internal void AddSystem(System system)
|
||||||
List<System> systems,
|
|
||||||
List<Renderer> renderers,
|
|
||||||
ComponentDepot componentDepot,
|
|
||||||
EntityStorage entityStorage,
|
|
||||||
MessageDepot messageDepot
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
Systems = systems;
|
system.RegisterEntityStorage(EntityStorage);
|
||||||
Renderers = renderers;
|
system.RegisterComponentDepot(ComponentDepot);
|
||||||
ComponentDepot = componentDepot;
|
system.RegisterMessageDepot(MessageDepot);
|
||||||
EntityStorage = entityStorage;
|
Systems.Add(system);
|
||||||
MessageDepot = messageDepot;
|
}
|
||||||
|
|
||||||
|
internal 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 void Update(TimeSpan delta)
|
public void Update(TimeSpan delta)
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
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