scene_debugger.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. private:
  42. static SceneDebugger *singleton;
  43. SceneDebugger();
  44. public:
  45. static void initialize();
  46. static void deinitialize();
  47. ~SceneDebugger();
  48. #ifdef DEBUG_ENABLED
  49. private:
  50. static void _save_node(ObjectID id, const String &p_path);
  51. static void _set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value);
  52. static void _send_object_id(ObjectID p_id, int p_max_size = 1 << 20);
  53. public:
  54. static Error parse_message(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured);
  55. static void add_to_cache(const String &p_filename, Node *p_node);
  56. static void remove_from_cache(const String &p_filename, Node *p_node);
  57. #endif
  58. };
  59. #ifdef DEBUG_ENABLED
  60. class SceneDebuggerObject {
  61. private:
  62. void _parse_script_properties(Script *p_script, ScriptInstance *p_instance);
  63. public:
  64. typedef Pair<PropertyInfo, Variant> SceneDebuggerProperty;
  65. ObjectID id;
  66. String class_name;
  67. List<SceneDebuggerProperty> properties;
  68. SceneDebuggerObject(ObjectID p_id);
  69. SceneDebuggerObject() {}
  70. void serialize(Array &r_arr, int p_max_size = 1 << 20);
  71. void deserialize(const Array &p_arr);
  72. };
  73. class SceneDebuggerTree {
  74. public:
  75. struct RemoteNode {
  76. int child_count = 0;
  77. String name;
  78. String type_name;
  79. ObjectID id;
  80. String scene_file_path;
  81. uint8_t view_flags = 0;
  82. enum ViewFlags {
  83. VIEW_HAS_VISIBLE_METHOD = 1 << 1,
  84. VIEW_VISIBLE = 1 << 2,
  85. VIEW_VISIBLE_IN_TREE = 1 << 3,
  86. };
  87. RemoteNode(int p_child, const String &p_name, const String &p_type, ObjectID p_id, const String p_scene_file_path, int p_view_flags) {
  88. child_count = p_child;
  89. name = p_name;
  90. type_name = p_type;
  91. id = p_id;
  92. scene_file_path = p_scene_file_path;
  93. view_flags = p_view_flags;
  94. }
  95. RemoteNode() {}
  96. };
  97. List<RemoteNode> nodes;
  98. void serialize(Array &r_arr);
  99. void deserialize(const Array &p_arr);
  100. SceneDebuggerTree(Node *p_root);
  101. SceneDebuggerTree() {}
  102. };
  103. class LiveEditor {
  104. private:
  105. friend class SceneDebugger;
  106. HashMap<int, NodePath> live_edit_node_path_cache;
  107. HashMap<int, String> live_edit_resource_cache;
  108. NodePath live_edit_root;
  109. String live_edit_scene;
  110. HashMap<String, HashSet<Node *>> live_scene_edit_cache;
  111. HashMap<Node *, HashMap<ObjectID, Node *>> live_edit_remove_list;
  112. void _send_tree();
  113. void _node_path_func(const NodePath &p_path, int p_id);
  114. void _res_path_func(const String &p_path, int p_id);
  115. void _node_set_func(int p_id, const StringName &p_prop, const Variant &p_value);
  116. void _node_set_res_func(int p_id, const StringName &p_prop, const String &p_value);
  117. void _node_call_func(int p_id, const StringName &p_method, const Variant **p_args, int p_argcount);
  118. void _res_set_func(int p_id, const StringName &p_prop, const Variant &p_value);
  119. void _res_set_res_func(int p_id, const StringName &p_prop, const String &p_value);
  120. void _res_call_func(int p_id, const StringName &p_method, const Variant **p_args, int p_argcount);
  121. void _root_func(const NodePath &p_scene_path, const String &p_scene_from);
  122. void _create_node_func(const NodePath &p_parent, const String &p_type, const String &p_name);
  123. void _instance_node_func(const NodePath &p_parent, const String &p_path, const String &p_name);
  124. void _remove_node_func(const NodePath &p_at);
  125. void _remove_and_keep_node_func(const NodePath &p_at, ObjectID p_keep_id);
  126. void _restore_node_func(ObjectID p_id, const NodePath &p_at, int p_at_pos);
  127. void _duplicate_node_func(const NodePath &p_at, const String &p_new_name);
  128. void _reparent_node_func(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
  129. LiveEditor() {
  130. singleton = this;
  131. live_edit_root = NodePath("/root");
  132. };
  133. static LiveEditor *singleton;
  134. public:
  135. static LiveEditor *get_singleton();
  136. };
  137. #endif
  138. #endif // SCENE_DEBUGGER_H