public void SetupSystem(ISystem system) { var affinities = system.GetGroupAffinities(); var observableGroup = ObservableGroupManager.GetObservableGroup(system.Group, affinities); var entitySubscriptions = new Dictionary <int, IDisposable>(); var entityChangeSubscriptions = new CompositeDisposable(); _systemSubscriptions.Add(system, entityChangeSubscriptions); var castSystem = (IReactToEntitySystem)system; observableGroup.OnEntityAdded .Subscribe(x => { var entitySubscription = ProcessEntity(castSystem, x); entitySubscriptions.Add(x.Id, entitySubscription); }) .AddTo(entityChangeSubscriptions); observableGroup.OnEntityRemoved .Subscribe(x => { entitySubscriptions.RemoveAndDispose(x.Id); }) .AddTo(entityChangeSubscriptions); foreach (var entity in observableGroup) { var subscription = ProcessEntity(castSystem, entity); entitySubscriptions.Add(entity.Id, subscription); } _entitySubscriptions.Add(system, entitySubscriptions); }
public void SetupSystem(ISystem system) { var castSystem = (IBasicEntitySystem)system; var affinities = castSystem.GetGroupAffinities(); var observableGroup = _observableGroupManager.GetObservableGroup(castSystem.Group, affinities); var hasEntityPredicate = castSystem.Group is IHasPredicate; var runParallel = system.ShouldMutliThread(); IDisposable subscription; if (!hasEntityPredicate) { subscription = UpdateScheduler.OnUpdate .Subscribe(x => ExecuteForGroup(observableGroup, castSystem, runParallel)); } else { var groupPredicate = castSystem.Group as IHasPredicate; subscription = UpdateScheduler.OnUpdate .Subscribe(x => ExecuteForGroup(observableGroup .Where(groupPredicate.CanProcessEntity).ToList(), castSystem, runParallel)); } _systemSubscriptions.Add(system, subscription); }
public TurnsSystem(GameConfiguration gameConfiguration, IEventSystem eventSystem, IObservableGroupManager observableGroupManager) { _gameConfiguration = gameConfiguration; _eventSystem = eventSystem; _levelAccessor = observableGroupManager.GetObservableGroup(new Group(typeof(LevelComponent))); }
public void SetupSystem(ISystem system) { var entityChangeSubscriptions = new CompositeDisposable(); SystemSubscriptions.Add(system, entityChangeSubscriptions); var castSystem = (ITeardownSystem)system; var affinities = castSystem.GetGroupAffinities(); var observableGroup = ObservableGroupManager.GetObservableGroup(castSystem.Group, affinities); observableGroup.OnEntityRemoving .Subscribe(castSystem.Teardown) .AddTo(entityChangeSubscriptions); }
public void SetupSystem(ISystem system) { var entitySubscriptions = new Dictionary <int, IDisposable>(); _entitySubscriptions.Add(system, entitySubscriptions); var entityChangeSubscriptions = new CompositeDisposable(); _systemSubscriptions.Add(system, entityChangeSubscriptions); var castSystem = (ISetupSystem)system; var affinities = castSystem.GetGroupAffinities(); var observableGroup = ObservableGroupManager.GetObservableGroup(castSystem.Group, affinities); observableGroup.OnEntityAdded .Subscribe(x => { var possibleSubscription = ProcessEntity(castSystem, x); if (possibleSubscription != null) { entitySubscriptions.Add(x.Id, possibleSubscription); } }) .AddTo(entityChangeSubscriptions); observableGroup.OnEntityRemoved .Subscribe(x => { if (entitySubscriptions.ContainsKey(x.Id)) { entitySubscriptions.RemoveAndDispose(x.Id); } }) .AddTo(entityChangeSubscriptions); foreach (var entity in observableGroup) { var possibleSubscription = ProcessEntity(castSystem, entity); if (possibleSubscription != null) { entitySubscriptions.Add(entity.Id, possibleSubscription); } } }
public void SetupSystem(ISystem system) { var affinities = system.GetGroupAffinities(); var observableGroup = _observableGroupManager.GetObservableGroup(system.Group, affinities); var groupPredicate = system.Group as IHasPredicate; var isExtendedSystem = system is IReactToGroupExSystem; var castSystem = (IReactToGroupSystem)system; var reactObservable = castSystem.ReactToGroup(observableGroup); var runParallel = system.ShouldMutliThread(); if (groupPredicate == null) { IDisposable noPredicateSub; if (isExtendedSystem) { noPredicateSub = reactObservable.Subscribe(x => ExecuteForGroup(x, (IReactToGroupExSystem)castSystem, runParallel)); } else { noPredicateSub = reactObservable.Subscribe(x => ExecuteForGroup(x, castSystem, runParallel)); } _systemSubscriptions.Add(system, noPredicateSub); return; } IDisposable predicateSub; if (isExtendedSystem) { predicateSub = reactObservable.Subscribe(x => ExecuteForGroup(x.Where(groupPredicate.CanProcessEntity).ToList(), (IReactToGroupExSystem)castSystem, runParallel)); } else { predicateSub = reactObservable.Subscribe(x => ExecuteForGroup(x.Where(groupPredicate.CanProcessEntity).ToList(), castSystem, runParallel)); } _systemSubscriptions.Add(system, predicateSub); }
public void SetupSystem(ISystem system) { var castSystem = (SpriteBatchSystem)system; var observableGroup = ObservableGroupManager.GetObservableGroup(castSystem.Group); var hasEntityPredicate = castSystem.Group is IHasPredicate; var renderTargetId = castSystem.GetRenderTexture2dId(); var currentRenderTargets = _graphicsDevice.GetRenderTargets(); var drawSubscription = _gameScheduler.OnRender.Subscribe(x => { if (renderTargetId >= 0) { var renderTarget = _renderTarget2dRegistry.GetRenderTarget(renderTargetId); _graphicsDevice.SetRenderTarget(renderTarget); } castSystem.PreDraw(); if (!hasEntityPredicate) { ExecuteForGroup(observableGroup, castSystem); } else { var groupPredicate = castSystem.Group as IHasPredicate; ExecuteForGroup(observableGroup.Where(groupPredicate.CanProcessEntity), castSystem); } castSystem.PostDraw(); if (renderTargetId >= 0) { _graphicsDevice.SetRenderTargets(currentRenderTargets); } }); _systemSubscriptions.Add(system, drawSubscription); }
public void SetupSystem(ISystem system) { var processEntityFunction = CreateEntityProcessorFunction(system); var entityChangeSubscriptions = new CompositeDisposable(); _systemSubscriptions.Add(system, entityChangeSubscriptions); var entitySubscriptions = new Dictionary <int, IDisposable>(); _entitySubscriptions.Add(system, entitySubscriptions); var groupSystem = system as IGroupSystem; var affinities = groupSystem.GetGroupAffinities(); var observableGroup = ObservableGroupManager.GetObservableGroup(groupSystem.Group, affinities); observableGroup.OnEntityAdded .Subscribe(x => { var subscription = processEntityFunction(x); entitySubscriptions.Add(x.Id, subscription); }) .AddTo(entityChangeSubscriptions); observableGroup.OnEntityRemoved .Subscribe(x => { entitySubscriptions.RemoveAndDispose(x.Id); }) .AddTo(entityChangeSubscriptions); foreach (var entity in observableGroup) { var subscription = processEntityFunction(entity); entitySubscriptions.Add(entity.Id, subscription); } }
public IObservableGroup GetPlayerGroup(IObservableGroupManager observableGroupManager) { return(observableGroupManager.GetObservableGroup(new Group(typeof(PlayerStateComponent)))); }