Skip to content

Commit

Permalink
Make Game toolbar a debugger tab
Browse files Browse the repository at this point in the history
Move the toolbar in Game view to the new Game tab in debugger panel.

Also made the toolbar's debugging features per session.

Features in the old Misc tab are moved to other tabs:
- "User clicked control" and "Live edit root" are moved into the Game tab.
- "Export measures as CSV" is moved to the "Profiler" tab and the "Monitor"
  tab accordingly.
  • Loading branch information
timothyqiu committed Dec 11, 2024
1 parent cf038de commit a06caca
Show file tree
Hide file tree
Showing 12 changed files with 486 additions and 492 deletions.
11 changes: 0 additions & 11 deletions editor/debugger/editor_debugger_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,17 +801,6 @@ void EditorDebuggerNode::live_debug_reparent_node(const NodePath &p_at, const No
});
}

void EditorDebuggerNode::set_camera_override(CameraOverride p_override) {
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
dbg->set_camera_override(p_override);
});
camera_override = p_override;
}

EditorDebuggerNode::CameraOverride EditorDebuggerNode::get_camera_override() {
return camera_override;
}

void EditorDebuggerNode::add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin) {
ERR_FAIL_COND_MSG(p_plugin.is_null(), "Debugger plugin is null.");
ERR_FAIL_COND_MSG(debugger_plugins.has(p_plugin), "Debugger plugin already exists.");
Expand Down
11 changes: 0 additions & 11 deletions editor/debugger/editor_debugger_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ class UndoRedo;
class EditorDebuggerNode : public MarginContainer {
GDCLASS(EditorDebuggerNode, MarginContainer);

public:
enum CameraOverride {
OVERRIDE_NONE,
OVERRIDE_INGAME,
OVERRIDE_EDITORS,
};

private:
enum Options {
DEBUG_NEXT,
Expand Down Expand Up @@ -111,7 +104,6 @@ class EditorDebuggerNode : public MarginContainer {
bool keep_open = false;
String current_uri;

CameraOverride camera_override = OVERRIDE_NONE;
HashMap<Breakpoint, bool, Breakpoint> breakpoints;

HashSet<Ref<EditorDebuggerPlugin>> debugger_plugins;
Expand Down Expand Up @@ -205,9 +197,6 @@ class EditorDebuggerNode : public MarginContainer {
void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name);
void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);

void set_camera_override(CameraOverride p_override);
CameraOverride get_camera_override();

String get_server_uri() const;

void set_keep_open(bool p_keep_open);
Expand Down
91 changes: 89 additions & 2 deletions editor/debugger/editor_performance_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@
#include "editor/editor_property_name_processor.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/gui/editor_file_dialog.h"
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "main/performance.h"
#include "scene/gui/box_container.h"
#include "scene/gui/control.h"
#include "scene/gui/label.h"
#include "scene/gui/tree.h"

EditorPerformanceProfiler::Monitor::Monitor() {}

Expand Down Expand Up @@ -97,6 +102,15 @@ String EditorPerformanceProfiler::_create_label(float p_value, Performance::Moni
}

void EditorPerformanceProfiler::_monitor_select() {
bool nothing_checked = true;
for (const KeyValue<StringName, Monitor> &E : monitors) {
if (E.value.item->is_checked(0)) {
nothing_checked = false;
break;
}
}
deselect_all_button->set_disabled(nothing_checked);

monitor_draw->queue_redraw();
}

Expand Down Expand Up @@ -300,6 +314,50 @@ void EditorPerformanceProfiler::_marker_input(const Ref<InputEvent> &p_event) {
}
}

void EditorPerformanceProfiler::_export_csv(const String &p_path) {
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE);
ERR_FAIL_COND_MSG(file.is_null(), "Failed to open file: " + p_path);

Vector<String> line;
line.resize(Performance::MONITOR_MAX);

// signatures
for (int i = 0; i < Performance::MONITOR_MAX; i++) {
line.write[i] = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
}
file->store_csv_line(line);

// values
Vector<List<float>::Element *> iterators;
iterators.resize(Performance::MONITOR_MAX);
bool continue_iteration = false;
for (int i = 0; i < Performance::MONITOR_MAX; i++) {
iterators.write[i] = _get_monitor_data(Performance::get_singleton()->get_monitor_name(Performance::Monitor(i)))->back();
continue_iteration = continue_iteration || iterators[i];
}
while (continue_iteration) {
continue_iteration = false;
for (int i = 0; i < Performance::MONITOR_MAX; i++) {
if (iterators[i]) {
line.write[i] = String::num_real(iterators[i]->get());
iterators.write[i] = iterators[i]->prev();
} else {
line.write[i] = "";
}
continue_iteration = continue_iteration || iterators[i];
}
file->store_csv_line(line);
}
}

void EditorPerformanceProfiler::_deselect_all() {
deselect_all_button->set_disabled(true);
for (KeyValue<StringName, Monitor> &E : monitors) {
E.value.item->set_checked(0, false);
}
monitor_draw->queue_redraw();
}

void EditorPerformanceProfiler::reset() {
HashMap<StringName, Monitor>::Iterator E = monitors.begin();
while (E != monitors.end()) {
Expand Down Expand Up @@ -368,7 +426,7 @@ void EditorPerformanceProfiler::add_profile_frame(const Vector<float> &p_values)
monitor_draw->queue_redraw();
}

List<float> *EditorPerformanceProfiler::get_monitor_data(const StringName &p_name) {
List<float> *EditorPerformanceProfiler::_get_monitor_data(const StringName &p_name) {
if (monitors.has(p_name)) {
return &monitors[p_name].history;
}
Expand All @@ -378,6 +436,8 @@ List<float> *EditorPerformanceProfiler::get_monitor_data(const StringName &p_nam
void EditorPerformanceProfiler::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
export_csv_button->set_button_icon(get_editor_theme_icon(SNAME("Save")));
deselect_all_button->set_button_icon(get_editor_theme_icon(SNAME("ThemeDeselectAll")));
for (KeyValue<StringName, TreeItem *> &E : base_map) {
E.value->set_custom_font(0, get_theme_font(SNAME("bold"), EditorStringName(EditorFonts)));
}
Expand All @@ -395,6 +455,9 @@ EditorPerformanceProfiler::EditorPerformanceProfiler() {
set_name(TTR("Monitors"));
set_split_offset(340 * EDSCALE);

VBoxContainer *vbox = memnew(VBoxContainer);
add_child(vbox);

monitor_tree = memnew(Tree);
monitor_tree->set_custom_minimum_size(Size2(300, 0) * EDSCALE);
monitor_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
Expand All @@ -409,7 +472,31 @@ EditorPerformanceProfiler::EditorPerformanceProfiler() {
monitor_tree->create_item();
monitor_tree->set_hide_root(true);
monitor_tree->set_theme_type_variation("TreeSecondary");
add_child(monitor_tree);
monitor_tree->set_v_size_flags(SIZE_EXPAND_FILL);
vbox->add_child(monitor_tree);

file_dialog = memnew(EditorFileDialog);
file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
file_dialog->connect("file_selected", callable_mp(this, &EditorPerformanceProfiler::_export_csv));
vbox->add_child(file_dialog);

HBoxContainer *hbox = memnew(HBoxContainer);
vbox->add_child(hbox);

deselect_all_button = memnew(Button(TTR("Deselect All")));
deselect_all_button->set_theme_type_variation("FlatButton");
deselect_all_button->connect(SceneStringName(pressed), callable_mp(this, &EditorPerformanceProfiler::_deselect_all));
deselect_all_button->set_h_size_flags(SIZE_SHRINK_BEGIN);
deselect_all_button->set_disabled(true);
hbox->add_child(deselect_all_button);

export_csv_button = memnew(Button(TTR("Export")));
export_csv_button->set_theme_type_variation("FlatButton");
export_csv_button->set_tooltip_text(TTR("Export list to a CSV file"));
export_csv_button->connect(SceneStringName(pressed), callable_mp(file_dialog, &EditorFileDialog::popup_file_dialog));
export_csv_button->set_h_size_flags(SIZE_SHRINK_BEGIN);
hbox->add_child(export_csv_button);

monitor_draw = memnew(Control);
monitor_draw->set_custom_minimum_size(Size2(300, 0) * EDSCALE);
Expand Down
17 changes: 12 additions & 5 deletions editor/debugger/editor_performance_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
#define EDITOR_PERFORMANCE_PROFILER_H

#include "core/templates/hash_map.h"
#include "core/templates/rb_map.h"
#include "main/performance.h"
#include "scene/gui/control.h"
#include "scene/gui/label.h"
#include "scene/gui/split_container.h"
#include "scene/gui/tree.h"

class Button;
class EditorFileDialog;
class Tree;
class TreeItem;

class EditorPerformanceProfiler : public HSplitContainer {
GDCLASS(EditorPerformanceProfiler, HSplitContainer);
Expand All @@ -63,6 +64,9 @@ class EditorPerformanceProfiler : public HSplitContainer {

HashMap<StringName, TreeItem *> base_map;
Tree *monitor_tree = nullptr;
EditorFileDialog *file_dialog = nullptr;
Button *export_csv_button = nullptr;
Button *deselect_all_button = nullptr;
Control *monitor_draw = nullptr;
Label *info_message = nullptr;
StringName marker_key;
Expand All @@ -79,14 +83,17 @@ class EditorPerformanceProfiler : public HSplitContainer {
TreeItem *_create_monitor_item(const StringName &p_monitor_name, TreeItem *p_base);
void _marker_input(const Ref<InputEvent> &p_event);

List<float> *_get_monitor_data(const StringName &p_name);
void _export_csv(const String &p_path);
void _deselect_all();

protected:
void _notification(int p_what);

public:
void reset();
void update_monitors(const Vector<StringName> &p_names);
void add_profile_frame(const Vector<float> &p_values);
List<float> *get_monitor_data(const StringName &p_name);
EditorPerformanceProfiler();
};

Expand Down
36 changes: 30 additions & 6 deletions editor/debugger/editor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@
#include "editor_profiler.h"

#include "core/io/image.h"
#include "core/os/os.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "scene/gui/button.h"
#include "scene/gui/check_box.h"
#include "scene/gui/check_button.h"
#include "scene/gui/label.h"
#include "scene/gui/option_button.h"
#include "scene/gui/spin_box.h"
#include "scene/gui/split_container.h"
#include "scene/gui/texture_rect.h"
#include "scene/gui/tree.h"
#include "scene/resources/image_texture.h"

void EditorProfiler::_make_metric_ptrs(Metric &m) {
Expand Down Expand Up @@ -440,6 +446,7 @@ void EditorProfiler::_notification(int p_what) {
case NOTIFICATION_TRANSLATION_CHANGED: {
activate->set_button_icon(get_editor_theme_icon(SNAME("Play")));
clear_button->set_button_icon(get_editor_theme_icon(SNAME("Clear")));
export_csv_button->set_button_icon(get_editor_theme_icon(SNAME("Save")));

theme_cache.seek_line_color = get_theme_color(SceneStringName(font_color), EditorStringName(Editor));
theme_cache.seek_line_color.a = 0.8;
Expand Down Expand Up @@ -587,13 +594,16 @@ bool EditorProfiler::is_profiling() {
return activate->is_pressed();
}

Vector<Vector<String>> EditorProfiler::get_data_as_csv() const {
Vector<Vector<String>> res;
void EditorProfiler::_export_csv(const String &p_path) const {
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE);
ERR_FAIL_COND_MSG(file.is_null(), "Failed to open file: " + p_path);

if (frame_metrics.is_empty()) {
return res;
return;
}

Vector<Vector<String>> res;

// Different metrics may contain different number of categories.
HashSet<StringName> possible_signatures;
for (int i = 0; i < frame_metrics.size(); i++) {
Expand Down Expand Up @@ -653,7 +663,9 @@ Vector<Vector<String>> EditorProfiler::get_data_as_csv() const {
res.push_back(values);
}

return res;
for (int i = 0; i < res.size(); i++) {
file->store_csv_line(res[i]);
}
}

EditorProfiler::EditorProfiler() {
Expand Down Expand Up @@ -718,6 +730,18 @@ EditorProfiler::EditorProfiler() {
hb->add_child(cursor_metric_edit);
cursor_metric_edit->connect(SceneStringName(value_changed), callable_mp(this, &EditorProfiler::_cursor_metric_changed));

file_dialog = memnew(EditorFileDialog);
file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
file_dialog->connect("file_selected", callable_mp(this, &EditorProfiler::_export_csv));
hb->add_child(file_dialog);

export_csv_button = memnew(Button);
export_csv_button->set_theme_type_variation("FlatButton");
export_csv_button->set_tooltip_text(TTR("Export list to a CSV file"));
export_csv_button->connect(SceneStringName(pressed), callable_mp(file_dialog, &EditorFileDialog::popup_file_dialog));
hb->add_child(export_csv_button);

hb->add_theme_constant_override("separation", 8 * EDSCALE);

h_split = memnew(HSplitContainer);
Expand Down
23 changes: 13 additions & 10 deletions editor/debugger/editor_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
#ifndef EDITOR_PROFILER_H
#define EDITOR_PROFILER_H

#include "editor/gui/editor_file_dialog.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/check_button.h"
#include "scene/gui/label.h"
#include "scene/gui/option_button.h"
#include "scene/gui/spin_box.h"
#include "scene/gui/split_container.h"
#include "scene/gui/texture_rect.h"
#include "scene/gui/tree.h"

class Button;
class CheckButton;
class HSplitContainer;
class ImageTexture;
class OptionButton;
class SpinBox;
class TextureRect;
class Tree;

class EditorProfiler : public VBoxContainer {
GDCLASS(EditorProfiler, VBoxContainer);
Expand Down Expand Up @@ -121,6 +121,9 @@ class EditorProfiler : public VBoxContainer {

SpinBox *cursor_metric_edit = nullptr;

EditorFileDialog *file_dialog = nullptr;
Button *export_csv_button = nullptr;

Vector<Metric> frame_metrics;
int total_metrics = 0;
int last_metric = -1;
Expand Down Expand Up @@ -168,6 +171,8 @@ class EditorProfiler : public VBoxContainer {

Metric _get_frame_metric(int index);

void _export_csv(const String &p_path) const;

protected:
void _notification(int p_what);
static void _bind_methods();
Expand All @@ -182,8 +187,6 @@ class EditorProfiler : public VBoxContainer {

void clear();

Vector<Vector<String>> get_data_as_csv() const;

EditorProfiler();
};

Expand Down
Loading

0 comments on commit a06caca

Please sign in to comment.