using System.Threading;
using Fort23.Core;
using Fort23.UTool;
using Utility;

namespace CombatLibrary.CombatLibrary.CombatCore
{
    public class CombatListPool<T>: Singleton<CombatListPool<T>>
    {
        private  readonly CombatPool<BetterList<T>> s_ListPool = new CombatPool<BetterList<T>>();

        public CombatListPool()
        {
#if !COMBAT_SERVER
            EventManager.Instance.AddEventListener(CustomEventType.ClearList, ClearList);
#endif
        }

        private void ClearList(IEventData iEventData)
        {
#if !COMBAT_SERVER
            s_ListPool.Clear();
#endif
        }


        public  BetterList<T> Get()
        {
      
                BetterList<T> betterList = s_ListPool.Get();
                betterList.isNotPool = false;
                if (betterList.tranId != 0)
                {
                    LogTool.Error("线程冲突");
                }
                betterList.tranId = Thread.CurrentThread.ManagedThreadId;
                return betterList;
            
        }

        public  void Recycle(BetterList<T> toRelease)
        {
   
                toRelease.tranId = 0;
                toRelease.Clear();
                s_ListPool.Recycle(toRelease);
            
        }
    }
}