diff options
author | Nao Pross <naopross@thearcway.org> | 2018-11-19 00:02:46 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-11-19 00:02:46 +0100 |
commit | bf6bbd5609cd125d8b3e5a7fbe6f2cd49146af49 (patch) | |
tree | d16adf89b93b44c4a040725b54dbfe5ccf84ef14 /src/Scene.java | |
parent | Add gitignore, remove binaries (diff) | |
download | Subconscious-java-master.tar.gz Subconscious-java-master.zip |
Diffstat (limited to 'src/Scene.java')
-rw-r--r-- | src/Scene.java | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Scene.java b/src/Scene.java index dcc3e5e..08608cf 100644 --- a/src/Scene.java +++ b/src/Scene.java @@ -2,6 +2,7 @@ import java.awt.Canvas; import java.awt.Graphics2D; import java.awt.Dimension; import java.awt.BorderLayout; + import java.awt.event.KeyListener; import java.awt.event.KeyEvent; import java.awt.event.MouseListener; @@ -10,20 +11,28 @@ import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelListener; import java.awt.event.MouseWheelEvent; import java.awt.image.BufferStrategy; + import javax.swing.JFrame; import javax.swing.JPanel; +// TODO: implement pause (rendering) function public class Scene extends JPanel implements Runnable, KeyListener, MouseListener, MouseMotionListener, MouseWheelListener { + // TODO: lowercase not constant values protected int WIDTH; protected int HEIGHT; protected BufferStrategy buffer; + // TODO: make final protected long desiredFPS = 60; + // TODO: make final protected long desiredDeltaLoop = (1000*1000*1000)/desiredFPS; protected JFrame frame; protected boolean running; protected Canvas canvas; + + // TODO: make accessible from user settings protected int guiSize = 2; + // TODO: remove sub argument protected Scene(JFrame frame, Sub sub) { this.frame = frame; //getting window size @@ -41,6 +50,7 @@ public class Scene extends JPanel implements Runnable, KeyListener, MouseListen this.canvas.addMouseWheelListener(this); } + // TODO: fix this weird memory shit public void start() { this.canvas.createBufferStrategy(2); this.buffer = this.canvas.getBufferStrategy(); @@ -60,6 +70,7 @@ public class Scene extends JPanel implements Runnable, KeyListener, MouseListen while (running) { beginLoopTime = System.nanoTime(); + // TODO: use WindowEventListener to wait for changes //getting window size this.WIDTH = (int) this.frame.getSize().getWidth(); this.HEIGHT = (int) this.frame.getSize().getHeight(); @@ -74,7 +85,7 @@ public class Scene extends JPanel implements Runnable, KeyListener, MouseListen deltaLoop = endLoopTime - beginLoopTime; if (deltaLoop > this.desiredDeltaLoop) { - //late + // late => skip frame } else { try { Thread.sleep((this.desiredDeltaLoop - deltaLoop)/(1000*1000)); @@ -85,6 +96,7 @@ public class Scene extends JPanel implements Runnable, KeyListener, MouseListen } } + // TODO: make abstract protected void render() {} protected void update(int deltaTime) {} |