summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-11-24 19:37:14 +0100
committerNao Pross <naopross@thearcway.org>2018-11-24 19:37:14 +0100
commit458abd31f29c9fb9926c43bc707bc383a2b5f501 (patch)
tree708c677c2550362143f50eaaaf3e0b41ebf0bb88
parentAdd dynamic widgets (update on every gameloop tick) (diff)
downloadSubconscious-java-458abd31f29c9fb9926c43bc707bc383a2b5f501.tar.gz
Subconscious-java-458abd31f29c9fb9926c43bc707bc383a2b5f501.zip
Add simple PerfView widget to show the deltaTime
-rw-r--r--src/subconscious/graphics/Scene.java6
-rw-r--r--src/subconscious/graphics/widget/PerfView.java28
2 files changed, 34 insertions, 0 deletions
diff --git a/src/subconscious/graphics/Scene.java b/src/subconscious/graphics/Scene.java
index f1a947d..466aa03 100644
--- a/src/subconscious/graphics/Scene.java
+++ b/src/subconscious/graphics/Scene.java
@@ -5,6 +5,7 @@ import subconscious.Game;
import subconscious.graphics.widget.Widget;
import subconscious.graphics.widget.Clickable;
import subconscious.graphics.widget.Dynamic;
+import subconscious.graphics.widget.PerfView;
import java.util.ArrayList;
import java.util.Map;
@@ -103,6 +104,11 @@ public abstract class Scene extends Panel
// this.add(this.canvas, BorderLayout.CENTER);
this.build();
+ // TODO: this will be controlled in the settings
+ this.widgets.add(new PerfView("default-perfview", 0, 0));
+
+ // cache dynamic widgets
+ // TODO: add Scene.addWidget(Widget w) to update these caches
for (Widget w : this.widgets) {
if (w instanceof Dynamic) {
this.dynamicWidgetsCache.add(w);
diff --git a/src/subconscious/graphics/widget/PerfView.java b/src/subconscious/graphics/widget/PerfView.java
new file mode 100644
index 0000000..8aa7c7e
--- /dev/null
+++ b/src/subconscious/graphics/widget/PerfView.java
@@ -0,0 +1,28 @@
+package subconscious.graphics.widget;
+
+import java.awt.Graphics2D;
+
+
+public class PerfView extends Widget implements Dynamic {
+
+ public static final int WIDTH = 120;
+ public static final int HEIGHT = 30;
+
+ protected long lastDeltaNanoTime = 0;
+
+
+ public PerfView(String uniqueName, int x, int y) {
+ super(uniqueName, x, y, PerfView.WIDTH, PerfView.HEIGHT);
+ }
+
+ @Override
+ public void render(Graphics2D g) {
+ g.drawString("DeltaTime (us): ", 0, HEIGHT/2);
+ g.drawString(Long.toString(this.lastDeltaNanoTime/1000), 0, HEIGHT);
+ }
+
+ @Override
+ public void update(long deltaNanoTime) {
+ this.lastDeltaNanoTime = deltaNanoTime;
+ }
+} \ No newline at end of file