armory/Sources/armory/trait/internal/DebugConsole.hx

199 lines
5.5 KiB
Haxe
Raw Normal View History

2016-07-21 17:45:39 +02:00
package armory.trait.internal;
import iron.Trait;
2017-11-12 21:56:01 +01:00
#if arm_debug
2016-07-22 23:25:07 +02:00
import kha.Scheduler;
2016-08-25 00:26:01 +02:00
import iron.object.CameraObject;
2016-12-05 01:54:01 +01:00
import iron.object.MeshObject;
2017-02-28 13:48:19 +01:00
import zui.Zui;
import zui.Id;
2016-07-21 17:45:39 +02:00
#end
2017-08-23 22:53:39 +02:00
@:access(zui.Zui)
2017-05-06 00:22:15 +02:00
class DebugConsole extends Trait {
2016-07-21 17:45:39 +02:00
2017-11-12 21:56:01 +01:00
#if (!arm_debug)
2016-10-15 20:19:09 +02:00
public function new() { super(); }
2016-07-21 17:45:39 +02:00
#else
2017-02-28 13:48:19 +01:00
var ui:Zui;
2016-07-21 17:45:39 +02:00
2016-10-15 20:19:09 +02:00
var lastTime = 0.0;
var frameTime = 0.0;
var totalTime = 0.0;
var frames = 0;
2016-07-22 23:25:07 +02:00
2017-02-28 13:48:19 +01:00
var frameTimeAvg = 0.0;
var frameTimeAvgMin = 0.0;
var frameTimeAvgMax = 0.0;
2017-05-13 10:44:17 +02:00
var renderPathTime = 0.0;
var renderPathTimeAvg = 0.0;
2017-02-28 13:48:19 +01:00
var updateTime = 0.0;
var updateTimeAvg = 0.0;
2017-05-13 10:44:17 +02:00
var animTime = 0.0;
var animTimeAvg = 0.0;
2017-02-28 13:48:19 +01:00
var physTime = 0.0;
var physTimeAvg = 0.0;
2016-07-22 23:25:07 +02:00
2016-10-15 20:19:09 +02:00
public function new() {
super();
2016-07-21 17:45:39 +02:00
2017-02-28 13:48:19 +01:00
iron.data.Data.getFont('droid_sans.ttf', function(font:kha.Font) {
2017-05-12 21:49:42 +02:00
var theme = Reflect.copy(zui.Themes.dark);
theme.WINDOW_BG_COL = 0xee111111;
ui = new Zui({font: font, theme: theme});
2016-10-15 20:19:09 +02:00
notifyOnRender2D(render2D);
notifyOnUpdate(update);
2017-05-06 00:22:15 +02:00
haxeTrace = haxe.Log.trace;
haxe.Log.trace = consoleTrace;
2016-10-15 20:19:09 +02:00
});
}
2016-07-21 17:45:39 +02:00
2017-05-06 00:22:15 +02:00
static var haxeTrace:Dynamic->haxe.PosInfos->Void;
static var lastTrace = '';
static function consoleTrace(v:Dynamic, ?inf:haxe.PosInfos) {
lastTrace = Std.string(v);
haxeTrace(v, inf);
}
2017-08-22 23:34:53 +02:00
static var lrow = [1/2, 1/2];
2016-10-15 20:19:09 +02:00
function render2D(g:kha.graphics2.Graphics) {
2017-02-28 13:48:19 +01:00
g.end();
ui.begin(g);
2017-03-11 01:50:47 +01:00
var hwin = Id.handle();
2017-08-22 23:34:53 +02:00
if (ui.window(hwin, 0, 0, 280, iron.App.h(), true)) {
2017-10-23 16:24:57 +02:00
var htab = Id.handle({position: 0});
2017-08-22 23:34:53 +02:00
if (ui.tab(htab, '')) {}
2017-12-07 17:44:44 +01:00
if (ui.tab(htab, lastTrace == '' ? 'Inspector' : lastTrace.substr(0, 20))) {
2017-08-22 23:34:53 +02:00
var i = 0;
function drawList(h:Handle, o:iron.object.Object) {
ui.row(lrow);
var b = false;
if (o.children.length > 0) {
b = ui.panel(h.nest(i, {selected: true}), o.name, 0, true);
}
else {
ui._x += 18; // Sign offset
ui.text(o.name);
ui._x -= 18;
}
ui.text('(' + Std.int(o.transform.worldx() * 10) / 10 + ', ' + Std.int(o.transform.worldy() * 10) / 10 + ', ' + Std.int(o.transform.worldz() * 10) / 10 + ')', Align.Right);
i++;
if (b) {
for (c in o.children) {
ui.indent();
drawList(h, c);
ui.unindent();
}
}
}
for (c in iron.Scene.active.root.children) {
drawList(Id.handle(), c);
}
}
2017-05-12 21:49:42 +02:00
var avg = Math.round(frameTimeAvg * 10000) / 10;
var fpsAvg = avg > 0 ? Math.round(1000 / avg) : 0;
2017-08-22 23:34:53 +02:00
if (ui.tab(htab, '$avg ms')) {
// ui.check(Id.handle(), "Show empties");
2017-10-23 16:24:57 +02:00
ui.text('$fpsAvg fps');
2017-08-23 22:53:39 +02:00
var numObjects = iron.Scene.active.meshes.length;
ui.text("meshes: " + numObjects);
2017-02-28 13:48:19 +01:00
var avgMin = Math.round(frameTimeAvgMin * 10000) / 10;
var avgMax = Math.round(frameTimeAvgMax * 10000) / 10;
2017-05-13 10:44:17 +02:00
ui.text('frame (min/max): $avgMin/$avgMax');
2017-03-12 17:29:22 +01:00
var fpsAvgMin = avgMin > 0 ? Math.round(1000 / avgMin) : 0;
var fpsAvgMax = avgMax > 0 ? Math.round(1000 / avgMax) : 0;
2017-05-13 10:44:17 +02:00
ui.text('fps (min/max): $fpsAvgMin/$fpsAvgMax');
ui.text('rpath: ' + Math.round(renderPathTimeAvg * 10000) / 10);
2017-05-12 21:49:42 +02:00
ui.text('update: ' + Math.round(updateTimeAvg * 10000) / 10);
2017-02-28 13:48:19 +01:00
ui.indent();
2017-05-13 10:44:17 +02:00
ui.text('- phys: ' + Math.round(physTimeAvg * 10000) / 10);
ui.text('- anim: ' + Math.round(animTimeAvg * 10000) / 10);
// ui.text('mem: ' + Std.int(getMem() / 1024 / 1024));
2017-02-28 13:48:19 +01:00
ui.unindent();
2017-11-22 21:17:36 +01:00
ui.text('draw calls: ' + iron.RenderPath.drawCalls);
ui.text('tris mesh: ' + iron.RenderPath.numTrisMesh);
ui.text('tris shadow: ' + iron.RenderPath.numTrisShadow);
2017-05-14 22:23:47 +02:00
#if arm_batch
2017-11-22 21:17:36 +01:00
ui.text('batch calls: ' + iron.RenderPath.batchCalls);
ui.text('batch buckets: ' + iron.RenderPath.batchBuckets);
2017-05-14 22:23:47 +02:00
#end
2017-11-22 21:17:36 +01:00
ui.text('culled: ' + iron.RenderPath.culled + ' / ' + numObjects * 2); // Assumes shadow context for all meshes
2017-05-14 22:23:47 +02:00
#if arm_stream
var total = iron.Scene.active.sceneStream.sceneTotal();
ui.text('streamed: $numObjects / $total');
#end
2017-11-22 21:17:36 +01:00
ui.text('render targets: ');
for (rt in iron.RenderPath.active.renderTargets) {
ui.text(rt.raw.name);
}
2017-02-28 13:48:19 +01:00
}
ui.separator();
}
ui.end();
g.begin(false);
2016-07-22 23:25:07 +02:00
2016-10-15 20:19:09 +02:00
totalTime += frameTime;
2017-05-13 10:44:17 +02:00
renderPathTime += iron.App.renderPathTime;
2016-10-15 20:19:09 +02:00
frames++;
if (totalTime > 1.0) {
2017-03-11 01:50:47 +01:00
hwin.redraws = 1;
2016-10-15 20:19:09 +02:00
var t = totalTime / frames;
// Second frame
if (frameTimeAvg > 0) {
if (t < frameTimeAvgMin || frameTimeAvgMin == 0) frameTimeAvgMin = t;
if (t > frameTimeAvgMax || frameTimeAvgMax == 0) frameTimeAvgMax = t;
}
2016-08-07 23:12:14 +02:00
2016-10-15 20:19:09 +02:00
frameTimeAvg = t;
2017-05-13 10:44:17 +02:00
renderPathTimeAvg = renderPathTime / frames;
2016-10-15 20:19:09 +02:00
updateTimeAvg = updateTime / frames;
2017-05-13 10:44:17 +02:00
animTimeAvg = animTime / frames;
2016-10-15 20:19:09 +02:00
physTimeAvg = physTime / frames;
totalTime = 0;
2017-05-13 10:44:17 +02:00
renderPathTime = 0;
2016-10-15 20:19:09 +02:00
updateTime = 0;
2017-05-13 10:44:17 +02:00
animTime = 0;
2016-10-15 20:19:09 +02:00
physTime = 0;
frames = 0;
}
frameTime = Scheduler.realTime() - lastTime;
lastTime = Scheduler.realTime();
2017-11-15 13:34:51 +01:00
// var rp = pathdata.renderTargets.get("shadowMap");
// g.drawScaledImage(rp.image, 0, 0, 256, 256);
2016-10-15 20:19:09 +02:00
}
2016-08-04 22:38:56 +02:00
2016-10-15 20:19:09 +02:00
function update() {
2017-08-23 22:53:39 +02:00
armory.trait.WalkNavigation.enabled = !(ui.isScrolling || (ui.currentWindow != null && ui.currentWindow.dragging));
2016-10-15 20:19:09 +02:00
updateTime += iron.App.updateTime;
2017-09-07 11:44:45 +02:00
animTime += iron.object.Animation.animationTime;
2016-10-15 20:19:09 +02:00
#if arm_physics
2017-09-30 00:32:06 +02:00
physTime += armory.trait.physics.PhysicsWorld.physTime;
2016-10-15 20:19:09 +02:00
#end
}
2017-05-13 10:44:17 +02:00
// function getMem():Int {
// #if cpp
// return untyped __global__.__hxcpp_gc_used_bytes();
// #elseif kha_webgl
// return untyped __js__("(window.performance && window.performance.memory) ? window.performance.memory.usedJSHeapSize : 0");
// #else
// return 0;
// #end
// }
// function rungc() {
// #if cpp
// return cpp.vm.Gc.run(true);
// #end
// }
2016-07-21 17:45:39 +02:00
#end
}