projects
/
sixth-3d.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed git clone URL
[sixth-3d.git]
/
src
/
main
/
java
/
eu
/
svjatoslav
/
sixth
/
e3d
/
gui
/
ViewPanel.java
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
7cf2b2f
..
e068bf5
100755
(executable)
--- a/
src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java
+++ b/
src/main/java/eu/svjatoslav/sixth/e3d/gui/ViewPanel.java
@@
-1,10
+1,10
@@
/*
/*
- * Sixth 3D engine. Author: Svjatoslav Agejenko.
+ * Sixth 3D engine. Author: Svjatoslav Agejenko.
* This project is released under Creative Commons Zero (CC0) license.
*/
package eu.svjatoslav.sixth.e3d.gui;
* This project is released under Creative Commons Zero (CC0) license.
*/
package eu.svjatoslav.sixth.e3d.gui;
-import eu.svjatoslav.sixth.e3d.gui.humaninput.HID
Inpu
tTracker;
+import eu.svjatoslav.sixth.e3d.gui.humaninput.HID
Even
tTracker;
import eu.svjatoslav.sixth.e3d.gui.humaninput.KeyboardFocusStack;
import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
import eu.svjatoslav.sixth.e3d.gui.humaninput.KeyboardFocusStack;
import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
@@
-18,27
+18,37
@@
import java.util.concurrent.ConcurrentHashMap;
/**
* Java Swing GUI panel that contains canvas for 3D rendering.
/**
* Java Swing GUI panel that contains canvas for 3D rendering.
+ * Usually it is used as a part of {@link ViewFrame}.
*/
public class ViewPanel extends JPanel implements ComponentListener {
private static final long serialVersionUID = 1683277888885045387L;
*/
public class ViewPanel extends JPanel implements ComponentListener {
private static final long serialVersionUID = 1683277888885045387L;
- public Color backgroundColor = Color.BLACK;
- private final HIDInputTracker HIDInputTracker = new HIDInputTracker(this);
+ private final HIDEventTracker HIDEventTracker = new HIDEventTracker(this);
private final KeyboardFocusStack keyboardFocusStack;
private final Avatar avatar = new Avatar();
private final ShapeCollection rootShapeCollection = new ShapeCollection();
private final Set<ViewRenderListener> viewRenderListeners = ConcurrentHashMap.newKeySet();
private final KeyboardFocusStack keyboardFocusStack;
private final Avatar avatar = new Avatar();
private final ShapeCollection rootShapeCollection = new ShapeCollection();
private final Set<ViewRenderListener> viewRenderListeners = ConcurrentHashMap.newKeySet();
+ public Color backgroundColor = Color.BLACK;
+
/**
/**
- * Last time this view was updated.
+ * Stores milliseconds when last frame was updated. This is needed to calculate time delta between frames.
+ * Time delta is used to calculate smooth animation.
*/
private long lastUpdateMillis = 0;
*/
private long lastUpdateMillis = 0;
+
+ /**
+ * Timer that is used to update canvas at target FPS rate.
+ */
private Timer canvasUpdateTimer;
private Timer canvasUpdateTimer;
+
private ViewUpdateTimerTask canvasUpdateTimerTask;
private RenderingContext renderingContext = null;
private ViewUpdateTimerTask canvasUpdateTimerTask;
private RenderingContext renderingContext = null;
+
/**
/**
- * Currently target
FPS for this view. It can be changed at runtime. Also when nothing
- *
changes in the view, then frames are not really repainted
.
+ * Currently target
frames per second rate for this view. Target FPS can be changed at runtime.
+ *
3D engine tries to be smart and only repaints screen when there are visible changes
.
*/
private int targetFPS = 60;
*/
private int targetFPS = 60;
+
/**
* Set to true if it is known than next frame reeds to be painted. Flag is cleared
* immediately after frame got updated.
/**
* Set to true if it is known than next frame reeds to be painted. Flag is cleared
* immediately after frame got updated.
@@
-47,7
+57,7
@@
public class ViewPanel extends JPanel implements ComponentListener {
public ViewPanel() {
viewRenderListeners.add(avatar);
public ViewPanel() {
viewRenderListeners.add(avatar);
- viewRenderListeners.add(HID
Inpu
tTracker);
+ viewRenderListeners.add(HID
Even
tTracker);
keyboardFocusStack = new KeyboardFocusStack(this);
keyboardFocusStack = new KeyboardFocusStack(this);
@@
-70,8
+80,8
@@
public class ViewPanel extends JPanel implements ComponentListener {
return rootShapeCollection;
}
return rootShapeCollection;
}
- public HID
Inpu
tTracker getHIDInputTracker() {
- return HID
Inpu
tTracker;
+ public HID
Even
tTracker getHIDInputTracker() {
+ return HID
Even
tTracker;
}
public void addViewUpdateListener(final ViewRenderListener listener) {
}
public void addViewUpdateListener(final ViewRenderListener listener) {
@@
-143,13
+153,17
@@
public class ViewPanel extends JPanel implements ComponentListener {
}
/**
}
/**
- * Calling th
is
methods tells 3D engine that current 3D view needs to be
+ * Calling th
ese
methods tells 3D engine that current 3D view needs to be
* repainted on first opportunity.
*/
public void repaintDuringNextViewUpdate() {
viewRepaintNeeded = true;
}
* repainted on first opportunity.
*/
public void repaintDuringNextViewUpdate() {
viewRepaintNeeded = true;
}
+ /**
+ * Set target frames per second rate for this view. Target FPS can be changed at runtime.
+ * @param frameRate target frames per second rate for this view.
+ */
public void setFrameRate(final int frameRate) {
if (canvasUpdateTimerTask != null) {
canvasUpdateTimerTask.cancel();
public void setFrameRate(final int frameRate) {
if (canvasUpdateTimerTask != null) {
canvasUpdateTimerTask.cancel();
@@
-161,25
+175,21
@@
public class ViewPanel extends JPanel implements ComponentListener {
targetFPS = frameRate;
targetFPS = frameRate;
- if (frameRate > 0) {
- canvasUpdateTimer = new Timer();
- canvasUpdateTimerTask = new ViewUpdateTimerTask(this);
+ if (frameRate <= 0) return;
- canvasUpdateTimer.schedule(canvasUpdateTimerTask, 0,
- 1000 / frameRate);
- }
+ canvasUpdateTimer = new Timer();
+ canvasUpdateTimerTask = new ViewUpdateTimerTask(this);
+
+ // schedule timer task to run in frequency according to defined frame rate
+ canvasUpdateTimer.schedule(canvasUpdateTimerTask, 0,
+ 1000 / frameRate);
}
}
+ /**
+ * Stops rendering of this view.
+ */
public void stop() {
public void stop() {
- if (canvasUpdateTimerTask != null) {
- canvasUpdateTimerTask.cancel();
- canvasUpdateTimerTask = null;
- }
-
- if (canvasUpdateTimer != null) {
- canvasUpdateTimer.cancel();
- canvasUpdateTimer = null;
- }
+ setFrameRate(0);
}
/**
}
/**
@@
-189,7
+199,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.
*/
* 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();
maintainRenderingContext();
final int millisecondsPassedSinceLastUpdate = getMillisecondsPassedSinceLastUpdate();
@@
-204,7
+214,7
@@
public class ViewPanel extends JPanel implements ComponentListener {
// abort rendering if window size is invalid
if ((getWidth() > 0) && (getHeight() > 0) && renderFrame) {
renderFrame();
// abort rendering if window size is invalid
if ((getWidth() > 0) && (getHeight() > 0) && renderFrame) {
renderFrame();
- viewRepaintNeeded = renderingContext.handle
DetectedComponentMouseEvents
();
+ viewRepaintNeeded = renderingContext.handle
PossibleComponentMouseEvent
();
}
}
}
}
@@
-213,11
+223,12
@@
public class ViewPanel extends JPanel implements ComponentListener {
int panelWidth = getWidth();
int panelHeight = getHeight();
int panelWidth = getWidth();
int panelHeight = getHeight();
- if (panelWidth <= 0 || panelHeight <=
0)
{
+ if (panelWidth <= 0 || panelHeight <=
0)
{
renderingContext = null;
return;
}
renderingContext = null;
return;
}
+ // create new rendering context if window size has changed
if ((renderingContext == null)
|| (renderingContext.width != panelWidth)
|| (renderingContext.height != panelHeight)) {
if ((renderingContext == null)
|| (renderingContext.width != panelWidth)
|| (renderingContext.height != panelHeight)) {