diff options
Diffstat (limited to '')
-rw-r--r-- | src/main/java/Subconscious.java | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/main/java/Subconscious.java b/src/main/java/Subconscious.java index cbb17dc..59824c2 100644 --- a/src/main/java/Subconscious.java +++ b/src/main/java/Subconscious.java @@ -96,9 +96,9 @@ public class Subconscious @Override public void run() { long beforeTime, afterTime, sleepTime; + int skipFrame = 0; window.setVisible(true); - beforeTime = System.currentTimeMillis(); running = true; @@ -111,6 +111,14 @@ public class Subconscious afterTime = System.currentTimeMillis(); sleepTime = RENDER_PERIOD_MS - (beforeTime - afterTime); + if (sleepTime < 0) { + skipFrame++; + continue; + } + + if (skipFrame > 0) + skipFrame--; + try { Thread.sleep(sleepTime); } catch (InterruptedException ex) {} @@ -138,13 +146,15 @@ public class Subconscious @Override public void mouseReleased(MouseEvent e) {} @Override public void mouseEntered(MouseEvent e) {} @Override public void mouseExited(MouseEvent e) {} - @Override public void mouseClicked(MouseEvent e) { + @Override + public void mouseClicked(MouseEvent e) { currentScene.mouseClicked(e.getX(), e.getY()); } @Override public void keyPressed(KeyEvent e) {} @Override public void keyTyped(KeyEvent e) {} - @Override public void keyReleased(KeyEvent e) { + @Override + public void keyReleased(KeyEvent e) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_Q && e.isControlDown()) { @@ -176,9 +186,10 @@ public class Subconscious } } - @Override public void mouseWheelMoved(MouseWheelEvent e) { + @Override + public void mouseWheelMoved(MouseWheelEvent e) { int value = e.getWheelRotation(); - currentScene.zoom(value*-3); + currentScene.zoom(value * -1); //rerender dbImage = null; } @@ -186,7 +197,8 @@ public class Subconscious @Override public void componentHidden(ComponentEvent e) {} @Override public void componentShown(ComponentEvent e) {} @Override public void componentMoved(ComponentEvent e) {} - @Override public void componentResized(ComponentEvent e) { + @Override + public void componentResized(ComponentEvent e) { dbImage = null; // create new image with the correct size } |