This commit is contained in:
yugecin 2017-01-15 23:38:20 +01:00
parent 7c79deac65
commit 07d15eeb56
4 changed files with 74 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import org.newdawn.slick.KeyListener; import org.newdawn.slick.KeyListener;
import org.newdawn.slick.MouseListener; import org.newdawn.slick.MouseListener;
import yugecin.opsudance.core.state.specialstates.FpsRenderState;
import yugecin.opsudance.core.state.transitions.*; import yugecin.opsudance.core.state.transitions.*;
import yugecin.opsudance.errorhandling.ErrorDumpable; import yugecin.opsudance.errorhandling.ErrorDumpable;
import yugecin.opsudance.kernel.InstanceContainer; import yugecin.opsudance.kernel.InstanceContainer;
@ -36,6 +37,8 @@ public class Demux implements ErrorDumpable, KeyListener, MouseListener {
private final InstanceContainer instanceContainer; private final InstanceContainer instanceContainer;
private FpsRenderState fpsState;
private TransitionState outTransitionState; private TransitionState outTransitionState;
private TransitionState inTransitionState; private TransitionState inTransitionState;
@ -71,6 +74,8 @@ public class Demux implements ErrorDumpable, KeyListener, MouseListener {
public void init(Class<? extends OpsuState> startingState) { public void init(Class<? extends OpsuState> startingState) {
state = instanceContainer.provide(startingState); state = instanceContainer.provide(startingState);
state.enter(); state.enter();
fpsState = instanceContainer.provide(FpsRenderState.class);
} }
public boolean isTransitioning() { public boolean isTransitioning() {
@ -125,6 +130,7 @@ public class Demux implements ErrorDumpable, KeyListener, MouseListener {
public void render(Graphics g) { public void render(Graphics g) {
state.render(g); state.render(g);
fpsState.render(g);
} }
public boolean onCloseRequest() { public boolean onCloseRequest() {

View File

@ -80,6 +80,8 @@ public class DisplayContainer implements ErrorDumpable {
targetRenderInterval = 16; // ~60 fps targetRenderInterval = 16; // ~60 fps
targetBackgroundRenderInterval = 41; // ~24 fps targetBackgroundRenderInterval = 41; // ~24 fps
lastFrame = getTime(); lastFrame = getTime();
delta = 1;
realRenderInterval = 1;
} }
public void run() throws LWJGLException { public void run() throws LWJGLException {

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<ResolutionChangedEvent> {
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;
}
}

View File

@ -22,6 +22,7 @@ import yugecin.opsudance.PreStartupInitializer;
import yugecin.opsudance.core.DisplayContainer; import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.Demux; import yugecin.opsudance.core.Demux;
import yugecin.opsudance.core.events.EventBus; import yugecin.opsudance.core.events.EventBus;
import yugecin.opsudance.core.state.specialstates.FpsRenderState;
import yugecin.opsudance.core.state.transitions.EmptyTransitionState; import yugecin.opsudance.core.state.transitions.EmptyTransitionState;
import yugecin.opsudance.errorhandling.ErrorHandler; import yugecin.opsudance.errorhandling.ErrorHandler;
import yugecin.opsudance.states.EmptyRedState; import yugecin.opsudance.states.EmptyRedState;
@ -41,6 +42,8 @@ public class OpsuDanceModule extends AbstractModule {
bind(ErrorHandler.class).asEagerSingleton(); bind(ErrorHandler.class).asEagerSingleton();
bind(FpsRenderState.class).asEagerSingleton();
bind(EmptyTransitionState.class).asEagerSingleton(); bind(EmptyTransitionState.class).asEagerSingleton();
bind(FadeInTransitionState.class).asEagerSingleton(); bind(FadeInTransitionState.class).asEagerSingleton();
bind(FadeOutTransitionState.class).asEagerSingleton(); bind(FadeOutTransitionState.class).asEagerSingleton();