Ejemplo n.º 1
0
        public override void SendUpdate()
        {
            ProfilerShort.Begin("ClientState.WriteAcks");

            // Client ACK Packet - reliable
            SendStream.ResetWrite();

            // ACK Header
            // Write last state sync packet id
            SendStream.WriteByte(m_lastStateSyncPacketId);

            // Write ACKs
            byte num = (byte)m_acks.Count;

            SendStream.WriteByte(num);
            for (int i = 0; i < num; i++)
            {
                SendStream.WriteByte(m_acks[i]);
            }
            SendStream.Terminate();
            m_acks.Clear();
            ProfilerShort.End();
            m_callback.SendClientAcks(SendStream);

            // Client Update Packet
            SendStream.ResetWrite();

            m_clientPacketId++;
            SendStream.WriteByte(m_clientPacketId);
            SendStream.WriteDouble(MyTimeSpan.FromTicks(Stopwatch.GetTimestamp()).Milliseconds);
            ProfilerShort.Begin("ClientState.Serialize");
            if (VRage.MyCompilationSymbols.EnableNetworkPacketTracking)
            {
                Trace.MyTrace.Send(Trace.TraceWindow.MPackets, "Send client update: ");
            }
            // Write Client state
            ClientState.Serialize(SendStream, false);
            ProfilerShort.End();
            SendStream.Terminate();

            ProfilerShort.Begin("SendClientUpdate");
            m_callback.SendClientUpdate(SendStream);
            ProfilerShort.End();

            //Client.SendMessageToServer(m_sendStream, PacketReliabilityEnum.UNRELIABLE, PacketPriorityEnum.IMMEDIATE_PRIORITY, MyChannelEnum.StateDataSync);
        }
Ejemplo n.º 2
0
        public override void Update()
        {
            if (!m_clientReady || !m_hasTypeTable || ClientState == null)
            {
                return;
            }

            m_frameIndex++;
            if (m_frameIndex % 2 == 0) // Client updates once per 2 frames
            {
                return;
            }


            // Update state groups on client
            foreach (var obj in NetworkObjects)
            {
                var stateGroup = obj as IMyStateGroup;
                if (stateGroup != null)
                {
                    stateGroup.ClientUpdate();
                }
            }

            m_sendStream.ResetWrite();

            // Write last state sync packet id
            m_sendStream.WriteByte(m_lastStateSyncPacketId);

            // Write ACKs
            byte num = (byte)m_acks.Count;

            m_sendStream.WriteByte(num);
            for (int i = 0; i < num; i++)
            {
                m_sendStream.WriteByte(m_acks[i]);
            }
            m_acks.Clear();

            // Write Client state
            ClientState.Serialize(m_sendStream);
            m_callback.SendClientUpdate(m_sendStream);
            //Client.SendMessageToServer(m_sendStream, PacketReliabilityEnum.UNRELIABLE, PacketPriorityEnum.IMMEDIATE_PRIORITY, MyChannelEnum.StateDataSync);
        }