示例#1
0
        public static unsafe void DeserializeWorld(ExclusiveEntityTransaction manager, BinaryReader reader)
        {
            int storedVersion = reader.ReadInt();

            if (storedVersion != CurrentFileFormatVersion)
            {
                throw new ArgumentException(
                          $"Attempting to read a entity scene stored in an old file format version (stored version : {storedVersion}, current version : {CurrentFileFormatVersion})");
            }

            var types      = ReadTypeArray(reader);
            var archetypes = ReadArchetypes(reader, types, manager, out var totalEntityCount);

            manager.AllocateConsecutiveEntitiesForLoading(totalEntityCount);

            int totalChunkCount = reader.ReadInt();

            for (int i = 0; i < totalChunkCount; ++i)
            {
                var chunk = (Chunk *)UnsafeUtility.Malloc(Chunk.kChunkSize, 64, Allocator.Persistent);
                reader.ReadBytes(chunk, Chunk.kChunkSize);

                chunk->Archetype = archetypes[(int)chunk->Archetype].Archetype;
                // Fixup the pointer to the shared component values
                // todo: more generic way of fixing up pointers?
                chunk->SharedComponentValueArray = (int *)((byte *)(chunk) + Chunk.GetSharedComponentOffset(chunk->Archetype->NumSharedComponents));
                chunk->ChangeVersion             = (uint *)((byte *)chunk +
                                                            Chunk.GetChangedComponentOffset(chunk->Archetype->TypesCount,
                                                                                            chunk->Archetype->NumSharedComponents));
                manager.AddExistingChunk(chunk);
            }

            archetypes.Dispose();
        }
示例#2
0
 public static void ReleaseSharedComponents(ExclusiveEntityTransaction transaction, int sharedComponentCount)
 {
     // Chunks have now taken over ownership of the shared components (reference counts have been added)
     // so remove the ref that was added on deserialization
     for (int i = 0; i < sharedComponentCount; ++i)
     {
         transaction.SharedComponentDataManager.RemoveReference(i + 1);
     }
 }
        public static unsafe void DeserializeWorld(ExclusiveEntityTransaction manager, BinaryReader reader)
        {
            int storedVersion = reader.ReadInt();

            if (storedVersion != CurrentFileFormatVersion)
            {
                throw new ArgumentException(
                          $"Attempting to read a entity scene stored in an old file format version (stored version : {storedVersion}, current version : {CurrentFileFormatVersion})");
            }

            var types      = ReadTypeArray(reader);
            var archetypes = ReadArchetypes(reader, types, manager, out var totalEntityCount);

            manager.AllocateConsecutiveEntitiesForLoading(totalEntityCount);

            int totalChunkCount = reader.ReadInt();

            for (int i = 0; i < totalChunkCount; ++i)
            {
                var chunk = (Chunk *)UnsafeUtility.Malloc(Chunk.kChunkSize, 64, Allocator.Persistent);
                reader.ReadBytes(chunk, Chunk.kChunkSize);

                chunk->Archetype = archetypes[(int)chunk->Archetype].Archetype;
                // Fixup the pointer to the shared component values
                // todo: more generic way of fixing up pointers?
                chunk->SharedComponentValueArray = (int *)((byte *)(chunk) + Chunk.GetSharedComponentOffset(chunk->Archetype->NumSharedComponents));
                chunk->ChangeVersion             = (uint *)((byte *)chunk +
                                                            Chunk.GetChangedComponentOffset(chunk->Archetype->TypesCount,
                                                                                            chunk->Archetype->NumSharedComponents));

                // Allocate additional heap memory for buffers that have overflown into the heap, and read their data.
                int bufferAllocationCount = reader.ReadInt();
                if (bufferAllocationCount > 0)
                {
                    var bufferPatches = new NativeArray <BufferPatchRecord>(bufferAllocationCount, Allocator.Temp);
                    reader.ReadArray(bufferPatches, bufferPatches.Length);

                    // TODO: PERF: Batch malloc interface.
                    for (int pi = 0; pi < bufferAllocationCount; ++pi)
                    {
                        var target = (BufferHeader *)OffsetFromPointer(chunk->Buffer, bufferPatches[pi].ChunkOffset);

                        // TODO: Alignment
                        target->Pointer = (byte *)UnsafeUtility.Malloc(bufferPatches[pi].AllocSizeBytes, 8, Allocator.Persistent);

                        reader.ReadBytes(target->Pointer, bufferPatches[pi].AllocSizeBytes);
                    }

                    bufferPatches.Dispose();
                }

                manager.AddExistingChunk(chunk);
            }

            archetypes.Dispose();
        }
