using Svelto.Common; using Svelto.DataStructures; using Svelto.ECS.Internal; namespace Svelto.ECS { /// /// ToDo it would be interesting to have a version of this dedicated to unmanaged, IEntityComponent /// that can be burstifiable /// /// public readonly ref struct AllGroupsEnumerable where T1 : struct, _IInternalEntityComponent { public readonly ref struct GroupCollection { readonly EntityCollection collection; readonly ExclusiveGroupStruct group; public GroupCollection(EntityCollection entityCollection, ExclusiveGroupStruct groupKey) { collection = entityCollection; group = groupKey; } public void Deconstruct(out EntityCollection collection, out ExclusiveGroupStruct group) { collection = this.collection; group = this.@group; } } public AllGroupsEnumerable(EntitiesDB db) { _db = db; } public ref struct GroupsIterator { public GroupsIterator(EntitiesDB db) : this() { _db = db.FindGroups_INTERNAL(ComponentTypeID.id).GetEnumerator(); } public bool MoveNext() { //attention, the while is necessary to skip empty groups while (_db.MoveNext() == true) { var group = _db.Current; if (group.key.IsEnabled() == false) continue; ITypeSafeDictionary typeSafeDictionary = @group.value as ITypeSafeDictionary; if (typeSafeDictionary.count == 0) continue; _array = new GroupCollection( new EntityCollection( typeSafeDictionary.GetValues(out var count), typeSafeDictionary.entityIDs, count), group.key); return true; } return false; } public GroupCollection Current => _array; SveltoDictionaryKeyValueEnumerator>, ManagedStrategy, ManagedStrategy> _db; GroupCollection _array; } public GroupsIterator GetEnumerator() { return new GroupsIterator(_db); } readonly EntitiesDB _db; } }