script_editor_debugger.cpp 56 KB

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