void IPoolableRecycle.OnRecycle() { this.ReleaseState(ref this.resetState); this.ReleaseState(ref this.currentState); for (int i = 0; i < this.systems.Count; ++i) { this.systems[i].OnDeconstruct(); PoolSystems.Recycle(this.systems[i]); } PoolList <ISystem <TState> > .Recycle(ref this.systems); for (int i = 0; i < this.modules.Count; ++i) { this.modules[i].OnDeconstruct(); PoolModules.Recycle(this.modules[i]); } PoolList <IModule <TState> > .Recycle(ref this.modules); PoolDictionary <int, IList> .Recycle(ref this.entitiesCache); //PoolDictionary<EntityId, IEntity>.Recycle(ref this.entitiesDirectCache); PoolDictionary <int, IList> .Recycle(ref this.filtersCache); PoolDictionary <int, IComponents> .Recycle(ref this.componentsCache); PoolDictionary <int, int> .Recycle(ref this.capacityCache); }
internal void Deconstruct() { for (int i = 0; i < this.systems.Count; ++i) { this.systems.arr[i].OnDeconstruct(); if (this.systems.arr[i] is ISystemFilter systemFilter) { systemFilter.filter = null; } PoolSystems.Recycle(this.systems.arr[i]); } PoolArray <ISystemBase> .Recycle(ref this.systems); PoolArray <ModuleState> .Recycle(ref this.statesSystems); }
/// <summary> /// Add system by type /// Retrieve system from pool, OnConstruct() call /// </summary> /// <typeparam name="TSystem"></typeparam> public bool AddSystem <TSystem>() where TSystem : class, ISystemBase, new() { if (this.world == null) { SystemGroupRegistryException.Throw(); } var instance = PoolSystems.Spawn <TSystem>(); if (this.AddSystem(instance) == false) { instance.world = null; PoolSystems.Recycle(ref instance); return(false); } return(true); }
public static void Recycle <T>(ref T system) where T : class, ISystemBase { PoolSystems.Recycle(system); system = null; }