Ejemplo n.º 1
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

        DriverUpdateJob updateJob = new DriverUpdateJob {
            driver      = m_ServerDriver,
            connections = m_connections,
            serverState = serverController.CurrentState
        };

        // Update the driver should be the first job in the chain
        jobHandler.ScheduleDriverUpdate(m_ServerDriver);
        // The DriverUpdateJob which accepts new connections should be the second job in the chain, it needs to depend
        // on the driver update job
        jobHandler.QueueJob(updateJob);
        // PongJob uses IJobParallelForDeferExtensions, we *must* schedule with a list as first parameter rather than
        // an int since the job needs to pick up new connections from DriverUpdateJob
        // The PongJob is the last job in the chain and it must depends on the DriverUpdateJob

        jobHandler.ScheduleJobsInQueue();

        jobHandler.Complete();

        for (int i = 0; i < m_connections.Length; i++)
        {
            pcc.StartProcessCoroutine(m_connections[i]);
            m_connections[i] = pcc.connection;
        }
    }
Ejemplo n.º 2
0
        void WaitForNetworkUpdate()
        {
            // The DriverUpdateJob which accepts new connections should be the second job in the chain,
            //  it needs to depend on the driver update job
            var updateJob = new DriverUpdateJob
            {
                driver      = m_ServerDriver,
                connections = m_Connections
            };

            // Update the driver should be the first job in the chain
            m_UpdateHandle = m_ServerDriver.ScheduleUpdate(m_UpdateHandle);
            m_UpdateHandle = updateJob.Schedule(m_UpdateHandle);

            // Wait for the job to complete
            m_UpdateHandle.Complete();
        }
Ejemplo n.º 3
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();
        // If there is at least one client connected update the activity so the server is not shutdown
        if (m_connections.Length > 0)
        {
            DedicatedServerConfig.UpdateLastActivity();
        }
        var updateJob = new DriverUpdateJob {
            driver = m_ServerDriver, connections = m_connections
        };
        var pongJob = new PongJob
        {
            // PongJob is a ParallelFor job, it must use the concurrent NetworkDriver
            driver = m_ServerDriver.ToConcurrent(),
            // PongJob uses IJobParallelForDeferExtensions, we *must* use ToDeferredJobArray in order to access the
            // list from the job
#if ENABLE_IL2CPP
            // IJobParallelForDeferExtensions is not working correctly with IL2CPP
            connections = m_connections
#else
            connections = m_connections.ToDeferredJobArray()
#endif
        };

        // Update the driver should be the first job in the chain
        m_updateHandle = m_ServerDriver.ScheduleUpdate();
        // The DriverUpdateJob which accepts new connections should be the second job in the chain, it needs to depend
        // on the driver update job
        m_updateHandle = updateJob.Schedule(m_updateHandle);
        // PongJob uses IJobParallelForDeferExtensions, we *must* schedule with a list as first parameter rather than
        // an int since the job needs to pick up new connections from DriverUpdateJob
        // The PongJob is the last job in the chain and it must depends on the DriverUpdateJob
#if ENABLE_IL2CPP
        m_updateHandle = pongJob.Schedule(m_updateHandle);
#else
        m_updateHandle = pongJob.Schedule(m_connections, 1, m_updateHandle);
#endif
    }
}