diff --git a/src/sig/engine/Panel.java b/src/sig/engine/Panel.java index b276f93..22605fd 100644 --- a/src/sig/engine/Panel.java +++ b/src/sig/engine/Panel.java @@ -31,8 +31,9 @@ public class Panel extends JPanel implements Runnable,ComponentListener { double y_offset=0; int frameCount=0; long lastSecond=0; - int lastFrameCount=0; boolean resizing=false; + long lastUpdate=System.nanoTime(); + final long TARGET_FRAMETIME = 8333333l; public Panel(JFrame f) { super(true); @@ -78,14 +79,6 @@ public class Panel extends JPanel implements Runnable,ComponentListener { mImageProducer.newPixels(); // draw it on panel g.drawImage(this.imageBuffer, 0, 0, this); - - - if (window!=null&&System.currentTimeMillis()-lastSecond>=1000) { - window.setTitle(RabiClone.PROGRAM_NAME+" - FPS: "+(frameCount-lastFrameCount)); - lastFrameCount=frameCount; - lastSecond=System.currentTimeMillis(); - } - frameCount++; } /** @@ -305,10 +298,36 @@ public class Panel extends JPanel implements Runnable,ComponentListener { // request a JPanel re-drawing repaint(); //System.out.println("Repaint "+frameCount++); - //try {Thread.sleep(1);} catch (InterruptedException e) {} + waitForNextFrame(); } } + private void waitForNextFrame() { + long newTime = System.nanoTime(); + if (newTime-lastUpdate=1000) { + window.setTitle(RabiClone.PROGRAM_NAME+" - FPS: "+(frameCount)); + frameCount=0; + lastSecond=System.currentTimeMillis(); + } + frameCount++; + } + @Override public void componentHidden(ComponentEvent e) { // TODO Auto-generated method stub