Пример #1
0
        public ulong blockTimestamp(ushort blockId)
        {
            if (Overflow.ge(blockId, timestampBlockId))
            {
                return(timestamp + (ulong)(blockId - timestampBlockId) * Constants.WorldHeartBeat);
            }

            return(timestamp - (ulong)(timestampBlockId - blockId) * Constants.WorldHeartBeat);
        }
Пример #2
0
        public void scheduleAck(ushort blockId)
        {
            if (Overflow.ge(blockId, _ackBase))
            {
                ushort ackDiff = Overflow.sub(blockId, _ackBase);
                _pendingAcks = (_pendingAcks << ackDiff) | 1; // | 1 because we are acking the base
                _ackBase     = blockId;
            }
            else
            {
                ushort ackDiff = Overflow.sub(_ackBase, blockId);
                _pendingAcks = _pendingAcks | (ushort)(1 << ackDiff);
            }

            _mustAck = true;
        }
Пример #3
0
        public bool read(IBaseClient client, SuperPacket <PQ> superpacket, IMarshal marshal)
        {
            timestampBlockId = ExpectedTickId;
            timestamp        = DateTimeExtensions.now();

            if (!client.hasPendingSuperPackets())
            {
                if (++sinceLastRecv >= Constants.MaxBlocksUntilDisconnection)
                {
                    client.disconnect();
                    return(false);
                }

                marshal.Update(client, ExpectedTickId);
                ExpectedTickId = Overflow.inc(ExpectedTickId);
                return(false);
            }

            sinceLastRecv = 0;
            ushort expectedId = ExpectedTickId;

            if (!Constants.UseKumoQueues)
            {
                ExpectedTickId = Overflow.sub(ExpectedTickId, bufferSize);
            }

            while (client.hasPendingSuperPackets() &&
                   !Overflow.ge(client.firstSuperPacketTickId(), expectedId))
            {
                read_impl(client, superpacket, marshal);
            }

            marshal.Update(client, ExpectedTickId);
            ExpectedTickId = Overflow.inc(ExpectedTickId);
            return(true);
        }