static void ConstructChunk(Archetype *archetype, Chunk *chunk,
                                   SharedComponentValues sharedComponentValues,
                                   EntityComponentStore *entityComponentStore,
                                   ManagedComponentStore managedComponentStore,
                                   EntityGroupManager entityGroupManager)
        {
            chunk->Archetype       = archetype;
            chunk->Count           = 0;
            chunk->Capacity        = archetype->ChunkCapacity;
            chunk->SequenceNumber  = entityComponentStore->AssignSequenceNumber(chunk);
            chunk->metaChunkEntity = Entity.Null;

            var numSharedComponents = archetype->NumSharedComponents;

            if (numSharedComponents > 0)
            {
                for (var i = 0; i < archetype->NumSharedComponents; ++i)
                {
                    var sharedComponentIndex = sharedComponentValues[i];
                    managedComponentStore.AddReference(sharedComponentIndex);
                }
            }

            archetype->AddToChunkList(chunk, sharedComponentValues, entityComponentStore->GlobalSystemVersion);

            Assert.IsTrue(archetype->Chunks.Count != 0);

            // Chunk can't be locked at at construction time
            archetype->EmptySlotTrackingAddChunk(chunk);

            if (numSharedComponents == 0)
            {
                Assert.IsTrue(archetype->ChunksWithEmptySlots.Count != 0);
            }
            else
            {
                Assert.IsTrue(archetype->FreeChunksBySharedComponents.TryGet(chunk->SharedComponentValues,
                                                                             archetype->NumSharedComponents) != null);
            }

            if (archetype->NumManagedArrays > 0)
            {
                chunk->ManagedArrayIndex =
                    managedComponentStore.AllocateManagedArrayStorage(archetype->NumManagedArrays * chunk->Capacity);
            }
            else
            {
                chunk->ManagedArrayIndex = -1;
            }

            chunk->Flags = 0;

            if (archetype->MetaChunkArchetype != null)
            {
                CreateMetaEntityForChunk(chunk, entityComponentStore, managedComponentStore, entityGroupManager);
            }
        }
예제 #2
0
        // ----------------------------------------------------------------------------------------------------------
        // PUBLIC
        // ----------------------------------------------------------------------------------------------------------

        public static void AddExistingChunk(Chunk *chunk, int *sharedComponentIndices,
                                            EntityComponentStore *entityComponentStore,
                                            ManagedComponentStore managedComponentStore)
        {
            var archetype = chunk->Archetype;

            archetype->AddToChunkList(chunk, sharedComponentIndices, entityComponentStore->GlobalSystemVersion);
            archetype->EntityCount += chunk->Count;

            for (var i = 0; i < archetype->NumSharedComponents; ++i)
            {
                managedComponentStore.AddReference(sharedComponentIndices[i]);
            }

            if (chunk->Count < chunk->Capacity)
            {
                archetype->EmptySlotTrackingAddChunk(chunk);
            }

            entityComponentStore->AddExistingEntitiesInChunk(chunk);
        }