summaryrefslogtreecommitdiff
path: root/scene/debugger
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-02-07 02:52:05 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-02-21 11:12:03 +0100
commitcbc450c0e53dbfc31a30f5ebf37c51cee77cde5c (patch)
treefa1e7a1e80ec7cbe0546a752732bf34b66299100 /scene/debugger
parent8b058d4b9a63799e29d3e9ef551bbdf8144f8f8b (diff)
Huge Debugger/EditorDebugger refactor.
Diffstat (limited to 'scene/debugger')
-rw-r--r--scene/debugger/scene_debugger.cpp867
-rw-r--r--scene/debugger/scene_debugger.h151
-rw-r--r--scene/debugger/script_debugger_remote.cpp1313
-rw-r--r--scene/debugger/script_debugger_remote.h197
4 files changed, 1018 insertions, 1510 deletions
diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp
new file mode 100644
index 0000000000..9b9f0455a1
--- /dev/null
+++ b/scene/debugger/scene_debugger.cpp
@@ -0,0 +1,867 @@
+/*************************************************************************/
+/* scene_debugger.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "scene_debugger.h"
+
+#include "core/io/marshalls.h"
+#include "core/script_debugger_remote.h"
+#include "scene/main/scene_tree.h"
+#include "scene/main/viewport.h"
+#include "scene/resources/packed_scene.h"
+
+void SceneDebugger::initialize() {
+#ifdef DEBUG_ENABLED
+ LiveEditor::singleton = memnew(LiveEditor);
+ ScriptDebuggerRemote::scene_tree_parse_func = SceneDebugger::parse_message;
+#endif
+}
+
+void SceneDebugger::deinitialize() {
+#ifdef DEBUG_ENABLED
+ if (LiveEditor::singleton) {
+ memdelete(LiveEditor::singleton);
+ LiveEditor::singleton = NULL;
+ }
+#endif
+}
+
+#ifdef DEBUG_ENABLED
+Error SceneDebugger::parse_message(const String &p_msg, const Array &p_args) {
+ SceneTree *scene_tree = SceneTree::get_singleton();
+ if (!scene_tree)
+ return ERR_UNCONFIGURED;
+ LiveEditor *live_editor = LiveEditor::get_singleton();
+ if (!live_editor)
+ return ERR_UNCONFIGURED;
+ if (p_msg == "request_scene_tree") { // Scene tree
+ live_editor->_send_tree();
+
+ } else if (p_msg == "save_node") { // Save node.
+ ERR_FAIL_COND_V(p_args.size() < 2, ERR_INVALID_DATA);
+ _save_node(p_args[0], p_args[1]);
+
+ } else if (p_msg == "inspect_object") { // Object Inspect
+ ERR_FAIL_COND_V(p_args.size() < 1, ERR_INVALID_DATA);
+ ObjectID id = p_args[0];
+ _send_object_id(id);
+
+ } else if (p_msg == "override_camera_2D:set") { // Camera
+ ERR_FAIL_COND_V(p_args.size() < 1, ERR_INVALID_DATA);
+ bool enforce = p_args[0];
+ scene_tree->get_root()->enable_canvas_transform_override(enforce);
+
+ } else if (p_msg == "override_camera_2D:transform") {
+ ERR_FAIL_COND_V(p_args.size() < 1, ERR_INVALID_DATA);
+ Transform2D transform = p_args[1];
+ scene_tree->get_root()->set_canvas_transform_override(transform);
+
+ } else if (p_msg == "override_camera_3D:set") {
+ ERR_FAIL_COND_V(p_args.size() < 1, ERR_INVALID_DATA);
+ bool enable = p_args[0];
+ scene_tree->get_root()->enable_camera_override(enable);
+
+ } else if (p_msg == "override_camera_3D:transform") {
+ ERR_FAIL_COND_V(p_args.size() < 5, ERR_INVALID_DATA);
+ Transform transform = p_args[0];
+ bool is_perspective = p_args[1];
+ float size_or_fov = p_args[2];
+ float near = p_args[3];
+ float far = p_args[4];
+ if (is_perspective) {
+ scene_tree->get_root()->set_camera_override_perspective(size_or_fov, near, far);
+ } else {
+ scene_tree->get_root()->set_camera_override_orthogonal(size_or_fov, near, far);
+ }
+ scene_tree->get_root()->set_camera_override_transform(transform);
+
+ } else if (p_msg == "set_object_property") {
+ ERR_FAIL_COND_V(p_args.size() < 3, ERR_INVALID_DATA);
+ _set_object_property(p_args[0], p_args[1], p_args[2]);
+
+ } else if (!p_msg.begins_with("live_")) { // Live edits below.
+ return ERR_SKIP;
+ } else if (p_msg == "live_set_root") {
+ ERR_FAIL_COND_V(p_args.size() < 2, ERR_INVALID_DATA);
+ live_editor->_root_func(p_args[0], p_args[1]);
+
+ } else if (p_msg == "live_node_path") {
+ ERR_FAIL_COND_V(p_args.size() < 2, ERR_INVALID_DATA);
+ live_editor->_node_path_func(p_args[0], p_args[1]);
+
+ } else if (p_msg == "live_res_path") {
+ ERR_FAIL_COND_V(p_args.size() < 2, ERR_INVALID_DATA);
+ live_editor->_res_path_func(p_args[0], p_args[1]);
+
+ } else if (p_msg == "live_node_prop_res") {
+ ERR_FAIL_COND_V(p_args.size() < 3, ERR_INVALID_DATA);
+ live_editor->_node_set_res_func(p_args[0], p_args[1], p_args[2]);
+
+ } else if (p_msg == "live_node_prop") {
+ ERR_FAIL_COND_V(p_args.size() < 3, ERR_INVALID_DATA);
+ live_editor->_node_set_func(p_args[0], p_args[1], p_args[2]);
+
+ } else if (p_msg == "live_res_prop_res") {
+ ERR_FAIL_COND_V(p_args.size() < 3, ERR_INVALID_DATA);
+ live_editor->_res_set_res_func(p_args[0], p_args[1], p_args[2]);
+
+ } else if (p_msg == "live_res_prop") {
+ ERR_FAIL_COND_V(p_args.size() < 3, ERR_INVALID_DATA);
+ live_editor->_res_set_func(p_args[0], p_args[1], p_args[2]);
+
+ } else if (p_msg == "live_node_call") {
+ ERR_FAIL_COND_V(p_args.size() < 7, ERR_INVALID_DATA);
+ live_editor->_node_call_func(p_args[0], p_args[1], p_args[2], p_args[3], p_args[4], p_args[5], p_args[6]);
+
+ } else if (p_msg == "live_res_call") {
+ ERR_FAIL_COND_V(p_args.size() < 7, ERR_INVALID_DATA);
+ live_editor->_res_call_func(p_args[0], p_args[1], p_args[2], p_args[3], p_args[4], p_args[5], p_args[6]);
+
+ } else if (p_msg == "live_create_node") {
+ ERR_FAIL_COND_V(p_args.size() < 3, ERR_INVALID_DATA);
+ live_editor->_create_node_func(p_args[0], p_args[1], p_args[2]);
+
+ } else if (p_msg == "live_instance_node") {
+ ERR_FAIL_COND_V(p_args.size() < 3, ERR_INVALID_DATA);
+ live_editor->_instance_node_func(p_args[0], p_args[1], p_args[2]);
+
+ } else if (p_msg == "live_remove_node") {
+ ERR_FAIL_COND_V(p_args.size() < 1, ERR_INVALID_DATA);
+ live_editor->_remove_node_func(p_args[0]);
+
+ } else if (p_msg == "live_remove_and_keep_node") {
+ ERR_FAIL_COND_V(p_args.size() < 2, ERR_INVALID_DATA);
+ live_editor->_remove_and_keep_node_func(p_args[0], p_args[1]);
+
+ } else if (p_msg == "live_restore_node") {
+ ERR_FAIL_COND_V(p_args.size() < 3, ERR_INVALID_DATA);
+ live_editor->_restore_node_func(p_args[0], p_args[1], p_args[2]);
+
+ } else if (p_msg == "live_duplicate_node") {
+ ERR_FAIL_COND_V(p_args.size() < 2, ERR_INVALID_DATA);
+ live_editor->_duplicate_node_func(p_args[0], p_args[1]);
+
+ } else if (p_msg == "live_reparent_node") {
+ 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;
+ }
+ return OK;
+}
+
+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);
+}
+
+void SceneDebugger::_send_object_id(ObjectID p_id, int p_max_size) {
+ SceneDebuggerObject obj(p_id);
+ if (obj.id.is_null())
+ return;
+
+ Array arr;
+ obj.serialize(arr);
+ ScriptDebugger::get_singleton()->send_message("inspect_object", arr);
+}
+
+void SceneDebugger::_set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value) {
+
+ Object *obj = ObjectDB::get_instance(p_id);
+ if (!obj)
+ return;
+
+ String prop_name = p_property;
+ if (p_property.begins_with("Members/")) {
+ Vector<String> ss = p_property.split("/");
+ prop_name = ss[ss.size() - 1];
+ }
+
+ obj->set(prop_name, p_value);
+}
+
+void SceneDebugger::add_to_cache(const String &p_filename, Node *p_node) {
+ LiveEditor *debugger = LiveEditor::get_singleton();
+ if (!debugger)
+ return;
+
+ if (ScriptDebugger::get_singleton() && p_filename != String()) {
+ debugger->live_scene_edit_cache[p_filename].insert(p_node);
+ }
+}
+void SceneDebugger::remove_from_cache(const String &p_filename, Node *p_node) {
+ LiveEditor *debugger = LiveEditor::get_singleton();
+ if (!debugger)
+ return;
+
+ Map<String, Set<Node *> > &edit_cache = debugger->live_scene_edit_cache;
+ Map<String, Set<Node *> >::Element *E = edit_cache.find(p_filename);
+ if (E) {
+ E->get().erase(p_node);
+ if (E->get().size() == 0) {
+ edit_cache.erase(E);
+ }
+ }
+
+ Map<Node *, Map<ObjectID, Node *> > &remove_list = debugger->live_edit_remove_list;
+ Map<Node *, Map<ObjectID, Node *> >::Element *F = remove_list.find(p_node);
+ if (F) {
+ for (Map<ObjectID, Node *>::Element *G = F->get().front(); G; G = G->next()) {
+
+ memdelete(G->get());
+ }
+ remove_list.erase(F);
+ }
+}
+
+/// SceneDebuggerObject
+SceneDebuggerObject::SceneDebuggerObject(ObjectID p_id) {
+ id = ObjectID();
+ Object *obj = ObjectDB::get_instance(p_id);
+ if (!obj)
+ return;
+
+ id = p_id;
+ class_name = obj->get_class();
+
+ if (ScriptInstance *si = obj->get_script_instance()) {
+ // Read script instance constants and variables
+ if (!si->get_script().is_null()) {
+ Script *s = si->get_script().ptr();
+ _parse_script_properties(s, si);
+ }
+ }
+
+ if (Node *node = Object::cast_to<Node>(obj)) {
+ // Add specialized NodePath info (if inside tree).
+ if (node->is_inside_tree()) {
+ PropertyInfo pi(Variant::NODE_PATH, String("Node/path"));
+ properties.push_back(SceneDebuggerProperty(pi, node->get_path()));
+ } else { // Can't ask for path if a node is not in tree.
+ PropertyInfo pi(Variant::STRING, String("Node/path"));
+ properties.push_back(SceneDebuggerProperty(pi, "[Orphan]"));
+ }
+ } else if (Script *s = Object::cast_to<Script>(obj)) {
+ // Add script constants (no instance).
+ _parse_script_properties(s, NULL);
+ }
+
+ // Add base object properties.
+ List<PropertyInfo> pinfo;
+ obj->get_property_list(&pinfo, true);
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ if (E->get().usage & (PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CATEGORY)) {
+ properties.push_back(SceneDebuggerProperty(E->get(), obj->get(E->get().name)));
+ }
+ }
+}
+
+void SceneDebuggerObject::_parse_script_properties(Script *p_script, ScriptInstance *p_instance) {
+ typedef Map<const Script *, Set<StringName> > ScriptMemberMap;
+ typedef Map<const Script *, Map<StringName, Variant> > ScriptConstantsMap;
+
+ ScriptMemberMap members;
+ if (p_instance) {
+ members[p_script] = Set<StringName>();
+ p_script->get_members(&(members[p_script]));
+ }
+
+ ScriptConstantsMap constants;
+ constants[p_script] = Map<StringName, Variant>();
+ p_script->get_constants(&(constants[p_script]));
+
+ Ref<Script> base = p_script->get_base_script();
+ while (base.is_valid()) {
+ if (p_instance) {
+ members[base.ptr()] = Set<StringName>();
+ base->get_members(&(members[base.ptr()]));
+ }
+
+ constants[base.ptr()] = Map<StringName, Variant>();
+ base->get_constants(&(constants[base.ptr()]));
+
+ base = base->get_base_script();
+ }
+
+ // Members
+ for (ScriptMemberMap::Element *sm = members.front(); sm; sm = sm->next()) {
+ for (Set<StringName>::Element *E = sm->get().front(); E; E = E->next()) {
+ Variant m;
+ if (p_instance->get(E->get(), m)) {
+ String script_path = sm->key() == p_script ? "" : sm->key()->get_path().get_file() + "/";
+ PropertyInfo pi(m.get_type(), "Members/" + script_path + E->get());
+ properties.push_back(SceneDebuggerProperty(pi, m));
+ }
+ }
+ }
+ // Constants
+ for (ScriptConstantsMap::Element *sc = constants.front(); sc; sc = sc->next()) {
+ for (Map<StringName, Variant>::Element *E = sc->get().front(); E; E = E->next()) {
+ String script_path = sc->key() == p_script ? "" : sc->key()->get_path().get_file() + "/";
+ if (E->value().get_type() == Variant::OBJECT) {
+ Variant id = ((Object *)E->value())->get_instance_id();
+ PropertyInfo pi(id.get_type(), "Constants/" + E->key(), PROPERTY_HINT_OBJECT_ID, "Object");
+ properties.push_back(SceneDebuggerProperty(pi, id));
+ } else {
+ PropertyInfo pi(E->value().get_type(), "Constants/" + script_path + E->key());
+ properties.push_back(SceneDebuggerProperty(pi, E->value()));
+ }
+ }
+ }
+}
+
+void SceneDebuggerObject::serialize(Array &r_arr, int p_max_size) {
+ Array send_props;
+ for (int i = 0; i < properties.size(); i++) {
+ const PropertyInfo &pi = properties[i].first;
+ Variant &var = properties[i].second;
+
+ WeakRef *ref = Object::cast_to<WeakRef>(var);
+ if (ref) {
+ var = ref->get_ref();
+ }
+
+ RES res = var;
+
+ Array prop;
+ prop.push_back(pi.name);
+ prop.push_back(pi.type);
+
+ PropertyHint hint = pi.hint;
+ String hint_string = pi.hint_string;
+ if (!res.is_null()) {
+ var = res->get_path();
+ } else { //only send information that can be sent..
+ int len = 0; //test how big is this to encode
+ encode_variant(var, NULL, len);
+ if (len > p_max_size) { //limit to max size
+ hint = PROPERTY_HINT_OBJECT_TOO_BIG;
+ hint_string = "";
+ var = Variant();
+ }
+ }
+ prop.push_back(hint);
+ prop.push_back(hint_string);
+ prop.push_back(pi.usage);
+ prop.push_back(var);
+ send_props.push_back(prop);
+ }
+ r_arr.push_back(uint64_t(id));
+ r_arr.push_back(class_name);
+ r_arr.push_back(send_props);
+}
+
+void SceneDebuggerObject::deserialize(const Array &p_arr) {
+#define CHECK_TYPE(p_what, p_type) ERR_FAIL_COND(p_what.get_type() != Variant::p_type);
+ ERR_FAIL_COND(p_arr.size() < 3);
+ CHECK_TYPE(p_arr[0], INT);
+ CHECK_TYPE(p_arr[1], STRING);
+ CHECK_TYPE(p_arr[2], ARRAY);
+
+ id = uint64_t(p_arr[0]);
+ class_name = p_arr[1];
+ Array props = p_arr[2];
+
+ for (int i = 0; i < props.size(); i++) {
+
+ CHECK_TYPE(props[i], ARRAY);
+ Array prop = props[i];
+
+ ERR_FAIL_COND(prop.size() != 6);
+ CHECK_TYPE(prop[0], STRING);
+ CHECK_TYPE(prop[1], INT);
+ CHECK_TYPE(prop[2], INT);
+ CHECK_TYPE(prop[3], STRING);
+ CHECK_TYPE(prop[4], INT);
+
+ PropertyInfo pinfo;
+ pinfo.name = prop[0];
+ pinfo.type = Variant::Type(int(prop[1]));
+ pinfo.hint = PropertyHint(int(prop[2]));
+ pinfo.hint_string = prop[3];
+ pinfo.usage = PropertyUsageFlags(int(prop[4]));
+ Variant var = prop[5];
+
+ if (pinfo.type == Variant::OBJECT) {
+ if (var.is_zero()) {
+ var = RES();
+ } else if (var.get_type() == Variant::OBJECT) {
+ if (((Object *)var)->is_class("EncodedObjectAsID")) {
+ var = Object::cast_to<EncodedObjectAsID>(var)->get_object_id();
+ pinfo.type = var.get_type();
+ pinfo.hint = PROPERTY_HINT_OBJECT_ID;
+ pinfo.hint_string = "Object";
+ }
+ }
+ }
+ properties.push_back(SceneDebuggerProperty(pinfo, var));
+ }
+}
+
+/// SceneDebuggerTree
+SceneDebuggerTree::SceneDebuggerTree(Node *p_root) {
+ // Flatten tree into list, depth first, use stack to avoid recursion.
+ List<Node *> stack;
+ stack.push_back(p_root);
+ while (stack.size()) {
+ Node *n = stack[0];
+ stack.pop_front();
+ int count = n->get_child_count();
+ nodes.push_back(RemoteNode(count, n->get_name(), n->get_class(), n->get_instance_id()));
+ for (int i = 0; i < count; i++) {
+ stack.push_front(n->get_child(count - i - 1));
+ }
+ }
+}
+
+void SceneDebuggerTree::serialize(Array &p_arr) {
+ for (List<RemoteNode>::Element *E = nodes.front(); E; E = E->next()) {
+ RemoteNode &n = E->get();
+ p_arr.push_back(n.child_count);
+ p_arr.push_back(n.name);
+ p_arr.push_back(n.type_name);
+ p_arr.push_back(n.id);
+ }
+}
+
+void SceneDebuggerTree::deserialize(const Array &p_arr) {
+ int idx = 0;
+ while (p_arr.size() > idx) {
+ ERR_FAIL_COND(p_arr.size() < 4);
+ CHECK_TYPE(p_arr[idx], INT);
+ CHECK_TYPE(p_arr[idx + 1], STRING);
+ CHECK_TYPE(p_arr[idx + 2], STRING);
+ CHECK_TYPE(p_arr[idx + 3], INT);
+ nodes.push_back(RemoteNode(p_arr[idx], p_arr[idx + 1], p_arr[idx + 2], p_arr[idx + 3]));
+ idx += 4;
+ }
+}
+
+/// LiveEditor
+LiveEditor *LiveEditor::singleton = NULL;
+LiveEditor *LiveEditor::get_singleton() {
+ return singleton;
+}
+
+void LiveEditor::_send_tree() {
+ SceneTree *scene_tree = SceneTree::get_singleton();
+ if (!scene_tree)
+ return;
+
+ Array arr;
+ // Encoded as a flat list depth fist.
+ SceneDebuggerTree tree(scene_tree->root);
+ tree.serialize(arr);
+ ScriptDebugger::get_singleton()->send_message("scene_tree", arr);
+}
+
+void LiveEditor::_node_path_func(const NodePath &p_path, int p_id) {
+
+ live_edit_node_path_cache[p_id] = p_path;
+}
+
+void LiveEditor::_res_path_func(const String &p_path, int p_id) {
+
+ live_edit_resource_cache[p_id] = p_path;
+}
+
+void LiveEditor::_node_set_func(int p_id, const StringName &p_prop, const Variant &p_value) {
+
+ SceneTree *scene_tree = SceneTree::get_singleton();
+ if (!scene_tree)
+ return;
+
+ if (!live_edit_node_path_cache.has(p_id))
+ return;
+
+ NodePath np = live_edit_node_path_cache[p_id];
+ Node *base = NULL;
+ if (scene_tree->root->has_node(live_edit_root))
+ base = scene_tree->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 LiveEditor::_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;
+ _node_set_func(p_id, p_prop, r);
+}
+void LiveEditor::_node_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE) {
+ SceneTree *scene_tree = SceneTree::get_singleton();
+ if (!scene_tree)
+ return;
+ if (!live_edit_node_path_cache.has(p_id))
+ return;
+
+ NodePath np = live_edit_node_path_cache[p_id];
+ Node *base = NULL;
+ if (scene_tree->root->has_node(live_edit_root))
+ base = scene_tree->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 LiveEditor::_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 LiveEditor::_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;
+ _res_set_func(p_id, p_prop, r);
+}
+void LiveEditor::_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 LiveEditor::_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 LiveEditor::_create_node_func(const NodePath &p_parent, const String &p_type, const String &p_name) {
+ SceneTree *scene_tree = SceneTree::get_singleton();
+ if (!scene_tree)
+ return;
+
+ Node *base = NULL;
+ if (scene_tree->root->has_node(live_edit_root))
+ base = scene_tree->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 LiveEditor::_instance_node_func(const NodePath &p_parent, const String &p_path, const String &p_name) {
+ SceneTree *scene_tree = SceneTree::get_singleton();
+ if (!scene_tree)
+ return;
+
+ Ref<PackedScene> ps = ResourceLoader::load(p_path);
+
+ if (!ps.is_valid())
+ return;
+
+ Node *base = NULL;
+ if (scene_tree->root->has_node(live_edit_root))
+ base = scene_tree->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 LiveEditor::_remove_node_func(const NodePath &p_at) {
+ SceneTree *scene_tree = SceneTree::get_singleton();
+ if (!scene_tree)
+ return;
+
+ Node *base = NULL;
+ if (scene_tree->root->has_node(live_edit_root))
+ base = scene_tree->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 LiveEditor::_remove_and_keep_node_func(const NodePath &p_at, ObjectID p_keep_id) {
+ SceneTree *scene_tree = SceneTree::get_singleton();
+ if (!scene_tree)
+ return;
+
+ Node *base = NULL;
+ if (scene_tree->root->has_node(live_edit_root))
+ base = scene_tree->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 LiveEditor::_restore_node_func(ObjectID p_id, const NodePath &p_at, int p_at_pos) {
+ SceneTree *scene_tree = SceneTree::get_singleton();
+ if (!scene_tree)
+ return;
+
+ Node *base = NULL;
+ if (scene_tree->root->has_node(live_edit_root))
+ base = scene_tree->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 LiveEditor::_duplicate_node_func(const NodePath &p_at, const String &p_new_name) {
+ SceneTree *scene_tree = SceneTree::get_singleton();
+ if (!scene_tree)
+ return;
+
+ Node *base = NULL;
+ if (scene_tree->root->has_node(live_edit_root))
+ base = scene_tree->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 LiveEditor::_reparent_node_func(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) {
+ SceneTree *scene_tree = SceneTree::get_singleton();
+ if (!scene_tree)
+ return;
+
+ Node *base = NULL;
+ if (scene_tree->root->has_node(live_edit_root))
+ base = scene_tree->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
diff --git a/scene/debugger/scene_debugger.h b/scene/debugger/scene_debugger.h
new file mode 100644
index 0000000000..d22f8e8e18
--- /dev/null
+++ b/scene/debugger/scene_debugger.h
@@ -0,0 +1,151 @@
+/*************************************************************************/
+/* scene_debugger.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef SCENE_DEBUGGER_H
+#define SCENE_DEBUGGER_H
+
+#include "core/array.h"
+#include "core/object.h"
+#include "core/pair.h"
+#include "core/script_language.h"
+#include "core/ustring.h"
+
+class SceneDebugger {
+
+public:
+ static void initialize();
+ static void deinitialize();
+
+#ifdef DEBUG_ENABLED
+private:
+ static void _save_node(ObjectID id, const String &p_path);
+ static void _set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value);
+ 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 void add_to_cache(const String &p_filename, Node *p_node);
+ static void remove_from_cache(const String &p_filename, Node *p_node);
+#endif
+};
+
+#ifdef DEBUG_ENABLED
+class SceneDebuggerObject {
+
+private:
+ void _parse_script_properties(Script *p_script, ScriptInstance *p_instance);
+
+public:
+ typedef Pair<PropertyInfo, Variant> SceneDebuggerProperty;
+ ObjectID id;
+ String class_name;
+ List<SceneDebuggerProperty> properties;
+
+ SceneDebuggerObject(ObjectID p_id);
+ SceneDebuggerObject() {}
+
+ void serialize(Array &r_arr, int p_max_size = 1 << 20);
+ void deserialize(const Array &p_arr);
+};
+
+class SceneDebuggerTree {
+
+public:
+ struct RemoteNode {
+ int child_count;
+ String name;
+ String type_name;
+ ObjectID id;
+
+ RemoteNode(int p_child, const String &p_name, const String &p_type, ObjectID p_id) {
+ child_count = p_child;
+ name = p_name;
+ type_name = p_type;
+ id = p_id;
+ }
+
+ RemoteNode() {}
+ };
+
+ List<RemoteNode> nodes;
+
+ void serialize(Array &r_arr);
+ void deserialize(const Array &p_arr);
+ SceneDebuggerTree(Node *p_root);
+ SceneDebuggerTree(){};
+};
+
+class LiveEditor {
+
+private:
+ friend class SceneDebugger;
+ 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 _send_tree();
+
+ void _node_path_func(const NodePath &p_path, int p_id);
+ void _res_path_func(const String &p_path, int p_id);
+
+ void _node_set_func(int p_id, const StringName &p_prop, const Variant &p_value);
+ void _node_set_res_func(int p_id, const StringName &p_prop, const String &p_value);
+ void _node_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE);
+ void _res_set_func(int p_id, const StringName &p_prop, const Variant &p_value);
+ void _res_set_res_func(int p_id, const StringName &p_prop, const String &p_value);
+ void _res_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE);
+ void _root_func(const NodePath &p_scene_path, const String &p_scene_from);
+
+ void _create_node_func(const NodePath &p_parent, const String &p_type, const String &p_name);
+ void _instance_node_func(const NodePath &p_parent, const String &p_path, const String &p_name);
+ void _remove_node_func(const NodePath &p_at);
+ void _remove_and_keep_node_func(const NodePath &p_at, ObjectID p_keep_id);
+ void _restore_node_func(ObjectID p_id, const NodePath &p_at, int p_at_pos);
+ void _duplicate_node_func(const NodePath &p_at, const String &p_new_name);
+ void _reparent_node_func(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
+
+ LiveEditor() {
+ singleton = this;
+ live_edit_root = NodePath("/root");
+ };
+
+ static LiveEditor *singleton;
+
+public:
+ static LiveEditor *get_singleton();
+};
+#endif
+
+#endif
diff --git a/scene/debugger/script_debugger_remote.cpp b/scene/debugger/script_debugger_remote.cpp
deleted file mode 100644
index 0e61a5746b..0000000000
--- a/scene/debugger/script_debugger_remote.cpp
+++ /dev/null
@@ -1,1313 +0,0 @@
-/*************************************************************************/
-/* script_debugger_remote.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#include "script_debugger_remote.h"
-
-#include "core/engine.h"
-#include "core/io/ip.h"
-#include "core/io/marshalls.h"
-#include "core/os/input.h"
-#include "core/os/os.h"
-#include "core/project_settings.h"
-#include "scene/main/node.h"
-#include "scene/main/scene_tree.h"
-#include "scene/main/viewport.h"
-#include "scene/resources/packed_scene.h"
-#include "servers/visual_server.h"
-
-void ScriptDebuggerRemote::_send_video_memory() {
-
- List<ResourceUsage> usage;
- if (resource_usage_func)
- resource_usage_func(&usage);
-
- usage.sort();
-
- packet_peer_stream->put_var("message:video_mem");
- packet_peer_stream->put_var(usage.size() * 4);
-
- for (List<ResourceUsage>::Element *E = usage.front(); E; E = E->next()) {
-
- packet_peer_stream->put_var(E->get().path);
- packet_peer_stream->put_var(E->get().type);
- packet_peer_stream->put_var(E->get().format);
- packet_peer_stream->put_var(E->get().vram);
- }
-}
-
-Error ScriptDebuggerRemote::connect_to_host(const String &p_host, uint16_t p_port) {
-
- IP_Address ip;
- if (p_host.is_valid_ip_address())
- ip = p_host;
- else
- ip = IP::get_singleton()->resolve_hostname(p_host);
-
- int port = p_port;
-
- const int tries = 6;
- int waits[tries] = { 1, 10, 100, 1000, 1000, 1000 };
-
- tcp_client->connect_to_host(ip, port);
-
- for (int i = 0; i < tries; i++) {
-
- if (tcp_client->get_status() == StreamPeerTCP::STATUS_CONNECTED) {
- print_verbose("Remote Debugger: Connected!");
- break;
- } else {
-
- const int ms = waits[i];
- OS::get_singleton()->delay_usec(ms * 1000);
- print_verbose("Remote Debugger: Connection failed with status: '" + String::num(tcp_client->get_status()) + "', retrying in " + String::num(ms) + " msec.");
- };
- };
-
- if (tcp_client->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
-
- ERR_PRINT("Remote Debugger: Unable to connect. Status: " + String::num(tcp_client->get_status()) + ".");
- return FAILED;
- };
-
- packet_peer_stream->set_stream_peer(tcp_client);
-
- return OK;
-}
-
-void ScriptDebuggerRemote::_put_variable(const String &p_name, const Variant &p_variable) {
-
- packet_peer_stream->put_var(p_name);
-
- Variant var = p_variable;
- if (p_variable.get_type() == Variant::OBJECT && p_variable.get_validated_object() == nullptr) {
- var = Variant();
- }
-
- int len = 0;
- Error err = encode_variant(var, NULL, len, true);
- if (err != OK)
- ERR_PRINT("Failed to encode variant.");
-
- if (len > packet_peer_stream->get_output_buffer_max_size()) { //limit to max size
- packet_peer_stream->put_var(Variant());
- } else {
- packet_peer_stream->put_var(var);
- }
-}
-
-void ScriptDebuggerRemote::_save_node(ObjectID id, const String &p_path) {
-
- Node *node = Object::cast_to<Node>(ObjectDB::get_instance(id));
- ERR_FAIL_COND(!node);
-
- Ref<PackedScene> ps = memnew(PackedScene);
- ps->pack(node);
- ResourceSaver::save(p_path, ps);
-}
-
-void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue, bool p_is_error_breakpoint) {
-
- //this function is called when there is a debugger break (bug on script)
- //or when execution is paused from editor
-
- if (skip_breakpoints && !p_is_error_breakpoint)
- return;
-
- ERR_FAIL_COND_MSG(!tcp_client->is_connected_to_host(), "Script Debugger failed to connect, but being used anyway.");
-
- packet_peer_stream->put_var("debug_enter");
- packet_peer_stream->put_var(2);
- packet_peer_stream->put_var(p_can_continue);
- packet_peer_stream->put_var(p_script->debug_get_error());
-
- skip_profile_frame = true; // to avoid super long frame time for the frame
-
- Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode();
- if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
- Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
-
- uint64_t loop_begin_usec = 0;
- uint64_t loop_time_sec = 0;
- while (true) {
- loop_begin_usec = OS::get_singleton()->get_ticks_usec();
-
- _get_output();
-
- if (packet_peer_stream->get_available_packet_count() > 0) {
-
- Variant var;
- Error err = packet_peer_stream->get_var(var);
-
- ERR_CONTINUE(err != OK);
- ERR_CONTINUE(var.get_type() != Variant::ARRAY);
-
- Array cmd = var;
-
- ERR_CONTINUE(cmd.size() == 0);
- ERR_CONTINUE(cmd[0].get_type() != Variant::STRING);
-
- String command = cmd[0];
-
- if (command == "get_stack_dump") {
-
- packet_peer_stream->put_var("stack_dump");
- int slc = p_script->debug_get_stack_level_count();
- packet_peer_stream->put_var(slc);
-
- for (int i = 0; i < slc; i++) {
-
- Dictionary d;
- d["file"] = p_script->debug_get_stack_level_source(i);
- d["line"] = p_script->debug_get_stack_level_line(i);
- d["function"] = p_script->debug_get_stack_level_function(i);
- //d["id"]=p_script->debug_get_stack_level_
- d["id"] = 0;
-
- packet_peer_stream->put_var(d);
- }
-
- } else if (command == "get_stack_frame_vars") {
-
- cmd.remove(0);
- ERR_CONTINUE(cmd.size() != 1);
- int lv = cmd[0];
-
- List<String> members;
- List<Variant> member_vals;
- if (ScriptInstance *inst = p_script->debug_get_stack_level_instance(lv)) {
- members.push_back("self");
- member_vals.push_back(inst->get_owner());
- }
- p_script->debug_get_stack_level_members(lv, &members, &member_vals);
- ERR_CONTINUE(members.size() != member_vals.size());
-
- List<String> locals;
- List<Variant> local_vals;
- p_script->debug_get_stack_level_locals(lv, &locals, &local_vals);
- ERR_CONTINUE(locals.size() != local_vals.size());
-
- List<String> globals;
- List<Variant> globals_vals;
- p_script->debug_get_globals(&globals, &globals_vals);
- ERR_CONTINUE(globals.size() != globals_vals.size());
-
- packet_peer_stream->put_var("stack_frame_vars");
- packet_peer_stream->put_var(3 + (locals.size() + members.size() + globals.size()) * 2);
-
- { //locals
- packet_peer_stream->put_var(locals.size());
-
- List<String>::Element *E = locals.front();
- List<Variant>::Element *F = local_vals.front();
-
- while (E) {
- _put_variable(E->get(), F->get());
-
- E = E->next();
- F = F->next();
- }
- }
-
- { //members
- packet_peer_stream->put_var(members.size());
-
- List<String>::Element *E = members.front();
- List<Variant>::Element *F = member_vals.front();
-
- while (E) {
-
- _put_variable(E->get(), F->get());
-
- E = E->next();
- F = F->next();
- }
- }
-
- { //globals
- packet_peer_stream->put_var(globals.size());
-
- List<String>::Element *E = globals.front();
- List<Variant>::Element *F = globals_vals.front();
-
- while (E) {
- _put_variable(E->get(), F->get());
-
- E = E->next();
- F = F->next();
- }
- }
-
- } else if (command == "step") {
-
- set_depth(-1);
- set_lines_left(1);
- break;
- } else if (command == "next") {
-
- set_depth(0);
- set_lines_left(1);
- break;
-
- } else if (command == "continue") {
- set_depth(-1);
- set_lines_left(-1);
- OS::get_singleton()->move_window_to_foreground();
- break;
- } else if (command == "break") {
- ERR_PRINT("Got break when already broke!");
- break;
- } else if (command == "request_scene_tree") {
-
-#ifdef DEBUG_ENABLED
- if (scene_tree)
- scene_tree->_debugger_request_tree();
-#endif
- } else if (command == "request_video_mem") {
-
- _send_video_memory();
- } else if (command == "inspect_object") {
-
- ObjectID id = cmd[1];
- _send_object_id(id);
- } else if (command == "set_object_property") {
-
- _set_object_property(cmd[1], cmd[2], cmd[3]);
-
- } else if (command == "override_camera_2D:set") {
- bool enforce = cmd[1];
-
- if (scene_tree) {
- scene_tree->get_root()->enable_canvas_transform_override(enforce);
- }
- } else if (command == "override_camera_2D:transform") {
- Transform2D transform = cmd[1];
-
- if (scene_tree) {
- scene_tree->get_root()->set_canvas_transform_override(transform);
- }
- } else if (command == "override_camera_3D:set") {
- bool enable = cmd[1];
-
- if (scene_tree) {
- scene_tree->get_root()->enable_camera_override(enable);
- }
- } else if (command == "override_camera_3D:transform") {
- Transform transform = cmd[1];
- bool is_perspective = cmd[2];
- float size_or_fov = cmd[3];
- float near = cmd[4];
- float far = cmd[5];
-
- if (scene_tree) {
- if (is_perspective) {
- scene_tree->get_root()->set_camera_override_perspective(size_or_fov, near, far);
- } else {
- scene_tree->get_root()->set_camera_override_orthogonal(size_or_fov, near, far);
- }
- scene_tree->get_root()->set_camera_override_transform(transform);
- }
-
- } else if (command == "reload_scripts") {
- reload_all_scripts = true;
- } else if (command == "breakpoint") {
-
- bool set = cmd[3];
- if (set)
- insert_breakpoint(cmd[2], cmd[1]);
- else
- remove_breakpoint(cmd[2], cmd[1]);
-
- } else if (command == "save_node") {
- _save_node(cmd[1], cmd[2]);
- } else if (command == "set_skip_breakpoints") {
- skip_breakpoints = cmd[1];
- } else {
- _parse_live_edit(cmd);
- }
-
- } else {
- OS::get_singleton()->delay_usec(10000);
- OS::get_singleton()->process_and_drop_events();
- }
-
- // This is for the camera override to stay live even when the game is paused from the editor
- loop_time_sec = (OS::get_singleton()->get_ticks_usec() - loop_begin_usec) / 1000000.0f;
- VisualServer::get_singleton()->sync();
- if (VisualServer::get_singleton()->has_changed()) {
- VisualServer::get_singleton()->draw(true, loop_time_sec * Engine::get_singleton()->get_time_scale());
- }
- }
-
- packet_peer_stream->put_var("debug_exit");
- packet_peer_stream->put_var(0);
-
- if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
- Input::get_singleton()->set_mouse_mode(mouse_mode);
-}
-
-void ScriptDebuggerRemote::_get_output() {
-
- mutex->lock();
- if (output_strings.size()) {
-
- locking = true;
- packet_peer_stream->put_var("output");
- packet_peer_stream->put_var(output_strings.size());
-
- while (output_strings.size()) {
-
- packet_peer_stream->put_var(output_strings.front()->get());
- output_strings.pop_front();
- }
- locking = false;
- }
-
- if (n_messages_dropped > 0) {
- Message msg;
- msg.message = "Too many messages! " + String::num_int64(n_messages_dropped) + " messages were dropped.";
- messages.push_back(msg);
- n_messages_dropped = 0;
- }
-
- while (messages.size()) {
- locking = true;
- packet_peer_stream->put_var("message:" + messages.front()->get().message);
- packet_peer_stream->put_var(messages.front()->get().data.size());
- for (int i = 0; i < messages.front()->get().data.size(); i++) {
- packet_peer_stream->put_var(messages.front()->get().data[i]);
- }
- messages.pop_front();
- locking = false;
- }
-
- if (n_errors_dropped == 1) {
- // Only print one message about dropping per second
- OutputError oe;
- oe.error = "TOO_MANY_ERRORS";
- oe.error_descr = "Too many errors! Ignoring errors for up to 1 second.";
- oe.warning = false;
- uint64_t time = OS::get_singleton()->get_ticks_msec();
- oe.hr = time / 3600000;
- oe.min = (time / 60000) % 60;
- oe.sec = (time / 1000) % 60;
- oe.msec = time % 1000;
- errors.push_back(oe);
- }
-
- if (n_warnings_dropped == 1) {
- // Only print one message about dropping per second
- OutputError oe;
- oe.error = "TOO_MANY_WARNINGS";
- oe.error_descr = "Too many warnings! Ignoring warnings for up to 1 second.";
- oe.warning = true;
- uint64_t time = OS::get_singleton()->get_ticks_msec();
- oe.hr = time / 3600000;
- oe.min = (time / 60000) % 60;
- oe.sec = (time / 1000) % 60;
- oe.msec = time % 1000;
- errors.push_back(oe);
- }
-
- while (errors.size()) {
- locking = true;
- packet_peer_stream->put_var("error");
- OutputError oe = errors.front()->get();
-
- packet_peer_stream->put_var(oe.callstack.size() + 2);
-
- Array error_data;
-
- error_data.push_back(oe.hr);
- error_data.push_back(oe.min);
- error_data.push_back(oe.sec);
- error_data.push_back(oe.msec);
- error_data.push_back(oe.source_func);
- error_data.push_back(oe.source_file);
- error_data.push_back(oe.source_line);
- error_data.push_back(oe.error);
- error_data.push_back(oe.error_descr);
- error_data.push_back(oe.warning);
- packet_peer_stream->put_var(error_data);
- packet_peer_stream->put_var(oe.callstack.size());
- for (int i = 0; i < oe.callstack.size(); i++) {
- packet_peer_stream->put_var(oe.callstack[i]);
- }
-
- errors.pop_front();
- locking = false;
- }
- mutex->unlock();
-}
-
-void ScriptDebuggerRemote::line_poll() {
-
- //the purpose of this is just processing events every now and then when the script might get too busy
- //otherwise bugs like infinite loops can't be caught
- if (poll_every % 2048 == 0)
- _poll_events();
- poll_every++;
-}
-
-void ScriptDebuggerRemote::_err_handler(void *ud, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, ErrorHandlerType p_type) {
-
- if (p_type == ERR_HANDLER_SCRIPT)
- return; //ignore script errors, those go through debugger
-
- Vector<ScriptLanguage::StackInfo> si;
-
- for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- si = ScriptServer::get_language(i)->debug_get_current_stack_info();
- if (si.size())
- break;
- }
-
- ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)ud;
- sdr->send_error(p_func, p_file, p_line, p_err, p_descr, p_type, si);
-}
-
-bool ScriptDebuggerRemote::_parse_live_edit(const Array &p_command) {
-
-#ifdef DEBUG_ENABLED
-
- String cmdstr = p_command[0];
- if (!scene_tree || !cmdstr.begins_with("live_"))
- return false;
-
- if (cmdstr == "live_set_root") {
-
- scene_tree->_live_edit_root_func(p_command[1], p_command[2]);
-
- } else if (cmdstr == "live_node_path") {
-
- scene_tree->_live_edit_node_path_func(p_command[1], p_command[2]);
-
- } else if (cmdstr == "live_res_path") {
-
- scene_tree->_live_edit_res_path_func(p_command[1], p_command[2]);
-
- } else if (cmdstr == "live_node_prop_res") {
-
- scene_tree->_live_edit_node_set_res_func(p_command[1], p_command[2], p_command[3]);
-
- } else if (cmdstr == "live_node_prop") {
-
- scene_tree->_live_edit_node_set_func(p_command[1], p_command[2], p_command[3]);
-
- } else if (cmdstr == "live_res_prop_res") {
-
- scene_tree->_live_edit_res_set_res_func(p_command[1], p_command[2], p_command[3]);
-
- } else if (cmdstr == "live_res_prop") {
-
- scene_tree->_live_edit_res_set_func(p_command[1], p_command[2], p_command[3]);
-
- } else if (cmdstr == "live_node_call") {
-
- scene_tree->_live_edit_node_call_func(p_command[1], p_command[2], p_command[3], p_command[4], p_command[5], p_command[6], p_command[7]);
-
- } else if (cmdstr == "live_res_call") {
-
- scene_tree->_live_edit_res_call_func(p_command[1], p_command[2], p_command[3], p_command[4], p_command[5], p_command[6], p_command[7]);
-
- } else if (cmdstr == "live_create_node") {
-
- scene_tree->_live_edit_create_node_func(p_command[1], p_command[2], p_command[3]);
-
- } else if (cmdstr == "live_instance_node") {
-
- scene_tree->_live_edit_instance_node_func(p_command[1], p_command[2], p_command[3]);
-
- } else if (cmdstr == "live_remove_node") {
-
- scene_tree->_live_edit_remove_node_func(p_command[1]);
-
- } else if (cmdstr == "live_remove_and_keep_node") {
-
- scene_tree->_live_edit_remove_and_keep_node_func(p_command[1], p_command[2]);
-
- } else if (cmdstr == "live_restore_node") {
-
- scene_tree->_live_edit_restore_node_func(p_command[1], p_command[2], p_command[3]);
-
- } else if (cmdstr == "live_duplicate_node") {
-
- scene_tree->_live_edit_duplicate_node_func(p_command[1], p_command[2]);
-
- } else if (cmdstr == "live_reparent_node") {
-
- scene_tree->_live_edit_reparent_node_func(p_command[1], p_command[2], p_command[3], p_command[4]);
-
- } else {
-
- return false;
- }
-
- return true;
-#else
-
- return false;
-#endif
-}
-
-void ScriptDebuggerRemote::_send_object_id(ObjectID p_id) {
-
- Object *obj = ObjectDB::get_instance(p_id);
- if (!obj)
- return;
-
- typedef Pair<PropertyInfo, Variant> PropertyDesc;
- List<PropertyDesc> properties;
-
- if (ScriptInstance *si = obj->get_script_instance()) {
- if (!si->get_script().is_null()) {
-
- typedef Map<const Script *, Set<StringName> > ScriptMemberMap;
- typedef Map<const Script *, Map<StringName, Variant> > ScriptConstantsMap;
-
- ScriptMemberMap members;
- members[si->get_script().ptr()] = Set<StringName>();
- si->get_script()->get_members(&(members[si->get_script().ptr()]));
-
- ScriptConstantsMap constants;
- constants[si->get_script().ptr()] = Map<StringName, Variant>();
- si->get_script()->get_constants(&(constants[si->get_script().ptr()]));
-
- Ref<Script> base = si->get_script()->get_base_script();
- while (base.is_valid()) {
-
- members[base.ptr()] = Set<StringName>();
- base->get_members(&(members[base.ptr()]));
-
- constants[base.ptr()] = Map<StringName, Variant>();
- base->get_constants(&(constants[base.ptr()]));
-
- base = base->get_base_script();
- }
-
- for (ScriptMemberMap::Element *sm = members.front(); sm; sm = sm->next()) {
- for (Set<StringName>::Element *E = sm->get().front(); E; E = E->next()) {
- Variant m;
- if (si->get(E->get(), m)) {
- String script_path = sm->key() == si->get_script().ptr() ? "" : sm->key()->get_path().get_file() + "/";
- PropertyInfo pi(m.get_type(), "Members/" + script_path + E->get());
- properties.push_back(PropertyDesc(pi, m));
- }
- }
- }
-
- for (ScriptConstantsMap::Element *sc = constants.front(); sc; sc = sc->next()) {
- for (Map<StringName, Variant>::Element *E = sc->get().front(); E; E = E->next()) {
- String script_path = sc->key() == si->get_script().ptr() ? "" : sc->key()->get_path().get_file() + "/";
- if (E->value().get_type() == Variant::OBJECT) {
- Variant id = ((Object *)E->value())->get_instance_id();
- PropertyInfo pi(id.get_type(), "Constants/" + E->key(), PROPERTY_HINT_OBJECT_ID, "Object");
- properties.push_back(PropertyDesc(pi, id));
- } else {
- PropertyInfo pi(E->value().get_type(), "Constants/" + script_path + E->key());
- properties.push_back(PropertyDesc(pi, E->value()));
- }
- }
- }
- }
- }
-
- if (Node *node = Object::cast_to<Node>(obj)) {
- // in some cases node will not be in tree here
- // for instance where it created as variable and not yet added to tree
- // in such cases we can't ask for it's path
- if (node->is_inside_tree()) {
- PropertyInfo pi(Variant::NODE_PATH, String("Node/path"));
- properties.push_front(PropertyDesc(pi, node->get_path()));
- } else {
- PropertyInfo pi(Variant::STRING, String("Node/path"));
- properties.push_front(PropertyDesc(pi, "[Orphan]"));
- }
-
- } else if (Resource *res = Object::cast_to<Resource>(obj)) {
- if (Script *s = Object::cast_to<Script>(res)) {
- Map<StringName, Variant> constants;
- s->get_constants(&constants);
- for (Map<StringName, Variant>::Element *E = constants.front(); E; E = E->next()) {
- if (E->value().get_type() == Variant::OBJECT) {
- Variant id = ((Object *)E->value())->get_instance_id();
- PropertyInfo pi(id.get_type(), "Constants/" + E->key(), PROPERTY_HINT_OBJECT_ID, "Object");
- properties.push_front(PropertyDesc(pi, E->value()));
- } else {
- PropertyInfo pi(E->value().get_type(), String("Constants/") + E->key());
- properties.push_front(PropertyDesc(pi, E->value()));
- }
- }
- }
- }
-
- List<PropertyInfo> pinfo;
- obj->get_property_list(&pinfo, true);
- for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (E->get().usage & (PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CATEGORY)) {
- properties.push_back(PropertyDesc(E->get(), obj->get(E->get().name)));
- }
- }
-
- Array send_props;
- for (int i = 0; i < properties.size(); i++) {
- const PropertyInfo &pi = properties[i].first;
- Variant &var = properties[i].second;
-
- WeakRef *ref = Object::cast_to<WeakRef>(var);
- if (ref) {
- var = ref->get_ref();
- }
-
- RES res = var;
-
- Array prop;
- prop.push_back(pi.name);
- prop.push_back(pi.type);
-
- //only send information that can be sent..
- int len = 0; //test how big is this to encode
- encode_variant(var, NULL, len);
- if (len > packet_peer_stream->get_output_buffer_max_size()) { //limit to max size
- prop.push_back(PROPERTY_HINT_OBJECT_TOO_BIG);
- prop.push_back("");
- prop.push_back(pi.usage);
- prop.push_back(Variant());
- } else {
- prop.push_back(pi.hint);
- prop.push_back(pi.hint_string);
- prop.push_back(pi.usage);
-
- if (!res.is_null()) {
- var = res->get_path();
- }
-
- prop.push_back(var);
- }
- send_props.push_back(prop);
- }
-
- packet_peer_stream->put_var("message:inspect_object");
- packet_peer_stream->put_var(3);
- packet_peer_stream->put_var(p_id);
- packet_peer_stream->put_var(obj->get_class());
- packet_peer_stream->put_var(send_props);
-}
-
-void ScriptDebuggerRemote::_set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value) {
-
- Object *obj = ObjectDB::get_instance(p_id);
- if (!obj)
- return;
-
- String prop_name = p_property;
- if (p_property.begins_with("Members/")) {
- Vector<String> ss = p_property.split("/");
- prop_name = ss[ss.size() - 1];
- }
-
- obj->set(prop_name, p_value);
-}
-
-void ScriptDebuggerRemote::_poll_events() {
-
- //this si called from ::idle_poll, happens only when running the game,
- //does not get called while on debug break
-
- while (packet_peer_stream->get_available_packet_count() > 0) {
-
- _get_output();
-
- //send over output_strings
-
- Variant var;
- Error err = packet_peer_stream->get_var(var);
-
- ERR_CONTINUE(err != OK);
- ERR_CONTINUE(var.get_type() != Variant::ARRAY);
-
- Array cmd = var;
-
- ERR_CONTINUE(cmd.size() == 0);
- ERR_CONTINUE(cmd[0].get_type() != Variant::STRING);
-
- String command = cmd[0];
- //cmd.remove(0);
-
- if (command == "break") {
-
- if (get_break_language())
- debug(get_break_language());
- } else if (command == "request_scene_tree") {
-
-#ifdef DEBUG_ENABLED
- if (scene_tree)
- scene_tree->_debugger_request_tree();
-#endif
- } else if (command == "request_video_mem") {
-
- _send_video_memory();
- } else if (command == "inspect_object") {
-
- ObjectID id = cmd[1];
- _send_object_id(id);
- } else if (command == "set_object_property") {
-
- _set_object_property(cmd[1], cmd[2], cmd[3]);
-
- } else if (command == "start_profiling") {
-
- for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- ScriptServer::get_language(i)->profiling_start();
- }
-
- max_frame_functions = cmd[1];
- profiler_function_signature_map.clear();
- profiling = true;
- frame_time = 0;
- idle_time = 0;
- physics_time = 0;
- physics_frame_time = 0;
-
- print_line("PROFILING ALRIGHT!");
-
- } else if (command == "stop_profiling") {
-
- for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- ScriptServer::get_language(i)->profiling_stop();
- }
- profiling = false;
- _send_profiling_data(false);
- print_line("PROFILING END!");
- } else if (command == "start_visual_profiling") {
-
- visual_profiling = true;
- VS::get_singleton()->set_frame_profiling_enabled(true);
- } else if (command == "stop_visual_profiling") {
-
- visual_profiling = false;
- VS::get_singleton()->set_frame_profiling_enabled(false);
- } else if (command == "start_network_profiling") {
-
- network_profiling = true;
- multiplayer->profiling_start();
- } else if (command == "stop_network_profiling") {
-
- network_profiling = false;
- multiplayer->profiling_end();
- } else if (command == "override_camera_2D:set") {
- bool enforce = cmd[1];
-
- if (scene_tree) {
- scene_tree->get_root()->enable_canvas_transform_override(enforce);
- }
- } else if (command == "override_camera_2D:transform") {
- Transform2D transform = cmd[1];
-
- if (scene_tree) {
- scene_tree->get_root()->set_canvas_transform_override(transform);
- }
- } else if (command == "override_camera_3D:set") {
- bool enable = cmd[1];
-
- if (scene_tree) {
- scene_tree->get_root()->enable_camera_override(enable);
- }
- } else if (command == "override_camera_3D:transform") {
- Transform transform = cmd[1];
- bool is_perspective = cmd[2];
- float size_or_fov = cmd[3];
- float near = cmd[4];
- float far = cmd[5];
-
- if (scene_tree) {
- if (is_perspective) {
- scene_tree->get_root()->set_camera_override_perspective(size_or_fov, near, far);
- } else {
- scene_tree->get_root()->set_camera_override_orthogonal(size_or_fov, near, far);
- }
- scene_tree->get_root()->set_camera_override_transform(transform);
- }
-
- } else if (command == "reload_scripts") {
- reload_all_scripts = true;
- } else if (command == "breakpoint") {
-
- bool set = cmd[3];
- if (set)
- insert_breakpoint(cmd[2], cmd[1]);
- else
- remove_breakpoint(cmd[2], cmd[1]);
- } else if (command == "set_skip_breakpoints") {
- skip_breakpoints = cmd[1];
- } else {
- _parse_live_edit(cmd);
- }
- }
-}
-
-void ScriptDebuggerRemote::_send_profiling_data(bool p_for_frame) {
-
- int ofs = 0;
-
- for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- if (p_for_frame)
- ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&profile_info.write[ofs], profile_info.size() - ofs);
- else
- ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&profile_info.write[ofs], profile_info.size() - ofs);
- }
-
- for (int i = 0; i < ofs; i++) {
- profile_info_ptrs.write[i] = &profile_info.write[i];
- }
-
- SortArray<ScriptLanguage::ProfilingInfo *, ProfileInfoSort> sa;
- sa.sort(profile_info_ptrs.ptrw(), ofs);
-
- int to_send = MIN(ofs, max_frame_functions);
-
- //check signatures first
- uint64_t total_script_time = 0;
-
- for (int i = 0; i < to_send; i++) {
-
- if (!profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) {
-
- int idx = profiler_function_signature_map.size();
- packet_peer_stream->put_var("profile_sig");
- packet_peer_stream->put_var(2);
- packet_peer_stream->put_var(profile_info_ptrs[i]->signature);
- packet_peer_stream->put_var(idx);
-
- profiler_function_signature_map[profile_info_ptrs[i]->signature] = idx;
- }
-
- total_script_time += profile_info_ptrs[i]->self_time;
- }
-
- //send frames then
-
- if (p_for_frame) {
- packet_peer_stream->put_var("profile_frame");
- packet_peer_stream->put_var(8 + profile_frame_data.size() * 2 + to_send * 4);
- } else {
- packet_peer_stream->put_var("profile_total");
- packet_peer_stream->put_var(8 + to_send * 4);
- }
-
- packet_peer_stream->put_var(Engine::get_singleton()->get_frames_drawn()); //total frame time
- packet_peer_stream->put_var(frame_time); //total frame time
- packet_peer_stream->put_var(idle_time); //idle frame time
- packet_peer_stream->put_var(physics_time); //fixed frame time
- packet_peer_stream->put_var(physics_frame_time); //fixed frame time
-
- packet_peer_stream->put_var(USEC_TO_SEC(total_script_time)); //total script execution time
-
- if (p_for_frame) {
-
- packet_peer_stream->put_var(profile_frame_data.size()); //how many profile framedatas to send
- packet_peer_stream->put_var(to_send); //how many script functions to send
- for (int i = 0; i < profile_frame_data.size(); i++) {
-
- packet_peer_stream->put_var(profile_frame_data[i].name);
- packet_peer_stream->put_var(profile_frame_data[i].data);
- }
- } else {
- packet_peer_stream->put_var(0); //how many script functions to send
- packet_peer_stream->put_var(to_send); //how many script functions to send
- }
-
- for (int i = 0; i < to_send; i++) {
-
- int sig_id = -1;
-
- if (profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) {
- sig_id = profiler_function_signature_map[profile_info_ptrs[i]->signature];
- }
-
- packet_peer_stream->put_var(sig_id);
- packet_peer_stream->put_var(profile_info_ptrs[i]->call_count);
- packet_peer_stream->put_var(profile_info_ptrs[i]->total_time / 1000000.0);
- packet_peer_stream->put_var(profile_info_ptrs[i]->self_time / 1000000.0);
- }
-
- if (p_for_frame) {
- profile_frame_data.clear();
- }
-}
-
-void ScriptDebuggerRemote::idle_poll() {
-
- // this function is called every frame, except when there is a debugger break (::debug() in this class)
- // execution stops and remains in the ::debug function
-
- _get_output();
-
- if (requested_quit) {
-
- packet_peer_stream->put_var("kill_me");
- packet_peer_stream->put_var(0);
- requested_quit = false;
- }
-
- if (performance) {
-
- uint64_t pt = OS::get_singleton()->get_ticks_msec();
- if (pt - last_perf_time > 1000) {
-
- last_perf_time = pt;
- int max = performance->get("MONITOR_MAX");
- Array arr;
- arr.resize(max);
- for (int i = 0; i < max; i++) {
- arr[i] = performance->call("get_monitor", i);
- }
- packet_peer_stream->put_var("performance");
- packet_peer_stream->put_var(1);
- packet_peer_stream->put_var(arr);
- }
- }
- if (visual_profiling) {
- Vector<VS::FrameProfileArea> profile_areas = VS::get_singleton()->get_frame_profile();
- if (profile_areas.size()) {
- Vector<String> area_names;
- Vector<real_t> area_times;
- area_names.resize(profile_areas.size());
- area_times.resize(profile_areas.size() * 2);
- {
- String *area_namesw = area_names.ptrw();
- real_t *area_timesw = area_times.ptrw();
-
- for (int i = 0; i < profile_areas.size(); i++) {
- area_namesw[i] = profile_areas[i].name;
- area_timesw[i * 2 + 0] = profile_areas[i].cpu_msec;
- area_timesw[i * 2 + 1] = profile_areas[i].gpu_msec;
- }
- }
- packet_peer_stream->put_var("visual_profile");
- packet_peer_stream->put_var(3);
- packet_peer_stream->put_var(VS::get_singleton()->get_frame_profile_frame());
- packet_peer_stream->put_var(area_names);
- packet_peer_stream->put_var(area_times);
- }
- }
-
- if (profiling) {
-
- if (skip_profile_frame) {
- skip_profile_frame = false;
- } else {
- //send profiling info normally
- _send_profiling_data(true);
- }
- }
-
- if (network_profiling) {
- uint64_t pt = OS::get_singleton()->get_ticks_msec();
- if (pt - last_net_bandwidth_time > 200) {
- last_net_bandwidth_time = pt;
- _send_network_bandwidth_usage();
- }
- if (pt - last_net_prof_time > 100) {
- last_net_prof_time = pt;
- _send_network_profiling_data();
- }
- }
-
- if (reload_all_scripts) {
-
- for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- ScriptServer::get_language(i)->reload_all_scripts();
- }
- reload_all_scripts = false;
- }
-
- _poll_events();
-}
-
-void ScriptDebuggerRemote::_send_network_profiling_data() {
- ERR_FAIL_COND(multiplayer.is_null());
-
- int n_nodes = multiplayer->get_profiling_frame(&network_profile_info.write[0]);
-
- packet_peer_stream->put_var("network_profile");
- packet_peer_stream->put_var(n_nodes * 6);
- for (int i = 0; i < n_nodes; ++i) {
- packet_peer_stream->put_var(network_profile_info[i].node);
- packet_peer_stream->put_var(network_profile_info[i].node_path);
- packet_peer_stream->put_var(network_profile_info[i].incoming_rpc);
- packet_peer_stream->put_var(network_profile_info[i].incoming_rset);
- packet_peer_stream->put_var(network_profile_info[i].outgoing_rpc);
- packet_peer_stream->put_var(network_profile_info[i].outgoing_rset);
- }
-}
-
-void ScriptDebuggerRemote::_send_network_bandwidth_usage() {
- ERR_FAIL_COND(multiplayer.is_null());
-
- int incoming_bandwidth = multiplayer->get_incoming_bandwidth_usage();
- int outgoing_bandwidth = multiplayer->get_outgoing_bandwidth_usage();
-
- packet_peer_stream->put_var("network_bandwidth");
- packet_peer_stream->put_var(2);
- packet_peer_stream->put_var(incoming_bandwidth);
- packet_peer_stream->put_var(outgoing_bandwidth);
-}
-
-void ScriptDebuggerRemote::send_message(const String &p_message, const Array &p_args) {
-
- mutex->lock();
- if (!locking && tcp_client->is_connected_to_host()) {
-
- if (messages.size() >= max_messages_per_frame) {
- n_messages_dropped++;
- } else {
- Message msg;
- msg.message = p_message;
- msg.data = p_args;
- messages.push_back(msg);
- }
- }
- mutex->unlock();
-}
-
-void ScriptDebuggerRemote::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info) {
-
- OutputError oe;
- oe.error = p_err;
- oe.error_descr = p_descr;
- oe.source_file = p_file;
- oe.source_line = p_line;
- oe.source_func = p_func;
- oe.warning = p_type == ERR_HANDLER_WARNING;
- uint64_t time = OS::get_singleton()->get_ticks_msec();
- oe.hr = time / 3600000;
- oe.min = (time / 60000) % 60;
- oe.sec = (time / 1000) % 60;
- oe.msec = time % 1000;
- Array cstack;
-
- uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000;
- msec_count += ticks - last_msec;
- last_msec = ticks;
-
- if (msec_count > 1000) {
- msec_count = 0;
-
- err_count = 0;
- n_errors_dropped = 0;
- warn_count = 0;
- n_warnings_dropped = 0;
- }
-
- cstack.resize(p_stack_info.size() * 3);
- for (int i = 0; i < p_stack_info.size(); i++) {
- cstack[i * 3 + 0] = p_stack_info[i].file;
- cstack[i * 3 + 1] = p_stack_info[i].func;
- cstack[i * 3 + 2] = p_stack_info[i].line;
- }
-
- oe.callstack = cstack;
- if (oe.warning) {
- warn_count++;
- } else {
- err_count++;
- }
-
- mutex->lock();
-
- if (!locking && tcp_client->is_connected_to_host()) {
-
- if (oe.warning) {
- if (warn_count > max_warnings_per_second) {
- n_warnings_dropped++;
- } else {
- errors.push_back(oe);
- }
- } else {
- if (err_count > max_errors_per_second) {
- n_errors_dropped++;
- } else {
- errors.push_back(oe);
- }
- }
- }
-
- mutex->unlock();
-}
-
-void ScriptDebuggerRemote::_print_handler(void *p_this, const String &p_string, bool p_error) {
-
- ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)p_this;
-
- uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000;
- sdr->msec_count += ticks - sdr->last_msec;
- sdr->last_msec = ticks;
-
- if (sdr->msec_count > 1000) {
- sdr->char_count = 0;
- sdr->msec_count = 0;
- }
-
- String s = p_string;
- int allowed_chars = MIN(MAX(sdr->max_cps - sdr->char_count, 0), s.length());
-
- if (allowed_chars == 0)
- return;
-
- if (allowed_chars < s.length()) {
- s = s.substr(0, allowed_chars);
- }
-
- sdr->char_count += allowed_chars;
- bool overflowed = sdr->char_count >= sdr->max_cps;
-
- sdr->mutex->lock();
- if (!sdr->locking && sdr->tcp_client->is_connected_to_host()) {
-
- if (overflowed)
- s += "[...]";
-
- sdr->output_strings.push_back(s);
-
- if (overflowed) {
- sdr->output_strings.push_back("[output overflow, print less text!]");
- }
- }
- sdr->mutex->unlock();
-}
-
-void ScriptDebuggerRemote::request_quit() {
-
- requested_quit = true;
-}
-
-void ScriptDebuggerRemote::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {
- multiplayer = p_multiplayer;
-}
-
-bool ScriptDebuggerRemote::is_profiling() const {
-
- return profiling;
-}
-void ScriptDebuggerRemote::add_profiling_frame_data(const StringName &p_name, const Array &p_data) {
-
- int idx = -1;
- for (int i = 0; i < profile_frame_data.size(); i++) {
- if (profile_frame_data[i].name == p_name) {
- idx = i;
- break;
- }
- }
-
- FrameData fd;
- fd.name = p_name;
- fd.data = p_data;
-
- if (idx == -1) {
- profile_frame_data.push_back(fd);
- } else {
- profile_frame_data.write[idx] = fd;
- }
-}
-
-void ScriptDebuggerRemote::profiling_start() {
- //ignores this, uses it via connection
-}
-
-void ScriptDebuggerRemote::profiling_end() {
- //ignores this, uses it via connection
-}
-
-void ScriptDebuggerRemote::profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) {
-
- frame_time = p_frame_time;
- idle_time = p_idle_time;
- physics_time = p_physics_time;
- physics_frame_time = p_physics_frame_time;
-}
-
-void ScriptDebuggerRemote::set_skip_breakpoints(bool p_skip_breakpoints) {
- skip_breakpoints = p_skip_breakpoints;
-}
-
-ScriptDebuggerRemote::ResourceUsageFunc ScriptDebuggerRemote::resource_usage_func = NULL;
-
-ScriptDebuggerRemote::ScriptDebuggerRemote() :
- profiling(false),
- visual_profiling(false),
- network_profiling(false),
- max_frame_functions(16),
- skip_profile_frame(false),
- reload_all_scripts(false),
- tcp_client(Ref<StreamPeerTCP>(memnew(StreamPeerTCP))),
- packet_peer_stream(Ref<PacketPeerStream>(memnew(PacketPeerStream))),
- last_perf_time(0),
- last_net_prof_time(0),
- last_net_bandwidth_time(0),
- performance(Engine::get_singleton()->get_singleton_object("Performance")),
- requested_quit(false),
- mutex(Mutex::create()),
- max_messages_per_frame(GLOBAL_GET("network/limits/debugger_stdout/max_messages_per_frame")),
- n_messages_dropped(0),
- max_errors_per_second(GLOBAL_GET("network/limits/debugger_stdout/max_errors_per_second")),
- max_warnings_per_second(GLOBAL_GET("network/limits/debugger_stdout/max_warnings_per_second")),
- n_errors_dropped(0),
- max_cps(GLOBAL_GET("network/limits/debugger_stdout/max_chars_per_second")),
- char_count(0),
- err_count(0),
- warn_count(0),
- last_msec(0),
- msec_count(0),
- locking(false),
- poll_every(0),
- scene_tree(NULL) {
-
- packet_peer_stream->set_stream_peer(tcp_client);
- packet_peer_stream->set_output_buffer_max_size((1024 * 1024 * 8) - 4); // 8 MiB should be way more than enough, minus 4 bytes for separator.
-
- phl.printfunc = _print_handler;
- phl.userdata = this;
- add_print_handler(&phl);
-
- eh.errfunc = _err_handler;
- eh.userdata = this;
- add_error_handler(&eh);
-
- profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions"));
- network_profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions"));
- profile_info_ptrs.resize(profile_info.size());
-}
-
-ScriptDebuggerRemote::~ScriptDebuggerRemote() {
-
- remove_print_handler(&phl);
- remove_error_handler(&eh);
- memdelete(mutex);
-}
diff --git a/scene/debugger/script_debugger_remote.h b/scene/debugger/script_debugger_remote.h
deleted file mode 100644
index ae44bf9ca2..0000000000
--- a/scene/debugger/script_debugger_remote.h
+++ /dev/null
@@ -1,197 +0,0 @@
-/*************************************************************************/
-/* script_debugger_remote.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#ifndef SCRIPT_DEBUGGER_REMOTE_H
-#define SCRIPT_DEBUGGER_REMOTE_H
-
-#include "core/io/packet_peer.h"
-#include "core/io/stream_peer_tcp.h"
-#include "core/list.h"
-#include "core/os/os.h"
-#include "core/script_language.h"
-
-class SceneTree;
-
-class ScriptDebuggerRemote : public ScriptDebugger {
-
- struct Message {
-
- String message;
- Array data;
- };
-
- struct ProfileInfoSort {
-
- bool operator()(ScriptLanguage::ProfilingInfo *A, ScriptLanguage::ProfilingInfo *B) const {
- return A->total_time < B->total_time;
- }
- };
-
- Vector<ScriptLanguage::ProfilingInfo> profile_info;
- Vector<ScriptLanguage::ProfilingInfo *> profile_info_ptrs;
- Vector<MultiplayerAPI::ProfilingInfo> network_profile_info;
-
- Map<StringName, int> profiler_function_signature_map;
- float frame_time, idle_time, physics_time, physics_frame_time;
-
- bool profiling;
- bool visual_profiling;
- bool network_profiling;
- int max_frame_functions;
- bool skip_profile_frame;
- bool reload_all_scripts;
-
- Ref<StreamPeerTCP> tcp_client;
- Ref<PacketPeerStream> packet_peer_stream;
-
- uint64_t last_perf_time;
- uint64_t last_net_prof_time;
- uint64_t last_net_bandwidth_time;
- Object *performance;
- bool requested_quit;
- Mutex *mutex;
-
- struct OutputError {
-
- int hr;
- int min;
- int sec;
- int msec;
- String source_file;
- String source_func;
- int source_line;
- String error;
- String error_descr;
- bool warning;
- Array callstack;
- };
-
- List<String> output_strings;
- List<Message> messages;
- int max_messages_per_frame;
- int n_messages_dropped;
- List<OutputError> errors;
- int max_errors_per_second;
- int max_warnings_per_second;
- int n_errors_dropped;
- int n_warnings_dropped;
-
- int max_cps;
- int char_count;
- int err_count;
- int warn_count;
- uint64_t last_msec;
- uint64_t msec_count;
-
- bool locking; //hack to avoid a deadloop
- static void _print_handler(void *p_this, const String &p_string, bool p_error);
-
- PrintHandlerList phl;
-
- void _get_output();
- void _poll_events();
- uint32_t poll_every;
-
- SceneTree *scene_tree;
-
- bool _parse_live_edit(const Array &p_command);
-
- void _set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value);
-
- void _send_object_id(ObjectID p_id);
- void _send_video_memory();
-
- Ref<MultiplayerAPI> multiplayer;
-
- ErrorHandlerList eh;
- static void _err_handler(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type);
-
- void _send_profiling_data(bool p_for_frame);
- void _send_network_profiling_data();
- void _send_network_bandwidth_usage();
-
- struct FrameData {
-
- StringName name;
- Array data;
- };
-
- Vector<FrameData> profile_frame_data;
-
- void _put_variable(const String &p_name, const Variant &p_variable);
-
- void _save_node(ObjectID id, const String &p_path);
-
- bool skip_breakpoints;
-
-public:
- struct ResourceUsage {
-
- String path;
- String format;
- String type;
- RID id;
- int vram;
- bool operator<(const ResourceUsage &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; }
- };
-
- typedef void (*ResourceUsageFunc)(List<ResourceUsage> *);
-
- static ResourceUsageFunc resource_usage_func;
-
- Error connect_to_host(const String &p_host, uint16_t p_port);
- virtual void debug(ScriptLanguage *p_script, bool p_can_continue = true, bool p_is_error_breakpoint = false);
- virtual void idle_poll();
- virtual void line_poll();
-
- virtual bool is_remote() const { return true; }
- virtual void request_quit();
-
- virtual void send_message(const String &p_message, const Array &p_args);
- virtual void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info);
-
- virtual void set_multiplayer(Ref<MultiplayerAPI> p_multiplayer);
-
- virtual bool is_profiling() const;
- virtual void add_profiling_frame_data(const StringName &p_name, const Array &p_data);
-
- virtual void profiling_start();
- virtual void profiling_end();
- virtual void profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time);
-
- virtual void set_skip_breakpoints(bool p_skip_breakpoints);
-
- void set_scene_tree(SceneTree *p_scene_tree) { scene_tree = p_scene_tree; };
-
- ScriptDebuggerRemote();
- ~ScriptDebuggerRemote();
-};
-
-#endif // SCRIPT_DEBUGGER_REMOTE_H