Implement Autostart Feature for Profiler / Visual Profiler / Network Profiler

Co-authored-by: stmSi <stm1998sithumyo@gmail.com>
This commit is contained in:
Hendrik Brucker
2024-09-10 19:40:42 +02:00
parent 27552a2f26
commit c53fd9c7be
8 changed files with 91 additions and 12 deletions

View File

@@ -34,6 +34,7 @@
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/check_box.h"
void EditorNetworkProfiler::_bind_methods() {
ADD_SIGNAL(MethodInfo("enable_profiling", PropertyInfo(Variant::BOOL, "enable")));
@@ -170,15 +171,42 @@ void EditorNetworkProfiler::add_node_data(const NodeInfo &p_info) {
}
void EditorNetworkProfiler::_activate_pressed() {
_update_button_text();
if (activate->is_pressed()) {
refresh_timer->start();
} else {
refresh_timer->stop();
}
emit_signal(SNAME("enable_profiling"), activate->is_pressed());
}
void EditorNetworkProfiler::_update_button_text() {
if (activate->is_pressed()) {
activate->set_icon(theme_cache.stop_icon);
activate->set_text(TTR("Stop"));
} else {
refresh_timer->stop();
activate->set_icon(theme_cache.play_icon);
activate->set_text(TTR("Start"));
}
}
void EditorNetworkProfiler::started() {
if (EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_network_profiler", false)) {
set_profiling(true);
refresh_timer->start();
}
}
void EditorNetworkProfiler::stopped() {
set_profiling(false);
refresh_timer->stop();
}
void EditorNetworkProfiler::set_profiling(bool p_pressed) {
activate->set_pressed(p_pressed);
_update_button_text();
emit_signal(SNAME("enable_profiling"), activate->is_pressed());
}
@@ -192,6 +220,10 @@ void EditorNetworkProfiler::_clear_pressed() {
refresh_replication_data();
}
void EditorNetworkProfiler::_autostart_toggled(bool p_toggled_on) {
EditorSettings::get_singleton()->set_project_metadata("debug_options", "autostart_network_profiler", p_toggled_on);
}
void EditorNetworkProfiler::_replication_button_clicked(TreeItem *p_item, int p_column, int p_idx, MouseButton p_button) {
if (!p_item) {
return;
@@ -268,6 +300,12 @@ EditorNetworkProfiler::EditorNetworkProfiler() {
clear_button->connect(SceneStringName(pressed), callable_mp(this, &EditorNetworkProfiler::_clear_pressed));
hb->add_child(clear_button);
CheckBox *autostart_checkbox = memnew(CheckBox);
autostart_checkbox->set_text(TTR("Autostart"));
autostart_checkbox->set_pressed(EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_network_profiler", false));
autostart_checkbox->connect(SceneStringName(toggled), callable_mp(this, &EditorNetworkProfiler::_autostart_toggled));
hb->add_child(autostart_checkbox);
hb->add_spacer();
Label *lb = memnew(Label);

View File

@@ -92,7 +92,9 @@ private:
void _activate_pressed();
void _clear_pressed();
void _autostart_toggled(bool p_toggled_on);
void _refresh();
void _update_button_text();
void _replication_button_clicked(TreeItem *p_item, int p_column, int p_idx, MouseButton p_button);
protected:
@@ -112,6 +114,10 @@ public:
void set_bandwidth(int p_incoming, int p_outgoing);
bool is_profiling();
void set_profiling(bool p_pressed);
void started();
void stopped();
EditorNetworkProfiler();
};

View File

@@ -106,6 +106,8 @@ void MultiplayerEditorDebugger::setup_session(int p_session_id) {
profiler->connect("enable_profiling", callable_mp(this, &MultiplayerEditorDebugger::_profiler_activate).bind(p_session_id));
profiler->connect("open_request", callable_mp(this, &MultiplayerEditorDebugger::_open_request));
profiler->set_name(TTR("Network Profiler"));
session->connect("started", callable_mp(profiler, &EditorNetworkProfiler::started));
session->connect("stopped", callable_mp(profiler, &EditorNetworkProfiler::stopped));
session->add_session_tab(profiler);
profilers[p_session_id] = profiler;
}