Beispiel #1
0
 // Use this for initialization
 void Start()
 {
     ins        = this;
     container  = transform;
     objects    = new GenericPool <ObjectItem>();
     components = new GenericPool <ObjectItem>();
 }
Beispiel #2
0
 protected override void Init()
 {
     _instance   = this;
     _tower1Pool = new GenericPool <BaseTower>(GetTowerPrefab(TowerType.Tower1), 5);
     _tower2Pool = new GenericPool <BaseTower>(GetTowerPrefab(TowerType.Tower2), 5);
     _tower3Pool = new GenericPool <BaseTower>(GetTowerPrefab(TowerType.Tower3), 5);
 }
Beispiel #3
0
        /// <summary>
        /// Creates a new <see cref="WritableMessageFragment"/> which represents a string.
        /// Fragments are created using an ObjectPool so they can be reused. Use <see cref="ReleaseFragment(MessageFragment)"/> to
        /// return the fragment or allow the Message to handle returning the fragment if it is part of <see cref="Fragments"/>.
        /// </summary>
        /// <param name="original">The source string.</param>
        /// <returns>A new fragment.</returns>
        public WritableMessageFragment CreateTextFragment(string original)
        {
            var frag = GenericPool <WritableMessageFragment> .Get();

            frag.Initialize(this, original);
            return(frag);
        }
Beispiel #4
0
        private IEnumerator Routine(GenericPool pool)
        {
            var remainder = count; // Remaining number of Flake to place
            var state     = true;

            while (state)
            {
                var batch = Random.Range(spawnRange.x, spawnRange.y);
                remainder -= batch;

                if (remainder <= 0) // If going into zero or negative, break out of the loop after last execution
                {
                    remainder = 0;
                    batch    -= remainder; // Correct the negative value

                    state = false;
                }

                for (var i = 0; i < batch; i++)
                {
                    var flake = pool.CastSingle <Flake>(); // A GenericPool allows to directly cast an Object request
                    flake.transform.position = new Vector2(Random.Range(rect.xMin, rect.xMax), rect.yMax);
                }

                yield return(new WaitForSeconds(Random.Range(delayRange.x, delayRange.y))); // Random wait for next placed batch
            }

            routine = null;
        }
Beispiel #5
0
        public override void Initiate()
        {
            shellPool = new ShellPool();
            shellPool.InitiatePool();

            PreSpawnShells(maxSheelCount);
        }
Beispiel #6
0
    public static GenericPool CreateNewPoolWithPrefab(PoolableObject _poolableObjectPrefab, Transform _parent, string _poolName = "Pool", string _poolObjName = "PoolObj", int _maxPoolSize = NoSizeLimit)
    {
        GenericPool pool = CreateNewPool(_parent, _poolName, _maxPoolSize);

        pool.SetPoolableObject(_poolableObjectPrefab, _poolObjName);
        return(pool);
    }
Beispiel #7
0
        /// <summary>
        /// Creates a <see cref="ReadOnlyMessageFragment"/> which represents string that should be preserved and not modified by any other pseudo methods.
        /// Fragments are created using an ObjectPool so they can be reused. Use <see cref="ReleaseFragment(MessageFragment)"/> to
        /// return the fragment or allow the Message to handle returning the fragment if it is part of <see cref="Fragments"/>.
        /// </summary>
        /// <param name="original">The source string.</param>
        /// <returns>A new fragment.</returns>
        public ReadOnlyMessageFragment CreateReadonlyTextFragment(string original)
        {
            var frag = GenericPool <ReadOnlyMessageFragment> .Get();

            frag.Initialize(this, original);
            return(frag);
        }
Beispiel #8
0
 private void Start()
 {
     audioSource = GetComponent <AudioSource>();
     anim        = GetComponentInChildren <Animator>();
     pool        = ProjectilePool.instance.pool;
     playerPhy   = GetComponent <PlayerController>();
 }
