public unsafe NativeArray<int> MoveAllSharedComponents(SharedComponentDataManager srcSharedComponents, Allocator allocator) { var remap = new NativeArray<int>(srcSharedComponents.GetSharedComponentCount(), allocator); remap[0] = 0; for (int srcIndex = 1; srcIndex < remap.Length; ++srcIndex) { var srcData = srcSharedComponents.m_SharedComponentData[srcIndex]; if (srcData == null) continue; var typeIndex = srcSharedComponents.m_SharedComponentType[srcIndex]; var hashCode = TypeManager.GetHashCode(srcData, typeIndex); var dstIndex = InsertSharedComponentAssumeNonDefault(typeIndex, hashCode, srcData); m_SharedComponentRefCount[dstIndex] += srcSharedComponents.m_SharedComponentRefCount[srcIndex] - 1; remap[srcIndex] = dstIndex; } srcSharedComponents.m_HashLookup.Clear(); srcSharedComponents.m_SharedComponentVersion.ResizeUninitialized(1); srcSharedComponents.m_SharedComponentRefCount.ResizeUninitialized(1); srcSharedComponents.m_SharedComponentType.ResizeUninitialized(1); srcSharedComponents.m_SharedComponentData.Clear(); srcSharedComponents.m_SharedComponentData.Add(null); srcSharedComponents.m_FreeListIndex = -1; return remap; }
public unsafe NativeArray <int> MoveSharedComponents(SharedComponentDataManager srcSharedComponents, NativeArray <ArchetypeChunk> chunks, Allocator allocator) { var remap = new NativeArray <int>(srcSharedComponents.GetSharedComponentCount(), allocator); for (int i = 0; i < chunks.Length; ++i) { var chunk = chunks[i].m_Chunk; var archetype = chunk->Archetype; for (int sharedComponentIndex = 0; sharedComponentIndex < archetype->NumSharedComponents; ++sharedComponentIndex) { remap[chunk->SharedComponentValueArray[sharedComponentIndex]]++; } } remap[0] = 0; for (int srcIndex = 1; srcIndex < remap.Length; ++srcIndex) { if (remap[srcIndex] == 0) { continue; } var srcData = srcSharedComponents.m_SharedComponentData[srcIndex]; var typeIndex = srcSharedComponents.m_SharedComponentType[srcIndex]; var typeInfo = TypeManager.GetTypeInfo(typeIndex).FastEqualityTypeInfo; var hashCode = GetHashCodeFast(srcData, typeInfo); var dstIndex = InsertSharedComponentAssumeNonDefault(typeIndex, hashCode, srcData, typeInfo); m_SharedComponentRefCount[dstIndex] += remap[srcIndex] - 1; srcSharedComponents.RemoveReference(srcIndex, remap[srcIndex]); remap[srcIndex] = dstIndex; } return(remap); }