コード例 #1
0
        private unsafe void ProcessMessage(MyPacket p)
        {
            HandlerId         id;
            Action <MyPacket> action;

            id.messageId     = (MyMessageId)p.BitStream.ReadByte(8);
            id.receiverIndex = p.BitStream.ReadByte(8);
            if (((ulong)id.messageId) < this.m_thisFrameTraffic.Length)
            {
                int *numPtr1 = (int *)ref this.m_thisFrameTraffic[(int)id.messageId];
                numPtr1[0] += p.BitStream.ByteLength;
            }
            p.Sender = new Endpoint(p.Sender.Id, id.receiverIndex);
            if (!this.m_handlers.TryGetValue(id, out action))
            {
                HandlerId key = new HandlerId {
                    messageId     = id.messageId,
                    receiverIndex = 0xff
                };
                this.m_handlers.TryGetValue(key, out action);
            }
            if (action == null)
            {
                p.Return();
            }
            else
            {
                MyStatsGraph.Begin(MyEnum <MyMessageId> .GetName(id.messageId), 0x7fffffff, "ProcessMessage", 0xe2, @"E:\Repo1\Sources\Sandbox.Game\Engine\Multiplayer\MyTransportLayer.cs");
                action(p);
                MyStatsGraph.End(new float?((float)p.BitStream.ByteLength), 0f, "", "{0} B", null, "ProcessMessage", 0xe4, @"E:\Repo1\Sources\Sandbox.Game\Engine\Multiplayer\MyTransportLayer.cs");
            }
        }
コード例 #2
0
        private void ProcessMessage(byte[] data, int dataSize, ulong sender, TimeSpan timestamp)
        {
            Debug.Assert(data.Length >= dataSize, "Wrong size");

            MyMessageId id = (MyMessageId)data[0];

            MyPacket p = new MyPacket();

            p.Data          = data;
            p.PayloadOffset = 1; // First byte is message id
            p.PayloadLength = dataSize - p.PayloadOffset;
            p.Sender        = new VRage.Network.EndpointId(sender);
            p.Timestamp     = timestamp;

            Action <MyPacket> handler;

            if (m_handlers.TryGetValue(id, out handler))
            {
                ProfilerShort.Begin(MyEnum <MyMessageId> .GetName(id));
                NetProfiler.Begin(MyEnum <MyMessageId> .GetName(id));
                handler(p);
                NetProfiler.End(p.PayloadLength);
                ProfilerShort.End();
            }
            else
            {
                Debug.Fail("No handler for message type: " + id);
            }
        }
コード例 #3
0
        public static string GetName(MyTrashRemovalFlags flag)
        {
            MyStringId id;

            if (m_names.TryGetValue(flag, out id))
            {
                return(MyTexts.GetString(id));
            }
            else
            {
                return(MyEnum <MyTrashRemovalFlags> .GetName(flag));
            }
        }
コード例 #4
0
        private void ProcessMessage(byte[] data, int dataSize, ulong sender, MyTimeSpan timestamp, MyTimeSpan receivedTime)
        {
            Debug.Assert(data.Length >= dataSize, "Wrong size");

            MyMessageId id = (MyMessageId)data[0];

            if (id == MyMessageId.CLIENT_CONNNECTED)
            {
                MyNetworkClient player;
                if (Sync.Layer != null && Sync.Layer.Clients != null)
                {
                    bool playerFound = Sync.Layer.Clients.TryGetClient(sender, out player);

                    if (!playerFound)
                    {
                        Sync.Layer.Clients.AddClient(sender);
                    }
                }
            }

            MyPacket p = new MyPacket
            {
                Data = data,
                // First byte is message id
                PayloadOffset = 1,
                PayloadLength = dataSize - 1,
                Sender        = new VRage.Network.EndpointId(sender),
                Timestamp     = timestamp,
                ReceivedTime  = receivedTime
            };

            Action <MyPacket> handler;

            if (m_handlers.TryGetValue(id, out handler))
            {
                ProfilerShort.Begin(MyEnum <MyMessageId> .GetName(id));
                NetProfiler.Begin(MyEnum <MyMessageId> .GetName(id));
                handler(p);
                NetProfiler.End(p.PayloadLength);
                ProfilerShort.End();
            }
            else
            {
                Debug.Fail("No handler for message type: " + id);
            }
        }
