Пример #1
0
        public void RemoveSharedComponentFromEntity()
        {
            ECSWorld world  = new ECSWorld();
            var      buffer = new EntityCommandBuffer(world);

            SharedComponent1 shared1   = new SharedComponent1();
            EntityArchetype  archetype = EntityArchetype.Empty;

            archetype = archetype.Add <TestComponent1>();
            archetype = archetype.AddShared(shared1);

            Entity target = world.Instantiate(archetype);

            buffer.RemoveSharedComponent <SharedComponent1>(target);
            buffer.Playback();

            ComponentQuery query = new ComponentQuery();

            query.IncludeReadWrite <TestComponent1>();
            query.ExcludeShared <SharedComponent1>();

            Assert.Collection(world.ComponentManager.GetBlocks(query), accessor => {
                Assert.Equal(1, accessor.GetEntityData().Length);
            });
        }
        public void HashCodeSame()
        {
            ComponentQuery query1 = new ComponentQuery();

            query1.IncludeReadWrite <TestComponent1>();
            ComponentQuery query2 = new ComponentQuery();

            query2.IncludeReadWrite <TestComponent1>();

            Assert.Equal(query1.GetHashCode(), query2.GetHashCode());

            query1 = new ComponentQuery();
            query1.Exclude <TestComponent1>();
            query2 = new ComponentQuery();
            query2.Exclude <TestComponent1>();

            Assert.Equal(query1.GetHashCode(), query2.GetHashCode());

            query1 = new ComponentQuery();
            query1.IncludeShared <SharedComponent1>();
            query2 = new ComponentQuery();
            query2.IncludeShared <SharedComponent1>();

            Assert.Equal(query1.GetHashCode(), query2.GetHashCode());

            query1 = new ComponentQuery();
            query1.ExcludeShared <SharedComponent1>();
            query2 = new ComponentQuery();
            query2.ExcludeShared <SharedComponent1>();

            Assert.Equal(query1.GetHashCode(), query2.GetHashCode());
        }
        public override ComponentQuery GetQuery()
        {
            ComponentQuery query = new ComponentQuery();

            query.IncludeReadonly <BoundingBox>();
            query.ExcludeShared <CulledRenderTag>();
            return(query);
        }
        public void ExcludeShared()
        {
            ComponentQuery query = new ComponentQuery();

            query.ExcludeShared <SharedComponent2>();

            Assert.True(query.Matches(archetypeEmpty));
            Assert.True(query.Matches(archetypeC1C2S1));
            Assert.False(query.Matches(archetypeC1C2S1S2));
            Assert.True(query.Matches(archetypeC1));
            Assert.True(query.Matches(archetypeC1C2));
            Assert.True(query.Matches(archetypeC1S1));
            Assert.True(query.Matches(archetypeC2S1));
        }
        public void IncludeExcludeAll()
        {
            ComponentQuery query = new ComponentQuery();

            query.IncludeReadWrite <TestComponent1>();
            query.Exclude <TestComponent2>();
            query.IncludeShared <SharedComponent1>();
            query.ExcludeShared <SharedComponent2>();

            Assert.False(query.Matches(archetypeEmpty));
            Assert.False(query.Matches(archetypeC1C2S1));
            Assert.False(query.Matches(archetypeC1C2S1S2));
            Assert.False(query.Matches(archetypeC1));
            Assert.False(query.Matches(archetypeC1C2));
            Assert.True(query.Matches(archetypeC1S1));
            Assert.False(query.Matches(archetypeC2S1));
        }
        public void HashCodeNotZero()
        {
            ComponentQuery query1 = new ComponentQuery();

            query1.IncludeReadWrite <TestComponent1>();
            Assert.NotEqual(0, query1.GetHashCode());

            query1 = new ComponentQuery();
            query1.Exclude <TestComponent1>();
            Assert.NotEqual(0, query1.GetHashCode());

            query1 = new ComponentQuery();
            query1.IncludeShared <SharedComponent1>();
            Assert.NotEqual(0, query1.GetHashCode());

            query1 = new ComponentQuery();
            query1.ExcludeShared <SharedComponent1>();
            Assert.NotEqual(0, query1.GetHashCode());
        }
        public void OnCreate(ECSWorld world)
        {
            query.IncludeReadonly <ObjectToWorld>();
            query.IncludeShared <DebugMeshConvexHullRenderer>();
            query.ExcludeShared <CulledRenderTag>();

            var fragShader = Asset.Load <ShaderAsset>("mesh_instanced_default.frag");
            var vertShader = Asset.Load <ShaderAsset>("mesh_instanced_default.vert");
            var shader     = new ShaderPipeline(fragShader, vertShader, ShaderType.Instanced);

            defaultShader = shader.ShaderPair;

            defaultMaterial = new Material(GraphicsContext.graphicsDevice,
                                           GraphicsContext.uniform0, defaultShader);
            defaultMaterial.wireframe = true;

            instanceMatricesBuffers = new List <DeviceBuffer>(1);
            GrowInstanceMatrices();
        }
Пример #8
0
        public void CreateEntityAddShared()
        {
            ECSWorld world  = new ECSWorld();
            var      buffer = new EntityCommandBuffer(world);

            SharedComponent1 shared1 = new SharedComponent1();
            Prefab           prefab  = new Prefab();

            prefab.AddComponent(new TestComponentVector3()
            {
                value = Vector3.UnitY
            });


            buffer.CreateEntity(prefab);
            buffer.CreateEntity(prefab);
            buffer.AddSharedComponent(shared1);
            buffer.Playback();

            ComponentQuery query = new ComponentQuery();

            query.IncludeReadWrite <TestComponentVector3>();
            query.ExcludeShared <SharedComponent1>();

            Assert.Collection(world.ComponentManager.GetBlocks(query), accessor => {
                Assert.Equal(1, accessor.GetEntityData().Length);
                var cData = accessor.GetComponentData <TestComponentVector3>();
                Assert.Equal(Vector3.UnitY, cData[0].value);
            });

            query.IncludeShared <SharedComponent1>();

            Assert.Collection(world.ComponentManager.GetBlocks(query), accessor => {
                Assert.Equal(1, accessor.GetEntityData().Length);
                var cData = accessor.GetComponentData <TestComponentVector3>();
                Assert.Equal(Vector3.UnitY, cData[0].value);

                var shared = accessor.GetSharedComponentData <SharedComponent1>();
                Assert.Same(shared1, shared);
            });
        }