From 90684c084ac75b84baeca4d11cf4e9bc47b8a041 Mon Sep 17 00:00:00 2001 From: yugecin Date: Tue, 10 Jan 2017 14:11:15 +0100 Subject: [PATCH] fix incorrect calling of update method --- src/yugecin/opsudance/core/Demux.java | 2 +- src/yugecin/opsudance/core/DisplayContainer.java | 3 ++- src/yugecin/opsudance/states/EmptyRedState.java | 6 +++++- src/yugecin/opsudance/states/EmptyState.java | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/yugecin/opsudance/core/Demux.java b/src/yugecin/opsudance/core/Demux.java index 0b3014ae..14cf80fd 100644 --- a/src/yugecin/opsudance/core/Demux.java +++ b/src/yugecin/opsudance/core/Demux.java @@ -86,7 +86,7 @@ public class Demux implements KeyListener, MouseListener { } public void preRenderUpdate(int delta) { - state.update(delta); + state.preRenderUpdate(delta); } public void render(Graphics g) { diff --git a/src/yugecin/opsudance/core/DisplayContainer.java b/src/yugecin/opsudance/core/DisplayContainer.java index 80d94085..b09bdb24 100644 --- a/src/yugecin/opsudance/core/DisplayContainer.java +++ b/src/yugecin/opsudance/core/DisplayContainer.java @@ -96,6 +96,7 @@ public class DisplayContainer { timeSinceLastRender += delta; input.poll(width, height); + demux.update(delta); int maxRenderInterval; if (Display.isVisible() && Display.isActive()) { @@ -114,7 +115,7 @@ public class DisplayContainer { graphics.resetTransform(); */ - demux.update(timeSinceLastRender); + demux.preRenderUpdate(timeSinceLastRender); demux.render(graphics); realRenderInterval = timeSinceLastRender; diff --git a/src/yugecin/opsudance/states/EmptyRedState.java b/src/yugecin/opsudance/states/EmptyRedState.java index f1073d0c..b055876b 100644 --- a/src/yugecin/opsudance/states/EmptyRedState.java +++ b/src/yugecin/opsudance/states/EmptyRedState.java @@ -26,6 +26,7 @@ import yugecin.opsudance.core.state.OpsuState; public class EmptyRedState implements OpsuState { private int counter; + private long start; private final DisplayContainer displayContainer; @@ -38,6 +39,8 @@ public class EmptyRedState implements OpsuState { public void update(int delta) { counter -= delta; 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); } } @@ -55,6 +58,7 @@ public class EmptyRedState implements OpsuState { @Override public void enter() { counter = 5000; + start = System.currentTimeMillis(); } @Override @@ -63,6 +67,7 @@ public class EmptyRedState implements OpsuState { @Override public boolean keyPressed(int key, char c) { + System.out.println("pressed"); return false; } @@ -73,7 +78,6 @@ public class EmptyRedState implements OpsuState { @Override public boolean mouseWheelMoved(int delta) { - System.out.println("moved"); return false; } diff --git a/src/yugecin/opsudance/states/EmptyState.java b/src/yugecin/opsudance/states/EmptyState.java index 484795ac..02a1a443 100644 --- a/src/yugecin/opsudance/states/EmptyState.java +++ b/src/yugecin/opsudance/states/EmptyState.java @@ -38,6 +38,7 @@ public class EmptyState implements OpsuState { public void update(int delta) { counter -= delta; if (counter < 0) { + counter = 10000; // to prevent more calls to switch, as this will keep rendingering untill state transitioned displayContainer.switchState(EmptyRedState.class); } }