Skip to content

Commit

Permalink
No longer using structs for serverMessageBuffer
Browse files Browse the repository at this point in the history
Should increase framerate
  • Loading branch information
Squaresweets authored Jun 20, 2021
1 parent db8bca7 commit 360710f
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions BubbleTransport/BubbleTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,10 @@ public class InviteRecievedEvent : UnityEvent { }
private MatchFoundEvent inviteRecieved = new MatchFoundEvent();

static List<ArraySegment<Byte>> clientMessageBuffer = new List<ArraySegment<byte>>();
struct ServerMessage
{
public ArraySegment<Byte> message;
public int connId;

public ServerMessage(ArraySegment<byte> message, int connId) : this()
{
this.message = message;
this.connId = connId;
}
}
static List<ServerMessage> serverMessageBuffer = new List<ServerMessage>();
//Done this way as structs seem to be pretty slow
static List<ArraySegment<Byte>> serverMessageBuffer = new List<ArraySegment<byte>>();
static List<int> serverMessageBufferConnIds = new List<int>();


bool available = true;
Expand Down Expand Up @@ -328,7 +320,8 @@ Objective C code splits this up into offset and count and sends it here
byte[] _data = new byte[count];
Marshal.Copy(data, _data, 0, count);

serverMessageBuffer.Add(new ServerMessage(new ArraySegment<byte>(_data, offset, count), connId));
serverMessageBuffer.Add(new ArraySegment<byte>(_data, offset, count));
serverMessageBufferConnIds.Add(connId);
}

/// <summary>
Expand Down Expand Up @@ -389,8 +382,9 @@ public override void ServerLateUpdate()
//This executes any messages that were recieved in the last frame
for (int i = 0; i < serverMessageBuffer.Count && i < MaxReceivesPerTick; i++)
{
OnServerDataReceived?.Invoke(serverMessageBuffer[0].connId, serverMessageBuffer[0].message, 0);
OnServerDataReceived?.Invoke(serverMessageBufferConnIds[0], serverMessageBuffer[0], 0);
serverMessageBuffer.RemoveAt(0);
serverMessageBufferConnIds.RemoveAt(0);
}
}
private void Start()
Expand Down

0 comments on commit 360710f

Please sign in to comment.