Skip to content

Commit

Permalink
Switch to microseconds for statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Mar 4, 2024
1 parent ce00c07 commit 203461a
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class TransportClientConnection extends BedrockClientConnection {

private final Channel channel;
private long lastPingTimestamp;
private long latency;
private long latency; // Latency in microseconds

private final List<ScheduledFuture<?>> scheduledTasks = new ArrayList<>();

Expand Down Expand Up @@ -105,7 +105,7 @@ private void onBedrockBatch(@NonNull BedrockBatchWrapper batch) {
wrapper.release(); // release
batch.modify();

this.latency = (System.currentTimeMillis() - this.lastPingTimestamp) / 2;
this.latency = (System.nanoTime() - this.lastPingTimestamp) / 2000;
this.broadcastPing();
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ public void collectStats() {

sendPacket(packet);

this.lastPingTimestamp = System.currentTimeMillis();
this.lastPingTimestamp = System.nanoTime();
} else if (this.channel instanceof EpollSocketChannel epollChannel) {
this.latency = epollChannel.tcpInfo().rtt() / 2;
this.broadcastPing();
Expand All @@ -200,7 +200,7 @@ public void collectStats() {

private void broadcastPing() {
TickSyncPacket latencyPacket = new TickSyncPacket();
latencyPacket.setRequestTimestamp(getPlayer().getPing());
latencyPacket.setRequestTimestamp(getPlayer().getPing() * 1000);
latencyPacket.setResponseTimestamp(this.latency);

sendPacket(latencyPacket);
Expand Down

0 comments on commit 203461a

Please sign in to comment.