浏览代码

Caching side channel data for one step (#3565)

* Caching side channel data for one step

* [skip ci] Update com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs

Co-Authored-By: Chris Elion <chris.elion@unity3d.com>

Co-authored-by: Chris Elion <celion@gmail.com>
/bug-failed-api-check
GitHub 4 年前
当前提交
529214e7
共有 1 个文件被更改,包括 31 次插入3 次删除
  1. 34
      com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs

34
com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs


}
}
private struct CachedSideChannelMessage
{
public Guid ChannelId;
public byte[] Message;
}
private static Queue<CachedSideChannelMessage> m_CachedMessages = new Queue<CachedSideChannelMessage>();
/// <summary>
/// Separates the data received from Python into individual messages for each registered side channel.
/// </summary>

{
while(m_CachedMessages.Count!=0)
{
var cachedMessage = m_CachedMessages.Dequeue();
if (sideChannels.ContainsKey(cachedMessage.ChannelId))
{
sideChannels[cachedMessage.ChannelId].OnMessageReceived(cachedMessage.Message);
}
else
{
Debug.Log(string.Format(
"Unknown side channel data received. Channel Id is "
+ ": {0}", cachedMessage.ChannelId));
}
}
if (dataReceived.Length == 0)
{
return;

}
else
{
Debug.Log(string.Format(
"Unknown side channel data received. Channel Id is "
+ ": {0}", channelId));
// Don't recognize this ID, but cache it in case the SideChannel that can handle
// it is registered before the next call to ProcessSideChannelData.
m_CachedMessages.Enqueue(new CachedSideChannelMessage
{
ChannelId = channelId,
Message = message
});
}
}
}

正在加载...
取消
保存