diff --git a/src/yugecin/opsudance/core/Demux.java b/src/yugecin/opsudance/core/Demux.java
index 8ed07ba2..07c9b037 100644
--- a/src/yugecin/opsudance/core/Demux.java
+++ b/src/yugecin/opsudance/core/Demux.java
@@ -22,6 +22,7 @@ import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.KeyListener;
import org.newdawn.slick.MouseListener;
+import yugecin.opsudance.core.state.specialstates.FpsRenderState;
import yugecin.opsudance.core.state.transitions.*;
import yugecin.opsudance.errorhandling.ErrorDumpable;
import yugecin.opsudance.kernel.InstanceContainer;
@@ -36,6 +37,8 @@ public class Demux implements ErrorDumpable, KeyListener, MouseListener {
private final InstanceContainer instanceContainer;
+ private FpsRenderState fpsState;
+
private TransitionState outTransitionState;
private TransitionState inTransitionState;
@@ -71,6 +74,8 @@ public class Demux implements ErrorDumpable, KeyListener, MouseListener {
public void init(Class extends OpsuState> startingState) {
state = instanceContainer.provide(startingState);
state.enter();
+
+ fpsState = instanceContainer.provide(FpsRenderState.class);
}
public boolean isTransitioning() {
@@ -125,6 +130,7 @@ public class Demux implements ErrorDumpable, KeyListener, MouseListener {
public void render(Graphics g) {
state.render(g);
+ fpsState.render(g);
}
public boolean onCloseRequest() {
diff --git a/src/yugecin/opsudance/core/DisplayContainer.java b/src/yugecin/opsudance/core/DisplayContainer.java
index eb3ee1b7..bbfa9c0b 100644
--- a/src/yugecin/opsudance/core/DisplayContainer.java
+++ b/src/yugecin/opsudance/core/DisplayContainer.java
@@ -80,6 +80,8 @@ public class DisplayContainer implements ErrorDumpable {
targetRenderInterval = 16; // ~60 fps
targetBackgroundRenderInterval = 41; // ~24 fps
lastFrame = getTime();
+ delta = 1;
+ realRenderInterval = 1;
}
public void run() throws LWJGLException {
diff --git a/src/yugecin/opsudance/core/state/specialstates/FpsRenderState.java b/src/yugecin/opsudance/core/state/specialstates/FpsRenderState.java
new file mode 100644
index 00000000..5f8eaabf
--- /dev/null
+++ b/src/yugecin/opsudance/core/state/specialstates/FpsRenderState.java
@@ -0,0 +1,63 @@
+/*
+ * opsu!dance - fork of opsu! with cursordance auto
+ * Copyright (C) 2017 yugecin
+ *
+ * opsu!dance is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * opsu!dance is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with opsu!dance. If not, see .
+ */
+package yugecin.opsudance.core.state.specialstates;
+
+import com.google.inject.Inject;
+import itdelatrisu.opsu.ui.Fonts;
+import org.newdawn.slick.Color;
+import org.newdawn.slick.Graphics;
+import yugecin.opsudance.core.DisplayContainer;
+import yugecin.opsudance.core.events.EventListener;
+import yugecin.opsudance.events.ResolutionChangedEvent;
+
+public class FpsRenderState implements EventListener {
+
+ private final DisplayContainer displayContainer;
+
+ private int x;
+ private int y;
+ private int singleHeight;
+
+ @Inject
+ public FpsRenderState(DisplayContainer displayContainer) {
+ this.displayContainer = displayContainer;
+ displayContainer.eventBus.subscribe(ResolutionChangedEvent.class, this);
+ }
+
+ public void render(Graphics g) {
+ int x = this.x;
+ x = drawText(g, (1000 / displayContainer.realRenderInterval) + " fps", x, this.y);
+ drawText(g, (1000 / displayContainer.delta) + " ups", x, this.y);
+ }
+
+ private int drawText(Graphics g, String text, int x, int y) {
+ int width = Fonts.SMALL.getWidth(text) + 10;
+ g.setColor(new Color(0, 0x80, 0));
+ g.fillRoundRect(x - width, y, width, singleHeight + 6, 2);
+ Fonts.SMALL.drawString(x - width + 3, y + 3, text, Color.white);
+ return x - width - 6;
+ }
+
+ @Override
+ public void onEvent(ResolutionChangedEvent event) {
+ singleHeight = Fonts.SMALL.getLineHeight();
+ x = event.width - 3;
+ y = event.height - 3 - singleHeight - 10;
+ }
+
+}
diff --git a/src/yugecin/opsudance/kernel/OpsuDanceModule.java b/src/yugecin/opsudance/kernel/OpsuDanceModule.java
index ce3950d7..ff61f773 100644
--- a/src/yugecin/opsudance/kernel/OpsuDanceModule.java
+++ b/src/yugecin/opsudance/kernel/OpsuDanceModule.java
@@ -22,6 +22,7 @@ import yugecin.opsudance.PreStartupInitializer;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.Demux;
import yugecin.opsudance.core.events.EventBus;
+import yugecin.opsudance.core.state.specialstates.FpsRenderState;
import yugecin.opsudance.core.state.transitions.EmptyTransitionState;
import yugecin.opsudance.errorhandling.ErrorHandler;
import yugecin.opsudance.states.EmptyRedState;
@@ -41,6 +42,8 @@ public class OpsuDanceModule extends AbstractModule {
bind(ErrorHandler.class).asEagerSingleton();
+ bind(FpsRenderState.class).asEagerSingleton();
+
bind(EmptyTransitionState.class).asEagerSingleton();
bind(FadeInTransitionState.class).asEagerSingleton();
bind(FadeOutTransitionState.class).asEagerSingleton();