예제 #1
0
        public static void CopyComponentData(Chunk *source, Chunk *destination, int sourceIndex, int destinationIndex)
        {
            // TODO: I've no clue what this is about...

            var types = source->archetype->componentTypes;
            var count = source->archetype->componentCount;
            var sizes = source->archetype->componentSizes;

            var sourceOffsets = source->archetype->componentOffsets;
            var destOffsets   = destination->archetype->componentOffsets;

            for (int i = 0; i < count; ++i)
            {
                int indexInChunk = ArchetypeUtility.GetTypeIndex(destination->archetype, types[i]);

                if (indexInChunk == -1)
                {
                    continue;
                }

                var offsetInSourceBuffer = source->buffer + sourceOffsets[i] + (sourceIndex * sizes[i]);
                var offsetInDestBuffer   = destination->buffer + destOffsets[indexInChunk] + (destinationIndex * sizes[i]);

                Buffer.MemoryCopy(offsetInDestBuffer, offsetInSourceBuffer, (uint)sizes[indexInChunk], (uint)sizes[indexInChunk]);
                // Unsafe.CopyBlock((void*)offsetInDestBuffer, (void*)offsetInSourceBuffer, (uint)sizes[indexInChunk]);
            }
        }
예제 #2
0
        public static int CopyComponentData <T>(Chunk *chunk, int typeIndex, T *buffer, int count) where T : unmanaged
        {
            count = (count <= chunk->count) ? count : chunk->count;

            var indexInArchetype = ArchetypeUtility.GetTypeIndex(chunk->archetype, typeIndex);             // Make sure that the type is in the archetype beforehand...
            var size             = count * sizeof(T);

            Buffer.MemoryCopy(ChunkUtility.GetComponentPtrInBuffer <T>(chunk, indexInArchetype), buffer, size, size);

            return(count);
        }
예제 #3
0
        public static T *GetComponentDataPtr <T>(Chunk *chunk, int index, int typeIndex) where T : unmanaged
        {
            var indexInArchetype = ArchetypeUtility.GetTypeIndex(chunk->archetype, typeIndex);

            if (indexInArchetype < 0)
            {
                return(null);
            }

            return(&GetComponentPtrInBuffer <T>(chunk, indexInArchetype)[index]);
        }
예제 #4
0
        public static Span <T> GetComponentData <T>(Chunk *chunk, int typeIndex) where T : unmanaged
        {
            var indexInArchetype = ArchetypeUtility.GetTypeIndex(chunk->archetype, typeIndex);

            if (indexInArchetype < 0)
            {
                return(Span <T> .Empty);
            }

            return(new Span <T>(GetComponentPtrInBuffer <T>(chunk, indexInArchetype), chunk->count));
        }
예제 #5
0
        public bool HasComponentData <T>(Entity entity) where T : unmanaged, IComponentData
        {
            if (!IsAlive(entity))
            {
                return(false);
            }

            int typeIndex = TypeRegistry <T> .typeIndex;

            return(ArchetypeUtility.GetTypeIndex(GetArchetypeInternal(entity), typeIndex) >= 0);
        }
예제 #6
0
        public static bool TryGetComponentData <T>(Chunk *chunk, int index, int typeIndex, out T value) where T : unmanaged
        {
            var indexInArchetype = ArchetypeUtility.GetTypeIndex(chunk->archetype, typeIndex);

            if (indexInArchetype < 0)
            {
                value = default;
                return(false);
            }

            value = GetComponentPtrInBuffer <T>(chunk, indexInArchetype)[index];
            return(true);
        }
예제 #7
0
        public static bool SetComponentData <T>(Chunk *chunk, int index, int typeIndex, T value) where T : unmanaged
        {
            var indexInArchetype = ArchetypeUtility.GetTypeIndex(chunk->archetype, typeIndex);

            if (indexInArchetype < 0)
            {
                return(false);
            }

            T *data = GetComponentPtrInBuffer <T>(chunk, indexInArchetype);

            data[index] = value;

            return(true);
        }
예제 #8
0
        internal EntityArchetype RemoveTypeFromArchetype <T>(Archetype *archetype) where T : unmanaged
        {
            // TODO: Needs a check if the archetypes contains typeof(T).

            int srcCount = archetype->componentCount;

            if (srcCount <= 1)
            {
                return(CreateArchetype());
            }

            int        destCount     = srcCount - 1;
            Span <int> componentData = destCount > 16
                                ? new int[destCount * 2]
                                : stackalloc int[destCount * 2];

            var destTypes = componentData.Slice(0, destCount);
            var destSizes = componentData.Slice(destCount);

            var sourceTypes = new Span <int>(archetype->componentTypes, srcCount);
            var sourceSizes = new Span <int>(archetype->componentSizes, srcCount);

            int indexInArchetype = ArchetypeUtility.GetTypeIndex(archetype, TypeRegistry <T> .typeIndex);

            // Is it somehow possible to remove the branches here?

            if (indexInArchetype > 0)
            {
                sourceTypes.Slice(0, indexInArchetype).CopyTo(destTypes);
                sourceSizes.Slice(0, indexInArchetype).CopyTo(destSizes);
            }

            if (indexInArchetype < destCount)
            {
                sourceTypes.Slice(indexInArchetype + 1).CopyTo(destTypes.Slice(indexInArchetype));
                sourceSizes.Slice(indexInArchetype + 1).CopyTo(destSizes.Slice(indexInArchetype));
            }

            int blockSize = 0;

            for (int i = 0; i < destSizes.Length; ++i)            // TODO: Use CalculateBlockSize instead.
            {
                blockSize += destSizes[i];
            }

            return(CreateArchetypeInternal(destTypes, destSizes, blockSize));
        }
예제 #9
0
파일: EntityBatch.cs 프로젝트: dn9090/Checs
        public bool HasComponentData <T>() where T : unmanaged
        {
            int typeIndex = TypeRegistry <T> .typeIndex;

            return(ArchetypeUtility.GetTypeIndex(this.chunk->archetype, typeIndex) != -1);
        }