fix incorrect calling of update method

This commit is contained in:
yugecin 2017-01-10 14:11:15 +01:00
parent 6aefa559f4
commit 90684c084a
4 changed files with 9 additions and 3 deletions

View File

@ -86,7 +86,7 @@ public class Demux implements KeyListener, MouseListener {
} }
public void preRenderUpdate(int delta) { public void preRenderUpdate(int delta) {
state.update(delta); state.preRenderUpdate(delta);
} }
public void render(Graphics g) { public void render(Graphics g) {

View File

@ -96,6 +96,7 @@ public class DisplayContainer {
timeSinceLastRender += delta; timeSinceLastRender += delta;
input.poll(width, height); input.poll(width, height);
demux.update(delta);
int maxRenderInterval; int maxRenderInterval;
if (Display.isVisible() && Display.isActive()) { if (Display.isVisible() && Display.isActive()) {
@ -114,7 +115,7 @@ public class DisplayContainer {
graphics.resetTransform(); graphics.resetTransform();
*/ */
demux.update(timeSinceLastRender); demux.preRenderUpdate(timeSinceLastRender);
demux.render(graphics); demux.render(graphics);
realRenderInterval = timeSinceLastRender; realRenderInterval = timeSinceLastRender;

View File

@ -26,6 +26,7 @@ import yugecin.opsudance.core.state.OpsuState;
public class EmptyRedState implements OpsuState { public class EmptyRedState implements OpsuState {
private int counter; private int counter;
private long start;
private final DisplayContainer displayContainer; private final DisplayContainer displayContainer;
@ -38,6 +39,8 @@ public class EmptyRedState implements OpsuState {
public void update(int delta) { public void update(int delta) {
counter -= delta; counter -= delta;
if (counter < 0) { if (counter < 0) {
counter = 10000; // to prevent more calls to switch, as this will keep rendingering untill state transitioned
System.out.println(System.currentTimeMillis() - start);
displayContainer.switchState(EmptyState.class); displayContainer.switchState(EmptyState.class);
} }
} }
@ -55,6 +58,7 @@ public class EmptyRedState implements OpsuState {
@Override @Override
public void enter() { public void enter() {
counter = 5000; counter = 5000;
start = System.currentTimeMillis();
} }
@Override @Override
@ -63,6 +67,7 @@ public class EmptyRedState implements OpsuState {
@Override @Override
public boolean keyPressed(int key, char c) { public boolean keyPressed(int key, char c) {
System.out.println("pressed");
return false; return false;
} }
@ -73,7 +78,6 @@ public class EmptyRedState implements OpsuState {
@Override @Override
public boolean mouseWheelMoved(int delta) { public boolean mouseWheelMoved(int delta) {
System.out.println("moved");
return false; return false;
} }

View File

@ -38,6 +38,7 @@ public class EmptyState implements OpsuState {
public void update(int delta) { public void update(int delta) {
counter -= delta; counter -= delta;
if (counter < 0) { if (counter < 0) {
counter = 10000; // to prevent more calls to switch, as this will keep rendingering untill state transitioned
displayContainer.switchState(EmptyRedState.class); displayContainer.switchState(EmptyRedState.class);
} }
} }