public void CreateEntityBeforeUpdate() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <TestEntityTemplate>(); Assert.That(entity.Transform, Is.Not.Null); ComponentA component = entity.GetComponent <ComponentA>(); Assert.That(component.Transform, Is.Not.Null); Assert.That(!component.IsStarted); Assert.That(!component.IsUpdated); Assert.That(!component.IsDrew); Assert.That(!component.IsDestroyed); service.Update(new GameTime()); service.Draw(new GameTime()); Assert.That(component.IsStarted); Assert.That(component.IsUpdated); Assert.That(component.IsDrew); Assert.That(!component.IsDestroyed); }
public void CheckIdsAddingAndRemoving() { EcsService service = EcsServiceFactory.CreateECSManager(); int entitesCount = 10; Entity[] createdEntities = new Entity[entitesCount]; for (int i = 0; i < entitesCount; i++) { createdEntities[i] = service.CreateEntityFromTemplate <TestEntityTemplate>(); } for (int i = 0; i < entitesCount; i++) { Assert.That(createdEntities[i].Id, Is.EqualTo(i + 1)); } service.Update(new GameTime()); createdEntities[1].Destroy(); service.Update(new GameTime()); var newEntityWithOldId = service.CreateEntityFromTemplate <TestEntityTemplate>(); Assert.That(newEntityWithOldId.Id, Is.EqualTo(2)); }
public void DrawDisabledHierarchicalEntities() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <TestEntityTemplate>(); Entity entityChild = service.CreateEntityFromTemplate <TestEntityTemplate>(); entityChild.Transform.Parent = entity.Transform; ComponentA component = entity.GetComponent <ComponentA>(); ComponentA componentChild = entityChild.GetComponent <ComponentA>(); entity.Enabled = false; service.Update(new GameTime()); service.Draw(new GameTime()); Assert.That(entity.EnabledInHierarchy, Is.False); Assert.That(component.IsStarted, Is.True); Assert.That(component.IsDrew, Is.False); Assert.That(entityChild.EnabledInHierarchy, Is.False); Assert.That(componentChild.IsStarted, Is.True); Assert.That(componentChild.IsDrew, Is.False); }
public void RemoveTransformComponent() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); Assert.That(() => entity.RemoveComponent <Transform2DComponent>(), Throws.Exception.TypeOf <ArgumentException>()); }
public void ParentChangingTwiceAfterRegistration() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity parent = service.CreateEntityFromTemplate <TestEntityTemplate>(); Entity child = service.CreateEntityFromTemplate <TestEntityTemplate>(); service.Update(new GameTime()); child.Transform.Parent = parent.Transform; service.Update(new GameTime()); child.Transform.Parent = null; service.Update(new GameTime()); foreach (EntityNode entityNode in service.Tree) { if (entityNode.Entity == parent) { Assert.That(parent.Transform.Parent, Is.Null); } if (entityNode.Entity == child) { Assert.That(child.Transform.Parent, Is.Null); } } }
public void CreateEntityWithComponentWhichAddedAnotherComponentDuringUpdate() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); var component = entity.GetComponent <ConfigurableComponent>(); component.OnUpdateAction = configurableComponent => { if (configurableComponent.Entity.GetComponent <ComponentA>() == null) { configurableComponent.Entity.AddComponent <ComponentA>(); } }; service.Update(new GameTime()); var componentA = entity.GetComponent <ComponentA>(); Assert.That(componentA, Is.Not.Null); Assert.That(componentA.IsStarted, Is.False); service.Update(new GameTime()); Assert.That(componentA.IsStarted, Is.True); Assert.That(componentA.IsUpdated, Is.True); }
public void FindNonExistentComponents() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); var components = entity.FindComponents <ComponentA>(); Assert.That(components, Is.Empty); }
public void FindExistentComponents() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); var components = entity.FindComponents <ConfigurableComponent>(); Assert.That(components, Has.Exactly(1).TypeOf <ConfigurableComponent>()); }
public void FindExistentComponent() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); var component = entity.FindComponent <ConfigurableComponent>(); Assert.That(component, Is.Not.Null); }
public void DoubleDestroyEntity() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); service.Update(new GameTime()); entity.Destroy(); Assert.That(() => entity.Destroy(), Throws.Exception.TypeOf <EcsWorkflowException>()); }
public void GetComponentInParentAndChild() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); Entity entityChild = service.CreateEntityFromTemplate <TestEntityTemplate>(); entityChild.Transform.Parent = entity.Transform; Assert.That(entityChild.GetComponentInParent <ConfigurableComponent>(), Is.Not.Null); Assert.That(entity.GetComponentInChild <ConfigurableComponent>(), Is.Not.Null); }
public void DoubleRemoveComponent() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <TestEntityTemplate>(); var componentA = entity.GetComponent <ComponentA>(); service.Update(new GameTime()); componentA.Destroy(); Assert.That(() => componentA.Destroy(), Throws.Exception.TypeOf <EcsWorkflowException>()); }
public void CreateEntityWithTwoComponents() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <TwoComponentsEntityTemplate>(); ComponentA componentA = entity.GetComponent <ComponentA>(); ComponentB componentB = entity.GetComponent <ComponentB>(); service.Update(new GameTime()); Assert.That(componentB.ComponentAReference, Is.EqualTo(componentA)); }
public void UpdateDisabledEntity() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <TestEntityTemplate>(); ComponentA component = entity.GetComponent <ComponentA>(); entity.Enabled = false; service.Update(new GameTime()); Assert.That(entity.EnabledInHierarchy, Is.False); Assert.That(component.IsStarted, Is.True); Assert.That(component.IsUpdated, Is.False); }
public void EntityDestroyDuringDraw() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); var component = entity.GetComponent <ConfigurableComponent>(); component.OnDrawAction = configurableComponent => { configurableComponent.Entity.Destroy(); }; service.Update(new GameTime()); Assert.That(() => service.Draw(new GameTime()), Throws.Exception.TypeOf <EcsWorkflowException>()); }
public void DestroyEntityDuringUpdate() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); var component = entity.FindComponent <ConfigurableComponent>(); component.OnUpdateAction = configurableComponent => { configurableComponent.Entity.Destroy(); }; service.Update(new GameTime()); Assert.That(service.Tree, Is.Empty); }
public void CreateEntityWithComponentWhichRemovesItselfOnUpdate() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); var component = entity.GetComponent <ConfigurableComponent>(); component.OnUpdateAction = configurableComponent => { configurableComponent.Destroy(); }; service.Update(new GameTime()); service.Draw(new GameTime()); Assert.That(entity.GetComponent <ConfigurableComponent>(), Is.Null); }
public void GetComponentsInParentAndChild() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); Entity entityChild = service.CreateEntityFromTemplate <TestEntityTemplate>(); entityChild.Transform.Parent = entity.Transform; var parentComponents = entityChild.GetComponentsInParent <ConfigurableComponent>(); var childComponents = entity.GetComponentsInChild <ComponentA>(); Assert.That(parentComponents, Has.Exactly(1).Items); Assert.That(parentComponents, Has.Exactly(1).TypeOf <ConfigurableComponent>()); Assert.That(childComponents, Has.Exactly(1).Items); Assert.That(childComponents, Has.Exactly(1).TypeOf <ComponentA>()); }
public void RemoveComponentBeforeUpdate() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <TwoComponentsEntityTemplate>(); ComponentB componentB = entity.GetComponent <ComponentB>(); Assert.That(!componentB.IsEnabled); entity.RemoveComponent <ComponentB>(); service.Update(new GameTime()); Assert.That(!componentB.IsStarted); Assert.That(!componentB.IsUpdated); Assert.That(!componentB.IsEnabled); Assert.That(componentB.IsDestroyed); }
public void CreateEntityDuringUpdateFromTemplate() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); var component = entity.FindComponent <ConfigurableComponent>(); Entity newEntity = null; component.OnUpdateAction = configurableComponent => { newEntity = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); }; service.Update(new GameTime()); Assert.That(component, Is.Not.Null); Assert.That(newEntity, Is.Not.Null); Assert.That(newEntity.GetComponent <ConfigurableComponent>(), Is.Not.Null); }
public void DestoryEntityWithChildrenBeforeAdding() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entityParent = service.CreateEntityFromTemplate <TestEntityTemplate>(); Entity entityChild = service.CreateEntityFromTemplate <TestEntityTemplate>(); entityChild.Transform.Parent = entityParent.Transform; ComponentA parentComponent = entityParent.GetComponent <ComponentA>(); ComponentA childComponent = entityChild.GetComponent <ComponentA>(); entityParent.Destroy(); service.Update(new GameTime()); Assert.That(parentComponent.IsDestroyed); Assert.That(childComponent.IsDestroyed); Assert.That(service.Tree.Count(), Is.EqualTo(0)); }
public void DestoryEntityBeforeAdding() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <TwoComponentsEntityTemplate>(); ComponentB componentA = entity.GetComponent <ComponentB>(); ComponentB componentB = entity.GetComponent <ComponentB>(); entity.Destroy(); service.Update(new GameTime()); Assert.That(!componentA.IsStarted); Assert.That(!componentA.IsUpdated); Assert.That(!componentB.IsStarted); Assert.That(!componentB.IsUpdated); Assert.That(componentA.IsDestroyed); Assert.That(componentB.IsDestroyed); Assert.That(service.Tree.Count(), Is.EqualTo(0)); }
public void TransformChildIterationTest() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity parent = service.CreateEntityFromTemplate <TestEntityTemplate>(); Entity child1 = service.CreateEntityFromTemplate <TestEntityTemplate>(); Entity child2 = service.CreateEntityFromTemplate <TestEntityTemplate>(); Entity child3 = service.CreateEntityFromTemplate <TestEntityTemplate>(); child1.Transform.Parent = parent.Transform; child2.Transform.Parent = parent.Transform; child3.Transform.Parent = parent.Transform; Transform2DComponent[] childTransforms = new[] { child1.Transform, child2.Transform, child3.Transform }; service.Update(new GameTime()); Assert.That(parent.Transform, Is.EquivalentTo(childTransforms)); }
public void DrawEntityWhenChildChangedEnableness() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity entity = service.CreateEntityFromTemplate <TestEntityTemplate>(); Entity entityChild = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>(); entityChild.Transform.Parent = entity.Transform; var component = entity.GetComponent <ComponentA>(); var componentChild = entityChild.GetComponent <ConfigurableComponent>(); componentChild.OnDrawAction = configurableComponent => { configurableComponent.Entity.Transform.Parent.Entity.Enabled = false; }; service.Update(new GameTime()); service.Draw(new GameTime()); Assert.That(entity.EnabledInHierarchy, Is.False); Assert.That(component.IsStarted, Is.True); Assert.That(component.IsDrew, Is.False); }
public void RunBeforeAnyTests() { EcsServiceFactory.ScanAssemblies(AppDomain.CurrentDomain.GetAssemblies()); }
public void ZIndexChanging() { EcsService service = EcsServiceFactory.CreateECSManager(); Entity parent = service.CreateEntityFromTemplate <TestEntityTemplate>(); Entity childOne = service.CreateEntityFromTemplate <TestEntityTemplate>(); Entity childTwo = service.CreateEntityFromTemplate <TestEntityTemplate>(); Entity childThree = service.CreateEntityFromTemplate <TestEntityTemplate>(); childOne.Transform.Parent = parent.Transform; childTwo.Transform.Parent = parent.Transform; childThree.Transform.Parent = parent.Transform; childOne.Transform.ZIndex = 10; childTwo.Transform.ZIndex = 20; childThree.Transform.ZIndex = 30; service.Update(new GameTime()); foreach (EntityNode entityNode in service.Tree) { if (entityNode.Entity == parent) { Assert.That(entityNode, Is.Ordered.Using(new EntityNodeZIndexComparator())); } } childOne.Transform.ZIndex = 20; childTwo.Transform.ZIndex = 10; childThree.Transform.ZIndex = 5; foreach (EntityNode entityNode in service.Tree) { if (entityNode.Entity == parent) { Assert.That(entityNode, Is.Ordered.Using(new EntityNodeZIndexComparator())); } } childOne.Transform.ZIndex = 20; childTwo.Transform.ZIndex = 5; childThree.Transform.ZIndex = 10; foreach (EntityNode entityNode in service.Tree) { if (entityNode.Entity == parent) { Assert.That(entityNode, Is.Ordered.Using(new EntityNodeZIndexComparator())); } } childOne.Transform.ZIndex = 5; childTwo.Transform.ZIndex = 5; childThree.Transform.ZIndex = 10; foreach (EntityNode entityNode in service.Tree) { if (entityNode.Entity == parent) { Assert.That(entityNode, Is.Ordered.Using(new EntityNodeZIndexComparator())); } } }
public void CreateEntityFromNotExistentTemplateByName() { EcsService service = EcsServiceFactory.CreateECSManager(); Assert.That(() => service.CreateEntityFromTemplate("SomeNotExistentTemplateName"), Throws.Exception.TypeOf <ArgumentException>()); }
public void CreateEntityFromNotExistentTemplateByType() { EcsService service = EcsServiceFactory.CreateECSManager(); Assert.That(() => service.CreateEntityFromTemplate(typeof(ComponentA)), Throws.Exception.TypeOf <ArgumentException>()); }