LocalClient: removed static message caching to simplify code and reduce state

This commit is contained in:
vis2k 2018-06-11 10:34:32 +02:00
parent 8a748281de
commit aff994a1b0

View File

@ -5,8 +5,6 @@ namespace UnityEngine.Networking
{
sealed class LocalClient : NetworkClient
{
const int k_InitialFreeMessagePoolSize = 64;
struct InternalMsg
{
internal byte[] buffer;
@ -15,7 +13,6 @@ struct InternalMsg
List<InternalMsg> m_InternalMsgs = new List<InternalMsg>();
List<InternalMsg> m_InternalMsgs2 = new List<InternalMsg>();
Stack<InternalMsg> m_FreeMessages;
NetworkServer m_LocalServer;
bool m_Connected;
@ -35,16 +32,6 @@ public override void Disconnect()
internal void InternalConnectLocalServer(bool generateConnectMsg)
{
if (m_FreeMessages == null)
{
m_FreeMessages = new Stack<InternalMsg>();
for (int i = 0; i < k_InitialFreeMessagePoolSize; i++)
{
InternalMsg msg = new InternalMsg();
m_FreeMessages.Push(msg);
}
}
m_LocalServer = NetworkServer.instance;
m_Connection = new ULocalConnectionToServer(m_LocalServer);
SetHandlers(m_Connection);
@ -84,15 +71,7 @@ internal void AddLocalPlayer(PlayerController localPlayer)
private void PostInternalMessage(byte[] buffer, int channelId)
{
InternalMsg msg;
if (m_FreeMessages.Count == 0)
{
msg = new InternalMsg(); // grow forever?
}
else
{
msg = m_FreeMessages.Pop();
}
InternalMsg msg = new InternalMsg();
msg.buffer = buffer;
msg.channelId = channelId;
m_InternalMsgs.Add(msg);
@ -136,7 +115,6 @@ private void ProcessInternalMessages()
s_InternalMessage.msgType = s_InternalMessage.reader.ReadInt16();
m_Connection.InvokeHandler(s_InternalMessage);
m_FreeMessages.Push(msg);
connection.lastMessageTime = Time.time;
}