Beispiel #9
0
    public static GenericPool CreateNewPool <T>(Transform _parent, string _poolName = "Pool", string _poolObjName = "PoolObj", int _maxPoolSize = NoSizeLimit) where T : PoolableObject
    {
        GenericPool pool    = CreateNewPool(_parent, _poolName, _maxPoolSize);
        T           poolObj = GameObjectUtil.CreateInstance <T>(pool.transform, _poolObjName);

        pool.SetPoolableObject(poolObj, _poolObjName);
        return(pool);
    }
Beispiel #10
0
    public static GenericPool CreateNewPool(Transform _parent, string _poolName = "Pool", int _maxPoolSize = NoSizeLimit)
    {
        GenericPool pool = GameObjectUtil.CreateInstance <GenericPool>(_parent, _poolName);

        pool.maxPoolSize = _maxPoolSize;
        pool.InitializePool();
        return(pool);
    }
Beispiel #11
0
        /// <summary>
        /// Creates a new message to represent a piece of text.
        /// </summary>
        /// <param name="text">The source text.</param>
        /// <returns>A new Message instance.</returns>
        internal static Message CreateMessage(string text)
        {
            var message = GenericPool <Message> .Get();

            message.Fragments.Add(message.CreateTextFragment(text));
            message.Original = text;
            return(message);
        }
Beispiel #12
0
        protected virtual void InitializeCollectionsIfNecessary()
        {
            Teams     = Teams ?? new Dictionary <string, LobbyTeamUi>();
            TeamsPool = TeamsPool ?? new GenericPool <LobbyTeamUi>(TeamPrefab);

            Users     = Users ?? new Dictionary <string, LobbyUserUi>();
            UsersPool = UsersPool ?? new GenericPool <LobbyUserUi>(UserPrefab);
        }
Beispiel #13
0
        private SocketAsyncEventArgs CreateNewSocketAsyncEventArgs(GenericPool <SocketAsyncEventArgs> pool)
        {
            SocketAsyncEventArgs acceptEventArg = new SocketAsyncEventArgs();

            acceptEventArg.Completed += new EventHandler <SocketAsyncEventArgs>(AcceptEventArg_Completed);

            return(acceptEventArg);
        }
 protected override void Destroy()
 {
     loadTables.Clear();
     loadTablesOperation.Clear();
     m_PreloadTablesOperations.Clear();
     m_TableReferences.Clear();
     GenericPool <PreLoadTablesOperation <TTable, TEntry> > .Release(this);
 }
Beispiel #15
0
        internal void WriteAsyncLogEvents(ArraySegment <AsyncLogEventInfo> logEventInfos, AsyncContinuation continuation)
        {
            if (logEventInfos.Count == 0)
            {
                continuation(null);
            }
            else
            {
                AsyncLogEventInfo[] wrappedLogEventInfos = null;
                try
                {
                    Counter counter;

                    GenericPool <ContinueWhenAll> continuePool = null;
                    int remaining = logEventInfos.Count;

                    if (this.LoggingConfiguration.PoolingEnabled())
                    {
                        counter              = this.LoggingConfiguration.PoolFactory.Get <Counter>();
                        continuePool         = this.LoggingConfiguration.PoolFactory.Get <GenericPool <ContinueWhenAll>, ContinueWhenAll>();
                        wrappedLogEventInfos = this.LoggingConfiguration.PoolFactory.Get <AsyncLogEventInfoArrayPool, AsyncLogEventInfo[]>().Get(logEventInfos.Count);
                    }
                    else
                    {
                        wrappedLogEventInfos = new AsyncLogEventInfo[logEventInfos.Count];
                        counter = new Counter();
                    }

                    counter.Reset(remaining);

                    for (int i = 0; i < logEventInfos.Count; ++i)
                    {
                        AsyncContinuation originalContinuation = logEventInfos.Array[i].Continuation;

                        ContinueWhenAll cont;
                        if (continuePool != null)
                        {
                            cont = continuePool.Get();
                            cont.Reset(counter, originalContinuation, continuation);
                            wrappedLogEventInfos[i] = logEventInfos.Array[i].LogEvent.WithContinuation(cont.Delegate);
                        }
                        else
                        {
                            cont = new ContinueWhenAll();
                        }
                        cont.Reset(counter, originalContinuation, continuation);
                        wrappedLogEventInfos[i] = logEventInfos.Array[i].LogEvent.WithContinuation(cont.Delegate);
                    }

                    this.WriteAsyncLogEvents(new ArraySegment <AsyncLogEventInfo>(wrappedLogEventInfos, 0, logEventInfos.Count));
                }
                finally
                {
                    this.LoggingConfiguration.PutBack(wrappedLogEventInfos);
                }
            }
        }
Beispiel #16
0
        /// <inheritdoc cref="Message.CreateReadonlyTextFragment(string, int, int)"/>
        public ReadOnlyMessageFragment CreateReadonlyTextFragment(int start, int end)
        {
            var frag = GenericPool <ReadOnlyMessageFragment> .Get();

            var startIndex = m_StartIndex == -1 ? start : m_StartIndex + start;

            frag.Initialize(@Message, m_OriginalString, startIndex, end);
            return(frag);
        }
Beispiel #17
0
        public void Dispose()
        {
            if (disposed)
            {
                throw new ObjectDisposedException(ToString());
            }

            GenericPool <Flow> .Free(this);
        }
Beispiel #18
0
    public void Recycle(GameObject go)
    {
        GenericPool <T> pool = Find(go.name);

        if (pool != null)
        {
            pool.Recycle(go);
        }
    }
Beispiel #19
0
    protected virtual void Awake()
    {
        redApplePool    = GenericPool.Create(gameObject, spawns.Length * 2, redApple);
        goldenApplePool = GenericPool.Create(gameObject, spawns.Length, goldenApple);

        EventManager <GameStartEvent> .AddListener(this);

        EventManager <GameEndEvent> .AddListener(this);
    }
        public Executable GetExecutable(HiraComponentContainer target, IBlackboardComponent blackboard)
        {
            if (target is IContainsComponent <NavMeshAgent> navigableTarget && navigableTarget.Component != null)
            {
                return(GenericPool <StaticMoveToExecutable> .Retrieve().Init(navigableTarget.Component, blackboard, targetPosition, followTarget, speed, tolerance));
            }

            return(AutoFailExecutable.INSTANCE);
        }
        public Executable GetExecutable(HiraComponentContainer target, IBlackboardComponent blackboard)
        {
            if (target is IContainsComponent <AgentAnimator> animatedTarget)
            {
                return(GenericPool <KickExecutable> .Retrieve().Init(animatedTarget.Component));
            }

            return(AutoFailExecutable.INSTANCE);
        }
Beispiel #22
0
    private void Initialize()
    {
        bulletType = BulletType.Default;
        bulletPool = GenericPool.CreateNewPool(this.transform, "BulletPool");
        SetBulletPrefab(BulletType.Default);

        bulletSpawnTimer = Timer.InstantiateTimer(this.transform, "BulletTimer");
        bulletSpawnTimer.SetOnCompleteCallback(ShootBullet);
        bulletSpawnTimer.RunTimer(bulletSpawnPeriod, true);
    }
Beispiel #23
0
        public EnemySpawner(GenericPool <EnemyBase> _enemyPool, List <Transform> _spawnPos, Transform _enemyHolder, MonoBehaviour _mono, EnemyBase[] _enemies)
        {
            enemyPool   = _enemyPool;
            spawnPos    = _spawnPos;
            enemies     = _enemies;
            mono        = _mono;
            enemyHolder = _enemyHolder;

            PrespawnEnemies();
        }
