script_editor_debugger.cpp 55 KB

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