コード例 #5
0
        internal static void ProcessDrawQueue()
        {
            while (m_drawQueue.Count > 0)
            {
                var drawMessage = m_drawQueue.Dequeue();
                ProfilerShort.Begin(MyEnum <MyRenderMessageEnum> .GetName(drawMessage.MessageType));
                ProcessDrawMessage(drawMessage);
                ProfilerShort.End();
            }

            ProfilerShort.Begin("OnMessagesProcessedOnce");
            if (OnMessagesProcessedOnce != null)
            {
                OnMessagesProcessedOnce();
            }
            OnMessagesProcessedOnce = null;
            ProfilerShort.End();
        }
コード例 #6
0
        public unsafe void Tick()
        {
            foreach (var steamId in m_pendingFlushes)
            {
                byte data = 0;
                if (!Peer2Peer.SendPacket(steamId, &data, 0, P2PMessageEnum.Reliable, m_channel))
                {
                    System.Diagnostics.Debug.Fail("P2P packet send fail (flush)");
                }
            }
            m_pendingFlushes.Clear();

            int totalSum = 0;

            NetProfiler.Begin("Avg per frame (60 frames window)");
            for (int i = 0; i < MessageTypeCount; i++)
            {
                var window = m_slidingWindows[i];
                window.Enqueue(m_thisFrameTraffic[i]);
                m_thisFrameTraffic[i] = 0;

                while (window.Count > 60)
                {
                    window.Dequeue();
                }

                int sum = 0;
                foreach (var item in window)
                {
                    sum += item;
                }
                if (sum > 0)
                {
                    NetProfiler.Begin(MyEnum <MyMessageId> .GetName((MyMessageId)i));
                    NetProfiler.End(sum / 60.0f, sum / 1024.0f, "{0} KB/s");
                }
                totalSum += sum;
            }
            NetProfiler.End(totalSum / 60.0f, totalSum / 1024.0f, "{0} KB/s");
        }
コード例 #7
0
        public void Tick()
        {
            int num = 0;

            this.ProfilePacketStatistics(true);
            MyStatsGraph.Begin("Average data", 0x7fffffff, "Tick", 130, @"E:\Repo1\Sources\Sandbox.Game\Engine\Multiplayer\MyTransportLayer.cs");
            int index = 0;

            while (index < m_messageTypeCount)
            {
                Queue <int> queue = this.m_slidingWindows[index];
                queue.Enqueue(this.m_thisFrameTraffic[index]);
                this.m_thisFrameTraffic[index] = 0;
                while (true)
                {
                    if (queue.Count <= 60)
                    {
                        int num3 = 0;
                        foreach (int num4 in queue)
                        {
                            num3 += num4;
                        }
                        if (num3 > 0)
                        {
                            MyStatsGraph.Begin(MyEnum <MyMessageId> .GetName((MyMessageId)((byte)index)), 0x7fffffff, "Tick", 0x93, @"E:\Repo1\Sources\Sandbox.Game\Engine\Multiplayer\MyTransportLayer.cs");
                            MyStatsGraph.End(new float?(((float)num3) / 60f), ((float)num3) / 1024f, "{0} KB/s", "{0} B", null, "Tick", 0x94, @"E:\Repo1\Sources\Sandbox.Game\Engine\Multiplayer\MyTransportLayer.cs");
                        }
                        num += num3;
                        index++;
                        break;
                    }
                    queue.Dequeue();
                }
            }
            MyStatsGraph.End(new float?(((float)num) / 60f), ((float)num) / 1024f, "{0} KB/s", "{0} B", null, "Tick", 0x98, @"E:\Repo1\Sources\Sandbox.Game\Engine\Multiplayer\MyTransportLayer.cs");
            this.ProfilePacketStatistics(false);
        }