Esempio n. 1
0
        private static int AddToimeout(Delegate a, float delay, params object[] args)
        {
            if (delay <= 0.001)
            {
                if (a == null)
                {
                    return(0);
                }
                try{
                    if (args == null)
                    {
                        a.DynamicInvoke();
                    }
                    else
                    {
                        a.DynamicInvoke(args);
                    }
                }
                catch {
                    //TopTip.addTip(a.Method.Name + "执行出错");
                }
                return(0);
            }
            delayIDKey++;
            CacheTimeout ct = new CacheTimeout();

            ct.isAdd   = true;
            ct.key     = delayIDKey;
            ct.action  = a;
            ct.endTime = Time.time + delay;
            ct.args    = args;
            timeoutCache.Add(ct);
            return(delayIDKey);
        }
Esempio n. 2
0
        private static void OnTimeoutLoop()
        {
            IEnumerator enumerator = timeoutDict.Values.GetEnumerator();
            float       now        = Time.time;

            while (enumerator.MoveNext())
            {
                CacheTimeout ct = (CacheTimeout)enumerator.Current;
                if (now >= ct.endTime)
                {
                    try{
                        if (ct.args == null)
                        {
                            ct.action.DynamicInvoke();
                        }
                        else
                        {
                            ct.action.DynamicInvoke(ct.args);
                        }
                    }
                    catch {
                        //TopTip.addTip(ct.action.Method.Name + "执行出错");
                    }
                    ct.isAdd = false;
                    timeoutCache.Add(ct);
                }
            }
        }
Esempio n. 3
0
        public static void ClearTimeout(int key)
        {
            CacheTimeout ct = new CacheTimeout();

            ct.key   = key;
            ct.isAdd = false;
            timeoutCache.Add(ct);
        }
Esempio n. 4
0
 private void Ontimeout(object o)
 {
     Age = _stopwatch.ElapsedMilliseconds;
     CacheTimeout?.Invoke(this, new EventArgs());
     _ageTimer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
 }
Esempio n. 5
0
 public CacheAttribute(CacheLevel cacheLevel, CacheTimeout timeout)
 {
     CacheTimeout = (int)timeout;
     CacheLevel   = cacheLevel;
 }
Esempio n. 6
0
        public static void FrameLoop()
        {
            if (frameCache.Count > 0)
            {
                for (int i = 0; i < frameCache.Count; i++)
                {
                    CacheAction c = frameCache[i];
                    if (c.isAdd == true)
                    {
                        if (frameDict.ContainsKey(c.key) == false)
                        {
                            frameDict.Add(c.key, c.action);
                        }
                    }
                    else
                    {
                        if (frameDict.ContainsKey(c.key) == true)
                        {
                            frameDict.Remove(c.key);
                        }
                    }
                }
                frameCache.Clear();
            }
            IEnumerator enumerator = frameDict.Values.GetEnumerator();

            while (enumerator.MoveNext())
            {
                Action a = enumerator.Current as Action;
                try {
                    if (a != null)
                    {
                        a.DynamicInvoke();
                    }
                } catch (Exception e) {
                    throw (e);
                }
            }

            /////以上处理帧循环函数,以下预更新timer和second字典/////////
            if (timerCache.Count > 0)
            {
                for (int i = 0; i < timerCache.Count; i++)
                {
                    CacheAction c = timerCache[i];
                    if (c.isAdd == true)
                    {
                        if (timerDict.ContainsKey(c.key) == false)
                        {
                            timerDict.Add(c.key, c.action);
                        }
                    }
                    else
                    {
                        if (timerDict.ContainsKey(c.key) == true)
                        {
                            timerDict.Remove(c.key);
                        }
                    }
                }
                timerCache.Clear();
            }
            //////////////////
            if (secondCache.Count > 0)
            {
                for (int i = 0; i < secondCache.Count; i++)
                {
                    CacheAction c = secondCache[i];
                    if (c.isAdd == true)
                    {
                        if (secondDict.ContainsKey(c.key) == false)
                        {
                            secondDict.Add(c.key, c.action);
                        }
                    }
                    else
                    {
                        if (secondDict.ContainsKey(c.key) == true)
                        {
                            secondDict.Remove(c.key);
                        }
                    }
                }
                secondCache.Clear();
            }
            //////////////////////////
            if (timeoutCache.Count > 0)
            {
                for (int i = 0; i < timeoutCache.Count; i++)
                {
                    CacheTimeout c = timeoutCache[i];
                    if (c.isAdd == true)
                    {
                        if (timeoutDict.ContainsKey(c.key) == false)
                        {
                            timeoutDict.Add(c.key, c);
                        }
                    }
                    else
                    {
                        if (timeoutDict.ContainsKey(c.key) == true)
                        {
                            timeoutDict.Remove(c.key);
                        }
                    }
                }
                timeoutCache.Clear();
            }
            ///////////以下时间到了执行timer和second函数字典////////////////
            float now = Time.time;

            if (now - timerLastTime > 0.08f)
            {
                timerLastTime = now;
                OnTimerLoop();
                OnTimeoutLoop();
            }
            if (now - secondLastTime > 1)
            {
                secondLastTime = now;
                OnSecondLoop();
            }
        }
Esempio n. 7
0
 public static void SetDefaultCacheTimeout(CacheTimeout timeout)
 {
     DefaultCacheTimeout = (int)timeout;
 }
Esempio n. 8
0
 public CacheAttribute(CacheLevel cacheLevel, CacheTimeout timeout)
 {
     CacheTimeout = (int)timeout;
     CacheLevel = cacheLevel;
 }
Esempio n. 9
0
 public static void SetDefaultCacheTimeout(CacheTimeout timeout)
 {
     DefaultCacheTimeout = (int)timeout;
 }