From 0f6403554351aeb25b8def037c83ef6cdac5d386 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Sat, 13 Aug 2022 19:18:01 +0530 Subject: [PATCH] profiler ui --- compile.hxml | 1 - src/Main.hx | 14 ++++++++------ src/MarbleGame.hx | 2 ++ src/MarbleWorld.hx | 8 ++++++++ src/ProfilerUI.hx | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 src/ProfilerUI.hx diff --git a/compile.hxml b/compile.hxml index 0d5f3c68..532a696f 100644 --- a/compile.hxml +++ b/compile.hxml @@ -5,6 +5,5 @@ -hl marblegame.hl -D windowSize=1280x720 -D keep-inline-positions --D android --main Main -debug \ No newline at end of file diff --git a/src/Main.hx b/src/Main.hx index addb80fa..00be103b 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -16,12 +16,11 @@ import gui.MainMenuGui; import hxd.res.DefaultFont; import h2d.Text; import h3d.Vector; +import src.ProfilerUI; class Main extends hxd.App { var marbleGame:MarbleGame; - // var fpsCounter:Text; - var debugProfiler:h3d.impl.Benchmark; var loaded:Bool = false; override function init() { @@ -64,6 +63,8 @@ class Main extends hxd.App { marbleGame = new MarbleGame(s2d, s3d); MarbleGame.canvas.setContent(new MainMenuGui()); + new ProfilerUI(s2d); + loaded = true; }); @@ -91,19 +92,20 @@ class Main extends hxd.App { override function update(dt:Float) { super.update(dt); if (loaded) { + ProfilerUI.begin(); + ProfilerUI.measure("updateBegin"); marbleGame.update(dt); // world.update(dt); - // fpsCounter.text = 'FPS: ${this.engine.fps}'; + ProfilerUI.update(this.engine.fps); } } override function render(e:h3d.Engine) { // this.world.render(e); if (loaded) { - // debugProfiler.begin(); - // debugProfiler.measure("marbleGame"); + ProfilerUI.measure("renderBegin"); marbleGame.render(e); - // debugProfiler.end(); + ProfilerUI.end(); } super.render(e); } diff --git a/src/MarbleGame.hx b/src/MarbleGame.hx index c803c143..355a56af 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -14,6 +14,7 @@ import src.MarbleWorld; import src.JSPlatform; import gui.Canvas; import src.Util; +import src.ProfilerUI; @:publicFields class MarbleGame { @@ -159,6 +160,7 @@ class MarbleGame { var mouseState:MouseState = { position: new Vector(canvas.scene2d.mouseX, canvas.scene2d.mouseY) } + ProfilerUI.measure("canvasUpdate"); canvas.update(dt, mouseState); } } diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 8cb988b4..7c491418 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -70,6 +70,7 @@ import h3d.scene.Scene; import collision.CollisionWorld; import src.Marble; import src.Resource; +import src.ProfilerUI; class MarbleWorld extends Scheduler { public var collisionWorld:CollisionWorld; @@ -723,18 +724,25 @@ class MarbleWorld extends Scheduler { if (!_ready) { return; } + ProfilerUI.measure("updateTimer"); this.updateTimer(dt); this.tickSchedule(timeState.currentAttemptTime); this.updateGameState(); + ProfilerUI.measure("updateDTS"); for (obj in dtsObjects) { obj.update(timeState); } + ProfilerUI.measure("updateMarbles"); for (marble in marbles) { marble.update(timeState, collisionWorld, this.pathedInteriors); } + ProfilerUI.measure("updateInstances"); this.instanceManager.update(dt); + ProfilerUI.measure("updateParticles"); this.particleManager.update(1000 * timeState.timeSinceLoad, dt); + ProfilerUI.measure("updatePlayGui"); this.playGui.update(timeState); + ProfilerUI.measure("updateAudio"); AudioManager.update(this.scene); if (this.outOfBounds && this.finishTime == null && Key.isDown(Settings.controlsSettings.powerup)) { diff --git a/src/ProfilerUI.hx b/src/ProfilerUI.hx new file mode 100644 index 00000000..b7276790 --- /dev/null +++ b/src/ProfilerUI.hx @@ -0,0 +1,41 @@ +package src; + +import h3d.Vector; +import hxd.res.DefaultFont; +import h2d.Text; + +class ProfilerUI { + var fpsCounter:Text; + var debugProfiler:h3d.impl.Benchmark; + + public static var instance:ProfilerUI; + + 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); + } + + public static function begin() { + // instance.debugProfiler.begin(); + } + + public static function measure(name:String) { + // instance.debugProfiler.measure(name); + } + + public static function end() { + // instance.debugProfiler.end(); + } + + public static function update(fps:Float) { + // instance.fpsCounter.text = "FPS: " + fps; + } +}