Removed the FPS background, and lowered the update frequency so it doesn't flip too fast.

#story[923]
This commit is contained in:
Haoming Yin
2017-05-24 19:33:24 +12:00
parent 6301fd2fb7
commit d2e55bf964
@@ -120,6 +120,9 @@ public class CanvasController {
initializeMarks(); initializeMarks();
timer = new AnimationTimer() { timer = new AnimationTimer() {
private int UPDATE_FPM_PERIOD = 50; // update FPM label every 50 frames
private int updateFPMCounter = 100;
@Override @Override
public void handle(long now) { public void handle(long now) {
@@ -135,7 +138,10 @@ public class CanvasController {
elapsedNanos = now - oldFrameTime ; elapsedNanos = now - oldFrameTime ;
long elapsedNanosPerFrame = elapsedNanos / frameTimes.length ; long elapsedNanosPerFrame = elapsedNanos / frameTimes.length ;
frameRate = 1_000_000_000.0 / elapsedNanosPerFrame ; frameRate = 1_000_000_000.0 / elapsedNanosPerFrame ;
drawFps(frameRate.intValue()); if (updateFPMCounter++ > UPDATE_FPM_PERIOD) {
updateFPMCounter = 0;
drawFps(frameRate.intValue());
}
} }
// TODO: 1/05/17 cir27 - Make the RaceObjects update on the actual delay. // TODO: 1/05/17 cir27 - Make the RaceObjects update on the actual delay.
@@ -348,17 +354,14 @@ public class CanvasController {
private void drawFps(int fps){ private void drawFps(int fps){
if (raceViewController.isDisplayFps()){ if (raceViewController.isDisplayFps()){
gc.clearRect(5,5,50,20); gc.clearRect(5, 5, 60, 30);
gc.setFill(Color.SKYBLUE); gc.setFont(new Font(16));
gc.fillRect(4,4,51,21); gc.setLineWidth(4);
gc.setFill(Color.BLACK); gc.setGlobalAlpha(0.75);
gc.setFont(new Font(14));
gc.setLineWidth(3);
gc.fillText(fps + " FPS", 5, 20); gc.fillText(fps + " FPS", 5, 20);
gc.setGlobalAlpha(0.5);
} else { } else {
gc.clearRect(5,5,50,20); gc.clearRect(5,5,60,30);
gc.setFill(Color.SKYBLUE);
gc.fillRect(4,4,51,21);
} }
} }