浏览代码

Merge of the "resetting event queue" fix branch

/main/staging
nathaniel.buck@unity3d.com 3 年前
当前提交
3638cb6a
共有 2 个文件被更改,包括 10 次插入13 次删除
  1. 19
      Assets/Scripts/Relay/RelayUtpClient.cs
  2. 4
      Assets/Scripts/Relay/RelayUtpHost.cs

19
Assets/Scripts/Relay/RelayUtpClient.cs


{
if (m_connections.Count == 0) // This could be the case for the host alone in the lobby.
return;
m_networkDriver.ScheduleUpdate().Complete();
foreach (NetworkConnection conn in m_connections)
DoUserUpdate(m_networkDriver, conn, m_localUser);
}

protected virtual void OnUpdate()
{
m_networkDriver.ScheduleUpdate().Complete(); // This pumps all messages, which pings the Relay allocation and keeps it alive.
ReceiveNetworkEvents(m_networkDriver, m_connections);
if (!m_hasSentInitialMessage)
ReceiveNetworkEvents(m_networkDriver); // Just on the first execution, make sure to handle any events that accumulated while completing the connection.
m_networkDriver.ScheduleUpdate().Complete(); // This pumps all messages, which pings the Relay allocation and keeps it alive. It should be called no more often than ReceiveNetworkEvents.
ReceiveNetworkEvents(m_networkDriver); // This reads the message queue which was just updated.
SendInitialMessage(m_networkDriver, m_connections[0]);
SendInitialMessage(m_networkDriver, m_connections[0]); // On a client, the 0th (and only) connection is to the host.
private void ReceiveNetworkEvents(NetworkDriver driver, List<NetworkConnection> connections)
private void ReceiveNetworkEvents(NetworkDriver driver)
NetworkConnection conn;
foreach (NetworkConnection connection in connections)
while ((cmd = driver.PopEvent(out conn, out strm)) != NetworkEvent.Type.Empty) // NetworkConnection also has PopEvent, but NetworkDriver.PopEvent automatically includes new connections.
while ((cmd = connection.PopEvent(driver, out strm)) != NetworkEvent.Type.Empty)
{
ProcessNetworkEvent(connection, strm, cmd);
}
ProcessNetworkEvent(conn, strm, cmd);
}
}

4
Assets/Scripts/Relay/RelayUtpHost.cs


/// </summary>
private void DoHeartbeat()
{
m_networkDriver.ScheduleUpdate().Complete();
for (int c = m_connections.Count - 1; c >= 0; c--)
{
if (!m_connections[c].IsCreated)

{
var conn = m_networkDriver.Accept();
var conn = m_networkDriver.Accept(); // Note that since we pumped the event queue earlier in Update, m_networkDriver has been updated already this frame.
if (!conn.IsCreated) // "Nothing more to accept" is signalled by returning an invalid connection from Accept.
break;
m_connections.Add(conn);

正在加载...
取消
保存