mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-26 04:31:40 +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.Settings;
|
||||||
import src.Debug;
|
import src.Debug;
|
||||||
import src.MarbleGame;
|
import src.MarbleGame;
|
||||||
|
import src.ProfilerUI;
|
||||||
|
|
||||||
@:publicFields
|
@:publicFields
|
||||||
class ConsoleEntry {
|
class ConsoleEntry {
|
||||||
|
|
@ -122,6 +123,7 @@ class Console {
|
||||||
log("rewindTimeScale <scale>");
|
log("rewindTimeScale <scale>");
|
||||||
log("drawBounds <true/false>");
|
log("drawBounds <true/false>");
|
||||||
log("wireframe <true/false>");
|
log("wireframe <true/false>");
|
||||||
|
log("fps <true/false>");
|
||||||
} else if (cmdType == "timeScale") {
|
} else if (cmdType == "timeScale") {
|
||||||
if (cmdSplit.length == 2) {
|
if (cmdSplit.length == 2) {
|
||||||
var scale = Std.parseFloat(cmdSplit[1]);
|
var scale = Std.parseFloat(cmdSplit[1]);
|
||||||
|
|
@ -163,6 +165,14 @@ class Console {
|
||||||
} else {
|
} else {
|
||||||
error("Expected one argument, got " + (cmdSplit.length - 1));
|
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 {
|
} else {
|
||||||
error("Unknown command");
|
error("Unknown command");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,38 +7,69 @@ import h2d.Text;
|
||||||
class ProfilerUI {
|
class ProfilerUI {
|
||||||
var fpsCounter:Text;
|
var fpsCounter:Text;
|
||||||
var debugProfiler:h3d.impl.Benchmark;
|
var debugProfiler:h3d.impl.Benchmark;
|
||||||
|
var s2d:h2d.Scene;
|
||||||
|
|
||||||
public var fps:Float;
|
public var fps:Float;
|
||||||
|
|
||||||
public static var instance:ProfilerUI;
|
public static var instance:ProfilerUI;
|
||||||
|
|
||||||
|
static var enabled:Bool = false;
|
||||||
|
|
||||||
public function new(s2d:h2d.Scene) {
|
public function new(s2d:h2d.Scene) {
|
||||||
if (instance != null)
|
if (instance != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
instance = this;
|
instance = this;
|
||||||
// debugProfiler = new h3d.impl.Benchmark(s2d);
|
this.s2d = s2d;
|
||||||
// debugProfiler.y = 40;
|
|
||||||
|
|
||||||
// fpsCounter = new Text(DefaultFont.get(), s2d);
|
|
||||||
// fpsCounter.y = 80;
|
|
||||||
// fpsCounter.color = new Vector(1, 1, 1, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function begin() {
|
public static function begin() {
|
||||||
// instance.debugProfiler.begin();
|
if (!enabled)
|
||||||
|
return;
|
||||||
|
instance.debugProfiler.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function measure(name:String) {
|
public static function measure(name:String) {
|
||||||
// instance.debugProfiler.measure(name);
|
if (!enabled)
|
||||||
|
return;
|
||||||
|
instance.debugProfiler.measure(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function end() {
|
public static function end() {
|
||||||
// instance.debugProfiler.end();
|
if (!enabled)
|
||||||
|
return;
|
||||||
|
instance.debugProfiler.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function update(fps:Float) {
|
public static function update(fps:Float) {
|
||||||
instance.fps = fps;
|
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);
|
retryButton.pressedAction = (e) -> restartFunc(retryButton);
|
||||||
bottomBar.addChild(retryButton);
|
bottomBar.addChild(retryButton);
|
||||||
|
|
||||||
var lbButton = new GuiXboxButton("Leaderboard", 220);
|
// var lbButton = new GuiXboxButton("Leaderboard", 220);
|
||||||
lbButton.position = new Vector(750, 0);
|
// lbButton.position = new Vector(750, 0);
|
||||||
lbButton.vertSizing = Bottom;
|
// lbButton.vertSizing = Bottom;
|
||||||
lbButton.horizSizing = Right;
|
// lbButton.horizSizing = Right;
|
||||||
bottomBar.addChild(lbButton);
|
// bottomBar.addChild(lbButton);
|
||||||
|
|
||||||
var nextButton = new GuiXboxButton("Next", 160);
|
var nextButton = new GuiXboxButton("Next", 160);
|
||||||
nextButton.position = new Vector(960, 0);
|
nextButton.position = new Vector(960, 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue