コード例 #1
0
        /// <summary>
        /// Sends a message using the reliable pipeline, queues message if inflight packet limit is reached.
        /// </summary>
        private unsafe void sendReliableMessage(byte[] msg)
        {
            //DataStreamWriter is needed to send data
            //using statement makes sure DataStreamWriter memory is disposed
            using (var writer = new DataStreamWriter(msg.Length, Allocator.Temp))
            {
                writer.Write(msg); //Write msg byte data

                //Below code copied from documentation here: https://github.com/Unity-Technologies/multiplayer/blob/master/com.unity.transport/Documentation~/pipelines-usage.md

                // Get a reference to the internal state or shared context of the reliability
                NativeSlice <byte> tmpReceiveBuffer     = default;
                NativeSlice <byte> tmpSendBuffer        = default;
                NativeSlice <byte> serverReliableBuffer = default;
                networkDriver.GetPipelineBuffers(typeof(ReliableSequencedPipelineStage), connectionToServer, ref tmpReceiveBuffer, ref tmpSendBuffer, ref serverReliableBuffer);
                var serverReliableCtx = (ReliableUtility.SharedContext *)serverReliableBuffer.GetUnsafePtr();

                connectionToServer.Send(networkDriver, reliablePipeline, writer); //Send msg data to server

                // Failed to send with reliability, error code will be ReliableUtility.ErrorCodes.OutgoingQueueIsFull if no buffer space is left to store the packet
                if (serverReliableCtx->errorCode != 0)
                {
                    messageQueue.Enqueue(new QueuedMessage(msg, true)); //Requeue message
                }
            }
        }
コード例 #2
0
        public static unsafe void SetMinimumResendTime(int value, UdpNetworkDriver driver,
                                                       NetworkPipeline pipeline, int stageId, NetworkConnection con)
        {
            NativeSlice <byte> receiveBuffer = default(NativeSlice <byte>);
            NativeSlice <byte> sendBuffer    = default(NativeSlice <byte>);
            NativeSlice <byte> sharedBuffer  = default(NativeSlice <byte>);

            driver.GetPipelineBuffers(pipeline, stageId, con, ref receiveBuffer, ref sendBuffer, ref sharedBuffer);
            var sharedCtx = (ReliableUtility.SharedContext *)sharedBuffer.GetUnsafePtr();

            sharedCtx->MinimumResendTime = value;
        }
コード例 #3
0
    public unsafe void DumpSimulatorStatistics()
    {
        NativeSlice <byte> receiveBuffer = default;
        NativeSlice <byte> sendBuffer    = default;
        NativeSlice <byte> sharedBuffer  = default;

        driver.GetPipelineBuffers(pipeline, 0, connection[0], ref receiveBuffer, ref sendBuffer, ref sharedBuffer);

        /*var simCtx = (Simulator.Context*)sharedBuffer.GetUnsafeReadOnlyPtr();
         * Debug.Log("Simulator stats\n" +
         *  "PacketCount: " + simCtx->PacketCount + "\n" +
         *  "PacketDropCount: " + simCtx->PacketDropCount + "\n" +
         *  "MaxPacketCount: " + simCtx->MaxPacketCount + "\n" +
         *  "ReadyPackets: " + simCtx->ReadyPackets + "\n" +
         *  "WaitingPackets: " + simCtx->WaitingPackets + "\n" +
         *  "NextPacketTime: " + simCtx->NextPacketTime + "\n" +
         *  "StatsTime: " + simCtx->StatsTime);*/
    }
コード例 #4
0
    public static unsafe void DumpReliabilityStatistics(UdpNetworkDriver driver, NetworkPipeline pipeline, NetworkConnection con)
    {
        NativeSlice <byte> receiveBuffer = default;
        NativeSlice <byte> sendBuffer    = default;
        NativeSlice <byte> sharedBuffer  = default;

        driver.GetPipelineBuffers(pipeline, 4, con, ref receiveBuffer, ref sendBuffer, ref sharedBuffer);

        /*var relCtx = (ReliableUtility.SharedContext*)sharedBuffer.GetUnsafeReadOnlyPtr();
        *  var sendCtx = (ReliableUtility.Context*)sendBuffer.GetUnsafeReadOnlyPtr();
        *  UnityEngine.Debug.Log("Reliability stats\nPacketsDropped: " + relCtx->stats.PacketsDropped + "\n" +
        *         "PacketsDuplicated: " + relCtx->stats.PacketsDuplicated + "\n" +
        *         "PacketsOutOfOrder: " + relCtx->stats.PacketsOutOfOrder + "\n" +
        *         "PacketsReceived: " + relCtx->stats.PacketsReceived + "\n" +
        *         "PacketsResent: " + relCtx->stats.PacketsResent + "\n" +
        *         "PacketsSent: " + relCtx->stats.PacketsSent + "\n" +
        *         "PacketsStale: " + relCtx->stats.PacketsStale + "\n" +
        *         "Last received remote seqId: " + relCtx->ReceivedPackets.Sequence + "\n" +
        *         "Last received remote ackMask: " + SequenceHelpers.BitMaskToString(relCtx->ReceivedPackets.AckMask) + "\n" +
        *         "Last sent seqId: " + (relCtx->SentPackets.Sequence - 1)+ "\n" +
        *         "Last acked seqId: " + relCtx->SentPackets.Acked + "\n" +
        *         "Last ackmask: " + SequenceHelpers.BitMaskToString(relCtx->SentPackets.AckMask));*/
    }
コード例 #5
0
    public static unsafe void GatherReliabilityStats(ref SoakStatisticsPoint stats, ref SoakStatisticsPoint lastStats, UdpNetworkDriver driver,
                                                     NetworkPipeline pipeline, NetworkConnection con, long timestamp)
    {
        NativeSlice <byte> receiveBuffer = default;
        NativeSlice <byte> sendBuffer    = default;
        NativeSlice <byte> sharedBuffer  = default;

        driver.GetPipelineBuffers(pipeline, 4, con, ref receiveBuffer, ref sendBuffer, ref sharedBuffer);

        var sharedCtx = (ReliableUtility.SharedContext *)sharedBuffer.GetUnsafeReadOnlyPtr();

        stats.ReliableSent += sharedCtx->stats.PacketsSent - lastStats.ReliableSent;
        //Console.WriteLine("sharedCtx->stats.PacketsSent=" + sharedCtx->stats.PacketsSent + " lastStats.ReliableSent=" + lastStats.ReliableSent + " stats.ReliableSent=" + stats.ReliableSent);
        stats.ReliableResent    += sharedCtx->stats.PacketsResent - lastStats.ReliableResent;
        stats.ReliableDropped   += sharedCtx->stats.PacketsDropped - lastStats.ReliableDropped;
        stats.ReliableReceived  += sharedCtx->stats.PacketsReceived - lastStats.ReliableReceived;
        stats.ReliableDuplicate += sharedCtx->stats.PacketsDuplicated - lastStats.ReliableDuplicate;
        stats.ReliableRTT        = sharedCtx->RttInfo.LastRtt;
        stats.ReliableSRTT       = sharedCtx->RttInfo.SmoothedRtt;
        int resendQueueSize       = 0;
        int oldestResendPacketAge = 0;
        int maxRtt            = 0;
        int maxProcessingTime = 0;

        GatherExtraStats(sendBuffer, sharedBuffer, timestamp, ref resendQueueSize, ref oldestResendPacketAge, ref maxRtt, ref maxProcessingTime);
        stats.ReliableResendQueue           = resendQueueSize;
        stats.ReliableOldestResendPacketAge = oldestResendPacketAge;
        stats.ReliableMaxRTT            = maxRtt;
        stats.ReliableMaxProcessingTime = maxProcessingTime;

        lastStats.ReliableSent      = sharedCtx->stats.PacketsSent;
        lastStats.ReliableResent    = sharedCtx->stats.PacketsResent;
        lastStats.ReliableDropped   = sharedCtx->stats.PacketsDropped;
        lastStats.ReliableReceived  = sharedCtx->stats.PacketsReceived;
        lastStats.ReliableDuplicate = sharedCtx->stats.PacketsDuplicated;
    }