Example #1
0
        public void ACS_Buffers()
        {
            CreateEntities(128);

            var query = new EntityArchetypeQuery
            {
                Any  = new ComponentType[] {},                        // any
                None = Array.Empty <ComponentType>(),                 // none
                All  = new ComponentType[] { typeof(EcsIntElement) }, // all
            };
            var chunks = m_Manager.CreateArchetypeChunkArray(query, Allocator.TempJob);

            var intElements = m_Manager.GetArchetypeChunkBufferType <EcsIntElement>(false);

            for (int i = 0; i < chunks.Length; ++i)
            {
                var chunk    = chunks[i];
                var accessor = chunk.GetBufferAccessor(intElements);

                for (int k = 0; k < accessor.Length; ++k)
                {
                    var buffer = accessor[i];

                    for (int n = 0; n < buffer.Length; ++n)
                    {
                        if (buffer[n] != n)
                        {
                            Assert.Fail("buffer element does not have the expected value");
                        }
                    }
                }
            }

            chunks.Dispose();
        }
    protected override void OnCreateManager()
    {
        m_DataStream = new DataStreamWriter(2048, Allocator.Persistent);
        ghostGroup   = GetComponentGroup(typeof(GhostComponent), typeof(GhostSystemStateComponent));
        var filterSpawn = new EntityArchetypeQuery
        {
            All  = new ComponentType[] { typeof(GhostComponent) },
            None = new ComponentType[] { typeof(GhostSystemStateComponent) }
        };
        var filterDespawn = new EntityArchetypeQuery
        {
            All  = new ComponentType[] { typeof(GhostSystemStateComponent) },
            None = new ComponentType[] { typeof(GhostComponent) }
        };

        ghostSpawnGroup   = GetComponentGroup(filterSpawn);
        ghostDespawnGroup = GetComponentGroup(filterDespawn);

        m_FreeGhostIds         = new NativeQueue <int>(Allocator.Persistent);
        m_AllocatedGhostIds    = new NativeArray <int>(1, Allocator.Persistent);
        m_AllocatedGhostIds[0] = 1; // To make sure 0 is invalid

        connectionGroup = GetComponentGroup(
            ComponentType.ReadWrite <NetworkStreamConnection>(),
            ComponentType.ReadOnly <PlayerStateComponentData>());

        m_ServerSimulation = World.GetExistingManager <ServerSimulationSystemGroup>();
        m_Barrier          = World.GetOrCreateManager <BeginSimulationEntityCommandBufferSystem>();

        m_ConnectionStates      = new List <ConnectionStateData>(256);
        m_ConnectionStateLookup = new NativeHashMap <Entity, int>(256, Allocator.Persistent);
        m_CompressionModel      = new NetworkCompressionModel(Allocator.Persistent);

        m_SerialSpawnChunks = new NativeList <PrioChunk>(1024, Allocator.Persistent);
    }
Example #3
0
        protected override void OnCreateManager()
        {
            var query = new EntityArchetypeQuery
            {
                All = new ComponentType[] {
                    ComponentType.Create <LineSegment>(),
                    ComponentType.Create <LineStyle>(),
                },
                Any  = new ComponentType[] {
                },
                None = new ComponentType[] {
                    ComponentType.Create <RegisteredState>(),
                },
            };
            var query2 = new EntityArchetypeQuery
            {
                All = new ComponentType[] {
                    ComponentType.Create <RegisteredState>(),
                },
                Any  = new ComponentType[] {
                },
                None = new ComponentType[] {
                    ComponentType.Create <LineSegment>(),
                    ComponentType.Create <LineStyle>(),
                },
            };

            cg            = GetComponentGroup(query, query2);
            newRegisterCg = GetComponentGroup(ComponentType.Create <NewRegister>());
            unregisterCg  = GetComponentGroup(ComponentType.Create <Unregister>());
            CreateMesh();
        }
