don't pass deltas as param

This commit is contained in:
yugecin 2017-01-17 18:45:17 +01:00
parent f0883ff1af
commit 580b4142f6
8 changed files with 27 additions and 25 deletions

View File

@ -84,7 +84,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
public int targetRenderInterval; public int targetRenderInterval;
public int targetBackgroundRenderInterval; public int targetBackgroundRenderInterval;
public int realRenderInterval; public int renderDelta;
public int delta; public int delta;
public int timeSinceLastRender; public int timeSinceLastRender;
@ -122,7 +122,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
targetBackgroundRenderInterval = 41; // ~24 fps targetBackgroundRenderInterval = 41; // ~24 fps
lastFrame = getTime(); lastFrame = getTime();
delta = 1; delta = 1;
realRenderInterval = 1; renderDelta = 1;
} }
public void init(Class<? extends OpsuState> startingState) { public void init(Class<? extends OpsuState> startingState) {
@ -144,7 +144,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
input.poll(width, height); input.poll(width, height);
mouseX = input.getMouseX(); mouseX = input.getMouseX();
mouseY = input.getMouseY(); mouseY = input.getMouseY();
state.update(delta); state.update();
int maxRenderInterval; int maxRenderInterval;
if (Display.isVisible() && Display.isActive()) { if (Display.isVisible() && Display.isActive()) {
@ -163,13 +163,14 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
graphics.resetTransform(); graphics.resetTransform();
*/ */
state.preRenderUpdate(timeSinceLastRender); renderDelta = timeSinceLastRender;
state.preRenderUpdate();
state.render(graphics); state.render(graphics);
fpsState.render(graphics); fpsState.render(graphics);
bubNotifState.render(graphics, timeSinceLastRender); bubNotifState.render(graphics);
barNotifState.render(graphics, timeSinceLastRender); barNotifState.render(graphics);
realRenderInterval = timeSinceLastRender;
timeSinceLastRender = 0; timeSinceLastRender = 0;
Display.update(false); Display.update(false);

View File

@ -22,8 +22,8 @@ import yugecin.opsudance.core.errorhandling.ErrorDumpable;
public interface OpsuState extends ErrorDumpable { public interface OpsuState extends ErrorDumpable {
void update(int delta); void update();
void preRenderUpdate(int delta); void preRenderUpdate();
void render(Graphics g); void render(Graphics g);
void enter(); void enter();
void leave(); void leave();

View File

@ -66,11 +66,11 @@ public class BarNotificationState implements EventListener<BarNotificationEvent>
}); });
} }
public void render(Graphics g, int delta) { public void render(Graphics g) {
if (timeShown >= TOTAL_TIME) { if (timeShown >= TOTAL_TIME) {
return; return;
} }
timeShown += delta; timeShown += displayContainer.renderDelta;
processAnimations(); processAnimations();
g.setColor(bgcol); g.setColor(bgcol);
g.fillRect(0, displayContainer.height / 2 - barHalfHeight, displayContainer.width, barHalfHeight * 2); g.fillRect(0, displayContainer.height / 2 - barHalfHeight, displayContainer.width, barHalfHeight * 2);

View File

@ -57,12 +57,12 @@ public class BubbleNotificationState implements EventListener<BubbleNotification
}); });
} }
public void render(Graphics g, int delta) { public void render(Graphics g) {
ListIterator<Notification> iter = bubbles.listIterator(); ListIterator<Notification> iter = bubbles.listIterator();
if (!iter.hasNext()) { if (!iter.hasNext()) {
return; return;
} }
addAnimationTime += delta; addAnimationTime += displayContainer.renderDelta;
if (addAnimationTime > IN_TIME) { if (addAnimationTime > IN_TIME) {
finishAddAnimation(); finishAddAnimation();
} }
@ -72,7 +72,7 @@ public class BubbleNotificationState implements EventListener<BubbleNotification
if (animateUp && addAnimationTime < IN_TIME) { if (animateUp && addAnimationTime < IN_TIME) {
next.y = next.baseY - (int) (addAnimationHeight * AnimationEquation.OUT_QUINT.calc((float) addAnimationTime / IN_TIME)); next.y = next.baseY - (int) (addAnimationHeight * AnimationEquation.OUT_QUINT.calc((float) addAnimationTime / IN_TIME));
} }
if (next.render(g, displayContainer.mouseX, displayContainer.mouseY, delta)) { if (next.render(g, displayContainer.mouseX, displayContainer.mouseY, displayContainer.renderDelta)) {
iter.remove(); iter.remove();
} }
animateUp = true; animateUp = true;

View File

@ -39,7 +39,7 @@ public class FpsRenderState implements EventListener<ResolutionChangedEvent> {
public void render(Graphics g) { public void render(Graphics g) {
int x = this.x; int x = this.x;
x = drawText(g, (1000 / displayContainer.realRenderInterval) + " fps", x, this.y); x = drawText(g, (1000 / displayContainer.renderDelta) + " fps", x, this.y);
drawText(g, (1000 / displayContainer.delta) + " ups", x, this.y); drawText(g, (1000 / displayContainer.delta) + " ups", x, this.y);
} }

View File

@ -49,16 +49,17 @@ public abstract class TransitionState extends BaseOpsuState {
} }
@Override @Override
public void update(int delta) { public void update() {
applicableState.update(delta); applicableState.update();
transitionTime += delta; transitionTime += displayContainer.delta;
if (transitionTime >= transitionTargetTime) { if (transitionTime >= transitionTargetTime) {
finish(); finish();
} }
} }
@Override @Override
public void preRenderUpdate(int delta) { public void preRenderUpdate() {
applicableState.preRenderUpdate();
} }
@Override @Override

View File

@ -38,8 +38,8 @@ public class EmptyRedState implements OpsuState {
} }
@Override @Override
public void update(int delta) { public void update() {
counter -= delta; counter -= displayContainer.delta;
if (counter < 0) { if (counter < 0) {
counter = 10000; // to prevent more calls to switch, as this will keep rendering until state transitioned counter = 10000; // to prevent more calls to switch, as this will keep rendering until state transitioned
System.out.println(System.currentTimeMillis() - start); System.out.println(System.currentTimeMillis() - start);
@ -48,7 +48,7 @@ public class EmptyRedState implements OpsuState {
} }
@Override @Override
public void preRenderUpdate(int delta) { public void preRenderUpdate() {
} }
@Override @Override

View File

@ -35,8 +35,8 @@ public class EmptyState implements OpsuState {
} }
@Override @Override
public void update(int delta) { public void update() {
counter -= delta; counter -= displayContainer.delta;
if (counter < 0) { if (counter < 0) {
counter = 10000; // to prevent more calls to switch, as this will keep rending until state transitioned counter = 10000; // to prevent more calls to switch, as this will keep rending until state transitioned
displayContainer.switchState(EmptyRedState.class); displayContainer.switchState(EmptyRedState.class);
@ -44,7 +44,7 @@ public class EmptyState implements OpsuState {
} }
@Override @Override
public void preRenderUpdate(int delta) { public void preRenderUpdate() {
} }
@Override @Override