summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-02-27 03:30:20 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-03-08 12:36:39 +0100
commitb8ddaf9c33107e01928e04ed462aa08d4017247b (patch)
tree6ab71cdcbfd372e8390baa6ac30a2974fe43d119 /scene
parentd0009636df6544dd26ab7c568a0244af6a20634a (diff)
Refactor ScriptDebugger.
EngineDebugger is the new interface to access the debugger. It tries to be as agnostic as possible on the data that various subsystems can expose. It allows 2 types of interactions: - Profilers: A subsystem can register a profiler, assigning it a unique name. That name can be used to activate the profiler or add data to it. The registered profiler can be composed of up to 3 functions: - Toggle: called when the profiler is activated/deactivated. - Add: called whenever data is added to the debugger (via `EngineDebugger::profiler_add_frame_data`) - Tick: called every frame (during idle), receives frame times. - Captures: (Only relevant in remote debugger for now) A subsystem can register a capture, assigning it a unique name. When receiving a message, the remote debugger will check if it starts with `[prefix]:` and call the associated capture with name `prefix`. Port MultiplayerAPI, Servers, Scripts, Visual, Performance to the new profiler system. Port SceneDebugger and RemoteDebugger to the new capture system. The LocalDebugger also uses the new profiler system for scripts profiling.
Diffstat (limited to 'scene')
-rw-r--r--scene/debugger/scene_debugger.cpp21
-rw-r--r--scene/debugger/scene_debugger.h5
-rw-r--r--scene/main/scene_tree.cpp10
-rw-r--r--scene/main/viewport.cpp5
4 files changed, 22 insertions, 19 deletions
diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp
index 22ff0611a7..2a98b4cf22 100644
--- a/scene/debugger/scene_debugger.cpp
+++ b/scene/debugger/scene_debugger.cpp
@@ -30,8 +30,9 @@
#include "scene_debugger.h"
+#include "core/debugger/engine_debugger.h"
#include "core/io/marshalls.h"
-#include "core/script_debugger_remote.h"
+#include "core/script_language.h"
#include "scene/main/scene_tree.h"
#include "scene/main/viewport.h"
#include "scene/resources/packed_scene.h"
@@ -39,13 +40,16 @@
void SceneDebugger::initialize() {
#ifdef DEBUG_ENABLED
LiveEditor::singleton = memnew(LiveEditor);
- ScriptDebuggerRemote::scene_tree_parse_func = SceneDebugger::parse_message;
+ EngineDebugger::register_message_capture("scene", EngineDebugger::Capture(NULL, SceneDebugger::parse_message));
#endif
}
void SceneDebugger::deinitialize() {
#ifdef DEBUG_ENABLED
if (LiveEditor::singleton) {
+ // Should be removed automatically when deiniting debugger, but just in case
+ if (EngineDebugger::has_capture("scene"))
+ EngineDebugger::unregister_message_capture("scene");
memdelete(LiveEditor::singleton);
LiveEditor::singleton = NULL;
}
@@ -53,13 +57,15 @@ void SceneDebugger::deinitialize() {
}
#ifdef DEBUG_ENABLED
-Error SceneDebugger::parse_message(const String &p_msg, const Array &p_args) {
+Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured) {
SceneTree *scene_tree = SceneTree::get_singleton();
if (!scene_tree)
return ERR_UNCONFIGURED;
LiveEditor *live_editor = LiveEditor::get_singleton();
if (!live_editor)
return ERR_UNCONFIGURED;
+
+ r_captured = true;
if (p_msg == "request_scene_tree") { // Scene tree
live_editor->_send_tree();
@@ -171,7 +177,7 @@ Error SceneDebugger::parse_message(const String &p_msg, const Array &p_args) {
ERR_FAIL_COND_V(p_args.size() < 4, ERR_INVALID_DATA);
live_editor->_reparent_node_func(p_args[0], p_args[1], p_args[2], p_args[3]);
} else {
- return ERR_SKIP;
+ r_captured = false;
}
return OK;
}
@@ -180,7 +186,6 @@ void SceneDebugger::_save_node(ObjectID id, const String &p_path) {
Node *node = Object::cast_to<Node>(ObjectDB::get_instance(id));
ERR_FAIL_COND(!node);
- WARN_PRINT("SAVING " + itos(id) + " TO " + p_path);
Ref<PackedScene> ps = memnew(PackedScene);
ps->pack(node);
ResourceSaver::save(p_path, ps);
@@ -193,7 +198,7 @@ void SceneDebugger::_send_object_id(ObjectID p_id, int p_max_size) {
Array arr;
obj.serialize(arr);
- ScriptDebugger::get_singleton()->send_message("inspect_object", arr);
+ EngineDebugger::get_singleton()->send_message("scene:inspect_object", arr);
}
void SceneDebugger::_set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value) {
@@ -216,7 +221,7 @@ void SceneDebugger::add_to_cache(const String &p_filename, Node *p_node) {
if (!debugger)
return;
- if (ScriptDebugger::get_singleton() && p_filename != String()) {
+ if (EngineDebugger::get_script_debugger() && p_filename != String()) {
debugger->live_scene_edit_cache[p_filename].insert(p_node);
}
}
@@ -487,7 +492,7 @@ void LiveEditor::_send_tree() {
// Encoded as a flat list depth fist.
SceneDebuggerTree tree(scene_tree->root);
tree.serialize(arr);
- ScriptDebugger::get_singleton()->send_message("scene_tree", arr);
+ EngineDebugger::get_singleton()->send_message("scene:scene_tree", arr);
}
void LiveEditor::_node_path_func(const NodePath &p_path, int p_id) {
diff --git a/scene/debugger/scene_debugger.h b/scene/debugger/scene_debugger.h
index d22f8e8e18..afe58a5d01 100644
--- a/scene/debugger/scene_debugger.h
+++ b/scene/debugger/scene_debugger.h
@@ -34,9 +34,10 @@
#include "core/array.h"
#include "core/object.h"
#include "core/pair.h"
-#include "core/script_language.h"
#include "core/ustring.h"
+class Script;
+
class SceneDebugger {
public:
@@ -50,7 +51,7 @@ private:
static void _send_object_id(ObjectID p_id, int p_max_size = 1 << 20);
public:
- static Error parse_message(const String &p_msg, const Array &p_args);
+ static Error parse_message(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured);
static void add_to_cache(const String &p_filename, Node *p_node);
static void remove_from_cache(const String &p_filename, Node *p_node);
#endif
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 370cf6a2a4..57bb3b6b5e 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -30,6 +30,7 @@
#include "scene_tree.h"
+#include "core/debugger/engine_debugger.h"
#include "core/io/marshalls.h"
#include "core/io/resource_loader.h"
#include "core/message_queue.h"
@@ -38,7 +39,6 @@
#include "core/os/os.h"
#include "core/print_string.h"
#include "core/project_settings.h"
-#include "core/script_debugger_remote.h"
#include "main/input_default.h"
#include "node.h"
#include "scene/debugger/scene_debugger.h"
@@ -432,11 +432,11 @@ void SceneTree::input_event(const Ref<InputEvent> &p_event) {
call_group_flags(GROUP_CALL_REALTIME, "_viewports", "_vp_input", ev); //special one for GUI, as controls use their own process check
- if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_remote()) {
+ if (EngineDebugger::is_active()) {
//quit from game window using F8
Ref<InputEventKey> k = ev;
if (k.is_valid() && k->is_pressed() && !k->is_echo() && k->get_keycode() == KEY_F8) {
- ScriptDebugger::get_singleton()->request_quit();
+ EngineDebugger::get_singleton()->send_message("request_quit", Array());
}
}
@@ -1737,10 +1737,6 @@ SceneTree::SceneTree() {
last_screen_size = Size2(OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height);
_update_root_rect();
- if (ScriptDebugger::get_singleton()) {
- ScriptDebugger::get_singleton()->set_multiplayer(multiplayer);
- }
-
root->set_physics_object_picking(GLOBAL_DEF("physics/common/enable_object_picking", true));
#ifdef TOOLS_ENABLED
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index e027ec9b4b..c11b11bc71 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -31,6 +31,7 @@
#include "viewport.h"
#include "core/core_string_names.h"
+#include "core/debugger/engine_debugger.h"
#include "core/os/input.h"
#include "core/os/os.h"
#include "core/project_settings.h"
@@ -1927,12 +1928,12 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
mb->set_position(pos);
#ifdef DEBUG_ENABLED
- if (ScriptDebugger::get_singleton() && gui.mouse_focus) {
+ if (EngineDebugger::get_singleton() && gui.mouse_focus) {
Array arr;
arr.push_back(gui.mouse_focus->get_path());
arr.push_back(gui.mouse_focus->get_class());
- ScriptDebugger::get_singleton()->send_message("click_ctrl", arr);
+ EngineDebugger::get_singleton()->send_message("scene:click_ctrl", arr);
}
#endif