Esempio n. 1
0
        public NativeArray <ArchetypeChunk> CreateArchetypeChunkArray(NativeList <EntityArchetype> archetypes,
                                                                      Allocator allocator)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            var safetyHandle = AtomicSafetyHandle.Create();
            return(ArchetypeChunkArray.Create(archetypes, allocator, safetyHandle));
#else
            return(ArchetypeChunkArray.Create(archetypes, allocator));
#endif
        }
Esempio n. 2
0
        public NativeArray <Entity> GetAllEntities(Allocator allocator = 2)
        {
            this.BeforeStructuralChange();
            EntityArchetypeQuery query1 = new EntityArchetypeQuery();

            query1.Any  = Array.Empty <ComponentType>();
            query1.None = Array.Empty <ComponentType>();
            query1.All  = Array.Empty <ComponentType>();
            EntityArchetypeQuery query  = query1;
            EntityArchetypeQuery query4 = new EntityArchetypeQuery {
                Any  = Array.Empty <ComponentType>(),
                None = Array.Empty <ComponentType>()
            };

            query4.All = new ComponentType[] { typeof(Disabled) };
            EntityArchetypeQuery query2 = query4;

            query4 = new EntityArchetypeQuery {
                Any  = Array.Empty <ComponentType>(),
                None = Array.Empty <ComponentType>()
            };
            query4.All = new ComponentType[] { typeof(Prefab) };
            EntityArchetypeQuery         query3          = query4;
            NativeList <EntityArchetype> foundArchetypes = new NativeList <EntityArchetype>(Allocator.TempJob);

            this.AddMatchingArchetypes(query, foundArchetypes);
            this.AddMatchingArchetypes(query2, foundArchetypes);
            this.AddMatchingArchetypes(query3, foundArchetypes);
            NativeArray <ArchetypeChunk> chunks    = this.CreateArchetypeChunkArray(foundArchetypes, Allocator.TempJob);
            NativeArray <Entity>         thisArray = new NativeArray <Entity>(ArchetypeChunkArray.CalculateEntityCount(chunks), allocator, NativeArrayOptions.ClearMemory);
            ArchetypeChunkEntityType     archetypeChunkEntityType = this.GetArchetypeChunkEntityType();
            int start = 0;
            int num3  = 0;

            while (true)
            {
                if (num3 >= chunks.Length)
                {
                    chunks.Dispose();
                    foundArchetypes.Dispose();
                    return(thisArray);
                }
                NativeArray <Entity> nativeArray = chunks[num3].GetNativeArray(archetypeChunkEntityType);
                thisArray.Slice <Entity>(start, nativeArray.Length).CopyFrom(nativeArray);
                start += nativeArray.Length;
                num3++;
            }
        }
Esempio n. 3
0
        public NativeArray <Entity> GetAllEntities(Allocator allocator = Allocator.Temp)
        {
            BeforeStructuralChange();

            var enabledQuery = new EntityArchetypeQuery
            {
                Any  = Array.Empty <ComponentType>(),
                None = Array.Empty <ComponentType>(),
                All  = Array.Empty <ComponentType>(),
            };
            var disabledQuery = new EntityArchetypeQuery
            {
                Any  = Array.Empty <ComponentType>(),
                None = Array.Empty <ComponentType>(),
                All  = new ComponentType[] { typeof(Disabled) }
            };
            var prefabQuery = new EntityArchetypeQuery
            {
                Any  = Array.Empty <ComponentType>(),
                None = Array.Empty <ComponentType>(),
                All  = new ComponentType[] { typeof(Prefab) }
            };
            var archetypes = new NativeList <EntityArchetype>(Allocator.TempJob);

            AddMatchingArchetypes(enabledQuery, archetypes);
            AddMatchingArchetypes(disabledQuery, archetypes);
            AddMatchingArchetypes(prefabQuery, archetypes);

            var chunks     = CreateArchetypeChunkArray(archetypes, Allocator.TempJob);
            var count      = ArchetypeChunkArray.CalculateEntityCount(chunks);
            var array      = new NativeArray <Entity>(count, allocator);
            var entityType = GetArchetypeChunkEntityType();
            var offset     = 0;

            for (int i = 0; i < chunks.Length; i++)
            {
                var chunk    = chunks[i];
                var entities = chunk.GetNativeArray(entityType);
                array.Slice(offset, entities.Length).CopyFrom(entities);
                offset += entities.Length;
            }

            chunks.Dispose();
            archetypes.Dispose();

            return(array);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets all the entities managed by this EntityManager.
        /// </summary>
        /// <remarks>
        /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
        /// currently running Jobs to complete before getting the entities and no additional Jobs can start before
        /// the function is finished. A sync point can cause a drop in performance because the ECS framework may not
        /// be able to make use of the processing power of all available cores.
        /// </remarks>
        /// <param name="allocator">The type of allocation for creating the NativeArray to hold the Entity objects.</param>
        /// <returns>An array of Entity objects referring to all the entities in the World.</returns>
        public NativeArray <Entity> GetAllEntities(Allocator allocator = Allocator.Temp)
        {
            BeforeStructuralChange();

            var chunks     = GetAllChunks();
            var count      = ArchetypeChunkArray.CalculateEntityCount(chunks);
            var array      = new NativeArray <Entity>(count, allocator);
            var entityType = GetArchetypeChunkEntityType();
            var offset     = 0;

            for (int i = 0; i < chunks.Length; i++)
            {
                var chunk    = chunks[i];
                var entities = chunk.GetNativeArray(entityType);
                array.Slice(offset, entities.Length).CopyFrom(entities);
                offset += entities.Length;
            }

            chunks.Dispose();
            return(array);
        }
Esempio n. 5
0
        public NativeArray <ArchetypeChunk> CreateArchetypeChunkArray(NativeList <EntityArchetype> archetypes, Allocator allocator)
        {
            AtomicSafetyHandle safetyHandle = AtomicSafetyHandle.Create();

            return(ArchetypeChunkArray.Create(archetypes, allocator, safetyHandle));
        }