script_editor_debugger.cpp 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  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-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 "editor_node.h"
  32. #include "editor_profiler.h"
  33. #include "editor_settings.h"
  34. #include "main/performance.h"
  35. #include "project_settings.h"
  36. #include "property_editor.h"
  37. #include "scene/gui/dialogs.h"
  38. #include "scene/gui/label.h"
  39. #include "scene/gui/line_edit.h"
  40. #include "scene/gui/margin_container.h"
  41. #include "scene/gui/rich_text_label.h"
  42. #include "scene/gui/separator.h"
  43. #include "scene/gui/split_container.h"
  44. #include "scene/gui/tab_container.h"
  45. #include "scene/gui/texture_button.h"
  46. #include "scene/gui/tree.h"
  47. class ScriptEditorDebuggerVariables : public Object {
  48. GDCLASS(ScriptEditorDebuggerVariables, Object);
  49. List<PropertyInfo> props;
  50. Map<StringName, Variant> values;
  51. protected:
  52. bool _set(const StringName &p_name, const Variant &p_value) {
  53. return false;
  54. }
  55. bool _get(const StringName &p_name, Variant &r_ret) const {
  56. if (!values.has(p_name))
  57. return false;
  58. r_ret = values[p_name];
  59. return true;
  60. }
  61. void _get_property_list(List<PropertyInfo> *p_list) const {
  62. for (const List<PropertyInfo>::Element *E = props.front(); E; E = E->next())
  63. p_list->push_back(E->get());
  64. }
  65. public:
  66. void clear() {
  67. props.clear();
  68. values.clear();
  69. }
  70. String get_var_value(const String &p_var) const {
  71. for (Map<StringName, Variant>::Element *E = values.front(); E; E = E->next()) {
  72. String v = E->key().operator String().get_slice("/", 1);
  73. if (v == p_var)
  74. return E->get();
  75. }
  76. return "";
  77. }
  78. void add_property(const String &p_name, const Variant &p_value, const PropertyHint &p_hint, const String p_hint_string) {
  79. PropertyInfo pinfo;
  80. pinfo.name = p_name;
  81. pinfo.type = p_value.get_type();
  82. pinfo.hint = p_hint;
  83. pinfo.hint_string = p_hint_string;
  84. props.push_back(pinfo);
  85. values[p_name] = p_value;
  86. }
  87. void update() {
  88. _change_notify();
  89. }
  90. ScriptEditorDebuggerVariables() {
  91. }
  92. };
  93. class ScriptEditorDebuggerInspectedObject : public Object {
  94. GDCLASS(ScriptEditorDebuggerInspectedObject, Object);
  95. protected:
  96. bool _set(const StringName &p_name, const Variant &p_value) {
  97. if (!prop_values.has(p_name))
  98. return false;
  99. emit_signal("value_edited", p_name, p_value);
  100. prop_values[p_name] = p_value;
  101. return true;
  102. }
  103. bool _get(const StringName &p_name, Variant &r_ret) const {
  104. if (!prop_values.has(p_name))
  105. return false;
  106. r_ret = prop_values[p_name];
  107. return true;
  108. }
  109. void _get_property_list(List<PropertyInfo> *p_list) const {
  110. p_list->clear(); //sorry, no want category
  111. for (const List<PropertyInfo>::Element *E = prop_list.front(); E; E = E->next()) {
  112. p_list->push_back(E->get());
  113. }
  114. }
  115. static void _bind_methods() {
  116. ADD_SIGNAL(MethodInfo("value_edited"));
  117. }
  118. public:
  119. ObjectID last_edited_id;
  120. List<PropertyInfo> prop_list;
  121. Map<StringName, Variant> prop_values;
  122. void update() {
  123. _change_notify();
  124. }
  125. void update_single(const char *p_prop) {
  126. _change_notify(p_prop);
  127. }
  128. ScriptEditorDebuggerInspectedObject() { last_edited_id = 0; }
  129. };
  130. void ScriptEditorDebugger::debug_next() {
  131. ERR_FAIL_COND(!breaked);
  132. ERR_FAIL_COND(connection.is_null());
  133. ERR_FAIL_COND(!connection->is_connected_to_host());
  134. Array msg;
  135. msg.push_back("next");
  136. ppeer->put_var(msg);
  137. stack_dump->clear();
  138. inspector->edit(NULL);
  139. }
  140. void ScriptEditorDebugger::debug_step() {
  141. ERR_FAIL_COND(!breaked);
  142. ERR_FAIL_COND(connection.is_null());
  143. ERR_FAIL_COND(!connection->is_connected_to_host());
  144. Array msg;
  145. msg.push_back("step");
  146. ppeer->put_var(msg);
  147. stack_dump->clear();
  148. inspector->edit(NULL);
  149. }
  150. void ScriptEditorDebugger::debug_break() {
  151. ERR_FAIL_COND(breaked);
  152. ERR_FAIL_COND(connection.is_null());
  153. ERR_FAIL_COND(!connection->is_connected_to_host());
  154. Array msg;
  155. msg.push_back("break");
  156. ppeer->put_var(msg);
  157. }
  158. void ScriptEditorDebugger::debug_continue() {
  159. ERR_FAIL_COND(!breaked);
  160. ERR_FAIL_COND(connection.is_null());
  161. ERR_FAIL_COND(!connection->is_connected_to_host());
  162. OS::get_singleton()->enable_for_stealing_focus(EditorNode::get_singleton()->get_child_process_id());
  163. Array msg;
  164. msg.push_back("continue");
  165. ppeer->put_var(msg);
  166. }
  167. void ScriptEditorDebugger::_scene_tree_folded(Object *obj) {
  168. if (updating_scene_tree) {
  169. return;
  170. }
  171. TreeItem *item = Object::cast_to<TreeItem>(obj);
  172. if (!item)
  173. return;
  174. ObjectID id = item->get_metadata(0);
  175. if (item->is_collapsed()) {
  176. unfold_cache.erase(id);
  177. } else {
  178. unfold_cache.insert(id);
  179. }
  180. }
  181. void ScriptEditorDebugger::_scene_tree_selected() {
  182. if (updating_scene_tree) {
  183. return;
  184. }
  185. TreeItem *item = inspect_scene_tree->get_selected();
  186. if (!item) {
  187. return;
  188. }
  189. inspected_object_id = item->get_metadata(0);
  190. Array msg;
  191. msg.push_back("inspect_object");
  192. msg.push_back(inspected_object_id);
  193. ppeer->put_var(msg);
  194. }
  195. void ScriptEditorDebugger::_scene_tree_property_value_edited(const String &p_prop, const Variant &p_value) {
  196. Array msg;
  197. msg.push_back("set_object_property");
  198. msg.push_back(inspected_object_id);
  199. msg.push_back(p_prop);
  200. msg.push_back(p_value);
  201. ppeer->put_var(msg);
  202. inspect_edited_object_timeout = 0.7; //avoid annoyance, don't request soon after editing
  203. }
  204. void ScriptEditorDebugger::_scene_tree_property_select_object(ObjectID p_object) {
  205. inspected_object_id = p_object;
  206. Array msg;
  207. msg.push_back("inspect_object");
  208. msg.push_back(inspected_object_id);
  209. ppeer->put_var(msg);
  210. }
  211. void ScriptEditorDebugger::_scene_tree_request() {
  212. ERR_FAIL_COND(connection.is_null());
  213. ERR_FAIL_COND(!connection->is_connected_to_host());
  214. Array msg;
  215. msg.push_back("request_scene_tree");
  216. ppeer->put_var(msg);
  217. }
  218. void ScriptEditorDebugger::_video_mem_request() {
  219. ERR_FAIL_COND(connection.is_null());
  220. ERR_FAIL_COND(!connection->is_connected_to_host());
  221. Array msg;
  222. msg.push_back("request_video_mem");
  223. ppeer->put_var(msg);
  224. }
  225. Size2 ScriptEditorDebugger::get_minimum_size() const {
  226. Size2 ms = Control::get_minimum_size();
  227. ms.y = MAX(ms.y, 250);
  228. return ms;
  229. }
  230. void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_data) {
  231. if (p_msg == "debug_enter") {
  232. Array msg;
  233. msg.push_back("get_stack_dump");
  234. ppeer->put_var(msg);
  235. ERR_FAIL_COND(p_data.size() != 2);
  236. bool can_continue = p_data[0];
  237. String error = p_data[1];
  238. step->set_disabled(!can_continue);
  239. next->set_disabled(!can_continue);
  240. _set_reason_text(error, MESSAGE_ERROR);
  241. breaked = true;
  242. dobreak->set_disabled(true);
  243. docontinue->set_disabled(false);
  244. emit_signal("breaked", true, can_continue);
  245. OS::get_singleton()->move_window_to_foreground();
  246. if (error != "") {
  247. tabs->set_current_tab(0);
  248. }
  249. profiler->set_enabled(false);
  250. EditorNode::get_singleton()->get_pause_button()->set_pressed(true);
  251. EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  252. } else if (p_msg == "debug_exit") {
  253. breaked = false;
  254. step->set_disabled(true);
  255. next->set_disabled(true);
  256. reason->set_text("");
  257. reason->set_tooltip("");
  258. back->set_disabled(true);
  259. forward->set_disabled(true);
  260. dobreak->set_disabled(false);
  261. docontinue->set_disabled(true);
  262. emit_signal("breaked", false, false, Variant());
  263. //tabs->set_current_tab(0);
  264. profiler->set_enabled(true);
  265. profiler->disable_seeking();
  266. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  267. } else if (p_msg == "message:click_ctrl") {
  268. clicked_ctrl->set_text(p_data[0]);
  269. clicked_ctrl_type->set_text(p_data[1]);
  270. } else if (p_msg == "message:scene_tree") {
  271. inspect_scene_tree->clear();
  272. Map<int, TreeItem *> lv;
  273. updating_scene_tree = true;
  274. for (int i = 0; i < p_data.size(); i += 4) {
  275. TreeItem *p;
  276. int level = p_data[i];
  277. if (level == 0) {
  278. p = NULL;
  279. } else {
  280. ERR_CONTINUE(!lv.has(level - 1));
  281. p = lv[level - 1];
  282. }
  283. TreeItem *it = inspect_scene_tree->create_item(p);
  284. ObjectID id = ObjectID(p_data[i + 3]);
  285. it->set_text(0, p_data[i + 1]);
  286. if (has_icon(p_data[i + 2], "EditorIcons"))
  287. it->set_icon(0, get_icon(p_data[i + 2], "EditorIcons"));
  288. it->set_metadata(0, id);
  289. if (id == inspected_object_id) {
  290. TreeItem *cti = it->get_parent(); //ensure selected is always uncollapsed
  291. while (cti) {
  292. cti->set_collapsed(false);
  293. cti = cti->get_parent();
  294. }
  295. it->select(0);
  296. }
  297. if (p) {
  298. if (!unfold_cache.has(id)) {
  299. it->set_collapsed(true);
  300. }
  301. } else {
  302. if (unfold_cache.has(id)) { //reverse for root
  303. it->set_collapsed(true);
  304. }
  305. }
  306. lv[level] = it;
  307. }
  308. updating_scene_tree = false;
  309. le_clear->set_disabled(false);
  310. le_set->set_disabled(false);
  311. } else if (p_msg == "message:inspect_object") {
  312. ObjectID id = p_data[0];
  313. String type = p_data[1];
  314. Variant path = p_data[2]; //what to do yet, i don't know
  315. int prop_count = p_data[3];
  316. int idx = 4;
  317. if (inspected_object->last_edited_id != id) {
  318. inspected_object->prop_list.clear();
  319. inspected_object->prop_values.clear();
  320. }
  321. for (int i = 0; i < prop_count; i++) {
  322. PropertyInfo pinfo;
  323. pinfo.name = p_data[idx++];
  324. pinfo.type = Variant::Type(int(p_data[idx++]));
  325. pinfo.hint = PropertyHint(int(p_data[idx++]));
  326. pinfo.hint_string = p_data[idx++];
  327. if (pinfo.name.begins_with("*")) {
  328. pinfo.name = pinfo.name.substr(1, pinfo.name.length());
  329. pinfo.usage = PROPERTY_USAGE_CATEGORY;
  330. } else {
  331. pinfo.usage = PROPERTY_USAGE_EDITOR;
  332. }
  333. if (inspected_object->last_edited_id != id) {
  334. //don't update.. it's the same, instead refresh
  335. inspected_object->prop_list.push_back(pinfo);
  336. }
  337. inspected_object->prop_values[pinfo.name] = p_data[idx++];
  338. if (inspected_object->last_edited_id == id) {
  339. //same, just update value, don't rebuild
  340. inspected_object->update_single(pinfo.name.ascii().get_data());
  341. }
  342. }
  343. if (inspected_object->last_edited_id != id) {
  344. //only if different
  345. inspected_object->update();
  346. }
  347. inspected_object->last_edited_id = id;
  348. tabs->set_current_tab(inspect_info->get_index());
  349. inspect_properties->edit(inspected_object);
  350. } else if (p_msg == "message:video_mem") {
  351. vmem_tree->clear();
  352. TreeItem *root = vmem_tree->create_item();
  353. int total = 0;
  354. for (int i = 0; i < p_data.size(); i += 4) {
  355. TreeItem *it = vmem_tree->create_item(root);
  356. String type = p_data[i + 1];
  357. int bytes = p_data[i + 3].operator int();
  358. it->set_text(0, p_data[i + 0]); //path
  359. it->set_text(1, type); //type
  360. it->set_text(2, p_data[i + 2]); //type
  361. it->set_text(3, String::humanize_size(bytes)); //type
  362. total += bytes;
  363. if (has_icon(type, "EditorIcons"))
  364. it->set_icon(0, get_icon(type, "EditorIcons"));
  365. }
  366. vmem_total->set_tooltip(TTR("Bytes:") + " " + itos(total));
  367. vmem_total->set_text(String::humanize_size(total));
  368. } else if (p_msg == "stack_dump") {
  369. stack_dump->clear();
  370. TreeItem *r = stack_dump->create_item();
  371. for (int i = 0; i < p_data.size(); i++) {
  372. Dictionary d = p_data[i];
  373. ERR_CONTINUE(!d.has("function"));
  374. ERR_CONTINUE(!d.has("file"));
  375. ERR_CONTINUE(!d.has("line"));
  376. ERR_CONTINUE(!d.has("id"));
  377. TreeItem *s = stack_dump->create_item(r);
  378. d["frame"] = i;
  379. s->set_metadata(0, d);
  380. //String line = itos(i)+" - "+String(d["file"])+":"+itos(d["line"])+" - at func: "+d["function"];
  381. String line = itos(i) + " - " + String(d["file"]) + ":" + itos(d["line"]);
  382. s->set_text(0, line);
  383. if (i == 0)
  384. s->select(0);
  385. }
  386. } else if (p_msg == "stack_frame_vars") {
  387. variables->clear();
  388. int ofs = 0;
  389. int mcount = p_data[ofs];
  390. ofs++;
  391. for (int i = 0; i < mcount; i++) {
  392. String n = p_data[ofs + i * 2 + 0];
  393. Variant v = p_data[ofs + i * 2 + 1];
  394. PropertyHint h = PROPERTY_HINT_NONE;
  395. String hs = String();
  396. if (n.begins_with("*")) {
  397. n = n.substr(1, n.length());
  398. h = PROPERTY_HINT_OBJECT_ID;
  399. String s = v;
  400. s = s.replace("[", "");
  401. hs = s.get_slice(":", 0);
  402. v = s.get_slice(":", 1).to_int();
  403. }
  404. variables->add_property("members/" + n, v, h, hs);
  405. }
  406. ofs += mcount * 2;
  407. mcount = p_data[ofs];
  408. ofs++;
  409. for (int i = 0; i < mcount; i++) {
  410. String n = p_data[ofs + i * 2 + 0];
  411. Variant v = p_data[ofs + i * 2 + 1];
  412. PropertyHint h = PROPERTY_HINT_NONE;
  413. String hs = String();
  414. if (n.begins_with("*")) {
  415. n = n.substr(1, n.length());
  416. h = PROPERTY_HINT_OBJECT_ID;
  417. String s = v;
  418. s = s.replace("[", "");
  419. hs = s.get_slice(":", 0);
  420. v = s.get_slice(":", 1).to_int();
  421. }
  422. variables->add_property("locals/" + n, v, h, hs);
  423. }
  424. variables->update();
  425. inspector->edit(variables);
  426. } else if (p_msg == "output") {
  427. //OUT
  428. for (int i = 0; i < p_data.size(); i++) {
  429. String t = p_data[i];
  430. //LOG
  431. if (!EditorNode::get_log()->is_visible()) {
  432. if (EditorNode::get_singleton()->are_bottom_panels_hidden()) {
  433. EditorNode::get_singleton()->make_bottom_panel_item_visible(EditorNode::get_log());
  434. }
  435. }
  436. EditorNode::get_log()->add_message(t);
  437. }
  438. } else if (p_msg == "performance") {
  439. Array arr = p_data[0];
  440. Vector<float> p;
  441. p.resize(arr.size());
  442. for (int i = 0; i < arr.size(); i++) {
  443. p[i] = arr[i];
  444. if (i < perf_items.size()) {
  445. float v = p[i];
  446. String vs = rtos(v);
  447. String tt = vs;
  448. switch (Performance::MonitorType((int)perf_items[i]->get_metadata(1))) {
  449. case Performance::MONITOR_TYPE_MEMORY: {
  450. // for the time being, going above GBs is a bad sign.
  451. String unit = "B";
  452. if ((int)v > 1073741824) {
  453. unit = "GB";
  454. v /= 1073741824.0;
  455. } else if ((int)v > 1048576) {
  456. unit = "MB";
  457. v /= 1048576.0;
  458. } else if ((int)v > 1024) {
  459. unit = "KB";
  460. v /= 1024.0;
  461. }
  462. tt += " bytes";
  463. vs = rtos(v) + " " + unit;
  464. } break;
  465. case Performance::MONITOR_TYPE_TIME: {
  466. tt += " seconds";
  467. vs += " s";
  468. } break;
  469. default: {
  470. tt += " " + perf_items[i]->get_text(0);
  471. } break;
  472. }
  473. perf_items[i]->set_text(1, vs);
  474. perf_items[i]->set_tooltip(1, tt);
  475. if (p[i] > perf_max[i])
  476. perf_max[i] = p[i];
  477. }
  478. }
  479. perf_history.push_front(p);
  480. perf_draw->update();
  481. } else if (p_msg == "error") {
  482. Array err = p_data[0];
  483. Array vals;
  484. vals.push_back(err[0]);
  485. vals.push_back(err[1]);
  486. vals.push_back(err[2]);
  487. vals.push_back(err[3]);
  488. bool warning = err[9];
  489. bool e;
  490. String time = String("%d:%02d:%02d:%04d").sprintf(vals, &e);
  491. String txt = time + " - " + (err[8].is_zero() ? String(err[7]) : String(err[8]));
  492. String tooltip = TTR("Type:") + String(warning ? TTR("Warning") : TTR("Error"));
  493. tooltip += "\n" + TTR("Description:") + " " + String(err[8]);
  494. tooltip += "\n" + TTR("Time:") + " " + time;
  495. tooltip += "\nC " + TTR("Error:") + " " + String(err[7]);
  496. tooltip += "\nC " + TTR("Source:") + " " + String(err[5]) + ":" + String(err[6]);
  497. tooltip += "\nC " + TTR("Function:") + " " + String(err[4]);
  498. error_list->add_item(txt, EditorNode::get_singleton()->get_gui_base()->get_icon(warning ? "Warning" : "Error", "EditorIcons"));
  499. error_list->set_item_tooltip(error_list->get_item_count() - 1, tooltip);
  500. int scc = p_data[1];
  501. Array stack;
  502. stack.resize(scc);
  503. for (int i = 0; i < scc; i++) {
  504. stack[i] = p_data[2 + i];
  505. }
  506. error_list->set_item_metadata(error_list->get_item_count() - 1, stack);
  507. error_count++;
  508. /*
  509. int count = p_data[1];
  510. Array cstack;
  511. OutputError oe = errors.front()->get();
  512. packet_peer_stream->put_var(oe.hr);
  513. packet_peer_stream->put_var(oe.min);
  514. packet_peer_stream->put_var(oe.sec);
  515. packet_peer_stream->put_var(oe.msec);
  516. packet_peer_stream->put_var(oe.source_func);
  517. packet_peer_stream->put_var(oe.source_file);
  518. packet_peer_stream->put_var(oe.source_line);
  519. packet_peer_stream->put_var(oe.error);
  520. packet_peer_stream->put_var(oe.error_descr);
  521. packet_peer_stream->put_var(oe.warning);
  522. packet_peer_stream->put_var(oe.callstack);
  523. */
  524. } else if (p_msg == "profile_sig") {
  525. //cache a signature
  526. profiler_signature[p_data[1]] = p_data[0];
  527. } else if (p_msg == "profile_frame" || p_msg == "profile_total") {
  528. EditorProfiler::Metric metric;
  529. metric.valid = true;
  530. metric.frame_number = p_data[0];
  531. metric.frame_time = p_data[1];
  532. metric.idle_time = p_data[2];
  533. metric.physics_time = p_data[3];
  534. metric.physics_frame_time = p_data[4];
  535. int frame_data_amount = p_data[6];
  536. int frame_function_amount = p_data[7];
  537. if (frame_data_amount) {
  538. EditorProfiler::Metric::Category frame_time;
  539. frame_time.signature = "category_frame_time";
  540. frame_time.name = "Frame Time";
  541. frame_time.total_time = metric.frame_time;
  542. EditorProfiler::Metric::Category::Item item;
  543. item.calls = 1;
  544. item.line = 0;
  545. item.name = "Physics Time";
  546. item.total = metric.physics_time;
  547. item.self = item.total;
  548. item.signature = "physics_time";
  549. frame_time.items.push_back(item);
  550. item.name = "Idle Time";
  551. item.total = metric.idle_time;
  552. item.self = item.total;
  553. item.signature = "idle_time";
  554. frame_time.items.push_back(item);
  555. item.name = "Physics Frame Time";
  556. item.total = metric.physics_frame_time;
  557. item.self = item.total;
  558. item.signature = "physics_frame_time";
  559. frame_time.items.push_back(item);
  560. metric.categories.push_back(frame_time);
  561. }
  562. int idx = 8;
  563. for (int i = 0; i < frame_data_amount; i++) {
  564. EditorProfiler::Metric::Category c;
  565. String name = p_data[idx++];
  566. Array values = p_data[idx++];
  567. c.name = name.capitalize();
  568. c.items.resize(values.size() / 2);
  569. c.total_time = 0;
  570. c.signature = "categ::" + name;
  571. for (int i = 0; i < values.size(); i += 2) {
  572. EditorProfiler::Metric::Category::Item item;
  573. item.name = values[i];
  574. item.calls = 1;
  575. item.self = values[i + 1];
  576. item.total = item.self;
  577. item.signature = "categ::" + name + "::" + item.name;
  578. item.name = item.name.capitalize();
  579. c.total_time += item.total;
  580. c.items[i / 2] = item;
  581. }
  582. metric.categories.push_back(c);
  583. }
  584. EditorProfiler::Metric::Category funcs;
  585. funcs.total_time = p_data[5]; //script time
  586. funcs.items.resize(frame_function_amount);
  587. funcs.name = "Script Functions";
  588. funcs.signature = "script_functions";
  589. for (int i = 0; i < frame_function_amount; i++) {
  590. int signature = p_data[idx++];
  591. int calls = p_data[idx++];
  592. float total = p_data[idx++];
  593. float self = p_data[idx++];
  594. EditorProfiler::Metric::Category::Item item;
  595. if (profiler_signature.has(signature)) {
  596. item.signature = profiler_signature[signature];
  597. String name = profiler_signature[signature];
  598. Vector<String> strings = name.split("::");
  599. if (strings.size() == 3) {
  600. item.name = strings[2];
  601. item.script = strings[0];
  602. item.line = strings[1].to_int();
  603. }
  604. } else {
  605. item.name = "SigErr " + itos(signature);
  606. }
  607. item.calls = calls;
  608. item.self = self;
  609. item.total = total;
  610. funcs.items[i] = item;
  611. }
  612. metric.categories.push_back(funcs);
  613. if (p_msg == "profile_frame")
  614. profiler->add_frame_metric(metric, false);
  615. else
  616. profiler->add_frame_metric(metric, true);
  617. } else if (p_msg == "kill_me") {
  618. editor->call_deferred("stop_child_process");
  619. }
  620. }
  621. void ScriptEditorDebugger::_set_reason_text(const String &p_reason, MessageType p_type) {
  622. switch (p_type) {
  623. case MESSAGE_ERROR:
  624. reason->add_color_override("font_color", get_color("error_color", "Editor"));
  625. break;
  626. case MESSAGE_WARNING:
  627. reason->add_color_override("font_color", get_color("warning_color", "Editor"));
  628. break;
  629. default:
  630. reason->add_color_override("font_color", get_color("success_color", "Editor"));
  631. }
  632. reason->set_text(p_reason);
  633. reason->set_tooltip(p_reason);
  634. }
  635. void ScriptEditorDebugger::_performance_select() {
  636. perf_draw->update();
  637. }
  638. void ScriptEditorDebugger::_performance_draw() {
  639. Vector<int> which;
  640. for (int i = 0; i < perf_items.size(); i++) {
  641. if (perf_items[i]->is_checked(0))
  642. which.push_back(i);
  643. }
  644. Ref<Font> graph_font = get_font("font", "TextEdit");
  645. if (which.empty()) {
  646. perf_draw->draw_string(graph_font, Point2(0, graph_font->get_ascent()), TTR("Pick one or more items from the list to display the graph."), get_color("font_color", "Label"), perf_draw->get_size().x);
  647. return;
  648. }
  649. Ref<StyleBox> graph_sb = get_stylebox("normal", "TextEdit");
  650. int cols = Math::ceil(Math::sqrt((float)which.size()));
  651. int rows = Math::ceil((float)which.size() / cols);
  652. if (which.size() == 1)
  653. rows = 1;
  654. int margin = 3;
  655. int point_sep = 5;
  656. Size2i s = Size2i(perf_draw->get_size()) / Size2i(cols, rows);
  657. for (int i = 0; i < which.size(); i++) {
  658. Point2i p(i % cols, i / cols);
  659. Rect2i r(p * s, s);
  660. r.position += Point2(margin, margin);
  661. r.size -= Point2(margin, margin) * 2.0;
  662. perf_draw->draw_style_box(graph_sb, r);
  663. r.position += graph_sb->get_offset();
  664. r.size -= graph_sb->get_minimum_size();
  665. int pi = which[i];
  666. Color c = get_color("accent_color", "Editor");
  667. float h = (float)which[i] / (float)(perf_items.size());
  668. c.set_hsv(Math::fmod(h + 0.4, 0.9), c.get_s() * 0.9, c.get_v() * 1.4);
  669. c.a = 0.6;
  670. perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x);
  671. c.a = 0.9;
  672. 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);
  673. float spacing = point_sep / float(cols);
  674. float from = r.size.width;
  675. List<Vector<float> >::Element *E = perf_history.front();
  676. float prev = -1;
  677. while (from >= 0 && E) {
  678. float m = perf_max[pi];
  679. if (m == 0)
  680. m = 0.00001;
  681. float h = E->get()[pi] / m;
  682. h = (1.0 - h) * r.size.y;
  683. c.a = 0.7;
  684. if (E != perf_history.front())
  685. perf_draw->draw_line(r.position + Point2(from, h), r.position + Point2(from + spacing, prev), c, 2.0);
  686. prev = h;
  687. E = E->next();
  688. from -= spacing;
  689. }
  690. }
  691. }
  692. void ScriptEditorDebugger::_notification(int p_what) {
  693. switch (p_what) {
  694. case NOTIFICATION_ENTER_TREE: {
  695. inspector->edit(variables);
  696. step->set_icon(get_icon("DebugStep", "EditorIcons"));
  697. next->set_icon(get_icon("DebugNext", "EditorIcons"));
  698. back->set_icon(get_icon("Back", "EditorIcons"));
  699. forward->set_icon(get_icon("Forward", "EditorIcons"));
  700. dobreak->set_icon(get_icon("Pause", "EditorIcons"));
  701. docontinue->set_icon(get_icon("DebugContinue", "EditorIcons"));
  702. //scene_tree_refresh->set_icon( get_icon("Reload","EditorIcons"));
  703. le_set->connect("pressed", this, "_live_edit_set");
  704. le_clear->connect("pressed", this, "_live_edit_clear");
  705. error_list->connect("item_selected", this, "_error_selected");
  706. error_stack->connect("item_selected", this, "_error_stack_selected");
  707. vmem_refresh->set_icon(get_icon("Reload", "EditorIcons"));
  708. reason->add_color_override("font_color", get_color("error_color", "Editor"));
  709. } break;
  710. case NOTIFICATION_PROCESS: {
  711. if (connection.is_valid()) {
  712. inspect_scene_tree_timeout -= get_process_delta_time();
  713. if (inspect_scene_tree_timeout < 0) {
  714. inspect_scene_tree_timeout = EditorSettings::get_singleton()->get("debugger/scene_tree_refresh_interval");
  715. if (inspect_scene_tree->is_visible_in_tree()) {
  716. _scene_tree_request();
  717. if (inspected_object_id != 0) {
  718. //take the chance and re-inspect selected object
  719. Array msg;
  720. msg.push_back("inspect_object");
  721. msg.push_back(inspected_object_id);
  722. ppeer->put_var(msg);
  723. }
  724. }
  725. }
  726. inspect_edited_object_timeout -= get_process_delta_time();
  727. if (inspect_edited_object_timeout < 0) {
  728. inspect_edited_object_timeout = EditorSettings::get_singleton()->get("debugger/remote_inspect_refresh_interval");
  729. if (inspect_scene_tree->is_visible_in_tree() && inspected_object_id) {
  730. //take the chance and re-inspect selected object
  731. Array msg;
  732. msg.push_back("inspect_object");
  733. msg.push_back(inspected_object_id);
  734. ppeer->put_var(msg);
  735. }
  736. }
  737. }
  738. if (error_count != last_error_count) {
  739. if (error_count == 0) {
  740. error_split->set_name(TTR("Errors"));
  741. debugger_button->set_text(TTR("Debugger"));
  742. debugger_button->set_icon(Ref<Texture>());
  743. tabs->set_tab_icon(error_split->get_index(), Ref<Texture>());
  744. } else {
  745. error_split->set_name(TTR("Errors") + " (" + itos(error_count) + ")");
  746. debugger_button->set_text(TTR("Debugger") + " (" + itos(error_count) + ")");
  747. debugger_button->set_icon(get_icon("Error", "EditorIcons"));
  748. tabs->set_tab_icon(error_split->get_index(), get_icon("Error", "EditorIcons"));
  749. }
  750. last_error_count = error_count;
  751. }
  752. if (connection.is_null()) {
  753. if (server->is_connection_available()) {
  754. connection = server->take_connection();
  755. if (connection.is_null())
  756. break;
  757. EditorNode::get_log()->add_message("** Debug Process Started **");
  758. ppeer->set_stream_peer(connection);
  759. //EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  760. //emit_signal("show_debugger",true);
  761. dobreak->set_disabled(false);
  762. tabs->set_current_tab(0);
  763. _set_reason_text(TTR("Child Process Connected"), MESSAGE_SUCCESS);
  764. profiler->clear();
  765. inspect_scene_tree->clear();
  766. le_set->set_disabled(true);
  767. le_clear->set_disabled(false);
  768. error_list->clear();
  769. error_stack->clear();
  770. error_count = 0;
  771. profiler_signature.clear();
  772. //live_edit_root->set_text("/root");
  773. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  774. EditorNode::get_singleton()->get_pause_button()->set_disabled(false);
  775. update_live_edit_root();
  776. if (profiler->is_profiling()) {
  777. _profiler_activate(true);
  778. }
  779. } else {
  780. break;
  781. }
  782. };
  783. if (!connection->is_connected_to_host()) {
  784. stop();
  785. editor->notify_child_process_exited(); //somehow, exited
  786. break;
  787. };
  788. if (ppeer->get_available_packet_count() <= 0) {
  789. break;
  790. };
  791. while (ppeer->get_available_packet_count() > 0) {
  792. if (pending_in_queue) {
  793. int todo = MIN(ppeer->get_available_packet_count(), pending_in_queue);
  794. for (int i = 0; i < todo; i++) {
  795. Variant cmd;
  796. Error ret = ppeer->get_var(cmd);
  797. if (ret != OK) {
  798. stop();
  799. ERR_FAIL_COND(ret != OK);
  800. }
  801. message.push_back(cmd);
  802. pending_in_queue--;
  803. }
  804. if (pending_in_queue == 0) {
  805. _parse_message(message_type, message);
  806. message.clear();
  807. }
  808. } else {
  809. if (ppeer->get_available_packet_count() >= 2) {
  810. Variant cmd;
  811. Error ret = ppeer->get_var(cmd);
  812. if (ret != OK) {
  813. stop();
  814. ERR_FAIL_COND(ret != OK);
  815. }
  816. if (cmd.get_type() != Variant::STRING) {
  817. stop();
  818. ERR_FAIL_COND(cmd.get_type() != Variant::STRING);
  819. }
  820. message_type = cmd;
  821. //print_line("GOT: "+message_type);
  822. ret = ppeer->get_var(cmd);
  823. if (ret != OK) {
  824. stop();
  825. ERR_FAIL_COND(ret != OK);
  826. }
  827. if (cmd.get_type() != Variant::INT) {
  828. stop();
  829. ERR_FAIL_COND(cmd.get_type() != Variant::INT);
  830. }
  831. pending_in_queue = cmd;
  832. if (pending_in_queue == 0) {
  833. _parse_message(message_type, Array());
  834. message.clear();
  835. }
  836. } else {
  837. break;
  838. }
  839. }
  840. }
  841. } break;
  842. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  843. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  844. tabs->add_style_override("tab_fg", editor->get_gui_base()->get_stylebox("DebuggerTabFG", "EditorStyles"));
  845. tabs->add_style_override("tab_bg", editor->get_gui_base()->get_stylebox("DebuggerTabBG", "EditorStyles"));
  846. tabs->set_margin(MARGIN_LEFT, -EditorNode::get_singleton()->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT));
  847. tabs->set_margin(MARGIN_RIGHT, EditorNode::get_singleton()->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_RIGHT));
  848. } break;
  849. }
  850. }
  851. void ScriptEditorDebugger::start() {
  852. stop();
  853. if (is_visible_in_tree()) {
  854. EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  855. }
  856. perf_history.clear();
  857. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  858. perf_max[i] = 0;
  859. }
  860. int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
  861. if (server->listen(remote_port) != OK) {
  862. EditorNode::get_log()->add_message(String("Error listening on port ") + itos(remote_port), true);
  863. return;
  864. }
  865. set_process(true);
  866. }
  867. void ScriptEditorDebugger::pause() {
  868. }
  869. void ScriptEditorDebugger::unpause() {
  870. }
  871. void ScriptEditorDebugger::stop() {
  872. set_process(false);
  873. server->stop();
  874. ppeer->set_stream_peer(Ref<StreamPeer>());
  875. if (connection.is_valid()) {
  876. EditorNode::get_log()->add_message("** Debug Process Stopped **");
  877. connection.unref();
  878. }
  879. pending_in_queue = 0;
  880. message.clear();
  881. node_path_cache.clear();
  882. res_path_cache.clear();
  883. profiler_signature.clear();
  884. le_clear->set_disabled(false);
  885. le_set->set_disabled(true);
  886. profiler->set_enabled(true);
  887. inspect_properties->edit(NULL);
  888. inspect_scene_tree->clear();
  889. EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
  890. EditorNode::get_singleton()->get_pause_button()->set_disabled(true);
  891. if (hide_on_stop) {
  892. if (is_visible_in_tree())
  893. EditorNode::get_singleton()->hide_bottom_panel();
  894. emit_signal("show_debugger", false);
  895. }
  896. }
  897. void ScriptEditorDebugger::_profiler_activate(bool p_enable) {
  898. if (!connection.is_valid())
  899. return;
  900. if (p_enable) {
  901. profiler_signature.clear();
  902. Array msg;
  903. msg.push_back("start_profiling");
  904. int max_funcs = EditorSettings::get_singleton()->get("debugger/profiler_frame_max_functions");
  905. max_funcs = CLAMP(max_funcs, 16, 512);
  906. msg.push_back(max_funcs);
  907. ppeer->put_var(msg);
  908. print_line("BEGIN PROFILING!");
  909. } else {
  910. Array msg;
  911. msg.push_back("stop_profiling");
  912. ppeer->put_var(msg);
  913. print_line("END PROFILING!");
  914. }
  915. }
  916. void ScriptEditorDebugger::_profiler_seeked() {
  917. if (!connection.is_valid() || !connection->is_connected_to_host())
  918. return;
  919. if (breaked)
  920. return;
  921. debug_break();
  922. }
  923. void ScriptEditorDebugger::_stack_dump_frame_selected() {
  924. TreeItem *ti = stack_dump->get_selected();
  925. if (!ti)
  926. return;
  927. Dictionary d = ti->get_metadata(0);
  928. stack_script = ResourceLoader::load(d["file"]);
  929. emit_signal("goto_script_line", stack_script, int(d["line"]) - 1);
  930. stack_script.unref();
  931. ERR_FAIL_COND(connection.is_null());
  932. ERR_FAIL_COND(!connection->is_connected_to_host());
  933. ///
  934. Array msg;
  935. msg.push_back("get_stack_frame_vars");
  936. msg.push_back(d["frame"]);
  937. ppeer->put_var(msg);
  938. }
  939. void ScriptEditorDebugger::_output_clear() {
  940. //output->clear();
  941. //output->push_color(Color(0,0,0));
  942. }
  943. String ScriptEditorDebugger::get_var_value(const String &p_var) const {
  944. if (!breaked)
  945. return String();
  946. return variables->get_var_value(p_var);
  947. }
  948. int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) {
  949. const int *r = node_path_cache.getptr(p_path);
  950. if (r)
  951. return *r;
  952. last_path_id++;
  953. node_path_cache[p_path] = last_path_id;
  954. Array msg;
  955. msg.push_back("live_node_path");
  956. msg.push_back(p_path);
  957. msg.push_back(last_path_id);
  958. ppeer->put_var(msg);
  959. return last_path_id;
  960. }
  961. int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) {
  962. Map<String, int>::Element *E = res_path_cache.find(p_path);
  963. if (E)
  964. return E->get();
  965. last_path_id++;
  966. res_path_cache[p_path] = last_path_id;
  967. Array msg;
  968. msg.push_back("live_res_path");
  969. msg.push_back(p_path);
  970. msg.push_back(last_path_id);
  971. ppeer->put_var(msg);
  972. return last_path_id;
  973. }
  974. void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
  975. if (!p_base || !live_debug || !connection.is_valid() || !editor->get_edited_scene())
  976. return;
  977. Node *node = Object::cast_to<Node>(p_base);
  978. VARIANT_ARGPTRS
  979. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  980. //no pointers, sorry
  981. if (argptr[i] && (argptr[i]->get_type() == Variant::OBJECT || argptr[i]->get_type() == Variant::_RID))
  982. return;
  983. }
  984. if (node) {
  985. NodePath path = editor->get_edited_scene()->get_path_to(node);
  986. int pathid = _get_node_path_cache(path);
  987. Array msg;
  988. msg.push_back("live_node_call");
  989. msg.push_back(pathid);
  990. msg.push_back(p_name);
  991. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  992. //no pointers, sorry
  993. msg.push_back(*argptr[i]);
  994. }
  995. ppeer->put_var(msg);
  996. return;
  997. }
  998. Resource *res = Object::cast_to<Resource>(p_base);
  999. if (res && res->get_path() != String()) {
  1000. String respath = res->get_path();
  1001. int pathid = _get_res_path_cache(respath);
  1002. Array msg;
  1003. msg.push_back("live_res_call");
  1004. msg.push_back(pathid);
  1005. msg.push_back(p_name);
  1006. for (int i = 0; i < VARIANT_ARG_MAX; i++) {
  1007. //no pointers, sorry
  1008. msg.push_back(*argptr[i]);
  1009. }
  1010. ppeer->put_var(msg);
  1011. return;
  1012. }
  1013. //print_line("method");
  1014. }
  1015. void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p_property, const Variant &p_value) {
  1016. if (!p_base || !live_debug || !connection.is_valid() || !editor->get_edited_scene())
  1017. return;
  1018. Node *node = Object::cast_to<Node>(p_base);
  1019. if (node) {
  1020. NodePath path = editor->get_edited_scene()->get_path_to(node);
  1021. int pathid = _get_node_path_cache(path);
  1022. if (p_value.is_ref()) {
  1023. Ref<Resource> res = p_value;
  1024. if (res.is_valid() && res->get_path() != String()) {
  1025. Array msg;
  1026. msg.push_back("live_node_prop_res");
  1027. msg.push_back(pathid);
  1028. msg.push_back(p_property);
  1029. msg.push_back(res->get_path());
  1030. ppeer->put_var(msg);
  1031. }
  1032. } else {
  1033. Array msg;
  1034. msg.push_back("live_node_prop");
  1035. msg.push_back(pathid);
  1036. msg.push_back(p_property);
  1037. msg.push_back(p_value);
  1038. ppeer->put_var(msg);
  1039. }
  1040. return;
  1041. }
  1042. Resource *res = Object::cast_to<Resource>(p_base);
  1043. if (res && res->get_path() != String()) {
  1044. String respath = res->get_path();
  1045. int pathid = _get_res_path_cache(respath);
  1046. if (p_value.is_ref()) {
  1047. Ref<Resource> res = p_value;
  1048. if (res.is_valid() && res->get_path() != String()) {
  1049. Array msg;
  1050. msg.push_back("live_res_prop_res");
  1051. msg.push_back(pathid);
  1052. msg.push_back(p_property);
  1053. msg.push_back(res->get_path());
  1054. ppeer->put_var(msg);
  1055. }
  1056. } else {
  1057. Array msg;
  1058. msg.push_back("live_res_prop");
  1059. msg.push_back(pathid);
  1060. msg.push_back(p_property);
  1061. msg.push_back(p_value);
  1062. ppeer->put_var(msg);
  1063. }
  1064. return;
  1065. }
  1066. //print_line("prop");
  1067. }
  1068. void ScriptEditorDebugger::_method_changeds(void *p_ud, Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
  1069. ScriptEditorDebugger *sed = (ScriptEditorDebugger *)p_ud;
  1070. sed->_method_changed(p_base, p_name, VARIANT_ARG_PASS);
  1071. }
  1072. void ScriptEditorDebugger::_property_changeds(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value) {
  1073. ScriptEditorDebugger *sed = (ScriptEditorDebugger *)p_ud;
  1074. sed->_property_changed(p_base, p_property, p_value);
  1075. }
  1076. void ScriptEditorDebugger::set_live_debugging(bool p_enable) {
  1077. live_debug = p_enable;
  1078. }
  1079. void ScriptEditorDebugger::_live_edit_set() {
  1080. if (!connection.is_valid())
  1081. return;
  1082. TreeItem *ti = inspect_scene_tree->get_selected();
  1083. if (!ti)
  1084. return;
  1085. String path;
  1086. while (ti) {
  1087. String lp = ti->get_text(0);
  1088. path = "/" + lp + path;
  1089. ti = ti->get_parent();
  1090. }
  1091. NodePath np = path;
  1092. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  1093. update_live_edit_root();
  1094. }
  1095. void ScriptEditorDebugger::_live_edit_clear() {
  1096. NodePath np = NodePath("/root");
  1097. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  1098. update_live_edit_root();
  1099. }
  1100. void ScriptEditorDebugger::update_live_edit_root() {
  1101. NodePath np = editor->get_editor_data().get_edited_scene_live_edit_root();
  1102. if (connection.is_valid()) {
  1103. Array msg;
  1104. msg.push_back("live_set_root");
  1105. msg.push_back(np);
  1106. if (editor->get_edited_scene())
  1107. msg.push_back(editor->get_edited_scene()->get_filename());
  1108. else
  1109. msg.push_back("");
  1110. ppeer->put_var(msg);
  1111. }
  1112. live_edit_root->set_text(np);
  1113. }
  1114. void ScriptEditorDebugger::live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name) {
  1115. if (live_debug && connection.is_valid()) {
  1116. Array msg;
  1117. msg.push_back("live_create_node");
  1118. msg.push_back(p_parent);
  1119. msg.push_back(p_type);
  1120. msg.push_back(p_name);
  1121. ppeer->put_var(msg);
  1122. }
  1123. }
  1124. void ScriptEditorDebugger::live_debug_instance_node(const NodePath &p_parent, const String &p_path, const String &p_name) {
  1125. if (live_debug && connection.is_valid()) {
  1126. Array msg;
  1127. msg.push_back("live_instance_node");
  1128. msg.push_back(p_parent);
  1129. msg.push_back(p_path);
  1130. msg.push_back(p_name);
  1131. ppeer->put_var(msg);
  1132. }
  1133. }
  1134. void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) {
  1135. if (live_debug && connection.is_valid()) {
  1136. Array msg;
  1137. msg.push_back("live_remove_node");
  1138. msg.push_back(p_at);
  1139. ppeer->put_var(msg);
  1140. }
  1141. }
  1142. void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) {
  1143. if (live_debug && connection.is_valid()) {
  1144. Array msg;
  1145. msg.push_back("live_remove_and_keep_node");
  1146. msg.push_back(p_at);
  1147. msg.push_back(p_keep_id);
  1148. ppeer->put_var(msg);
  1149. }
  1150. }
  1151. void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) {
  1152. if (live_debug && connection.is_valid()) {
  1153. Array msg;
  1154. msg.push_back("live_restore_node");
  1155. msg.push_back(p_id);
  1156. msg.push_back(p_at);
  1157. msg.push_back(p_at_pos);
  1158. ppeer->put_var(msg);
  1159. }
  1160. }
  1161. void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) {
  1162. if (live_debug && connection.is_valid()) {
  1163. Array msg;
  1164. msg.push_back("live_duplicate_node");
  1165. msg.push_back(p_at);
  1166. msg.push_back(p_new_name);
  1167. ppeer->put_var(msg);
  1168. }
  1169. }
  1170. void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) {
  1171. if (live_debug && connection.is_valid()) {
  1172. Array msg;
  1173. msg.push_back("live_reparent_node");
  1174. msg.push_back(p_at);
  1175. msg.push_back(p_new_place);
  1176. msg.push_back(p_new_name);
  1177. msg.push_back(p_at_pos);
  1178. ppeer->put_var(msg);
  1179. }
  1180. }
  1181. void ScriptEditorDebugger::set_breakpoint(const String &p_path, int p_line, bool p_enabled) {
  1182. if (connection.is_valid()) {
  1183. Array msg;
  1184. msg.push_back("breakpoint");
  1185. msg.push_back(p_path);
  1186. msg.push_back(p_line);
  1187. msg.push_back(p_enabled);
  1188. ppeer->put_var(msg);
  1189. }
  1190. }
  1191. void ScriptEditorDebugger::reload_scripts() {
  1192. if (connection.is_valid()) {
  1193. Array msg;
  1194. msg.push_back("reload_scripts");
  1195. ppeer->put_var(msg);
  1196. }
  1197. }
  1198. void ScriptEditorDebugger::_error_selected(int p_idx) {
  1199. error_stack->clear();
  1200. Array st = error_list->get_item_metadata(p_idx);
  1201. for (int i = 0; i < st.size(); i += 2) {
  1202. String script = st[i];
  1203. int line = st[i + 1];
  1204. Array md;
  1205. md.push_back(st[i]);
  1206. md.push_back(st[i + 1]);
  1207. String str = script.get_file() + ":" + itos(line);
  1208. error_stack->add_item(str);
  1209. error_stack->set_item_metadata(error_stack->get_item_count() - 1, md);
  1210. error_stack->set_item_tooltip(error_stack->get_item_count() - 1, TTR("File:") + " " + String(st[i]) + "\n" + TTR("Line:") + " " + itos(line));
  1211. }
  1212. }
  1213. void ScriptEditorDebugger::_error_stack_selected(int p_idx) {
  1214. Array arr = error_stack->get_item_metadata(p_idx);
  1215. if (arr.size() != 2)
  1216. return;
  1217. Ref<Script> s = ResourceLoader::load(arr[0]);
  1218. emit_signal("goto_script_line", s, int(arr[1]) - 1);
  1219. }
  1220. void ScriptEditorDebugger::set_hide_on_stop(bool p_hide) {
  1221. hide_on_stop = p_hide;
  1222. }
  1223. bool ScriptEditorDebugger::get_debug_with_external_editor() const {
  1224. return enable_external_editor;
  1225. }
  1226. void ScriptEditorDebugger::set_debug_with_external_editor(bool p_enabled) {
  1227. enable_external_editor = p_enabled;
  1228. }
  1229. Ref<Script> ScriptEditorDebugger::get_dump_stack_script() const {
  1230. return stack_script;
  1231. }
  1232. void ScriptEditorDebugger::_paused() {
  1233. ERR_FAIL_COND(connection.is_null());
  1234. ERR_FAIL_COND(!connection->is_connected_to_host());
  1235. if (!breaked && EditorNode::get_singleton()->get_pause_button()->is_pressed()) {
  1236. debug_break();
  1237. }
  1238. if (breaked && !EditorNode::get_singleton()->get_pause_button()->is_pressed()) {
  1239. debug_continue();
  1240. }
  1241. }
  1242. void ScriptEditorDebugger::_bind_methods() {
  1243. ClassDB::bind_method(D_METHOD("_stack_dump_frame_selected"), &ScriptEditorDebugger::_stack_dump_frame_selected);
  1244. ClassDB::bind_method(D_METHOD("debug_next"), &ScriptEditorDebugger::debug_next);
  1245. ClassDB::bind_method(D_METHOD("debug_step"), &ScriptEditorDebugger::debug_step);
  1246. ClassDB::bind_method(D_METHOD("debug_break"), &ScriptEditorDebugger::debug_break);
  1247. ClassDB::bind_method(D_METHOD("debug_continue"), &ScriptEditorDebugger::debug_continue);
  1248. ClassDB::bind_method(D_METHOD("_output_clear"), &ScriptEditorDebugger::_output_clear);
  1249. ClassDB::bind_method(D_METHOD("_performance_draw"), &ScriptEditorDebugger::_performance_draw);
  1250. ClassDB::bind_method(D_METHOD("_performance_select"), &ScriptEditorDebugger::_performance_select);
  1251. ClassDB::bind_method(D_METHOD("_scene_tree_request"), &ScriptEditorDebugger::_scene_tree_request);
  1252. ClassDB::bind_method(D_METHOD("_video_mem_request"), &ScriptEditorDebugger::_video_mem_request);
  1253. ClassDB::bind_method(D_METHOD("_live_edit_set"), &ScriptEditorDebugger::_live_edit_set);
  1254. ClassDB::bind_method(D_METHOD("_live_edit_clear"), &ScriptEditorDebugger::_live_edit_clear);
  1255. ClassDB::bind_method(D_METHOD("_error_selected"), &ScriptEditorDebugger::_error_selected);
  1256. ClassDB::bind_method(D_METHOD("_error_stack_selected"), &ScriptEditorDebugger::_error_stack_selected);
  1257. ClassDB::bind_method(D_METHOD("_profiler_activate"), &ScriptEditorDebugger::_profiler_activate);
  1258. ClassDB::bind_method(D_METHOD("_profiler_seeked"), &ScriptEditorDebugger::_profiler_seeked);
  1259. ClassDB::bind_method(D_METHOD("_paused"), &ScriptEditorDebugger::_paused);
  1260. ClassDB::bind_method(D_METHOD("_scene_tree_selected"), &ScriptEditorDebugger::_scene_tree_selected);
  1261. ClassDB::bind_method(D_METHOD("_scene_tree_folded"), &ScriptEditorDebugger::_scene_tree_folded);
  1262. ClassDB::bind_method(D_METHOD("live_debug_create_node"), &ScriptEditorDebugger::live_debug_create_node);
  1263. ClassDB::bind_method(D_METHOD("live_debug_instance_node"), &ScriptEditorDebugger::live_debug_instance_node);
  1264. ClassDB::bind_method(D_METHOD("live_debug_remove_node"), &ScriptEditorDebugger::live_debug_remove_node);
  1265. ClassDB::bind_method(D_METHOD("live_debug_remove_and_keep_node"), &ScriptEditorDebugger::live_debug_remove_and_keep_node);
  1266. ClassDB::bind_method(D_METHOD("live_debug_restore_node"), &ScriptEditorDebugger::live_debug_restore_node);
  1267. ClassDB::bind_method(D_METHOD("live_debug_duplicate_node"), &ScriptEditorDebugger::live_debug_duplicate_node);
  1268. ClassDB::bind_method(D_METHOD("live_debug_reparent_node"), &ScriptEditorDebugger::live_debug_reparent_node);
  1269. ClassDB::bind_method(D_METHOD("_scene_tree_property_select_object"), &ScriptEditorDebugger::_scene_tree_property_select_object);
  1270. ClassDB::bind_method(D_METHOD("_scene_tree_property_value_edited"), &ScriptEditorDebugger::_scene_tree_property_value_edited);
  1271. ADD_SIGNAL(MethodInfo("goto_script_line"));
  1272. ADD_SIGNAL(MethodInfo("breaked", PropertyInfo(Variant::BOOL, "reallydid"), PropertyInfo(Variant::BOOL, "can_debug")));
  1273. ADD_SIGNAL(MethodInfo("show_debugger", PropertyInfo(Variant::BOOL, "reallydid")));
  1274. }
  1275. ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
  1276. ppeer = Ref<PacketPeerStream>(memnew(PacketPeerStream));
  1277. ppeer->set_input_buffer_max_size(1024 * 1024 * 8); //8mb should be enough
  1278. editor = p_editor;
  1279. tabs = memnew(TabContainer);
  1280. tabs->set_tab_align(TabContainer::ALIGN_LEFT);
  1281. tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles"));
  1282. tabs->add_style_override("tab_fg", editor->get_gui_base()->get_stylebox("DebuggerTabFG", "EditorStyles"));
  1283. tabs->add_style_override("tab_bg", editor->get_gui_base()->get_stylebox("DebuggerTabBG", "EditorStyles"));
  1284. tabs->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  1285. tabs->set_margin(MARGIN_LEFT, -editor->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT));
  1286. tabs->set_margin(MARGIN_RIGHT, editor->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_RIGHT));
  1287. add_child(tabs);
  1288. { //debugger
  1289. VBoxContainer *vbc = memnew(VBoxContainer);
  1290. vbc->set_name(TTR("Debugger"));
  1291. //tabs->add_child(vbc);
  1292. Control *dbg = vbc;
  1293. HBoxContainer *hbc = memnew(HBoxContainer);
  1294. vbc->add_child(hbc);
  1295. reason = memnew(Label);
  1296. reason->set_text("");
  1297. hbc->add_child(reason);
  1298. reason->set_h_size_flags(SIZE_EXPAND_FILL);
  1299. hbc->add_child(memnew(VSeparator));
  1300. step = memnew(ToolButton);
  1301. hbc->add_child(step);
  1302. step->set_tooltip(TTR("Step Into"));
  1303. step->connect("pressed", this, "debug_step");
  1304. next = memnew(ToolButton);
  1305. hbc->add_child(next);
  1306. next->set_tooltip(TTR("Step Over"));
  1307. next->connect("pressed", this, "debug_next");
  1308. hbc->add_child(memnew(VSeparator));
  1309. dobreak = memnew(ToolButton);
  1310. hbc->add_child(dobreak);
  1311. dobreak->set_tooltip(TTR("Break"));
  1312. dobreak->connect("pressed", this, "debug_break");
  1313. docontinue = memnew(ToolButton);
  1314. hbc->add_child(docontinue);
  1315. docontinue->set_tooltip(TTR("Continue"));
  1316. docontinue->connect("pressed", this, "debug_continue");
  1317. back = memnew(Button);
  1318. hbc->add_child(back);
  1319. back->set_tooltip(TTR("Inspect Previous Instance"));
  1320. back->hide();
  1321. forward = memnew(Button);
  1322. hbc->add_child(forward);
  1323. forward->set_tooltip(TTR("Inspect Next Instance"));
  1324. forward->hide();
  1325. HSplitContainer *sc = memnew(HSplitContainer);
  1326. vbc->add_child(sc);
  1327. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  1328. stack_dump = memnew(Tree);
  1329. stack_dump->set_columns(1);
  1330. stack_dump->set_column_titles_visible(true);
  1331. stack_dump->set_column_title(0, TTR("Stack Frames"));
  1332. stack_dump->set_h_size_flags(SIZE_EXPAND_FILL);
  1333. stack_dump->set_hide_root(true);
  1334. stack_dump->connect("cell_selected", this, "_stack_dump_frame_selected");
  1335. sc->add_child(stack_dump);
  1336. inspector = memnew(PropertyEditor);
  1337. inspector->set_h_size_flags(SIZE_EXPAND_FILL);
  1338. inspector->hide_top_label();
  1339. inspector->get_scene_tree()->set_column_title(0, TTR("Variable"));
  1340. inspector->set_enable_capitalize_paths(false);
  1341. inspector->set_read_only(true);
  1342. inspector->connect("object_id_selected", this, "_scene_tree_property_select_object");
  1343. sc->add_child(inspector);
  1344. server = TCP_Server::create_ref();
  1345. pending_in_queue = 0;
  1346. variables = memnew(ScriptEditorDebuggerVariables);
  1347. breaked = false;
  1348. tabs->add_child(dbg);
  1349. }
  1350. { //errors
  1351. error_split = memnew(HSplitContainer);
  1352. VBoxContainer *errvb = memnew(VBoxContainer);
  1353. errvb->set_h_size_flags(SIZE_EXPAND_FILL);
  1354. error_list = memnew(ItemList);
  1355. errvb->add_margin_child(TTR("Errors:"), error_list, true);
  1356. error_split->add_child(errvb);
  1357. errvb = memnew(VBoxContainer);
  1358. errvb->set_h_size_flags(SIZE_EXPAND_FILL);
  1359. error_stack = memnew(ItemList);
  1360. errvb->add_margin_child(TTR("Stack Trace (if applicable):"), error_stack, true);
  1361. error_split->add_child(errvb);
  1362. error_split->set_name(TTR("Errors"));
  1363. tabs->add_child(error_split);
  1364. }
  1365. { // inquire
  1366. inspect_info = memnew(HSplitContainer);
  1367. inspect_info->set_name(TTR("Remote Inspector"));
  1368. tabs->add_child(inspect_info);
  1369. VBoxContainer *info_left = memnew(VBoxContainer);
  1370. info_left->set_h_size_flags(SIZE_EXPAND_FILL);
  1371. inspect_info->add_child(info_left);
  1372. inspect_scene_tree = memnew(Tree);
  1373. info_left->add_margin_child(TTR("Live Scene Tree:"), inspect_scene_tree, true);
  1374. inspect_scene_tree->connect("cell_selected", this, "_scene_tree_selected");
  1375. inspect_scene_tree->connect("item_collapsed", this, "_scene_tree_folded");
  1376. //
  1377. VBoxContainer *info_right = memnew(VBoxContainer);
  1378. info_right->set_h_size_flags(SIZE_EXPAND_FILL);
  1379. inspect_info->add_child(info_right);
  1380. inspect_properties = memnew(PropertyEditor);
  1381. inspect_properties->hide_top_label();
  1382. inspect_properties->set_show_categories(true);
  1383. inspect_properties->connect("object_id_selected", this, "_scene_tree_property_select_object");
  1384. info_right->add_margin_child(TTR("Remote Object Properties: "), inspect_properties, true);
  1385. inspect_scene_tree_timeout = EDITOR_DEF("debugger/scene_tree_refresh_interval", 1.0);
  1386. inspect_edited_object_timeout = EDITOR_DEF("debugger/remote_inspect_refresh_interval", 0.2);
  1387. inspected_object_id = 0;
  1388. updating_scene_tree = false;
  1389. inspected_object = memnew(ScriptEditorDebuggerInspectedObject);
  1390. inspected_object->connect("value_edited", this, "_scene_tree_property_value_edited");
  1391. }
  1392. { //profiler
  1393. profiler = memnew(EditorProfiler);
  1394. profiler->set_name(TTR("Profiler"));
  1395. tabs->add_child(profiler);
  1396. profiler->connect("enable_profiling", this, "_profiler_activate");
  1397. profiler->connect("break_request", this, "_profiler_seeked");
  1398. }
  1399. { //monitors
  1400. HSplitContainer *hsp = memnew(HSplitContainer);
  1401. perf_monitors = memnew(Tree);
  1402. perf_monitors->set_columns(2);
  1403. perf_monitors->set_column_title(0, TTR("Monitor"));
  1404. perf_monitors->set_column_title(1, TTR("Value"));
  1405. perf_monitors->set_column_titles_visible(true);
  1406. hsp->add_child(perf_monitors);
  1407. perf_monitors->connect("item_edited", this, "_performance_select");
  1408. perf_draw = memnew(Control);
  1409. perf_draw->connect("draw", this, "_performance_draw");
  1410. hsp->add_child(perf_draw);
  1411. hsp->set_name(TTR("Monitors"));
  1412. hsp->set_split_offset(340 * EDSCALE);
  1413. tabs->add_child(hsp);
  1414. perf_max.resize(Performance::MONITOR_MAX);
  1415. Map<String, TreeItem *> bases;
  1416. TreeItem *root = perf_monitors->create_item();
  1417. perf_monitors->set_hide_root(true);
  1418. for (int i = 0; i < Performance::MONITOR_MAX; i++) {
  1419. String n = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  1420. Performance::MonitorType mtype = Performance::get_singleton()->get_monitor_type(Performance::Monitor(i));
  1421. String base = n.get_slice("/", 0);
  1422. String name = n.get_slice("/", 1);
  1423. if (!bases.has(base)) {
  1424. TreeItem *b = perf_monitors->create_item(root);
  1425. b->set_text(0, base.capitalize());
  1426. b->set_editable(0, false);
  1427. b->set_selectable(0, false);
  1428. b->set_expand_right(0, true);
  1429. bases[base] = b;
  1430. }
  1431. TreeItem *it = perf_monitors->create_item(bases[base]);
  1432. it->set_metadata(1, mtype);
  1433. it->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  1434. it->set_editable(0, true);
  1435. it->set_selectable(0, false);
  1436. it->set_selectable(1, false);
  1437. it->set_text(0, name.capitalize());
  1438. perf_items.push_back(it);
  1439. perf_max[i] = 0;
  1440. }
  1441. }
  1442. { //vmem inspect
  1443. VBoxContainer *vmem_vb = memnew(VBoxContainer);
  1444. HBoxContainer *vmem_hb = memnew(HBoxContainer);
  1445. Label *vmlb = memnew(Label(TTR("List of Video Memory Usage by Resource:") + " "));
  1446. vmlb->set_h_size_flags(SIZE_EXPAND_FILL);
  1447. vmem_hb->add_child(vmlb);
  1448. vmem_hb->add_child(memnew(Label(TTR("Total:") + " ")));
  1449. vmem_total = memnew(LineEdit);
  1450. vmem_total->set_editable(false);
  1451. vmem_total->set_custom_minimum_size(Size2(100, 1) * EDSCALE);
  1452. vmem_hb->add_child(vmem_total);
  1453. vmem_refresh = memnew(ToolButton);
  1454. vmem_hb->add_child(vmem_refresh);
  1455. vmem_vb->add_child(vmem_hb);
  1456. vmem_refresh->connect("pressed", this, "_video_mem_request");
  1457. VBoxContainer *vmmc = memnew(VBoxContainer);
  1458. vmem_tree = memnew(Tree);
  1459. vmem_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1460. vmem_tree->set_h_size_flags(SIZE_EXPAND_FILL);
  1461. vmmc->add_child(vmem_tree);
  1462. vmmc->set_v_size_flags(SIZE_EXPAND_FILL);
  1463. vmem_vb->add_child(vmmc);
  1464. vmem_vb->set_name(TTR("Video Mem"));
  1465. vmem_tree->set_columns(4);
  1466. vmem_tree->set_column_titles_visible(true);
  1467. vmem_tree->set_column_title(0, TTR("Resource Path"));
  1468. vmem_tree->set_column_expand(0, true);
  1469. vmem_tree->set_column_expand(1, false);
  1470. vmem_tree->set_column_title(1, TTR("Type"));
  1471. vmem_tree->set_column_min_width(1, 100);
  1472. vmem_tree->set_column_expand(2, false);
  1473. vmem_tree->set_column_title(2, TTR("Format"));
  1474. vmem_tree->set_column_min_width(2, 150);
  1475. vmem_tree->set_column_expand(3, false);
  1476. vmem_tree->set_column_title(3, TTR("Usage"));
  1477. vmem_tree->set_column_min_width(3, 80);
  1478. vmem_tree->set_hide_root(true);
  1479. tabs->add_child(vmem_vb);
  1480. }
  1481. { // misc
  1482. GridContainer *info_left = memnew(GridContainer);
  1483. info_left->set_columns(2);
  1484. info_left->set_name(TTR("Misc"));
  1485. tabs->add_child(info_left);
  1486. clicked_ctrl = memnew(LineEdit);
  1487. clicked_ctrl->set_h_size_flags(SIZE_EXPAND_FILL);
  1488. info_left->add_child(memnew(Label(TTR("Clicked Control:"))));
  1489. info_left->add_child(clicked_ctrl);
  1490. clicked_ctrl_type = memnew(LineEdit);
  1491. info_left->add_child(memnew(Label(TTR("Clicked Control Type:"))));
  1492. info_left->add_child(clicked_ctrl_type);
  1493. live_edit_root = memnew(LineEdit);
  1494. live_edit_root->set_h_size_flags(SIZE_EXPAND_FILL);
  1495. {
  1496. HBoxContainer *lehb = memnew(HBoxContainer);
  1497. Label *l = memnew(Label(TTR("Live Edit Root:")));
  1498. info_left->add_child(l);
  1499. lehb->add_child(live_edit_root);
  1500. le_set = memnew(Button(TTR("Set From Tree")));
  1501. lehb->add_child(le_set);
  1502. le_clear = memnew(Button(TTR("Clear")));
  1503. lehb->add_child(le_clear);
  1504. info_left->add_child(lehb);
  1505. le_set->set_disabled(true);
  1506. le_clear->set_disabled(true);
  1507. }
  1508. }
  1509. msgdialog = memnew(AcceptDialog);
  1510. add_child(msgdialog);
  1511. p_editor->get_undo_redo()->set_method_notify_callback(_method_changeds, this);
  1512. p_editor->get_undo_redo()->set_property_notify_callback(_property_changeds, this);
  1513. live_debug = false;
  1514. last_path_id = false;
  1515. error_count = 0;
  1516. hide_on_stop = true;
  1517. enable_external_editor = false;
  1518. last_error_count = 0;
  1519. EditorNode::get_singleton()->get_pause_button()->connect("pressed", this, "_paused");
  1520. }
  1521. ScriptEditorDebugger::~ScriptEditorDebugger() {
  1522. //inspector->edit(NULL);
  1523. memdelete(variables);
  1524. ppeer->set_stream_peer(Ref<StreamPeer>());
  1525. server->stop();
  1526. memdelete(inspected_object);
  1527. }