Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5f6649b
fix: remove singleton references
NoelStephensUnity Mar 15, 2021
51717d0
test: rpc queue tests
NoelStephensUnity Mar 15, 2021
7275697
Merge branch 'develop' into test/newrpcqueuetests
NoelStephensUnity Mar 16, 2021
95d29d2
fix: Merging Artifact
NoelStephensUnity Mar 16, 2021
ea95749
refactor: Better StartNetworkManager parameters
NoelStephensUnity Mar 16, 2021
81093f3
Merge branch 'develop' into test/newrpcqueuetests
NoelStephensUnity Mar 16, 2021
860042e
Update com.unity.multiplayer.mlapi/Tests/Runtime/NetworkManagerHelper.cs
NoelStephensUnity Mar 16, 2021
9d71778
style: static Standards
NoelStephensUnity Mar 16, 2021
224c6c4
Update com.unity.multiplayer.mlapi/Tests/Runtime/NetworkManagerHelper.cs
NoelStephensUnity Mar 16, 2021
b6aa98e
style
NoelStephensUnity Mar 16, 2021
33c412e
Merge branch 'test/newrpcqueuetests' of https://github.com/Unity-Tech…
NoelStephensUnity Mar 16, 2021
db204d9
Update com.unity.multiplayer.mlapi/Tests/Runtime/NetworkManagerHelper.cs
NoelStephensUnity Mar 16, 2021
e2f5646
style: wording
NoelStephensUnity Mar 16, 2021
2548571
Merge branch 'test/newrpcqueuetests' of https://github.com/Unity-Tech…
NoelStephensUnity Mar 16, 2021
84b0010
refactor: debug logs to debug log
NoelStephensUnity Mar 16, 2021
4f81274
Update com.unity.multiplayer.mlapi/Tests/Runtime/RpcQueueTests.cs
NoelStephensUnity Mar 17, 2021
5a1ca8f
Update com.unity.multiplayer.mlapi/Tests/Runtime/RpcQueueTests.cs
NoelStephensUnity Mar 17, 2021
fb0f45b
Update com.unity.multiplayer.mlapi/Tests/Runtime/RpcQueueTests.cs
NoelStephensUnity Mar 17, 2021
671b83b
Refactor: minor adjustment to logging
NoelStephensUnity Mar 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
namespace MLAPI.Messaging
{
/// <summary>
/// QueueHistoryFrame
/// Used by the RpcQueueContainer to hold queued RPCs
/// All queued Rpcs end up in a PooledNetworkBuffer within a QueueHistoryFrame instance.
/// </summary>
public class RpcQueueHistoryFrame
Comment thread
NoelStephensUnity marked this conversation as resolved.
{
Expand Down Expand Up @@ -35,11 +33,10 @@ public enum QueueFrameType
private int m_MaximumClients;
private long m_CurrentStreamSizeMark;
private NetworkUpdateStage m_StreamUpdateStage; //Update stage specific to RPCs (typically inbound has most potential for variation)
private const int k_MaxStreamBounds = 131072;
private int m_MaxStreamBounds;
private const int k_MinStreamBounds = 0;

/// <summary>
/// GetQueueFrameType
/// Returns whether this is an inbound or outbound frame
/// </summary>
/// <returns></returns>
Expand All @@ -49,7 +46,6 @@ public QueueFrameType GetQueueFrameType()
}

/// <summary>
/// MarkCurrentStreamSize
/// Marks the current size of the stream (used primarily for sanity checks)
/// </summary>
public void MarkCurrentStreamPosition()
Expand All @@ -74,7 +70,6 @@ public long GetCurrentMarkedPosition()
}

/// <summary>
/// GetCurrentQueueItem
/// Internal method to get the current Queue Item from the stream at its current position
/// </summary>
/// <returns>FrameQueueItem</returns>
Expand Down Expand Up @@ -119,7 +114,7 @@ private RpcFrameQueueItem GetCurrentQueueItem()
m_CurrentQueueItem.StreamSize = QueueReader.ReadInt64();

//Sanity checking for boundaries
if (m_CurrentQueueItem.StreamSize < k_MaxStreamBounds && m_CurrentQueueItem.StreamSize > k_MinStreamBounds)
if (m_CurrentQueueItem.StreamSize < m_MaxStreamBounds && m_CurrentQueueItem.StreamSize > k_MinStreamBounds)
{
//Inbound and Outbound message streams are handled differently
if (m_QueueFrameType == QueueFrameType.Inbound)
Expand All @@ -145,15 +140,14 @@ private RpcFrameQueueItem GetCurrentQueueItem()
}
else
{
UnityEngine.Debug.LogWarning($"{nameof(m_CurrentQueueItem)}.{nameof(RpcFrameQueueItem.StreamSize)} exceeds allowed size ({k_MaxStreamBounds} vs {m_CurrentQueueItem.StreamSize})! Exiting from the current RpcQueue enumeration loop!");
UnityEngine.Debug.LogWarning($"{nameof(m_CurrentQueueItem)}.{nameof(RpcFrameQueueItem.StreamSize)} exceeds allowed size ({m_MaxStreamBounds} vs {m_CurrentQueueItem.StreamSize})! Exiting from the current RpcQueue enumeration loop!");
m_CurrentQueueItem.QueueItemType = RpcQueueContainer.QueueItemType.None;
}

return m_CurrentQueueItem;
}

