diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2020-02-07 02:52:05 +0100 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2020-02-21 11:12:03 +0100 |
commit | cbc450c0e53dbfc31a30f5ebf37c51cee77cde5c (patch) | |
tree | fa1e7a1e80ec7cbe0546a752732bf34b66299100 /scene/main | |
parent | 8b058d4b9a63799e29d3e9ef551bbdf8144f8f8b (diff) |
Huge Debugger/EditorDebugger refactor.
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/node.cpp | 28 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 388 | ||||
-rw-r--r-- | scene/main/scene_tree.h | 36 |
3 files changed, 8 insertions, 444 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 2c15ac6aae..6556dd6d6c 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -37,6 +37,7 @@ #include "core/message_queue.h" #include "core/print_string.h" #include "instance_placeholder.h" +#include "scene/debugger/scene_debugger.h" #include "scene/resources/packed_scene.h" #include "scene/scene_string_names.h" #include "viewport.h" @@ -244,11 +245,7 @@ void Node::_propagate_enter_tree() { data.blocked--; #ifdef DEBUG_ENABLED - - if (ScriptDebugger::get_singleton() && data.filename != String()) { - //used for live edit - data.tree->live_scene_edit_cache[data.filename].insert(this); - } + SceneDebugger::add_to_cache(data.filename, this); #endif // enter groups } @@ -268,26 +265,7 @@ void Node::_propagate_exit_tree() { //block while removing children #ifdef DEBUG_ENABLED - - if (ScriptDebugger::get_singleton() && data.filename != String()) { - //used for live edit - Map<String, Set<Node *> >::Element *E = data.tree->live_scene_edit_cache.find(data.filename); - if (E) { - E->get().erase(this); - if (E->get().size() == 0) { - data.tree->live_scene_edit_cache.erase(E); - } - } - - Map<Node *, Map<ObjectID, Node *> >::Element *F = data.tree->live_edit_remove_list.find(this); - if (F) { - for (Map<ObjectID, Node *>::Element *G = F->get().front(); G; G = G->next()) { - - memdelete(G->get()); - } - data.tree->live_edit_remove_list.erase(F); - } - } + SceneDebugger::remove_from_cache(data.filename, this); #endif data.blocked++; diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index f558670693..9f9dace9f9 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -38,9 +38,10 @@ #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/script_debugger_remote.h" +#include "scene/debugger/scene_debugger.h" #include "scene/resources/dynamic_font.h" #include "scene/resources/material.h" #include "scene/resources/mesh.h" @@ -1329,380 +1330,6 @@ void SceneTree::add_current_scene(Node *p_current) { root->add_child(p_current); } -#ifdef DEBUG_ENABLED - -static void _fill_array(Node *p_node, Array &array, int p_level) { - - array.push_back(p_node->get_child_count()); - array.push_back(p_node->get_name()); - array.push_back(p_node->get_class()); - array.push_back(p_node->get_instance_id()); - for (int i = 0; i < p_node->get_child_count(); i++) { - - _fill_array(p_node->get_child(i), array, p_level + 1); - } -} - -void SceneTree::_debugger_request_tree() { - - Array arr; - _fill_array(root, arr, 0); - ScriptDebugger::get_singleton()->send_message("scene_tree", arr); -} - -void SceneTree::_live_edit_node_path_func(const NodePath &p_path, int p_id) { - - live_edit_node_path_cache[p_id] = p_path; -} - -void SceneTree::_live_edit_res_path_func(const String &p_path, int p_id) { - - live_edit_resource_cache[p_id] = p_path; -} - -void SceneTree::_live_edit_node_set_func(int p_id, const StringName &p_prop, const Variant &p_value) { - - if (!live_edit_node_path_cache.has(p_id)) - return; - - NodePath np = live_edit_node_path_cache[p_id]; - Node *base = NULL; - if (root->has_node(live_edit_root)) - base = root->get_node(live_edit_root); - - Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); - if (!E) - return; //scene not editable - - for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { - - Node *n = F->get(); - - if (base && !base->is_a_parent_of(n)) - continue; - - if (!n->has_node(np)) - continue; - Node *n2 = n->get_node(np); - - n2->set(p_prop, p_value); - } -} - -void SceneTree::_live_edit_node_set_res_func(int p_id, const StringName &p_prop, const String &p_value) { - - RES r = ResourceLoader::load(p_value); - if (!r.is_valid()) - return; - _live_edit_node_set_func(p_id, p_prop, r); -} -void SceneTree::_live_edit_node_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE) { - - if (!live_edit_node_path_cache.has(p_id)) - return; - - NodePath np = live_edit_node_path_cache[p_id]; - Node *base = NULL; - if (root->has_node(live_edit_root)) - base = root->get_node(live_edit_root); - - Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); - if (!E) - return; //scene not editable - - for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { - - Node *n = F->get(); - - if (base && !base->is_a_parent_of(n)) - continue; - - if (!n->has_node(np)) - continue; - Node *n2 = n->get_node(np); - - n2->call(p_method, VARIANT_ARG_PASS); - } -} -void SceneTree::_live_edit_res_set_func(int p_id, const StringName &p_prop, const Variant &p_value) { - - if (!live_edit_resource_cache.has(p_id)) - return; - - String resp = live_edit_resource_cache[p_id]; - - if (!ResourceCache::has(resp)) - return; - - RES r = ResourceCache::get(resp); - if (!r.is_valid()) - return; - - r->set(p_prop, p_value); -} -void SceneTree::_live_edit_res_set_res_func(int p_id, const StringName &p_prop, const String &p_value) { - - RES r = ResourceLoader::load(p_value); - if (!r.is_valid()) - return; - _live_edit_res_set_func(p_id, p_prop, r); -} -void SceneTree::_live_edit_res_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE) { - - if (!live_edit_resource_cache.has(p_id)) - return; - - String resp = live_edit_resource_cache[p_id]; - - if (!ResourceCache::has(resp)) - return; - - RES r = ResourceCache::get(resp); - if (!r.is_valid()) - return; - - r->call(p_method, VARIANT_ARG_PASS); -} - -void SceneTree::_live_edit_root_func(const NodePath &p_scene_path, const String &p_scene_from) { - - live_edit_root = p_scene_path; - live_edit_scene = p_scene_from; -} - -void SceneTree::_live_edit_create_node_func(const NodePath &p_parent, const String &p_type, const String &p_name) { - - Node *base = NULL; - if (root->has_node(live_edit_root)) - base = root->get_node(live_edit_root); - - Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); - if (!E) - return; //scene not editable - - for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { - - Node *n = F->get(); - - if (base && !base->is_a_parent_of(n)) - continue; - - if (!n->has_node(p_parent)) - continue; - Node *n2 = n->get_node(p_parent); - - Node *no = Object::cast_to<Node>(ClassDB::instance(p_type)); - if (!no) { - continue; - } - - no->set_name(p_name); - n2->add_child(no); - } -} -void SceneTree::_live_edit_instance_node_func(const NodePath &p_parent, const String &p_path, const String &p_name) { - - Ref<PackedScene> ps = ResourceLoader::load(p_path); - - if (!ps.is_valid()) - return; - - Node *base = NULL; - if (root->has_node(live_edit_root)) - base = root->get_node(live_edit_root); - - Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); - if (!E) - return; //scene not editable - - for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { - - Node *n = F->get(); - - if (base && !base->is_a_parent_of(n)) - continue; - - if (!n->has_node(p_parent)) - continue; - Node *n2 = n->get_node(p_parent); - - Node *no = ps->instance(); - if (!no) { - continue; - } - - no->set_name(p_name); - n2->add_child(no); - } -} -void SceneTree::_live_edit_remove_node_func(const NodePath &p_at) { - - Node *base = NULL; - if (root->has_node(live_edit_root)) - base = root->get_node(live_edit_root); - - Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); - if (!E) - return; //scene not editable - - for (Set<Node *>::Element *F = E->get().front(); F;) { - - Set<Node *>::Element *N = F->next(); - - Node *n = F->get(); - - if (base && !base->is_a_parent_of(n)) - continue; - - if (!n->has_node(p_at)) - continue; - Node *n2 = n->get_node(p_at); - - memdelete(n2); - - F = N; - } -} -void SceneTree::_live_edit_remove_and_keep_node_func(const NodePath &p_at, ObjectID p_keep_id) { - - Node *base = NULL; - if (root->has_node(live_edit_root)) - base = root->get_node(live_edit_root); - - Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); - if (!E) - return; //scene not editable - - for (Set<Node *>::Element *F = E->get().front(); F;) { - - Set<Node *>::Element *N = F->next(); - - Node *n = F->get(); - - if (base && !base->is_a_parent_of(n)) - continue; - - if (!n->has_node(p_at)) - continue; - - Node *n2 = n->get_node(p_at); - - n2->get_parent()->remove_child(n2); - - live_edit_remove_list[n][p_keep_id] = n2; - - F = N; - } -} -void SceneTree::_live_edit_restore_node_func(ObjectID p_id, const NodePath &p_at, int p_at_pos) { - - Node *base = NULL; - if (root->has_node(live_edit_root)) - base = root->get_node(live_edit_root); - - Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); - if (!E) - return; //scene not editable - - for (Set<Node *>::Element *F = E->get().front(); F;) { - - Set<Node *>::Element *N = F->next(); - - Node *n = F->get(); - - if (base && !base->is_a_parent_of(n)) - continue; - - if (!n->has_node(p_at)) - continue; - Node *n2 = n->get_node(p_at); - - Map<Node *, Map<ObjectID, Node *> >::Element *EN = live_edit_remove_list.find(n); - - if (!EN) - continue; - - Map<ObjectID, Node *>::Element *FN = EN->get().find(p_id); - - if (!FN) - continue; - n2->add_child(FN->get()); - - EN->get().erase(FN); - - if (EN->get().size() == 0) { - live_edit_remove_list.erase(EN); - } - - F = N; - } -} -void SceneTree::_live_edit_duplicate_node_func(const NodePath &p_at, const String &p_new_name) { - - Node *base = NULL; - if (root->has_node(live_edit_root)) - base = root->get_node(live_edit_root); - - Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); - if (!E) - return; //scene not editable - - for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { - - Node *n = F->get(); - - if (base && !base->is_a_parent_of(n)) - continue; - - if (!n->has_node(p_at)) - continue; - Node *n2 = n->get_node(p_at); - - Node *dup = n2->duplicate(Node::DUPLICATE_SIGNALS | Node::DUPLICATE_GROUPS | Node::DUPLICATE_SCRIPTS); - - if (!dup) - continue; - - dup->set_name(p_new_name); - n2->get_parent()->add_child(dup); - } -} -void SceneTree::_live_edit_reparent_node_func(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) { - - Node *base = NULL; - if (root->has_node(live_edit_root)) - base = root->get_node(live_edit_root); - - Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); - if (!E) - return; //scene not editable - - for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { - - Node *n = F->get(); - - if (base && !base->is_a_parent_of(n)) - continue; - - if (!n->has_node(p_at)) - continue; - Node *nfrom = n->get_node(p_at); - - if (!n->has_node(p_new_place)) - continue; - Node *nto = n->get_node(p_new_place); - - nfrom->get_parent()->remove_child(nfrom); - nfrom->set_name(p_new_name); - - nto->add_child(nfrom); - if (p_at_pos >= 0) - nto->move_child(nfrom, p_at_pos); - } -} - -#endif - void SceneTree::drop_files(const Vector<String> &p_files, int p_from_screen) { emit_signal("files_dropped", p_files, p_from_screen); @@ -2116,11 +1743,6 @@ SceneTree::SceneTree() { _update_root_rect(); if (ScriptDebugger::get_singleton()) { - if (ScriptDebugger::get_singleton()->is_remote()) { - ScriptDebuggerRemote *remote_debugger = static_cast<ScriptDebuggerRemote *>(ScriptDebugger::get_singleton()); - - remote_debugger->set_scene_tree(this); - } ScriptDebugger::get_singleton()->set_multiplayer(multiplayer); } @@ -2129,12 +1751,6 @@ SceneTree::SceneTree() { #ifdef TOOLS_ENABLED edited_scene_root = NULL; #endif - -#ifdef DEBUG_ENABLED - - live_edit_root = NodePath("/root"); - -#endif } SceneTree::~SceneTree() { diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index 80f0da66e2..1bef0d3131 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -44,6 +44,7 @@ class Node; class Viewport; class Material; class Mesh; +class SceneDebugger; class SceneTreeTimer : public Reference { GDCLASS(SceneTreeTimer, Reference); @@ -219,39 +220,8 @@ private: SelfList<Node>::List xform_change_list; - friend class ScriptDebuggerRemote; -#ifdef DEBUG_ENABLED - - Map<int, NodePath> live_edit_node_path_cache; - Map<int, String> live_edit_resource_cache; - - NodePath live_edit_root; - String live_edit_scene; - - Map<String, Set<Node *> > live_scene_edit_cache; - Map<Node *, Map<ObjectID, Node *> > live_edit_remove_list; - - void _debugger_request_tree(); - - void _live_edit_node_path_func(const NodePath &p_path, int p_id); - void _live_edit_res_path_func(const String &p_path, int p_id); - - void _live_edit_node_set_func(int p_id, const StringName &p_prop, const Variant &p_value); - void _live_edit_node_set_res_func(int p_id, const StringName &p_prop, const String &p_value); - void _live_edit_node_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE); - void _live_edit_res_set_func(int p_id, const StringName &p_prop, const Variant &p_value); - void _live_edit_res_set_res_func(int p_id, const StringName &p_prop, const String &p_value); - void _live_edit_res_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE); - void _live_edit_root_func(const NodePath &p_scene_path, const String &p_scene_from); - - void _live_edit_create_node_func(const NodePath &p_parent, const String &p_type, const String &p_name); - void _live_edit_instance_node_func(const NodePath &p_parent, const String &p_path, const String &p_name); - void _live_edit_remove_node_func(const NodePath &p_at); - void _live_edit_remove_and_keep_node_func(const NodePath &p_at, ObjectID p_keep_id); - void _live_edit_restore_node_func(ObjectID p_id, const NodePath &p_at, int p_at_pos); - void _live_edit_duplicate_node_func(const NodePath &p_at, const String &p_new_name); - void _live_edit_reparent_node_func(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos); - +#ifdef DEBUG_ENABLED // No live editor in release build. + friend class LiveEditor; #endif enum { |