예제 #1
0
파일: World.cs 프로젝트: PushoN/ecs
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
 public static void Recycle <T>(ref T system) where T : class, ISystemBase
 {
     PoolSystems.Recycle(system);
     system = null;
 }