示例#1
0
 public SimpleChunkIterator(ref ArchetypeView buffer)
 {
     _source = buffer;
     _index  = -1;
 }
示例#2
0
        public EventBatch(EntityManager em, EventDefinition definition, Allocator allocator = Allocator.Persistent) : this()
        {
            var componentType  = ComponentType.FromTypeIndex(definition.ComponentTypeInfo.TypeIndex);
            var bufferType     = ComponentType.FromTypeIndex(definition.BufferTypeInfo.TypeIndex);
            var bufferLinkType = ComponentType.ReadWrite <BufferLink>();

            HasBuffer    = definition.BufferTypeInfo.TypeIndex != 0;
            HasComponent = definition.ComponentTypeInfo.TypeIndex != 0;

            var components = new List <ComponentType>()
            {
                definition.MetaType,
            };

            if (HasComponent)
            {
                components.AddRange(new[] {
                    componentType,
                });
            }

            if (HasBuffer)
            {
                components.AddRange(new[] {
                    bufferType,
                    bufferLinkType,
                });
            }

            Archetype = em.CreateArchetype(components.ToArray());

            var inactiveComponents = new List <ComponentType>(components)
            {
                ComponentType.ReadWrite <Disabled>()
            };

            InactiveArchetype = em.CreateArchetype(inactiveComponents.ToArray());


            Allocator          = allocator;
            ComponentType      = componentType;
            ComponentTypeIndex = definition.ComponentTypeInfo.TypeIndex;
            ComponentTypeSize  = definition.ComponentTypeInfo.SizeInChunk;

            BufferType             = bufferType;
            BufferTypeIndex        = definition.BufferTypeInfo.TypeIndex;
            BufferElementSize      = definition.BufferTypeInfo.ElementSize;
            BufferSizeInChunk      = definition.BufferTypeInfo.SizeInChunk;
            BufferAlignmentInBytes = definition.BufferTypeInfo.AlignmentInBytes;
            BufferLinkTypeIndex    = TypeManager.GetTypeIndex <BufferLink>();

            StartingPoolSize = definition.StartingPoolSize;

            ComponentQueue = new EventQueue(ComponentTypeIndex, ComponentTypeSize, BufferTypeIndex, BufferElementSize, allocator);
            Offsets        = GetChunkOffsets(em, Archetype, definition.MetaType, componentType, bufferType, bufferLinkType);

            ActiveChunks   = new ArchetypeView(Archetype);
            InactiveChunks = new ArchetypeView(InactiveArchetype);

            ActiveArchetypeChunks         = new UnsafeList(Allocator.Persistent);
            ActiveFullArchetypeChunks     = new UnsafeList(Allocator.Persistent);
            ActivePartialArchetypeChunk   = new UnsafeList(Allocator.Persistent);
            InactiveFullArchetypeChunks   = new UnsafeList(Allocator.Persistent);
            InactivePartialArchetypeChunk = new UnsafeList(Allocator.Persistent);

            if (definition.StartingPoolSize > 0)
            {
                CreateInactiveEntities(em, definition.StartingPoolSize);
                UpdateChunkCollections();
            }
        }