示例#4
0
    static void LoadWorld(EntityManager entityManager, object[] objectTable)
    {
        string filePath = Application.persistentDataPath + "/test.bin";

        using (var binaryReader = new StreamBinaryReader(filePath))
        {
            ExclusiveEntityTransaction transaction = entityManager.BeginExclusiveEntityTransaction();

            SerializeUtility.DeserializeWorld(transaction, binaryReader, objectTable);

            entityManager.EndExclusiveEntityTransaction();
        }
    }
示例#5
0
        protected override void OnUpdate()
        {
            Profiler.BeginSample("Scheduling Jobs");
            m_Transaction = EntityManager.BeginExclusiveEntityTransaction();

            var inputDeps = new JobHandle();

            ScheduleSplineToRoadJobs(inputDeps, out inputDeps);
            ScheduleLateralProfileCreationJobs(inputDeps, out inputDeps);
            ScheduleCornerCreationJobs(inputDeps, out inputDeps);
            ScheduleIntersectionGeometryJobs(inputDeps, out inputDeps);
            ScheduleRoadCropJobs(inputDeps, out inputDeps);
            ScheduleMeshCreationJobs(inputDeps, out inputDeps);
            ScheduleSharedContainerDisposal(inputDeps);
            Profiler.EndSample();

            EntityManager.ExclusiveEntityTransactionDependency = inputDeps;
            EntityManager.EndExclusiveEntityTransaction();
        }
