private static PackedSharedComponentDataChange[] GetChangedSharedComponents( PackedCollection <EntityGuid> packedEntityCollection, PackedCollection <ComponentTypeHash> packedStableTypeHashCollection, NativeList <DeferredPackedSharedComponentDataChange> changes, ManagedComponentStore beforeManagedComponentStore, ManagedComponentStore afterManagedComponentStore) { if (changes.Length == 0) { return(s_EmptySetSharedComponentDiff); } var result = new List <PackedSharedComponentDataChange>(); for (var i = 0; i < changes.Length; i++) { var change = changes[i]; object afterValue = null; if (change.AfterSharedComponentIndex != 0) { afterValue = afterManagedComponentStore.GetSharedComponentDataBoxed(change.AfterSharedComponentIndex, change.TypeIndex); } if (change.BeforeSharedComponentIndex > -1 && change.AfterSharedComponentIndex != 0) { var beforeValue = beforeManagedComponentStore.GetSharedComponentDataBoxed(change.BeforeSharedComponentIndex, change.TypeIndex); if (TypeManager.Equals(beforeValue, afterValue, change.TypeIndex)) { continue; } } var packedEntityIndex = packedEntityCollection.GetOrAdd(change.EntityGuid); var packedTypeIndex = packedStableTypeHashCollection.GetOrAdd(new ComponentTypeHash { StableTypeHash = TypeManager.GetTypeInfo(change.TypeIndex).StableTypeHash }); var packedComponent = new PackedComponent { PackedEntityIndex = packedEntityIndex, PackedTypeIndex = packedTypeIndex }; result.Add(new PackedSharedComponentDataChange { Component = packedComponent, BoxedSharedValue = afterValue }); } return(result.ToArray()); }
public unsafe BuildChangeSetTask(WorldState beforeState, WorldState afterState, TypeInfoStream typeInfoStream, Allocator allocator) { m_BeforeState = beforeState; m_AfterState = afterState; m_TypeInfoStream = typeInfoStream; m_CreatedEntities = new NativeList <EntityInChunkWithComponent <EntityGuid> >(1, allocator); m_ModifiedEntities = new NativeList <ModifiedEntity>(1, allocator); m_DestroyedEntities = new NativeList <EntityInChunkWithComponent <EntityGuid> >(1, allocator); m_PackedEntities = new PackedCollection <EntityGuid>(1, allocator); m_PackedStableTypeHashes = new PackedCollection <ComponentTypeHash>(1, allocator); m_AddComponents = new NativeList <PackedComponent>(1, allocator); m_RemoveComponents = new NativeList <PackedComponent>(1, allocator); m_ComponentDataStream = new ComponentDataStream(allocator); m_EntityReference = new NativeList <EntityReferenceChange>(1, allocator); m_LinkedEntityGroupAdditions = new NativeList <LinkedEntityGroupChange>(1, allocator); m_LinkedEntityGroupRemovals = new NativeList <LinkedEntityGroupChange>(1, allocator); m_BeforeEntityToEntityGuid = new EntityToComponentMap <EntityGuid>(m_BeforeState.EntityComponentStore, allocator); m_AfterEntityToEntityGuid = new EntityToComponentMap <EntityGuid>(m_AfterState.EntityComponentStore, allocator); IsCreated = true; }