script_editor_debugger.cpp 74 KB

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