Added Queue
+Added Queue class *Replaced TPS Averager with a Queue
This commit is contained in:
parent
8327fcfd19
commit
3c74a808f3
@ -64,7 +64,7 @@ public class ServerThread implements Runnable {
|
|||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
ticker.start();
|
ticker.start();
|
||||||
executor.scheduleAtFixedRate(this, 0, 1000 / 20, TimeUnit.MILLISECONDS);
|
executor.scheduleAtFixedRate(this, 0, 1000 / 47, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -328,14 +328,59 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
return average();
|
return average();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Queue {
|
||||||
|
|
||||||
|
private static final int DISPLAY_INERTIA = 32;
|
||||||
|
private static final double UPDATE_INTERVAL = Units.get(50.0, "ms");
|
||||||
|
|
||||||
|
private final double[] values = new double[DISPLAY_INERTIA];
|
||||||
|
private int size;
|
||||||
|
private int head;
|
||||||
|
|
||||||
|
private long lastUpdate;
|
||||||
|
|
||||||
|
public void add(double value) {
|
||||||
|
if (size == values.length) {
|
||||||
|
values[head] = value;
|
||||||
|
head++;
|
||||||
|
if (head == values.length)
|
||||||
|
head = 0;
|
||||||
|
} else {
|
||||||
|
values[size] = value;
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double average() {
|
||||||
|
if (size == values.length && head!=0) {
|
||||||
|
return (values[head-1]-values[head])/DISPLAY_INERTIA*20;
|
||||||
|
} else if (head==0) {
|
||||||
|
return (values[size-1]-values[0])/DISPLAY_INERTIA*20;
|
||||||
|
} else {
|
||||||
|
return values[head-1]/size*20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double update(double value) {
|
||||||
|
long now = (long) (GraphicsInterface.getTime() / UPDATE_INTERVAL);
|
||||||
|
if (lastUpdate != now) {
|
||||||
|
lastUpdate = now;
|
||||||
|
add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return average();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Averager FPS_RECORD = new Averager();
|
private static final Averager FPS_RECORD = new Averager();
|
||||||
private static final Counter TPS_RECORD = new Counter(4000, 25);
|
private static final Queue TPS_RECORD = new Queue();
|
||||||
|
|
||||||
private static final Supplier<CharSequence> TPS_STRING = DynamicStrings.builder()
|
private static final Supplier<CharSequence> TPS_STRING = DynamicStrings.builder()
|
||||||
.addDyn(new MutableStringLocalized("LayerTestGUI.TPSDisplay"))
|
.addDyn(new MutableStringLocalized("LayerTestGUI.TPSDisplay"))
|
||||||
.addDyn(() -> TPS_RECORD.update(), 5, 1)
|
.addDyn(() -> TPS_RECORD.update(ServerState.getInstance().getUptimeTicks()), 5, 1)
|
||||||
.buildSupplier();
|
.buildSupplier();
|
||||||
|
|
||||||
private static final Supplier<CharSequence> POS_STRING = DynamicStrings.builder()
|
private static final Supplier<CharSequence> POS_STRING = DynamicStrings.builder()
|
||||||
|
Reference in New Issue
Block a user