mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
add fps display cmd
This commit is contained in:
parent
f7601f1689
commit
313ce01e66
3 changed files with 56 additions and 15 deletions
|
|
@ -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 <scale>");
|
||||
log("drawBounds <true/false>");
|
||||
log("wireframe <true/false>");
|
||||
log("fps <true/false>");
|
||||
} 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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue