MoonTools.ECS/src/Rev2/Archetype.cs

41 lines
904 B
C#
Raw Normal View History

2023-10-19 22:41:49 +00:00
using System.Collections.Generic;
2023-10-30 19:11:50 +00:00
using MoonTools.ECS.Collections;
2023-10-19 22:41:49 +00:00
2023-10-25 01:44:41 +00:00
namespace MoonTools.ECS.Rev2;
internal class Archetype
2023-10-19 22:41:49 +00:00
{
2023-10-25 01:44:41 +00:00
public World World;
public ArchetypeSignature Signature;
2023-10-31 18:10:42 +00:00
public NativeArray[] ComponentColumns;
2023-10-30 19:11:50 +00:00
public NativeArray<Id> RowToEntity = new NativeArray<Id>();
2023-10-25 01:44:41 +00:00
2023-10-26 23:16:28 +00:00
public Dictionary<Id, int> ComponentToColumnIndex =
new Dictionary<Id, int>();
public SortedDictionary<Id, ArchetypeEdge> Edges = new SortedDictionary<Id, ArchetypeEdge>();
2023-10-21 00:24:35 +00:00
2023-10-25 01:44:41 +00:00
public int Count => RowToEntity.Count;
public Archetype(World world, ArchetypeSignature signature)
{
World = world;
Signature = signature;
2023-10-31 18:10:42 +00:00
ComponentColumns = new NativeArray[signature.Count];
2023-10-25 01:44:41 +00:00
}
2023-10-19 22:41:49 +00:00
2023-10-25 01:44:41 +00:00
public void ClearAll()
{
2023-10-30 19:11:50 +00:00
for (int i = 0; i < ComponentColumns.Length; i += 1)
2023-10-25 01:44:41 +00:00
{
ComponentColumns[i].Count = 0;
}
2023-10-19 22:41:49 +00:00
2023-10-25 01:44:41 +00:00
foreach (var entityId in RowToEntity)
2023-10-19 22:41:49 +00:00
{
2023-10-25 01:44:41 +00:00
World.FreeEntity(entityId);
2023-10-19 22:41:49 +00:00
}
2023-10-25 01:44:41 +00:00
RowToEntity.Clear();
2023-10-19 22:41:49 +00:00
}
}