public ulong blockTimestamp(ushort blockId) { if (Overflow.ge(blockId, timestampBlockId)) { return(timestamp + (ulong)(blockId - timestampBlockId) * Constants.WorldHeartBeat); } return(timestamp - (ulong)(timestampBlockId - blockId) * Constants.WorldHeartBeat); }
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; }
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); }