From 8c8245500fd4d5898906ade204714a0624af5e9d Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Tue, 11 Jul 2023 19:40:37 +0530 Subject: [PATCH] add fps display cmd --- src/Console.hx | 10 +++++++++ src/ProfilerUI.hx | 51 ++++++++++++++++++++++++++++++++++--------- src/gui/EndGameGui.hx | 10 ++++----- 3 files changed, 56 insertions(+), 15 deletions(-) diff --git a/src/Console.hx b/src/Console.hx index 310e6d00..2a2b6740 100644 --- a/src/Console.hx +++ b/src/Console.hx @@ -7,6 +7,7 @@ import mis.MisParser; import src.Settings; import src.Debug; import src.MarbleGame; +import src.ProfilerUI; @:publicFields class ConsoleEntry { @@ -122,6 +123,7 @@ class Console { log("rewindTimeScale "); log("drawBounds "); log("wireframe "); + log("fps "); } else if (cmdType == "timeScale") { if (cmdSplit.length == 2) { var scale = Std.parseFloat(cmdSplit[1]); @@ -163,6 +165,14 @@ class Console { } else { error("Expected one argument, got " + (cmdSplit.length - 1)); } + } else if (cmdType == "fps") { + if (cmdSplit.length == 2) { + var scale = MisParser.parseBoolean(cmdSplit[1]); + ProfilerUI.setEnabled(scale); + log("FPS Display set to " + scale); + } else { + error("Expected one argument, got " + (cmdSplit.length - 1)); + } } else { error("Unknown command"); } diff --git a/src/ProfilerUI.hx b/src/ProfilerUI.hx index 4d30d88e..80933f74 100644 --- a/src/ProfilerUI.hx +++ b/src/ProfilerUI.hx @@ -7,38 +7,69 @@ import h2d.Text; class ProfilerUI { var fpsCounter:Text; var debugProfiler:h3d.impl.Benchmark; + var s2d:h2d.Scene; public var fps:Float; public static var instance:ProfilerUI; + static var enabled:Bool = false; + public function new(s2d:h2d.Scene) { if (instance != null) return; instance = this; - // debugProfiler = new h3d.impl.Benchmark(s2d); - // debugProfiler.y = 40; - - // fpsCounter = new Text(DefaultFont.get(), s2d); - // fpsCounter.y = 80; - // fpsCounter.color = new Vector(1, 1, 1, 1); + this.s2d = s2d; } public static function begin() { - // instance.debugProfiler.begin(); + if (!enabled) + return; + instance.debugProfiler.begin(); } public static function measure(name:String) { - // instance.debugProfiler.measure(name); + if (!enabled) + return; + instance.debugProfiler.measure(name); } public static function end() { - // instance.debugProfiler.end(); + if (!enabled) + return; + instance.debugProfiler.end(); } public static function update(fps:Float) { instance.fps = fps; - // instance.fpsCounter.text = "FPS: " + fps; + if (!enabled) + return; + instance.fpsCounter.text = "FPS: " + fps; + } + + public static function setEnabled(val:Bool) { + enabled = val; + if (enabled) { + if (instance.debugProfiler != null) { + instance.debugProfiler.remove(); + instance.debugProfiler = null; + } + if (instance.fpsCounter != null) { + instance.fpsCounter.remove(); + instance.fpsCounter = null; + } + instance.debugProfiler = new h3d.impl.Benchmark(instance.s2d); + instance.debugProfiler.y = 40; + + instance.fpsCounter = new Text(DefaultFont.get(), instance.s2d); + instance.fpsCounter.y = 80; + instance.fpsCounter.color = new Vector(1, 1, 1, 1); + } else { + instance.debugProfiler.remove(); + instance.fpsCounter.remove(); + instance.debugProfiler = null; + instance.fpsCounter = null; + } } } diff --git a/src/gui/EndGameGui.hx b/src/gui/EndGameGui.hx index 26c3f0aa..e10a4e23 100644 --- a/src/gui/EndGameGui.hx +++ b/src/gui/EndGameGui.hx @@ -157,11 +157,11 @@ class EndGameGui extends GuiImage { retryButton.pressedAction = (e) -> restartFunc(retryButton); bottomBar.addChild(retryButton); - var lbButton = new GuiXboxButton("Leaderboard", 220); - lbButton.position = new Vector(750, 0); - lbButton.vertSizing = Bottom; - lbButton.horizSizing = Right; - bottomBar.addChild(lbButton); + // var lbButton = new GuiXboxButton("Leaderboard", 220); + // lbButton.position = new Vector(750, 0); + // lbButton.vertSizing = Bottom; + // lbButton.horizSizing = Right; + // bottomBar.addChild(lbButton); var nextButton = new GuiXboxButton("Next", 160); nextButton.position = new Vector(960, 0);