using System; using EcsRx.Components; using EcsRx.Components.Database; using EcsRx.Components.Lookups; using EcsRx.Extensions; using EcsRx.Groups.Observable; using EcsRx.MicroRx.Disposables; using EcsRx.MicroRx.Extensions; using EcsRx.Plugins.Batching.Batches; using EcsRx.Plugins.Batching.Builders; namespace EcsRx.Plugins.Batching.Accessors { public class ReferenceBatchAccessor : BatchAccessor, IReferenceBatchAccessor where T1 : class, IComponent where T2 : class, IComponent { public ReferenceBatch[] Batch { get; private set; } public ReferenceBatchAccessor(IObservableGroup observableGroup, IComponentDatabase componentDatabase, IBatchBuilder batchBuilder, IComponentTypeLookup componentTypeLookup) : base(observableGroup, componentDatabase, batchBuilder, componentTypeLookup) { } protected override IDisposable ReactToPools() { var componentType1 = ComponentTypeLookup.GetComponentType(typeof(T1)); var componentType2 = ComponentTypeLookup.GetComponentType(typeof(T2)); var pool1 = ComponentDatabase.GetPoolFor(componentType1); var pool2 = ComponentDatabase.GetPoolFor(componentType2); var subscriptions = new CompositeDisposable(); pool1.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool2.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); return subscriptions; } public override void Refresh() { Batch = ((IReferenceBatchBuilder) BatchBuilder).Build(ObservableGroup); } } public class ReferenceBatchAccessor : BatchAccessor, IReferenceBatchAccessor where T1 : class, IComponent where T2 : class, IComponent where T3 : class, IComponent { public ReferenceBatch[] Batch { get; private set; } public ReferenceBatchAccessor(IObservableGroup observableGroup, IComponentDatabase componentDatabase, IBatchBuilder batchBuilder, IComponentTypeLookup componentTypeLookup) : base(observableGroup, componentDatabase, batchBuilder, componentTypeLookup) { } protected override IDisposable ReactToPools() { var componentType1 = ComponentTypeLookup.GetComponentType(typeof(T1)); var componentType2 = ComponentTypeLookup.GetComponentType(typeof(T2)); var componentType3 = ComponentTypeLookup.GetComponentType(typeof(T3)); var pool1 = ComponentDatabase.GetPoolFor(componentType1); var pool2 = ComponentDatabase.GetPoolFor(componentType2); var pool3 = ComponentDatabase.GetPoolFor(componentType3); var subscriptions = new CompositeDisposable(); pool1.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool2.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool3.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); return subscriptions; } public override void Refresh() { Batch = ((IReferenceBatchBuilder) BatchBuilder).Build(ObservableGroup); } } public class ReferenceBatchAccessor : BatchAccessor, IReferenceBatchAccessor where T1 : class, IComponent where T2 : class, IComponent where T3 : class, IComponent where T4 : class, IComponent { public ReferenceBatch[] Batch { get; private set; } public ReferenceBatchAccessor(IObservableGroup observableGroup, IComponentDatabase componentDatabase, IBatchBuilder batchBuilder, IComponentTypeLookup componentTypeLookup) : base(observableGroup, componentDatabase, batchBuilder, componentTypeLookup) { } protected override IDisposable ReactToPools() { var componentType1 = ComponentTypeLookup.GetComponentType(typeof(T1)); var componentType2 = ComponentTypeLookup.GetComponentType(typeof(T2)); var componentType3 = ComponentTypeLookup.GetComponentType(typeof(T3)); var componentType4 = ComponentTypeLookup.GetComponentType(typeof(T4)); var pool1 = ComponentDatabase.GetPoolFor(componentType1); var pool2 = ComponentDatabase.GetPoolFor(componentType2); var pool3 = ComponentDatabase.GetPoolFor(componentType3); var pool4 = ComponentDatabase.GetPoolFor(componentType4); var subscriptions = new CompositeDisposable(); pool1.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool2.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool3.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool4.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); return subscriptions; } public override void Refresh() { Batch = ((IReferenceBatchBuilder) BatchBuilder).Build(ObservableGroup); } } public class ReferenceBatchAccessor : BatchAccessor, IReferenceBatchAccessor where T1 : class, IComponent where T2 : class, IComponent where T3 : class, IComponent where T4 : class, IComponent where T5 : class, IComponent { public ReferenceBatch[] Batch { get; private set; } public ReferenceBatchAccessor(IObservableGroup observableGroup, IComponentDatabase componentDatabase, IBatchBuilder batchBuilder, IComponentTypeLookup componentTypeLookup) : base(observableGroup, componentDatabase, batchBuilder, componentTypeLookup) { } protected override IDisposable ReactToPools() { var componentType1 = ComponentTypeLookup.GetComponentType(typeof(T1)); var componentType2 = ComponentTypeLookup.GetComponentType(typeof(T2)); var componentType3 = ComponentTypeLookup.GetComponentType(typeof(T3)); var componentType4 = ComponentTypeLookup.GetComponentType(typeof(T4)); var componentType5 = ComponentTypeLookup.GetComponentType(typeof(T5)); var pool1 = ComponentDatabase.GetPoolFor(componentType1); var pool2 = ComponentDatabase.GetPoolFor(componentType2); var pool3 = ComponentDatabase.GetPoolFor(componentType3); var pool4 = ComponentDatabase.GetPoolFor(componentType4); var pool5 = ComponentDatabase.GetPoolFor(componentType5); var subscriptions = new CompositeDisposable(); pool1.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool2.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool3.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool4.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool5.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); return subscriptions; } public override void Refresh() { Batch = ((IReferenceBatchBuilder) BatchBuilder).Build(ObservableGroup); } } public class ReferenceBatchAccessor : BatchAccessor, IReferenceBatchAccessor where T1 : class, IComponent where T2 : class, IComponent where T3 : class, IComponent where T4 : class, IComponent where T5 : class, IComponent where T6 : class, IComponent { public ReferenceBatch[] Batch { get; private set; } public ReferenceBatchAccessor(IObservableGroup observableGroup, IComponentDatabase componentDatabase, IBatchBuilder batchBuilder, IComponentTypeLookup componentTypeLookup) : base(observableGroup, componentDatabase, batchBuilder, componentTypeLookup) { } protected override IDisposable ReactToPools() { var componentType1 = ComponentTypeLookup.GetComponentType(typeof(T1)); var componentType2 = ComponentTypeLookup.GetComponentType(typeof(T2)); var componentType3 = ComponentTypeLookup.GetComponentType(typeof(T3)); var componentType4 = ComponentTypeLookup.GetComponentType(typeof(T4)); var componentType5 = ComponentTypeLookup.GetComponentType(typeof(T5)); var componentType6 = ComponentTypeLookup.GetComponentType(typeof(T6)); var pool1 = ComponentDatabase.GetPoolFor(componentType1); var pool2 = ComponentDatabase.GetPoolFor(componentType2); var pool3 = ComponentDatabase.GetPoolFor(componentType3); var pool4 = ComponentDatabase.GetPoolFor(componentType4); var pool5 = ComponentDatabase.GetPoolFor(componentType5); var pool6 = ComponentDatabase.GetPoolFor(componentType6); var subscriptions = new CompositeDisposable(); pool1.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool2.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool3.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool4.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool5.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); pool6.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions); return subscriptions; } public override void Refresh() { Batch = ((IReferenceBatchBuilder) BatchBuilder).Build(ObservableGroup); } } }