Ejemplo n.º 1
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// 创建Timer
        /// </summary>
        /// <param name="nTimerID"></param>
        /// <param name="nIntervalTime"></param>
        /// <param name="del"></param>
        /// <param name="nCallTime"></param>
        public void CreateTimer(uint uTimerID, uint uIntervalTime, DelITimerHander del, uint uCallTime = 0xffffffff, string strInfo = "")
        {
            if (null == del)
            {
                return;
            }

            if (uIntervalTime == 0)
            {
                uIntervalTime = 1;
            }

            //Debug.Log("CTimerSystem::CreateTimer del.GetHashCode() = " + del.GetHashCode());

            int         nHashCode  = del.GetHashCode();
            List <uint> singleList = null;

            if (m_TimerDict.TryGetValue(nHashCode, out singleList))
            {
                bool isExists = singleList.Exists(delegate(uint p) { return(p == uTimerID); });
                if (isExists)
                {
                    return;
                }
                singleList.Add(uTimerID);
            }
            else
            {
                singleList = new List <uint>();
                singleList.Add(uTimerID);
                m_TimerDict.Add(nHashCode, singleList);
            }

            CTimerHandle sTimerHandle = new CTimerHandle();

            sTimerHandle.m_Handle          = del;
            sTimerHandle.m_unTimerID       = uTimerID;
            sTimerHandle.m_unCallTimes     = uCallTime;
            sTimerHandle.m_unIntervalTime  = uIntervalTime;
            sTimerHandle.m_unLastCallTick  = m_unLastCheckTick;
            sTimerHandle.m_nHandleHashCode = nHashCode;
            if (!string.IsNullOrEmpty(strInfo))
            {
                sTimerHandle.m_strDebugInfo = strInfo;
            }
            sTimerHandle.m_unTimerGridIndex =
                ((sTimerHandle.m_unLastCallTick + sTimerHandle.m_unIntervalTime - m_unInitializeTime) / gs_DEFAULT_TIME_GRID) % m_unTimerAxisSize;

            List <CTimerHandle> axisList = null;

            if (!m_TimerAxis.TryGetValue(sTimerHandle.m_unTimerGridIndex, out axisList))
            {
                axisList = new List <CTimerHandle>();
                m_TimerAxis.Add(sTimerHandle.m_unTimerGridIndex, axisList);
            }
            if (null != axisList)
            {
                axisList.Add(sTimerHandle);
            }
        }
Ejemplo n.º 2
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// 消除Timer
        /// </summary>
        /// <param name="nTimerID"></param>
        /// <param name="del"></param>
        public void DestroyTimer(uint uTimerID, DelITimerHander del)
        {
            if (null == del)
            {
                return;
            }

            //Debug.Log("CTimerSystem::DestroyTimer del.GetHashCode() = " + del.GetHashCode());

            int         nHashCode  = del.GetHashCode();
            List <uint> singleList = null;

            if (m_TimerDict.TryGetValue(nHashCode, out singleList))
            {
                bool isExists = singleList.Exists(delegate(uint p) { return(p == uTimerID); });
                if (!isExists)
                {
                    return;
                }
            }

            if (null == singleList)
            {
                return;
            }

            singleList.Remove(uTimerID);

            if (0 == singleList.Count)
            {
                m_TimerDict.Remove(nHashCode);
            }
        }
Ejemplo n.º 3
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// 创建Timer
        /// </summary>
        /// <param name="nTimerID"></param>
        /// <param name="nIntervalTime"></param>
        /// <param name="del"></param>
        /// <param name="nCallTime"></param>
        public void CreateTimer(uint uTimerID, uint uIntervalTime, DelITimerHander del, uint uCallTime = 0xffffffff, string strInfo = "")
        {
            if (null == del)
            {
                return;
            }

            if( uIntervalTime == 0 )
                uIntervalTime = 1;

            Debug.Log("CTimerSystem::CreateTimer del.GetHashCode() = " + del.GetHashCode());

            int nHashCode = del.GetHashCode();
            List<uint> singleList = null;
            if (m_TimerDict.TryGetValue(nHashCode,out singleList))
            {
                bool isExists = singleList.Exists(delegate(uint p) { return p == uTimerID; });
                if (isExists)
                {
                    return;
                }
                singleList.Add(uTimerID);
            }
            else
            {
                singleList = new List<uint>();
                singleList.Add(uTimerID);
                m_TimerDict.Add(nHashCode, singleList);
            }

            CTimerHandle sTimerHandle = new CTimerHandle();
            sTimerHandle.m_Handle = del;
            sTimerHandle.m_unTimerID = uTimerID;
            sTimerHandle.m_unCallTimes = uCallTime;
            sTimerHandle.m_unIntervalTime = uIntervalTime;
            sTimerHandle.m_unLastCallTick = m_unLastCheckTick;
            sTimerHandle.m_nHandleHashCode = nHashCode;
            if (!string.IsNullOrEmpty(strInfo))
            {
                sTimerHandle.m_strDebugInfo = strInfo;
            }
            sTimerHandle.m_unTimerGridIndex =
                ((sTimerHandle.m_unLastCallTick + sTimerHandle.m_unIntervalTime - m_unInitializeTime) / gs_DEFAULT_TIME_GRID) % m_unTimerAxisSize;

            List<CTimerHandle> axisList = null;
            if (!m_TimerAxis.TryGetValue(sTimerHandle.m_unTimerGridIndex,out axisList))
            {
                axisList = new List<CTimerHandle>();
                m_TimerAxis.Add(sTimerHandle.m_unTimerGridIndex, axisList);
            }
            if (null != axisList)
            {
                axisList.Add(sTimerHandle);
            }
        }
Ejemplo n.º 4
0
        public string m_strDebugInfo;      // 描述信息
        //-------------------------------------------------------------------------
        #endregion


        #region Public Method
        //-------------------------------------------------------------------------
        public CTimerHandle()
        {
            m_Handle           = null;
            m_nHandleHashCode  = 0;
            m_unTimerID        = 0;
            m_unIntervalTime   = 0;
            m_unCallTimes      = 0;
            m_unLastCallTick   = 0;
            m_unTimerGridIndex = 0;
            m_strDebugInfo     = null;
        }
Ejemplo n.º 5
0
        public uint m_unTimerID; // 用户自定义定时器ID

        #endregion Fields

        #region Constructors

        //-------------------------------------------------------------------------
        public CTimerHandle()
        {
            m_Handle = null;
            m_nHandleHashCode = 0;
            m_unTimerID = 0;
            m_unIntervalTime = 0;
            m_unCallTimes = 0;
            m_unLastCallTick = 0;
            m_unTimerGridIndex = 0;
            m_strDebugInfo = null;
        }
Ejemplo n.º 6
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// 消除Timer
        /// </summary>
        /// <param name="nTimerID"></param>
        /// <param name="del"></param>
        public void DestroyTimer(uint uTimerID, DelITimerHander del)
        {
            if (null == del)
            {
                return;
            }

            Debug.Log("CTimerSystem::DestroyTimer del.GetHashCode() = " + del.GetHashCode());

            int nHashCode = del.GetHashCode();
            List<uint> singleList = null;
            if (m_TimerDict.TryGetValue(nHashCode, out singleList))
            {
                bool isExists = singleList.Exists(delegate(uint p) { return p == uTimerID; });
                if (!isExists)
                {
                    return;
                }

            }

            if (null == singleList)
            {
                return;
            }

            singleList.Remove(uTimerID);

            if (0 == singleList.Count)
            {
                m_TimerDict.Remove(nHashCode);
            }
        }