Example #4
0
        public void EntityArrayListAdapter_SequentialAccessConsistent()
        {
            var archetype = m_Manager.CreateArchetype(new ComponentType[] { typeof(EcsTestData), typeof(EcsTestData2), typeof(EcsTestData3),
                                                                            typeof(EcsTestData4) });

            using (var entities = new NativeArray <Entity>(100000, Allocator.Temp))
            {
                m_Manager.CreateEntity(archetype, entities);
            }

            var query = new EntityArchetypeQuery()
            {
                Any  = new ComponentType[0],
                All  = new ComponentType[0],
                None = new ComponentType[0]
            };

            using (var chunkArray = m_Manager.CreateArchetypeChunkArray(query, Allocator.TempJob))
            {
                var adapter = new EntityArrayListAdapter();
                adapter.SetSource(chunkArray, m_Manager, null);
                var e1      = adapter[50001].id;
                var e2      = adapter[50002].id;
                var e3      = adapter[50003].id;
                var e2Again = adapter[50002].id;
                var e1Again = adapter[50001].id;
                Assert.AreNotEqual(e1, e2);
                Assert.AreNotEqual(e1, e2Again);
                Assert.AreNotEqual(e2, e1Again);
                Assert.AreEqual(e1, e1Again);
                Assert.AreEqual(e2, e2Again);
            }
        }
Example #5
0
        public void ACS_BufferHas()
        {
            CreateEntities(128);

            var query = new EntityArchetypeQuery
            {
                Any  = new ComponentType[] {},                        // any
                None = Array.Empty <ComponentType>(),                 // none
                All  = new ComponentType[] { typeof(EcsIntElement) }, // all
            };
            var chunks = m_Manager.CreateArchetypeChunkArray(query, Allocator.TempJob);

            var intElements     = m_Manager.GetArchetypeChunkBufferType <EcsIntElement>(false);
            var missingElements = m_Manager.GetArchetypeChunkBufferType <EcsComplexEntityRefElement>(false);

            for (int i = 0; i < chunks.Length; ++i)
            {
                var chunk = chunks[i];

                // Test Has<T>()
                bool hasIntElements = chunk.Has(intElements);
                Assert.IsTrue(hasIntElements, "Has(EcsIntElement) should be true");
                bool hasMissingElements = chunk.Has(missingElements);
                Assert.IsFalse(hasMissingElements, "Has(EcsComplexEntityRefElement) should be false");
            }

            chunks.Dispose();
        }
 protected override void OnCreateManager()
 {
     _allRandomQuery = new EntityArchetypeQuery
     {
         Any  = new ComponentType[0],
         All  = new[] { ComponentType.Create <RandomValue>() },
         None = new ComponentType[0]
     };
     _noTagQuery = new EntityArchetypeQuery
     {
         Any  = new ComponentType[0],
         All  = new[] { ComponentType.Create <RandomValue>() },
         None = new[] { ComponentType.Create <FirstTag>(), ComponentType.Create <SecondTag>() }
     };
     _firstTagQuery = new EntityArchetypeQuery
     {
         Any  = new ComponentType[0],
         All  = new[] { ComponentType.Create <RandomValue>(), ComponentType.Create <FirstTag>() },
         None = new ComponentType[0]
     };
     _secondTagQuery = new EntityArchetypeQuery
     {
         Any  = new ComponentType[0],
         All  = new[] { ComponentType.Create <RandomValue>(), ComponentType.Create <SecondTag>(), },
         None = new ComponentType[0]
     };
 }