示例#6
0
        IEnumerator CreateEntityFromAnotherWorld()
        {
            var entity = EntityMgrs[1].CreateEntity(type);

            ExclusiveEntityTransaction cmd = EntityMgrs[1].BeginExclusiveEntityTransaction();

            EntityMgrs[1].ExclusiveEntityTransactionDependency = new CreateDummyDataJob()
            {
                commands = cmd,
                prefab   = entity,
                count    = 999
            }.Schedule(EntityMgrs[1].ExclusiveEntityTransactionDependency);

            JobHandle.ScheduleBatchedJobs();

            yield return(new WaitUntil(() => EntityMgrs[1].ExclusiveEntityTransactionDependency.IsCompleted));

            EntityMgrs[1].EndExclusiveEntityTransaction();
            EntityMgrs[0].MoveEntitiesFrom(EntityMgrs[1]);

            co = null;
        }
        protected override void OnUpdate()
        {
            EntityManager.CompleteAllJobs();

            //We need to call this after EntityManager.CompleteAllJobs so that our uiEntityDataGroup is updated
            UpdateInjectedComponentGroups();

            //Copy our current UI data in a tmp array
            Entity uiEntity = uiEntityDataGroup.GetEntityArray()[0];
            UIData testData = GetComponentDataFromEntity <UIData>()[uiEntity];

            NativeArray <UIData> uiTmpDataArray = new NativeArray <UIData>(1, Allocator.TempJob);

            uiTmpDataArray[0] = testData;

            //Create a tmp list to contain the data needed to do some logic after entities destruction
            NativeList <InfoForLogicAfterDestroy> infoLogicTmpDataList = new NativeList <InfoForLogicAfterDestroy>(entityCollisionQueue.Count, Allocator.TempJob);

            //Tell the EntityManager that we will start doing entity work only via an ExclusiveEntityTransaction (that can be passed to a job)
            ExclusiveEntityTransaction exclusiveEntityTransaction = EntityManager.BeginExclusiveEntityTransaction();

            //Set up our job to destroy our entities and fill the infoLogicTmpDataList with the data we need to do some logic after the destruction
            DestroyEntityWithLogicJob destroyEntityWithLogicJob = new DestroyEntityWithLogicJob
            {
                entityTransaction = exclusiveEntityTransaction,
                uiDataArray       = uiTmpDataArray,
                entityQueue       = entityCollisionQueue,
                scoreValue        = MonoBehaviourECSBridge.Instance.destroyScoreValue,
                infoForLogic      = infoLogicTmpDataList,
            };

            JobHandle destroyHandle = destroyEntityWithLogicJob.Schedule(EntityManager.ExclusiveEntityTransactionDependency);

            EntityManager.ExclusiveEntityTransactionDependency = JobHandle.CombineDependencies(destroyHandle, EntityManager.ExclusiveEntityTransactionDependency);

            //Send the job to the worker thread queue, we need to do this because we need the job to run now
            JobHandle.ScheduleBatchedJobs();

            //Wait for it to be completed
            destroyHandle.Complete();

            //Start a new job to destroy out of bound entities
            DestroyEntityJob destroyEntityJob = new DestroyEntityJob
            {
                entityTransaction = exclusiveEntityTransaction,
                entityQueue       = entityOutOfBoundQueue,
            };

            //Make sure we depend on the previous job (only one job at a time can use the ExclusiveEntityTransaction)
            destroyHandle = destroyEntityJob.Schedule(destroyHandle);
            EntityManager.ExclusiveEntityTransactionDependency = JobHandle.CombineDependencies(destroyHandle, EntityManager.ExclusiveEntityTransactionDependency);

            //Send the job to the worker thread queue, we need to do this because we need the job to run now
            JobHandle.ScheduleBatchedJobs();

            //While the job for the entity out of bound is running, do our logic for the entity destruction on the main thread
            //The list was generated from the first job
            DestroyLogic(infoLogicTmpDataList);

            //wait for the entity out of bound destroy job to finish
            destroyHandle.Complete();

            //Tell the entity manager that we are done with the ExclusiveEntityTransaction
            EntityManager.EndExclusiveEntityTransaction();

            //We need to call this after EndExclusiveEntityTransaction so that our uiEntityDataGroup is updated
            UpdateInjectedComponentGroups();

            //Copy back the UI data with the update score
            testData = uiTmpDataArray[0];
            EntityManager.SetComponentData(uiEntity, testData);



            //dispose of our tmp array/list
            uiTmpDataArray.Dispose();
            infoLogicTmpDataList.Dispose();
        }
示例#8
0
        public static unsafe void DeserializeWorld(ExclusiveEntityTransaction manager, BinaryReader reader, int numSharedComponents)
        {
            int num2;

            if (manager.ArchetypeManager.CountEntities() != 0)
            {
                throw new ArgumentException("DeserializeWorld can only be used on completely empty EntityManager. Please create a new empty World and use EntityManager.MoveEntitiesFrom to move the loaded entities into the destination world instead.");
            }
            int num = reader.ReadInt();

            if (num != CurrentFileFormatVersion)
            {
                throw new ArgumentException($"Attempting to read a entity scene stored in an old file format version (stored version : {num}, current version : {CurrentFileFormatVersion})");
            }
            NativeArray <int>             types  = ReadTypeArray(reader);
            NativeArray <EntityArchetype> array2 = ReadArchetypes(reader, types, manager, out num2);

            manager.AllocateConsecutiveEntitiesForLoading(num2);
            int num3 = reader.ReadInt();
            int num4 = 0;

            while (true)
            {
                if (num4 >= num3)
                {
                    array2.Dispose();
                    return;
                }
                Chunk *chunk = (Chunk *)UnsafeUtility.Malloc(0x3f00L, 0x40, Allocator.Persistent);
                reader.ReadBytes((void *)chunk, 0x3f00);
                chunk->Archetype = array2[(int)chunk->Archetype].Archetype;
                chunk->SharedComponentValueArray = (int *)(chunk + Chunk.GetSharedComponentOffset(chunk->Archetype.NumSharedComponents));
                int num5  = chunk->Archetype.NumSharedComponents;
                int index = 0;
                while (true)
                {
                    if (index >= num5)
                    {
                        chunk->ChangeVersion = (uint *)(chunk + Chunk.GetChangedComponentOffset(chunk->Archetype.TypesCount, chunk->Archetype.NumSharedComponents));
                        int length = reader.ReadInt();
                        if (length > 0)
                        {
                            NativeArray <BufferPatchRecord> elements = new NativeArray <BufferPatchRecord>(length, Allocator.Temp, NativeArrayOptions.ClearMemory);
                            reader.ReadArray <BufferPatchRecord>(elements, elements.Length);
                            int num8 = 0;
                            while (true)
                            {
                                if (num8 >= length)
                                {
                                    elements.Dispose();
                                    break;
                                }
                                BufferHeader *headerPtr = (BufferHeader *)ref OffsetFromPointer((void *)&chunk->Buffer.FixedElementField, elements[num8].ChunkOffset);
                                headerPtr->Pointer = (byte *)UnsafeUtility.Malloc((long)elements[num8].AllocSizeBytes, 8, Allocator.Persistent);
                                reader.ReadBytes((void *)headerPtr->Pointer, elements[num8].AllocSizeBytes);
                                num8++;
                            }
                        }
                        manager.AddExistingChunk(chunk);
                        num4++;
                        break;
                    }
                    if (chunk->SharedComponentValueArray[index] > numSharedComponents)
                    {
                        throw new ArgumentException($"Archetype uses shared component at index {chunk->SharedComponentValueArray[index]} but only {numSharedComponents} are available, check if the shared scene has been properly loaded.");
                    }
                    index++;
                }
            }
        }
