Skip to content

Commit

Permalink
Server.getTickUseNano
Browse files Browse the repository at this point in the history
  • Loading branch information
boybook committed May 21, 2024
1 parent 6875f39 commit e7a613d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public class Server {

private float maxUse = 0;
private float tickUsage;
private long tickUseNano;

private int sendUsageTicker = 0;

Expand Down Expand Up @@ -1257,7 +1258,8 @@ private boolean tick() {
//float use = Math.min(1, (now - tickTime) / 50);

float tick = (float) Math.min(20, 1000000000 / Math.max(1000000, ((double) nowNano - tickTimeNano)));
float use = (float) Math.min(1, ((double) (nowNano - tickTimeNano)) / 50000000);
this.tickUseNano = nowNano - tickTimeNano; // record the tick time in nano seconds
float use = (float) Math.min(1, ((double) tickUseNano) / 50000000);

if (this.maxTick > tick) {
this.maxTick = tick;
Expand Down Expand Up @@ -1577,6 +1579,10 @@ public float getTickUsageAverage() {
return tickUsageAverage;
}

public long getTickUseNano() {
return tickUseNano;
}

private static float getAverage(float[] array) {
float sum = 0;
int count = array.length;
Expand Down

0 comments on commit e7a613d

Please sign in to comment.