script_editor_debugger.cpp 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519
  1. /*************************************************************************/
  2. /* script_editor_debugger.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. #include "script_editor_debugger.h"
  31. #include "core/io/marshalls.h"
  32. #include "core/project_settings.h"
  33. #include "core/ustring.h"
  34. #include "editor_network_profiler.h"
  35. #include "editor_node.h"
  36. #include "editor_profiler.h"
  37. #include "editor_settings.h"
  38. #include "main/performance.h"
  39. #include "property_editor.h"
  40. #include "scene/gui/dialogs.h"
  41. #include "scene/gui/label.h"
  42. #include "scene/gui/line_edit.h"
  43. #include "scene/gui/margin_container.h"
  44. #include "scene/gui/rich_text_label.h"
  45. #include "scene/gui/separator.h"
  46. #include "scene/gui/split_container.h"
  47. #include "scene/gui/tab_container.h"
  48. #include "scene/gui/texture_button.h"
  49. #include "scene/gui/tree.h"
  50. #include "scene/resources/packed_scene.h"
  51. class ScriptEditorDebuggerVariables : public Object {
  52. GDCLASS(ScriptEditorDebuggerVariables, Object);
  53. List<PropertyInfo> props;
  54. Map<StringName, Variant> values;
  55. protected:
  56. bool _set(const StringName &p_name, const Variant &p_value) {
  57. return false;
  58. }
  59. bool _get(const StringName &p_name, Variant &r_ret) const {
  60. if (!values.has(p_name))
  61. return false;
  62. r_ret = values[p_name];
  63. return true;
  64. }
  65. void _get_property_list(List<PropertyInfo> *p_list) const {
  66. for (const List<PropertyInfo>::Element *E = props.front(); E; E = E->next())
  67. p_list->push_back(E->get());
  68. }
  69. public:
  70. void clear() {
  71. props.clear();
  72. values.clear();
  73. }
  74. String get_var_value(const String &p_var) const {
  75. for (Map<StringName, Variant>::Element *E = values.front(); E; E = E->next()) {
  76. String v = E->key().operator String().get_slice("/", 1);
  77. if (v == p_var)
  78. return E->get();
  79. }
  80. return "";
  81. }
  82. void add_property(const String &p_name, const Variant &p_value, const PropertyHint &p_hint, const String p_hint_string) {
  83. PropertyInfo pinfo;
  84. pinfo.name = p_name;
  85. pinfo.type = p_value.get_type();
  86. pinfo.hint = p_hint;
  87. pinfo.hint_string = p_hint_string;
  88. props.push_back(pinfo);
  89. values[p_name] = p_value;
  90. }
  91. void update() {
  92. _change_notify();
  93. }
  94. ScriptEditorDebuggerVariables() {
  95. }
  96. };
  97. class ScriptEditorDebuggerInspectedObject : public Object {
  98. GDCLASS(ScriptEditorDebuggerInspectedObject, Object);
  99. protected:
  100. bool _set(const StringName &p_name, const Variant &p_value) {
  101. if (!prop_values.has(p_name) || String(p_name).begins_with("Constants/"))
  102. return false;
  103. prop_values[p_name] = p_value;
  104. emit_signal("value_edited", p_name, p_value);
  105. return true;
  106. }
  107. bool _get(const StringName &p_name, Variant &r_ret) const {
  108. if (!prop_values.has(p_name))
  109. return false;
  110. r_ret = prop_values[p_name];
  111. return true;
  112. }
  113. void _get_property_list(List<PropertyInfo> *p_list) const {
  114. p_list->clear(); //sorry, no want category
  115. for (const List<PropertyInfo>::Element *E = prop_list.front(); E; E = E->next()) {
  116. p_list->push_back(E->get());
  117. }
  118. }
  119. static void _bind_methods() {
  120. ClassDB::bind_method(D_METHOD("get_title"), &ScriptEditorDebuggerInspectedObject::get_title);
  121. ClassDB::bind_method(D_METHOD("get_variant"), &ScriptEditorDebuggerInspectedObject::get_variant);
  122. ClassDB::bind_method(D_METHOD("clear"), &ScriptEditorDebuggerInspectedObject::clear);
  123. ClassDB::bind_method(D_METHOD("get_remote_object_id"), &ScriptEditorDebuggerInspectedObject::get_remote_object_id);
  124. ADD_SIGNAL(MethodInfo("value_edited"));
  125. }
  126. public:
  127. String type_name;
  128. ObjectID remote_object_id;
  129. List<PropertyInfo> prop_list;
  130. Map<StringName, Variant> prop_values;
  131. ObjectID get_remote_object_id() {
  132. return remote_object_id;
  133. }
  134. String get_title() {
  135. if (remote_object_id)
  136. return TTR("Remote ") + String(type_name) + ": " + itos(remote_object_id);
  137. else
  138. return "<null>";
  139. }
  140. Variant get_variant(const StringName &p_name) {
  141. Variant var;
  142. _get(p_name, var);
  143. return var;
  144. }
  145. void clear() {
  146. prop_list.clear();
  147. prop_values.clear();
  148. }
  149. void update() {
  150. _change_notify();
  151. }
  152. void update_single(const char *p_prop) {
  153. _change_notify(p_prop);
  154. }
  155. ScriptEditorDebuggerInspectedObject() {
  156. remote_object_id = 0;
  157. }
  158. };
  159. void ScriptEditorDebugger::debug_copy() {
  160. String msg = reason->get_text();
  161. if (msg == "") return;
  162. OS::get_singleton()->set_clipboard(msg);
  163. }
  164. void ScriptEditorDebugger::debug_skip_breakpoints() {
  165. skip_breakpoints_value = !skip_breakpoints_value;
  166. if (skip_breakpoints_value)
  167. skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOn", "EditorIcons"));
  168. else
  169. skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOff", "EditorIcons"));
  170. if (connection.is_valid()) {
  171. Array msg;
  172. msg.push_back("set_skip_breakpoints");
  173. msg.push_back(skip_breakpoints_value);
  174. ppeer->put_var(msg);
  175. }
  176. }
  177. void ScriptEditorDebugger::debug_next() {
  178. ERR_FAIL_COND(!breaked);
  179. ERR_FAIL_COND(connection.is_null());
  180. ERR_FAIL_COND(!connection->is_connected_to_host());
  181. Array msg;
  182. msg.push_back("next");
  183. ppeer->put_var(msg);
  184. _clear_execution();
  185. stack_dump->clear();
  186. }
  187. void ScriptEditorDebugger::debug_step() {
  188. ERR_FAIL_COND(!breaked);
  189. ERR_FAIL_COND(connection.is_null());
  190. ERR_FAIL_COND(!connection->is_connected_to_host());
  191. Array msg;
  192. msg.push_back("step");
  193. ppeer->put_var(msg);
  194. _clear_execution();
  195. stack_dump->clear();
  196. }
  197. void ScriptEditorDebugger::debug_break() {
  198. ERR_FAIL_COND(breaked);
  199. ERR_FAIL_COND(connection.is_null());
  200. ERR_FAIL_COND(!connection->is_connected_to_host());
  201. Array msg;
  202. msg.push_back("break");
  203. ppeer->put_var(msg);
  204. }
  205. void ScriptEditorDebugger::debug_continue() {
  206. ERR_FAIL_COND(!breaked);
  207. ERR_FAIL_COND(connection.is_null());
  208. ERR_FAIL_COND(!connection->is_connected_to_host());
  209. OS::get_singleton()->enable_for_stealing_focus(EditorNode::get_singleton()->get_child_process_id());
  210. Array msg;
  211. _clear_execution();
  212. msg.push_back("continue");
  213. ppeer->put_var(msg);
  214. }
  215. void ScriptEditorDebugger::_scene_tree_folded(Object *obj) {
  216. if (updating_scene_tree) {
  217. return;
  218. }
  219. TreeItem *item = Object::cast_to<TreeItem>(obj);
  220. if (!item)
  221. return;
  222. ObjectID id = item->get_metadata(0);
  223. if (unfold_cache.has(id)) {
  224. unfold_cache.erase(id);
  225. } else {
  226. unfold_cache.insert(id);
  227. }
  228. }
  229. void ScriptEditorDebugger::_scene_tree_selected() {
  230. if (updating_scene_tree) {
  231. return;
  232. }
  233. TreeItem *item = inspect_scene_tree->get_selected();
  234. if (!item) {
  235. return;
  236. }
  237. inspected_object_id = item->get_metadata(0);
  238. Array msg;
  239. msg.push_back("inspect_object");
  240. msg.push_back(inspected_object_id);
  241. ppeer->put_var(msg);
  242. }
  243. void ScriptEditorDebugger::_scene_tree_rmb_selected(const Vector2 &p_position) {
  244. TreeItem *item = inspect_scene_tree->get_item_at_position(p_position);
  245. if (!item)
  246. return;
  247. item->select(0);
  248. item_menu->clear();
  249. item_menu->add_icon_item(get_icon("CreateNewSceneFrom", "EditorIcons"), TTR("Save Branch as Scene"), ITEM_MENU_SAVE_REMOTE_NODE);
  250. item_menu->add_icon_item(get_icon("CopyNodePath", "EditorIcons"), TTR("Copy Node Path"), ITEM_MENU_COPY_NODE_PATH);
  251. item_menu->set_global_position(get_global_mouse_position());
  252. item_menu->popup();
  253. }
  254. void ScriptEditorDebugger::_file_selected(const String &p_file) {
  255. switch (file_dialog_mode) {
  256. case SAVE_NODE: {
  257. Array msg;
  258. msg.push_back("save_node");
  259. msg.push_back(inspected_object_id);
  260. msg.push_back(p_file);
  261. ppeer->put_var(msg);
  262. } break;
  263. case SAVE_CSV: {
  264. Error err;
  265. FileAccessRef file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  266. if (err != OK) {
  267. ERR_PRINTS("Failed to open " + p_file);
  268. return;
  269. }
  270. Vector<String> line;
  271. line.resize(Performance::MONITOR_MAX);
  272. // signatures
  273. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  274. line.write[i] = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  275. }
  276. file->store_csv_line(line);
  277. // values
  278. List<Vector<float> >::Element *E = perf_history.back();
  279. while (E) {
  280. Vector<float> &perf_data = E->get();
  281. for (int i = 0; i < perf_data.size(); i++) {
  282. line.write[i] = String::num_real(perf_data[i]);
  283. }
  284. file->store_csv_line(line);
  285. E = E->prev();
  286. }
  287. file->store_string("\n");
  288. Vector<Vector<String> > profiler_data = profiler->get_data_as_csv();
  289. for (int i = 0; i < profiler_data.size(); i++) {
  290. file->store_csv_line(profiler_data[i]);
  291. }
  292. } break;
  293. }
  294. }
  295. void ScriptEditorDebugger::_scene_tree_property_value_edited(const String &p_prop, const Variant &p_value) {
  296. Array msg;
  297. msg.push_back("set_object_property");
  298. msg.push_back(inspected_object_id);
  299. msg.push_back(p_prop);
  300. msg.push_back(p_value);
  301. ppeer->put_var(msg);
  302. inspect_edited_object_timeout = 0.7; //avoid annoyance, don't request soon after editing
  303. }
  304. void ScriptEditorDebugger::_scene_tree_property_select_object(ObjectID p_object) {
  305. inspected_object_id = p_object;
  306. Array msg;
  307. msg.push_back("inspect_object");
  308. msg.push_back(inspected_object_id);
  309. ppeer->put_var(msg);
  310. }
  311. void ScriptEditorDebugger::_scene_tree_request() {
  312. ERR_FAIL_COND(connection.is_null());
  313. ERR_FAIL_COND(!connection->is_connected_to_host());
  314. Array msg;
  315. msg.push_back("request_scene_tree");
  316. ppeer->put_var(msg);
  317. }
  318. /// Populates inspect_scene_tree recursively given data in nodes.
  319. /// Nodes is an array containing 4 elements for each node, it follows this pattern:
  320. /// nodes[i] == number of direct children of this node
  321. /// nodes[i + 1] == node name
  322. /// nodes[i + 2] == node class
  323. /// nodes[i + 3] == node instance id
  324. ///
  325. /// Returns the number of items parsed in nodes from current_index.
  326. ///
  327. /// Given a nodes array like [R,A,B,C,D,E] the following Tree will be generated, assuming
  328. /// filter is an empty String, R and A child count are 2, B is 1 and C, D and E are 0.
  329. ///
  330. /// R
  331. /// |-A
  332. /// | |-B
  333. /// | | |-C
  334. /// | |
  335. /// | |-D
  336. /// |
  337. /// |-E
  338. ///
  339. int ScriptEditorDebugger::_update_scene_tree(TreeItem *parent, const Array &nodes, int current_index) {
  340. String filter = EditorNode::get_singleton()->get_scene_tree_dock()->get_filter();
  341. String item_text = nodes[current_index + 1];
  342. String item_type = nodes[current_index + 2];
  343. bool keep = filter.is_subsequence_ofi(item_text);
  344. TreeItem *item = inspect_scene_tree->create_item(parent);
  345. item->set_text(0, item_text);
  346. item->set_tooltip(0, TTR("Type:") + " " + item_type);
  347. ObjectID id = ObjectID(nodes[current_index + 3]);
  348. Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(nodes[current_index + 2], "");
  349. if (icon.is_valid()) {
  350. item->set_icon(0, icon);
  351. }
  352. item->set_metadata(0, id);
  353. if (id == inspected_object_id) {
  354. TreeItem *cti = item->get_parent();
  355. while (cti) {
  356. cti->set_collapsed(false);
  357. cti = cti->get_parent();
  358. }
  359. item->select(0);
  360. }
  361. // Set current item as collapsed if necessary
  362. if (parent) {
  363. if (!unfold_cache.has(id)) {
  364. item->set_collapsed(true);
  365. }
  366. }
  367. int children_count = nodes[current_index];
  368. // Tracks the total number of items parsed in nodes, this is used to skips nodes that
  369. // are not direct children of the current node since we can't know in advance the total
  370. // number of children, direct and not, of a node without traversing the nodes array previously.
  371. // Keeping track of this allows us to build our remote scene tree by traversing the node
  372. // array just once.
  373. int items_count = 1;
  374. for (int i = 0; i < children_count; i++) {
  375. // Called for each direct child of item.
  376. // Direct children of current item might not be adjacent so items_count must
  377. // be incremented by the number of items parsed until now, otherwise we would not
  378. // be able to access the next child of the current item.
  379. // items_count is multiplied by 4 since that's the number of elements in the nodes
  380. // array needed to represent a single node.
  381. items_count += _update_scene_tree(item, nodes, current_index + items_count * 4);
  382. }
  383. // If item has not children and should not be kept delete it
  384. if (!keep && !item->get_children() && parent) {
  385. parent->remove_child(item);
  386. memdelete(item);
  387. }
  388. return items_count;
  389. }
  390. void ScriptEditorDebugger::_video_mem_request() {
  391. ERR_FAIL_COND(connection.is_null());
  392. ERR_FAIL_COND(!connection->is_connected_to_host());
  393. Array msg;
  394. msg.push_back("request_video_mem");
  395. ppeer->put_var(msg);
  396. }
  397. Size2 ScriptEditorDebugger::get_minimum_size() const {
  398. Size2 ms = Control::get_minimum_size();
  399. ms.y = MAX(ms.y, 250 * EDSCALE);
  400. return ms;
  401. }
  402. void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_data) {
  403. if (p_msg == "debug_enter") {
  404. Array msg;
  405. msg.push_back("get_stack_dump");
  406. ppeer->put_var(msg);
  407. ERR_FAIL_COND(p_data.size() != 2);
  408. bool can_continue = p_data[0];
  409. String error = p_data[1];
  410. step->set_disabled(!can_continue);
  411. next->set_disabled(!can_continue);
  412. _set_reason_text(error, MESSAGE_ERROR);
  413. copy->set_disabled(false);
  414. breaked = true;
  415. dobreak->set_disabled(true);
  416. docontinue->set_disabled(false);
  417. emit_signal("breaked", true, can_continue);
  418. OS::get_singleton()->move_window_to_foreground();
  419. if (error != "") {
  420. tabs->set_current_tab(0);
  421. }
  422. profiler->set_enabled(false);
  423. EditorNode::get_singleton()->get_pause_button()->set_pressed(true);
  424. EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  425. _clear_remote_objects();
  426. } else if (p_msg == "debug_exit") {
  427. breaked = false;
  428. _clear_execution();
  429. copy->set_disabled(true);
  430. step->set_disabled(true);
  431. next->set_disabled(true);
  432. reason->set_text("");
  433. reason->set_tooltip("");
  434. back->set_disabled(true);
  435. forward->set_disabled(true);
  436. dobreak->set_disabled(false);
  437. docontinue->set_disabled(true);
  438. emit_signal("breaked", false, false, Variant());
  439. profiler->set_enabled(true);
  440. profiler->disable_seeking();
  441. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  442. } else if (p_msg == "message:click_ctrl") {
  443. clicked_ctrl->set_text(p_data[0]);
  444. clicked_ctrl_type->set_text(p_data[1]);
  445. } else if (p_msg == "message:scene_tree") {
  446. inspect_scene_tree->clear();
  447. Map<int, TreeItem *> lv;
  448. updating_scene_tree = true;
  449. _update_scene_tree(NULL, p_data, 0);
  450. updating_scene_tree = false;
  451. le_clear->set_disabled(false);
  452. le_set->set_disabled(false);
  453. } else if (p_msg == "message:inspect_object") {
  454. ScriptEditorDebuggerInspectedObject *debugObj = NULL;
  455. ObjectID id = p_data[0];
  456. String type = p_data[1];
  457. Array properties = p_data[2];
  458. if (remote_objects.has(id)) {
  459. debugObj = remote_objects[id];
  460. } else {
  461. debugObj = memnew(ScriptEditorDebuggerInspectedObject);
  462. debugObj->remote_object_id = id;
  463. debugObj->type_name = type;
  464. remote_objects[id] = debugObj;
  465. debugObj->connect("value_edited", this, "_scene_tree_property_value_edited");
  466. }
  467. int old_prop_size = debugObj->prop_list.size();
  468. debugObj->prop_list.clear();
  469. int new_props_added = 0;
  470. Set<String> changed;
  471. for (int i = 0; i < properties.size(); i++) {
  472. Array prop = properties[i];
  473. if (prop.size() != 6)
  474. continue;
  475. PropertyInfo pinfo;
  476. pinfo.name = prop[0];
  477. pinfo.type = Variant::Type(int(prop[1]));
  478. pinfo.hint = PropertyHint(int(prop[2]));
  479. pinfo.hint_string = prop[3];
  480. pinfo.usage = PropertyUsageFlags(int(prop[4]));
  481. Variant var = prop[5];
  482. if (pinfo.type == Variant::OBJECT) {
  483. if (var.is_zero()) {
  484. var = RES();
  485. } else if (var.get_type() == Variant::STRING) {
  486. var = ResourceLoader::load(var);
  487. if (pinfo.hint_string == "Script")
  488. debugObj->set_script(var);
  489. } else if (var.get_type() == Variant::OBJECT) {
  490. if (((Object *)var)->is_class("EncodedObjectAsID")) {
  491. var = Object::cast_to<EncodedObjectAsID>(var)->get_object_id();
  492. pinfo.type = var.get_type();
  493. pinfo.hint = PROPERTY_HINT_OBJECT_ID;
  494. pinfo.hint_string = "Object";
  495. }
  496. }
  497. }
  498. //always add the property, since props may have been added or removed
  499. debugObj->prop_list.push_back(pinfo);
  500. if (!debugObj->prop_values.has(pinfo.name)) {
  501. new_props_added++;
  502. debugObj->prop_values[pinfo.name] = var;
  503. } else {
  504. if (bool(Variant::evaluate(Variant::OP_NOT_EQUAL, debugObj->prop_values[pinfo.name], var))) {
  505. debugObj->prop_values[pinfo.name] = var;
  506. changed.insert(pinfo.name);
  507. }
  508. }
  509. }
  510. if (editor->get_editor_history()->get_current() != debugObj->get_instance_id()) {
  511. editor->push_item(debugObj, "");
  512. } else {
  513. if (old_prop_size == debugObj->prop_list.size() && new_props_added == 0) {
  514. //only some may have changed, if so, then update those, if exist
  515. for (Set<String>::Element *E = changed.front(); E; E = E->next()) {
  516. EditorNode::get_singleton()->get_inspector()->update_property(E->get());
  517. }
  518. } else {
  519. //full update, because props were added or removed
  520. debugObj->update();
  521. }
  522. }
  523. } else if (p_msg == "message:video_mem") {
  524. vmem_tree->clear();
  525. TreeItem *root = vmem_tree->create_item();
  526. int total = 0;
  527. for (int i = 0; i < p_data.size(); i += 4) {
  528. TreeItem *it = vmem_tree->create_item(root);
  529. String type = p_data[i + 1];
  530. int bytes = p_data[i + 3].operator int();
  531. it->set_text(0, p_data[i + 0]); //path
  532. it->set_text(1, type); //type
  533. it->set_text(2, p_data[i + 2]); //type
  534. it->set_text(3, String::humanize_size(bytes)); //type
  535. total += bytes;
  536. if (has_icon(type, "EditorIcons"))
  537. it->set_icon(0, get_icon(type, "EditorIcons"));
  538. }
  539. vmem_total->set_tooltip(TTR("Bytes:") + " " + itos(total));
  540. vmem_total->set_text(String::humanize_size(total));
  541. } else if (p_msg == "stack_dump") {
  542. stack_dump->clear();
  543. TreeItem *r = stack_dump->create_item();
  544. for (int i = 0; i < p_data.size(); i++) {
  545. Dictionary d = p_data[i];
  546. ERR_CONTINUE(!d.has("function"));
  547. ERR_CONTINUE(!d.has("file"));
  548. ERR_CONTINUE(!d.has("line"));
  549. ERR_CONTINUE(!d.has("id"));
  550. TreeItem *s = stack_dump->create_item(r);
  551. d["frame"] = i;
  552. s->set_metadata(0, d);
  553. String line = itos(i) + " - " + String(d["file"]) + ":" + itos(d["line"]) + " - at function: " + d["function"];
  554. s->set_text(0, line);
  555. if (i == 0)
  556. s->select(0);
  557. }
  558. } else if (p_msg == "stack_frame_vars") {
  559. variables->clear();
  560. int ofs = 0;
  561. int mcount = p_data[ofs];
  562. ofs++;
  563. for (int i = 0; i < mcount; i++) {
  564. String n = p_data[ofs + i * 2 + 0];
  565. Variant v = p_data[ofs + i * 2 + 1];
  566. PropertyHint h = PROPERTY_HINT_NONE;
  567. String hs = String();
  568. if (v.get_type() == Variant::OBJECT) {
  569. v = Object::cast_to<EncodedObjectAsID>(v)->get_object_id();
  570. h = PROPERTY_HINT_OBJECT_ID;
  571. hs = "Object";
  572. }
  573. variables->add_property("Locals/" + n, v, h, hs);
  574. }
  575. ofs += mcount * 2;
  576. mcount = p_data[ofs];
  577. ofs++;
  578. for (int i = 0; i < mcount; i++) {
  579. String n = p_data[ofs + i * 2 + 0];
  580. Variant v = p_data[ofs + i * 2 + 1];
  581. PropertyHint h = PROPERTY_HINT_NONE;
  582. String hs = String();
  583. if (v.get_type() == Variant::OBJECT) {
  584. v = Object::cast_to<EncodedObjectAsID>(v)->get_object_id();
  585. h = PROPERTY_HINT_OBJECT_ID;
  586. hs = "Object";
  587. }
  588. variables->add_property("Members/" + n, v, h, hs);
  589. }
  590. ofs += mcount * 2;
  591. mcount = p_data[ofs];
  592. ofs++;
  593. for (int i = 0; i < mcount; i++) {
  594. String n = p_data[ofs + i * 2 + 0];
  595. Variant v = p_data[ofs + i * 2 + 1];
  596. PropertyHint h = PROPERTY_HINT_NONE;
  597. String hs = String();
  598. if (v.get_type() == Variant::OBJECT) {
  599. v = Object::cast_to<EncodedObjectAsID>(v)->get_object_id();
  600. h = PROPERTY_HINT_OBJECT_ID;
  601. hs = "Object";
  602. }
  603. variables->add_property("Globals/" + n, v, h, hs);
  604. }
  605. variables->update();
  606. inspector->edit(variables);
  607. } else if (p_msg == "output") {
  608. //OUT
  609. for (int i = 0; i < p_data.size(); i++) {
  610. String t = p_data[i];
  611. //LOG
  612. if (!EditorNode::get_log()->is_visible()) {
  613. if (EditorNode::get_singleton()->are_bottom_panels_hidden()) {
  614. if (EDITOR_GET("run/output/always_open_output_on_play")) {
  615. EditorNode::get_singleton()->make_bottom_panel_item_visible(EditorNode::get_log());
  616. }
  617. }
  618. }
  619. EditorNode::get_log()->add_message(t);
  620. }
  621. } else if (p_msg == "performance") {
  622. Array arr = p_data[0];
  623. Vector<float> p;
  624. p.resize(arr.size());
  625. for (int i = 0; i < arr.size(); i++) {
  626. p.write[i] = arr[i];
  627. if (i < perf_items.size()) {
  628. float v = p[i];
  629. String vs = rtos(v);
  630. String tt = vs;
  631. switch (Performance::MonitorType((int)perf_items[i]->get_metadata(1))) {
  632. case Performance::MONITOR_TYPE_MEMORY: {
  633. vs = String::humanize_size(v);
  634. tt = vs;
  635. } break;
  636. case Performance::MONITOR_TYPE_TIME: {
  637. tt += " seconds";
  638. vs += " s";
  639. } break;
  640. default: {
  641. tt += " " + perf_items[i]->get_text(0);
  642. } break;
  643. }
  644. perf_items[i]->set_text(1, vs);
  645. perf_items[i]->set_tooltip(1, tt);
  646. if (p[i] > perf_max[i])
  647. perf_max.write[i] = p[i];
  648. }
  649. }
  650. perf_history.push_front(p);
  651. perf_draw->update();
  652. } else if (p_msg == "error") {
  653. // Should have at least two elements, error array and stack items count.
  654. ERR_FAIL_COND_MSG(p_data.size() < 2, "Malformed error message from script debugger.");
  655. // Error or warning data.
  656. Array err = p_data[0];
  657. ERR_FAIL_COND_MSG(err.size() < 10, "Malformed error message from script debugger.");
  658. // Format time.
  659. Array time_vals;
  660. time_vals.push_back(err[0]);
  661. time_vals.push_back(err[1]);
  662. time_vals.push_back(err[2]);
  663. time_vals.push_back(err[3]);
  664. bool e;
  665. String time = String("%d:%02d:%02d:%04d").sprintf(time_vals, &e);
  666. // Rest of the error data.
  667. String method = err[4];
  668. String source_file = err[5];
  669. String source_line = err[6];
  670. String error_cond = err[7];
  671. String error_msg = err[8];
  672. bool is_warning = err[9];
  673. bool has_method = !method.empty();
  674. bool has_error_msg = !error_msg.empty();
  675. bool source_is_project_file = source_file.begins_with("res://");
  676. // Metadata to highlight error line in scripts.
  677. Array source_meta;
  678. source_meta.push_back(source_file);
  679. source_meta.push_back(source_line);
  680. // Create error tree to display above error or warning details.
  681. TreeItem *r = error_tree->get_root();
  682. if (!r) {
  683. r = error_tree->create_item();
  684. }
  685. // Also provide the relevant details as tooltip to quickly check without
  686. // uncollapsing the tree.
  687. String tooltip = is_warning ? TTR("Warning:") : TTR("Error:");
  688. TreeItem *error = error_tree->create_item(r);
  689. error->set_collapsed(true);
  690. error->set_icon(0, get_icon(is_warning ? "Warning" : "Error", "EditorIcons"));
  691. error->set_text(0, time);
  692. error->set_text_align(0, TreeItem::ALIGN_LEFT);
  693. String error_title;
  694. // Include method name, when given, in error title.
  695. if (has_method)
  696. error_title += method + ": ";
  697. // If we have a (custom) error message, use it as title, and add a C++ Error
  698. // item with the original error condition.
  699. error_title += error_msg.empty() ? error_cond : error_msg;
  700. error->set_text(1, error_title);
  701. tooltip += " " + error_title + "\n";
  702. if (has_error_msg) {
  703. // Add item for C++ error condition.
  704. TreeItem *cpp_cond = error_tree->create_item(error);
  705. cpp_cond->set_text(0, "<" + TTR("C++ Error") + ">");
  706. cpp_cond->set_text(1, error_cond);
  707. cpp_cond->set_text_align(0, TreeItem::ALIGN_LEFT);
  708. tooltip += TTR("C++ Error:") + " " + error_cond + "\n";
  709. if (source_is_project_file)
  710. cpp_cond->set_metadata(0, source_meta);
  711. }
  712. // Source of the error.
  713. String source_txt = (source_is_project_file ? source_file.get_file() : source_file) + ":" + source_line;
  714. if (has_method)
  715. source_txt += " @ " + method + "()";
  716. TreeItem *cpp_source = error_tree->create_item(error);
  717. cpp_source->set_text(0, "<" + (source_is_project_file ? TTR("Source") : TTR("C++ Source")) + ">");
  718. cpp_source->set_text(1, source_txt);
  719. cpp_source->set_text_align(0, TreeItem::ALIGN_LEFT);
  720. tooltip += (source_is_project_file ? TTR("Source:") : TTR("C++ Source:")) + " " + source_txt + "\n";
  721. // Set metadata to highlight error line in scripts.
  722. if (source_is_project_file) {
  723. error->set_metadata(0, source_meta);
  724. cpp_source->set_metadata(0, source_meta);
  725. }
  726. error->set_tooltip(0, tooltip);
  727. error->set_tooltip(1, tooltip);
  728. // Format stack trace.
  729. // stack_items_count is the number of elements to parse, with 3 items per frame
  730. // of the stack trace (script, method, line).
  731. int stack_items_count = p_data[1];
  732. for (int i = 0; i < stack_items_count; i += 3) {
  733. String script = p_data[2 + i];
  734. String method2 = p_data[3 + i];
  735. int line = p_data[4 + i];
  736. TreeItem *stack_trace = error_tree->create_item(error);
  737. Array meta;
  738. meta.push_back(script);
  739. meta.push_back(line);
  740. stack_trace->set_metadata(0, meta);
  741. if (i == 0) {
  742. stack_trace->set_text(0, "<" + TTR("Stack Trace") + ">");
  743. stack_trace->set_text_align(0, TreeItem::ALIGN_LEFT);
  744. error->set_metadata(0, meta);
  745. }
  746. stack_trace->set_text(1, script.get_file() + ":" + itos(line) + " @ " + method2 + "()");
  747. }
  748. if (is_warning)
  749. warning_count++;
  750. else
  751. error_count++;
  752. } else if (p_msg == "profile_sig") {
  753. //cache a signature
  754. profiler_signature[p_data[1]] = p_data[0];
  755. } else if (p_msg == "profile_frame" || p_msg == "profile_total") {
  756. EditorProfiler::Metric metric;
  757. metric.valid = true;
  758. metric.frame_number = p_data[0];
  759. metric.frame_time = p_data[1];
  760. metric.idle_time = p_data[2];
  761. metric.physics_time = p_data[3];
  762. metric.physics_frame_time = p_data[4];
  763. int frame_data_amount = p_data[6];
  764. int frame_function_amount = p_data[7];
  765. if (frame_data_amount) {
  766. EditorProfiler::Metric::Category frame_time;
  767. frame_time.signature = "category_frame_time";
  768. frame_time.name = "Frame Time";
  769. frame_time.total_time = metric.frame_time;
  770. EditorProfiler::Metric::Category::Item item;
  771. item.calls = 1;
  772. item.line = 0;
  773. item.name = "Physics Time";
  774. item.total = metric.physics_time;
  775. item.self = item.total;
  776. item.signature = "physics_time";
  777. frame_time.items.push_back(item);
  778. item.name = "Idle Time";
  779. item.total = metric.idle_time;
  780. item.self = item.total;
  781. item.signature = "idle_time";
  782. frame_time.items.push_back(item);
  783. item.name = "Physics Frame Time";
  784. item.total = metric.physics_frame_time;
  785. item.self = item.total;
  786. item.signature = "physics_frame_time";
  787. frame_time.items.push_back(item);
  788. metric.categories.push_back(frame_time);
  789. }
  790. int idx = 8;
  791. for (int i = 0; i < frame_data_amount; i++) {
  792. EditorProfiler::Metric::Category c;
  793. String name = p_data[idx++];
  794. Array values = p_data[idx++];
  795. c.name = name.capitalize();
  796. c.items.resize(values.size() / 2);
  797. c.total_time = 0;
  798. c.signature = "categ::" + name;
  799. for (int j = 0; j < values.size(); j += 2) {
  800. EditorProfiler::Metric::Category::Item item;
  801. item.calls = 1;
  802. item.line = 0;
  803. item.name = values[j];
  804. item.self = values[j + 1];
  805. item.total = item.self;
  806. item.signature = "categ::" + name + "::" + item.name;
  807. item.name = item.name.capitalize();
  808. c.total_time += item.total;
  809. c.items.write[j / 2] = item;
  810. }
  811. metric.categories.push_back(c);
  812. }
  813. EditorProfiler::Metric::Category funcs;
  814. funcs.total_time = p_data[5]; //script time
  815. funcs.items.resize(frame_function_amount);
  816. funcs.name = "Script Functions";
  817. funcs.signature = "script_functions";
  818. for (int i = 0; i < frame_function_amount; i++) {
  819. int signature = p_data[idx++];
  820. int calls = p_data[idx++];
  821. float total = p_data[idx++];
  822. float self = p_data[idx++];
  823. EditorProfiler::Metric::Category::Item item;
  824. if (profiler_signature.has(signature)) {
  825. item.signature = profiler_signature[signature];
  826. String name = profiler_signature[signature];
  827. Vector<String> strings = name.split("::");
  828. if (strings.size() == 3) {
  829. item.name = strings[2];
  830. item.script = strings[0];
  831. item.line = strings[1].to_int();
  832. } else if (strings.size() == 4) { //Built-in scripts have an :: in their name
  833. item.name = strings[3];
  834. item.script = strings[0] + "::" + strings[1];
  835. item.line = strings[2].to_int();
  836. }
  837. } else {
  838. item.name = "SigErr " + itos(signature);
  839. }
  840. item.calls = calls;
  841. item.self = self;
  842. item.total = total;
  843. funcs.items.write[i] = item;
  844. }
  845. metric.categories.push_back(funcs);
  846. if (p_msg == "profile_frame")
  847. profiler->add_frame_metric(metric, false);
  848. else
  849. profiler->add_frame_metric(metric, true);
  850. } else if (p_msg == "network_profile") {
  851. int frame_size = 6;
  852. for (int i = 0; i < p_data.size(); i += frame_size) {
  853. MultiplayerAPI::ProfilingInfo pi;
  854. pi.node = p_data[i + 0];
  855. pi.node_path = p_data[i + 1];
  856. pi.incoming_rpc = p_data[i + 2];
  857. pi.incoming_rset = p_data[i + 3];
  858. pi.outgoing_rpc = p_data[i + 4];
  859. pi.outgoing_rset = p_data[i + 5];
  860. network_profiler->add_node_frame_data(pi);
  861. }
  862. } else if (p_msg == "network_bandwidth") {
  863. network_profiler->set_bandwidth(p_data[0], p_data[1]);
  864. } else if (p_msg == "kill_me") {
  865. editor->call_deferred("stop_child_process");
  866. }
  867. }
  868. void ScriptEditorDebugger::_set_reason_text(const String &p_reason, MessageType p_type) {
  869. switch (p_type) {
  870. case MESSAGE_ERROR:
  871. reason->add_color_override("font_color", get_color("error_color", "Editor"));
  872. break;
  873. case MESSAGE_WARNING:
  874. reason->add_color_override("font_color", get_color("warning_color", "Editor"));
  875. break;
  876. default:
  877. reason->add_color_override("font_color", get_color("success_color", "Editor"));
  878. }
  879. reason->set_text(p_reason);
  880. reason->set_tooltip(p_reason.word_wrap(80));
  881. }
  882. void ScriptEditorDebugger::_performance_select() {
  883. perf_draw->update();
  884. }
  885. void ScriptEditorDebugger::_performance_draw() {
  886. Vector<int> which;
  887. for (int i = 0; i < perf_items.size(); i++) {
  888. if (perf_items[i]->is_checked(0))
  889. which.push_back(i);
  890. }
  891. if (which.empty()) {
  892. info_message->show();
  893. return;
  894. }
  895. info_message->hide();
  896. Ref<StyleBox> graph_sb = get_stylebox("normal", "TextEdit");
  897. Ref<Font> graph_font = get_font("font", "TextEdit");
  898. int cols = Math::ceil(Math::sqrt((float)which.size()));
  899. int rows = Math::ceil((float)which.size() / cols);
  900. if (which.size() == 1)
  901. rows = 1;
  902. int margin = 3;
  903. int point_sep = 5;
  904. Size2i s = Size2i(perf_draw->get_size()) / Size2i(cols, rows);
  905. for (int i = 0; i < which.size(); i++) {
  906. Point2i p(i % cols, i / cols);
  907. Rect2i r(p * s, s);
  908. r.position += Point2(margin, margin);
  909. r.size -= Point2(margin, margin) * 2.0;
  910. perf_draw->draw_style_box(graph_sb, r);
  911. r.position += graph_sb->get_offset();
  912. r.size -= graph_sb->get_minimum_size();
  913. int pi = which[i];
  914. Color c = get_color("accent_color", "Editor");
  915. float h = (float)which[i] / (float)(perf_items.size());
  916. // Use a darker color on light backgrounds for better visibility
  917. float value_multiplier = EditorSettings::get_singleton()->is_dark_theme() ? 1.4 : 0.55;
  918. c.set_hsv(Math::fmod(h + 0.4, 0.9), c.get_s() * 0.9, c.get_v() * value_multiplier);
  919. c.a = 0.6;
  920. perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x);
  921. c.a = 0.9;
  922. perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent() + graph_font->get_height()), perf_items[pi]->get_text(1), c, r.size.y);
  923. float spacing = point_sep / float(cols);
  924. float from = r.size.width;
  925. List<Vector<float> >::Element *E = perf_history.front();
  926. float prev = -1;
  927. while (from >= 0 && E) {
  928. float m = perf_max[pi];
  929. if (m == 0)
  930. m = 0.00001;
  931. float h2 = E->get()[pi] / m;
  932. h2 = (1.0 - h2) * r.size.y;
  933. if (E != perf_history.front())
  934. perf_draw->draw_line(r.position + Point2(from, h2), r.position + Point2(from + spacing, prev), c, Math::round(EDSCALE), true);
  935. prev = h2;
  936. E = E->next();
  937. from -= spacing;
  938. }
  939. }
  940. }
  941. void ScriptEditorDebugger::_notification(int p_what) {
  942. switch (p_what) {
  943. case NOTIFICATION_ENTER_TREE: {
  944. inspector->edit(variables);
  945. skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOff", "EditorIcons"));
  946. copy->set_icon(get_icon("ActionCopy", "EditorIcons"));
  947. step->set_icon(get_icon("DebugStep", "EditorIcons"));
  948. next->set_icon(get_icon("DebugNext", "EditorIcons"));
  949. back->set_icon(get_icon("Back", "EditorIcons"));
  950. forward->set_icon(get_icon("Forward", "EditorIcons"));
  951. dobreak->set_icon(get_icon("Pause", "EditorIcons"));
  952. docontinue->set_icon(get_icon("DebugContinue", "EditorIcons"));
  953. le_set->connect("pressed", this, "_live_edit_set");
  954. le_clear->connect("pressed", this, "_live_edit_clear");
  955. error_tree->connect("item_selected", this, "_error_selected");
  956. error_tree->connect("item_activated", this, "_error_activated");
  957. vmem_refresh->set_icon(get_icon("Reload", "EditorIcons"));
  958. reason->add_color_override("font_color", get_color("error_color", "Editor"));
  959. } break;
  960. case NOTIFICATION_PROCESS: {
  961. if (connection.is_valid()) {
  962. inspect_scene_tree_timeout -= get_process_delta_time();
  963. if (inspect_scene_tree_timeout < 0) {
  964. inspect_scene_tree_timeout = EditorSettings::get_singleton()->get("debugger/remote_scene_tree_refresh_interval");
  965. if (inspect_scene_tree->is_visible_in_tree()) {
  966. _scene_tree_request();
  967. }
  968. }
  969. inspect_edited_object_timeout -= get_process_delta_time();
  970. if (inspect_edited_object_timeout < 0) {
  971. inspect_edited_object_timeout = EditorSettings::get_singleton()->get("debugger/remote_inspect_refresh_interval");
  972. if (inspected_object_id) {
  973. if (ScriptEditorDebuggerInspectedObject *obj = Object::cast_to<ScriptEditorDebuggerInspectedObject>(ObjectDB::get_instance(editor->get_editor_history()->get_current()))) {
  974. if (obj->remote_object_id == inspected_object_id) {
  975. //take the chance and re-inspect selected object
  976. Array msg;
  977. msg.push_back("inspect_object");
  978. msg.push_back(inspected_object_id);
  979. ppeer->put_var(msg);
  980. }
  981. }
  982. }
  983. }
  984. }
  985. if (error_count != last_error_count || warning_count != last_warning_count) {
  986. if (error_count == 0 && warning_count == 0) {
  987. errors_tab->set_name(TTR("Errors"));
  988. debugger_button->set_text(TTR("Debugger"));
  989. debugger_button->set_icon(Ref<Texture>());
  990. tabs->set_tab_icon(errors_tab->get_index(), Ref<Texture>());
  991. } else {
  992. errors_tab->set_name(TTR("Errors") + " (" + itos(error_count + warning_count) + ")");
  993. debugger_button->set_text(TTR("Debugger") + " (" + itos(error_count + warning_count) + ")");
  994. if (error_count == 0) {
  995. debugger_button->set_icon(get_icon("Warning", "EditorIcons"));
  996. tabs->set_tab_icon(errors_tab->get_index(), get_icon("Warning", "EditorIcons"));
  997. } else {
  998. debugger_button->set_icon(get_icon("Error", "EditorIcons"));
  999. tabs->set_tab_icon(errors_tab->get_index(), get_icon("Error", "EditorIcons"));
  1000. }
  1001. }
  1002. last_error_count = error_count;
  1003. last_warning_count = warning_count;
  1004. }
  1005. if (server->is_connection_available()) {
  1006. if (connection.is_valid()) {
  1007. // We already have a valid connection. Disconnecting any new connecting client to prevent it from hanging.
  1008. // (If we don't keep a reference to the connection it will be destroyed and disconnect_from_host will be called internally)
  1009. server->take_connection();
  1010. } else {
  1011. // We just got the first connection.
  1012. connection = server->take_connection();
  1013. if (connection.is_null())
  1014. break;
  1015. EditorNode::get_log()->add_message("--- Debugging process started ---", EditorLog::MSG_TYPE_EDITOR);
  1016. ppeer->set_stream_peer(connection);
  1017. //EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  1018. //emit_signal("show_debugger",true);
  1019. dobreak->set_disabled(false);
  1020. tabs->set_current_tab(0);
  1021. _set_reason_text(TTR("Child process connected."), MESSAGE_SUCCESS);
  1022. profiler->clear();
  1023. inspect_scene_tree->clear();
  1024. le_set->set_disabled(true);
  1025. le_clear->set_disabled(false);
  1026. error_tree->clear();
  1027. error_count = 0;
  1028. warning_count = 0;
  1029. profiler_signature.clear();
  1030. //live_edit_root->set_text("/root");
  1031. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  1032. EditorNode::get_singleton()->get_pause_button()->set_disabled(false);
  1033. update_live_edit_root();
  1034. if (profiler->is_profiling()) {
  1035. _profiler_activate(true);
  1036. }
  1037. if (network_profiler->is_profiling()) {
  1038. _network_profiler_activate(true);
  1039. }
  1040. }
  1041. }
  1042. if (connection.is_null())
  1043. break;
  1044. if (!connection->is_connected_to_host()) {
  1045. stop();
  1046. editor->notify_child_process_exited(); //somehow, exited
  1047. break;
  1048. };
  1049. if (ppeer->get_available_packet_count() <= 0) {
  1050. break;
  1051. };
  1052. const uint64_t until = OS::get_singleton()->get_ticks_msec() + 20;
  1053. while (ppeer->get_available_packet_count() > 0) {
  1054. if (pending_in_queue) {
  1055. int todo = MIN(ppeer->get_available_packet_count(), pending_in_queue);
  1056. for (int i = 0; i < todo; i++) {
  1057. Variant cmd;
  1058. Error ret = ppeer->get_var(cmd);
  1059. if (ret != OK) {
  1060. stop();
  1061. ERR_FAIL_COND(ret != OK);
  1062. }
  1063. message.push_back(cmd);
  1064. pending_in_queue--;
  1065. }
  1066. if (pending_in_queue == 0) {
  1067. _parse_message(message_type, message);
  1068. message.clear();
  1069. }
  1070. } else {
  1071. if (ppeer->get_available_packet_count() >= 2) {
  1072. Variant cmd;
  1073. Error ret = ppeer->get_var(cmd);
  1074. if (ret != OK) {
  1075. stop();
  1076. ERR_FAIL_COND(ret != OK);
  1077. }
  1078. if (cmd.get_type() != Variant::STRING) {
  1079. stop();
  1080. ERR_FAIL_COND(cmd.get_type() != Variant::STRING);
  1081. }
  1082. message_type = cmd;
  1083. ret = ppeer->get_var(cmd);
  1084. if (ret != OK) {
  1085. stop();
  1086. ERR_FAIL_COND(ret != OK);
  1087. }
  1088. if (cmd.get_type() != Variant::INT) {
  1089. stop();
  1090. ERR_FAIL_COND(cmd.get_type() != Variant::INT);
  1091. }
  1092. pending_in_queue = cmd;
  1093. if (pending_in_queue == 0) {
  1094. _parse_message(message_type, Array());
  1095. message.clear();
  1096. }
  1097. } else {
  1098. break;
  1099. }
  1100. }
  1101. if (OS::get_singleton()->get_ticks_msec() > until)
  1102. break;
  1103. }
  1104. } break;
  1105. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  1106. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  1107. tabs->add_style_override("tab_fg", editor->get_gui_base()->get_stylebox("DebuggerTabFG", "EditorStyles"));
  1108. tabs->add_style_override("tab_bg", editor->get_gui_base()->get_stylebox("DebuggerTabBG", "EditorStyles"));
  1109. tabs->set_margin(MARGIN_LEFT, -EditorNode::get_singleton()->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT));
  1110. tabs->set_margin(MARGIN_RIGHT, EditorNode::get_singleton()->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_RIGHT));
  1111. copy->set_icon(get_icon("ActionCopy", "EditorIcons"));
  1112. step->set_icon(get_icon("DebugStep", "EditorIcons"));
  1113. next->set_icon(get_icon("DebugNext", "EditorIcons"));
  1114. back->set_icon(get_icon("Back", "EditorIcons"));
  1115. forward->set_icon(get_icon("Forward", "EditorIcons"));
  1116. dobreak->set_icon(get_icon("Pause", "EditorIcons"));
  1117. docontinue->set_icon(get_icon("DebugContinue", "EditorIcons"));
  1118. vmem_refresh->set_icon(get_icon("Reload", "EditorIcons"));
  1119. } break;
  1120. }
  1121. }
  1122. void ScriptEditorDebugger::_clear_execution() {
  1123. TreeItem *ti = stack_dump->get_selected();
  1124. if (!ti)
  1125. return;
  1126. Dictionary d = ti->get_metadata(0);
  1127. stack_script = ResourceLoader::load(d["file"]);
  1128. emit_signal("clear_execution", stack_script);
  1129. stack_script.unref();
  1130. }
  1131. void ScriptEditorDebugger::start() {
  1132. stop();
  1133. if (is_visible_in_tree()) {
  1134. EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  1135. }
  1136. perf_history.clear();
  1137. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  1138. perf_max.write[i] = 0;
  1139. }
  1140. int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
  1141. if (server->listen(remote_port) != OK) {
  1142. EditorNode::get_log()->add_message(String("Error listening on port ") + itos(remote_port), EditorLog::MSG_TYPE_ERROR);
  1143. return;
  1144. }
  1145. EditorNode::get_singleton()->get_scene_tree_dock()->show_tab_buttons();
  1146. auto_switch_remote_scene_tree = (bool)EditorSettings::get_singleton()->get("debugger/auto_switch_to_remote_scene_tree");
  1147. if (auto_switch_remote_scene_tree) {
  1148. EditorNode::get_singleton()->get_scene_tree_dock()->show_remote_tree();
  1149. }
  1150. set_process(true);
  1151. breaked = false;
  1152. }
  1153. void ScriptEditorDebugger::pause() {
  1154. }
  1155. void ScriptEditorDebugger::unpause() {
  1156. }
  1157. void ScriptEditorDebugger::stop() {
  1158. set_process(false);
  1159. breaked = false;
  1160. _clear_execution();
  1161. server->stop();
  1162. _clear_remote_objects();
  1163. ppeer->set_stream_peer(Ref<StreamPeer>());
  1164. if (connection.is_valid()) {
  1165. EditorNode::get_log()->add_message("--- Debugging process stopped ---", EditorLog::MSG_TYPE_EDITOR);
  1166. connection.unref();
  1167. reason->set_text("");
  1168. reason->set_tooltip("");
  1169. }
  1170. pending_in_queue = 0;
  1171. message.clear();
  1172. node_path_cache.clear();
  1173. res_path_cache.clear();
  1174. profiler_signature.clear();
  1175. le_clear->set_disabled(false);
  1176. le_set->set_disabled(true);
  1177. profiler->set_enabled(true);
  1178. inspect_scene_tree->clear();
  1179. inspector->edit(NULL);
  1180. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  1181. EditorNode::get_singleton()->get_pause_button()->set_disabled(true);
  1182. EditorNode::get_singleton()->get_scene_tree_dock()->hide_remote_tree();
  1183. EditorNode::get_singleton()->get_scene_tree_dock()->hide_tab_buttons();
  1184. if (hide_on_stop) {
  1185. if (is_visible_in_tree())
  1186. EditorNode::get_singleton()->hide_bottom_panel();
  1187. emit_signal("show_debugger", false);
  1188. }
  1189. }
  1190. void ScriptEditorDebugger::_profiler_activate(bool p_enable) {
  1191. if (!connection.is_valid())
  1192. return;
  1193. if (p_enable) {
  1194. profiler_signature.clear();
  1195. Array msg;
  1196. msg.push_back("start_profiling");
  1197. int max_funcs = EditorSettings::get_singleton()->get("debugger/profiler_frame_max_functions");
  1198. max_funcs = CLAMP(max_funcs, 16, 512);
  1199. msg.push_back(max_funcs);
  1200. ppeer->put_var(msg);
  1201. print_verbose("Starting profiling.");
  1202. } else {
  1203. Array msg;
  1204. msg.push_back("stop_profiling");
  1205. ppeer->put_var(msg);
  1206. print_verbose("Ending profiling.");
  1207. }
  1208. }
  1209. void ScriptEditorDebugger::_network_profiler_activate(bool p_enable) {
  1210. if (!connection.is_valid())
  1211. return;
  1212. if (p_enable) {
  1213. Array msg;
  1214. msg.push_back("start_network_profiling");
  1215. ppeer->put_var(msg);
  1216. print_verbose("Starting network profiling.");
  1217. } else {
  1218. Array msg;
  1219. msg.push_back("stop_network_profiling");
  1220. ppeer->put_var(msg);
  1221. print_verbose("Ending network profiling.");
  1222. }
  1223. }
  1224. void ScriptEditorDebugger::_profiler_seeked() {
  1225. if (!connection.is_valid() || !connection->is_connected_to_host())
  1226. return;
  1227. if (breaked)
  1228. return;
  1229. debug_break();
  1230. }
  1231. void ScriptEditorDebugger::_stack_dump_frame_selected() {
  1232. TreeItem *ti = stack_dump->get_selected();
  1233. if (!ti)
  1234. return;
  1235. Dictionary d = ti->get_metadata(0);
  1236. stack_script = ResourceLoader::load(d["file"]);
  1237. emit_signal("goto_script_line", stack_script, int(d["line"]) - 1);
  1238. emit_signal("set_execution", stack_script, int(d["line"]) - 1);
  1239. stack_script.unref();
  1240. if (connection.is_valid() && connection->is_connected_to_host()) {
  1241. Array msg;
  1242. msg.push_back("get_stack_frame_vars");
  1243. msg.push_back(d["frame"]);
  1244. ppeer->put_var(msg);
  1245. } else {
  1246. inspector->edit(NULL);
  1247. }
  1248. }
  1249. void ScriptEditorDebugger::_output_clear() {
  1250. //output->clear();
  1251. //output->push_color(Color(0,0,0));
  1252. }
  1253. void ScriptEditorDebugger::_export_csv() {
  1254. file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  1255. file_dialog_mode = SAVE_CSV;
  1256. file_dialog->popup_centered_ratio();
  1257. }
  1258. String ScriptEditorDebugger::get_var_value(const String &p_var) const {
  1259. if (!breaked)
  1260. return String();
  1261. return variables->get_var_value(p_var);
  1262. }
  1263. int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) {
  1264. const int *r = node_path_cache.getptr(p_path);
  1265. if (r)
  1266. return *r;
  1267. last_path_id++;
  1268. node_path_cache[p_path] = last_path_id;
  1269. Array msg;
  1270. msg.push_back("live_node_path");
  1271. msg.push_back(p_path);
  1272. msg.push_back(last_path_id);
  1273. ppeer->put_var(msg);
  1274. return last_path_id;
  1275. }
  1276. int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) {
  1277. Map<String, int>::Element *E = res_path_cache.find(p_path);
  1278. if (E)
  1279. return E->get();
  1280. last_path_id++;
  1281. res_path_cache[p_path] = last_path_id;
  1282. Array msg;
  1283. msg.push_back("live_res_path");
  1284. msg.push_back(p_path);
  1285. msg.push_back(last_path_id);
  1286. ppeer->put_var(msg);
  1287. return last_path_id;
  1288. }
  1289. void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
  1290. if (!p_base || !live_debug || !connection.is_valid() || !editor->get_edited_scene())
  1291. return;
  1292. Node *node = Object::cast_to<Node>(p_base);
  1293. VARIANT_ARGPTRS
  1294. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  1295. //no pointers, sorry
  1296. if (argptr[i] && (argptr[i]->get_type() == Variant::OBJECT || argptr[i]->get_type() == Variant::_RID))
  1297. return;
  1298. }
  1299. if (node) {
  1300. NodePath path = editor->get_edited_scene()->get_path_to(node);
  1301. int pathid = _get_node_path_cache(path);
  1302. Array msg;
  1303. msg.push_back("live_node_call");
  1304. msg.push_back(pathid);
  1305. msg.push_back(p_name);
  1306. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  1307. //no pointers, sorry
  1308. msg.push_back(*argptr[i]);
  1309. }
  1310. ppeer->put_var(msg);
  1311. return;
  1312. }
  1313. Resource *res = Object::cast_to<Resource>(p_base);
  1314. if (res && res->get_path() != String()) {
  1315. String respath = res->get_path();
  1316. int pathid = _get_res_path_cache(respath);
  1317. Array msg;
  1318. msg.push_back("live_res_call");
  1319. msg.push_back(pathid);
  1320. msg.push_back(p_name);
  1321. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  1322. //no pointers, sorry
  1323. msg.push_back(*argptr[i]);
  1324. }
  1325. ppeer->put_var(msg);
  1326. return;
  1327. }
  1328. }
  1329. void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p_property, const Variant &p_value) {
  1330. if (!p_base || !live_debug || !connection.is_valid() || !editor->get_edited_scene())
  1331. return;
  1332. Node *node = Object::cast_to<Node>(p_base);
  1333. if (node) {
  1334. NodePath path = editor->get_edited_scene()->get_path_to(node);
  1335. int pathid = _get_node_path_cache(path);
  1336. if (p_value.is_ref()) {
  1337. Ref<Resource> res = p_value;
  1338. if (res.is_valid() && res->get_path() != String()) {
  1339. Array msg;
  1340. msg.push_back("live_node_prop_res");
  1341. msg.push_back(pathid);
  1342. msg.push_back(p_property);
  1343. msg.push_back(res->get_path());
  1344. ppeer->put_var(msg);
  1345. }
  1346. } else {
  1347. Array msg;
  1348. msg.push_back("live_node_prop");
  1349. msg.push_back(pathid);
  1350. msg.push_back(p_property);
  1351. msg.push_back(p_value);
  1352. ppeer->put_var(msg);
  1353. }
  1354. return;
  1355. }
  1356. Resource *res = Object::cast_to<Resource>(p_base);
  1357. if (res && res->get_path() != String()) {
  1358. String respath = res->get_path();
  1359. int pathid = _get_res_path_cache(respath);
  1360. if (p_value.is_ref()) {
  1361. Ref<Resource> res2 = p_value;
  1362. if (res2.is_valid() && res2->get_path() != String()) {
  1363. Array msg;
  1364. msg.push_back("live_res_prop_res");
  1365. msg.push_back(pathid);
  1366. msg.push_back(p_property);
  1367. msg.push_back(res2->get_path());
  1368. ppeer->put_var(msg);
  1369. }
  1370. } else {
  1371. Array msg;
  1372. msg.push_back("live_res_prop");
  1373. msg.push_back(pathid);
  1374. msg.push_back(p_property);
  1375. msg.push_back(p_value);
  1376. ppeer->put_var(msg);
  1377. }
  1378. return;
  1379. }
  1380. }
  1381. void ScriptEditorDebugger::_method_changeds(void *p_ud, Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
  1382. ScriptEditorDebugger *sed = (ScriptEditorDebugger *)p_ud;
  1383. sed->_method_changed(p_base, p_name, VARIANT_ARG_PASS);
  1384. }
  1385. void ScriptEditorDebugger::_property_changeds(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value) {
  1386. ScriptEditorDebugger *sed = (ScriptEditorDebugger *)p_ud;
  1387. sed->_property_changed(p_base, p_property, p_value);
  1388. }
  1389. void ScriptEditorDebugger::set_live_debugging(bool p_enable) {
  1390. live_debug = p_enable;
  1391. }
  1392. void ScriptEditorDebugger::_live_edit_set() {
  1393. if (!connection.is_valid())
  1394. return;
  1395. TreeItem *ti = inspect_scene_tree->get_selected();
  1396. if (!ti)
  1397. return;
  1398. String path;
  1399. while (ti) {
  1400. String lp = ti->get_text(0);
  1401. path = "/" + lp + path;
  1402. ti = ti->get_parent();
  1403. }
  1404. NodePath np = path;
  1405. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  1406. update_live_edit_root();
  1407. }
  1408. void ScriptEditorDebugger::_live_edit_clear() {
  1409. NodePath np = NodePath("/root");
  1410. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  1411. update_live_edit_root();
  1412. }
  1413. void ScriptEditorDebugger::update_live_edit_root() {
  1414. NodePath np = editor->get_editor_data().get_edited_scene_live_edit_root();
  1415. if (connection.is_valid()) {
  1416. Array msg;
  1417. msg.push_back("live_set_root");
  1418. msg.push_back(np);
  1419. if (editor->get_edited_scene())
  1420. msg.push_back(editor->get_edited_scene()->get_filename());
  1421. else
  1422. msg.push_back("");
  1423. ppeer->put_var(msg);
  1424. }
  1425. live_edit_root->set_text(np);
  1426. }
  1427. void ScriptEditorDebugger::live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name) {
  1428. if (live_debug && connection.is_valid()) {
  1429. Array msg;
  1430. msg.push_back("live_create_node");
  1431. msg.push_back(p_parent);
  1432. msg.push_back(p_type);
  1433. msg.push_back(p_name);
  1434. ppeer->put_var(msg);
  1435. }
  1436. }
  1437. void ScriptEditorDebugger::live_debug_instance_node(const NodePath &p_parent, const String &p_path, const String &p_name) {
  1438. if (live_debug && connection.is_valid()) {
  1439. Array msg;
  1440. msg.push_back("live_instance_node");
  1441. msg.push_back(p_parent);
  1442. msg.push_back(p_path);
  1443. msg.push_back(p_name);
  1444. ppeer->put_var(msg);
  1445. }
  1446. }
  1447. void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) {
  1448. if (live_debug && connection.is_valid()) {
  1449. Array msg;
  1450. msg.push_back("live_remove_node");
  1451. msg.push_back(p_at);
  1452. ppeer->put_var(msg);
  1453. }
  1454. }
  1455. void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) {
  1456. if (live_debug && connection.is_valid()) {
  1457. Array msg;
  1458. msg.push_back("live_remove_and_keep_node");
  1459. msg.push_back(p_at);
  1460. msg.push_back(p_keep_id);
  1461. ppeer->put_var(msg);
  1462. }
  1463. }
  1464. void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) {
  1465. if (live_debug && connection.is_valid()) {
  1466. Array msg;
  1467. msg.push_back("live_restore_node");
  1468. msg.push_back(p_id);
  1469. msg.push_back(p_at);
  1470. msg.push_back(p_at_pos);
  1471. ppeer->put_var(msg);
  1472. }
  1473. }
  1474. void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) {
  1475. if (live_debug && connection.is_valid()) {
  1476. Array msg;
  1477. msg.push_back("live_duplicate_node");
  1478. msg.push_back(p_at);
  1479. msg.push_back(p_new_name);
  1480. ppeer->put_var(msg);
  1481. }
  1482. }
  1483. void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) {
  1484. if (live_debug && connection.is_valid()) {
  1485. Array msg;
  1486. msg.push_back("live_reparent_node");
  1487. msg.push_back(p_at);
  1488. msg.push_back(p_new_place);
  1489. msg.push_back(p_new_name);
  1490. msg.push_back(p_at_pos);
  1491. ppeer->put_var(msg);
  1492. }
  1493. }
  1494. void ScriptEditorDebugger::set_breakpoint(const String &p_path, int p_line, bool p_enabled) {
  1495. if (connection.is_valid()) {
  1496. Array msg;
  1497. msg.push_back("breakpoint");
  1498. msg.push_back(p_path);
  1499. msg.push_back(p_line);
  1500. msg.push_back(p_enabled);
  1501. ppeer->put_var(msg);
  1502. }
  1503. }
  1504. void ScriptEditorDebugger::reload_scripts() {
  1505. if (connection.is_valid()) {
  1506. Array msg;
  1507. msg.push_back("reload_scripts");
  1508. ppeer->put_var(msg);
  1509. }
  1510. }
  1511. bool ScriptEditorDebugger::is_skip_breakpoints() {
  1512. return skip_breakpoints_value;
  1513. }
  1514. void ScriptEditorDebugger::_error_activated() {
  1515. TreeItem *selected = error_tree->get_selected();
  1516. TreeItem *ci = selected->get_children();
  1517. if (ci) {
  1518. selected->set_collapsed(!selected->is_collapsed());
  1519. }
  1520. }
  1521. void ScriptEditorDebugger::_error_selected() {
  1522. TreeItem *selected = error_tree->get_selected();
  1523. Array meta = selected->get_metadata(0);
  1524. if (meta.size() == 0) {
  1525. return;
  1526. }
  1527. Ref<Script> s = ResourceLoader::load(meta[0]);
  1528. emit_signal("goto_script_line", s, int(meta[1]) - 1);
  1529. }
  1530. void ScriptEditorDebugger::_expand_errors_list() {
  1531. TreeItem *root = error_tree->get_root();
  1532. if (!root)
  1533. return;
  1534. TreeItem *item = root->get_children();
  1535. while (item) {
  1536. item->set_collapsed(false);
  1537. item = item->get_next();
  1538. }
  1539. }
  1540. void ScriptEditorDebugger::_collapse_errors_list() {
  1541. TreeItem *root = error_tree->get_root();
  1542. if (!root)
  1543. return;
  1544. TreeItem *item = root->get_children();
  1545. while (item) {
  1546. item->set_collapsed(true);
  1547. item = item->get_next();
  1548. }
  1549. }
  1550. void ScriptEditorDebugger::set_hide_on_stop(bool p_hide) {
  1551. hide_on_stop = p_hide;
  1552. }
  1553. bool ScriptEditorDebugger::get_debug_with_external_editor() const {
  1554. return enable_external_editor;
  1555. }
  1556. void ScriptEditorDebugger::set_debug_with_external_editor(bool p_enabled) {
  1557. enable_external_editor = p_enabled;
  1558. }
  1559. Ref<Script> ScriptEditorDebugger::get_dump_stack_script() const {
  1560. return stack_script;
  1561. }
  1562. void ScriptEditorDebugger::_paused() {
  1563. ERR_FAIL_COND(connection.is_null());
  1564. ERR_FAIL_COND(!connection->is_connected_to_host());
  1565. if (!breaked && EditorNode::get_singleton()->get_pause_button()->is_pressed()) {
  1566. debug_break();
  1567. }
  1568. if (breaked && !EditorNode::get_singleton()->get_pause_button()->is_pressed()) {
  1569. debug_continue();
  1570. }
  1571. }
  1572. void ScriptEditorDebugger::_set_remote_object(ObjectID p_id, ScriptEditorDebuggerInspectedObject *p_obj) {
  1573. if (remote_objects.has(p_id))
  1574. memdelete(remote_objects[p_id]);
  1575. remote_objects[p_id] = p_obj;
  1576. }
  1577. void ScriptEditorDebugger::_clear_remote_objects() {
  1578. for (Map<ObjectID, ScriptEditorDebuggerInspectedObject *>::Element *E = remote_objects.front(); E; E = E->next()) {
  1579. if (editor->get_editor_history()->get_current() == E->value()->get_instance_id()) {
  1580. editor->push_item(NULL);
  1581. }
  1582. memdelete(E->value());
  1583. }
  1584. remote_objects.clear();
  1585. }
  1586. void ScriptEditorDebugger::_clear_errors_list() {
  1587. error_tree->clear();
  1588. error_count = 0;
  1589. warning_count = 0;
  1590. _notification(NOTIFICATION_PROCESS);
  1591. }
  1592. // Right click on specific file(s) or folder(s).
  1593. void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos) {
  1594. item_menu->clear();
  1595. item_menu->set_size(Size2(1, 1));
  1596. if (error_tree->is_anything_selected()) {
  1597. item_menu->add_icon_item(get_icon("ActionCopy", "EditorIcons"), TTR("Copy Error"), ITEM_MENU_COPY_ERROR);
  1598. }
  1599. if (item_menu->get_item_count() > 0) {
  1600. item_menu->set_position(error_tree->get_global_position() + p_pos);
  1601. item_menu->popup();
  1602. }
  1603. }
  1604. void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) {
  1605. switch (p_option) {
  1606. case ITEM_MENU_COPY_ERROR: {
  1607. TreeItem *ti = error_tree->get_selected();
  1608. while (ti->get_parent() != error_tree->get_root())
  1609. ti = ti->get_parent();
  1610. String type;
  1611. if (ti->get_icon(0) == get_icon("Warning", "EditorIcons")) {
  1612. type = "W ";
  1613. } else if (ti->get_icon(0) == get_icon("Error", "EditorIcons")) {
  1614. type = "E ";
  1615. }
  1616. String text = ti->get_text(0) + " ";
  1617. int rpad_len = text.length();
  1618. text = type + text + ti->get_text(1) + "\n";
  1619. TreeItem *ci = ti->get_children();
  1620. while (ci) {
  1621. text += " " + ci->get_text(0).rpad(rpad_len) + ci->get_text(1) + "\n";
  1622. ci = ci->get_next();
  1623. }
  1624. OS::get_singleton()->set_clipboard(text);
  1625. } break;
  1626. case ITEM_MENU_SAVE_REMOTE_NODE: {
  1627. file_dialog->set_access(EditorFileDialog::ACCESS_RESOURCES);
  1628. file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  1629. file_dialog_mode = SAVE_NODE;
  1630. List<String> extensions;
  1631. Ref<PackedScene> sd = memnew(PackedScene);
  1632. ResourceSaver::get_recognized_extensions(sd, &extensions);
  1633. file_dialog->clear_filters();
  1634. for (int i = 0; i < extensions.size(); i++) {
  1635. file_dialog->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
  1636. }
  1637. file_dialog->popup_centered_ratio();
  1638. } break;
  1639. case ITEM_MENU_COPY_NODE_PATH: {
  1640. TreeItem *ti = inspect_scene_tree->get_selected();
  1641. String text = ti->get_text(0);
  1642. if (ti->get_parent() == NULL) {
  1643. text = ".";
  1644. } else if (ti->get_parent()->get_parent() == NULL) {
  1645. text = ".";
  1646. } else {
  1647. while (ti->get_parent()->get_parent() != inspect_scene_tree->get_root()) {
  1648. ti = ti->get_parent();
  1649. text = ti->get_text(0) + "/" + text;
  1650. }
  1651. }
  1652. OS::get_singleton()->set_clipboard(text);
  1653. } break;
  1654. }
  1655. }
  1656. void ScriptEditorDebugger::_bind_methods() {
  1657. ClassDB::bind_method(D_METHOD("_stack_dump_frame_selected"), &ScriptEditorDebugger::_stack_dump_frame_selected);
  1658. ClassDB::bind_method(D_METHOD("debug_skip_breakpoints"), &ScriptEditorDebugger::debug_skip_breakpoints);
  1659. ClassDB::bind_method(D_METHOD("debug_copy"), &ScriptEditorDebugger::debug_copy);
  1660. ClassDB::bind_method(D_METHOD("debug_next"), &ScriptEditorDebugger::debug_next);
  1661. ClassDB::bind_method(D_METHOD("debug_step"), &ScriptEditorDebugger::debug_step);
  1662. ClassDB::bind_method(D_METHOD("debug_break"), &ScriptEditorDebugger::debug_break);
  1663. ClassDB::bind_method(D_METHOD("debug_continue"), &ScriptEditorDebugger::debug_continue);
  1664. ClassDB::bind_method(D_METHOD("_output_clear"), &ScriptEditorDebugger::_output_clear);
  1665. ClassDB::bind_method(D_METHOD("_export_csv"), &ScriptEditorDebugger::_export_csv);
  1666. ClassDB::bind_method(D_METHOD("_performance_draw"), &ScriptEditorDebugger::_performance_draw);
  1667. ClassDB::bind_method(D_METHOD("_performance_select"), &ScriptEditorDebugger::_performance_select);
  1668. ClassDB::bind_method(D_METHOD("_scene_tree_request"), &ScriptEditorDebugger::_scene_tree_request);
  1669. ClassDB::bind_method(D_METHOD("_video_mem_request"), &ScriptEditorDebugger::_video_mem_request);
  1670. ClassDB::bind_method(D_METHOD("_live_edit_set"), &ScriptEditorDebugger::_live_edit_set);
  1671. ClassDB::bind_method(D_METHOD("_live_edit_clear"), &ScriptEditorDebugger::_live_edit_clear);
  1672. ClassDB::bind_method(D_METHOD("_error_selected"), &ScriptEditorDebugger::_error_selected);
  1673. ClassDB::bind_method(D_METHOD("_error_activated"), &ScriptEditorDebugger::_error_activated);
  1674. ClassDB::bind_method(D_METHOD("_expand_errors_list"), &ScriptEditorDebugger::_expand_errors_list);
  1675. ClassDB::bind_method(D_METHOD("_collapse_errors_list"), &ScriptEditorDebugger::_collapse_errors_list);
  1676. ClassDB::bind_method(D_METHOD("_profiler_activate"), &ScriptEditorDebugger::_profiler_activate);
  1677. ClassDB::bind_method(D_METHOD("_network_profiler_activate"), &ScriptEditorDebugger::_network_profiler_activate);
  1678. ClassDB::bind_method(D_METHOD("_profiler_seeked"), &ScriptEditorDebugger::_profiler_seeked);
  1679. ClassDB::bind_method(D_METHOD("_clear_errors_list"), &ScriptEditorDebugger::_clear_errors_list);
  1680. ClassDB::bind_method(D_METHOD("_error_tree_item_rmb_selected"), &ScriptEditorDebugger::_error_tree_item_rmb_selected);
  1681. ClassDB::bind_method(D_METHOD("_item_menu_id_pressed"), &ScriptEditorDebugger::_item_menu_id_pressed);
  1682. ClassDB::bind_method(D_METHOD("_paused"), &ScriptEditorDebugger::_paused);
  1683. ClassDB::bind_method(D_METHOD("_scene_tree_selected"), &ScriptEditorDebugger::_scene_tree_selected);
  1684. ClassDB::bind_method(D_METHOD("_scene_tree_folded"), &ScriptEditorDebugger::_scene_tree_folded);
  1685. ClassDB::bind_method(D_METHOD("_scene_tree_rmb_selected"), &ScriptEditorDebugger::_scene_tree_rmb_selected);
  1686. ClassDB::bind_method(D_METHOD("_file_selected"), &ScriptEditorDebugger::_file_selected);
  1687. ClassDB::bind_method(D_METHOD("live_debug_create_node"), &ScriptEditorDebugger::live_debug_create_node);
  1688. ClassDB::bind_method(D_METHOD("live_debug_instance_node"), &ScriptEditorDebugger::live_debug_instance_node);
  1689. ClassDB::bind_method(D_METHOD("live_debug_remove_node"), &ScriptEditorDebugger::live_debug_remove_node);
  1690. ClassDB::bind_method(D_METHOD("live_debug_remove_and_keep_node"), &ScriptEditorDebugger::live_debug_remove_and_keep_node);
  1691. ClassDB::bind_method(D_METHOD("live_debug_restore_node"), &ScriptEditorDebugger::live_debug_restore_node);
  1692. ClassDB::bind_method(D_METHOD("live_debug_duplicate_node"), &ScriptEditorDebugger::live_debug_duplicate_node);
  1693. ClassDB::bind_method(D_METHOD("live_debug_reparent_node"), &ScriptEditorDebugger::live_debug_reparent_node);
  1694. ClassDB::bind_method(D_METHOD("_scene_tree_property_select_object"), &ScriptEditorDebugger::_scene_tree_property_select_object);
  1695. ClassDB::bind_method(D_METHOD("_scene_tree_property_value_edited"), &ScriptEditorDebugger::_scene_tree_property_value_edited);
  1696. ADD_SIGNAL(MethodInfo("goto_script_line"));
  1697. ADD_SIGNAL(MethodInfo("set_execution", PropertyInfo("script"), PropertyInfo(Variant::INT, "line")));
  1698. ADD_SIGNAL(MethodInfo("clear_execution", PropertyInfo("script")));
  1699. ADD_SIGNAL(MethodInfo("breaked", PropertyInfo(Variant::BOOL, "reallydid"), PropertyInfo(Variant::BOOL, "can_debug")));
  1700. ADD_SIGNAL(MethodInfo("show_debugger", PropertyInfo(Variant::BOOL, "reallydid")));
  1701. }
  1702. ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
  1703. ppeer = Ref<PacketPeerStream>(memnew(PacketPeerStream));
  1704. ppeer->set_input_buffer_max_size(1024 * 1024 * 8); //8mb should be enough
  1705. editor = p_editor;
  1706. editor->get_inspector()->connect("object_id_selected", this, "_scene_tree_property_select_object");
  1707. tabs = memnew(TabContainer);
  1708. tabs->set_tab_align(TabContainer::ALIGN_LEFT);
  1709. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  1710. tabs->add_style_override("tab_fg", editor->get_gui_base()->get_stylebox("DebuggerTabFG", "EditorStyles"));
  1711. tabs->add_style_override("tab_bg", editor->get_gui_base()->get_stylebox("DebuggerTabBG", "EditorStyles"));
  1712. tabs->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  1713. tabs->set_margin(MARGIN_LEFT, -editor->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT));
  1714. tabs->set_margin(MARGIN_RIGHT, editor->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_RIGHT));
  1715. add_child(tabs);
  1716. { //debugger
  1717. VBoxContainer *vbc = memnew(VBoxContainer);
  1718. vbc->set_name(TTR("Debugger"));
  1719. //tabs->add_child(vbc);
  1720. Control *dbg = vbc;
  1721. HBoxContainer *hbc = memnew(HBoxContainer);
  1722. vbc->add_child(hbc);
  1723. reason = memnew(Label);
  1724. reason->set_text("");
  1725. hbc->add_child(reason);
  1726. reason->set_h_size_flags(SIZE_EXPAND_FILL);
  1727. reason->set_autowrap(true);
  1728. reason->set_max_lines_visible(3);
  1729. reason->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  1730. hbc->add_child(memnew(VSeparator));
  1731. skip_breakpoints = memnew(ToolButton);
  1732. hbc->add_child(skip_breakpoints);
  1733. skip_breakpoints->set_tooltip(TTR("Skip Breakpoints"));
  1734. skip_breakpoints->connect("pressed", this, "debug_skip_breakpoints");
  1735. hbc->add_child(memnew(VSeparator));
  1736. copy = memnew(ToolButton);
  1737. hbc->add_child(copy);
  1738. copy->set_tooltip(TTR("Copy Error"));
  1739. copy->connect("pressed", this, "debug_copy");
  1740. hbc->add_child(memnew(VSeparator));
  1741. step = memnew(ToolButton);
  1742. hbc->add_child(step);
  1743. step->set_tooltip(TTR("Step Into"));
  1744. step->set_shortcut(ED_GET_SHORTCUT("debugger/step_into"));
  1745. step->connect("pressed", this, "debug_step");
  1746. next = memnew(ToolButton);
  1747. hbc->add_child(next);
  1748. next->set_tooltip(TTR("Step Over"));
  1749. next->set_shortcut(ED_GET_SHORTCUT("debugger/step_over"));
  1750. next->connect("pressed", this, "debug_next");
  1751. hbc->add_child(memnew(VSeparator));
  1752. dobreak = memnew(ToolButton);
  1753. hbc->add_child(dobreak);
  1754. dobreak->set_tooltip(TTR("Break"));
  1755. dobreak->set_shortcut(ED_GET_SHORTCUT("debugger/break"));
  1756. dobreak->connect("pressed", this, "debug_break");
  1757. docontinue = memnew(ToolButton);
  1758. hbc->add_child(docontinue);
  1759. docontinue->set_tooltip(TTR("Continue"));
  1760. docontinue->set_shortcut(ED_GET_SHORTCUT("debugger/continue"));
  1761. docontinue->connect("pressed", this, "debug_continue");
  1762. back = memnew(Button);
  1763. hbc->add_child(back);
  1764. back->set_tooltip(TTR("Inspect Previous Instance"));
  1765. back->hide();
  1766. forward = memnew(Button);
  1767. hbc->add_child(forward);
  1768. forward->set_tooltip(TTR("Inspect Next Instance"));
  1769. forward->hide();
  1770. HSplitContainer *sc = memnew(HSplitContainer);
  1771. vbc->add_child(sc);
  1772. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  1773. stack_dump = memnew(Tree);
  1774. stack_dump->set_allow_reselect(true);
  1775. stack_dump->set_columns(1);
  1776. stack_dump->set_column_titles_visible(true);
  1777. stack_dump->set_column_title(0, TTR("Stack Frames"));
  1778. stack_dump->set_h_size_flags(SIZE_EXPAND_FILL);
  1779. stack_dump->set_hide_root(true);
  1780. stack_dump->connect("cell_selected", this, "_stack_dump_frame_selected");
  1781. sc->add_child(stack_dump);
  1782. inspector = memnew(EditorInspector);
  1783. inspector->set_h_size_flags(SIZE_EXPAND_FILL);
  1784. inspector->set_enable_capitalize_paths(false);
  1785. inspector->set_read_only(true);
  1786. inspector->connect("object_id_selected", this, "_scene_tree_property_select_object");
  1787. sc->add_child(inspector);
  1788. server.instance();
  1789. pending_in_queue = 0;
  1790. variables = memnew(ScriptEditorDebuggerVariables);
  1791. breaked = false;
  1792. tabs->add_child(dbg);
  1793. }
  1794. { //errors
  1795. errors_tab = memnew(VBoxContainer);
  1796. errors_tab->set_name(TTR("Errors"));
  1797. HBoxContainer *errhb = memnew(HBoxContainer);
  1798. errors_tab->add_child(errhb);
  1799. Button *expand_all = memnew(Button);
  1800. expand_all->set_text(TTR("Expand All"));
  1801. expand_all->connect("pressed", this, "_expand_errors_list");
  1802. errhb->add_child(expand_all);
  1803. Button *collapse_all = memnew(Button);
  1804. collapse_all->set_text(TTR("Collapse All"));
  1805. collapse_all->connect("pressed", this, "_collapse_errors_list");
  1806. errhb->add_child(collapse_all);
  1807. Control *space = memnew(Control);
  1808. space->set_h_size_flags(SIZE_EXPAND_FILL);
  1809. errhb->add_child(space);
  1810. clearbutton = memnew(Button);
  1811. clearbutton->set_text(TTR("Clear"));
  1812. clearbutton->set_h_size_flags(0);
  1813. clearbutton->connect("pressed", this, "_clear_errors_list");
  1814. errhb->add_child(clearbutton);
  1815. error_tree = memnew(Tree);
  1816. error_tree->set_columns(2);
  1817. error_tree->set_column_expand(0, false);
  1818. error_tree->set_column_min_width(0, 140);
  1819. error_tree->set_column_expand(1, true);
  1820. error_tree->set_select_mode(Tree::SELECT_ROW);
  1821. error_tree->set_hide_root(true);
  1822. error_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1823. error_tree->set_allow_rmb_select(true);
  1824. error_tree->connect("item_rmb_selected", this, "_error_tree_item_rmb_selected");
  1825. errors_tab->add_child(error_tree);
  1826. item_menu = memnew(PopupMenu);
  1827. item_menu->connect("id_pressed", this, "_item_menu_id_pressed");
  1828. error_tree->add_child(item_menu);
  1829. tabs->add_child(errors_tab);
  1830. }
  1831. { // remote scene tree
  1832. inspect_scene_tree = memnew(Tree);
  1833. EditorNode::get_singleton()->get_scene_tree_dock()->add_remote_tree_editor(inspect_scene_tree);
  1834. EditorNode::get_singleton()->get_scene_tree_dock()->connect("remote_tree_selected", this, "_scene_tree_selected");
  1835. inspect_scene_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1836. inspect_scene_tree->connect("cell_selected", this, "_scene_tree_selected");
  1837. inspect_scene_tree->connect("item_collapsed", this, "_scene_tree_folded");
  1838. inspect_scene_tree->set_allow_rmb_select(true);
  1839. inspect_scene_tree->connect("item_rmb_selected", this, "_scene_tree_rmb_selected");
  1840. auto_switch_remote_scene_tree = EDITOR_DEF("debugger/auto_switch_to_remote_scene_tree", false);
  1841. inspect_scene_tree_timeout = EDITOR_DEF("debugger/remote_scene_tree_refresh_interval", 1.0);
  1842. inspect_edited_object_timeout = EDITOR_DEF("debugger/remote_inspect_refresh_interval", 0.2);
  1843. inspected_object_id = 0;
  1844. updating_scene_tree = false;
  1845. }
  1846. { // File dialog
  1847. file_dialog = memnew(EditorFileDialog);
  1848. file_dialog->connect("file_selected", this, "_file_selected");
  1849. add_child(file_dialog);
  1850. }
  1851. { //profiler
  1852. profiler = memnew(EditorProfiler);
  1853. profiler->set_name(TTR("Profiler"));
  1854. tabs->add_child(profiler);
  1855. profiler->connect("enable_profiling", this, "_profiler_activate");
  1856. profiler->connect("break_request", this, "_profiler_seeked");
  1857. }
  1858. { //network profiler
  1859. network_profiler = memnew(EditorNetworkProfiler);
  1860. network_profiler->set_name(TTR("Network Profiler"));
  1861. tabs->add_child(network_profiler);
  1862. network_profiler->connect("enable_profiling", this, "_network_profiler_activate");
  1863. }
  1864. { //monitors
  1865. HSplitContainer *hsp = memnew(HSplitContainer);
  1866. perf_monitors = memnew(Tree);
  1867. perf_monitors->set_columns(2);
  1868. perf_monitors->set_column_title(0, TTR("Monitor"));
  1869. perf_monitors->set_column_title(1, TTR("Value"));
  1870. perf_monitors->set_column_titles_visible(true);
  1871. perf_monitors->connect("item_edited", this, "_performance_select");
  1872. hsp->add_child(perf_monitors);
  1873. perf_draw = memnew(Control);
  1874. perf_draw->set_clip_contents(true);
  1875. perf_draw->connect("draw", this, "_performance_draw");
  1876. hsp->add_child(perf_draw);
  1877. hsp->set_name(TTR("Monitors"));
  1878. hsp->set_split_offset(340 * EDSCALE);
  1879. tabs->add_child(hsp);
  1880. perf_max.resize(Performance::MONITOR_MAX);
  1881. Map<String, TreeItem *> bases;
  1882. TreeItem *root = perf_monitors->create_item();
  1883. perf_monitors->set_hide_root(true);
  1884. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  1885. String n = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  1886. Performance::MonitorType mtype = Performance::get_singleton()->get_monitor_type(Performance::Monitor(i));
  1887. String base = n.get_slice("/", 0);
  1888. String name = n.get_slice("/", 1);
  1889. if (!bases.has(base)) {
  1890. TreeItem *b = perf_monitors->create_item(root);
  1891. b->set_text(0, base.capitalize());
  1892. b->set_editable(0, false);
  1893. b->set_selectable(0, false);
  1894. b->set_expand_right(0, true);
  1895. bases[base] = b;
  1896. }
  1897. TreeItem *it = perf_monitors->create_item(bases[base]);
  1898. it->set_metadata(1, mtype);
  1899. it->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  1900. it->set_editable(0, true);
  1901. it->set_selectable(0, false);
  1902. it->set_selectable(1, false);
  1903. it->set_text(0, name.capitalize());
  1904. perf_items.push_back(it);
  1905. perf_max.write[i] = 0;
  1906. }
  1907. info_message = memnew(Label);
  1908. info_message->set_text(TTR("Pick one or more items from the list to display the graph."));
  1909. info_message->set_valign(Label::VALIGN_CENTER);
  1910. info_message->set_align(Label::ALIGN_CENTER);
  1911. info_message->set_autowrap(true);
  1912. info_message->set_anchors_and_margins_preset(PRESET_WIDE, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE);
  1913. perf_draw->add_child(info_message);
  1914. }
  1915. { //vmem inspect
  1916. VBoxContainer *vmem_vb = memnew(VBoxContainer);
  1917. HBoxContainer *vmem_hb = memnew(HBoxContainer);
  1918. Label *vmlb = memnew(Label(TTR("List of Video Memory Usage by Resource:") + " "));
  1919. vmlb->set_h_size_flags(SIZE_EXPAND_FILL);
  1920. vmem_hb->add_child(vmlb);
  1921. vmem_hb->add_child(memnew(Label(TTR("Total:") + " ")));
  1922. vmem_total = memnew(LineEdit);
  1923. vmem_total->set_editable(false);
  1924. vmem_total->set_custom_minimum_size(Size2(100, 0) * EDSCALE);
  1925. vmem_hb->add_child(vmem_total);
  1926. vmem_refresh = memnew(ToolButton);
  1927. vmem_hb->add_child(vmem_refresh);
  1928. vmem_vb->add_child(vmem_hb);
  1929. vmem_refresh->connect("pressed", this, "_video_mem_request");
  1930. VBoxContainer *vmmc = memnew(VBoxContainer);
  1931. vmem_tree = memnew(Tree);
  1932. vmem_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1933. vmem_tree->set_h_size_flags(SIZE_EXPAND_FILL);
  1934. vmmc->add_child(vmem_tree);
  1935. vmmc->set_v_size_flags(SIZE_EXPAND_FILL);
  1936. vmem_vb->add_child(vmmc);
  1937. vmem_vb->set_name(TTR("Video Mem"));
  1938. vmem_tree->set_columns(4);
  1939. vmem_tree->set_column_titles_visible(true);
  1940. vmem_tree->set_column_title(0, TTR("Resource Path"));
  1941. vmem_tree->set_column_expand(0, true);
  1942. vmem_tree->set_column_expand(1, false);
  1943. vmem_tree->set_column_title(1, TTR("Type"));
  1944. vmem_tree->set_column_min_width(1, 100);
  1945. vmem_tree->set_column_expand(2, false);
  1946. vmem_tree->set_column_title(2, TTR("Format"));
  1947. vmem_tree->set_column_min_width(2, 150);
  1948. vmem_tree->set_column_expand(3, false);
  1949. vmem_tree->set_column_title(3, TTR("Usage"));
  1950. vmem_tree->set_column_min_width(3, 80);
  1951. vmem_tree->set_hide_root(true);
  1952. tabs->add_child(vmem_vb);
  1953. }
  1954. { // misc
  1955. VBoxContainer *misc = memnew(VBoxContainer);
  1956. misc->set_name(TTR("Misc"));
  1957. tabs->add_child(misc);
  1958. GridContainer *info_left = memnew(GridContainer);
  1959. info_left->set_columns(2);
  1960. misc->add_child(info_left);
  1961. clicked_ctrl = memnew(LineEdit);
  1962. clicked_ctrl->set_h_size_flags(SIZE_EXPAND_FILL);
  1963. info_left->add_child(memnew(Label(TTR("Clicked Control:"))));
  1964. info_left->add_child(clicked_ctrl);
  1965. clicked_ctrl_type = memnew(LineEdit);
  1966. info_left->add_child(memnew(Label(TTR("Clicked Control Type:"))));
  1967. info_left->add_child(clicked_ctrl_type);
  1968. live_edit_root = memnew(LineEdit);
  1969. live_edit_root->set_h_size_flags(SIZE_EXPAND_FILL);
  1970. {
  1971. HBoxContainer *lehb = memnew(HBoxContainer);
  1972. Label *l = memnew(Label(TTR("Live Edit Root:")));
  1973. info_left->add_child(l);
  1974. lehb->add_child(live_edit_root);
  1975. le_set = memnew(Button(TTR("Set From Tree")));
  1976. lehb->add_child(le_set);
  1977. le_clear = memnew(Button(TTR("Clear")));
  1978. lehb->add_child(le_clear);
  1979. info_left->add_child(lehb);
  1980. le_set->set_disabled(true);
  1981. le_clear->set_disabled(true);
  1982. }
  1983. misc->add_child(memnew(VSeparator));
  1984. HBoxContainer *buttons = memnew(HBoxContainer);
  1985. export_csv = memnew(Button(TTR("Export measures as CSV")));
  1986. export_csv->connect("pressed", this, "_export_csv");
  1987. buttons->add_child(export_csv);
  1988. misc->add_child(buttons);
  1989. }
  1990. msgdialog = memnew(AcceptDialog);
  1991. add_child(msgdialog);
  1992. p_editor->get_undo_redo()->set_method_notify_callback(_method_changeds, this);
  1993. p_editor->get_undo_redo()->set_property_notify_callback(_property_changeds, this);
  1994. live_debug = true;
  1995. last_path_id = false;
  1996. error_count = 0;
  1997. warning_count = 0;
  1998. hide_on_stop = true;
  1999. enable_external_editor = false;
  2000. last_error_count = 0;
  2001. last_warning_count = 0;
  2002. EditorNode::get_singleton()->get_pause_button()->connect("pressed", this, "_paused");
  2003. }
  2004. ScriptEditorDebugger::~ScriptEditorDebugger() {
  2005. memdelete(variables);
  2006. ppeer->set_stream_peer(Ref<StreamPeer>());
  2007. server->stop();
  2008. _clear_remote_objects();
  2009. }