private void MoveToNextMatchingChunk() { var m = m_CurrentMatchingArchetype; var c = m_CurrentChunk; var e = m->Archetype->Chunks.p + m->Archetype->Chunks.Count; do { c = c + 1; while (c == e) { m_CurrentArchetypeEntityIndex += m_CurrentChunkEntityIndex; m_CurrentChunkEntityIndex = 0; m = m->Next; if (m == null) { m_CurrentMatchingArchetype = null; m_CurrentChunk = null; return; } c = m->Archetype->Chunks.p; e = m->Archetype->Chunks.p + m->Archetype->Chunks.Count; } } while (!((*c)->MatchesFilter(m, ref m_Filter) && (*c)->Capacity > 0)); m_CurrentMatchingArchetype = m; m_CurrentChunk = c; }
public unsafe void MoveToChunkWithoutFiltering(int index) { if (index < this.m_CurrentArchetypeIndex) { this.m_CurrentMatchingArchetype = this.m_FirstMatchingArchetype; this.m_CurrentChunk = (Chunk *)this.m_CurrentMatchingArchetype.Archetype.ChunkList.Begin; this.m_CurrentArchetypeIndex = this.m_CurrentArchetypeEntityIndex = 0; this.m_CurrentChunkIndex = this.m_CurrentChunkEntityIndex = 0; } while (true) { if (index < (this.m_CurrentArchetypeIndex + this.m_CurrentMatchingArchetype.Archetype.ChunkCount)) { index -= this.m_CurrentArchetypeIndex; if (index < this.m_CurrentChunkIndex) { this.m_CurrentChunk = (Chunk *)this.m_CurrentMatchingArchetype.Archetype.ChunkList.Begin; this.m_CurrentChunkIndex = this.m_CurrentChunkEntityIndex = 0; } while (index >= (this.m_CurrentChunkIndex + 1)) { this.m_CurrentChunkEntityIndex += this.m_CurrentChunk.Count; this.m_CurrentChunkIndex++; this.m_CurrentChunk = (Chunk *)this.m_CurrentChunk.ChunkListNode.Next; } return; } this.m_CurrentArchetypeEntityIndex += this.m_CurrentMatchingArchetype.Archetype.EntityCount; this.m_CurrentArchetypeIndex += this.m_CurrentMatchingArchetype.Archetype.ChunkCount; this.m_CurrentMatchingArchetype = this.m_CurrentMatchingArchetype.Next; this.m_CurrentChunk = (Chunk *)this.m_CurrentMatchingArchetype.Archetype.ChunkList.Begin; this.m_CurrentChunkIndex = this.m_CurrentChunkEntityIndex = 0; } }
private void MoveToNextMatchingChunk() { var m = m_CurrentMatchingArchetype; var c = m_CurrentChunk; var e = (Chunk *)m->Archetype->ChunkList.End; do { c = (Chunk *)c->ChunkListNode.Next; while (c == e) { m_CurrentArchetypeEntityIndex += m_CurrentChunkEntityIndex; m_CurrentChunkEntityIndex = 0; m = m->Next; if (m == null) { m_CurrentMatchingArchetype = null; m_CurrentChunk = null; return; } c = (Chunk *)m->Archetype->ChunkList.Begin; e = (Chunk *)m->Archetype->ChunkList.End; } } while (!(c->MatchesFilter(m, ref m_Filter) && c->Capacity > 0)); m_CurrentMatchingArchetype = m; m_CurrentChunk = c; }
public void MoveToChunkByIndex(int index) { if (index < m_CurrentArchetypeIndex || m_CurrentChunk == null) { m_CurrentMatchingArchetype = m_FirstMatchingArchetype; m_CurrentArchetypeIndex = 0; m_CurrentChunk = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin; m_CurrentChunkIndex = 0; } while (index >= m_CurrentArchetypeIndex + m_CurrentMatchingArchetype->Archetype->ChunkCount) { m_CurrentArchetypeIndex += m_CurrentMatchingArchetype->Archetype->ChunkCount; m_CurrentMatchingArchetype = m_CurrentMatchingArchetype->Next; m_CurrentChunk = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin; m_CurrentChunkIndex = 0; } index -= m_CurrentArchetypeIndex; if (index < m_CurrentChunkIndex) { m_CurrentChunk = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin; m_CurrentChunkIndex = 0; } while (index >= m_CurrentChunkIndex + 1) { m_CurrentChunkIndex += 1; m_CurrentChunk = (Chunk *)m_CurrentChunk->ChunkListNode.Next; } }
private unsafe void AddArchetypeIfMatching(Archetype *archetype, EntityGroupData *group) { if (IsMatchingArchetype(archetype, group)) { MatchingArchetypes *archetypesPtr = (MatchingArchetypes *)ref this.m_GroupDataChunkAllocator.Allocate(MatchingArchetypes.GetAllocationSize(group.RequiredComponentsCount), 8); archetypesPtr->Archetype = archetype; int *numPtr = &archetypesPtr->IndexInArchetype.FixedElementField; if (group.LastMatchingArchetype == null) { group.LastMatchingArchetype = archetypesPtr; } archetypesPtr->Next = group.FirstMatchingArchetype; group.FirstMatchingArchetype = archetypesPtr; int index = 0; while (true) { if (index >= group.RequiredComponentsCount) { break; } int actual = -1; if (group.RequiredComponents[index].AccessModeType != ComponentType.AccessMode.Subtractive) { actual = ChunkDataUtility.GetIndexInTypeArray(archetype, group.RequiredComponents[index].TypeIndex); Assert.AreNotEqual(-1, actual); } numPtr[index] = actual; index++; } } }
public void MoveToEntityIndex(int index) { if (!m_Filter.RequiresMatchesFilter) { if (index < m_CurrentArchetypeEntityIndex) { m_CurrentMatchingArchetype = m_FirstMatchingArchetype; m_CurrentArchetypeEntityIndex = 0; m_CurrentChunk = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin; // m_CurrentChunk might point to an invalid chunk if the first matching archetype has no chunks // the while loop below will move to the first archetype that has any entities m_CurrentChunkEntityIndex = 0; } while (index >= m_CurrentArchetypeEntityIndex + m_CurrentMatchingArchetype->Archetype->EntityCount) { m_CurrentArchetypeEntityIndex += m_CurrentMatchingArchetype->Archetype->EntityCount; m_CurrentMatchingArchetype = m_CurrentMatchingArchetype->Next; m_CurrentChunk = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin; m_CurrentChunkEntityIndex = 0; } index -= m_CurrentArchetypeEntityIndex; if (index < m_CurrentChunkEntityIndex) { m_CurrentChunk = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin; m_CurrentChunkEntityIndex = 0; } while (index >= m_CurrentChunkEntityIndex + m_CurrentChunk->Count) { m_CurrentChunkEntityIndex += m_CurrentChunk->Count; m_CurrentChunk = (Chunk *)m_CurrentChunk->ChunkListNode.Next; } } else { if (index < m_CurrentArchetypeEntityIndex + m_CurrentChunkEntityIndex) { if (index < m_CurrentArchetypeEntityIndex) { m_CurrentMatchingArchetype = m_FirstMatchingArchetype; m_CurrentArchetypeEntityIndex = 0; } m_CurrentChunk = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.End; // m_CurrentChunk now points to an invalid chunk but since the chunk list is circular // it effectively points to the chunk before the first // MoveToNextMatchingChunk will move it to a valid chunk if any exists m_CurrentChunkEntityIndex = 0; MoveToNextMatchingChunk(); } while (index >= m_CurrentArchetypeEntityIndex + m_CurrentChunkEntityIndex + m_CurrentChunk->Count) { m_CurrentChunkEntityIndex += m_CurrentChunk->Count; MoveToNextMatchingChunk(); } } }
// Determines how many chunks of a particular archetype we must iterate through while filtering // If the chunk is in the current archetype, we can calculate # of iterations // If the chunk is not in the current archetype, just loop over all chunks in the current archetype private int CalculateFilteredIterationChunkCount(MatchingArchetypes *match) { var archetype = match->Archetype; var chunkCount = match == m_CurrentMatchingArchetype ? (int)((m_CurrentChunk - archetype->Chunks.p) / sizeof(Chunk *)) : archetype->Chunks.Count; return(chunkCount); }
public int GetSharedComponentIndex(MatchingArchetypes *match, int indexInComponentGroup) { var sharedComponentsInChunk = SharedComponentValueArray; var componentIndexInArcheType = match->TypeIndexInArchetypeArray[indexInComponentGroup]; var componentIndexInChunk = match->Archetype->SharedComponentOffset[componentIndexInArcheType]; return(sharedComponentsInChunk[componentIndexInChunk]); }
public ComponentChunkIterator(MatchingArchetypes *match, int length, Chunk *firstChunk, int *filteredSharedComponents) { m_FirstMatchingArchetype = match; m_CurrentMatchingArchetype = match; IndexInComponentGroup = -1; m_CurrentArchetypeIndex = 0; m_CurrentChunk = firstChunk; m_CurrentChunkIndex = 0; m_FilteredSharedComponents = filteredSharedComponents; }
internal static unsafe int CalculateNumberOfChunksWithoutFiltering(MatchingArchetypes *firstMatchingArchetype) { int num = 0; for (MatchingArchetypes *archetypesPtr = firstMatchingArchetype; archetypesPtr != null; archetypesPtr = archetypesPtr->Next) { num += archetypesPtr->Archetype.ChunkCount; } return(num); }
internal static int CalculateNumberOfChunksWithoutFiltering(MatchingArchetypes *firstMatchingArchetype) { var chunkCount = 0; for (var match = firstMatchingArchetype; match != null; match = match->Next) { chunkCount += match->Archetype->ChunkCount; } return(chunkCount); }
public static unsafe NativeArray <ArchetypeChunk> CreateArchetypeChunkArray(MatchingArchetypes *firstMatchingArchetype, Allocator allocator, out JobHandle jobHandle) { GatherChunksJob jobData = new GatherChunksJob { matchingArchetype = firstMatchingArchetype, chunks = new NativeArray <ArchetypeChunk>(CalculateNumberOfChunksWithoutFiltering(firstMatchingArchetype), allocator, NativeArrayOptions.ClearMemory) }; JobHandle dependsOn = new JobHandle(); jobHandle = jobData.Schedule <GatherChunksJob>(dependsOn); return(jobData.chunks); }
public unsafe ComponentChunkIterator(MatchingArchetypes *match, uint globalSystemVersion, ref ComponentGroupFilter filter) { this.m_FirstMatchingArchetype = match; this.m_CurrentMatchingArchetype = match; this.IndexInComponentGroup = -1; this.m_CurrentChunk = null; this.m_CurrentArchetypeIndex = this.m_CurrentArchetypeEntityIndex = 0x7fffffff; this.m_CurrentChunkIndex = this.m_CurrentChunkEntityIndex = 0; this.m_GlobalSystemVersion = globalSystemVersion; this.m_Filter = filter; }
public ComponentChunkIterator(MatchingArchetypes *match, uint globalSystemVersion, ref ComponentGroupFilter filter) { m_FirstMatchingArchetype = match; m_CurrentMatchingArchetype = match; IndexInComponentGroup = -1; m_CurrentChunk = null; m_CurrentArchetypeIndex = m_CurrentArchetypeEntityIndex = int.MaxValue; // This will trigger UpdateCacheResolvedIndex to update the cache on first access m_CurrentChunkIndex = m_CurrentChunkEntityIndex = 0; m_GlobalSystemVersion = globalSystemVersion; m_Filter = filter; }
public bool MatchesFilter(MatchingArchetypes *match, ref ComponentGroupFilter filter) { if (filter.Type == FilterType.SharedComponent) { var sharedComponentsInChunk = SharedComponentValueArray; var filteredCount = filter.Shared.Count; fixed(int *indexInComponentGroupPtr = filter.Shared.IndexInComponentGroup, sharedComponentIndexPtr = filter.Shared.SharedComponentIndex) { for (var i = 0; i < filteredCount; ++i) { var indexInComponentGroup = indexInComponentGroupPtr[i]; var sharedComponentIndex = sharedComponentIndexPtr[i]; var componentIndexInArcheType = match->TypeIndexInArchetypeArray[indexInComponentGroup]; var componentIndexInChunk = match->Archetype->SharedComponentOffset[componentIndexInArcheType]; if (sharedComponentsInChunk[componentIndexInChunk] != sharedComponentIndex) { return(false); } } } return(true); } if (filter.Type == FilterType.Changed) { var changedCount = filter.Changed.Count; var requiredVersion = filter.RequiredChangeVersion; fixed(int *indexInComponentGroupPtr = filter.Changed.IndexInComponentGroup) { for (var i = 0; i < changedCount; ++i) { var indexInArchetype = match->TypeIndexInArchetypeArray[indexInComponentGroupPtr[i]]; var changeVersion = ChangeVersion[indexInArchetype]; if (ChangeVersionUtility.DidChange(changeVersion, requiredVersion)) { return(true); } } } return(false); } return(true); }
public static NativeArray <ArchetypeChunk> CreateArchetypeChunkArray(MatchingArchetypes *firstMatchingArchetype, Allocator allocator, out JobHandle jobHandle) { var chunkCount = CalculateNumberOfChunksWithoutFiltering(firstMatchingArchetype); var job = new GatherChunksJob { matchingArchetype = firstMatchingArchetype, chunks = new NativeArray <ArchetypeChunk>(chunkCount, allocator) }; jobHandle = job.Schedule(); return(job.chunks); }
public static unsafe int CalculateLength(MatchingArchetypes *firstMatchingArchetype, ref ComponentGroupFilter filter) { int num = 0; if (!filter.RequiresMatchesFilter) { MatchingArchetypes *next = firstMatchingArchetype; while (true) { if (next == null) { break; } num += next->Archetype.EntityCount; next = next->Next; } } else { MatchingArchetypes *match = firstMatchingArchetype; while (true) { if (match == null) { break; } if (match->Archetype.EntityCount > 0) { Archetype *archetype = match->Archetype; Chunk * begin = (Chunk *)archetype->ChunkList.Begin; while (true) { if (begin == archetype->ChunkList.End) { break; } if (begin.MatchesFilter(match, ref filter)) { Assert.IsTrue(begin->Count > 0); num += begin->Count; } begin = (Chunk *)begin->ChunkListNode.Next; } } match = match->Next; } } return(num); }
public void Execute() { int index = 0; for (; matchingArchetype != null; matchingArchetype = matchingArchetype->Next) { Archetype *archetype = matchingArchetype->Archetype; for (var c = (Chunk *)archetype->ChunkList.Begin; c != archetype->ChunkList.End; c = (Chunk *)c->ChunkListNode.Next) { chunks[index++] = new ArchetypeChunk { m_Chunk = c }; } } }
public static int CalculateLength(MatchingArchetypes *firstMatchingArchetype, ref ComponentGroupFilter filter) { // Update the archetype segments var length = 0; if (!filter.RequiresMatchesFilter) { for (var match = firstMatchingArchetype; match != null; match = match->Next) { length += match->Archetype->EntityCount; } } else { /* * Can't be enabled yet because a bunch of tests rely on it, need to make some decisions on this... #if ENABLE_UNITY_COLLECTIONS_CHECKS * if ((filter.Type & FilterType.Changed) != 0) * { * throw new System.ArgumentException("CalculateLength() can't be used with change filtering since it requires all component data to have been processed"); * } #endif */ for (var match = firstMatchingArchetype; match != null; match = match->Next) { if (match->Archetype->EntityCount <= 0) { continue; } var archeType = match->Archetype; for (var c = (Chunk *)archeType->ChunkList.Begin; c != archeType->ChunkList.End; c = (Chunk *)c->ChunkListNode.Next) { if (!c->MatchesFilter(match, ref filter)) { continue; } Assert.IsTrue(c->Count > 0); length += c->Count; } } } return(length); }
public static void CalculateInitialChunkIterators(MatchingArchetypes *firstMatchingArchetype, int indexInComponentGroup, NativeArray <int> sharedComponentIndex, NativeArray <IntPtr> outFirstArchetype, NativeArray <IntPtr> outFirstChunk, NativeArray <int> outLength) { var lookup = new NativeHashMap <int, int>(sharedComponentIndex.Length, Allocator.Temp); for (var f = 0; f < sharedComponentIndex.Length; ++f) { lookup.TryAdd(sharedComponentIndex[f], f); } for (var match = firstMatchingArchetype; match != null; match = match->Next) { if (match->Archetype->EntityCount <= 0) { continue; } var archeType = match->Archetype; for (var c = (Chunk *)archeType->ChunkList.Begin; c != archeType->ChunkList.End; c = (Chunk *)c->ChunkListNode.Next) { if (c->Count <= 0) { continue; } var chunkSharedComponentIndex = c->GetSharedComponentIndex(match, indexInComponentGroup); int filterIndex; if (!lookup.TryGetValue(chunkSharedComponentIndex, out filterIndex)) { continue; } outLength[filterIndex] = outLength[filterIndex] + c->Count; if (outFirstChunk[filterIndex] != IntPtr.Zero) { continue; } outFirstArchetype[filterIndex] = (IntPtr)match; outFirstChunk[filterIndex] = (IntPtr)c; } } lookup.Dispose(); }
public static int CalculateLength(MatchingArchetypes *firstMatchingArchetype, ref ComponentGroupFilter filter) { if (filter.Type == FilterType.IndexList) { return(filter.Indices.Length); } // Update the archetype segments var length = 0; if (!filter.RequiresMatchesFilter) { for (var match = firstMatchingArchetype; match != null; match = match->Next) { length += match->Archetype->EntityCount; } } else { for (var match = firstMatchingArchetype; match != null; match = match->Next) { if (match->Archetype->EntityCount <= 0) { continue; } var archeType = match->Archetype; for (var c = (Chunk *)archeType->ChunkList.Begin; c != archeType->ChunkList.End; c = (Chunk *)c->ChunkListNode.Next) { if (!c->MatchesFilter(match, ref filter)) { continue; } Assert.IsTrue(c->Count > 0); length += c->Count; } } } return(length); }
/// <summary> /// Creates a NativeArray with all the chunks in a given archetype. /// </summary> /// <param name="firstMatchingArchetype">First node of MatchingArchetypes linked list.</param> /// <param name="allocator">Allocator to use for the array.</param> /// <param name="jobHandle">Handle to the GatherChunks job used to fill the output array.</param> /// <returns>NativeArray of all the chunks in the firstMatchingArchetype list.</returns> public static NativeArray <ArchetypeChunk> CreateArchetypeChunkArray(MatchingArchetypes *firstMatchingArchetype, Allocator allocator, out JobHandle jobHandle) { var archetypeCount = 0; for (var match = firstMatchingArchetype; match != null; match = match->Next) { archetypeCount++; } var matchingArchetypes = new NativeArray <EntityArchetype>(archetypeCount, Allocator.TempJob); var offsets = new NativeArray <int>(archetypeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var chunkCount = 0; { int i = 0; var length = 0; for (var match = firstMatchingArchetype; match != null; match = match->Next) { var archetype = match->Archetype; matchingArchetypes[i] = new EntityArchetype { Archetype = archetype }; offsets[i] = length; length += archetype->Chunks.Count; i++; } chunkCount = length; } var chunks = new NativeArray <ArchetypeChunk>(chunkCount, allocator, NativeArrayOptions.UninitializedMemory); var gatherChunksJob = new GatherChunks { Archetypes = matchingArchetypes, Offsets = offsets, Chunks = chunks }; var gatherChunksJobHandle = gatherChunksJob.Schedule(archetypeCount, 1); jobHandle = gatherChunksJobHandle; return(chunks); }
public bool MatchesFilter(MatchingArchetypes *match, int *filteredSharedComponents) { var sharedComponentsInChunk = SharedComponentValueArray; var filteredCount = filteredSharedComponents[0]; var filtered = filteredSharedComponents + 1; for (var i = 0; i < filteredCount; ++i) { var componetIndexInComponentGroup = filtered[i * 2]; var sharedComponentIndex = filtered[i * 2 + 1]; var componentIndexInArcheType = match->TypeIndexInArchetypeArray[componetIndexInComponentGroup]; var componentIndexInChunk = match->Archetype->SharedComponentOffset[componentIndexInArcheType]; if (sharedComponentsInChunk[componentIndexInChunk] != sharedComponentIndex) { return(false); } } return(true); }
/// <summary> /// Creates a NativeArray containing the entities in a given ComponentGroup. /// </summary> /// <param name="firstMatchingArchetype">First node of MatchingArchetypes linked list.</param> /// <param name="allocator">Allocator to use for the array.</param> /// <param name="type">An atomic safety handle required by GatherEntitiesJob so it can call GetNativeArray() on chunks.</param> /// <param name="componentGroup">ComponentGroup to gather entities from.</param> /// <param name="filter">ComponentGroupFilter for calculating the length of the output array.</param> /// <param name="jobHandle">Handle to the GatherEntitiesJob job used to fill the output array.</param> /// <param name="dependsOn">Handle to a job this GatherEntitiesJob must wait on.</param> /// <returns>NativeArray of the entities in a given ComponentGroup.</returns> public static NativeArray <Entity> CreateEntityArray(MatchingArchetypes *firstMatchingArchetype, Allocator allocator, ArchetypeChunkEntityType type, ComponentGroup componentGroup, ref ComponentGroupFilter filter, out JobHandle jobHandle, JobHandle dependsOn) { var entityCount = CalculateLength(firstMatchingArchetype, ref filter); var job = new GatherEntitiesJob { EntityType = type, Entities = new NativeArray <Entity>(entityCount, allocator) }; jobHandle = job.Schedule(componentGroup, dependsOn); return(job.Entities); }
public static NativeArray <T> CreateComponentDataArray <T>(MatchingArchetypes *firstMatchingArchetype, Allocator allocator, ArchetypeChunkComponentType <T> type, ComponentGroup componentGroup, ref ComponentGroupFilter filter, out JobHandle jobHandle, JobHandle dependsOn) where T : struct, IComponentData { var entityCount = CalculateLength(firstMatchingArchetype, ref filter); var job = new GatherComponentDataJob <T> { ComponentData = new NativeArray <T>(entityCount, allocator), ComponentType = type }; jobHandle = job.Schedule(componentGroup, dependsOn); return(job.ComponentData); }
/// <summary> /// Total number of entities contained in a given MatchingArchetype list. /// </summary> /// <param name="firstMatchingArchetype">First node of MatchingArchetypes linked list.</param> /// <param name="filter">ComponentGroupFilter to use when calculating total number of entities.</param> /// <returns>Number of entities</returns> public static int CalculateLength(MatchingArchetypes *firstMatchingArchetype, ref ComponentGroupFilter filter) { // Update the archetype segments var length = 0; if (!filter.RequiresMatchesFilter) { for (var match = firstMatchingArchetype; match != null; match = match->Next) { length += match->Archetype->EntityCount; } } else { for (var match = firstMatchingArchetype; match != null; match = match->Next) { if (match->Archetype->EntityCount <= 0) { continue; } var archeType = match->Archetype; for (var ci = 0; ci < archeType->Chunks.Count; ++ci) { var c = archeType->Chunks.p[ci]; if (!c->MatchesFilter(match, ref filter)) { continue; } Assert.IsTrue(c->Count > 0); length += c->Count; } } } return(length); }
public void MoveToChunkWithoutFiltering(int index) { if (index < m_CurrentArchetypeIndex) { m_CurrentMatchingArchetype = m_FirstMatchingArchetype; m_CurrentChunk = m_CurrentMatchingArchetype->Archetype->Chunks.p; m_CurrentArchetypeIndex = m_CurrentArchetypeEntityIndex = 0; m_CurrentChunkIndex = m_CurrentChunkEntityIndex = 0; } while (index >= m_CurrentArchetypeIndex + m_CurrentMatchingArchetype->Archetype->Chunks.Count) { m_CurrentArchetypeEntityIndex += m_CurrentMatchingArchetype->Archetype->EntityCount; m_CurrentArchetypeIndex += m_CurrentMatchingArchetype->Archetype->Chunks.Count; m_CurrentMatchingArchetype = m_CurrentMatchingArchetype->Next; m_CurrentChunk = m_CurrentMatchingArchetype->Archetype->Chunks.p; m_CurrentChunkIndex = m_CurrentChunkEntityIndex = 0; } index -= m_CurrentArchetypeIndex; if (index < m_CurrentChunkIndex) { m_CurrentChunk = m_CurrentMatchingArchetype->Archetype->Chunks.p; m_CurrentChunkIndex = m_CurrentChunkEntityIndex = 0; } while (index >= m_CurrentChunkIndex + 1) { m_CurrentChunkEntityIndex += (*m_CurrentChunk)->Count; m_CurrentChunkIndex += 1; m_CurrentChunk = m_CurrentChunk + 1; } }
public void MoveToChunkWithoutFiltering(int index) { if (index < m_CurrentArchetypeIndex) { m_CurrentMatchingArchetype = m_FirstMatchingArchetype; m_CurrentChunk = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin; m_CurrentArchetypeIndex = m_CurrentArchetypeEntityIndex = 0; m_CurrentChunkIndex = m_CurrentChunkEntityIndex = 0; } while (index >= m_CurrentArchetypeIndex + m_CurrentMatchingArchetype->Archetype->ChunkCount) { m_CurrentArchetypeEntityIndex += m_CurrentMatchingArchetype->Archetype->EntityCount; m_CurrentArchetypeIndex += m_CurrentMatchingArchetype->Archetype->ChunkCount; m_CurrentMatchingArchetype = m_CurrentMatchingArchetype->Next; m_CurrentChunk = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin; m_CurrentChunkIndex = m_CurrentChunkEntityIndex = 0; } index -= m_CurrentArchetypeIndex; if (index < m_CurrentChunkIndex) { m_CurrentChunk = (Chunk *)m_CurrentMatchingArchetype->Archetype->ChunkList.Begin; m_CurrentChunkIndex = m_CurrentChunkEntityIndex = 0; } while (index >= m_CurrentChunkIndex + 1) { m_CurrentChunkEntityIndex += m_CurrentChunk->Count; m_CurrentChunkIndex += 1; m_CurrentChunk = (Chunk *)m_CurrentChunk->ChunkListNode.Next; } }
public bool MatchesFilter(MatchingArchetypes *match, ref ComponentGroupFilter filter) { var sharedComponentsInChunk = SharedComponentValueArray; var filteredCount = filter.FilterCount; Assert.IsTrue(filteredCount > 0); fixed(int *indexInComponentGroupPtr = filter.IndexInComponentGroup, sharedComponentIndexPtr = filter.SharedComponentIndex) { for (var i = 0; i < filteredCount; ++i) { var indexInComponentGroup = indexInComponentGroupPtr[i]; var sharedComponentIndex = sharedComponentIndexPtr[i]; var componentIndexInArcheType = match->TypeIndexInArchetypeArray[indexInComponentGroup]; var componentIndexInChunk = match->Archetype->SharedComponentOffset[componentIndexInArcheType]; if (sharedComponentsInChunk[componentIndexInChunk] != sharedComponentIndex) { return(false); } } } return(true); }
public unsafe void Execute() { int index = 0; while (this.matchingArchetype != null) { Archetype *archetype = this.matchingArchetype.Archetype; Chunk * begin = (Chunk *)archetype->ChunkList.Begin; while (true) { if (begin == archetype->ChunkList.End) { this.matchingArchetype = this.matchingArchetype.Next; break; } index++; ArchetypeChunk chunk = new ArchetypeChunk { m_Chunk = begin }; this.chunks.set_Item(index, chunk); begin = (Chunk *)begin->ChunkListNode.Next; } } }