summaryrefslogtreecommitdiffstats
path: root/editor/debugger
diff options
context:
space:
mode:
authorMichael Alexsander <michaelalexsander@protonmail.com>2024-09-18 18:07:18 -0300
committerMichael Alexsander <michaelalexsander@protonmail.com>2024-10-30 11:42:17 -0300
commit16524a8a01408480ce2063461c8c042bc4eb3fa8 (patch)
treef82806e99d030ed26ddec9347681430db49fe199 /editor/debugger
parent8004c7524fb9f43425c4d6f614410a76678e0f7c (diff)
downloadredot-engine-16524a8a01408480ce2063461c8c042bc4eb3fa8.tar.gz
Add "Game" editor for better runtime debugging
Diffstat (limited to 'editor/debugger')
-rw-r--r--editor/debugger/editor_debugger_node.cpp8
-rw-r--r--editor/debugger/editor_debugger_node.h8
-rw-r--r--editor/debugger/editor_debugger_tree.cpp38
-rw-r--r--editor/debugger/editor_debugger_tree.h3
-rw-r--r--editor/debugger/script_editor_debugger.cpp89
5 files changed, 90 insertions, 56 deletions
diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp
index ee8aae661b..0f948b4ed5 100644
--- a/editor/debugger/editor_debugger_node.cpp
+++ b/editor/debugger/editor_debugger_node.cpp
@@ -105,6 +105,7 @@ ScriptEditorDebugger *EditorDebuggerNode::_add_debugger() {
node->connect("breakpoint_selected", callable_mp(this, &EditorDebuggerNode::_error_selected).bind(id));
node->connect("clear_execution", callable_mp(this, &EditorDebuggerNode::_clear_execution));
node->connect("breaked", callable_mp(this, &EditorDebuggerNode::_breaked).bind(id));
+ node->connect("remote_tree_select_requested", callable_mp(this, &EditorDebuggerNode::_remote_tree_select_requested).bind(id));
node->connect("remote_tree_updated", callable_mp(this, &EditorDebuggerNode::_remote_tree_updated).bind(id));
node->connect("remote_object_updated", callable_mp(this, &EditorDebuggerNode::_remote_object_updated).bind(id));
node->connect("remote_object_property_updated", callable_mp(this, &EditorDebuggerNode::_remote_object_property_updated).bind(id));
@@ -637,6 +638,13 @@ void EditorDebuggerNode::request_remote_tree() {
get_current_debugger()->request_remote_tree();
}
+void EditorDebuggerNode::_remote_tree_select_requested(ObjectID p_id, int p_debugger) {
+ if (p_debugger != tabs->get_current_tab()) {
+ return;
+ }
+ remote_scene_tree->select_node(p_id);
+}
+
void EditorDebuggerNode::_remote_tree_updated(int p_debugger) {
if (p_debugger != tabs->get_current_tab()) {
return;
diff --git a/editor/debugger/editor_debugger_node.h b/editor/debugger/editor_debugger_node.h
index 12e097f652..12c0d30c42 100644
--- a/editor/debugger/editor_debugger_node.h
+++ b/editor/debugger/editor_debugger_node.h
@@ -51,11 +51,8 @@ class EditorDebuggerNode : public MarginContainer {
public:
enum CameraOverride {
OVERRIDE_NONE,
- OVERRIDE_2D,
- OVERRIDE_3D_1, // 3D Viewport 1
- OVERRIDE_3D_2, // 3D Viewport 2
- OVERRIDE_3D_3, // 3D Viewport 3
- OVERRIDE_3D_4 // 3D Viewport 4
+ OVERRIDE_INGAME,
+ OVERRIDE_EDITORS,
};
private:
@@ -132,6 +129,7 @@ protected:
void _debugger_stopped(int p_id);
void _debugger_wants_stop(int p_id);
void _debugger_changed(int p_tab);
+ void _remote_tree_select_requested(ObjectID p_id, int p_debugger);
void _remote_tree_updated(int p_debugger);
void _remote_tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
void _remote_object_updated(ObjectID p_id, int p_debugger);
diff --git a/editor/debugger/editor_debugger_tree.cpp b/editor/debugger/editor_debugger_tree.cpp
index a900842651..4d67800e6e 100644
--- a/editor/debugger/editor_debugger_tree.cpp
+++ b/editor/debugger/editor_debugger_tree.cpp
@@ -30,6 +30,7 @@
#include "editor_debugger_tree.h"
+#include "editor/debugger/editor_debugger_node.h"
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
#include "editor/gui/editor_file_dialog.h"
@@ -148,7 +149,8 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int
updating_scene_tree = true;
const String last_path = get_selected_path();
const String filter = SceneTreeDock::get_singleton()->get_filter();
- bool filter_changed = filter != last_filter;
+ bool should_scroll = scrolling_to_item || filter != last_filter;
+ scrolling_to_item = false;
TreeItem *scroll_item = nullptr;
// Nodes are in a flatten list, depth first. Use a stack of parents, avoid recursion.
@@ -185,8 +187,18 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int
// Select previously selected node.
if (debugger_id == p_debugger) { // Can use remote id.
if (node.id == inspected_object_id) {
+ if (selection_uncollapse_all) {
+ selection_uncollapse_all = false;
+
+ // Temporarily set to `false`, to allow caching the unfolds.
+ updating_scene_tree = false;
+ item->uncollapse_tree();
+ updating_scene_tree = true;
+ }
+
item->select(0);
- if (filter_changed) {
+
+ if (should_scroll) {
scroll_item = item;
}
}
@@ -194,7 +206,7 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int
if (last_path == _get_path(item)) {
updating_scene_tree = false; // Force emission of new selection.
item->select(0);
- if (filter_changed) {
+ if (should_scroll) {
scroll_item = item;
}
updating_scene_tree = true;
@@ -258,14 +270,30 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int
}
}
}
- debugger_id = p_debugger; // Needed by hook, could be avoided if every debugger had its own tree
+
+ debugger_id = p_debugger; // Needed by hook, could be avoided if every debugger had its own tree.
if (scroll_item) {
- callable_mp((Tree *)this, &Tree::scroll_to_item).call_deferred(scroll_item, false);
+ scroll_to_item(scroll_item, false);
}
last_filter = filter;
updating_scene_tree = false;
}
+void EditorDebuggerTree::select_node(ObjectID p_id) {
+ // Manually select, as the tree control may be out-of-date for some reason (e.g. not shown yet).
+ selection_uncollapse_all = true;
+ inspected_object_id = uint64_t(p_id);
+ scrolling_to_item = true;
+ emit_signal(SNAME("object_selected"), inspected_object_id, debugger_id);
+
+ if (!updating_scene_tree) {
+ // Request a tree refresh.
+ EditorDebuggerNode::get_singleton()->request_remote_tree();
+ }
+ // Set the value immediately, so no update flooding happens and causes a crash.
+ updating_scene_tree = true;
+}
+
Variant EditorDebuggerTree::get_drag_data(const Point2 &p_point) {
if (get_button_id_at_position(p_point) != -1) {
return Variant();
diff --git a/editor/debugger/editor_debugger_tree.h b/editor/debugger/editor_debugger_tree.h
index 705df17baf..d048688cad 100644
--- a/editor/debugger/editor_debugger_tree.h
+++ b/editor/debugger/editor_debugger_tree.h
@@ -49,6 +49,8 @@ private:
ObjectID inspected_object_id;
int debugger_id = 0;
bool updating_scene_tree = false;
+ bool scrolling_to_item = false;
+ bool selection_uncollapse_all = false;
HashSet<ObjectID> unfold_cache;
PopupMenu *item_menu = nullptr;
EditorFileDialog *file_dialog = nullptr;
@@ -78,6 +80,7 @@ public:
ObjectID get_selected_object();
int get_current_debugger(); // Would love to have one tree for every debugger.
void update_scene_tree(const SceneDebuggerTree *p_tree, int p_debugger);
+ void select_node(ObjectID p_id);
EditorDebuggerTree();
};
diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp
index c42740de50..b78aad1721 100644
--- a/editor/debugger/script_editor_debugger.cpp
+++ b/editor/debugger/script_editor_debugger.cpp
@@ -806,6 +806,10 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, uint64_t p_thread
} else if (p_msg == "request_quit") {
emit_signal(SNAME("stop_requested"));
_stop_and_notify();
+ } else if (p_msg == "remote_node_clicked") {
+ if (!p_data.is_empty()) {
+ emit_signal(SNAME("remote_tree_select_requested"), p_data[0]);
+ }
} else if (p_msg == "performance:profile_names") {
Vector<StringName> monitors;
monitors.resize(p_data.size());
@@ -905,37 +909,42 @@ void ScriptEditorDebugger::_notification(int p_what) {
if (is_session_active()) {
peer->poll();
- if (camera_override == CameraOverride::OVERRIDE_2D) {
- Dictionary state = CanvasItemEditor::get_singleton()->get_state();
- float zoom = state["zoom"];
- Point2 offset = state["ofs"];
- Transform2D transform;
-
- transform.scale_basis(Size2(zoom, zoom));
- transform.columns[2] = -offset * zoom;
-
- Array msg;
- msg.push_back(transform);
- _put_msg("scene:override_camera_2D:transform", msg);
-
- } else if (camera_override >= CameraOverride::OVERRIDE_3D_1) {
- int viewport_idx = camera_override - CameraOverride::OVERRIDE_3D_1;
- Node3DEditorViewport *viewport = Node3DEditor::get_singleton()->get_editor_viewport(viewport_idx);
- Camera3D *const cam = viewport->get_camera_3d();
-
- Array msg;
- msg.push_back(cam->get_camera_transform());
- if (cam->get_projection() == Camera3D::PROJECTION_ORTHOGONAL) {
- msg.push_back(false);
- msg.push_back(cam->get_size());
- } else {
- msg.push_back(true);
- msg.push_back(cam->get_fov());
+ if (camera_override == CameraOverride::OVERRIDE_EDITORS) {
+ // CanvasItem Editor
+ {
+ Dictionary state = CanvasItemEditor::get_singleton()->get_state();
+ float zoom = state["zoom"];
+ Point2 offset = state["ofs"];
+ Transform2D transform;
+
+ transform.scale_basis(Size2(zoom, zoom));
+ transform.columns[2] = -offset * zoom;
+
+ Array msg;
+ msg.push_back(transform);
+ _put_msg("scene:transform_camera_2d", msg);
+ }
+
+ // Node3D Editor
+ {
+ Node3DEditorViewport *viewport = Node3DEditor::get_singleton()->get_last_used_viewport();
+ const Camera3D *cam = viewport->get_camera_3d();
+
+ Array msg;
+ msg.push_back(cam->get_camera_transform());
+ if (cam->get_projection() == Camera3D::PROJECTION_ORTHOGONAL) {
+ msg.push_back(false);
+ msg.push_back(cam->get_size());
+ } else {
+ msg.push_back(true);
+ msg.push_back(cam->get_fov());
+ }
+ msg.push_back(cam->get_near());
+ msg.push_back(cam->get_far());
+ _put_msg("scene:transform_camera_3d", msg);
}
- msg.push_back(cam->get_near());
- msg.push_back(cam->get_far());
- _put_msg("scene:override_camera_3D:transform", msg);
}
+
if (is_breaked() && can_request_idle_draw) {
_put_msg("servers:draw", Array());
can_request_idle_draw = false;
@@ -1469,23 +1478,10 @@ CameraOverride ScriptEditorDebugger::get_camera_override() const {
}
void ScriptEditorDebugger::set_camera_override(CameraOverride p_override) {
- if (p_override == CameraOverride::OVERRIDE_2D && camera_override != CameraOverride::OVERRIDE_2D) {
- Array msg;
- msg.push_back(true);
- _put_msg("scene:override_camera_2D:set", msg);
- } else if (p_override != CameraOverride::OVERRIDE_2D && camera_override == CameraOverride::OVERRIDE_2D) {
- Array msg;
- msg.push_back(false);
- _put_msg("scene:override_camera_2D:set", msg);
- } else if (p_override >= CameraOverride::OVERRIDE_3D_1 && camera_override < CameraOverride::OVERRIDE_3D_1) {
- Array msg;
- msg.push_back(true);
- _put_msg("scene:override_camera_3D:set", msg);
- } else if (p_override < CameraOverride::OVERRIDE_3D_1 && camera_override >= CameraOverride::OVERRIDE_3D_1) {
- Array msg;
- msg.push_back(false);
- _put_msg("scene:override_camera_3D:set", msg);
- }
+ Array msg;
+ msg.push_back(p_override != CameraOverride::OVERRIDE_NONE);
+ msg.push_back(p_override == CameraOverride::OVERRIDE_EDITORS);
+ _put_msg("scene:override_cameras", msg);
camera_override = p_override;
}
@@ -1776,6 +1772,7 @@ void ScriptEditorDebugger::_bind_methods() {
ADD_SIGNAL(MethodInfo("remote_object_updated", PropertyInfo(Variant::INT, "id")));
ADD_SIGNAL(MethodInfo("remote_object_property_updated", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "property")));
ADD_SIGNAL(MethodInfo("remote_tree_updated"));
+ ADD_SIGNAL(MethodInfo("remote_tree_select_requested", PropertyInfo(Variant::NODE_PATH, "path")));
ADD_SIGNAL(MethodInfo("output", PropertyInfo(Variant::STRING, "msg"), PropertyInfo(Variant::INT, "level")));
ADD_SIGNAL(MethodInfo("stack_dump", PropertyInfo(Variant::ARRAY, "stack_dump")));
ADD_SIGNAL(MethodInfo("stack_frame_vars", PropertyInfo(Variant::INT, "num_vars")));