2022-04-08 05:52:03 +00:00
|
|
|
|
namespace MoonTools.ECS
|
2022-03-05 02:01:44 +00:00
|
|
|
|
{
|
2022-04-08 05:52:03 +00:00
|
|
|
|
public class World
|
2022-03-05 02:01:44 +00:00
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
internal readonly TypeIndices ComponentTypeIndices = new TypeIndices();
|
|
|
|
|
internal readonly TypeIndices RelationTypeIndices = new TypeIndices();
|
2022-05-03 04:51:11 +00:00
|
|
|
|
internal readonly EntityStorage EntityStorage = new EntityStorage();
|
2022-12-03 07:43:54 +00:00
|
|
|
|
internal readonly ComponentDepot ComponentDepot;
|
2022-05-03 04:51:11 +00:00
|
|
|
|
internal readonly MessageDepot MessageDepot = new MessageDepot();
|
2022-12-03 07:43:54 +00:00
|
|
|
|
internal readonly RelationDepot RelationDepot;
|
|
|
|
|
internal readonly FilterStorage FilterStorage;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
internal readonly TemplateStorage TemplateStorage = new TemplateStorage();
|
|
|
|
|
internal readonly ComponentDepot TemplateComponentDepot = new ComponentDepot();
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public World()
|
|
|
|
|
{
|
|
|
|
|
ComponentDepot = new ComponentDepot(ComponentTypeIndices);
|
|
|
|
|
RelationDepot = new RelationDepot(RelationTypeIndices);
|
|
|
|
|
FilterStorage = new FilterStorage(EntityStorage, ComponentTypeIndices);
|
|
|
|
|
}
|
2022-04-08 05:52:03 +00:00
|
|
|
|
|
|
|
|
|
public Entity CreateEntity()
|
|
|
|
|
{
|
|
|
|
|
return EntityStorage.Create();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-03 04:51:11 +00:00
|
|
|
|
public void Set<TComponent>(Entity entity, in TComponent component) where TComponent : unmanaged
|
2022-04-08 05:52:03 +00:00
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
if (EntityStorage.SetComponent(entity.ID, ComponentTypeIndices.GetIndex<TComponent>()))
|
|
|
|
|
{
|
|
|
|
|
FilterStorage.Check<TComponent>(entity.ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ComponentDepot.Set<TComponent>(entity.ID, component);
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-03 07:43:54 +00:00
|
|
|
|
/*
|
|
|
|
|
public Template CreateTemplate()
|
2022-04-08 05:52:03 +00:00
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
return TemplateStorage.Create();
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-03 07:43:54 +00:00
|
|
|
|
public void Set<TComponent>(Template template, in TComponent component) where TComponent : unmanaged
|
2022-04-08 05:52:03 +00:00
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
TemplateComponentDepot.Set(template.ID, component);
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
2022-12-03 07:43:54 +00:00
|
|
|
|
*/
|
2022-05-03 04:51:11 +00:00
|
|
|
|
|
2022-12-03 07:43:54 +00:00
|
|
|
|
public Entity Instantiate(Template template)
|
2022-05-03 04:51:11 +00:00
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
var entity = EntityStorage.Create();
|
|
|
|
|
|
|
|
|
|
return entity;
|
2022-05-03 04:51:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-03 07:43:54 +00:00
|
|
|
|
public void Send<TMessage>(in TMessage message) where TMessage : unmanaged
|
2022-05-03 04:51:11 +00:00
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
MessageDepot.Add(message);
|
2022-05-03 04:51:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-03 07:43:54 +00:00
|
|
|
|
public void FinishUpdate()
|
2022-05-03 04:51:11 +00:00
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
MessageDepot.Clear();
|
2022-05-03 04:51:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-03 07:43:54 +00:00
|
|
|
|
public WorldState CreateState()
|
2022-05-03 04:51:11 +00:00
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
return new WorldState();
|
2022-05-03 04:51:11 +00:00
|
|
|
|
}
|
2022-03-05 02:01:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|