colorful fps counters
This commit is contained in:
parent
580b4142f6
commit
14c8fba9cb
|
@ -81,6 +81,9 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
|||
public int mouseX;
|
||||
public int mouseY;
|
||||
|
||||
private int targetUpdatesPerSecond;
|
||||
public int targetUpdateInterval;
|
||||
private int targetRendersPerSecond;
|
||||
public int targetRenderInterval;
|
||||
public int targetBackgroundRenderInterval;
|
||||
|
||||
|
@ -118,13 +121,24 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
|||
};
|
||||
|
||||
this.nativeDisplayMode = Display.getDisplayMode();
|
||||
targetRenderInterval = 16; // ~60 fps
|
||||
setUPS(1000);
|
||||
setFPS(60);
|
||||
targetBackgroundRenderInterval = 41; // ~24 fps
|
||||
lastFrame = getTime();
|
||||
delta = 1;
|
||||
renderDelta = 1;
|
||||
}
|
||||
|
||||
public void setUPS(int ups) {
|
||||
targetUpdatesPerSecond = ups;
|
||||
targetUpdateInterval = 1000 / targetUpdatesPerSecond;
|
||||
}
|
||||
|
||||
public void setFPS(int fps) {
|
||||
targetRendersPerSecond = fps;
|
||||
targetRenderInterval = 1000 / targetRendersPerSecond;
|
||||
}
|
||||
|
||||
public void init(Class<? extends OpsuState> startingState) {
|
||||
state = instanceContainer.provide(startingState);
|
||||
state.enter();
|
||||
|
@ -177,7 +191,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
|||
}
|
||||
|
||||
Display.processMessages();
|
||||
Display.sync(1000); // TODO add option to change this, to not eat CPUs
|
||||
Display.sync(targetUpdatesPerSecond);
|
||||
}
|
||||
teardown();
|
||||
}
|
||||
|
|
|
@ -28,6 +28,10 @@ public class FpsRenderState implements EventListener<ResolutionChangedEvent> {
|
|||
|
||||
private final DisplayContainer displayContainer;
|
||||
|
||||
private final static Color GREEN = new Color(171, 218, 25);
|
||||
private final static Color ORANGE = new Color(255, 204, 34);
|
||||
private final static Color DARKORANGE = new Color(255, 149, 24);
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int singleHeight;
|
||||
|
@ -39,15 +43,26 @@ public class FpsRenderState implements EventListener<ResolutionChangedEvent> {
|
|||
|
||||
public void render(Graphics g) {
|
||||
int x = this.x;
|
||||
x = drawText(g, (1000 / displayContainer.renderDelta) + " fps", x, this.y);
|
||||
drawText(g, (1000 / displayContainer.delta) + " ups", x, this.y);
|
||||
int target = displayContainer.targetRenderInterval - (displayContainer.targetUpdateInterval % displayContainer.targetRenderInterval);
|
||||
x = drawText(g, getColor(target, displayContainer.renderDelta), (1000 / displayContainer.renderDelta) + " fps", x, this.y);
|
||||
drawText(g, getColor(displayContainer.targetUpdateInterval, displayContainer.delta), (1000 / displayContainer.delta) + " ups", x, this.y);
|
||||
}
|
||||
|
||||
private int drawText(Graphics g, String text, int x, int y) {
|
||||
private Color getColor(int targetValue, int realValue) {
|
||||
if (realValue >= targetValue) {
|
||||
return GREEN;
|
||||
}
|
||||
if (realValue >= targetValue * 0.9f) {
|
||||
return ORANGE;
|
||||
}
|
||||
return DARKORANGE;
|
||||
}
|
||||
|
||||
private int drawText(Graphics g, Color color, String text, int x, int y) {
|
||||
int width = Fonts.SMALL.getWidth(text) + 10;
|
||||
g.setColor(new Color(0, 0x80, 0));
|
||||
g.setColor(color);
|
||||
g.fillRoundRect(x - width, y, width, singleHeight + 6, 2);
|
||||
Fonts.SMALL.drawString(x - width + 3, y + 3, text, Color.white);
|
||||
Fonts.SMALL.drawString(x - width + 3, y + 3, text, Color.black);
|
||||
return x - width - 6;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user