Merge pull request #12343 from djrm/pr_improve_monitors

Improved monitors units and colors.
This commit is contained in:
Rémi Verschelde 2017-10-23 20:06:23 +02:00 committed by GitHub
commit 7c18881808
3 changed files with 86 additions and 7 deletions

View File

@ -574,7 +574,38 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
for (int i = 0; i < arr.size(); i++) { for (int i = 0; i < arr.size(); i++) {
p[i] = arr[i]; p[i] = arr[i];
if (i < perf_items.size()) { if (i < perf_items.size()) {
perf_items[i]->set_text(1, rtos(p[i]));
float v = p[i];
String vs = rtos(v);
String tt = vs;
switch (Performance::MonitorType((int)perf_items[i]->get_metadata(1))) {
case Performance::MONITOR_TYPE_MEMORY: {
// for the time being, going above GBs is a bad sign.
String unit = "B";
if ((int)v > 1073741824) {
unit = "GB";
v /= 1073741824.0;
} else if ((int)v > 1048576) {
unit = "MB";
v /= 1048576.0;
} else if ((int)v > 1024) {
unit = "KB";
v /= 1024.0;
}
tt += " bytes";
vs = rtos(v) + " " + unit;
} break;
case Performance::MONITOR_TYPE_TIME: {
tt += " seconds";
vs += " s";
} break;
default: {
tt += " " + perf_items[i]->get_text(0);
} break;
}
perf_items[i]->set_text(1, vs);
perf_items[i]->set_tooltip(1, tt);
if (p[i] > perf_max[i]) if (p[i] > perf_max[i])
perf_max[i] = p[i]; perf_max[i] = p[i];
} }
@ -816,14 +847,14 @@ void ScriptEditorDebugger::_performance_draw() {
r.position += graph_sb->get_offset(); r.position += graph_sb->get_offset();
r.size -= graph_sb->get_minimum_size(); r.size -= graph_sb->get_minimum_size();
int pi = which[i]; int pi = which[i];
Color c = get_color("success_color", "Editor"); Color c = get_color("accent_color", "Editor");
c.set_hsv(Math::fmod(c.get_h() + pi * 0.7654, 1), c.get_s(), c.get_v()); float h = (float)which[i] / (float)(perf_items.size());
//c = c.linear_interpolate(get_color("base_color", "Editor"), 0.9); c.set_hsv(Math::fmod(h + 0.4, 0.9), c.get_s() * 0.9, c.get_v() * 1.4);
c.a = 0.8;
perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x);
c.a = 0.6; c.a = 0.6;
perf_draw->draw_string(graph_font, r.position + Point2(graph_font->get_char_size('X').width, graph_font->get_ascent() + graph_font->get_height()), perf_items[pi]->get_text(1), c, r.size.y); perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x);
c.a = 0.9;
perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent() + graph_font->get_height()), perf_items[pi]->get_text(1), c, r.size.y);
float spacing = point_sep / float(cols); float spacing = point_sep / float(cols);
float from = r.size.width; float from = r.size.width;
@ -1801,6 +1832,7 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
for (int i = 0; i < Performance::MONITOR_MAX; i++) { for (int i = 0; i < Performance::MONITOR_MAX; i++) {
String n = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i)); String n = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
Performance::MonitorType mtype = Performance::get_singleton()->get_monitor_type(Performance::Monitor(i));
String base = n.get_slice("/", 0); String base = n.get_slice("/", 0);
String name = n.get_slice("/", 1); String name = n.get_slice("/", 1);
if (!bases.has(base)) { if (!bases.has(base)) {
@ -1812,6 +1844,7 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
} }
TreeItem *it = perf_monitors->create_item(bases[base]); TreeItem *it = perf_monitors->create_item(bases[base]);
it->set_metadata(1, mtype);
it->set_editable(0, false); it->set_editable(0, false);
it->set_selectable(0, true); it->set_selectable(0, true);
it->set_text(0, name.capitalize()); it->set_text(0, name.capitalize());

View File

@ -153,6 +153,44 @@ float Performance::get_monitor(Monitor p_monitor) const {
return 0; return 0;
} }
Performance::MonitorType Performance::get_monitor_type(Monitor p_monitor) const {
ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, MONITOR_TYPE_QUANTITY);
// ugly
static const MonitorType types[MONITOR_MAX] = {
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_TIME,
MONITOR_TYPE_TIME,
MONITOR_TYPE_MEMORY,
MONITOR_TYPE_MEMORY,
MONITOR_TYPE_MEMORY,
MONITOR_TYPE_MEMORY,
MONITOR_TYPE_MEMORY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_MEMORY,
MONITOR_TYPE_MEMORY,
MONITOR_TYPE_MEMORY,
MONITOR_TYPE_MEMORY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
};
return types[p_monitor];
}
void Performance::set_process_time(float p_pt) { void Performance::set_process_time(float p_pt) {
_process_time = p_pt; _process_time = p_pt;

View File

@ -79,9 +79,17 @@ public:
MONITOR_MAX MONITOR_MAX
}; };
enum MonitorType {
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_MEMORY,
MONITOR_TYPE_TIME
};
float get_monitor(Monitor p_monitor) const; float get_monitor(Monitor p_monitor) const;
String get_monitor_name(Monitor p_monitor) const; String get_monitor_name(Monitor p_monitor) const;
MonitorType get_monitor_type(Monitor p_monitor) const;
void set_process_time(float p_pt); void set_process_time(float p_pt);
void set_physics_process_time(float p_pt); void set_physics_process_time(float p_pt);