scene_debugger.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*************************************************************************/
  2. /* scene_debugger.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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/string/ustring.h"
  34. #include "core/templates/pair.h"
  35. #include "core/variant/array.h"
  36. class Script;
  37. class SceneDebugger {
  38. public:
  39. static void initialize();
  40. static void deinitialize();
  41. #ifdef DEBUG_ENABLED
  42. private:
  43. static void _save_node(ObjectID id, const String &p_path);
  44. static void _set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value);
  45. static void _send_object_id(ObjectID p_id, int p_max_size = 1 << 20);
  46. public:
  47. static Error parse_message(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured);
  48. static void add_to_cache(const String &p_filename, Node *p_node);
  49. static void remove_from_cache(const String &p_filename, Node *p_node);
  50. #endif
  51. };
  52. #ifdef DEBUG_ENABLED
  53. class SceneDebuggerObject {
  54. private:
  55. void _parse_script_properties(Script *p_script, ScriptInstance *p_instance);
  56. public:
  57. typedef Pair<PropertyInfo, Variant> SceneDebuggerProperty;
  58. ObjectID id;
  59. String class_name;
  60. List<SceneDebuggerProperty> properties;
  61. SceneDebuggerObject(ObjectID p_id);
  62. SceneDebuggerObject() {}
  63. void serialize(Array &r_arr, int p_max_size = 1 << 20);
  64. void deserialize(const Array &p_arr);
  65. };
  66. class SceneDebuggerTree {
  67. public:
  68. struct RemoteNode {
  69. int child_count = 0;
  70. String name;
  71. String type_name;
  72. ObjectID id;
  73. RemoteNode(int p_child, const String &p_name, const String &p_type, ObjectID p_id) {
  74. child_count = p_child;
  75. name = p_name;
  76. type_name = p_type;
  77. id = p_id;
  78. }
  79. RemoteNode() {}
  80. };
  81. List<RemoteNode> nodes;
  82. void serialize(Array &r_arr);
  83. void deserialize(const Array &p_arr);
  84. SceneDebuggerTree(Node *p_root);
  85. SceneDebuggerTree() {}
  86. };
  87. class LiveEditor {
  88. private:
  89. friend class SceneDebugger;
  90. Map<int, NodePath> live_edit_node_path_cache;
  91. Map<int, String> live_edit_resource_cache;
  92. NodePath live_edit_root;
  93. String live_edit_scene;
  94. Map<String, Set<Node *>> live_scene_edit_cache;
  95. Map<Node *, Map<ObjectID, Node *>> live_edit_remove_list;
  96. void _send_tree();
  97. void _node_path_func(const NodePath &p_path, int p_id);
  98. void _res_path_func(const String &p_path, int p_id);
  99. void _node_set_func(int p_id, const StringName &p_prop, const Variant &p_value);
  100. void _node_set_res_func(int p_id, const StringName &p_prop, const String &p_value);
  101. void _node_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE);
  102. void _res_set_func(int p_id, const StringName &p_prop, const Variant &p_value);
  103. void _res_set_res_func(int p_id, const StringName &p_prop, const String &p_value);
  104. void _res_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE);
  105. void _root_func(const NodePath &p_scene_path, const String &p_scene_from);
  106. void _create_node_func(const NodePath &p_parent, const String &p_type, const String &p_name);
  107. void _instance_node_func(const NodePath &p_parent, const String &p_path, const String &p_name);
  108. void _remove_node_func(const NodePath &p_at);
  109. void _remove_and_keep_node_func(const NodePath &p_at, ObjectID p_keep_id);
  110. void _restore_node_func(ObjectID p_id, const NodePath &p_at, int p_at_pos);
  111. void _duplicate_node_func(const NodePath &p_at, const String &p_new_name);
  112. void _reparent_node_func(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
  113. LiveEditor() {
  114. singleton = this;
  115. live_edit_root = NodePath("/root");
  116. };
  117. static LiveEditor *singleton;
  118. public:
  119. static LiveEditor *get_singleton();
  120. };
  121. #endif
  122. #endif