script_editor_debugger.cpp 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874
  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-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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/script_debugger_remote.h"
  34. #include "core/ustring.h"
  35. #include "editor/editor_log.h"
  36. #include "editor/editor_network_profiler.h"
  37. #include "editor/editor_node.h"
  38. #include "editor/editor_profiler.h"
  39. #include "editor/editor_scale.h"
  40. #include "editor/editor_settings.h"
  41. #include "editor/editor_visual_profiler.h"
  42. #include "editor/plugins/canvas_item_editor_plugin.h"
  43. #include "editor/plugins/spatial_editor_plugin.h"
  44. #include "editor/property_editor.h"
  45. #include "main/performance.h"
  46. #include "scene/debugger/scene_debugger.h"
  47. #include "scene/gui/dialogs.h"
  48. #include "scene/gui/label.h"
  49. #include "scene/gui/line_edit.h"
  50. #include "scene/gui/margin_container.h"
  51. #include "scene/gui/rich_text_label.h"
  52. #include "scene/gui/separator.h"
  53. #include "scene/gui/split_container.h"
  54. #include "scene/gui/tab_container.h"
  55. #include "scene/gui/texture_button.h"
  56. #include "scene/gui/tree.h"
  57. #include "scene/resources/packed_scene.h"
  58. void ScriptEditorDebugger::_put_msg(String p_message, Array p_data) {
  59. if (is_session_active()) {
  60. Array msg;
  61. msg.push_back(p_message);
  62. msg.push_back(p_data);
  63. ppeer->put_var(msg);
  64. }
  65. }
  66. void ScriptEditorDebugger::debug_copy() {
  67. String msg = reason->get_text();
  68. if (msg == "") return;
  69. OS::get_singleton()->set_clipboard(msg);
  70. }
  71. void ScriptEditorDebugger::debug_skip_breakpoints() {
  72. skip_breakpoints_value = !skip_breakpoints_value;
  73. if (skip_breakpoints_value)
  74. skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOn", "EditorIcons"));
  75. else
  76. skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOff", "EditorIcons"));
  77. Array msg;
  78. msg.push_back(skip_breakpoints_value);
  79. _put_msg("set_skip_breakpoints", msg);
  80. }
  81. void ScriptEditorDebugger::debug_next() {
  82. ERR_FAIL_COND(!breaked);
  83. _put_msg("next", Array());
  84. _clear_execution();
  85. }
  86. void ScriptEditorDebugger::debug_step() {
  87. ERR_FAIL_COND(!breaked);
  88. _put_msg("step", Array());
  89. _clear_execution();
  90. }
  91. void ScriptEditorDebugger::debug_break() {
  92. ERR_FAIL_COND(breaked);
  93. _put_msg("break", Array());
  94. }
  95. void ScriptEditorDebugger::debug_continue() {
  96. ERR_FAIL_COND(!breaked);
  97. // Allow focus stealing only if we actually run this client for security.
  98. if (remote_pid && EditorNode::get_singleton()->has_child_process(remote_pid))
  99. OS::get_singleton()->enable_for_stealing_focus(remote_pid);
  100. _clear_execution();
  101. _put_msg("continue", Array());
  102. }
  103. void ScriptEditorDebugger::update_tabs() {
  104. if (error_count == 0 && warning_count == 0) {
  105. errors_tab->set_name(TTR("Errors"));
  106. tabs->set_tab_icon(errors_tab->get_index(), Ref<Texture2D>());
  107. } else {
  108. errors_tab->set_name(TTR("Errors") + " (" + itos(error_count + warning_count) + ")");
  109. if (error_count == 0) {
  110. tabs->set_tab_icon(errors_tab->get_index(), get_icon("Warning", "EditorIcons"));
  111. } else {
  112. tabs->set_tab_icon(errors_tab->get_index(), get_icon("Error", "EditorIcons"));
  113. }
  114. }
  115. }
  116. void ScriptEditorDebugger::clear_style() {
  117. tabs->add_style_override("panel", NULL);
  118. }
  119. void ScriptEditorDebugger::save_node(ObjectID p_id, const String &p_file) {
  120. Array msg;
  121. msg.push_back(p_id);
  122. msg.push_back(p_file);
  123. _put_msg("save_node", msg);
  124. }
  125. void ScriptEditorDebugger::_file_selected(const String &p_file) {
  126. Error err;
  127. FileAccessRef file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  128. if (err != OK) {
  129. ERR_PRINT("Failed to open " + p_file);
  130. return;
  131. }
  132. Vector<String> line;
  133. line.resize(Performance::MONITOR_MAX);
  134. // signatures
  135. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  136. line.write[i] = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  137. }
  138. file->store_csv_line(line);
  139. // values
  140. List<Vector<float> >::Element *E = perf_history.back();
  141. while (E) {
  142. Vector<float> &perf_data = E->get();
  143. for (int i = 0; i < perf_data.size(); i++) {
  144. line.write[i] = String::num_real(perf_data[i]);
  145. }
  146. file->store_csv_line(line);
  147. E = E->prev();
  148. }
  149. file->store_string("\n");
  150. Vector<Vector<String> > profiler_data = profiler->get_data_as_csv();
  151. for (int i = 0; i < profiler_data.size(); i++) {
  152. file->store_csv_line(profiler_data[i]);
  153. }
  154. }
  155. void ScriptEditorDebugger::request_remote_tree() {
  156. _put_msg("request_scene_tree", Array());
  157. }
  158. const SceneDebuggerTree *ScriptEditorDebugger::get_remote_tree() {
  159. return scene_tree;
  160. }
  161. void ScriptEditorDebugger::update_remote_object(ObjectID p_obj_id, const String &p_prop, const Variant &p_value) {
  162. Array msg;
  163. msg.push_back(p_obj_id);
  164. msg.push_back(p_prop);
  165. msg.push_back(p_value);
  166. _put_msg("set_object_property", msg);
  167. }
  168. void ScriptEditorDebugger::request_remote_object(ObjectID p_obj_id) {
  169. ERR_FAIL_COND(p_obj_id.is_null());
  170. Array msg;
  171. msg.push_back(p_obj_id);
  172. _put_msg("inspect_object", msg);
  173. }
  174. Object *ScriptEditorDebugger::get_remote_object(ObjectID p_id) {
  175. return inspector->get_object(p_id);
  176. }
  177. void ScriptEditorDebugger::_remote_object_selected(ObjectID p_id) {
  178. emit_signal("remote_object_requested", p_id);
  179. }
  180. void ScriptEditorDebugger::_remote_object_edited(ObjectID p_id, const String &p_prop, const Variant &p_value) {
  181. update_remote_object(p_id, p_prop, p_value);
  182. request_remote_object(p_id);
  183. }
  184. void ScriptEditorDebugger::_remote_object_property_updated(ObjectID p_id, const String &p_property) {
  185. emit_signal("remote_object_property_updated", p_id, p_property);
  186. }
  187. void ScriptEditorDebugger::_video_mem_request() {
  188. _put_msg("request_video_mem", Array());
  189. }
  190. Size2 ScriptEditorDebugger::get_minimum_size() const {
  191. Size2 ms = MarginContainer::get_minimum_size();
  192. ms.y = MAX(ms.y, 250 * EDSCALE);
  193. return ms;
  194. }
  195. void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_data) {
  196. if (p_msg == "debug_enter") {
  197. _put_msg("get_stack_dump", Array());
  198. ERR_FAIL_COND(p_data.size() != 2);
  199. bool can_continue = p_data[0];
  200. String error = p_data[1];
  201. breaked = true;
  202. can_debug = can_continue;
  203. _update_buttons_state();
  204. _set_reason_text(error, MESSAGE_ERROR);
  205. emit_signal("breaked", true, can_continue);
  206. OS::get_singleton()->move_window_to_foreground();
  207. if (error != "") {
  208. tabs->set_current_tab(0);
  209. }
  210. profiler->set_enabled(false);
  211. inspector->clear_cache(); // Take a chance to force remote objects update.
  212. } else if (p_msg == "debug_exit") {
  213. breaked = false;
  214. can_debug = false;
  215. _clear_execution();
  216. _update_buttons_state();
  217. _set_reason_text(TTR("Execution resumed."), MESSAGE_SUCCESS);
  218. emit_signal("breaked", false, false);
  219. profiler->set_enabled(true);
  220. profiler->disable_seeking();
  221. } else if (p_msg == "message:set_pid") {
  222. ERR_FAIL_COND(p_data.size() < 1);
  223. remote_pid = p_data[0];
  224. } else if (p_msg == "message:click_ctrl") {
  225. ERR_FAIL_COND(p_data.size() < 2);
  226. clicked_ctrl->set_text(p_data[0]);
  227. clicked_ctrl_type->set_text(p_data[1]);
  228. } else if (p_msg == "message:scene_tree") {
  229. scene_tree->nodes.clear();
  230. scene_tree->deserialize(p_data);
  231. emit_signal("remote_tree_updated");
  232. _update_buttons_state();
  233. } else if (p_msg == "message:inspect_object") {
  234. ObjectID id = inspector->add_object(p_data);
  235. if (id.is_valid())
  236. emit_signal("remote_object_updated", id);
  237. } else if (p_msg == "message:video_mem") {
  238. vmem_tree->clear();
  239. TreeItem *root = vmem_tree->create_item();
  240. ScriptDebuggerRemote::ResourceUsage usage;
  241. usage.deserialize(p_data);
  242. int total = 0;
  243. for (List<ScriptDebuggerRemote::ResourceInfo>::Element *E = usage.infos.front(); E; E = E->next()) {
  244. TreeItem *it = vmem_tree->create_item(root);
  245. String type = E->get().type;
  246. int bytes = E->get().vram;
  247. it->set_text(0, E->get().path);
  248. it->set_text(1, type);
  249. it->set_text(2, E->get().format);
  250. it->set_text(3, String::humanize_size(bytes));
  251. total += bytes;
  252. if (has_icon(type, "EditorIcons"))
  253. it->set_icon(0, get_icon(type, "EditorIcons"));
  254. }
  255. vmem_total->set_tooltip(TTR("Bytes:") + " " + itos(total));
  256. vmem_total->set_text(String::humanize_size(total));
  257. } else if (p_msg == "stack_dump") {
  258. ScriptDebuggerRemote::ScriptStackDump stack;
  259. stack.deserialize(p_data);
  260. stack_dump->clear();
  261. inspector->clear_stack_variables();
  262. TreeItem *r = stack_dump->create_item();
  263. for (int i = 0; i < stack.frames.size(); i++) {
  264. TreeItem *s = stack_dump->create_item(r);
  265. Dictionary d;
  266. d["frame"] = i;
  267. d["file"] = stack.frames[i].file;
  268. d["function"] = stack.frames[i].func;
  269. d["line"] = stack.frames[i].line;
  270. s->set_metadata(0, d);
  271. String line = itos(i) + " - " + String(d["file"]) + ":" + itos(d["line"]) + " - at function: " + d["function"];
  272. s->set_text(0, line);
  273. if (i == 0)
  274. s->select(0);
  275. }
  276. } else if (p_msg == "stack_frame_vars") {
  277. inspector->clear_stack_variables();
  278. } else if (p_msg == "stack_frame_var") {
  279. inspector->add_stack_variable(p_data);
  280. } else if (p_msg == "output") {
  281. ERR_FAIL_COND(p_data.size() < 1);
  282. String t = p_data[0];
  283. EditorNode::get_log()->add_message(t);
  284. } else if (p_msg == "performance") {
  285. Vector<float> p;
  286. p.resize(p_data.size());
  287. for (int i = 0; i < p_data.size(); i++) {
  288. p.write[i] = p_data[i];
  289. if (i < perf_items.size()) {
  290. const float value = p[i];
  291. String label = rtos(value);
  292. String tooltip = label;
  293. switch (Performance::MonitorType((int)perf_items[i]->get_metadata(1))) {
  294. case Performance::MONITOR_TYPE_MEMORY: {
  295. label = String::humanize_size(value);
  296. tooltip = label;
  297. } break;
  298. case Performance::MONITOR_TYPE_TIME: {
  299. label = rtos(value * 1000).pad_decimals(2) + " ms";
  300. tooltip = label;
  301. } break;
  302. default: {
  303. tooltip += " " + perf_items[i]->get_text(0);
  304. } break;
  305. }
  306. perf_items[i]->set_text(1, label);
  307. perf_items[i]->set_tooltip(1, tooltip);
  308. if (p[i] > perf_max[i])
  309. perf_max.write[i] = p[i];
  310. }
  311. }
  312. perf_history.push_front(p);
  313. perf_draw->update();
  314. } else if (p_msg == "visual_profile") {
  315. // TODO check me.
  316. uint64_t frame = p_data[0];
  317. Vector<String> names = p_data[1];
  318. Vector<real_t> values = p_data[2];
  319. EditorVisualProfiler::Metric metric;
  320. metric.areas.resize(names.size());
  321. metric.frame_number = frame;
  322. metric.valid = true;
  323. {
  324. EditorVisualProfiler::Metric::Area *areas_ptr = metric.areas.ptrw();
  325. int metric_count = names.size();
  326. const String *rs = names.ptr();
  327. const real_t *rr = values.ptr();
  328. for (int i = 0; i < metric_count; i++) {
  329. areas_ptr[i].name = rs[i];
  330. areas_ptr[i].cpu_time = rr[i * 2 + 0];
  331. areas_ptr[i].gpu_time = rr[i * 2 + 1];
  332. }
  333. }
  334. visual_profiler->add_frame_metric(metric);
  335. } else if (p_msg == "error") {
  336. ScriptDebuggerRemote::OutputError oe;
  337. ERR_FAIL_COND_MSG(oe.deserialize(p_data) == false, "Failed to deserialize error message");
  338. // Format time.
  339. Array time_vals;
  340. time_vals.push_back(oe.hr);
  341. time_vals.push_back(oe.min);
  342. time_vals.push_back(oe.sec);
  343. time_vals.push_back(oe.msec);
  344. bool e;
  345. String time = String("%d:%02d:%02d:%04d").sprintf(time_vals, &e);
  346. // Rest of the error data.
  347. bool source_is_project_file = oe.source_file.begins_with("res://");
  348. // Metadata to highlight error line in scripts.
  349. Array source_meta;
  350. source_meta.push_back(oe.source_file);
  351. source_meta.push_back(oe.source_line);
  352. // Create error tree to display above error or warning details.
  353. TreeItem *r = error_tree->get_root();
  354. if (!r) {
  355. r = error_tree->create_item();
  356. }
  357. // Also provide the relevant details as tooltip to quickly check without
  358. // uncollapsing the tree.
  359. String tooltip = oe.warning ? TTR("Warning:") : TTR("Error:");
  360. TreeItem *error = error_tree->create_item(r);
  361. error->set_collapsed(true);
  362. error->set_icon(0, get_icon(oe.warning ? "Warning" : "Error", "EditorIcons"));
  363. error->set_text(0, time);
  364. error->set_text_align(0, TreeItem::ALIGN_LEFT);
  365. String error_title;
  366. // Include method name, when given, in error title.
  367. if (!oe.source_func.empty())
  368. error_title += oe.source_func + ": ";
  369. // If we have a (custom) error message, use it as title, and add a C++ Error
  370. // item with the original error condition.
  371. error_title += oe.error_descr.empty() ? oe.error : oe.error_descr;
  372. error->set_text(1, error_title);
  373. tooltip += " " + error_title + "\n";
  374. if (!oe.error_descr.empty()) {
  375. // Add item for C++ error condition.
  376. TreeItem *cpp_cond = error_tree->create_item(error);
  377. cpp_cond->set_text(0, "<" + TTR("C++ Error") + ">");
  378. cpp_cond->set_text(1, oe.error);
  379. cpp_cond->set_text_align(0, TreeItem::ALIGN_LEFT);
  380. tooltip += TTR("C++ Error:") + " " + oe.error + "\n";
  381. if (source_is_project_file)
  382. cpp_cond->set_metadata(0, source_meta);
  383. }
  384. Vector<uint8_t> v;
  385. v.resize(100);
  386. // Source of the error.
  387. String source_txt = (source_is_project_file ? oe.source_file.get_file() : oe.source_file) + ":" + itos(oe.source_line);
  388. if (!oe.source_func.empty())
  389. source_txt += " @ " + oe.source_func + "()";
  390. TreeItem *cpp_source = error_tree->create_item(error);
  391. cpp_source->set_text(0, "<" + (source_is_project_file ? TTR("Source") : TTR("C++ Source")) + ">");
  392. cpp_source->set_text(1, source_txt);
  393. cpp_source->set_text_align(0, TreeItem::ALIGN_LEFT);
  394. tooltip += (source_is_project_file ? TTR("Source:") : TTR("C++ Source:")) + " " + source_txt + "\n";
  395. // Set metadata to highlight error line in scripts.
  396. if (source_is_project_file) {
  397. error->set_metadata(0, source_meta);
  398. cpp_source->set_metadata(0, source_meta);
  399. }
  400. error->set_tooltip(0, tooltip);
  401. error->set_tooltip(1, tooltip);
  402. // Format stack trace.
  403. // stack_items_count is the number of elements to parse, with 3 items per frame
  404. // of the stack trace (script, method, line).
  405. const ScriptLanguage::StackInfo *infos = oe.callstack.ptr();
  406. for (unsigned int i = 0; i < (unsigned int)oe.callstack.size(); i++) {
  407. TreeItem *stack_trace = error_tree->create_item(error);
  408. Array meta;
  409. meta.push_back(infos[i].file);
  410. meta.push_back(infos[i].line);
  411. stack_trace->set_metadata(0, meta);
  412. if (i == 0) {
  413. stack_trace->set_text(0, "<" + TTR("Stack Trace") + ">");
  414. stack_trace->set_text_align(0, TreeItem::ALIGN_LEFT);
  415. error->set_metadata(0, meta);
  416. }
  417. stack_trace->set_text(1, infos[i].file.get_file() + ":" + itos(infos[i].line) + " @ " + infos[i].func + "()");
  418. }
  419. if (oe.warning)
  420. warning_count++;
  421. else
  422. error_count++;
  423. } else if (p_msg == "profile_sig") {
  424. // Cache a profiler signature.
  425. ScriptDebuggerRemote::ProfilerSignature sig;
  426. sig.deserialize(p_data);
  427. profiler_signature[sig.id] = sig.name;
  428. } else if (p_msg == "profile_frame" || p_msg == "profile_total") {
  429. EditorProfiler::Metric metric;
  430. ScriptDebuggerRemote::ProfilerFrame frame;
  431. frame.deserialize(p_data);
  432. metric.valid = true;
  433. metric.frame_number = frame.frame_number;
  434. metric.frame_time = frame.frame_time;
  435. metric.idle_time = frame.idle_time;
  436. metric.physics_time = frame.physics_time;
  437. metric.physics_frame_time = frame.physics_frame_time;
  438. int frame_data_amount = frame.frames_data.size();
  439. int frame_function_amount = frame.frame_functions.size();
  440. if (frame_data_amount) {
  441. EditorProfiler::Metric::Category frame_time;
  442. frame_time.signature = "category_frame_time";
  443. frame_time.name = "Frame Time";
  444. frame_time.total_time = metric.frame_time;
  445. EditorProfiler::Metric::Category::Item item;
  446. item.calls = 1;
  447. item.line = 0;
  448. item.name = "Physics Time";
  449. item.total = metric.physics_time;
  450. item.self = item.total;
  451. item.signature = "physics_time";
  452. frame_time.items.push_back(item);
  453. item.name = "Idle Time";
  454. item.total = metric.idle_time;
  455. item.self = item.total;
  456. item.signature = "idle_time";
  457. frame_time.items.push_back(item);
  458. item.name = "Physics Frame Time";
  459. item.total = metric.physics_frame_time;
  460. item.self = item.total;
  461. item.signature = "physics_frame_time";
  462. frame_time.items.push_back(item);
  463. metric.categories.push_back(frame_time);
  464. }
  465. for (int i = 0; i < frame_data_amount; i++) {
  466. EditorProfiler::Metric::Category c;
  467. String name = frame.frames_data[i].name;
  468. Array values = frame.frames_data[i].data;
  469. c.name = name.capitalize();
  470. c.items.resize(values.size() / 2);
  471. c.total_time = 0;
  472. c.signature = "categ::" + name;
  473. for (int j = 0; j < values.size(); j += 2) {
  474. EditorProfiler::Metric::Category::Item item;
  475. item.calls = 1;
  476. item.line = 0;
  477. item.name = values[j];
  478. item.self = values[j + 1];
  479. item.total = item.self;
  480. item.signature = "categ::" + name + "::" + item.name;
  481. item.name = item.name.capitalize();
  482. c.total_time += item.total;
  483. c.items.write[j / 2] = item;
  484. }
  485. metric.categories.push_back(c);
  486. }
  487. EditorProfiler::Metric::Category funcs;
  488. funcs.total_time = frame.script_time;
  489. funcs.items.resize(frame_function_amount);
  490. funcs.name = "Script Functions";
  491. funcs.signature = "script_functions";
  492. for (int i = 0; i < frame_function_amount; i++) {
  493. int signature = frame.frame_functions[i].sig_id;
  494. int calls = frame.frame_functions[i].call_count;
  495. float total = frame.frame_functions[i].total_time;
  496. float self = frame.frame_functions[i].self_time;
  497. EditorProfiler::Metric::Category::Item item;
  498. if (profiler_signature.has(signature)) {
  499. item.signature = profiler_signature[signature];
  500. String name = profiler_signature[signature];
  501. Vector<String> strings = name.split("::");
  502. if (strings.size() == 3) {
  503. item.name = strings[2];
  504. item.script = strings[0];
  505. item.line = strings[1].to_int();
  506. } else if (strings.size() == 4) { //Built-in scripts have an :: in their name
  507. item.name = strings[3];
  508. item.script = strings[0] + "::" + strings[1];
  509. item.line = strings[2].to_int();
  510. }
  511. } else {
  512. item.name = "SigErr " + itos(signature);
  513. }
  514. item.calls = calls;
  515. item.self = self;
  516. item.total = total;
  517. funcs.items.write[i] = item;
  518. }
  519. metric.categories.push_back(funcs);
  520. if (p_msg == "profile_frame")
  521. profiler->add_frame_metric(metric, false);
  522. else
  523. profiler->add_frame_metric(metric, true);
  524. } else if (p_msg == "network_profile") {
  525. ScriptDebuggerRemote::NetworkProfilerFrame frame;
  526. frame.deserialize(p_data);
  527. for (int i = 0; i < frame.infos.size(); i++) {
  528. network_profiler->add_node_frame_data(frame.infos[i]);
  529. }
  530. } else if (p_msg == "network_bandwidth") {
  531. ERR_FAIL_COND(p_data.size() < 2);
  532. network_profiler->set_bandwidth(p_data[0], p_data[1]);
  533. } else if (p_msg == "kill_me") {
  534. emit_signal("stop_requested");
  535. _stop_and_notify();
  536. }
  537. }
  538. void ScriptEditorDebugger::_set_reason_text(const String &p_reason, MessageType p_type) {
  539. switch (p_type) {
  540. case MESSAGE_ERROR:
  541. reason->add_color_override("font_color", get_color("error_color", "Editor"));
  542. break;
  543. case MESSAGE_WARNING:
  544. reason->add_color_override("font_color", get_color("warning_color", "Editor"));
  545. break;
  546. default:
  547. reason->add_color_override("font_color", get_color("success_color", "Editor"));
  548. }
  549. reason->set_text(p_reason);
  550. reason->set_tooltip(p_reason.word_wrap(80));
  551. }
  552. void ScriptEditorDebugger::_performance_select() {
  553. perf_draw->update();
  554. }
  555. void ScriptEditorDebugger::_performance_draw() {
  556. Vector<int> which;
  557. for (int i = 0; i < perf_items.size(); i++) {
  558. if (perf_items[i]->is_checked(0))
  559. which.push_back(i);
  560. }
  561. if (which.empty()) {
  562. info_message->show();
  563. return;
  564. }
  565. info_message->hide();
  566. Ref<StyleBox> graph_sb = get_stylebox("normal", "TextEdit");
  567. Ref<Font> graph_font = get_font("font", "TextEdit");
  568. int cols = Math::ceil(Math::sqrt((float)which.size()));
  569. int rows = Math::ceil((float)which.size() / cols);
  570. if (which.size() == 1)
  571. rows = 1;
  572. int margin = 3;
  573. int point_sep = 5;
  574. Size2i s = Size2i(perf_draw->get_size()) / Size2i(cols, rows);
  575. for (int i = 0; i < which.size(); i++) {
  576. Point2i p(i % cols, i / cols);
  577. Rect2i r(p * s, s);
  578. r.position += Point2(margin, margin);
  579. r.size -= Point2(margin, margin) * 2.0;
  580. perf_draw->draw_style_box(graph_sb, r);
  581. r.position += graph_sb->get_offset();
  582. r.size -= graph_sb->get_minimum_size();
  583. int pi = which[i];
  584. Color c = get_color("accent_color", "Editor");
  585. float h = (float)which[i] / (float)(perf_items.size());
  586. // Use a darker color on light backgrounds for better visibility
  587. float value_multiplier = EditorSettings::get_singleton()->is_dark_theme() ? 1.4 : 0.55;
  588. c.set_hsv(Math::fmod(h + 0.4, 0.9), c.get_s() * 0.9, c.get_v() * value_multiplier);
  589. c.a = 0.6;
  590. perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x);
  591. c.a = 0.9;
  592. 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);
  593. float spacing = point_sep / float(cols);
  594. float from = r.size.width;
  595. List<Vector<float> >::Element *E = perf_history.front();
  596. float prev = -1;
  597. while (from >= 0 && E) {
  598. float m = perf_max[pi];
  599. if (m == 0)
  600. m = 0.00001;
  601. float h2 = E->get()[pi] / m;
  602. h2 = (1.0 - h2) * r.size.y;
  603. if (E != perf_history.front())
  604. perf_draw->draw_line(r.position + Point2(from, h2), r.position + Point2(from + spacing, prev), c, Math::round(EDSCALE));
  605. prev = h2;
  606. E = E->next();
  607. from -= spacing;
  608. }
  609. }
  610. }
  611. void ScriptEditorDebugger::_notification(int p_what) {
  612. switch (p_what) {
  613. case NOTIFICATION_ENTER_TREE: {
  614. skip_breakpoints->set_icon(get_icon("DebugSkipBreakpointsOff", "EditorIcons"));
  615. copy->set_icon(get_icon("ActionCopy", "EditorIcons"));
  616. step->set_icon(get_icon("DebugStep", "EditorIcons"));
  617. next->set_icon(get_icon("DebugNext", "EditorIcons"));
  618. dobreak->set_icon(get_icon("Pause", "EditorIcons"));
  619. docontinue->set_icon(get_icon("DebugContinue", "EditorIcons"));
  620. le_set->connect_compat("pressed", this, "_live_edit_set");
  621. le_clear->connect_compat("pressed", this, "_live_edit_clear");
  622. error_tree->connect_compat("item_selected", this, "_error_selected");
  623. error_tree->connect_compat("item_activated", this, "_error_activated");
  624. vmem_refresh->set_icon(get_icon("Reload", "EditorIcons"));
  625. reason->add_color_override("font_color", get_color("error_color", "Editor"));
  626. } break;
  627. case NOTIFICATION_PROCESS: {
  628. if (is_session_active()) {
  629. if (camera_override == OVERRIDE_2D) {
  630. CanvasItemEditor *editor = CanvasItemEditor::get_singleton();
  631. Dictionary state = editor->get_state();
  632. float zoom = state["zoom"];
  633. Point2 offset = state["ofs"];
  634. Transform2D transform;
  635. transform.scale_basis(Size2(zoom, zoom));
  636. transform.elements[2] = -offset * zoom;
  637. Array msg;
  638. msg.push_back(transform);
  639. _put_msg("override_camera_2D:transform", msg);
  640. } else if (camera_override >= OVERRIDE_3D_1) {
  641. int viewport_idx = camera_override - OVERRIDE_3D_1;
  642. SpatialEditorViewport *viewport = SpatialEditor::get_singleton()->get_editor_viewport(viewport_idx);
  643. Camera *const cam = viewport->get_camera();
  644. Array msg;
  645. msg.push_back(cam->get_camera_transform());
  646. if (cam->get_projection() == Camera::PROJECTION_ORTHOGONAL) {
  647. msg.push_back(false);
  648. msg.push_back(cam->get_size());
  649. } else {
  650. msg.push_back(true);
  651. msg.push_back(cam->get_fov());
  652. }
  653. msg.push_back(cam->get_znear());
  654. msg.push_back(cam->get_zfar());
  655. _put_msg("override_camera_3D:transform", msg);
  656. }
  657. }
  658. if (!is_session_active()) {
  659. _stop_and_notify();
  660. break;
  661. };
  662. if (ppeer->get_available_packet_count() <= 0) {
  663. break;
  664. };
  665. const uint64_t until = OS::get_singleton()->get_ticks_msec() + 20;
  666. while (ppeer->get_available_packet_count() > 0) {
  667. Variant cmd;
  668. Error ret = ppeer->get_var(cmd);
  669. if (ret != OK) {
  670. _stop_and_notify();
  671. ERR_FAIL_MSG("Error decoding variant from peer");
  672. }
  673. if (cmd.get_type() != Variant::ARRAY) {
  674. _stop_and_notify();
  675. ERR_FAIL_MSG("Invalid message format received from peer");
  676. }
  677. Array arr = cmd;
  678. if (arr.size() != 2 || arr[0].get_type() != Variant::STRING || arr[1].get_type() != Variant::ARRAY) {
  679. _stop_and_notify();
  680. ERR_FAIL_MSG("Invalid message format received from peer");
  681. }
  682. _parse_message(arr[0], arr[1]);
  683. if (OS::get_singleton()->get_ticks_msec() > until)
  684. break;
  685. }
  686. } break;
  687. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  688. if (tabs->has_stylebox_override("panel")) {
  689. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  690. }
  691. copy->set_icon(get_icon("ActionCopy", "EditorIcons"));
  692. step->set_icon(get_icon("DebugStep", "EditorIcons"));
  693. next->set_icon(get_icon("DebugNext", "EditorIcons"));
  694. dobreak->set_icon(get_icon("Pause", "EditorIcons"));
  695. docontinue->set_icon(get_icon("DebugContinue", "EditorIcons"));
  696. vmem_refresh->set_icon(get_icon("Reload", "EditorIcons"));
  697. } break;
  698. }
  699. }
  700. void ScriptEditorDebugger::_clear_execution() {
  701. TreeItem *ti = stack_dump->get_selected();
  702. if (!ti)
  703. return;
  704. Dictionary d = ti->get_metadata(0);
  705. stack_script = ResourceLoader::load(d["file"]);
  706. emit_signal("clear_execution", stack_script);
  707. stack_script.unref();
  708. stack_dump->clear();
  709. inspector->clear_stack_variables();
  710. }
  711. void ScriptEditorDebugger::start(Ref<StreamPeerTCP> p_connection) {
  712. error_count = 0;
  713. warning_count = 0;
  714. stop();
  715. connection = p_connection;
  716. ppeer->set_stream_peer(connection);
  717. perf_history.clear();
  718. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  719. perf_max.write[i] = 0;
  720. }
  721. set_process(true);
  722. breaked = false;
  723. can_debug = true;
  724. camera_override = OVERRIDE_NONE;
  725. tabs->set_current_tab(0);
  726. _set_reason_text(TTR("Debug session started."), MESSAGE_SUCCESS);
  727. _update_buttons_state();
  728. if (profiler->is_profiling()) {
  729. _profiler_activate(true);
  730. }
  731. if (network_profiler->is_profiling()) {
  732. _network_profiler_activate(true);
  733. }
  734. }
  735. void ScriptEditorDebugger::_update_buttons_state() {
  736. const bool active = is_session_active();
  737. const bool has_editor_tree = active && editor_remote_tree && editor_remote_tree->get_selected();
  738. vmem_refresh->set_disabled(!active);
  739. step->set_disabled(!active || !breaked || !can_debug);
  740. next->set_disabled(!active || !breaked || !can_debug);
  741. copy->set_disabled(!active || !breaked);
  742. docontinue->set_disabled(!active || !breaked);
  743. dobreak->set_disabled(!active || breaked);
  744. le_clear->set_disabled(!active);
  745. le_set->set_disabled(!has_editor_tree);
  746. }
  747. void ScriptEditorDebugger::_stop_and_notify() {
  748. stop();
  749. emit_signal("stopped");
  750. _set_reason_text(TTR("Debug session closed."), MESSAGE_WARNING);
  751. }
  752. void ScriptEditorDebugger::stop() {
  753. set_process(false);
  754. breaked = false;
  755. can_debug = false;
  756. remote_pid = 0;
  757. _clear_execution();
  758. inspector->clear_cache();
  759. ppeer->set_stream_peer(Ref<StreamPeer>());
  760. if (connection.is_valid()) {
  761. connection.unref();
  762. reason->set_text("");
  763. reason->set_tooltip("");
  764. }
  765. node_path_cache.clear();
  766. res_path_cache.clear();
  767. profiler_signature.clear();
  768. inspector->edit(NULL);
  769. _update_buttons_state();
  770. }
  771. void ScriptEditorDebugger::_profiler_activate(bool p_enable) {
  772. if (p_enable) {
  773. profiler_signature.clear();
  774. Array msg;
  775. int max_funcs = EditorSettings::get_singleton()->get("debugger/profiler_frame_max_functions");
  776. max_funcs = CLAMP(max_funcs, 16, 512);
  777. msg.push_back(max_funcs);
  778. _put_msg("start_profiling", msg);
  779. print_verbose("Starting profiling.");
  780. } else {
  781. _put_msg("stop_profiling", Array());
  782. print_verbose("Ending profiling.");
  783. }
  784. }
  785. void ScriptEditorDebugger::_visual_profiler_activate(bool p_enable) {
  786. if (!connection.is_valid())
  787. return;
  788. if (p_enable) {
  789. profiler_signature.clear();
  790. _put_msg("start_visual_profiling", Array());
  791. print_verbose("Starting visual profiling.");
  792. } else {
  793. _put_msg("stop_visual_profiling", Array());
  794. print_verbose("Ending visual profiling.");
  795. }
  796. }
  797. void ScriptEditorDebugger::_network_profiler_activate(bool p_enable) {
  798. if (p_enable) {
  799. profiler_signature.clear();
  800. _put_msg("start_network_profiling", Array());
  801. print_verbose("Starting network profiling.");
  802. } else {
  803. _put_msg("stop_network_profiling", Array());
  804. print_verbose("Ending network profiling.");
  805. }
  806. }
  807. void ScriptEditorDebugger::_profiler_seeked() {
  808. if (breaked)
  809. return;
  810. debug_break();
  811. }
  812. void ScriptEditorDebugger::_stack_dump_frame_selected() {
  813. emit_signal("stack_frame_selected");
  814. int frame = get_stack_script_frame();
  815. if (is_session_active() && frame >= 0) {
  816. Array msg;
  817. msg.push_back(frame);
  818. _put_msg("get_stack_frame_vars", msg);
  819. } else {
  820. inspector->edit(NULL);
  821. }
  822. }
  823. void ScriptEditorDebugger::_export_csv() {
  824. file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  825. file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  826. file_dialog->popup_centered_ratio();
  827. }
  828. String ScriptEditorDebugger::get_var_value(const String &p_var) const {
  829. if (!breaked)
  830. return String();
  831. return inspector->get_stack_variable(p_var);
  832. }
  833. int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) {
  834. const int *r = node_path_cache.getptr(p_path);
  835. if (r)
  836. return *r;
  837. last_path_id++;
  838. node_path_cache[p_path] = last_path_id;
  839. Array msg;
  840. msg.push_back(p_path);
  841. msg.push_back(last_path_id);
  842. _put_msg("live_node_path", msg);
  843. return last_path_id;
  844. }
  845. int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) {
  846. Map<String, int>::Element *E = res_path_cache.find(p_path);
  847. if (E)
  848. return E->get();
  849. last_path_id++;
  850. res_path_cache[p_path] = last_path_id;
  851. Array msg;
  852. msg.push_back(p_path);
  853. msg.push_back(last_path_id);
  854. _put_msg("live_res_path", msg);
  855. return last_path_id;
  856. }
  857. void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
  858. if (!p_base || !live_debug || !is_session_active() || !editor->get_edited_scene())
  859. return;
  860. Node *node = Object::cast_to<Node>(p_base);
  861. VARIANT_ARGPTRS
  862. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  863. //no pointers, sorry
  864. if (argptr[i] && (argptr[i]->get_type() == Variant::OBJECT || argptr[i]->get_type() == Variant::_RID))
  865. return;
  866. }
  867. if (node) {
  868. NodePath path = editor->get_edited_scene()->get_path_to(node);
  869. int pathid = _get_node_path_cache(path);
  870. Array msg;
  871. msg.push_back(pathid);
  872. msg.push_back(p_name);
  873. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  874. //no pointers, sorry
  875. msg.push_back(*argptr[i]);
  876. }
  877. _put_msg("live_node_call", msg);
  878. return;
  879. }
  880. Resource *res = Object::cast_to<Resource>(p_base);
  881. if (res && res->get_path() != String()) {
  882. String respath = res->get_path();
  883. int pathid = _get_res_path_cache(respath);
  884. Array msg;
  885. msg.push_back(pathid);
  886. msg.push_back(p_name);
  887. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  888. //no pointers, sorry
  889. msg.push_back(*argptr[i]);
  890. }
  891. _put_msg("live_res_call", msg);
  892. return;
  893. }
  894. }
  895. void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p_property, const Variant &p_value) {
  896. if (!p_base || !live_debug || !editor->get_edited_scene())
  897. return;
  898. Node *node = Object::cast_to<Node>(p_base);
  899. if (node) {
  900. NodePath path = editor->get_edited_scene()->get_path_to(node);
  901. int pathid = _get_node_path_cache(path);
  902. if (p_value.is_ref()) {
  903. Ref<Resource> res = p_value;
  904. if (res.is_valid() && res->get_path() != String()) {
  905. Array msg;
  906. msg.push_back(pathid);
  907. msg.push_back(p_property);
  908. msg.push_back(res->get_path());
  909. _put_msg("live_node_prop_res", msg);
  910. }
  911. } else {
  912. Array msg;
  913. msg.push_back(pathid);
  914. msg.push_back(p_property);
  915. msg.push_back(p_value);
  916. _put_msg("live_node_prop", msg);
  917. }
  918. return;
  919. }
  920. Resource *res = Object::cast_to<Resource>(p_base);
  921. if (res && res->get_path() != String()) {
  922. String respath = res->get_path();
  923. int pathid = _get_res_path_cache(respath);
  924. if (p_value.is_ref()) {
  925. Ref<Resource> res2 = p_value;
  926. if (res2.is_valid() && res2->get_path() != String()) {
  927. Array msg;
  928. msg.push_back(pathid);
  929. msg.push_back(p_property);
  930. msg.push_back(res2->get_path());
  931. _put_msg("live_res_prop_res", msg);
  932. }
  933. } else {
  934. Array msg;
  935. msg.push_back(pathid);
  936. msg.push_back(p_property);
  937. msg.push_back(p_value);
  938. _put_msg("live_res_prop", msg);
  939. }
  940. return;
  941. }
  942. }
  943. String ScriptEditorDebugger::get_stack_script_file() const {
  944. TreeItem *ti = stack_dump->get_selected();
  945. if (!ti)
  946. return "";
  947. Dictionary d = ti->get_metadata(0);
  948. return d["file"];
  949. }
  950. int ScriptEditorDebugger::get_stack_script_line() const {
  951. TreeItem *ti = stack_dump->get_selected();
  952. if (!ti)
  953. return -1;
  954. Dictionary d = ti->get_metadata(0);
  955. return d["line"];
  956. }
  957. int ScriptEditorDebugger::get_stack_script_frame() const {
  958. TreeItem *ti = stack_dump->get_selected();
  959. if (!ti)
  960. return -1;
  961. Dictionary d = ti->get_metadata(0);
  962. return d["frame"];
  963. }
  964. void ScriptEditorDebugger::set_live_debugging(bool p_enable) {
  965. live_debug = p_enable;
  966. }
  967. void ScriptEditorDebugger::_live_edit_set() {
  968. if (!is_session_active() || !editor_remote_tree)
  969. return;
  970. TreeItem *ti = editor_remote_tree->get_selected();
  971. if (!ti)
  972. return;
  973. String path;
  974. while (ti) {
  975. String lp = ti->get_text(0);
  976. path = "/" + lp + path;
  977. ti = ti->get_parent();
  978. }
  979. NodePath np = path;
  980. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  981. update_live_edit_root();
  982. }
  983. void ScriptEditorDebugger::_live_edit_clear() {
  984. NodePath np = NodePath("/root");
  985. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  986. update_live_edit_root();
  987. }
  988. void ScriptEditorDebugger::update_live_edit_root() {
  989. NodePath np = editor->get_editor_data().get_edited_scene_live_edit_root();
  990. Array msg;
  991. msg.push_back(np);
  992. if (editor->get_edited_scene())
  993. msg.push_back(editor->get_edited_scene()->get_filename());
  994. else
  995. msg.push_back("");
  996. _put_msg("live_set_root", msg);
  997. live_edit_root->set_text(np);
  998. }
  999. void ScriptEditorDebugger::live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name) {
  1000. if (live_debug) {
  1001. Array msg;
  1002. msg.push_back(p_parent);
  1003. msg.push_back(p_type);
  1004. msg.push_back(p_name);
  1005. _put_msg("live_create_node", msg);
  1006. }
  1007. }
  1008. void ScriptEditorDebugger::live_debug_instance_node(const NodePath &p_parent, const String &p_path, const String &p_name) {
  1009. if (live_debug) {
  1010. Array msg;
  1011. msg.push_back(p_parent);
  1012. msg.push_back(p_path);
  1013. msg.push_back(p_name);
  1014. _put_msg("live_instance_node", msg);
  1015. }
  1016. }
  1017. void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) {
  1018. if (live_debug) {
  1019. Array msg;
  1020. msg.push_back(p_at);
  1021. _put_msg("live_remove_node", msg);
  1022. }
  1023. }
  1024. void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) {
  1025. if (live_debug) {
  1026. Array msg;
  1027. msg.push_back(p_at);
  1028. msg.push_back(p_keep_id);
  1029. _put_msg("live_remove_and_keep_node", msg);
  1030. }
  1031. }
  1032. void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) {
  1033. if (live_debug) {
  1034. Array msg;
  1035. msg.push_back(p_id);
  1036. msg.push_back(p_at);
  1037. msg.push_back(p_at_pos);
  1038. _put_msg("live_restore_node", msg);
  1039. }
  1040. }
  1041. void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) {
  1042. if (live_debug) {
  1043. Array msg;
  1044. msg.push_back(p_at);
  1045. msg.push_back(p_new_name);
  1046. _put_msg("live_duplicate_node", msg);
  1047. }
  1048. }
  1049. void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) {
  1050. if (live_debug) {
  1051. Array msg;
  1052. msg.push_back(p_at);
  1053. msg.push_back(p_new_place);
  1054. msg.push_back(p_new_name);
  1055. msg.push_back(p_at_pos);
  1056. _put_msg("live_reparent_node", msg);
  1057. }
  1058. }
  1059. ScriptEditorDebugger::CameraOverride ScriptEditorDebugger::get_camera_override() const {
  1060. return camera_override;
  1061. }
  1062. void ScriptEditorDebugger::set_camera_override(CameraOverride p_override) {
  1063. if (p_override == OVERRIDE_2D && camera_override != OVERRIDE_2D) {
  1064. Array msg;
  1065. msg.push_back(true);
  1066. _put_msg("override_camera_2D:set", msg);
  1067. } else if (p_override != OVERRIDE_2D && camera_override == OVERRIDE_2D) {
  1068. Array msg;
  1069. msg.push_back(false);
  1070. _put_msg("override_camera_2D:set", msg);
  1071. } else if (p_override >= OVERRIDE_3D_1 && camera_override < OVERRIDE_3D_1) {
  1072. Array msg;
  1073. msg.push_back(true);
  1074. _put_msg("override_camera_3D:set", msg);
  1075. } else if (p_override < OVERRIDE_3D_1 && camera_override >= OVERRIDE_3D_1) {
  1076. Array msg;
  1077. msg.push_back(false);
  1078. _put_msg("override_camera_3D:set", msg);
  1079. }
  1080. camera_override = p_override;
  1081. }
  1082. void ScriptEditorDebugger::set_breakpoint(const String &p_path, int p_line, bool p_enabled) {
  1083. Array msg;
  1084. msg.push_back(p_path);
  1085. msg.push_back(p_line);
  1086. msg.push_back(p_enabled);
  1087. _put_msg("breakpoint", msg);
  1088. }
  1089. void ScriptEditorDebugger::reload_scripts() {
  1090. _put_msg("reload_scripts", Array());
  1091. }
  1092. bool ScriptEditorDebugger::is_skip_breakpoints() {
  1093. return skip_breakpoints_value;
  1094. }
  1095. void ScriptEditorDebugger::_error_activated() {
  1096. TreeItem *selected = error_tree->get_selected();
  1097. TreeItem *ci = selected->get_children();
  1098. if (ci) {
  1099. selected->set_collapsed(!selected->is_collapsed());
  1100. }
  1101. }
  1102. void ScriptEditorDebugger::_error_selected() {
  1103. TreeItem *selected = error_tree->get_selected();
  1104. Array meta = selected->get_metadata(0);
  1105. if (meta.size() == 0) {
  1106. return;
  1107. }
  1108. emit_signal("error_selected", String(meta[0]), int(meta[1]));
  1109. }
  1110. void ScriptEditorDebugger::_expand_errors_list() {
  1111. TreeItem *root = error_tree->get_root();
  1112. if (!root)
  1113. return;
  1114. TreeItem *item = root->get_children();
  1115. while (item) {
  1116. item->set_collapsed(false);
  1117. item = item->get_next();
  1118. }
  1119. }
  1120. void ScriptEditorDebugger::_collapse_errors_list() {
  1121. TreeItem *root = error_tree->get_root();
  1122. if (!root)
  1123. return;
  1124. TreeItem *item = root->get_children();
  1125. while (item) {
  1126. item->set_collapsed(true);
  1127. item = item->get_next();
  1128. }
  1129. }
  1130. void ScriptEditorDebugger::_clear_errors_list() {
  1131. error_tree->clear();
  1132. error_count = 0;
  1133. warning_count = 0;
  1134. _notification(NOTIFICATION_PROCESS);
  1135. }
  1136. // Right click on specific file(s) or folder(s).
  1137. void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos) {
  1138. item_menu->clear();
  1139. item_menu->set_size(Size2(1, 1));
  1140. if (error_tree->is_anything_selected()) {
  1141. item_menu->add_icon_item(get_icon("ActionCopy", "EditorIcons"), TTR("Copy Error"), 0);
  1142. }
  1143. if (item_menu->get_item_count() > 0) {
  1144. item_menu->set_position(error_tree->get_global_position() + p_pos);
  1145. item_menu->popup();
  1146. }
  1147. }
  1148. void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) {
  1149. TreeItem *ti = error_tree->get_selected();
  1150. while (ti->get_parent() != error_tree->get_root())
  1151. ti = ti->get_parent();
  1152. String type;
  1153. if (ti->get_icon(0) == get_icon("Warning", "EditorIcons")) {
  1154. type = "W ";
  1155. } else if (ti->get_icon(0) == get_icon("Error", "EditorIcons")) {
  1156. type = "E ";
  1157. }
  1158. String text = ti->get_text(0) + " ";
  1159. int rpad_len = text.length();
  1160. text = type + text + ti->get_text(1) + "\n";
  1161. TreeItem *ci = ti->get_children();
  1162. while (ci) {
  1163. text += " " + ci->get_text(0).rpad(rpad_len) + ci->get_text(1) + "\n";
  1164. ci = ci->get_next();
  1165. }
  1166. OS::get_singleton()->set_clipboard(text);
  1167. }
  1168. void ScriptEditorDebugger::_tab_changed(int p_tab) {
  1169. if (tabs->get_tab_title(p_tab) == TTR("Video RAM")) {
  1170. // "Video RAM" tab was clicked, refresh the data it's dislaying when entering the tab.
  1171. _video_mem_request();
  1172. }
  1173. }
  1174. void ScriptEditorDebugger::_bind_methods() {
  1175. ClassDB::bind_method(D_METHOD("_stack_dump_frame_selected"), &ScriptEditorDebugger::_stack_dump_frame_selected);
  1176. ClassDB::bind_method(D_METHOD("debug_skip_breakpoints"), &ScriptEditorDebugger::debug_skip_breakpoints);
  1177. ClassDB::bind_method(D_METHOD("debug_copy"), &ScriptEditorDebugger::debug_copy);
  1178. ClassDB::bind_method(D_METHOD("debug_next"), &ScriptEditorDebugger::debug_next);
  1179. ClassDB::bind_method(D_METHOD("debug_step"), &ScriptEditorDebugger::debug_step);
  1180. ClassDB::bind_method(D_METHOD("debug_break"), &ScriptEditorDebugger::debug_break);
  1181. ClassDB::bind_method(D_METHOD("debug_continue"), &ScriptEditorDebugger::debug_continue);
  1182. ClassDB::bind_method(D_METHOD("_export_csv"), &ScriptEditorDebugger::_export_csv);
  1183. ClassDB::bind_method(D_METHOD("_performance_draw"), &ScriptEditorDebugger::_performance_draw);
  1184. ClassDB::bind_method(D_METHOD("_performance_select"), &ScriptEditorDebugger::_performance_select);
  1185. ClassDB::bind_method(D_METHOD("_video_mem_request"), &ScriptEditorDebugger::_video_mem_request);
  1186. ClassDB::bind_method(D_METHOD("_live_edit_set"), &ScriptEditorDebugger::_live_edit_set);
  1187. ClassDB::bind_method(D_METHOD("_live_edit_clear"), &ScriptEditorDebugger::_live_edit_clear);
  1188. ClassDB::bind_method(D_METHOD("_error_selected"), &ScriptEditorDebugger::_error_selected);
  1189. ClassDB::bind_method(D_METHOD("_error_activated"), &ScriptEditorDebugger::_error_activated);
  1190. ClassDB::bind_method(D_METHOD("_expand_errors_list"), &ScriptEditorDebugger::_expand_errors_list);
  1191. ClassDB::bind_method(D_METHOD("_collapse_errors_list"), &ScriptEditorDebugger::_collapse_errors_list);
  1192. ClassDB::bind_method(D_METHOD("_profiler_activate"), &ScriptEditorDebugger::_profiler_activate);
  1193. ClassDB::bind_method(D_METHOD("_visual_profiler_activate"), &ScriptEditorDebugger::_visual_profiler_activate);
  1194. ClassDB::bind_method(D_METHOD("_network_profiler_activate"), &ScriptEditorDebugger::_network_profiler_activate);
  1195. ClassDB::bind_method(D_METHOD("_profiler_seeked"), &ScriptEditorDebugger::_profiler_seeked);
  1196. ClassDB::bind_method(D_METHOD("_clear_errors_list"), &ScriptEditorDebugger::_clear_errors_list);
  1197. ClassDB::bind_method(D_METHOD("_error_tree_item_rmb_selected"), &ScriptEditorDebugger::_error_tree_item_rmb_selected);
  1198. ClassDB::bind_method(D_METHOD("_item_menu_id_pressed"), &ScriptEditorDebugger::_item_menu_id_pressed);
  1199. ClassDB::bind_method(D_METHOD("_tab_changed"), &ScriptEditorDebugger::_tab_changed);
  1200. ClassDB::bind_method(D_METHOD("_file_selected"), &ScriptEditorDebugger::_file_selected);
  1201. ClassDB::bind_method(D_METHOD("_remote_object_selected", "id"), &ScriptEditorDebugger::_remote_object_selected);
  1202. ClassDB::bind_method(D_METHOD("_remote_object_edited", "id", "property", "value"), &ScriptEditorDebugger::_remote_object_edited);
  1203. ClassDB::bind_method(D_METHOD("_remote_object_property_updated", "id", "property"), &ScriptEditorDebugger::_remote_object_property_updated);
  1204. ClassDB::bind_method(D_METHOD("live_debug_create_node"), &ScriptEditorDebugger::live_debug_create_node);
  1205. ClassDB::bind_method(D_METHOD("live_debug_instance_node"), &ScriptEditorDebugger::live_debug_instance_node);
  1206. ClassDB::bind_method(D_METHOD("live_debug_remove_node"), &ScriptEditorDebugger::live_debug_remove_node);
  1207. ClassDB::bind_method(D_METHOD("live_debug_remove_and_keep_node"), &ScriptEditorDebugger::live_debug_remove_and_keep_node);
  1208. ClassDB::bind_method(D_METHOD("live_debug_restore_node"), &ScriptEditorDebugger::live_debug_restore_node);
  1209. ClassDB::bind_method(D_METHOD("live_debug_duplicate_node"), &ScriptEditorDebugger::live_debug_duplicate_node);
  1210. ClassDB::bind_method(D_METHOD("live_debug_reparent_node"), &ScriptEditorDebugger::live_debug_reparent_node);
  1211. ClassDB::bind_method(D_METHOD("request_remote_object", "id"), &ScriptEditorDebugger::request_remote_object);
  1212. ClassDB::bind_method(D_METHOD("update_remote_object", "id", "property", "value"), &ScriptEditorDebugger::update_remote_object);
  1213. ADD_SIGNAL(MethodInfo("stopped"));
  1214. ADD_SIGNAL(MethodInfo("stop_requested"));
  1215. ADD_SIGNAL(MethodInfo("stack_frame_selected", PropertyInfo(Variant::INT, "frame")));
  1216. ADD_SIGNAL(MethodInfo("error_selected", PropertyInfo(Variant::INT, "error")));
  1217. ADD_SIGNAL(MethodInfo("set_execution", PropertyInfo("script"), PropertyInfo(Variant::INT, "line")));
  1218. ADD_SIGNAL(MethodInfo("clear_execution", PropertyInfo("script")));
  1219. ADD_SIGNAL(MethodInfo("breaked", PropertyInfo(Variant::BOOL, "reallydid"), PropertyInfo(Variant::BOOL, "can_debug")));
  1220. ADD_SIGNAL(MethodInfo("remote_object_requested", PropertyInfo(Variant::INT, "id")));
  1221. ADD_SIGNAL(MethodInfo("remote_object_updated", PropertyInfo(Variant::INT, "id")));
  1222. ADD_SIGNAL(MethodInfo("remote_object_property_updated", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "property")));
  1223. ADD_SIGNAL(MethodInfo("remote_tree_updated"));
  1224. }
  1225. ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
  1226. ppeer = Ref<PacketPeerStream>(memnew(PacketPeerStream));
  1227. ppeer->set_input_buffer_max_size((1024 * 1024 * 8) - 4); // 8 MiB should be enough, minus 4 bytes for separator.
  1228. editor = p_editor;
  1229. tabs = memnew(TabContainer);
  1230. tabs->set_tab_align(TabContainer::ALIGN_LEFT);
  1231. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  1232. tabs->connect_compat("tab_changed", this, "_tab_changed");
  1233. add_child(tabs);
  1234. { //debugger
  1235. VBoxContainer *vbc = memnew(VBoxContainer);
  1236. vbc->set_name(TTR("Debugger"));
  1237. Control *dbg = vbc;
  1238. HBoxContainer *hbc = memnew(HBoxContainer);
  1239. vbc->add_child(hbc);
  1240. reason = memnew(Label);
  1241. reason->set_text("");
  1242. hbc->add_child(reason);
  1243. reason->set_h_size_flags(SIZE_EXPAND_FILL);
  1244. reason->set_autowrap(true);
  1245. reason->set_max_lines_visible(3);
  1246. reason->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  1247. hbc->add_child(memnew(VSeparator));
  1248. skip_breakpoints = memnew(ToolButton);
  1249. hbc->add_child(skip_breakpoints);
  1250. skip_breakpoints->set_tooltip(TTR("Skip Breakpoints"));
  1251. skip_breakpoints->connect_compat("pressed", this, "debug_skip_breakpoints");
  1252. hbc->add_child(memnew(VSeparator));
  1253. copy = memnew(ToolButton);
  1254. hbc->add_child(copy);
  1255. copy->set_tooltip(TTR("Copy Error"));
  1256. copy->connect_compat("pressed", this, "debug_copy");
  1257. hbc->add_child(memnew(VSeparator));
  1258. step = memnew(ToolButton);
  1259. hbc->add_child(step);
  1260. step->set_tooltip(TTR("Step Into"));
  1261. step->set_shortcut(ED_GET_SHORTCUT("debugger/step_into"));
  1262. step->connect_compat("pressed", this, "debug_step");
  1263. next = memnew(ToolButton);
  1264. hbc->add_child(next);
  1265. next->set_tooltip(TTR("Step Over"));
  1266. next->set_shortcut(ED_GET_SHORTCUT("debugger/step_over"));
  1267. next->connect_compat("pressed", this, "debug_next");
  1268. hbc->add_child(memnew(VSeparator));
  1269. dobreak = memnew(ToolButton);
  1270. hbc->add_child(dobreak);
  1271. dobreak->set_tooltip(TTR("Break"));
  1272. dobreak->set_shortcut(ED_GET_SHORTCUT("debugger/break"));
  1273. dobreak->connect_compat("pressed", this, "debug_break");
  1274. docontinue = memnew(ToolButton);
  1275. hbc->add_child(docontinue);
  1276. docontinue->set_tooltip(TTR("Continue"));
  1277. docontinue->set_shortcut(ED_GET_SHORTCUT("debugger/continue"));
  1278. docontinue->connect_compat("pressed", this, "debug_continue");
  1279. HSplitContainer *sc = memnew(HSplitContainer);
  1280. vbc->add_child(sc);
  1281. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  1282. stack_dump = memnew(Tree);
  1283. stack_dump->set_allow_reselect(true);
  1284. stack_dump->set_columns(1);
  1285. stack_dump->set_column_titles_visible(true);
  1286. stack_dump->set_column_title(0, TTR("Stack Frames"));
  1287. stack_dump->set_h_size_flags(SIZE_EXPAND_FILL);
  1288. stack_dump->set_hide_root(true);
  1289. stack_dump->connect_compat("cell_selected", this, "_stack_dump_frame_selected");
  1290. sc->add_child(stack_dump);
  1291. inspector = memnew(EditorDebuggerInspector);
  1292. inspector->set_h_size_flags(SIZE_EXPAND_FILL);
  1293. inspector->set_enable_capitalize_paths(false);
  1294. inspector->set_read_only(true);
  1295. inspector->connect_compat("object_selected", this, "_remote_object_selected");
  1296. inspector->connect_compat("object_edited", this, "_remote_object_edited");
  1297. inspector->connect_compat("object_property_updated", this, "_remote_object_property_updated");
  1298. sc->add_child(inspector);
  1299. tabs->add_child(dbg);
  1300. }
  1301. { //errors
  1302. errors_tab = memnew(VBoxContainer);
  1303. errors_tab->set_name(TTR("Errors"));
  1304. HBoxContainer *errhb = memnew(HBoxContainer);
  1305. errors_tab->add_child(errhb);
  1306. Button *expand_all = memnew(Button);
  1307. expand_all->set_text(TTR("Expand All"));
  1308. expand_all->connect_compat("pressed", this, "_expand_errors_list");
  1309. errhb->add_child(expand_all);
  1310. Button *collapse_all = memnew(Button);
  1311. collapse_all->set_text(TTR("Collapse All"));
  1312. collapse_all->connect_compat("pressed", this, "_collapse_errors_list");
  1313. errhb->add_child(collapse_all);
  1314. Control *space = memnew(Control);
  1315. space->set_h_size_flags(SIZE_EXPAND_FILL);
  1316. errhb->add_child(space);
  1317. clearbutton = memnew(Button);
  1318. clearbutton->set_text(TTR("Clear"));
  1319. clearbutton->set_h_size_flags(0);
  1320. clearbutton->connect_compat("pressed", this, "_clear_errors_list");
  1321. errhb->add_child(clearbutton);
  1322. error_tree = memnew(Tree);
  1323. error_tree->set_columns(2);
  1324. error_tree->set_column_expand(0, false);
  1325. error_tree->set_column_min_width(0, 140);
  1326. error_tree->set_column_expand(1, true);
  1327. error_tree->set_select_mode(Tree::SELECT_ROW);
  1328. error_tree->set_hide_root(true);
  1329. error_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1330. error_tree->set_allow_rmb_select(true);
  1331. error_tree->connect_compat("item_rmb_selected", this, "_error_tree_item_rmb_selected");
  1332. errors_tab->add_child(error_tree);
  1333. item_menu = memnew(PopupMenu);
  1334. item_menu->connect_compat("id_pressed", this, "_item_menu_id_pressed");
  1335. error_tree->add_child(item_menu);
  1336. tabs->add_child(errors_tab);
  1337. }
  1338. { // File dialog
  1339. file_dialog = memnew(EditorFileDialog);
  1340. file_dialog->connect_compat("file_selected", this, "_file_selected");
  1341. add_child(file_dialog);
  1342. }
  1343. { //profiler
  1344. profiler = memnew(EditorProfiler);
  1345. profiler->set_name(TTR("Profiler"));
  1346. tabs->add_child(profiler);
  1347. profiler->connect_compat("enable_profiling", this, "_profiler_activate");
  1348. profiler->connect_compat("break_request", this, "_profiler_seeked");
  1349. }
  1350. { //frame profiler
  1351. visual_profiler = memnew(EditorVisualProfiler);
  1352. visual_profiler->set_name(TTR("Visual Profiler"));
  1353. tabs->add_child(visual_profiler);
  1354. visual_profiler->connect_compat("enable_profiling", this, "_visual_profiler_activate");
  1355. }
  1356. { //network profiler
  1357. network_profiler = memnew(EditorNetworkProfiler);
  1358. network_profiler->set_name(TTR("Network Profiler"));
  1359. tabs->add_child(network_profiler);
  1360. network_profiler->connect_compat("enable_profiling", this, "_network_profiler_activate");
  1361. }
  1362. { //monitors
  1363. HSplitContainer *hsp = memnew(HSplitContainer);
  1364. perf_monitors = memnew(Tree);
  1365. perf_monitors->set_columns(2);
  1366. perf_monitors->set_column_title(0, TTR("Monitor"));
  1367. perf_monitors->set_column_title(1, TTR("Value"));
  1368. perf_monitors->set_column_titles_visible(true);
  1369. perf_monitors->connect_compat("item_edited", this, "_performance_select");
  1370. hsp->add_child(perf_monitors);
  1371. perf_draw = memnew(Control);
  1372. perf_draw->set_clip_contents(true);
  1373. perf_draw->connect_compat("draw", this, "_performance_draw");
  1374. hsp->add_child(perf_draw);
  1375. hsp->set_name(TTR("Monitors"));
  1376. hsp->set_split_offset(340 * EDSCALE);
  1377. tabs->add_child(hsp);
  1378. perf_max.resize(Performance::MONITOR_MAX);
  1379. Map<String, TreeItem *> bases;
  1380. TreeItem *root = perf_monitors->create_item();
  1381. perf_monitors->set_hide_root(true);
  1382. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  1383. String n = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  1384. Performance::MonitorType mtype = Performance::get_singleton()->get_monitor_type(Performance::Monitor(i));
  1385. String base = n.get_slice("/", 0);
  1386. String name = n.get_slice("/", 1);
  1387. if (!bases.has(base)) {
  1388. TreeItem *b = perf_monitors->create_item(root);
  1389. b->set_text(0, base.capitalize());
  1390. b->set_editable(0, false);
  1391. b->set_selectable(0, false);
  1392. b->set_expand_right(0, true);
  1393. bases[base] = b;
  1394. }
  1395. TreeItem *it = perf_monitors->create_item(bases[base]);
  1396. it->set_metadata(1, mtype);
  1397. it->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  1398. it->set_editable(0, true);
  1399. it->set_selectable(0, false);
  1400. it->set_selectable(1, false);
  1401. it->set_text(0, name.capitalize());
  1402. perf_items.push_back(it);
  1403. perf_max.write[i] = 0;
  1404. }
  1405. info_message = memnew(Label);
  1406. info_message->set_text(TTR("Pick one or more items from the list to display the graph."));
  1407. info_message->set_valign(Label::VALIGN_CENTER);
  1408. info_message->set_align(Label::ALIGN_CENTER);
  1409. info_message->set_autowrap(true);
  1410. info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  1411. info_message->set_anchors_and_margins_preset(PRESET_WIDE, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE);
  1412. perf_draw->add_child(info_message);
  1413. }
  1414. { //vmem inspect
  1415. VBoxContainer *vmem_vb = memnew(VBoxContainer);
  1416. HBoxContainer *vmem_hb = memnew(HBoxContainer);
  1417. Label *vmlb = memnew(Label(TTR("List of Video Memory Usage by Resource:") + " "));
  1418. vmlb->set_h_size_flags(SIZE_EXPAND_FILL);
  1419. vmem_hb->add_child(vmlb);
  1420. vmem_hb->add_child(memnew(Label(TTR("Total:") + " ")));
  1421. vmem_total = memnew(LineEdit);
  1422. vmem_total->set_editable(false);
  1423. vmem_total->set_custom_minimum_size(Size2(100, 0) * EDSCALE);
  1424. vmem_hb->add_child(vmem_total);
  1425. vmem_refresh = memnew(ToolButton);
  1426. vmem_hb->add_child(vmem_refresh);
  1427. vmem_vb->add_child(vmem_hb);
  1428. vmem_refresh->connect_compat("pressed", this, "_video_mem_request");
  1429. VBoxContainer *vmmc = memnew(VBoxContainer);
  1430. vmem_tree = memnew(Tree);
  1431. vmem_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1432. vmem_tree->set_h_size_flags(SIZE_EXPAND_FILL);
  1433. vmmc->add_child(vmem_tree);
  1434. vmmc->set_v_size_flags(SIZE_EXPAND_FILL);
  1435. vmem_vb->add_child(vmmc);
  1436. vmem_vb->set_name(TTR("Video RAM"));
  1437. vmem_tree->set_columns(4);
  1438. vmem_tree->set_column_titles_visible(true);
  1439. vmem_tree->set_column_title(0, TTR("Resource Path"));
  1440. vmem_tree->set_column_expand(0, true);
  1441. vmem_tree->set_column_expand(1, false);
  1442. vmem_tree->set_column_title(1, TTR("Type"));
  1443. vmem_tree->set_column_min_width(1, 100 * EDSCALE);
  1444. vmem_tree->set_column_expand(2, false);
  1445. vmem_tree->set_column_title(2, TTR("Format"));
  1446. vmem_tree->set_column_min_width(2, 150 * EDSCALE);
  1447. vmem_tree->set_column_expand(3, false);
  1448. vmem_tree->set_column_title(3, TTR("Usage"));
  1449. vmem_tree->set_column_min_width(3, 80 * EDSCALE);
  1450. vmem_tree->set_hide_root(true);
  1451. tabs->add_child(vmem_vb);
  1452. }
  1453. { // misc
  1454. VBoxContainer *misc = memnew(VBoxContainer);
  1455. misc->set_name(TTR("Misc"));
  1456. tabs->add_child(misc);
  1457. GridContainer *info_left = memnew(GridContainer);
  1458. info_left->set_columns(2);
  1459. misc->add_child(info_left);
  1460. clicked_ctrl = memnew(LineEdit);
  1461. clicked_ctrl->set_h_size_flags(SIZE_EXPAND_FILL);
  1462. info_left->add_child(memnew(Label(TTR("Clicked Control:"))));
  1463. info_left->add_child(clicked_ctrl);
  1464. clicked_ctrl_type = memnew(LineEdit);
  1465. info_left->add_child(memnew(Label(TTR("Clicked Control Type:"))));
  1466. info_left->add_child(clicked_ctrl_type);
  1467. scene_tree = memnew(SceneDebuggerTree);
  1468. live_edit_root = memnew(LineEdit);
  1469. live_edit_root->set_h_size_flags(SIZE_EXPAND_FILL);
  1470. {
  1471. HBoxContainer *lehb = memnew(HBoxContainer);
  1472. Label *l = memnew(Label(TTR("Live Edit Root:")));
  1473. info_left->add_child(l);
  1474. lehb->add_child(live_edit_root);
  1475. le_set = memnew(Button(TTR("Set From Tree")));
  1476. lehb->add_child(le_set);
  1477. le_clear = memnew(Button(TTR("Clear")));
  1478. lehb->add_child(le_clear);
  1479. info_left->add_child(lehb);
  1480. }
  1481. misc->add_child(memnew(VSeparator));
  1482. HBoxContainer *buttons = memnew(HBoxContainer);
  1483. export_csv = memnew(Button(TTR("Export measures as CSV")));
  1484. export_csv->connect_compat("pressed", this, "_export_csv");
  1485. buttons->add_child(export_csv);
  1486. misc->add_child(buttons);
  1487. }
  1488. msgdialog = memnew(AcceptDialog);
  1489. add_child(msgdialog);
  1490. live_debug = true;
  1491. camera_override = OVERRIDE_NONE;
  1492. last_path_id = false;
  1493. error_count = 0;
  1494. warning_count = 0;
  1495. _update_buttons_state();
  1496. }
  1497. ScriptEditorDebugger::~ScriptEditorDebugger() {
  1498. ppeer->set_stream_peer(Ref<StreamPeer>());
  1499. inspector->clear_cache();
  1500. memdelete(scene_tree);
  1501. }