コード例 #1
0
    public static void Free(IPool _object)
    {
        if (_object == null)
        {
            return;
        }

        ObjectPool objectPool;
        Type       type = _object.GetType();

        if (!poolDict.TryGetValue(type, out objectPool))
        {
            objectPool             = new ObjectPool();
            objectPool.capacity    = defaultCapacity;
            objectPool.objectQueue = new Queue <IPool>();
            poolDict.Add(type, objectPool);
        }

        if (objectPool.objectQueue.Count < objectPool.capacity && !_object.GetInPool())
        {
            objectPool.objectQueue.Enqueue(_object);
            _object.Recycle();
            _object.SetInPool(true);
        }
        else
        {
            _object.OnDestroy();
        }
    }
コード例 #2
0
        /// <summary>
        /// remove a pool, all inactive objects are destroyed,
        /// </summary>
        public void Remove(string name)
        {
            Dbg.Assert(m_poolCont.ContainsKey(name), "PoolMgr.Remove: poolName {0} not regiestered", name);

            IPool pool = m_poolCont[name];

            m_poolCont.Remove(name);
            pool.OnDestroy(); //destroy not-in-use object
        }
コード例 #3
0
        /// <summary>
        /// remove a pool, all inactive objects are destroyed,
        /// </summary>
        public void RemoveTypePool(RuntimeTypeHandle tp)
        {
            Dbg.Assert(m_TypePoolCont.ContainsKey(tp), "PoolMgr.RemoveTypePool: type {0} not regiestered", tp);

            IPool pool = m_TypePoolCont[tp];

            m_TypePoolCont.Remove(tp);
            pool.OnDestroy(); //destroy not-in-use object
        }
コード例 #4
0
ファイル: ObjectPool.cs プロジェクト: Enanyy/LuaGame-slua
    public static void Clear()
    {
        var it = mPoolDic.GetEnumerator();

        while (it.MoveNext())
        {
            var queue = it.Current.Value;
            while (queue.Count > 0)
            {
                IPool o = queue.Dequeue();
                o.isPool = false;
                o.OnDestroy();
            }
        }
        mPoolDic.Clear();
    }
コード例 #5
0
ファイル: ObjectPool.cs プロジェクト: Enanyy/LuaGame-slua
    public static void Clear(Type type, bool includeSubClass = false)
    {
        if (includeSubClass)
        {
            var         it   = mPoolDic.GetEnumerator();
            List <Type> list = new List <Type>();
            while (it.MoveNext())
            {
                if (it.Current.Key.IsSubclassOf(type))
                {
                    list.Add(type);
                    var queue = it.Current.Value;
                    while (queue.Count > 0)
                    {
                        IPool o = queue.Dequeue();
                        o.OnDestroy();
                    }
                }
            }
            for (int i = 0; i < list.Count; ++i)
            {
                mPoolDic.Remove(list[i]);
            }
        }

        if (mPoolDic.ContainsKey(type))
        {
            var queue = mPoolDic[type];
            while (queue.Count > 0)
            {
                IPool o = queue.Dequeue();
                o.OnDestroy();
            }
            mPoolDic.Remove(type);
        }
    }