/// <summary>
/// GetNextQueueItem
/// Handles getting the next queue item from this frame
/// If none are remaining, then it returns a queue item type of NONE
/// </summary>
Expand All @@ -172,7 +166,6 @@ internal RpcFrameQueueItem GetNextQueueItem()
}

/// <summary>
/// GetFirstQueueItem
/// Should be called the first time a queue item is pulled from a queue history frame.
/// This will reset the frame's stream indices and add a new stream and stream writer to the m_CurrentQueueItem instance.
/// </summary>
Expand Down Expand Up @@ -210,7 +203,6 @@ internal RpcFrameQueueItem GetFirstQueueItem()
}

/// <summary>
/// CloseQueue
/// Should be called once all processing of the current frame is complete.
/// This only closes the m_CurrentQueueItem's stream which is used as a "middle-man" (currently)
/// for delivering the RPC message to the method requesting a queue item from a frame.
Expand All @@ -236,16 +228,22 @@ public void CloseQueue()
}
}


/// <summary>
/// QueueHistoryFrame Constructor
/// </summary>
/// <param name="queueType">type of queue history frame (Inbound/Outbound)</param>
public RpcQueueHistoryFrame(QueueFrameType queueType, NetworkUpdateStage updateStage, int maxClients = 512)
/// <param name="queueType">Inbound or Outbound</param>
/// <param name="updateStage">Network Update Stage this RpcQueueHistoryFrame is assigned to</param>
/// <param name="maxClients">maximum number of clients</param>
/// <param name="maxStreamBounds">maximum size of the message stream an RPC can have (defaults to 1MB)</param>
public RpcQueueHistoryFrame(QueueFrameType queueType, NetworkUpdateStage updateStage, int maxClients = 512, int maxStreamBounds = 1 << 20)
{
//The added 512 is the Queue History Frame header information, leaving room to grow
m_MaxStreamBounds = maxStreamBounds + 512;
m_MaximumClients = maxClients;
m_QueueFrameType = queueType;
m_CurrentQueueItem = new RpcFrameQueueItem();
m_StreamUpdateStage = updateStage;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using MLAPI.Messaging;

namespace MLAPI.RuntimeTests
{
/// <summary>
/// Used in conjunction with the RpcQueueTest to validate from 1 byte to (n) MaximumBufferSize
/// - Sending and Receiving a continually growing buffer up to (MaximumBufferSize)
/// - Default maximum buffer size is 1MB
/// </summary>
public class BufferDataValidationComponent : NetworkBehaviour
{
/// <summary>
/// Allows the external RPCQueueTest to begin testing or stop it
/// </summary>
public bool EnableTesting;

/// <summary>
/// The maximum size of the buffer to send
/// </summary>
public int MaximumBufferSize = 1 << 20;

/// <summary>
/// The rate at which the buffer size increases until it reaches MaximumBufferSize
/// (the default starting buffer size is 1 bytes)
/// </summary>
public int BufferSizeStart = 1;

/// <summary>
/// Is checked to determine if the test exited because it failed
/// </summary>
public bool TestFailed { get; internal set; }
Comment thread
NoelStephensUnity marked this conversation as resolved.

private bool m_WaitForValidation;
private int m_CurrentBufferSize;

private List<byte> m_SendBuffer;
private List<byte> m_PreCalculatedBufferValues;

// Start is called before the first frame update
private void Start()
{
m_WaitForValidation = false;
m_CurrentBufferSize = BufferSizeStart;
m_SendBuffer = new List<byte>(MaximumBufferSize + 1);
m_PreCalculatedBufferValues = new List<byte>(MaximumBufferSize + 1);
while (m_PreCalculatedBufferValues.Count <= MaximumBufferSize)
{
m_PreCalculatedBufferValues.Add((byte)UnityEngine.Random.Range(0, 255));
}
}

/// <summary>
/// Returns back whether the test has completed the total number of iterations
/// </summary>
/// <returns></returns>
public bool IsTestComplete()
{
if (m_CurrentBufferSize > MaximumBufferSize || TestFailed)
{
return true;
}
return false;
}

// Update is called once per frame
private void Update()
{
if (NetworkManager.Singleton.IsListening && EnableTesting && !IsTestComplete() && !m_WaitForValidation)
{
m_SendBuffer.Clear();
//Keep the current contents of the bufffer and fill the buffer with the delta difference of the buffer's current size and new size from the m_PreCalculatedBufferValues
m_SendBuffer.AddRange(m_PreCalculatedBufferValues.GetRange(0, m_CurrentBufferSize));

//Make sure we don't do anything until we finish validating buffer
m_WaitForValidation = true;

//Send the buffer
SendBufferServerRpc(m_SendBuffer.ToArray());
}
}

/// <summary>
/// Server side RPC for testing
/// </summary>
/// <param name="parameters">server rpc parameters</param>
[ServerRpc]
private void SendBufferServerRpc(byte[] buffer)
{
TestFailed = !NetworkManagerHelper.BuffersMatch(0, buffer.Length, buffer, m_SendBuffer.ToArray());
if (!TestFailed)
{
Debug.Log($"Tested buffer size of {m_SendBuffer.Count} -- OK");
}

if (m_CurrentBufferSize == MaximumBufferSize)
{
m_CurrentBufferSize++;
}
else
{
//Increasse buffer size
m_CurrentBufferSize = m_CurrentBufferSize << 1;
}

m_WaitForValidation = false;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading