示例#1
0
 /// <summary>Initializes a new instance of the <see cref="EntitySystem" /> class.</summary>
 protected EntitySystem()
 {
     this.SystemBit = 0;
     this.Aspect    = Aspect.Empty();
     this.IsEnabled = true;
     this.Types     = null;
 }
        public void TestAspectAllOneExclude()
        {
            Aspect aspect = Aspect.Empty()
                            .GetAll(typeof(TestHealthComponent))
                            .GetOne(typeof(TestBaseComponent), typeof(TestDerivedComponent))
                            .GetExclude(typeof(TestPowerComponent), typeof(TestPowerComponentPoolable));

            EntityWorld entityWorld = new EntityWorld();
            Entity      entity;

            entity = entityWorld.CreateEntity();
            Assert.IsFalse(aspect.Interests(entity), "Entity without components must NOT be subject to \"(Healthy) && (Base || Derived) && !(Power || PowerPoolable)\" Aspect");

            entity = entityWorld.CreateEntity();
            entity.AddComponent(new TestHealthComponent());
            Assert.IsFalse(aspect.Interests(entity), "Entity with {TestHealthComponent} must NOT be subject to \"(Healthy) && (Base || Derived) && !(Power || PowerPoolable)\" Aspect");

            entity = entityWorld.CreateEntity();
            entity.AddComponent(new TestHealthComponent());
            entity.AddComponent(new TestBaseComponent());
            Assert.IsTrue(aspect.Interests(entity), "Entity with {TestHealthComponent, TestBaseComponent} must be subject to \"(Healthy) && (Base || Derived) && !(Power || PowerPoolable)\" Aspect");

            entity = entityWorld.CreateEntity();
            entity.AddComponent(new TestHealthComponent());
            entity.AddComponent(new TestBaseComponent());
            entity.AddComponent(new TestDerivedComponent());
            Assert.IsTrue(aspect.Interests(entity), "Entity with {TestHealthComponent, TestBaseComponent, TestDerivedComponent} must be subject to \"(Healthy) && (Base || Derived) && !(Power || PowerPoolable)\" Aspect");

            entity = entityWorld.CreateEntity();
            entity.AddComponent(new TestHealthComponent());
            entity.AddComponent(new TestBaseComponent());
            entity.AddComponent(new TestDerivedComponent());
            entity.AddComponent(new TestPowerComponent());
            Assert.IsFalse(aspect.Interests(entity), "Entity with {TestHealthComponent, TestBaseComponent, TestDerivedComponent, TestPowerComponent} must NOT be subject to \"(Healthy) && (Base || Derived) && !(Power || PowerPoolable)\" Aspect");

            entity = entityWorld.CreateEntity();
            entity.AddComponent(new TestHealthComponent());
            entity.AddComponent(new TestDerivedComponent());
            entity.AddComponent(new TestPowerComponentPoolable());
            Assert.IsFalse(aspect.Interests(entity), "Entity with {TestHealthComponent, TestDerivedComponent, TestPowerComponentPoolable} must NOT be subject to \"(Healthy) && (Base || Derived) && !(Power || PowerPoolable)\" Aspect");

            entity = entityWorld.CreateEntity();
            entity.AddComponent(new TestHealthComponent());
            entity.AddComponent(new TestBaseComponent());
            entity.AddComponent(new TestDerivedComponent());
            entity.AddComponent(new TestPowerComponent());
            entity.AddComponent(new TestPowerComponentPoolable());
            Assert.IsFalse(aspect.Interests(entity), "Entity with {TestHealthComponent, TestBaseComponent, TestDerivedComponent, TestPowerComponent, TestPowerComponentPoolable} must NOT be subject to \"(Healthy) && (Base || Derived) && !(Power || PowerPoolable)\" Aspect");
        }
        public void TestAspectEmpty()
        {
            Aspect      aspect      = Aspect.Empty();
            EntityWorld entityWorld = new EntityWorld();
            Entity      entity;

            // Aspect.Empty is a base Aspect for EntitySystem meaning "no entities to process"
            entity = entityWorld.CreateEntity();
            Assert.IsFalse(aspect.Interests(entity), "Entity without components must NOT be subject to empty Aspect");

            entity = entityWorld.CreateEntity();
            entity.AddComponent(new TestHealthComponent());
            Assert.IsFalse(aspect.Interests(entity), "Entity with any component must NOT be subject to empty Aspect");

            entity = entityWorld.CreateEntity();
            entity.AddComponent(new TestPowerComponent());
            entity.AddComponent(new TestHealthComponent());
            Assert.IsFalse(aspect.Interests(entity), "Entity with any components must NOT be subject to empty Aspect");
        }
示例#4
0
 /// <summary>Initializes a new instance of the <see cref="EntitySystem" /> class.</summary>
 protected EntitySystem()
 {
     this.Bit       = 0;
     this.aspect    = Aspect.Empty();
     this.IsEnabled = true;
 }
 /// <summary>Initializes a new instance of the <see cref="EntityComponentProcessingSystem{T}"/> class with an aspect which processes entities which have all the specified component types.</summary>
 protected EntityComponentProcessingSystem()
     : this(Aspect.Empty())
 {
 }