Example #1
0
        // Non-blocking; ticks ping state machine once
        //   3+ ticks required to do a full cycle (connect, send, receive + disconnect)
        void RunPingJob()
        {
            // Write stats from last job
            Stats.AddEntry(m_NumPings[0], m_LastPing[0]);

            // Disconnect if we exceeded our disconnect timeout
            if (m_ClientToServerConnection.Length > 0 &&
                m_ClientToServerConnection[0].IsCreated &&
                m_NumPings[0] == m_PendingPings[0].id &&
                Time.fixedTime - m_PendingPings[0].time > k_PingTimeoutMs)
            {
                Debug.Log($"Resetting connection to ping server due to ping timeout (time waiting for response > {k_PingTimeoutMs} ms).");
                m_ClientToServerConnection[0].Disconnect(m_ClientDriver);
                m_ClientToServerConnection[0] = default;
            }

            // Schedule driver update
            updateHandle = m_ClientDriver.ScheduleUpdate();

            var pingJob = new PingJob
            {
                driver       = m_ClientDriver,
                connection   = m_ClientToServerConnection,
                serverEp     = m_ServerEndpoint,
                pendingPings = m_PendingPings,
                numPings     = m_NumPings,
                lastPing     = m_LastPing
            };

            // Schedule an update chain with the driver update followed by the ping job
            updateHandle = pingJob.Schedule(updateHandle);

            JobHandle.ScheduleBatchedJobs();
        }
Example #2
0
    protected override JobHandle OnUpdate(JobHandle inputDep)
    {
        if (!m_DriverSystem.ClientDriver.IsCreated)
        {
            return(inputDep);
        }
        PingClientUIBehaviour.UpdateStats(m_pingStats[0], m_pingStats[1]);
        var pingJob = new PingJob
        {
            driver             = m_DriverSystem.ClientDriver,
            connections        = connectionList.connections,
            connectionEntities = connectionList.entities,
            serverEP           = PingClientUIBehaviour.ServerEndPoint,
            pendingPings       = m_pendingPings,
            pingStats          = m_pingStats,
            fixedTime          = Time.fixedTime,
            commandBuffer      = m_Barrier.CreateCommandBuffer()
        };

        return(pingJob.Schedule(inputDep));
    }
    void FixedUpdate()
    {
        // Wait for the previous frames ping to complete before starting a new one, the Complete in LateUpdate is not
        // enough since we can get multiple FixedUpdate per frame on slow clients
        m_updateHandle.Complete();

        // Update the ping client UI with the ping statistics computed by teh job scheduled previous frame since that
        // is now guaranteed to have completed
        PingClientUIBehaviour.UpdateStats(m_pingStats[0], m_pingStats[1]);
        var pingJob = new PingJob
        {
            driver       = m_ClientDriver,
            connection   = m_clientToServerConnection,
            serverEP     = PingClientUIBehaviour.ServerEndPoint,
            pendingPings = m_pendingPings,
            pingStats    = m_pingStats,
            fixedTime    = Time.fixedTime
        };

        // Schedule a chain with the driver update followed by the ping job
        m_updateHandle = m_ClientDriver.ScheduleUpdate();
        m_updateHandle = pingJob.Schedule(m_updateHandle);
    }
Example #4
0
    void FixedUpdate()
    {
        // Wait for the previous frames ping to complete before starting a new one, the Complete in LateUpdate is not
        // enough since we can get multiple FixedUpdate per frame on slow clients
        m_updateHandle.Complete();

        var serverEP = PingClientUIBehaviour.ServerEndPoint;

        // If the client ui indicates we should be sending pings but we do not have an active connection we create one
        if (serverEP.IsValid && !m_clientToServerConnection[0].IsCreated)
        {
            m_clientToServerConnection[0] = m_ClientDriver.Connect(serverEP);
        }
        // If the client ui indicates we should not be sending pings but we do have a connection we close that connection
        if (!serverEP.IsValid && m_clientToServerConnection[0].IsCreated)
        {
            m_clientToServerConnection[0].Disconnect(m_ClientDriver);
            m_clientToServerConnection[0] = default(NetworkConnection);
        }

        // Update the ping client UI with the ping statistics computed by teh job scheduled previous frame since that
        // is now guaranteed to have completed
        PingClientUIBehaviour.UpdateStats(m_pingStats[0], m_pingStats[1]);
        var pingJob = new PingJob
        {
            driver       = m_ClientDriver,
            connection   = m_clientToServerConnection,
            pendingPings = m_pendingPings,
            pingStats    = m_pingStats,
            fixedTime    = Time.fixedTime
        };

        // Schedule a chain with the driver update followed by the ping job
        m_updateHandle = m_ClientDriver.ScheduleUpdate();
        m_updateHandle = pingJob.Schedule(m_updateHandle);
    }