public NativeArray <ArchetypeChunk> CreateArchetypeChunkArray(EntityArchetypeQuery query, Allocator allocator) { var foundArchetypes = new NativeList <EntityArchetype>(Allocator.TempJob); AddMatchingArchetypes(query, foundArchetypes); var chunkStream = CreateArchetypeChunkArray(foundArchetypes, allocator); foundArchetypes.Dispose(); return(chunkStream); }
public NativeArray <ArchetypeChunk> CreateArchetypeChunkArray(EntityArchetypeQuery query, Allocator allocator) { NativeList <EntityArchetype> foundArchetypes = new NativeList <EntityArchetype>(Allocator.TempJob); this.AddMatchingArchetypes(query, foundArchetypes); NativeArray <ArchetypeChunk> array = this.CreateArchetypeChunkArray(foundArchetypes, allocator); foundArchetypes.Dispose(); return(array); }
public NativeArray <Entity> GetAllEntities(Allocator allocator = 2) { this.BeforeStructuralChange(); EntityArchetypeQuery query1 = new EntityArchetypeQuery(); query1.Any = Array.Empty <ComponentType>(); query1.None = Array.Empty <ComponentType>(); query1.All = Array.Empty <ComponentType>(); EntityArchetypeQuery query = query1; EntityArchetypeQuery query4 = new EntityArchetypeQuery { Any = Array.Empty <ComponentType>(), None = Array.Empty <ComponentType>() }; query4.All = new ComponentType[] { typeof(Disabled) }; EntityArchetypeQuery query2 = query4; query4 = new EntityArchetypeQuery { Any = Array.Empty <ComponentType>(), None = Array.Empty <ComponentType>() }; query4.All = new ComponentType[] { typeof(Prefab) }; EntityArchetypeQuery query3 = query4; NativeList <EntityArchetype> foundArchetypes = new NativeList <EntityArchetype>(Allocator.TempJob); this.AddMatchingArchetypes(query, foundArchetypes); this.AddMatchingArchetypes(query2, foundArchetypes); this.AddMatchingArchetypes(query3, foundArchetypes); NativeArray <ArchetypeChunk> chunks = this.CreateArchetypeChunkArray(foundArchetypes, Allocator.TempJob); NativeArray <Entity> thisArray = new NativeArray <Entity>(ArchetypeChunkArray.CalculateEntityCount(chunks), allocator, NativeArrayOptions.ClearMemory); ArchetypeChunkEntityType archetypeChunkEntityType = this.GetArchetypeChunkEntityType(); int start = 0; int num3 = 0; while (true) { if (num3 >= chunks.Length) { chunks.Dispose(); foundArchetypes.Dispose(); return(thisArray); } NativeArray <Entity> nativeArray = chunks[num3].GetNativeArray(archetypeChunkEntityType); thisArray.Slice <Entity>(start, nativeArray.Length).CopyFrom(nativeArray); start += nativeArray.Length; num3++; } }
public NativeArray <Entity> GetAllEntities(Allocator allocator = Allocator.Temp) { BeforeStructuralChange(); var enabledQuery = new EntityArchetypeQuery { Any = Array.Empty <ComponentType>(), None = Array.Empty <ComponentType>(), All = Array.Empty <ComponentType>(), }; var disabledQuery = new EntityArchetypeQuery { Any = Array.Empty <ComponentType>(), None = Array.Empty <ComponentType>(), All = new ComponentType[] { typeof(Disabled) } }; var prefabQuery = new EntityArchetypeQuery { Any = Array.Empty <ComponentType>(), None = Array.Empty <ComponentType>(), All = new ComponentType[] { typeof(Prefab) } }; var archetypes = new NativeList <EntityArchetype>(Allocator.TempJob); AddMatchingArchetypes(enabledQuery, archetypes); AddMatchingArchetypes(disabledQuery, archetypes); AddMatchingArchetypes(prefabQuery, archetypes); var chunks = CreateArchetypeChunkArray(archetypes, Allocator.TempJob); var count = ArchetypeChunkArray.CalculateEntityCount(chunks); var array = new NativeArray <Entity>(count, allocator); var entityType = GetArchetypeChunkEntityType(); var offset = 0; for (int i = 0; i < chunks.Length; i++) { var chunk = chunks[i]; var entities = chunk.GetNativeArray(entityType); array.Slice(offset, entities.Length).CopyFrom(entities); offset += entities.Length; } chunks.Dispose(); archetypes.Dispose(); return(array); }
public void AddMatchingArchetypes(EntityArchetypeQuery query, NativeList <EntityArchetype> foundArchetypes) { var anyCount = query.Any.Length; var noneCount = query.None.Length; var allCount = query.All.Length; fixed(ComponentType *any = query.Any) { fixed(ComponentType *none = query.None) { fixed(ComponentType *all = query.All) { for (var archetype = ArchetypeManager.m_LastArchetype; archetype != null; archetype = archetype->PrevArchetype) { if (archetype->EntityCount == 0) { continue; } if (!TestMatchingArchetypeAny(archetype, any, anyCount)) { continue; } if (!TestMatchingArchetypeNone(archetype, none, noneCount)) { continue; } if (!TestMatchingArchetypeAll(archetype, all, allCount)) { continue; } var entityArchetype = new EntityArchetype { Archetype = archetype }; var found = foundArchetypes.Contains(entityArchetype); if (!found) { foundArchetypes.Add(entityArchetype); } } } } } }
public unsafe void AddMatchingArchetypes(EntityArchetypeQuery query, NativeList <EntityArchetype> foundArchetypes) { ComponentType *typePtr; ComponentType[] pinned typeArray; ComponentType *typePtr2; ComponentType[] pinned typeArray2; ComponentType *typePtr3; ComponentType[] pinned typeArray3; int length = query.Any.Length; int noneCount = query.None.Length; int allCount = query.All.Length; if (((typeArray = query.Any) == null) || (typeArray.Length == 0)) { typePtr = null; } else { typePtr = typeArray; } if (((typeArray2 = query.None) == null) || (typeArray2.Length == 0)) { typePtr2 = null; } else { typePtr2 = typeArray2; } if (((typeArray3 = query.All) == null) || (typeArray3.Length == 0)) { typePtr3 = null; } else { typePtr3 = typeArray3; } Archetype *lastArchetype = this.ArchetypeManager.m_LastArchetype; while (true) { if (lastArchetype == null) { typeArray3 = null; typeArray2 = null; typeArray = null; return; } bool flag2 = lastArchetype->EntityCount == 0; if ((!flag2 && (this.TestMatchingArchetypeAny(lastArchetype, typePtr, length) && this.TestMatchingArchetypeNone(lastArchetype, typePtr2, noneCount))) && this.TestMatchingArchetypeAll(lastArchetype, typePtr3, allCount)) { EntityArchetype archetype = new EntityArchetype { Archetype = lastArchetype }; if (!foundArchetypes.Contains <EntityArchetype, EntityArchetype>(archetype)) { foundArchetypes.Add(archetype); } } lastArchetype = lastArchetype->PrevArchetype; } }