/// <summary> /// QueueHistoryFrame Constructor /// </summary> /// <param name="queueType">type of queue history frame (Inbound/Outbound)</param> public RpcQueueHistoryFrame(QueueFrameType queueType, NetworkUpdateStage updateStage, int maxClients = 512) { m_MaximumClients = maxClients; m_QueueFrameType = queueType; m_CurrentQueueItem = new RpcFrameQueueItem(); m_StreamUpdateStage = updateStage; }
/// <summary> /// QueueHistoryFrame Constructor /// </summary> /// <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; }
/// <summary> /// SendFrameQueueItem /// Sends the RPC Queue Item to the specified destination /// </summary> /// <param name="queueItem">Information on what to send</param> private void SendFrameQueueItem(RpcFrameQueueItem queueItem) { switch (queueItem.QueueItemType) { case RpcQueueContainer.QueueItemType.ServerRpc: { m_RpcQueueContainer.NetworkManager.NetworkConfig.NetworkTransport.Send(queueItem.NetworkId, queueItem.MessageData, queueItem.NetworkChannel); //For each packet sent, we want to record how much data we have sent PerformanceDataManager.Increment(ProfilerConstants.ByteSent, (int)queueItem.StreamSize); PerformanceDataManager.Increment(ProfilerConstants.RpcSent); ProfilerStatManager.BytesSent.Record((int)queueItem.StreamSize); ProfilerStatManager.RpcsSent.Record(); break; } case RpcQueueContainer.QueueItemType.ClientRpc: { foreach (ulong clientid in queueItem.ClientNetworkIds) { m_RpcQueueContainer.NetworkManager.NetworkConfig.NetworkTransport.Send(clientid, queueItem.MessageData, queueItem.NetworkChannel); //For each packet sent, we want to record how much data we have sent PerformanceDataManager.Increment(ProfilerConstants.ByteSent, (int)queueItem.StreamSize); ProfilerStatManager.BytesSent.Record((int)queueItem.StreamSize); } //For each client we send to, we want to record how many RPCs we have sent PerformanceDataManager.Increment(ProfilerConstants.RpcSent, queueItem.ClientNetworkIds.Length); ProfilerStatManager.RpcsSent.Record(queueItem.ClientNetworkIds.Length); break; } } }
/// <summary> /// QueueInternalMLAPICommand /// Added this as an example of how to add internal messages to the outbound send queue /// </summary> /// <param name="queueItem">message queue item to add</param> public void QueueInternalMLAPICommand(RpcFrameQueueItem queueItem) { m_InternalMLAPISendQueue.Add(queueItem); }
/// <summary> /// AddToInternalMLAPISendQueue /// NSS-TODO: This will need to be removed once we determine how we want to handle specific /// internal MLAPI commands relative to RPCS. /// Example: An network object is destroyed via server side (internal mlapi) command, but prior to this several RPCs are invoked for the to be destroyed object (Client RPC) /// If both the DestroyObject internal mlapi command and the ClientRPCs are received in the same frame but the internal mlapi DestroyObject command is processed prior to the /// RPCs being invoked then the object won't exist and additional warnings will be logged that the object no longer exists. /// The vices versa scenario (create and then RPCs sent) is an unlikely/improbable scenario, but just in case added the CreateObject to this special case scenario. /// /// To avoid the DestroyObject scenario, the internal MLAPI commands (DestroyObject and CreateObject) are always invoked after RPCs. /// </summary> /// <param name="queueItem">item to add to the internal MLAPI queue</param> public void AddToInternalMLAPISendQueue(RpcFrameQueueItem queueItem) { m_RpcQueueProcessor.QueueInternalMLAPICommand(queueItem); }