profiler ui

This commit is contained in:
RandomityGuy 2022-08-13 19:18:01 +05:30
parent d970c87015
commit 0f64035543
5 changed files with 59 additions and 7 deletions

View file

@ -5,6 +5,5 @@
-hl marblegame.hl -hl marblegame.hl
-D windowSize=1280x720 -D windowSize=1280x720
-D keep-inline-positions -D keep-inline-positions
-D android
--main Main --main Main
-debug -debug

View file

@ -16,12 +16,11 @@ import gui.MainMenuGui;
import hxd.res.DefaultFont; import hxd.res.DefaultFont;
import h2d.Text; import h2d.Text;
import h3d.Vector; import h3d.Vector;
import src.ProfilerUI;
class Main extends hxd.App { class Main extends hxd.App {
var marbleGame:MarbleGame; var marbleGame:MarbleGame;
// var fpsCounter:Text;
var debugProfiler:h3d.impl.Benchmark;
var loaded:Bool = false; var loaded:Bool = false;
override function init() { override function init() {
@ -64,6 +63,8 @@ class Main extends hxd.App {
marbleGame = new MarbleGame(s2d, s3d); marbleGame = new MarbleGame(s2d, s3d);
MarbleGame.canvas.setContent(new MainMenuGui()); MarbleGame.canvas.setContent(new MainMenuGui());
new ProfilerUI(s2d);
loaded = true; loaded = true;
}); });
@ -91,19 +92,20 @@ class Main extends hxd.App {
override function update(dt:Float) { override function update(dt:Float) {
super.update(dt); super.update(dt);
if (loaded) { if (loaded) {
ProfilerUI.begin();
ProfilerUI.measure("updateBegin");
marbleGame.update(dt); marbleGame.update(dt);
// world.update(dt); // world.update(dt);
// fpsCounter.text = 'FPS: ${this.engine.fps}'; ProfilerUI.update(this.engine.fps);
} }
} }
override function render(e:h3d.Engine) { override function render(e:h3d.Engine) {
// this.world.render(e); // this.world.render(e);
if (loaded) { if (loaded) {
// debugProfiler.begin(); ProfilerUI.measure("renderBegin");
// debugProfiler.measure("marbleGame");
marbleGame.render(e); marbleGame.render(e);
// debugProfiler.end(); ProfilerUI.end();
} }
super.render(e); super.render(e);
} }

View file

@ -14,6 +14,7 @@ import src.MarbleWorld;
import src.JSPlatform; import src.JSPlatform;
import gui.Canvas; import gui.Canvas;
import src.Util; import src.Util;
import src.ProfilerUI;
@:publicFields @:publicFields
class MarbleGame { class MarbleGame {
@ -159,6 +160,7 @@ class MarbleGame {
var mouseState:MouseState = { var mouseState:MouseState = {
position: new Vector(canvas.scene2d.mouseX, canvas.scene2d.mouseY) position: new Vector(canvas.scene2d.mouseX, canvas.scene2d.mouseY)
} }
ProfilerUI.measure("canvasUpdate");
canvas.update(dt, mouseState); canvas.update(dt, mouseState);
} }
} }

View file

@ -70,6 +70,7 @@ import h3d.scene.Scene;
import collision.CollisionWorld; import collision.CollisionWorld;
import src.Marble; import src.Marble;
import src.Resource; import src.Resource;
import src.ProfilerUI;
class MarbleWorld extends Scheduler { class MarbleWorld extends Scheduler {
public var collisionWorld:CollisionWorld; public var collisionWorld:CollisionWorld;
@ -723,18 +724,25 @@ class MarbleWorld extends Scheduler {
if (!_ready) { if (!_ready) {
return; return;
} }
ProfilerUI.measure("updateTimer");
this.updateTimer(dt); this.updateTimer(dt);
this.tickSchedule(timeState.currentAttemptTime); this.tickSchedule(timeState.currentAttemptTime);
this.updateGameState(); this.updateGameState();
ProfilerUI.measure("updateDTS");
for (obj in dtsObjects) { for (obj in dtsObjects) {
obj.update(timeState); obj.update(timeState);
} }
ProfilerUI.measure("updateMarbles");
for (marble in marbles) { for (marble in marbles) {
marble.update(timeState, collisionWorld, this.pathedInteriors); marble.update(timeState, collisionWorld, this.pathedInteriors);
} }
ProfilerUI.measure("updateInstances");
this.instanceManager.update(dt); this.instanceManager.update(dt);
ProfilerUI.measure("updateParticles");
this.particleManager.update(1000 * timeState.timeSinceLoad, dt); this.particleManager.update(1000 * timeState.timeSinceLoad, dt);
ProfilerUI.measure("updatePlayGui");
this.playGui.update(timeState); this.playGui.update(timeState);
ProfilerUI.measure("updateAudio");
AudioManager.update(this.scene); AudioManager.update(this.scene);
if (this.outOfBounds && this.finishTime == null && Key.isDown(Settings.controlsSettings.powerup)) { if (this.outOfBounds && this.finishTime == null && Key.isDown(Settings.controlsSettings.powerup)) {

41
src/ProfilerUI.hx Normal file
View file

@ -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;
}
}