示例#9
0
        private static unsafe NativeArray <EntityArchetype> ReadArchetypes(BinaryReader reader, NativeArray <int> types, ExclusiveEntityTransaction entityManager, out int totalEntityCount)
        {
            int length = reader.ReadInt();
            NativeArray <EntityArchetype> array  = new NativeArray <EntityArchetype>(length, Allocator.Temp, NativeArrayOptions.ClearMemory);
            NativeArray <int>             array2 = new NativeArray <int>(length, Allocator.Temp, NativeArrayOptions.ClearMemory);

            totalEntityCount = 0;
            NativeList <ComponentType> nativeList = new NativeList <ComponentType>(Allocator.Temp);
            int index = 0;

            while (true)
            {
                int num4;
                if (index >= length)
                {
                    nativeList.Dispose();
                    types.Dispose();
                    array2.Dispose();
                    return(array);
                }
                array2.set_Item(index, num4 = reader.ReadInt());
                totalEntityCount           += num4;
                int num3 = reader.ReadInt();
                nativeList.Clear();
                int num5 = 0;
                while (true)
                {
                    if (num5 >= num3)
                    {
                        array.set_Item(index, entityManager.CreateArchetype((ComponentType *)nativeList.GetUnsafePtr <ComponentType>(), nativeList.Length));
                        index++;
                        break;
                    }
                    int typeIndex = types[reader.ReadInt()];
                    nativeList.Add(ComponentType.FromTypeIndex(typeIndex));
                    num5++;
                }
            }
        }
示例#10
0
        public static unsafe void DeserializeWorld(ExclusiveEntityTransaction manager, BinaryReader reader, int numSharedComponents)
        {
            if (manager.ArchetypeManager.CountEntities() != 0)
            {
                throw new ArgumentException(
                          $"DeserializeWorld can only be used on completely empty EntityManager. Please create a new empty World and use EntityManager.MoveEntitiesFrom to move the loaded entities into the destination world instead.");
            }
            int storedVersion = reader.ReadInt();

            if (storedVersion != CurrentFileFormatVersion)
            {
                throw new ArgumentException(
                          $"Attempting to read a entity scene stored in an old file format version (stored version : {storedVersion}, current version : {CurrentFileFormatVersion})");
            }

            var types = ReadTypeArray(reader);
            int totalEntityCount;
            var typeCount  = new NativeArray <int>(types.Length, Allocator.Temp);
            var archetypes = ReadArchetypes(reader, types, manager, out totalEntityCount, typeCount);

            int sharedComponentArraysLength = reader.ReadInt();
            var sharedComponentArrays       = new NativeArray <int>(sharedComponentArraysLength, Allocator.Temp);

            reader.ReadArray(sharedComponentArrays, sharedComponentArraysLength);

            manager.AllocateConsecutiveEntitiesForLoading(totalEntityCount);

            int totalChunkCount             = reader.ReadInt();
            var chunksWithMetaChunkEntities = new NativeList <ArchetypeChunk>(totalChunkCount, Allocator.Temp);

            int   totalBlobAssetSize = reader.ReadInt();
            byte *allBlobAssetData   = null;

            NativeList <ArchetypeChunk> blobAssetRefChunks = new NativeList <ArchetypeChunk>();
            int blobAssetOwnerIndex = -1;

            if (totalBlobAssetSize != 0)
            {
                allBlobAssetData = (byte *)UnsafeUtility.Malloc(totalBlobAssetSize, 16, Allocator.Persistent);
                reader.ReadBytes(allBlobAssetData, totalBlobAssetSize);
                blobAssetOwnerIndex = manager.SharedComponentDataManager.InsertSharedComponent(new BlobAssetOwner(allBlobAssetData, totalBlobAssetSize));
                blobAssetRefChunks  = new NativeList <ArchetypeChunk>(32, Allocator.Temp);
                var end    = allBlobAssetData + totalBlobAssetSize;
                var header = (BlobAssetHeader *)allBlobAssetData;
                while (header < end)
                {
                    header->ValidationPtr = header + 1;
                    header = (BlobAssetHeader *)OffsetFromPointer(header + 1, header->Length);
                }
            }

            int sharedComponentArraysIndex = 0;

            for (int i = 0; i < totalChunkCount; ++i)
            {
                var chunk = (Chunk *)UnsafeUtility.Malloc(Chunk.kChunkSize, 64, Allocator.Persistent);
                reader.ReadBytes(chunk, Chunk.kChunkSize);

                var  archetype = chunk->Archetype = archetypes[(int)chunk->Archetype].Archetype;
                var  numSharedComponentsInArchetype = chunk->Archetype->NumSharedComponents;
                int *sharedComponentValueArray      = (int *)sharedComponentArrays.GetUnsafePtr() + sharedComponentArraysIndex;

                for (int j = 0; j < numSharedComponentsInArchetype; ++j)
                {
                    // The shared component 0 is not part of the array, so an index equal to the array size is valid.
                    if (sharedComponentValueArray[j] > numSharedComponents)
                    {
                        throw new ArgumentException(
                                  $"Archetype uses shared component at index {sharedComponentValueArray[j]} but only {numSharedComponents} are available, check if the shared scene has been properly loaded.");
                    }
                }

                var remapedSharedComponentValues = stackalloc int[archetype->NumSharedComponents];
                RemapSharedComponentIndices(remapedSharedComponentValues, archetype, sharedComponentValueArray);

                sharedComponentArraysIndex += numSharedComponentsInArchetype;

                // Allocate additional heap memory for buffers that have overflown into the heap, and read their data.
                int bufferAllocationCount = reader.ReadInt();
                if (bufferAllocationCount > 0)
                {
                    var bufferPatches = new NativeArray <BufferPatchRecord>(bufferAllocationCount, Allocator.Temp);
                    reader.ReadArray(bufferPatches, bufferPatches.Length);

                    // TODO: PERF: Batch malloc interface.
                    for (int pi = 0; pi < bufferAllocationCount; ++pi)
                    {
                        var target = (BufferHeader *)OffsetFromPointer(chunk->Buffer, bufferPatches[pi].ChunkOffset);

                        // TODO: Alignment
                        target->Pointer = (byte *)UnsafeUtility.Malloc(bufferPatches[pi].AllocSizeBytes, 8, Allocator.Persistent);

                        reader.ReadBytes(target->Pointer, bufferPatches[pi].AllocSizeBytes);
                    }

                    bufferPatches.Dispose();
                }

                if (totalBlobAssetSize != 0 && archetype->ContainsBlobAssetRefs)
                {
                    blobAssetRefChunks.Add(new ArchetypeChunk {
                        m_Chunk = chunk
                    });
                    PatchBlobAssetsInChunkAfterLoad(chunk, allBlobAssetData);
                }

                manager.AddExistingChunk(chunk, remapedSharedComponentValues);

                if (chunk->metaChunkEntity != Entity.Null)
                {
                    chunksWithMetaChunkEntities.Add(new ArchetypeChunk {
                        m_Chunk = chunk
                    });
                }
            }

            if (totalBlobAssetSize != 0)
            {
                manager.DataManager->AddSharedComponent(blobAssetRefChunks, ComponentType.ReadWrite <BlobAssetOwner>(), manager.ArchetypeManager, manager.EntityGroupManager, blobAssetOwnerIndex);
                manager.SharedComponentDataManager.AddReference(blobAssetOwnerIndex, blobAssetRefChunks.Length - 1);
                blobAssetRefChunks.Dispose();
            }

            for (int i = 0; i < chunksWithMetaChunkEntities.Length; ++i)
            {
                var chunk     = chunksWithMetaChunkEntities[i].m_Chunk;
                var archetype = chunk->Archetype;
                manager.SetComponentData(chunk->metaChunkEntity, new ChunkHeader {
                    chunk = chunk
                });
            }

            chunksWithMetaChunkEntities.Dispose();
            sharedComponentArrays.Dispose();
            archetypes.Dispose();
            types.Dispose();
            typeCount.Dispose();
        }
