Beispiel #1
0
    public static void OnPingBack(long t)
    {
        long curr = MonoTool.GetTimeStamp();
        long dt   = (curr - t) / 2;

        if (m_PingCount <= m_LastPingTimeOfLoop)
        {
            if (m_PingCount < m_PingTimes.Count)
            {
                m_PingTimes[m_PingCount] = dt;
            }
            else
            {
                m_PingTimes.Add(dt);
            }
            m_PingCount++;
        }
        else
        {
            m_LastPingTimeOfLoop = curr;
            m_PingCount          = 0;
            JiSuanPing();
            if (m_PingChangeCall != null)
            {
                m_PingChangeCall(m_PingValue);
            }
        }
        m_PingBack = true;
        m_bDrop    = false;
        m_SendPing = false;
    }
Beispiel #2
0
    public static void Update()
    {
        if (!m_OpenPing)
        {
            return;
        }
        float dt    = UnityEngine.Time.deltaTime;
        long  mmsec = (long)(dt * 1000);
        long  curr  = MonoTool.GetTimeStamp();

        if (m_SendPing)
        {
            if (!m_PingBack)
            {
                m_PingBackPastTime += mmsec;
                if (m_PingBackPastTime >= m_PingBackWaitTime)
                {
                    m_bDrop = true;
                }

                return;
            }
        }
        else
        {
            if (curr - m_LastPingTimeOfLoop > m_PingIntervalOfLoop)
            {
                if (m_PingPastTime >= m_PingInterval)
                {
                    MonoMessage.ReqHeart(curr);
                    m_PingPastTime     = 0;
                    m_PingBack         = false;
                    m_SendPing         = true;
                    m_PingBackPastTime = 0;
                    m_bDrop            = false;
                }
                else
                {
                    m_PingPastTime += mmsec;
                }
            }
        }
    }