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()); }
private PackedComponent PackComponent(EntityGuid entityGuid, int typeIndex, ulong stableTypeHash) { var flags = ComponentTypeFlags.None; if ((typeIndex & TypeManager.ChunkComponentTypeFlag) != 0) { flags |= ComponentTypeFlags.ChunkComponent; } var packedEntityIndex = PackedEntityCollection.GetOrAdd(entityGuid); var packedTypeIndex = PackedStableTypeHashCollection.GetOrAdd(new ComponentTypeHash { StableTypeHash = stableTypeHash, Flags = flags }); return(new PackedComponent { PackedEntityIndex = packedEntityIndex, PackedTypeIndex = packedTypeIndex }); }