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