scene_debugger.h 6.2 KB

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