Beispiel #24
0
        public TcpCommunicationService(IApplicationContext applicationContext, ILoggerService loggerService, IBufferManagerFactory bufferManagerFactory, IPacketsHandler packetsHandler, INodesResolutionService nodesResolutionService)
            : base(applicationContext, loggerService, bufferManagerFactory, packetsHandler, nodesResolutionService)
        {
            _acceptEventArgsPool = new GenericPool <SocketAsyncEventArgs>(10);

            for (Int32 i = 0; i < 10; i++)
            {
                _acceptEventArgsPool.Push(CreateNewSocketAsyncEventArgs(_acceptEventArgsPool));
            }
        }
Beispiel #25
0
        public static Flow New(GraphReference reference)
        {
            Ensure.That(nameof(reference)).IsNotNull(reference);

            var flow = GenericPool <Flow> .New(() => new Flow());;

            flow.stack = reference.ToStackPooled();

            return(flow);
        }
Beispiel #26
0
        internal void Release()
        {
            foreach (var f in Fragments)
            {
                ReleaseFragment(f);
            }
            Fragments.Clear();

            GenericPool <Message> .Release(this);
        }
Beispiel #27
0
 protected override void Init()
 {
     _terrainPool = new GenericPool<TerrainFragment>(_terrainPrefab, (uint)_startTerrainCount);
     bool genObjects = false;
     for(int i=1; i<=_startTerrainCount; i++)
     {
         GenerateTerrain(genObjects);
         genObjects = true;
     }
 }
Beispiel #28
0
        public static GenericPool <T> GetPool <T>() where T : class, new()
        {
            var type = typeof(T);

            if (!_pools.TryGetValue(type, out var pool))
            {
                pool = new GenericPool <T>(InitialSize);
                _pools.Add(type, pool);
            }
            return((GenericPool <T>)pool);
        }
            public void Clear()
            {
                Assert.IsNotNull(m_Requests);

                foreach (var pair in m_Requests)
                {
                    pair.Value.Clear();
                    GenericPool <Set> .Release(pair.Value);
                }
                m_Requests.Clear();
            }
Beispiel #30
0
 /// <summary>
 /// Returns a Fragment back to its ObjectPool so it can be used again.
 /// </summary>
 /// <param name="fragment"></param>
 public void ReleaseFragment(MessageFragment fragment)
 {
     if (fragment is WritableMessageFragment wmf)
     {
         GenericPool <WritableMessageFragment> .Release(wmf);
     }
     else if (fragment is ReadOnlyMessageFragment romf)
     {
         GenericPool <ReadOnlyMessageFragment> .Release(romf);
     }
 }
        public CullingItemFactory()
        {
            var shadowPool = new GenericPool <ShadowCullingHandler>();

            shadowPool.SetMeta(new ShadowCullingHandler(shadowPool.Reuse));
            _shadowPool = shadowPool;

            var probePool = new GenericPool <ProbeCullingHandler>();

            probePool.SetMeta(new ProbeCullingHandler(probePool.Reuse));
            _probePool = probePool;
        }
Beispiel #32
0
 public void AddSceneObject(BaseSceneObject sceneObject, GenericPool<BaseSceneObject> pool)
 {
     _sceneObjects.Add(new InstanceSceneObjects(sceneObject, pool));
 }
Beispiel #33
0
 public void InitPool()
 {
     SceneObjectPool = new GenericPool<BaseSceneObject>(SceneObjectPrefab, 5);
 }
Beispiel #34
0
 public InstanceSceneObjects(BaseSceneObject sceneObject, GenericPool<BaseSceneObject> pool)
 {
     SceneObject = sceneObject;
     Pool = pool;
 }
Beispiel #35
0
    void Awake()
    {
        _fireDelayTimer = new GameTimer(_fireDelay);

        _drawingTime = _gunAnimation["Gun Draw"].length;
        _drawingTimer = new GameTimer(_drawingTime);

        _bulletPool = GenericPool<Bullet>.CreatePool(_bulletPrefab, 30);

        _gunAnimation.Play("Gun Draw");
        _gunAnimation.Sample();
        _gunAnimation.Stop();
    }