/// <summary> /// Loops through entities with matching three components /// </summary> public void ForEach <T, J, K>(CompAction <T, J, K> action) where T : struct, IComponent where J : struct, IComponent where K : struct, IComponent { var manager = Game.Get <Game>().EntityManager; var components = manager.components; if (GetPool <T>() is BytePool poolT) { if (GetPool <J>() is BytePool poolJ) { if (GetPool <K>() is BytePool poolK) { for (int i = 0; i < manager.entities.Count; i++) { if (DoesMeetRequirementsAt(i) && poolT.IsValidAt(i) && poolJ.IsValidAt(i) && poolK.IsValidAt(i)) { var spanT = poolT.AsSpan <T>(); var spanJ = poolJ.AsSpan <J>(); var spanK = poolK.AsSpan <K>(); action(ref spanT[i], ref spanJ[i], ref spanK[i]); } } } } } Requirements.Clear(); }
/// <summary> /// Loops through entities with the matching component /// </summary> public void ForEach <T>(CompAction <T> action) where T : struct, IComponent { var manager = Game.Get <Game>().EntityManager; var components = manager.components; if (GetPool <T>() is BytePool pool) { for (int i = 0; i < manager.entities.Count; i++) { if (DoesMeetRequirementsAt(i) && pool.IsValidAt(i)) { var spanT = pool.AsSpan <T>(); action(ref spanT[i]); } } } Requirements.Clear(); }