Skip to content

Commit

Permalink
Merge pull request #2810 from rpaladin/method-get-framerate
Browse files Browse the repository at this point in the history
New getFramerate() method
  • Loading branch information
luboslenco committed Feb 27, 2023
2 parents e86ee6d + 8ed3bb3 commit 1e0c016
Showing 1 changed file with 59 additions and 52 deletions.
111 changes: 59 additions & 52 deletions Sources/armory/trait/internal/DebugConsole.hx
Expand Up @@ -27,6 +27,7 @@ class DebugConsole extends Trait {

public static var visible = true;
public static var traceWithPosition = true;
public static var fpsAvg = 0.0;

static var ui: Zui;
var scaleFactor = 1.0;
Expand Down Expand Up @@ -177,9 +178,62 @@ class DebugConsole extends Trait {
}

function render2D(g: kha.graphics2.Graphics) {
if (!visible) return;
var hwin = Id.handle();
var htab = Id.handle({position: 0});

var avg = Math.round(frameTimeAvg * 10000) / 10;
fpsAvg = avg > 0 ? Math.round(1000 / avg) : 0;

totalTime += frameTime;
renderPathTime += iron.App.renderPathTime;
frames++;
if (totalTime > 1.0) {
hwin.redraws = 1;
var t = totalTime / frames;
// Second frame
if (frameTimeAvg > 0) {
if (t < frameTimeAvgMin || frameTimeAvgMin == 0) frameTimeAvgMin = t;
if (t > frameTimeAvgMax || frameTimeAvgMax == 0) frameTimeAvgMax = t;
}

frameTimeAvg = t;

if (benchmark) {
benchFrames++;
if (benchFrames > 10) benchTime += t;
if (benchFrames == 20) trace(Std.int((benchTime / 10) * 1000000) / 1000); // ms
}

renderPathTimeAvg = renderPathTime / frames;
updateTimeAvg = updateTime / frames;
animTimeAvg = animTime / frames;
physTimeAvg = physTime / frames;

#if arm_shadowmap_atlas
smaLogicTimeAvg = smaLogicTime / frames;
smaLogicTime = 0;

smaRenderTimeAvg = smaRenderTime / frames;
smaRenderTime = 0;
#end

totalTime = 0;
renderPathTime = 0;
updateTime = 0;
animTime = 0;
physTime = 0;
frames = 0;

if (htab.position == 2) {
g.end();
updateGraph(); // Profile tab selected
g.begin(false);
}
}
frameTime = Scheduler.realTime() - lastTime;
lastTime = Scheduler.realTime();

if (!visible) return;
var ww = Std.int(280 * scaleFactor * getScale());
// RIGHT
var wx = iron.App.w() - ww;
Expand Down Expand Up @@ -489,8 +543,6 @@ class DebugConsole extends Trait {
}
}

var avg = Math.round(frameTimeAvg * 10000) / 10;
var fpsAvg = avg > 0 ? Math.round(1000 / avg) : 0;
if (ui.tab(htab, '$avg ms')) {

if (ui.panel(Id.handle({selected: true}), "Performance")) {
Expand Down Expand Up @@ -898,55 +950,6 @@ class DebugConsole extends Trait {

ui.end(bindG);
if (bindG) g.begin(false);

totalTime += frameTime;
renderPathTime += iron.App.renderPathTime;
frames++;
if (totalTime > 1.0) {
hwin.redraws = 1;
var t = totalTime / frames;
// Second frame
if (frameTimeAvg > 0) {
if (t < frameTimeAvgMin || frameTimeAvgMin == 0) frameTimeAvgMin = t;
if (t > frameTimeAvgMax || frameTimeAvgMax == 0) frameTimeAvgMax = t;
}

frameTimeAvg = t;

if (benchmark) {
benchFrames++;
if (benchFrames > 10) benchTime += t;
if (benchFrames == 20) trace(Std.int((benchTime / 10) * 1000000) / 1000); // ms
}

renderPathTimeAvg = renderPathTime / frames;
updateTimeAvg = updateTime / frames;
animTimeAvg = animTime / frames;
physTimeAvg = physTime / frames;

#if arm_shadowmap_atlas
smaLogicTimeAvg = smaLogicTime / frames;
smaLogicTime = 0;

smaRenderTimeAvg = smaRenderTime / frames;
smaRenderTime = 0;
#end

totalTime = 0;
renderPathTime = 0;
updateTime = 0;
animTime = 0;
physTime = 0;
frames = 0;

if (htab.position == 2) {
g.end();
updateGraph(); // Profile tab selected
g.begin(false);
}
}
frameTime = Scheduler.realTime() - lastTime;
lastTime = Scheduler.realTime();
}

function update() {
Expand Down Expand Up @@ -990,6 +993,10 @@ class DebugConsole extends Trait {
public static function getPosition(): PositionStateEnum {
return positionConsole;
}

public static function getFramerate(): Float {
return fpsAvg;
}
#end
}

Expand Down

0 comments on commit 1e0c016

Please sign in to comment.