示例#11
0
        private static unsafe NativeArray <EntityArchetype> ReadArchetypes(BinaryReader reader, NativeArray <int> types, ExclusiveEntityTransaction entityManager,
                                                                           out int totalEntityCount, NativeArray <int> typeCount)
        {
            int archetypeCount = reader.ReadInt();
            var archetypes     = new NativeArray <EntityArchetype>(archetypeCount, Allocator.Temp);

            totalEntityCount = 0;
            var tempComponentTypes = new NativeList <ComponentType>(Allocator.Temp);

            for (int i = 0; i < archetypeCount; ++i)
            {
                var archetypeEntityCount = reader.ReadInt();
                totalEntityCount += archetypeEntityCount;
                int archetypeComponentTypeCount = reader.ReadInt();
                tempComponentTypes.Clear();
                for (int iType = 0; iType < archetypeComponentTypeCount; ++iType)
                {
                    int typeIndexInFile             = reader.ReadInt();
                    int typeIndexInFileWithoutFlags = typeIndexInFile & TypeManager.ClearFlagsMask;
                    int typeIndex = types[typeIndexInFileWithoutFlags];
                    if (TypeManager.IsChunkComponent(typeIndexInFile))
                    {
                        typeIndex = TypeManager.MakeChunkComponentTypeIndex(typeIndex);
                    }

                    typeCount[typeIndexInFileWithoutFlags] += archetypeEntityCount;
                    tempComponentTypes.Add(ComponentType.FromTypeIndex(typeIndex));
                }

                archetypes[i] = entityManager.CreateArchetype((ComponentType *)tempComponentTypes.GetUnsafePtr(),
                                                              tempComponentTypes.Length);
            }

            tempComponentTypes.Dispose();
            return(archetypes);
        }
示例#12
0
        public static unsafe void DeserializeWorld(ExclusiveEntityTransaction manager, BinaryReader reader, int[] sharedComponents)
        {
            if (manager.ArchetypeManager.CountEntities() != 0)
            {
                throw new ArgumentException(
                          $"DeserializeWorld can only be used on completely empty EntityManager. Please create a new empty World and use EntityManager.MoveEntitiesFrom to move the loaded entities into the destination world instead.");
            }
            int storedVersion = reader.ReadInt();

            if (storedVersion != CurrentFileFormatVersion)
            {
                throw new ArgumentException(
                          $"Attempting to read a entity scene stored in an old file format version (stored version : {storedVersion}, current version : {CurrentFileFormatVersion})");
            }

            var types = ReadTypeArray(reader);
            int totalEntityCount;
            var archetypes = ReadArchetypes(reader, types, manager, out totalEntityCount);

            manager.AllocateConsecutiveEntitiesForLoading(totalEntityCount);

            int totalChunkCount = reader.ReadInt();

            for (int i = 0; i < totalChunkCount; ++i)
            {
                var chunk = (Chunk *)UnsafeUtility.Malloc(Chunk.kChunkSize, 64, Allocator.Persistent);
                reader.ReadBytes(chunk, Chunk.kChunkSize);

                chunk->Archetype = archetypes[(int)chunk->Archetype].Archetype;
                // Fixup the pointer to the shared component values
                // todo: more generic way of fixing up pointers?
                chunk->SharedComponentValueArray = (int *)((byte *)(chunk) + Chunk.GetSharedComponentOffset(chunk->Archetype->NumSharedComponents));

                var numSharedComponentsInArchetype = chunk->Archetype->NumSharedComponents;
                for (int j = 0; j < numSharedComponentsInArchetype; ++j)
                {
                    // The shared component 0 is not part of the array, so an index equal to the array size is valid.
                    if (chunk->SharedComponentValueArray[j] > sharedComponents.Length)
                    {
                        throw new ArgumentException(
                                  $"Archetype uses shared component at index {chunk->SharedComponentValueArray[j]} but only {sharedComponents.Length} are available, check if the shared scene has been properly loaded.");
                    }
                }

                chunk->ChangeVersion = (uint *)((byte *)chunk +
                                                Chunk.GetChangedComponentOffset(chunk->Archetype->TypesCount,
                                                                                chunk->Archetype->NumSharedComponents));

                // Allocate additional heap memory for buffers that have overflown into the heap, and read their data.
                int bufferAllocationCount = reader.ReadInt();
                if (bufferAllocationCount > 0)
                {
                    var bufferPatches = new NativeArray <BufferPatchRecord>(bufferAllocationCount, Allocator.Temp);
                    reader.ReadArray(bufferPatches, bufferPatches.Length);

                    // TODO: PERF: Batch malloc interface.
                    for (int pi = 0; pi < bufferAllocationCount; ++pi)
                    {
                        var target = (BufferHeader *)OffsetFromPointer(chunk->Buffer, bufferPatches[pi].ChunkOffset);

                        // TODO: Alignment
                        target->Pointer = (byte *)UnsafeUtility.Malloc(bufferPatches[pi].AllocSizeBytes, 8, Allocator.Persistent);

                        reader.ReadBytes(target->Pointer, bufferPatches[pi].AllocSizeBytes);
                    }

                    bufferPatches.Dispose();
                }

                manager.AddExistingChunk(chunk, sharedComponents);
            }

            archetypes.Dispose();
        }
示例#13
0
        private static unsafe NativeArray <EntityArchetype> ReadArchetypes(BinaryReader reader, NativeArray <int> types, ExclusiveEntityTransaction entityManager,
                                                                           out int totalEntityCount)
        {
            int archetypeCount        = reader.ReadInt();
            var archetypes            = new NativeArray <EntityArchetype>(archetypeCount, Allocator.Temp);
            var archetypeEntityCounts = new NativeArray <int>(archetypeCount, Allocator.Temp);

            totalEntityCount = 0;
            var tempComponentTypes = new NativeList <ComponentType>(Allocator.Temp);

            for (int i = 0; i < archetypeCount; ++i)
            {
                totalEntityCount += archetypeEntityCounts[i] = reader.ReadInt();
                int archetypeComponentTypeCount = reader.ReadInt();
                tempComponentTypes.Clear();
                for (int iType = 0; iType < archetypeComponentTypeCount; ++iType)
                {
                    int typeIndex = types[reader.ReadInt()];

                    tempComponentTypes.Add(ComponentType.FromTypeIndex(typeIndex));
                }

                archetypes[i] = entityManager.CreateArchetype((ComponentType *)tempComponentTypes.GetUnsafePtr(),
                                                              tempComponentTypes.Length);
            }

            tempComponentTypes.Dispose();
            types.Dispose();
            archetypeEntityCounts.Dispose();
            return(archetypes);
        }
示例#14
0
 protected override void OnUpdate()
 {
     ExclusiveSimWorld = _worldMaster.SimulationWorld.EntityManager.BeginExclusiveEntityTransaction();
 }
示例#15
0
 public SimWorldAccessorJob(ExclusiveEntityTransaction exclusiveEntityTransaction)
 {
     _exclusiveTransaction = exclusiveEntityTransaction;
 }