From: Svjatoslav Agejenko Date: Thu, 4 May 2023 20:11:23 +0000 (+0300) Subject: Improved code readability X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=037f1a226b5305f605fa15afb1abd9399554eccb;p=sixth-3d.git Improved code readability --- diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewFrame.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewFrame.java index f71e0a5..6a824c8 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewFrame.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewFrame.java @@ -129,11 +129,22 @@ public class ViewFrame extends JFrame implements WindowListener { public void windowDeactivated(final WindowEvent e) { } + /** + * Repaint the view when the window is deiconified. + * + * Deiconified means that the window is restored from minimized state. + */ @Override public void windowDeiconified(final WindowEvent e) { viewPanel.repaintDuringNextViewUpdate(); } + /** + * Do nothing when the window is iconified. + * + * Iconified means that the window is minimized. + * @param e the event to be processed + */ @Override public void windowIconified(final WindowEvent e) { } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java index f6603a0..184ddba 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java @@ -192,7 +192,7 @@ public class ViewPanel extends JPanel implements ComponentListener { * It tells view to update itself. View can decide if actual re-rendering of * graphics is needed. */ - void updateView() { + void ensureThatViewIsUpToDate() { maintainRenderingContext(); final int millisecondsPassedSinceLastUpdate = getMillisecondsPassedSinceLastUpdate(); @@ -221,6 +221,7 @@ public class ViewPanel extends JPanel implements ComponentListener { return; } + // create new rendering context if window size has changed if ((renderingContext == null) || (renderingContext.width != panelWidth) || (renderingContext.height != panelHeight)) { diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewUpdateTimerTask.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewUpdateTimerTask.java index b86dc88..8594a2c 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewUpdateTimerTask.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewUpdateTimerTask.java @@ -4,6 +4,11 @@ */ package eu.svjatoslav.sixth.e3d.gui; +/** + * Timer task that updates view. + * + * Tries to keep constant FPS. + */ public class ViewUpdateTimerTask extends java.util.TimerTask { public ViewPanel viewPanel; @@ -14,9 +19,7 @@ public class ViewUpdateTimerTask extends java.util.TimerTask { @Override public void run() { - - // update and possibly render view - viewPanel.updateView(); + viewPanel.ensureThatViewIsUpToDate(); } }