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

659 lines
18 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;
2020-01-02 13:47:06 +01:00
using armory.object.TransformExtension;
2016-07-21 17:45:39 +02:00
#end
#if arm_debug
2017-08-23 22:53:39 +02:00
@:access(zui.Zui)
@:access(armory.logicnode.LogicNode)
#end
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
2018-10-11 11:30:39 +02:00
public var visible = true;
2019-12-19 23:54:08 +01:00
var ui: Zui;
2018-08-29 09:59:23 +02:00
var scaleFactor = 1.0;
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;
2019-12-19 23:54:08 +01:00
var graph: kha.Image = null;
var graphA: kha.Image = null;
var graphB: kha.Image = null;
2018-08-28 13:52:53 +02:00
var benchmark = false;
2018-08-22 12:23:33 +02:00
var benchFrames = 0;
var benchTime = 0.0;
2018-06-20 14:57:37 +02:00
2019-12-19 23:54:08 +01:00
var selectedObject: iron.object.Object;
2018-06-20 14:57:37 +02:00
var selectedType = "";
var selectedTraits = new Array<Trait>();
2019-12-19 23:54:08 +01:00
static var lrow = [1 / 2, 1 / 2];
static var row4 = [1 / 4, 1 / 4, 1 / 4, 1 / 4];
2016-07-22 23:25:07 +02:00
2019-04-24 21:55:20 +02:00
public static var debugFloat = 1.0;
2019-12-19 23:54:08 +01:00
public static var watchNodes: Array<armory.logicnode.LogicNode> = [];
2018-06-14 22:50:11 +02:00
2018-08-29 09:59:23 +02:00
public function new(scaleFactor = 1.0) {
2016-10-15 20:19:09 +02:00
super();
2016-07-21 17:45:39 +02:00
2018-08-29 09:59:23 +02:00
this.scaleFactor = scaleFactor;
2019-12-19 23:54:08 +01:00
iron.data.Data.getFont("font_default.ttf", function(font: kha.Font) {
2019-04-04 15:53:11 +02:00
ui = new Zui({scaleFactor: scaleFactor, font: font});
2016-10-15 20:19:09 +02:00
notifyOnRender2D(render2D);
notifyOnUpdate(update);
2018-06-02 19:00:36 +02:00
if (haxeTrace == null) {
haxeTrace = haxe.Log.trace;
haxe.Log.trace = consoleTrace;
}
2018-02-18 19:28:47 +01:00
// Toggle console
kha.input.Keyboard.get().notify(null, null, function(char: String) {
2018-10-11 11:30:39 +02:00
if (char == "~") visible = !visible;
2019-04-25 22:40:21 +02:00
else if (char == "[") { debugFloat -= 0.1; trace(debugFloat); }
else if (char == "]") { debugFloat += 0.1; trace(debugFloat); }
2018-02-18 19:28:47 +01:00
});
2016-10-15 20:19:09 +02:00
});
}
2016-07-21 17:45:39 +02:00
2018-06-20 14:57:37 +02:00
var debugDrawSet = false;
2019-12-19 23:54:08 +01:00
function selectObject(o: iron.object.Object) {
2018-06-20 14:57:37 +02:00
selectedObject = o;
if (!debugDrawSet) {
debugDrawSet = true;
2019-12-19 23:54:08 +01:00
armory.trait.internal.DebugDraw.notifyOnRender(function(draw: armory.trait.internal.DebugDraw) {
2018-06-20 14:57:37 +02:00
if (selectedObject != null) draw.bounds(selectedObject.transform);
});
}
}
function updateGraph() {
if (graph == null) {
graphA = kha.Image.createRenderTarget(280, 33);
graphB = kha.Image.createRenderTarget(280, 33);
graph = graphA;
}
else graph = graph == graphA ? graphB : graphA;
var graphPrev = graph == graphA ? graphB : graphA;
graph.g2.begin(true, 0x00000000);
graph.g2.color = 0xffffffff;
graph.g2.drawImage(graphPrev, -3, 0);
var avg = Math.round(frameTimeAvg * 1000);
var miss = avg > 16.7 ? (avg - 16.7) / 16.7 : 0.0;
graph.g2.color = kha.Color.fromFloats(miss, 1 - miss, 0, 1.0);
graph.g2.fillRect(280 - 3, 33 - avg, 3, avg);
graph.g2.color = 0xff000000;
graph.g2.fillRect(280 - 3, 33 - 17, 3, 1);
2019-11-13 09:09:06 +01:00
2018-06-20 14:57:37 +02:00
graph.g2.end();
}
2019-12-19 23:54:08 +01:00
static var haxeTrace: Dynamic->haxe.PosInfos->Void = null;
static var lastTraces: Array<String> = [""];
static function consoleTrace(v: Dynamic, ?inf: haxe.PosInfos) {
lastTraces.unshift(haxe.Log.formatOutput(v,inf));
2018-06-20 14:57:37 +02:00
if (lastTraces.length > 10) lastTraces.pop();
2017-05-06 00:22:15 +02:00
haxeTrace(v, inf);
2018-03-06 22:05:36 +01:00
}
2017-05-06 00:22:15 +02:00
2019-12-19 23:54:08 +01:00
function render2D(g: kha.graphics2.Graphics) {
2018-10-11 11:30:39 +02:00
if (!visible) return;
2017-03-11 01:50:47 +01:00
var hwin = Id.handle();
2018-06-20 14:57:37 +02:00
var htab = Id.handle({position: 0});
2018-08-29 09:59:23 +02:00
var ww = Std.int(280 * scaleFactor);
var wx = iron.App.w() - ww;
2018-08-22 12:23:33 +02:00
var wy = 0;
var wh = iron.App.h();
2019-02-13 08:03:05 +01:00
// var bindG = ui.windowDirty(hwin, wx, wy, ww, wh) || hwin.redraws > 0;
var bindG = true;
2018-08-22 12:23:33 +02:00
if (bindG) g.end();
2019-11-13 09:09:06 +01:00
2018-08-22 12:23:33 +02:00
ui.begin(g);
if (ui.window(hwin, wx, wy, ww, wh, true)) {
2017-08-22 23:34:53 +02:00
2019-12-19 23:54:08 +01:00
if (ui.tab(htab, "")) {}
2018-06-20 14:57:37 +02:00
2019-12-19 23:54:08 +01:00
if (ui.tab(htab, "Scene")) {
2018-06-20 14:57:37 +02:00
if (ui.panel(Id.handle({selected: true}), "Outliner")) {
ui.indent();
2019-11-13 09:09:06 +01:00
2019-12-27 16:40:59 +01:00
var lineCounter = 0;
function drawList(listHandle: zui.Zui.Handle, currentObject: iron.object.Object) {
if (currentObject.name.charAt(0) == ".") return; // Hidden
2018-06-20 14:57:37 +02:00
var b = false;
2019-12-27 16:40:59 +01:00
// Highlight every other line
if (lineCounter % 2 == 0) {
ui.g.color = ui.t.SEPARATOR_COL;
ui.g.fillRect(0, ui._y, ui._windowW, ui.ELEMENT_H());
ui.g.color = 0xffffffff;
}
// Highlight selected line
if (currentObject == selectedObject) {
2018-06-20 14:57:37 +02:00
ui.g.color = 0xff205d9c;
2018-08-29 09:59:23 +02:00
ui.g.fillRect(0, ui._y, ui._windowW, ui.ELEMENT_H());
2018-06-20 14:57:37 +02:00
ui.g.color = 0xffffffff;
}
2019-12-27 16:40:59 +01:00
if (currentObject.children.length > 0) {
2019-12-19 23:54:08 +01:00
ui.row([1 / 13, 12 / 13]);
2020-04-09 00:21:35 +02:00
b = ui.panel(listHandle.nest(lineCounter, {selected: true}), "", true, false, false);
2019-12-27 16:40:59 +01:00
ui.text(currentObject.name);
2018-06-20 14:57:37 +02:00
}
else {
ui._x += 18; // Sign offset
2019-12-27 16:40:59 +01:00
// Draw line that shows parent relations
ui.g.color = ui.t.ACCENT_COL;
2020-04-12 20:04:16 +02:00
ui.g.drawLine(ui._x - 10, ui._y + ui.ELEMENT_H() / 2, ui._x, ui._y + ui.ELEMENT_H() / 2);
2019-12-27 16:40:59 +01:00
ui.g.color = 0xffffffff;
ui.text(currentObject.name);
2018-06-20 14:57:37 +02:00
ui._x -= 18;
}
2019-12-27 16:40:59 +01:00
lineCounter++;
// Undo applied offset for row drawing caused by endElement() in Zui.hx
ui._y -= ui.ELEMENT_OFFSET();
2018-06-20 14:57:37 +02:00
if (ui.isReleased) {
2019-12-27 16:40:59 +01:00
selectObject(currentObject);
2018-06-20 14:57:37 +02:00
}
2019-12-27 16:40:59 +01:00
2018-06-20 14:57:37 +02:00
if (b) {
2019-12-27 16:40:59 +01:00
var currentY = ui._y;
for (child in currentObject.children) {
2018-06-20 14:57:37 +02:00
ui.indent();
2019-12-27 16:40:59 +01:00
drawList(listHandle, child);
2018-06-20 14:57:37 +02:00
ui.unindent();
}
2019-12-27 16:40:59 +01:00
// Draw line that shows parent relations
ui.g.color = ui.t.ACCENT_COL;
ui.g.drawLine(ui._x + 14, currentY, ui._x + 14, ui._y - ui.ELEMENT_H() / 2);
ui.g.color = 0xffffffff;
2018-06-20 14:57:37 +02:00
}
2017-08-22 23:34:53 +02:00
}
2018-06-20 14:57:37 +02:00
for (c in iron.Scene.active.root.children) {
drawList(Id.handle(), c);
2017-08-22 23:34:53 +02:00
}
2018-06-20 14:57:37 +02:00
ui.unindent();
}
2019-11-13 09:09:06 +01:00
2018-06-20 14:57:37 +02:00
if (selectedObject == null) selectedType = "";
if (ui.panel(Id.handle({selected: true}), 'Properties $selectedType')) {
ui.indent();
2019-11-13 09:09:06 +01:00
2018-06-20 14:57:37 +02:00
if (selectedObject != null) {
var h = Id.handle();
h.selected = selectedObject.visible;
selectedObject.visible = ui.check(h, "Visible");
var localPos = selectedObject.transform.loc;
var worldPos = selectedObject.transform.getWorldPosition();
2018-06-20 14:57:37 +02:00
var scale = selectedObject.transform.scale;
var rot = selectedObject.transform.rot.getEuler();
2018-12-20 22:37:39 +01:00
var dim = selectedObject.transform.dim;
2018-06-20 14:57:37 +02:00
rot.mult(180 / 3.141592);
var f = 0.0;
ui.text("Transforms");
ui.indent();
ui.row(row4);
ui.text("World Loc");
// Read-only currently
ui.enabled = false;
h = Id.handle();
h.text = roundfp(worldPos.x) + "";
f = Std.parseFloat(ui.textInput(h, "X"));
h = Id.handle();
h.text = roundfp(worldPos.y) + "";
f = Std.parseFloat(ui.textInput(h, "Y"));
h = Id.handle();
h.text = roundfp(worldPos.z) + "";
f = Std.parseFloat(ui.textInput(h, "Z"));
ui.enabled = true;
2018-06-20 14:57:37 +02:00
ui.row(row4);
ui.text("Local Loc");
2018-06-20 14:57:37 +02:00
h = Id.handle();
h.text = roundfp(localPos.x) + "";
2018-06-20 14:57:37 +02:00
f = Std.parseFloat(ui.textInput(h, "X"));
if (ui.changed) localPos.x = f;
2018-06-20 14:57:37 +02:00
h = Id.handle();
h.text = roundfp(localPos.y) + "";
2018-06-20 14:57:37 +02:00
f = Std.parseFloat(ui.textInput(h, "Y"));
if (ui.changed) localPos.y = f;
2018-06-20 14:57:37 +02:00
h = Id.handle();
h.text = roundfp(localPos.z) + "";
2018-06-20 14:57:37 +02:00
f = Std.parseFloat(ui.textInput(h, "Z"));
if (ui.changed) localPos.z = f;
2018-06-20 14:57:37 +02:00
ui.row(row4);
ui.text("Rotation");
2019-11-13 09:09:06 +01:00
2018-06-20 14:57:37 +02:00
h = Id.handle();
2019-06-20 11:35:20 +02:00
h.text = roundfp(rot.x) + "";
2018-06-20 14:57:37 +02:00
f = Std.parseFloat(ui.textInput(h, "X"));
var changed = false;
if (ui.changed) { changed = true; rot.x = f; }
h = Id.handle();
2019-06-20 11:35:20 +02:00
h.text = roundfp(rot.y) + "";
2018-06-20 14:57:37 +02:00
f = Std.parseFloat(ui.textInput(h, "Y"));
if (ui.changed) { changed = true; rot.y = f; }
h = Id.handle();
2019-06-20 11:35:20 +02:00
h.text = roundfp(rot.z) + "";
2018-06-20 14:57:37 +02:00
f = Std.parseFloat(ui.textInput(h, "Z"));
if (ui.changed) { changed = true; rot.z = f; }
if (changed && selectedObject.name != "Scene") {
rot.mult(3.141592 / 180);
selectedObject.transform.rot.fromEuler(rot.x, rot.y, rot.z);
selectedObject.transform.buildMatrix();
2018-06-20 15:02:01 +02:00
#if arm_physics
2018-06-20 14:57:37 +02:00
var rb = selectedObject.getTrait(armory.trait.physics.RigidBody);
if (rb != null) rb.syncTransform();
2018-06-20 15:02:01 +02:00
#end
2018-06-20 14:57:37 +02:00
}
ui.row(row4);
ui.text("Scale");
2019-11-13 09:09:06 +01:00
2018-06-20 14:57:37 +02:00
h = Id.handle();
2019-06-20 11:35:20 +02:00
h.text = roundfp(scale.x) + "";
2018-06-20 14:57:37 +02:00
f = Std.parseFloat(ui.textInput(h, "X"));
if (ui.changed) scale.x = f;
h = Id.handle();
2019-06-20 11:35:20 +02:00
h.text = roundfp(scale.y) + "";
2018-06-20 14:57:37 +02:00
f = Std.parseFloat(ui.textInput(h, "Y"));
if (ui.changed) scale.y = f;
h = Id.handle();
2019-06-20 11:35:20 +02:00
h.text = roundfp(scale.z) + "";
2018-06-20 14:57:37 +02:00
f = Std.parseFloat(ui.textInput(h, "Z"));
if (ui.changed) scale.z = f;
2018-12-20 22:37:39 +01:00
ui.row(row4);
ui.text("Dimensions");
h = Id.handle();
2019-06-20 11:35:20 +02:00
h.text = roundfp(dim.x) + "";
2018-12-20 22:37:39 +01:00
f = Std.parseFloat(ui.textInput(h, "X"));
if (ui.changed) dim.x = f;
h = Id.handle();
2019-06-20 11:35:20 +02:00
h.text = roundfp(dim.y) + "";
2018-12-20 22:37:39 +01:00
f = Std.parseFloat(ui.textInput(h, "Y"));
if (ui.changed) dim.y = f;
h = Id.handle();
2019-06-20 11:35:20 +02:00
h.text = roundfp(dim.z) + "";
2018-12-20 22:37:39 +01:00
f = Std.parseFloat(ui.textInput(h, "Z"));
if (ui.changed) dim.z = f;
2018-06-20 14:57:37 +02:00
selectedObject.transform.dirty = true;
ui.unindent();
2018-06-20 14:57:37 +02:00
2018-06-28 11:34:56 +02:00
if (selectedObject.traits.length > 0) {
ui.text("Traits:");
2019-12-27 16:43:39 +01:00
ui.indent();
2018-06-28 11:34:56 +02:00
for (t in selectedObject.traits) {
ui.row([3/4, 1/4]);
2018-06-28 11:34:56 +02:00
ui.text(Type.getClassName(Type.getClass(t)));
if (ui.button("Details")) {
if (selectedTraits.indexOf(t) == -1) {
selectedTraits.push(t);
}
}
2018-06-28 11:34:56 +02:00
}
2019-12-27 16:43:39 +01:00
ui.unindent();
2018-06-28 11:34:56 +02:00
}
2018-06-20 14:57:37 +02:00
if (selectedObject.name == "Scene") {
selectedType = "(Scene)";
if (iron.Scene.active.world != null) {
var p = iron.Scene.active.world.probe;
p.raw.strength = ui.slider(Id.handle({value: p.raw.strength}), "Env Strength", 0.0, 5.0, true);
}
else {
ui.text("This scene has no world data to edit.");
}
2018-06-20 14:57:37 +02:00
}
else if (Std.is(selectedObject, iron.object.LightObject)) {
selectedType = "(Light)";
var light = cast(selectedObject, iron.object.LightObject);
var lightHandle = Id.handle();
lightHandle.value = light.data.raw.strength / 10;
light.data.raw.strength = ui.slider(lightHandle, "Strength", 0.0, 5.0, true) * 10;
2018-06-20 14:57:37 +02:00
}
else if (Std.is(selectedObject, iron.object.CameraObject)) {
selectedType = "(Camera)";
2019-01-28 11:37:34 +01:00
var cam = cast(selectedObject, iron.object.CameraObject);
var fovHandle = Id.handle();
fovHandle.value = Std.int(cam.data.raw.fov * 100) / 100;
cam.data.raw.fov = ui.slider(fovHandle, "Field of View", 0.3, 2.0, true);
2018-06-20 14:57:37 +02:00
if (ui.changed) {
cam.buildProjection();
}
}
else {
selectedType = "(Object)";
2019-11-13 09:09:06 +01:00
2017-08-22 23:34:53 +02:00
}
}
2018-06-20 14:57:37 +02:00
ui.unindent();
2017-08-22 23:34:53 +02:00
}
}
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')) {
2018-06-20 14:57:37 +02:00
2019-12-19 23:54:08 +01:00
if (ui.panel(Id.handle({selected: true}), "Performance")) {
2018-06-20 14:57:37 +02:00
if (graph != null) ui.image(graph);
ui.indent();
ui.row(lrow);
2019-12-19 23:54:08 +01:00
ui.text("Frame");
2018-06-20 14:57:37 +02:00
ui.text('$avg ms / $fpsAvg fps', Align.Right);
2019-11-13 09:09:06 +01:00
2018-06-20 14:57:37 +02:00
ui.row(lrow);
2019-12-19 23:54:08 +01:00
ui.text("Render-path");
2018-06-20 14:57:37 +02:00
ui.text(Math.round(renderPathTimeAvg * 10000) / 10 + " ms", Align.Right);
ui.row(lrow);
2019-12-19 23:54:08 +01:00
ui.text("Script");
2018-06-20 14:57:37 +02:00
ui.text(Math.round((updateTimeAvg - physTimeAvg - animTimeAvg) * 10000) / 10 + " ms", Align.Right);
ui.row(lrow);
2019-12-19 23:54:08 +01:00
ui.text("Animation");
2018-06-20 14:57:37 +02:00
ui.text(Math.round(animTimeAvg * 10000) / 10 + " ms", Align.Right);
ui.row(lrow);
2019-12-19 23:54:08 +01:00
ui.text("Physics");
2018-06-20 14:57:37 +02:00
ui.text(Math.round(physTimeAvg * 10000) / 10 + " ms", Align.Right);
ui.unindent();
}
2019-12-19 23:54:08 +01:00
if (ui.panel(Id.handle({selected: false}), "Draw")) {
2018-06-20 14:57:37 +02:00
ui.indent();
ui.row(lrow);
var numMeshes = iron.Scene.active.meshes.length;
ui.text("Meshes");
ui.text(numMeshes + "", Align.Right);
ui.row(lrow);
2019-12-19 23:54:08 +01:00
ui.text("Draw calls");
2018-06-20 14:57:37 +02:00
ui.text(iron.RenderPath.drawCalls + "", Align.Right);
ui.row(lrow);
2019-12-19 23:54:08 +01:00
ui.text("Tris mesh");
2018-06-20 14:57:37 +02:00
ui.text(iron.RenderPath.numTrisMesh + "", Align.Right);
ui.row(lrow);
2019-12-19 23:54:08 +01:00
ui.text("Tris shadow");
2018-06-20 14:57:37 +02:00
ui.text(iron.RenderPath.numTrisShadow + "", Align.Right);
#if arm_batch
ui.row(lrow);
2019-12-19 23:54:08 +01:00
ui.text("Batch calls");
2018-06-20 14:57:37 +02:00
ui.text(iron.RenderPath.batchCalls + "", Align.Right);
ui.row(lrow);
2019-12-19 23:54:08 +01:00
ui.text("Batch buckets");
2018-06-20 14:57:37 +02:00
ui.text(iron.RenderPath.batchBuckets + "", Align.Right);
#end
ui.row(lrow);
2019-12-19 23:54:08 +01:00
ui.text("Culled"); // Assumes shadow context for all meshes
ui.text(iron.RenderPath.culled + " / " + numMeshes * 2, Align.Right);
2019-11-13 09:09:06 +01:00
2018-06-20 14:57:37 +02:00
#if arm_stream
ui.row(lrow);
var total = iron.Scene.active.sceneStream.sceneTotal();
2019-12-19 23:54:08 +01:00
ui.text("Streamed");
2018-06-20 14:57:37 +02:00
ui.text('$numMeshes / $total', Align.Right);
#end
ui.unindent();
}
2019-12-19 23:54:08 +01:00
if (ui.panel(Id.handle({selected: false}), "Render Targets")) {
2018-06-20 14:57:37 +02:00
ui.indent();
2018-11-28 10:26:48 +01:00
#if (kha_opengl || kha_webgl)
2018-06-20 14:57:37 +02:00
ui.imageInvertY = true;
2018-11-28 10:26:48 +01:00
#end
2018-06-20 14:57:37 +02:00
for (rt in iron.RenderPath.active.renderTargets) {
ui.text(rt.raw.name);
if (rt.image != null && !rt.is3D) {
ui.image(rt.image);
}
}
2018-11-28 10:26:48 +01:00
#if (kha_opengl || kha_webgl)
2018-06-20 14:57:37 +02:00
ui.imageInvertY = false;
2018-11-28 10:26:48 +01:00
#end
2018-06-20 14:57:37 +02:00
ui.unindent();
}
2019-12-19 23:54:08 +01:00
if (ui.panel(Id.handle({selected: false}), "Cached Materials")) {
2018-06-20 14:57:37 +02:00
ui.indent();
for (c in iron.data.Data.cachedMaterials) {
ui.text(c.name);
}
ui.unindent();
}
2019-12-19 23:54:08 +01:00
if (ui.panel(Id.handle({selected: false}), "Cached Shaders")) {
2018-06-20 14:57:37 +02:00
ui.indent();
for (c in iron.data.Data.cachedShaders) {
ui.text(c.name);
}
ui.unindent();
}
// if (ui.panel(Id.handle({selected: false}), 'Cached Textures')) {
// ui.indent();
// for (c in iron.data.Data.cachedImages) {
// ui.image(c);
// }
// ui.unindent();
// }
}
2019-12-19 23:54:08 +01:00
if (ui.tab(htab, lastTraces[0] == "" ? "Console" : lastTraces[0].substr(0, 20))) {
2018-06-20 14:57:37 +02:00
#if js
2019-12-19 23:54:08 +01:00
if (ui.panel(Id.handle({selected: false}), "Script")) {
2018-06-20 14:57:37 +02:00
ui.indent();
var t = ui.textInput(Id.handle());
if (ui.button("Run")) {
2018-06-28 11:34:56 +02:00
try { trace("> " + t); js.Lib.eval(t); }
2019-12-19 23:54:08 +01:00
catch (e: Dynamic) { trace(e); }
2018-06-20 14:57:37 +02:00
}
ui.unindent();
}
2017-05-14 22:23:47 +02:00
#end
2019-12-19 23:54:08 +01:00
if (ui.panel(Id.handle({selected: true}), "Log")) {
2018-06-20 14:57:37 +02:00
ui.indent();
if (ui.button("Clear")) {
2019-12-19 23:54:08 +01:00
lastTraces[0] = "";
2018-06-20 14:57:37 +02:00
lastTraces.splice(1, lastTraces.length - 1);
}
for (t in lastTraces) ui.text(t);
ui.unindent();
2017-11-22 21:17:36 +01:00
}
2017-02-28 13:48:19 +01:00
}
2018-06-20 14:57:37 +02:00
if (watchNodes.length > 0 && ui.tab(htab, "Watch")) {
for (n in watchNodes) {
2019-12-19 23:54:08 +01:00
ui.text(n.tree.object.name + "." + n.tree.name + "." + n.name + " = " + n.get(0));
}
}
2018-06-28 11:34:56 +02:00
2017-02-28 13:48:19 +01:00
ui.separator();
}
2018-08-22 12:23:33 +02:00
// Draw trait debug windows
var handleWinTrait = Id.handle();
for (trait in selectedTraits) {
var objectID = trait.object.uid;
var traitIndex = trait.object.traits.indexOf(trait);
var handleWindow = handleWinTrait.nest(objectID).nest(traitIndex);
// This solution is not optimal, dragged windows will change their
// position if the selectedTraits array is changed.
wx -= ww + 8;
wy = 0;
handleWindow.redraws = 1;
ui.window(handleWindow, wx, wy, ww, wh, true);
if (ui.button("Close Trait View")) {
selectedTraits.remove(trait);
handleWinTrait.nest(objectID).unnest(traitIndex);
continue;
}
ui.row([1/2, 1/2]);
ui.text("Trait:");
ui.text(Type.getClassName(Type.getClass(trait)), Align.Right);
ui.row([1/2, 1/2]);
ui.text("Extends:");
ui.text(Type.getClassName(Type.getSuperClass(Type.getClass(trait))), Align.Right);
ui.row([1/2, 1/2]);
ui.text("Object:");
ui.text(trait.object.name, Align.Right);
ui.separator();
if (ui.panel(Id.handle().nest(objectID).nest(traitIndex), "Attributes")) {
ui.indent();
for (fieldName in Reflect.fields(trait)) {
ui.row([1/2, 1/2]);
ui.text(fieldName + "");
var fieldValue = Reflect.field(trait, fieldName);
var fieldClass = Type.getClass(fieldValue);
// Treat objects differently (VERY bad performance otherwise)
if (Reflect.isObject(fieldValue) && fieldClass != String) {
if (fieldClass != null) {
ui.text('<${Type.getClassName(fieldClass)}>', Align.Right);
} else {
// Anonymous data structures for example
ui.text("<???>", Align.Right);
}
} else {
ui.text(Std.string(fieldValue), Align.Right);
}
}
ui.unindent();
}
}
2018-08-22 12:23:33 +02:00
ui.end(bindG);
if (bindG) g.begin(false);
2017-02-28 13:48:19 +01: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;
2018-08-22 12:23:33 +02:00
if (benchmark) {
benchFrames++;
if (benchFrames > 10) benchTime += t;
if (benchFrames == 20) trace(Std.int((benchTime / 10) * 1000000) / 1000); // ms
}
2019-11-13 09:09:06 +01:00
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;
2019-11-13 09:09:06 +01:00
2016-10-15 20:19:09 +02:00
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;
2018-06-20 14:57:37 +02:00
2019-02-13 08:03:05 +01:00
if (htab.position == 2) {
g.end();
updateGraph(); // Profile tab selected
g.begin(false);
}
2016-10-15 20:19:09 +02:00
}
frameTime = Scheduler.realTime() - lastTime;
lastTime = Scheduler.realTime();
}
2016-08-04 22:38:56 +02:00
2016-10-15 20:19:09 +02:00
function update() {
2019-11-13 09:09:06 +01:00
armory.trait.WalkNavigation.enabled = !(ui.isScrolling || ui.dragHandle != null);
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
}
2019-06-20 11:35:20 +02:00
2019-12-19 23:54:08 +01:00
static function roundfp(f: Float, precision = 2): Float {
2019-06-20 11:35:20 +02:00
f *= Math.pow(10, precision);
return Math.round(f) / Math.pow(10, precision);
}
2016-07-21 17:45:39 +02:00
#end
}