From 458abd31f29c9fb9926c43bc707bc383a2b5f501 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sat, 24 Nov 2018 19:37:14 +0100 Subject: Add simple PerfView widget to show the deltaTime --- src/subconscious/graphics/Scene.java | 6 ++++++ src/subconscious/graphics/widget/PerfView.java | 28 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/subconscious/graphics/widget/PerfView.java 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 -- cgit v1.2.1