protected virtual ISystem RegisterBoundSystem <T>() where T : ISystem { var system = DependencyContainer.Resolve <T>(); SystemExecutor.AddSystem(system); return(system); }
public void should_effect_correct_setup_systems_once() { var dummyGroup = new Group(typeof(TestComponentOne), typeof(TestComponentTwo)); var mockPoolManager = Substitute.For <IPoolManager>(); var pool = mockPoolManager.GetPool(); var mockEventSystem = Substitute.For <IEventSystem>(); var mockSetupSystemHandler = Substitute.For <ISetupSystemHandler>(); var fakeSystem = Substitute.For <ISetupSystem>(); fakeSystem.TargetGroup.Returns(dummyGroup); var systemExecutor = new SystemExecutor(mockPoolManager, mockEventSystem, null, null, mockSetupSystemHandler, null, null); systemExecutor.AddSystem(fakeSystem); var entity = new Entity(Guid.NewGuid(), pool, mockEventSystem); entity.AddComponent(new TestComponentOne()); systemExecutor.OnEntityComponentAdded(new ComponentAddedEvent(entity, new TestComponentOne())); entity.AddComponent(new TestComponentTwo()); systemExecutor.OnEntityComponentAdded(new ComponentAddedEvent(entity, new TestComponentTwo())); entity.AddComponent(new TestComponentThree()); systemExecutor.OnEntityComponentAdded(new ComponentAddedEvent(entity, new TestComponentThree())); mockSetupSystemHandler.Received(1).ProcessEntity(Arg.Is(fakeSystem), Arg.Is(entity)); }
public void should_remove_setup_system_subscriptions_and_dispose_when_removing_corresponding_entity() { var dummyGroup = new Group(typeof(TestComponentOne)); var mockPoolManager = Substitute.For <IPoolManager>(); var mockEventSystem = Substitute.For <IEventSystem>(); var mockSetupSystemHandler = Substitute.For <ISetupSystemHandler>(); var fakeSystem = Substitute.For <ISetupSystem>(); fakeSystem.TargetGroup.Returns(dummyGroup); var entity = new Entity(Guid.NewGuid(), mockEventSystem); entity.AddComponent(new TestComponentOne()); var fakeDisposable = Substitute.For <IDisposable>(); mockSetupSystemHandler.ProcessEntity(fakeSystem, entity).Returns(new SubscriptionToken(entity, fakeDisposable)); var systemExecutor = new SystemExecutor(mockPoolManager, mockEventSystem, null, null, mockSetupSystemHandler, null, null); systemExecutor.AddSystem(fakeSystem); systemExecutor.OnEntityAddedToPool(new EntityAddedEvent(entity, null)); Assert.That(systemExecutor.GetSubscriptionCountForSystem(fakeSystem), Is.EqualTo(1)); Assert.That(systemExecutor.GetTotalSubscriptions(), Is.EqualTo(1)); systemExecutor.OnEntityRemovedFromPool(new EntityRemovedEvent(entity, null)); Assert.That(systemExecutor.GetSubscriptionCountForSystem(fakeSystem), Is.EqualTo(0)); Assert.That(systemExecutor.GetTotalSubscriptions(), Is.EqualTo(0)); fakeDisposable.Received().Dispose(); }
public void should_only_trigger_teardown_system_when_entity_loses_required_component() { var dummyGroup = new Group(typeof(TestComponentOne), typeof(TestComponentTwo)); var mockPoolManager = Substitute.For <IPoolManager>(); var pool = mockPoolManager.GetPool(); var mockEventSystem = Substitute.For <IEventSystem>(); var fakeSystem = Substitute.For <ITeardownSystem>(); fakeSystem.TargetGroup.Returns(dummyGroup); var systemExecutor = new SystemExecutor(mockPoolManager, mockEventSystem, null, null, null, null, null); systemExecutor.AddSystem(fakeSystem); var entity = new Entity(Guid.NewGuid(), pool, mockEventSystem); entity.AddComponent(new TestComponentOne()); entity.AddComponent(new TestComponentTwo()); // Should not trigger systemExecutor.OnEntityComponentRemoved(new ComponentRemovedEvent(entity, new TestComponentThree())); // Should trigger systemExecutor.OnEntityComponentRemoved(new ComponentRemovedEvent(entity, new TestComponentTwo())); fakeSystem.Received(1).Teardown(Arg.Is(entity)); }
protected override void GameStarted() { var defaultPool = PoolManager.GetPool(); SystemExecutor.AddSystem(DefaultViewResolver); SystemExecutor.AddSystem(RandomMovementSystem); var entity = defaultPool.CreateEntity(); entity.AddComponent(new ViewComponent()); }
protected override void ApplicationStarted() { SystemExecutor.AddSystem(CustomViewSetupSystem); SystemExecutor.AddSystem(PlayerControlSystem); SystemExecutor.AddSystem(CameraFollowSystem); var defaultPool = PoolManager.GetPool(); var viewEntity = defaultPool.CreateEntity(); viewEntity.AddComponent(new CustomViewComponent()); viewEntity.AddComponent(new PlayerControlledComponent()); viewEntity.AddComponent(new CameraFollowsComponent()); }
public void should_handle_and_expose_system() { var fakeSetupSystemHandler = Substitute.For <IConventionalSystemHandler>(); var fakeSystem = Substitute.For <ISetupSystem>(); fakeSetupSystemHandler.CanHandleSystem(Arg.Is(fakeSystem)).Returns(true); var systemExecutor = new SystemExecutor(new[] { fakeSetupSystemHandler }); systemExecutor.AddSystem(fakeSystem); fakeSetupSystemHandler.Received(1).SetupSystem(fakeSystem); Assert.Contains(fakeSystem, systemExecutor.Systems); }
public void should_identify_as_reactive_group_system_and_add_to_systems() { var mockPoolManager = Substitute.For <IPoolManager>(); var mockEventSystem = Substitute.For <IEventSystem>(); var mockReactToGroupSystemHandler = Substitute.For <IGroupReactionSystemHandler>(); var fakeSystem = Substitute.For <IGroupReactionSystem>(); var systemExecutor = new SystemExecutor(mockPoolManager, mockEventSystem, null, mockReactToGroupSystemHandler, null, null, null); systemExecutor.AddSystem(fakeSystem); mockReactToGroupSystemHandler.Received().Setup(fakeSystem); Assert.That(systemExecutor.Systems, Contains.Item(fakeSystem)); }
public void should_remove_system_from_systems() { var mockPoolManager = Substitute.For <IPoolManager>(); var mockEventSystem = Substitute.For <IEventSystem>(); var mockSetupSystemHandler = Substitute.For <ISetupSystemHandler>(); var fakeSystem = Substitute.For <ISetupSystem>(); var systemExecutor = new SystemExecutor(mockPoolManager, mockEventSystem, null, null, mockSetupSystemHandler, null, null); systemExecutor.AddSystem(fakeSystem); systemExecutor.RemoveSystem(fakeSystem); Assert.That(systemExecutor.Systems, Is.Empty); }
public void should_identify_as_reactive_entity_system_and_add_to_systems() { var mockPoolManager = Substitute.For <IPoolManager>(); var messageBroker = Substitute.For <IMessageBroker>(); var mockReactToEntitySystemHandler = Substitute.For <IReactToEntitySystemHandler>(); var fakeSystem = Substitute.For <IReactToEntitySystem>(); var systemExecutor = new SystemExecutor(mockPoolManager, messageBroker, mockReactToEntitySystemHandler, null, null, null); systemExecutor.AddSystem(fakeSystem); mockReactToEntitySystemHandler.Received().Setup(fakeSystem); Assert.That(systemExecutor.Systems, Contains.Item(fakeSystem)); }
public void should_identify_as_react_with_data_system_and_add_to_systems() { var mockPoolManager = Substitute.For <IPoolManager>(); var mockEventSystem = Substitute.For <IEventSystem>(); var mockReactToDataSystemHandler = Substitute.For <IReactToDataSystemHandler>(); var fakeSystem = Substitute.For <IReactToDataSystem <int> >(); var systemExecutor = new SystemExecutor(mockPoolManager, mockEventSystem, null, null, null, mockReactToDataSystemHandler, null); systemExecutor.AddSystem(fakeSystem); mockReactToDataSystemHandler.Received().SetupWithoutType(fakeSystem); Assert.That(systemExecutor.Systems, Contains.Item(fakeSystem)); }
public void should_run_systems_in_correct_priority() { var expectedOrder = "1234"; var actualOrder = new StringBuilder(); var conventionalSystems = new IConventionalSystemHandler[] { new DefaultPriorityHandler(() => actualOrder.Append(3)), new HigherPriorityHandler(() => actualOrder.Append(1)), new HighPriorityHandler(() => actualOrder.Append(2)), new LowerPriorityHandler(() => actualOrder.Append(4)) }; var systemExecutor = new SystemExecutor(conventionalSystems); var fakeSystem1 = Substitute.For <ISetupSystem>(); systemExecutor.AddSystem(fakeSystem1); Assert.Equal(expectedOrder, actualOrder.ToString()); }
protected override void ApplicationStarted() { var namedHealthGroup = EntityCollectionManager.GetObservableGroup(new Group(typeof(HasHealthComponent), typeof(HasNameComponent))); var computedGroup = new LowestHealthComputedGroup(namedHealthGroup); var displayHealthSystem = new DisplayLowestHealthSystem(computedGroup); SystemExecutor.AddSystem(displayHealthSystem); this.StartAllBoundSystems(); var defaultPool = EntityCollectionManager.GetCollection(); defaultPool.CreateEntity(new CharacterBlueprint("Bob", 200)); defaultPool.CreateEntity(new CharacterBlueprint("Tom", 150)); defaultPool.CreateEntity(new CharacterBlueprint("Rolf", 150)); defaultPool.CreateEntity(new CharacterBlueprint("Mez", 100)); defaultPool.CreateEntity(new CharacterBlueprint("TP", 1000)); defaultPool.CreateEntity(new CharacterBlueprint("MasterChief", 100)); defaultPool.CreateEntity(new CharacterBlueprint("Weakling", 20)); HandleInput(); }
public void should_throw_exception_if_system_already_exists() { var fakeSystem = Substitute.For <ISystem>(); var systemExecutor = new SystemExecutor(new IConventionalSystemHandler[0]); systemExecutor._systems.Add(fakeSystem); var exceptionWasRaised = false; try { systemExecutor.AddSystem(fakeSystem); } catch (SystemAlreadyRegisteredException e) { exceptionWasRaised = true; } Assert.Single(systemExecutor.Systems); Assert.True(exceptionWasRaised); }
protected virtual void StartPluginSystems() { _plugins.SelectMany(x => x.GetSystemsForRegistration(Container)) .ForEachRun(x => SystemExecutor.AddSystem(x)); }
protected override void ApplicationStarting() { SystemExecutor.AddSystem(new SomeSystem()); SystemExecutor.AddSystem(new SomeSystem2()); SystemExecutor.AddSystem(new SomeSystem3()); }
protected virtual void SetupAllPluginSystems() { Plugins.SelectMany(x => x.GetSystemsForRegistration(DependencyContainer)) .ForEachRun(x => SystemExecutor.AddSystem(x)); }
protected virtual void RegisterBoundSystem <T>() where T : ISystem { var system = Container.Resolve <T>(); SystemExecutor.AddSystem(system); }
protected override void SetupSystems() { SystemExecutor.AddSystem(ViewSetupSystem); SystemExecutor.AddSystem(PlayerControlSystem); SystemExecutor.AddSystem(CameraFollowSystem); }
protected override void SetupSystems() { SystemExecutor.AddSystem(CubeSetupSystem); SystemExecutor.AddSystem(ColorChangingSystem); SystemExecutor.AddSystem(CubeColourChangerSystem); }