Example #7
0
        public void PFB_InstantiatedWithoutPrefab()
        {
            var archetype0 = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(Prefab));

            var entity0 = m_Manager.CreateEntity(archetype0);
            var entity1 = m_Manager.Instantiate(entity0);

            Assert.AreEqual(true, m_Manager.HasComponent <Prefab>(entity0));
            Assert.AreEqual(false, m_Manager.HasComponent <Prefab>(entity1));

            var query = new EntityArchetypeQuery
            {
                Any  = Array.Empty <ComponentType>(),
                None = Array.Empty <ComponentType>(),
                All  = new ComponentType[] { typeof(EcsTestData) }
            };
            var chunks = m_Manager.CreateArchetypeChunkArray(query, Allocator.TempJob);
            var count  = ArchetypeChunkArray.CalculateEntityCount(chunks);

            chunks.Dispose();

            Assert.AreEqual(1, count);

            m_Manager.DestroyEntity(entity0);
            m_Manager.DestroyEntity(entity1);
        }
        public void DIS_FindDisabledIfRequestedInChunkIterator()
        {
            var archetype0 = m_Manager.CreateArchetype(typeof(EcsTestData));
            var archetype1 = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(Disabled));

            var entity0 = m_Manager.CreateEntity(archetype0);
            var entity1 = m_Manager.CreateEntity(archetype1);
            var entity2 = m_Manager.CreateEntity(archetype1);

            var query = new EntityArchetypeQuery
            {
                Any  = Array.Empty <ComponentType>(),
                None = Array.Empty <ComponentType>(),
                All  = new ComponentType[] { typeof(EcsTestData), typeof(Disabled) }
            };
            var chunks = m_Manager.CreateArchetypeChunkArray(query, Allocator.TempJob);
            var count  = ArchetypeChunkArray.CalculateEntityCount(chunks);

            chunks.Dispose();

            Assert.AreEqual(2, count);

            m_Manager.DestroyEntity(entity0);
            m_Manager.DestroyEntity(entity1);
            m_Manager.DestroyEntity(entity2);
        }
Example #9
0
        public void ACS_ChunkArchetypeTypesMatch()
        {
            var entityTypes = new ComponentType[] { typeof(EcsTestData), typeof(EcsTestSharedComp), typeof(EcsIntElement) };

            CreateEntities(128);

            var query = new EntityArchetypeQuery
            {
                Any  = new ComponentType[0], // any
                None = new ComponentType[0], // none
                All  = entityTypes,          // all
            };

            using (var chunks = m_Manager.CreateArchetypeChunkArray(query, Allocator.TempJob))
            {
                foreach (var chunk in chunks)
                {
                    var archetype  = chunk.Archetype;
                    var chunkTypes = archetype.ComponentTypes;
                    foreach (var type in entityTypes)
                    {
                        Assert.Contains(type, chunkTypes);
                    }

                    Assert.Contains(new ComponentType(typeof(Entity)), chunkTypes);
                }
            }
        }
Example #10
0
        // Walk all accessible entity data and check that the versions match what we
        // believe the generation numbers should be.
        private void SanityCheckVersions()
        {
            var query = new EntityArchetypeQuery
            {
                Any  = Array.Empty <ComponentType>(),
                None = Array.Empty <ComponentType>(),
                All  = s_OurTypes,
            };
            var chunks = m_Manager.CreateArchetypeChunkArray(query, Allocator.TempJob);

            ArchetypeChunkEntityType entityType = m_Manager.GetArchetypeChunkEntityType();

            for (int i = 0; i < chunks.Length; ++i)
            {
                ArchetypeChunk chunk           = chunks[i];
                var            entitiesInChunk = chunk.GetNativeArray(entityType);

                for (int k = 0; k < chunk.Count; ++k)
                {
                    Entity e       = entitiesInChunk[k];
                    int    index   = e.Index;
                    int    version = e.Version;

                    int ourArray   = index / kBatchCount;
                    int ourVersion = Bags[ourArray].ValidVersion;

                    Assert.IsTrue(ourVersion == version);
                }
            }

            chunks.Dispose();
        }
        void VerifyQueryCount(EntityArchetypeQuery query, int expectedCount)
        {
            var chunks = m_Manager.CreateArchetypeChunkArray(query, Allocator.TempJob);

            Assert.AreEqual(expectedCount, ArchetypeChunkArray.CalculateEntityCount(chunks));
            chunks.Dispose();
        }
