1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-12 13:20:55 +00:00

Huge Debugger/EditorDebugger refactor.

This commit is contained in:
Fabio Alessandrelli
2020-02-07 02:52:05 +01:00
parent 8b058d4b9a
commit cbc450c0e5
41 changed files with 4487 additions and 3292 deletions

View File

@@ -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() {