コード例 #1
0
        //process packets that have a tick stamp
        private void ProcessReceivedTickStampedPackets(Packet pktPacket)
        {
            //check if packet is ping packet
            if (pktPacket is PingPacket)
            {
                m_iLastTickReceived += TickStampedPacket.MaxTicksBetweenTickStampedPackets;

                return;
            }

            if (pktPacket is TickStampedPacket)
            {
                TickStampedPacket tspPacket = pktPacket as TickStampedPacket;

                //update the tick of the connection target
                m_iLastTickReceived += tspPacket.Offset;

                //set the tick of the packet
                tspPacket.m_iTick = m_iLastTickReceived;

                return;
            }

            if (pktPacket is ResetTickCountPacket)
            {
                m_iLastTickReceived = 0;

                return;
            }
        }
コード例 #2
0
        private void ProcessSendingTickStampedPackets(Packet pktPacket)
        {
            //reset the tick for game start events
            if (pktPacket is ResetTickCountPacket)
            {
                //reset connection tick
                m_iLastPacketTickQueuedToSend = 0;
            }

            if (pktPacket is PingPacket)
            {
                m_iLastPacketTickQueuedToSend += TickStampedPacket.MaxTicksBetweenTickStampedPackets;
            }

            //set the offset for tick stamped packets
            if (pktPacket is TickStampedPacket)
            {
                TickStampedPacket tspPacket = pktPacket as TickStampedPacket;

                //check if the target tick between this packet and the next is too big
                while (tspPacket.m_iTick - m_iLastPacketTickQueuedToSend > TickStampedPacket.MaxTicksBetweenTickStampedPackets)
                {
                    //queue a ping packet
                    QueuePacketToSend(new PingPacket());

                    //shift the tick forward
                    m_iLastPacketTickQueuedToSend += TickStampedPacket.MaxTicksBetweenTickStampedPackets;
                }

                //set the packets offset from the previouse packet
                tspPacket.SetOffset(m_iLastPacketTickQueuedToSend);

                //update the current tick
                m_iLastPacketTickQueuedToSend = tspPacket.m_iTick;

                return;
            }
        }