Example #12
0
        public void ACS_WriteMixed()
        {
            CreateMixedEntities(64);

            var query = new EntityArchetypeQuery
            {
                Any  = new ComponentType[] { typeof(EcsTestData2), typeof(EcsTestData) }, // any
                None = Array.Empty <ComponentType>(),                                     // none
                All  = Array.Empty <ComponentType>(),                                     // all
            };
            var chunks = m_Manager.CreateArchetypeChunkArray(query, Allocator.TempJob);

            Assert.AreEqual(14, chunks.Length);

            var ecsTestData      = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false);
            var ecsTestData2     = m_Manager.GetArchetypeChunkComponentType <EcsTestData2>(false);
            var changeValuesJobs = new ChangeMixedValues
            {
                chunks       = chunks,
                ecsTestData  = ecsTestData,
                ecsTestData2 = ecsTestData2,
            };

            var collectValuesJobHandle = changeValuesJobs.Schedule(chunks.Length, 64);

            collectValuesJobHandle.Complete();

            ulong foundValues = 0;

            for (int chunkIndex = 0; chunkIndex < chunks.Length; chunkIndex++)
            {
                var chunk      = chunks[chunkIndex];
                var chunkCount = chunk.Count;

                Assert.AreEqual(4, math.ceil_pow2(chunkCount - 1));

                var chunkEcsTestData  = chunk.GetNativeArray(ecsTestData);
                var chunkEcsTestData2 = chunk.GetNativeArray(ecsTestData2);
                if (chunkEcsTestData.Length > 0)
                {
                    for (int i = 0; i < chunkCount; i++)
                    {
                        foundValues |= (ulong)1 << (chunkEcsTestData[i].value - 100);
                    }
                }
                else if (chunkEcsTestData2.Length > 0)
                {
                    for (int i = 0; i < chunkCount; i++)
                    {
                        foundValues |= (ulong)1 << (-chunkEcsTestData2[i].value0 - 1000);
                    }
                }
            }

            foundValues++;
            Assert.AreEqual(0, foundValues);

            chunks.Dispose();
        }
Example #13
0
 public EventBatch()
 {
     this.query = new EntityArchetypeQuery
     {
         Any  = Array.Empty <ComponentType>(),
         None = Array.Empty <ComponentType>(),
         All  = new[] { ComponentType.Create <T>() },
     };
 }
Example #14
0
 protected override void OnCreateManager()
 {
     _query = new EntityArchetypeQuery
     {
         Any  = new ComponentType[0],
         All  = new[] { ComponentType.Create <RandomValue>() },
         None = new ComponentType[0]
     };
 }
    protected override void OnCreateManager()
    {
        var query = new EntityArchetypeQuery
        {
            All = new ComponentType[] { typeof(AABB) }
        };

        m_AABBGroup = GetComponentGroup(query);
    }
Example #16
0
 public EntityListQuery(ComponentGroup group)
 {
     this.Group = group;
     this.Query = new EntityArchetypeQuery()
     {
         All  = group.Types.Where(x => x.AccessModeType != ComponentType.AccessMode.Subtractive).ToArray(),
         None = group.Types.Where(x => x.AccessModeType == ComponentType.AccessMode.Subtractive).ToArray(),
         Any  = new ComponentType[0]
     };
 }
Example #17
0
        public void EntityArchetypeQueryMembersHaveSensibleDefaults()
        {
            ComponentType[] types = { typeof(Issue476Data) };
            var             query = new EntityArchetypeQuery {
                All = types
            };
            var temp = m_Manager.CreateArchetypeChunkArray(query, Allocator.TempJob);

            temp.Dispose();
        }
        protected override void OnCreateManager()
        {
            base.OnCreateManager();

            var query = new EntityArchetypeQuery()
            {
                All = new ComponentType[] { typeof(MicrophoneInput), },
            };

            microphoneInputs = GetComponentGroup(query);
        }
