[DEV] update FPS to use monotonic clock
This commit is contained in:
parent
39ac99553d
commit
1707c6cb11
@ -4,85 +4,85 @@ public class Fps {
|
|||||||
private long startTime = 0;
|
private long startTime = 0;
|
||||||
private long nbCallTime = 0;
|
private long nbCallTime = 0;
|
||||||
private long nbDisplayTime = 0;
|
private long nbDisplayTime = 0;
|
||||||
private float min = 99999999;
|
private float min = (float) 99999999999999.0;
|
||||||
private float avg = 0;
|
private float avg = 0;
|
||||||
private float max = 0;
|
private float max = 0;
|
||||||
private float minIdle = 99999999;
|
private float minIdle = (float) 9999999999999.0;
|
||||||
private float avgIdle = 0;
|
private float avgIdle = 0;
|
||||||
private float maxIdle = 0;
|
private float maxIdle = 0;
|
||||||
private long ticTime = 0;
|
private long ticTime = 0;
|
||||||
private boolean display = false;
|
private boolean display = false;
|
||||||
private boolean drawingDone = false;
|
private boolean drawingDone = false;
|
||||||
private String displayName = null;
|
private String displayName = null;
|
||||||
private boolean displayFPS;
|
private final boolean displayFPS;
|
||||||
public Fps(String displayName, boolean displayFPS) {
|
public Fps(final String displayName, final boolean displayFPS) {
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
this.displayFPS = displayFPS;
|
this.displayFPS = displayFPS;
|
||||||
}
|
}
|
||||||
public void tic() {
|
public void tic() {
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.nanoTime();
|
||||||
ticTime = currentTime;
|
this.ticTime = currentTime;
|
||||||
nbCallTime++;
|
this.nbCallTime++;
|
||||||
if (startTime == 0) {
|
if (this.startTime == 0) {
|
||||||
startTime = currentTime;
|
this.startTime = currentTime;
|
||||||
}
|
}
|
||||||
if ( (currentTime - startTime) > 10000) {
|
if ( (currentTime - this.startTime) > 10000000000L) {
|
||||||
display = true;
|
this.display = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void toc() {
|
public void toc() {
|
||||||
toc(false);
|
toc(false);
|
||||||
}
|
}
|
||||||
public void toc(boolean displayTime) {
|
public void toc(final boolean displayTime) {
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.nanoTime();
|
||||||
long processTimeLocal = (currentTime - ticTime);
|
long processTimeLocal = (currentTime - this.ticTime);
|
||||||
if (displayTime) {
|
if (displayTime) {
|
||||||
System.out.println(displayName + ": processTime: " + processTimeLocal);
|
System.out.println(this.displayName + ": processTime: " + processTimeLocal);
|
||||||
}
|
}
|
||||||
if (drawingDone) {
|
if (this.drawingDone) {
|
||||||
min = Math.min(min, processTimeLocal);
|
this.min = Math.min(this.min, processTimeLocal);
|
||||||
max = Math.max(max, processTimeLocal);
|
this.max = Math.max(this.max, processTimeLocal);
|
||||||
avg += processTimeLocal;
|
this.avg += processTimeLocal;
|
||||||
drawingDone = false;
|
this.drawingDone = false;
|
||||||
} else {
|
} else {
|
||||||
minIdle = Math.min(minIdle, processTimeLocal);
|
this.minIdle = Math.min(this.minIdle, processTimeLocal);
|
||||||
maxIdle = Math.max(maxIdle, processTimeLocal);
|
this.maxIdle = Math.max(this.maxIdle, processTimeLocal);
|
||||||
avgIdle += processTimeLocal;
|
this.avgIdle += processTimeLocal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void incrementCounter() {
|
public void incrementCounter() {
|
||||||
nbDisplayTime++;
|
this.nbDisplayTime++;
|
||||||
drawingDone = true;
|
this.drawingDone = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw() {
|
public void draw() {
|
||||||
if (display) {
|
if (this.display) {
|
||||||
if (nbDisplayTime > 0) {
|
if (this.nbDisplayTime > 0) {
|
||||||
System.out.println(displayName + " : Active : "
|
System.out.println(this.displayName + " : Active : "
|
||||||
+ min + " "
|
+ this.min + " "
|
||||||
+ avg / nbDisplayTime + "ms "
|
+ this.avg / this.nbDisplayTime + "ms "
|
||||||
+ max + " ");
|
+ this.max + " ");
|
||||||
}
|
}
|
||||||
if (nbCallTime-nbDisplayTime>0) {
|
if (this.nbCallTime-this.nbDisplayTime>0) {
|
||||||
System.out.println(displayName + " : idle : "
|
System.out.println(this.displayName + " : idle : "
|
||||||
+ minIdle + " "
|
+ this.minIdle + " "
|
||||||
+ avgIdle / (nbCallTime-nbDisplayTime) + "ms "
|
+ this.avgIdle / (this.nbCallTime-this.nbDisplayTime) + "ms "
|
||||||
+ maxIdle + " ");
|
+ this.maxIdle + " ");
|
||||||
}
|
}
|
||||||
if (displayFPS) {
|
if (this.displayFPS) {
|
||||||
System.out.println("FPS : " + nbDisplayTime + "/" + nbCallTime + "fps");
|
System.out.println("FPS : " + this.nbDisplayTime + "/" + this.nbCallTime + "fps");
|
||||||
}
|
}
|
||||||
max = 0;
|
this.max = 0;
|
||||||
min = 99999999;
|
this.min = 99999999;
|
||||||
avg = 0;
|
this.avg = 0;
|
||||||
maxIdle = 0;
|
this.maxIdle = 0;
|
||||||
minIdle = 99999999;
|
this.minIdle = 99999999;
|
||||||
avgIdle = 0;
|
this.avgIdle = 0;
|
||||||
nbCallTime = 0;
|
this.nbCallTime = 0;
|
||||||
nbDisplayTime = 0;
|
this.nbDisplayTime = 0;
|
||||||
startTime = 0;
|
this.startTime = 0;
|
||||||
display = false;
|
this.display = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user