scene_debugger.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*************************************************************************/
  2. /* scene_debugger.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef SCENE_DEBUGGER_H
  31. #define SCENE_DEBUGGER_H
  32. #include "core/object/class_db.h"
  33. #include "core/object/ref_counted.h"
  34. #include "core/string/ustring.h"
  35. #include "core/templates/pair.h"
  36. #include "core/variant/array.h"
  37. class Script;
  38. class Node;
  39. class SceneDebugger {
  40. public:
  41. // RPC profiler
  42. struct RPCNodeInfo {
  43. ObjectID node;
  44. String node_path;
  45. int incoming_rpc = 0;
  46. int outgoing_rpc = 0;
  47. };
  48. struct RPCProfilerFrame {
  49. Vector<RPCNodeInfo> infos;
  50. Array serialize();
  51. bool deserialize(const Array &p_arr);
  52. };
  53. private:
  54. class RPCProfiler;
  55. static SceneDebugger *singleton;
  56. Ref<RPCProfiler> rpc_profiler;
  57. SceneDebugger();
  58. public:
  59. static void initialize();
  60. static void deinitialize();
  61. ~SceneDebugger();
  62. #ifdef DEBUG_ENABLED
  63. private:
  64. static void _save_node(ObjectID id, const String &p_path);
  65. static void _set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value);
  66. static void _send_object_id(ObjectID p_id, int p_max_size = 1 << 20);
  67. public:
  68. static Error parse_message(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured);
  69. static void add_to_cache(const String &p_filename, Node *p_node);
  70. static void remove_from_cache(const String &p_filename, Node *p_node);
  71. #endif
  72. };
  73. #ifdef DEBUG_ENABLED
  74. class SceneDebuggerObject {
  75. private:
  76. void _parse_script_properties(Script *p_script, ScriptInstance *p_instance);
  77. public:
  78. typedef Pair<PropertyInfo, Variant> SceneDebuggerProperty;
  79. ObjectID id;
  80. String class_name;
  81. List<SceneDebuggerProperty> properties;
  82. SceneDebuggerObject(ObjectID p_id);
  83. SceneDebuggerObject() {}
  84. void serialize(Array &r_arr, int p_max_size = 1 << 20);
  85. void deserialize(const Array &p_arr);
  86. };
  87. class SceneDebuggerTree {
  88. public:
  89. struct RemoteNode {
  90. int child_count = 0;
  91. String name;
  92. String type_name;
  93. ObjectID id;
  94. RemoteNode(int p_child, const String &p_name, const String &p_type, ObjectID p_id) {
  95. child_count = p_child;
  96. name = p_name;
  97. type_name = p_type;
  98. id = p_id;
  99. }
  100. RemoteNode() {}
  101. };
  102. List<RemoteNode> nodes;
  103. void serialize(Array &r_arr);
  104. void deserialize(const Array &p_arr);
  105. SceneDebuggerTree(Node *p_root);
  106. SceneDebuggerTree() {}
  107. };
  108. class LiveEditor {
  109. private:
  110. friend class SceneDebugger;
  111. HashMap<int, NodePath> live_edit_node_path_cache;
  112. HashMap<int, String> live_edit_resource_cache;
  113. NodePath live_edit_root;
  114. String live_edit_scene;
  115. HashMap<String, HashSet<Node *>> live_scene_edit_cache;
  116. HashMap<Node *, HashMap<ObjectID, Node *>> live_edit_remove_list;
  117. void _send_tree();
  118. void _node_path_func(const NodePath &p_path, int p_id);
  119. void _res_path_func(const String &p_path, int p_id);
  120. void _node_set_func(int p_id, const StringName &p_prop, const Variant &p_value);
  121. void _node_set_res_func(int p_id, const StringName &p_prop, const String &p_value);
  122. void _node_call_func(int p_id, const StringName &p_method, const Variant **p_args, int p_argcount);
  123. void _res_set_func(int p_id, const StringName &p_prop, const Variant &p_value);
  124. void _res_set_res_func(int p_id, const StringName &p_prop, const String &p_value);
  125. void _res_call_func(int p_id, const StringName &p_method, const Variant **p_args, int p_argcount);
  126. void _root_func(const NodePath &p_scene_path, const String &p_scene_from);
  127. void _create_node_func(const NodePath &p_parent, const String &p_type, const String &p_name);
  128. void _instance_node_func(const NodePath &p_parent, const String &p_path, const String &p_name);
  129. void _remove_node_func(const NodePath &p_at);
  130. void _remove_and_keep_node_func(const NodePath &p_at, ObjectID p_keep_id);
  131. void _restore_node_func(ObjectID p_id, const NodePath &p_at, int p_at_pos);
  132. void _duplicate_node_func(const NodePath &p_at, const String &p_new_name);
  133. void _reparent_node_func(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
  134. LiveEditor() {
  135. singleton = this;
  136. live_edit_root = NodePath("/root");
  137. };
  138. static LiveEditor *singleton;
  139. public:
  140. static LiveEditor *get_singleton();
  141. };
  142. #endif
  143. #endif // SCENE_DEBUGGER_H