Example #19
0
    protected override void OnCreateManager()
    {
        entityManager = World.Active.GetOrCreateManager <EntityManager>();
        material      = TerrainSettings.terrainMaterial;
        EntityArchetypeQuery applyMeshQuery = new EntityArchetypeQuery
        {
            None = new ComponentType[] { typeof(NotInDrawRangeSectorTag), typeof(InnerDrawRangeSectorTag) },
            All  = new ComponentType[] { typeof(Sector), typeof(MeshVert) }
        };

        applyMeshGroup = GetComponentGroup(applyMeshQuery);
    }
    protected override void OnCreateManager()
    {
        entityManager = World.Active.GetOrCreateManager <EntityManager>();

        EntityArchetypeQuery squareQuery = new EntityArchetypeQuery
        {
            None = new ComponentType[] { typeof(NotInDrawRangeSectorTag), typeof(NeighboursAreReady) },
            All  = new ComponentType[] { typeof(Sector), typeof(DrawMeshTag), typeof(AdjacentSectors) }
        };

        meshReadyGroup = GetComponentGroup(squareQuery);
    }
 protected override void OnCreateManager()
 {
     query = new EntityArchetypeQuery
     {
         All = new ComponentType[] {
             ComponentType.Create <PositionData>(),
             ComponentType.Create <DestinationData>()
         },
         Any  = System.Array.Empty <ComponentType>(),
         None = System.Array.Empty <ComponentType>()
     };
 }
    protected override void OnCreateManager()
    {
        entityManager = World.Active.GetOrCreateManager <EntityManager>();

        EntityArchetypeQuery meshDataQuery = new EntityArchetypeQuery
        {
            None = new ComponentType[] { typeof(NotInDrawRangeSectorTag), typeof(OuterDrawRangeSectorTag) },
            All  = new ComponentType[] { typeof(Sector), typeof(SectorVisFacesCount) }
        };

        meshDataGroup = GetComponentGroup(meshDataQuery);
    }
Example #23
0
    protected override void OnCreateManager()
    {
        base.OnCreateManager();

        var query = new EntityArchetypeQuery()
        {
            All = new ComponentType[] { typeof(PitchDetector), },
        };

        pitchDetectors = GetComponentGroup(query);

        fastYin = new FastYin(44100, 1024);
    }
        protected override void OnCreateManager()
        {
            m_Query = new EntityArchetypeQuery {
                Any  = new ComponentType[] { typeof(MeshInstanceRenderer), typeof(CustomMeshInstanceRenderer), },
                None = System.Array.Empty <ComponentType>(),
                All  = new ComponentType[] { typeof(StartTime), },
            };
            m_PrevInvMatrix = UnityEngine.Matrix4x4.identity;

            m_CurrentTimeID   = UnityEngine.Shader.PropertyToID("_CurrentTime");
            m_DTID            = UnityEngine.Shader.PropertyToID("_DT");
            m_PrevInvMatrixID = UnityEngine.Shader.PropertyToID("_PrevInvMatrix");
        }
 protected override void OnCreateManager()
 {
     base.OnCreateManager();
     _query = new EntityArchetypeQuery
     {
         Any  = new ComponentType[0],
         All  = new[] { ComponentType.Create <RandomValue>() },
         None = new ComponentType[0]
     };
     _totalSum      = new NativeArray <double>(BatchesCount, Allocator.Persistent);
     _noTagSum      = new NativeArray <double>(BatchesCount, Allocator.Persistent);
     _firstTagSum   = new NativeArray <double>(BatchesCount, Allocator.Persistent);
     _secondTimeSum = new NativeArray <double>(BatchesCount, Allocator.Persistent);
 }
