Esempio n. 1
0
        internal void GetEntityArray(ref ComponentChunkIterator iterator, int length, out EntityArray output)
        {
            iterator.IndexInComponentGroup = 0;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            output = new EntityArray(iterator, length, m_SafetyManager.GetSafetyHandle(TypeManager.GetTypeIndex <Entity>(), true));
#else
            output = new EntityArray(iterator, length);
#endif
        }
Esempio n. 2
0
        /// <summary>
        ///     Creates an EntityArray that gives you access to the entities in this ComponentGroup.
        /// </summary>
        /// <returns>EntityArray of all the entities in this ComponentGroup.</returns>
        public EntityArray GetEntityArray()
        {
            int length = CalculateLength();
            ComponentChunkIterator iterator = GetComponentChunkIterator();

            EntityArray output;

            iterator.IndexInComponentGroup = 0;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            output = new EntityArray(iterator, length, m_SafetyManager.GetSafetyHandle(TypeManager.GetTypeIndex <Entity>(), true));
#else
            output = new EntityArray(iterator, length);
#endif
            return(output);
        }
Esempio n. 3
0
        public unsafe void DestroyEntity(ComponentGroup componentGroupFilter)
        {
            this.BeforeStructuralChange();
            EntityArray entityArray = componentGroupFilter.GetEntityArray();

            if (entityArray.Length != 0)
            {
                NativeArray <Entity> dst = new NativeArray <Entity>(entityArray.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
                entityArray.CopyTo(dst, 0);
                if (dst.Length != 0)
                {
                    this.Entities.TryRemoveEntityId((Entity *)dst.GetUnsafeReadOnlyPtr <Entity>(), dst.Length, this.ArchetypeManager, this.m_SharedComponentManager, this.m_GroupManager, this.m_CachedComponentTypeInArchetypeArray);
                }
                dst.Dispose();
            }
        }
        public unsafe void UpdateInjection(byte *systemPtr)
        {
            var groupStructPtr = systemPtr + m_GroupFieldOffset;

            int length = m_EntityGroup.CalculateLength();
            ComponentChunkIterator iterator = m_EntityGroup.GetComponentChunkIterator();

            for (var i = 0; i != m_ComponentDataInjections.Length; i++)
            {
                ComponentDataArray <ProxyComponentData> data;
                m_EntityGroup.GetComponentDataArray(ref iterator, m_ComponentDataInjections[i].IndexInComponentGroup,
                                                    length, out data);
                UnsafeUtility.CopyStructureToPtr(ref data, groupStructPtr + m_ComponentDataInjections[i].FieldOffset);
            }

            for (var i = 0; i != m_SharedComponentInjections.Length; i++)
            {
                SharedComponentDataArray <ProxySharedComponentData> data;
                m_EntityGroup.GetSharedComponentDataArray(ref iterator,
                                                          m_SharedComponentInjections[i].IndexInComponentGroup, length, out data);
                UnsafeUtility.CopyStructureToPtr(ref data, groupStructPtr + m_SharedComponentInjections[i].FieldOffset);
            }

            for (var i = 0; i != m_BufferArrayInjections.Length; i++)
            {
                BufferArray <ProxyBufferElementData> data;
                m_EntityGroup.GetBufferArray(ref iterator, m_BufferArrayInjections[i].IndexInComponentGroup, length,
                                             out data);
                UnsafeUtility.CopyStructureToPtr(ref data, groupStructPtr + m_BufferArrayInjections[i].FieldOffset);
            }

            if (m_EntityArrayOffset != -1)
            {
                EntityArray entityArray = m_EntityGroup.GetEntityArray();
                UnsafeUtility.CopyStructureToPtr(ref entityArray, groupStructPtr + m_EntityArrayOffset);
            }

            if (m_InjectionContext.HasEntries)
            {
                m_InjectionContext.UpdateEntries(m_EntityGroup, ref iterator, length, groupStructPtr);
            }

            if (m_LengthOffset != -1)
            {
                UnsafeUtility.CopyStructureToPtr(ref length, groupStructPtr + m_LengthOffset);
            }
        }
Esempio n. 5
0
        /// <summary>
        ///     Creates an EntityArray that gives you access to the entities in this ComponentGroup.
        /// </summary>
        /// <returns>EntityArray of all the entities in this ComponentGroup.</returns>
        public EntityArray GetEntityArray()
        {
            int length = CalculateLength();
            ComponentChunkIterator iterator = GetComponentChunkIterator();

            EntityArray output;

            iterator.IndexInComponentGroup = 0;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (m_GroupData->RequiredComponentsCount == 0)
            {
                throw new InvalidOperationException($"GetEntityArray() is currently not supported from a ComponentGroup created with EntityArchetypeQuery.");
            }

            output = new EntityArray(iterator, length, m_SafetyManager.GetSafetyHandle(TypeManager.GetTypeIndex <Entity>(), true));
#else
            output = new EntityArray(iterator, length);
#endif
            return(output);
        }