Example #26
0
 protected override void OnCreateManager()
 {
     query = new EntityArchetypeQuery
     {
         All = new ComponentType[] {
             ComponentType.Create <RiderData>()
         },
         Any = new ComponentType[] {
             ComponentType.ReadOnly <BikeData>(),
             ComponentType.ReadOnly <CarData>()
         },
         None = System.Array.Empty <ComponentType>()
     };
 }
        void VerifyComponentCount <T>(int expectedCount)
            where T : IComponentData
        {
            var query = new EntityArchetypeQuery
            {
                Any  = Array.Empty <ComponentType>(),
                None = Array.Empty <ComponentType>(),
                All  = new ComponentType[] { typeof(T) }
            };
            var chunks = m_Manager.CreateArchetypeChunkArray(query, Allocator.TempJob);

            Assert.AreEqual(expectedCount, ArchetypeChunkArray.CalculateEntityCount(chunks));
            chunks.Dispose();
        }
Example #28
0
        protected override void OnCreateManager()
        {
            base.OnCreateManager();

            var query = new EntityArchetypeQuery()
            {
                All = new ComponentType[] { typeof(PitchDetector), },
            };

            pitchDetectors = GetComponentGroup(query);

            pitchTracker            = new PitchTracker();
            pitchTracker.SampleRate = 44100;
        }
Example #29
0
        public void ACS_BufferVersions()
        {
            CreateEntities(128);

            var query = new EntityArchetypeQuery
            {
                Any  = new ComponentType[] {},                        // any
                None = Array.Empty <ComponentType>(),                 // none
                All  = new ComponentType[] { typeof(EcsIntElement) }, // all
            };
            var chunks = m_Manager.CreateArchetypeChunkArray(query, Allocator.TempJob);

            var intElements = m_Manager.GetArchetypeChunkBufferType <EcsIntElement>(false);

            uint[] chunkBufferVersions = new uint[chunks.Length];

            for (int i = 0; i < chunks.Length; ++i)
            {
                var chunk = chunks[i];

                // Test DidChange() and DidAddOrChange() before modifications
                chunkBufferVersions[i] = chunk.GetComponentVersion(intElements);
                bool beforeDidAddOrChange = chunk.DidAddOrChange(intElements, chunkBufferVersions[i]);
                Assert.IsFalse(beforeDidAddOrChange, "DidAddOrChange() is true before modifications");
                bool beforeDidChange = chunk.DidChange(intElements);
                Assert.IsFalse(beforeDidChange, "DidChange() is true before modifications");
                uint beforeVersion = chunk.GetComponentVersion(intElements);
                Assert.AreEqual(chunkBufferVersions[i], beforeVersion, "version mismatch before modifications");
            }

            // Run system to bump chunk versions
            var bumpChunkBufferTypeVersionSystem = World.CreateManager <BumpChunkBufferTypeVersionSystem>();

            bumpChunkBufferTypeVersionSystem.Update();

            // Check versions after modifications
            for (int i = 0; i < chunks.Length; ++i)
            {
                var chunk = chunks[i];

                uint afterVersion = chunk.GetComponentVersion(intElements);
                Assert.AreNotEqual(chunkBufferVersions[i], afterVersion, "version match after modifications");
                bool afterDidAddChange = chunk.DidAddOrChange(intElements, chunkBufferVersions[i]);
                Assert.IsTrue(afterDidAddChange, "DidAddOrChange() is false after modifications");
                bool afterDidChange = chunk.DidChange(intElements);
                Assert.IsTrue(afterDidChange, "DidChange() is false after modifications");
            }

            chunks.Dispose();
        }
        private static EntityArchetypeQuery GetQueryForGroup(ComponentGroup group)
        {
            if (!queriesByGroup.ContainsKey(group))
            {
                var query = new EntityArchetypeQuery()
                {
                    All  = group.Types.Where(x => x.AccessModeType != ComponentType.AccessMode.Subtractive).ToArray(),
                    Any  = new ComponentType[0],
                    None = group.Types.Where(x => x.AccessModeType == ComponentType.AccessMode.Subtractive).ToArray()
                };
                queriesByGroup.Add(group, query);
            }

            return(queriesByGroup[group]);
        }