script_editor_debugger.cpp 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  1. /*************************************************************************/
  2. /* script_editor_debugger.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "script_editor_debugger.h"
  30. #include "scene/gui/separator.h"
  31. #include "scene/gui/label.h"
  32. #include "scene/gui/split_container.h"
  33. #include "scene/gui/tree.h"
  34. #include "scene/gui/texture_button.h"
  35. #include "scene/gui/tab_container.h"
  36. #include "scene/gui/line_edit.h"
  37. #include "scene/gui/dialogs.h"
  38. #include "scene/gui/rich_text_label.h"
  39. #include "scene/gui/margin_container.h"
  40. #include "property_editor.h"
  41. #include "globals.h"
  42. #include "editor_node.h"
  43. #include "main/performance.h"
  44. class ScriptEditorDebuggerVariables : public Object {
  45. OBJ_TYPE( ScriptEditorDebuggerVariables, Object );
  46. List<PropertyInfo> props;
  47. Map<StringName,Variant> values;
  48. protected:
  49. bool _set(const StringName& p_name, const Variant& p_value) {
  50. return false;
  51. }
  52. bool _get(const StringName& p_name,Variant &r_ret) const {
  53. if (!values.has(p_name))
  54. return false;
  55. r_ret=values[p_name];
  56. return true;
  57. }
  58. void _get_property_list( List<PropertyInfo> *p_list) const {
  59. for(const List<PropertyInfo>::Element *E=props.front();E;E=E->next() )
  60. p_list->push_back(E->get());
  61. }
  62. public:
  63. void clear() {
  64. props.clear();
  65. values.clear();
  66. }
  67. String get_var_value(const String& p_var) const {
  68. for(Map<StringName,Variant>::Element *E=values.front();E;E=E->next()) {
  69. String v = E->key().operator String().get_slice("/",1);
  70. if (v==p_var)
  71. return E->get();
  72. }
  73. return "";
  74. }
  75. void add_property(const String &p_name, const Variant& p_value) {
  76. PropertyInfo pinfo;
  77. pinfo.name=p_name;
  78. pinfo.type=p_value.get_type();
  79. props.push_back(pinfo);
  80. values[p_name]=p_value;
  81. }
  82. void update() {
  83. _change_notify();
  84. }
  85. ScriptEditorDebuggerVariables() {
  86. }
  87. };
  88. void ScriptEditorDebugger::debug_next() {
  89. ERR_FAIL_COND(!breaked);
  90. ERR_FAIL_COND(connection.is_null());
  91. ERR_FAIL_COND(!connection->is_connected());
  92. Array msg;
  93. msg.push_back("next");
  94. ppeer->put_var(msg);
  95. stack_dump->clear();
  96. inspector->edit(NULL);
  97. }
  98. void ScriptEditorDebugger::debug_step() {
  99. ERR_FAIL_COND(!breaked);
  100. ERR_FAIL_COND(connection.is_null());
  101. ERR_FAIL_COND(!connection->is_connected());
  102. Array msg;
  103. msg.push_back("step");
  104. ppeer->put_var(msg);
  105. stack_dump->clear();
  106. inspector->edit(NULL);
  107. }
  108. void ScriptEditorDebugger::debug_break() {
  109. ERR_FAIL_COND(breaked);
  110. ERR_FAIL_COND(connection.is_null());
  111. ERR_FAIL_COND(!connection->is_connected());
  112. Array msg;
  113. msg.push_back("break");
  114. ppeer->put_var(msg);
  115. }
  116. void ScriptEditorDebugger::debug_continue() {
  117. ERR_FAIL_COND(!breaked);
  118. ERR_FAIL_COND(connection.is_null());
  119. ERR_FAIL_COND(!connection->is_connected());
  120. Array msg;
  121. msg.push_back("continue");
  122. ppeer->put_var(msg);
  123. }
  124. void ScriptEditorDebugger::_scene_tree_request() {
  125. ERR_FAIL_COND(connection.is_null());
  126. ERR_FAIL_COND(!connection->is_connected());
  127. Array msg;
  128. msg.push_back("request_scene_tree");
  129. ppeer->put_var(msg);
  130. }
  131. void ScriptEditorDebugger::_video_mem_request() {
  132. ERR_FAIL_COND(connection.is_null());
  133. ERR_FAIL_COND(!connection->is_connected());
  134. Array msg;
  135. msg.push_back("request_video_mem");
  136. ppeer->put_var(msg);
  137. }
  138. Size2 ScriptEditorDebugger::get_minimum_size() const {
  139. Size2 ms = Control::get_minimum_size();
  140. ms.y = MAX(ms.y , 250 );
  141. return ms;
  142. }
  143. void ScriptEditorDebugger::_parse_message(const String& p_msg,const Array& p_data) {
  144. if (p_msg=="debug_enter") {
  145. Array msg;
  146. msg.push_back("get_stack_dump");
  147. ppeer->put_var(msg);
  148. ERR_FAIL_COND(p_data.size()!=2);
  149. bool can_continue=p_data[0];
  150. String error = p_data[1];
  151. step->set_disabled(!can_continue);
  152. next->set_disabled(!can_continue);
  153. reason->set_text(error);
  154. reason->set_tooltip(error);
  155. breaked=true;
  156. dobreak->set_disabled(true);
  157. docontinue->set_disabled(false);
  158. emit_signal("breaked",true,can_continue);
  159. OS::get_singleton()->move_window_to_foreground();
  160. tabs->set_current_tab(0);
  161. EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  162. } else if (p_msg=="debug_exit") {
  163. breaked=false;
  164. step->set_disabled(true);
  165. next->set_disabled(true);
  166. reason->set_text("");
  167. reason->set_tooltip("");
  168. back->set_disabled(true);
  169. forward->set_disabled(true);
  170. dobreak->set_disabled(false);
  171. docontinue->set_disabled(true);
  172. emit_signal("breaked",false,false);
  173. //tabs->set_current_tab(0);
  174. } else if (p_msg=="message:click_ctrl") {
  175. clicked_ctrl->set_text(p_data[0]);
  176. clicked_ctrl_type->set_text(p_data[1]);
  177. } else if (p_msg=="message:scene_tree") {
  178. scene_tree->clear();
  179. Map<int,TreeItem*> lv;
  180. for(int i=0;i<p_data.size();i+=3) {
  181. TreeItem *p;
  182. int level = p_data[i];
  183. if (level==0) {
  184. p = NULL;
  185. } else {
  186. ERR_CONTINUE(!lv.has(level-1));
  187. p=lv[level-1];
  188. }
  189. TreeItem *it = scene_tree->create_item(p);
  190. it->set_text(0,p_data[i+1]);
  191. if (has_icon(p_data[i+2],"EditorIcons"))
  192. it->set_icon(0,get_icon(p_data[i+2],"EditorIcons"));
  193. lv[level]=it;
  194. }
  195. le_clear->set_disabled(false);
  196. le_set->set_disabled(false);
  197. } else if (p_msg=="message:video_mem") {
  198. vmem_tree->clear();
  199. TreeItem* root=vmem_tree->create_item();
  200. int total=0;
  201. for(int i=0;i<p_data.size();i+=4) {
  202. TreeItem *it = vmem_tree->create_item(root);
  203. String type=p_data[i+1];
  204. int bytes=p_data[i+3].operator int();
  205. it->set_text(0,p_data[i+0]); //path
  206. it->set_text(1,type); //type
  207. it->set_text(2,p_data[i+2]); //type
  208. it->set_text(3,String::humanize_size(bytes)); //type
  209. total+=bytes;
  210. if (has_icon(type,"EditorIcons"))
  211. it->set_icon(0,get_icon(type,"EditorIcons"));
  212. }
  213. vmem_total->set_tooltip(TTR("Bytes:")+" "+itos(total));
  214. vmem_total->set_text(String::humanize_size(total));
  215. } else if (p_msg=="stack_dump") {
  216. stack_dump->clear();
  217. TreeItem *r = stack_dump->create_item();
  218. for(int i=0;i<p_data.size();i++) {
  219. Dictionary d = p_data[i];
  220. ERR_CONTINUE(!d.has("function"));
  221. ERR_CONTINUE(!d.has("file"));
  222. ERR_CONTINUE(!d.has("line"));
  223. ERR_CONTINUE(!d.has("id"));
  224. TreeItem *s = stack_dump->create_item(r);
  225. d["frame"]=i;
  226. s->set_metadata(0,d);
  227. // String line = itos(i)+" - "+String(d["file"])+":"+itos(d["line"])+" - at func: "+d["function"];
  228. String line = itos(i)+" - "+String(d["file"])+":"+itos(d["line"]);
  229. s->set_text(0,line);
  230. if (i==0)
  231. s->select(0);
  232. }
  233. } else if (p_msg=="stack_frame_vars") {
  234. variables->clear();
  235. int ofs =0;
  236. int mcount = p_data[ofs];
  237. ofs++;
  238. for(int i=0;i<mcount;i++) {
  239. String n = p_data[ofs+i*2+0];
  240. Variant v = p_data[ofs+i*2+1];
  241. if (n.begins_with("*")) {
  242. n=n.substr(1,n.length());
  243. }
  244. variables->add_property("members/"+n,v);
  245. }
  246. ofs+=mcount*2;
  247. mcount = p_data[ofs];
  248. ofs++;
  249. for(int i=0;i<mcount;i++) {
  250. String n = p_data[ofs+i*2+0];
  251. Variant v = p_data[ofs+i*2+1];
  252. if (n.begins_with("*")) {
  253. n=n.substr(1,n.length());
  254. }
  255. variables->add_property("locals/"+n,v);
  256. }
  257. variables->update();
  258. inspector->edit(variables);
  259. } else if (p_msg=="output") {
  260. //OUT
  261. for(int i=0;i<p_data.size();i++) {
  262. String t = p_data[i];
  263. //LOG
  264. if (EditorNode::get_log()->is_hidden()) {
  265. log_forced_visible=true;
  266. if (EditorNode::get_singleton()->are_bottom_panels_hidden()) {
  267. EditorNode::get_singleton()->make_bottom_panel_item_visible(EditorNode::get_log());
  268. }
  269. }
  270. EditorNode::get_log()->add_message(t);
  271. }
  272. } else if (p_msg=="performance") {
  273. Array arr = p_data[0];
  274. Vector<float> p;
  275. p.resize(arr.size());
  276. for(int i=0;i<arr.size();i++) {
  277. p[i]=arr[i];
  278. if (i<perf_items.size()) {
  279. perf_items[i]->set_text(1,rtos(p[i]));
  280. if (p[i]>perf_max[i])
  281. perf_max[i]=p[i];
  282. }
  283. }
  284. perf_history.push_front(p);
  285. perf_draw->update();
  286. } else if (p_msg=="error") {
  287. Array err = p_data[0];
  288. Array vals;
  289. vals.push_back(err[0]);
  290. vals.push_back(err[1]);
  291. vals.push_back(err[2]);
  292. vals.push_back(err[3]);
  293. bool warning = err[9];
  294. bool e;
  295. String time = String("%d:%02d:%02d:%04d").sprintf(vals,&e);
  296. String txt=time+" - "+String(err[8]);
  297. String tooltip=TTR("Type:")+String(warning?TTR("Warning"):TTR("Error"));
  298. tooltip+="\n"+TTR("Description:")+" "+String(err[8]);
  299. tooltip+="\n"+TTR("Time:")+" "+time;
  300. tooltip+="\nC "+TTR("Error:")+" "+String(err[7]);
  301. tooltip+="\nC "+TTR("Source:")+" "+String(err[5])+":"+String(err[6]);
  302. tooltip+="\nC "+TTR("Function:")+" "+String(err[4]);
  303. error_list->add_item(txt,EditorNode::get_singleton()->get_gui_base()->get_icon(warning?"Warning":"Error","EditorIcons"));
  304. error_list->set_item_tooltip( error_list->get_item_count() -1,tooltip );
  305. int scc = p_data[1];
  306. Array stack;
  307. stack.resize(scc);
  308. for(int i=0;i<scc;i++) {
  309. stack[i]=p_data[2+i];
  310. }
  311. error_list->set_item_metadata( error_list->get_item_count() -1,stack );
  312. error_count++;
  313. /*
  314. int count = p_data[1];
  315. Array cstack;
  316. OutputError oe = errors.front()->get();
  317. packet_peer_stream->put_var(oe.hr);
  318. packet_peer_stream->put_var(oe.min);
  319. packet_peer_stream->put_var(oe.sec);
  320. packet_peer_stream->put_var(oe.msec);
  321. packet_peer_stream->put_var(oe.source_func);
  322. packet_peer_stream->put_var(oe.source_file);
  323. packet_peer_stream->put_var(oe.source_line);
  324. packet_peer_stream->put_var(oe.error);
  325. packet_peer_stream->put_var(oe.error_descr);
  326. packet_peer_stream->put_var(oe.warning);
  327. packet_peer_stream->put_var(oe.callstack);
  328. */
  329. } else if (p_msg=="kill_me") {
  330. editor->call_deferred("stop_child_process");
  331. }
  332. }
  333. void ScriptEditorDebugger::_performance_select(Object*,int,bool) {
  334. perf_draw->update();
  335. }
  336. void ScriptEditorDebugger::_performance_draw() {
  337. Vector<int> which;
  338. for(int i=0;i<perf_items.size();i++) {
  339. if (perf_items[i]->is_selected(0))
  340. which.push_back(i);
  341. }
  342. if(which.empty())
  343. return;
  344. Color graph_color=get_color("font_color","TextEdit");
  345. Ref<StyleBox> graph_sb = get_stylebox("normal","TextEdit");
  346. Ref<Font> graph_font = get_font("font","TextEdit");
  347. int cols = Math::ceil(Math::sqrt(which.size()));
  348. int rows = (which.size()+1)/cols;
  349. if (which.size()==1)
  350. rows=1;
  351. int margin =3;
  352. int point_sep=5;
  353. Size2i s = Size2i(perf_draw->get_size())/Size2i(cols,rows);
  354. for(int i=0;i<which.size();i++) {
  355. Point2i p(i%cols,i/cols);
  356. Rect2i r(p*s,s);
  357. r.pos+=Point2(margin,margin);
  358. r.size-=Point2(margin,margin)*2.0;
  359. perf_draw->draw_style_box(graph_sb,r);
  360. r.pos+=graph_sb->get_offset();
  361. r.size-=graph_sb->get_minimum_size();
  362. int pi=which[i];
  363. Color c = Color(0.7,0.9,0.5);
  364. c.set_hsv(Math::fmod(c.get_h()+pi*0.7654,1),c.get_s(),c.get_v());
  365. c.a=0.8;
  366. perf_draw->draw_string(graph_font,r.pos+Point2(0,graph_font->get_ascent()),perf_items[pi]->get_text(0),c,r.size.x);
  367. c.a=0.6;
  368. 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);
  369. float spacing=point_sep/float(cols);
  370. float from = r.size.width;
  371. List<Vector<float> >::Element *E=perf_history.front();
  372. float prev=-1;
  373. while(from>=0 && E) {
  374. float m = perf_max[pi];
  375. if (m==0)
  376. m=0.00001;
  377. float h = E->get()[pi]/m;
  378. h=(1.0-h)*r.size.y;
  379. c.a=0.7;
  380. if (E!=perf_history.front())
  381. perf_draw->draw_line(r.pos+Point2(from,h),r.pos+Point2(from+spacing,prev),c,2.0);
  382. prev=h;
  383. E=E->next();
  384. from-=spacing;
  385. }
  386. }
  387. }
  388. void ScriptEditorDebugger::_notification(int p_what) {
  389. switch(p_what) {
  390. case NOTIFICATION_ENTER_TREE: {
  391. inspector->edit(variables);
  392. step->set_icon( get_icon("DebugStep","EditorIcons"));
  393. next->set_icon( get_icon("DebugNext","EditorIcons"));
  394. back->set_icon( get_icon("Back","EditorIcons"));
  395. forward->set_icon( get_icon("Forward","EditorIcons"));
  396. dobreak->set_icon( get_icon("Pause","EditorIcons"));
  397. docontinue->set_icon( get_icon("DebugContinue","EditorIcons"));
  398. scene_tree_refresh->set_icon( get_icon("Reload","EditorIcons"));
  399. le_set->connect("pressed",this,"_live_edit_set");
  400. le_clear->connect("pressed",this,"_live_edit_clear");
  401. error_list->connect("item_selected",this,"_error_selected");
  402. error_stack->connect("item_selected",this,"_error_stack_selected");
  403. vmem_refresh->set_icon( get_icon("Reload","EditorIcons"));
  404. } break;
  405. case NOTIFICATION_PROCESS: {
  406. if (error_count!=last_error_count) {
  407. if (error_count==0) {
  408. error_split->set_name(TTR("Errors"));
  409. debugger_button->set_text(TTR("Debugger"));
  410. debugger_button->set_icon(Ref<Texture>());
  411. tabs->set_tab_icon(error_split->get_index(),Ref<Texture>());
  412. } else {
  413. error_split->set_name(TTR("Errors")+" ("+itos(error_count)+")");
  414. debugger_button->set_text(TTR("Debugger")+" ("+itos(error_count)+")");
  415. debugger_button->set_icon(get_icon("Error","EditorIcons"));
  416. tabs->set_tab_icon(error_split->get_index(),get_icon("Error","EditorIcons"));
  417. }
  418. last_error_count=error_count;
  419. }
  420. if (connection.is_null()) {
  421. if (server->is_connection_available()) {
  422. connection = server->take_connection();
  423. if (connection.is_null())
  424. break;
  425. EditorNode::get_log()->add_message("** Debug Process Started **");
  426. log_forced_visible=false;
  427. ppeer->set_stream_peer(connection);
  428. //EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  429. //emit_signal("show_debugger",true);
  430. dobreak->set_disabled(false);
  431. tabs->set_current_tab(0);
  432. reason->set_text(TTR("Child Process Connected"));
  433. reason->set_tooltip(TTR("Child Process Connected"));
  434. scene_tree->clear();
  435. le_set->set_disabled(true);
  436. le_clear->set_disabled(false);
  437. error_list->clear();
  438. error_stack->clear();
  439. error_count=0;
  440. //live_edit_root->set_text("/root");
  441. update_live_edit_root();
  442. } else {
  443. break;
  444. }
  445. };
  446. if (!connection->is_connected()) {
  447. stop();
  448. editor->notify_child_process_exited(); //somehow, exited
  449. break;
  450. };
  451. if (ppeer->get_available_packet_count() <= 0) {
  452. break;
  453. };
  454. while(ppeer->get_available_packet_count() > 0) {
  455. if (pending_in_queue) {
  456. int todo = MIN( ppeer->get_available_packet_count(), pending_in_queue );
  457. for(int i=0;i<todo;i++) {
  458. Variant cmd;
  459. Error ret = ppeer->get_var(cmd);
  460. if (ret!=OK) {
  461. stop();
  462. ERR_FAIL_COND(ret!=OK);
  463. }
  464. message.push_back(cmd);
  465. pending_in_queue--;
  466. }
  467. if (pending_in_queue==0) {
  468. _parse_message(message_type,message);
  469. message.clear();
  470. }
  471. } else {
  472. if (ppeer->get_available_packet_count()>=2) {
  473. Variant cmd;
  474. Error ret = ppeer->get_var(cmd);
  475. if (ret!=OK) {
  476. stop();
  477. ERR_FAIL_COND(ret!=OK);
  478. }
  479. if (cmd.get_type()!=Variant::STRING) {
  480. stop();
  481. ERR_FAIL_COND(cmd.get_type()!=Variant::STRING);
  482. }
  483. message_type=cmd;
  484. ret = ppeer->get_var(cmd);
  485. if (ret!=OK) {
  486. stop();
  487. ERR_FAIL_COND(ret!=OK);
  488. }
  489. if (cmd.get_type()!=Variant::INT) {
  490. stop();
  491. ERR_FAIL_COND(cmd.get_type()!=Variant::INT);
  492. }
  493. pending_in_queue=cmd;
  494. if (pending_in_queue==0) {
  495. _parse_message(message_type,Array());
  496. message.clear();
  497. }
  498. } else {
  499. break;
  500. }
  501. }
  502. }
  503. } break;
  504. }
  505. }
  506. void ScriptEditorDebugger::start() {
  507. stop();
  508. uint16_t port = GLOBAL_DEF("debug/remote_port",6007);
  509. perf_history.clear();
  510. for(int i=0;i<Performance::MONITOR_MAX;i++) {
  511. perf_max[i]=0;
  512. }
  513. server->listen(port);
  514. set_process(true);
  515. }
  516. void ScriptEditorDebugger::pause(){
  517. }
  518. void ScriptEditorDebugger::unpause(){
  519. }
  520. void ScriptEditorDebugger::stop(){
  521. set_process(false);
  522. server->stop();
  523. ppeer->set_stream_peer(Ref<StreamPeer>());
  524. if (connection.is_valid()) {
  525. EditorNode::get_log()->add_message("** Debug Process Stopped **");
  526. connection.unref();
  527. }
  528. pending_in_queue=0;
  529. message.clear();
  530. if (log_forced_visible) {
  531. //EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
  532. if (EditorNode::get_log()->is_visible())
  533. EditorNode::get_singleton()->hide_bottom_panel();
  534. log_forced_visible=false;
  535. }
  536. node_path_cache.clear();
  537. res_path_cache.clear();
  538. le_clear->set_disabled(false);
  539. le_set->set_disabled(true);
  540. if (hide_on_stop) {
  541. if (is_visible())
  542. EditorNode::get_singleton()->hide_bottom_panel();
  543. emit_signal("show_debugger",false);
  544. }
  545. }
  546. void ScriptEditorDebugger::_stack_dump_frame_selected() {
  547. TreeItem *ti = stack_dump->get_selected();
  548. if (!ti)
  549. return;
  550. Dictionary d = ti->get_metadata(0);
  551. Ref<Script> s = ResourceLoader::load(d["file"]);
  552. emit_signal("goto_script_line",s,int(d["line"])-1);
  553. ERR_FAIL_COND(connection.is_null());
  554. ERR_FAIL_COND(!connection->is_connected());
  555. ///
  556. Array msg;
  557. msg.push_back("get_stack_frame_vars");
  558. msg.push_back(d["frame"]);
  559. ppeer->put_var(msg);
  560. }
  561. void ScriptEditorDebugger::_output_clear() {
  562. //output->clear();
  563. //output->push_color(Color(0,0,0));
  564. }
  565. String ScriptEditorDebugger::get_var_value(const String& p_var) const {
  566. if (!breaked)
  567. return String();
  568. return variables->get_var_value(p_var);
  569. }
  570. int ScriptEditorDebugger::_get_node_path_cache(const NodePath& p_path) {
  571. const int *r = node_path_cache.getptr(p_path);
  572. if (r)
  573. return *r;
  574. last_path_id++;
  575. node_path_cache[p_path]=last_path_id;
  576. Array msg;
  577. msg.push_back("live_node_path");
  578. msg.push_back(p_path);
  579. msg.push_back(last_path_id);
  580. ppeer->put_var(msg);
  581. return last_path_id;
  582. }
  583. int ScriptEditorDebugger::_get_res_path_cache(const String& p_path) {
  584. Map<String,int>::Element *E=res_path_cache.find(p_path);
  585. if (E)
  586. return E->get();
  587. last_path_id++;
  588. res_path_cache[p_path]=last_path_id;
  589. Array msg;
  590. msg.push_back("live_res_path");
  591. msg.push_back(p_path);
  592. msg.push_back(last_path_id);
  593. ppeer->put_var(msg);
  594. return last_path_id;
  595. }
  596. void ScriptEditorDebugger::_method_changed(Object*p_base,const StringName& p_name,VARIANT_ARG_DECLARE) {
  597. if (!p_base || !live_debug || !connection.is_valid() || !editor->get_edited_scene())
  598. return;
  599. Node *node = p_base->cast_to<Node>();
  600. VARIANT_ARGPTRS
  601. for(int i=0;i<VARIANT_ARG_MAX;i++) {
  602. //no pointers, sorry
  603. if (argptr[i] && (argptr[i]->get_type()==Variant::OBJECT || argptr[i]->get_type()==Variant::_RID))
  604. return;
  605. }
  606. if (node) {
  607. NodePath path = editor->get_edited_scene()->get_path_to(node);
  608. int pathid = _get_node_path_cache(path);
  609. Array msg;
  610. msg.push_back("live_node_call");
  611. msg.push_back(pathid);
  612. msg.push_back(p_name);
  613. for(int i=0;i<VARIANT_ARG_MAX;i++) {
  614. //no pointers, sorry
  615. msg.push_back(*argptr[i]);
  616. }
  617. ppeer->put_var(msg);
  618. return;
  619. }
  620. Resource *res = p_base->cast_to<Resource>();
  621. if (res && res->get_path()!=String()) {
  622. String respath = res->get_path();
  623. int pathid = _get_res_path_cache(respath);
  624. Array msg;
  625. msg.push_back("live_res_call");
  626. msg.push_back(pathid);
  627. msg.push_back(p_name);
  628. for(int i=0;i<VARIANT_ARG_MAX;i++) {
  629. //no pointers, sorry
  630. msg.push_back(*argptr[i]);
  631. }
  632. ppeer->put_var(msg);
  633. return;
  634. }
  635. //print_line("method");
  636. }
  637. void ScriptEditorDebugger::_property_changed(Object*p_base,const StringName& p_property,const Variant& p_value){
  638. if (!p_base || !live_debug || !connection.is_valid() || !editor->get_edited_scene())
  639. return;
  640. Node *node = p_base->cast_to<Node>();
  641. if (node) {
  642. NodePath path = editor->get_edited_scene()->get_path_to(node);
  643. int pathid = _get_node_path_cache(path);
  644. if (p_value.is_ref()) {
  645. Ref<Resource> res = p_value;
  646. if (res.is_valid() && res->get_path()!=String()) {
  647. Array msg;
  648. msg.push_back("live_node_prop_res");
  649. msg.push_back(pathid);
  650. msg.push_back(p_property);
  651. msg.push_back(res->get_path());
  652. ppeer->put_var(msg);
  653. }
  654. } else {
  655. Array msg;
  656. msg.push_back("live_node_prop");
  657. msg.push_back(pathid);
  658. msg.push_back(p_property);
  659. msg.push_back(p_value);
  660. ppeer->put_var(msg);
  661. }
  662. return;
  663. }
  664. Resource *res = p_base->cast_to<Resource>();
  665. if (res && res->get_path()!=String()) {
  666. String respath = res->get_path();
  667. int pathid = _get_res_path_cache(respath);
  668. if (p_value.is_ref()) {
  669. Ref<Resource> res = p_value;
  670. if (res.is_valid() && res->get_path()!=String()) {
  671. Array msg;
  672. msg.push_back("live_res_prop_res");
  673. msg.push_back(pathid);
  674. msg.push_back(p_property);
  675. msg.push_back(res->get_path());
  676. ppeer->put_var(msg);
  677. }
  678. } else {
  679. Array msg;
  680. msg.push_back("live_res_prop");
  681. msg.push_back(pathid);
  682. msg.push_back(p_property);
  683. msg.push_back(p_value);
  684. ppeer->put_var(msg);
  685. }
  686. return;
  687. }
  688. //print_line("prop");
  689. }
  690. void ScriptEditorDebugger::_method_changeds(void *p_ud,Object*p_base,const StringName& p_name,VARIANT_ARG_DECLARE) {
  691. ScriptEditorDebugger *sed = (ScriptEditorDebugger*)p_ud;
  692. sed->_method_changed(p_base,p_name,VARIANT_ARG_PASS);
  693. }
  694. void ScriptEditorDebugger::_property_changeds(void *p_ud,Object*p_base,const StringName& p_property,const Variant& p_value){
  695. ScriptEditorDebugger *sed = (ScriptEditorDebugger*)p_ud;
  696. sed->_property_changed(p_base,p_property,p_value);
  697. }
  698. void ScriptEditorDebugger::set_live_debugging(bool p_enable) {
  699. live_debug=p_enable;
  700. }
  701. void ScriptEditorDebugger::_live_edit_set() {
  702. if (!connection.is_valid())
  703. return;
  704. TreeItem* ti = scene_tree->get_selected();
  705. if (!ti)
  706. return;
  707. String path;
  708. while(ti) {
  709. String lp=ti->get_text(0);
  710. path="/"+lp+path;
  711. ti=ti->get_parent();
  712. }
  713. NodePath np = path;
  714. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  715. update_live_edit_root();
  716. }
  717. void ScriptEditorDebugger::_live_edit_clear() {
  718. NodePath np = NodePath("/root");
  719. editor->get_editor_data().set_edited_scene_live_edit_root(np);
  720. update_live_edit_root();
  721. }
  722. void ScriptEditorDebugger::update_live_edit_root() {
  723. NodePath np = editor->get_editor_data().get_edited_scene_live_edit_root();
  724. if (connection.is_valid()) {
  725. Array msg;
  726. msg.push_back("live_set_root");
  727. msg.push_back(np);
  728. if (editor->get_edited_scene())
  729. msg.push_back(editor->get_edited_scene()->get_filename());
  730. else
  731. msg.push_back("");
  732. ppeer->put_var(msg);
  733. }
  734. live_edit_root->set_text(np);
  735. }
  736. void ScriptEditorDebugger::live_debug_create_node(const NodePath& p_parent,const String& p_type,const String& p_name) {
  737. if (live_debug && connection.is_valid()) {
  738. Array msg;
  739. msg.push_back("live_create_node");
  740. msg.push_back(p_parent);
  741. msg.push_back(p_type);
  742. msg.push_back(p_name);
  743. ppeer->put_var(msg);
  744. }
  745. }
  746. void ScriptEditorDebugger::live_debug_instance_node(const NodePath& p_parent,const String& p_path,const String& p_name){
  747. if (live_debug && connection.is_valid()) {
  748. Array msg;
  749. msg.push_back("live_instance_node");
  750. msg.push_back(p_parent);
  751. msg.push_back(p_path);
  752. msg.push_back(p_name);
  753. ppeer->put_var(msg);
  754. }
  755. }
  756. void ScriptEditorDebugger::live_debug_remove_node(const NodePath& p_at){
  757. if (live_debug && connection.is_valid()) {
  758. Array msg;
  759. msg.push_back("live_remove_node");
  760. msg.push_back(p_at);
  761. ppeer->put_var(msg);
  762. }
  763. }
  764. void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath& p_at,ObjectID p_keep_id) {
  765. if (live_debug && connection.is_valid()) {
  766. Array msg;
  767. msg.push_back("live_remove_and_keep_node");
  768. msg.push_back(p_at);
  769. msg.push_back(p_keep_id);
  770. ppeer->put_var(msg);
  771. }
  772. }
  773. void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath& p_at, int p_at_pos){
  774. if (live_debug && connection.is_valid()) {
  775. Array msg;
  776. msg.push_back("live_restore_node");
  777. msg.push_back(p_id);
  778. msg.push_back(p_at);
  779. msg.push_back(p_at_pos);
  780. ppeer->put_var(msg);
  781. }
  782. }
  783. void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath& p_at,const String& p_new_name){
  784. if (live_debug && connection.is_valid()) {
  785. Array msg;
  786. msg.push_back("live_duplicate_node");
  787. msg.push_back(p_at);
  788. msg.push_back(p_new_name);
  789. ppeer->put_var(msg);
  790. }
  791. }
  792. void ScriptEditorDebugger::live_debug_reparent_node(const NodePath& p_at, const NodePath& p_new_place, const String &p_new_name, int p_at_pos){
  793. if (live_debug && connection.is_valid()) {
  794. Array msg;
  795. msg.push_back("live_reparent_node");
  796. msg.push_back(p_at);
  797. msg.push_back(p_new_place);
  798. msg.push_back(p_new_name);
  799. msg.push_back(p_at_pos);
  800. ppeer->put_var(msg);
  801. }
  802. }
  803. void ScriptEditorDebugger::set_breakpoint(const String& p_path,int p_line,bool p_enabled) {
  804. if (connection.is_valid()) {
  805. Array msg;
  806. msg.push_back("breakpoint");
  807. msg.push_back(p_path);
  808. msg.push_back(p_line);
  809. msg.push_back(p_enabled);
  810. ppeer->put_var(msg);
  811. }
  812. }
  813. void ScriptEditorDebugger::_error_selected(int p_idx) {
  814. error_stack->clear();
  815. Array st=error_list->get_item_metadata(p_idx);
  816. for(int i=0;i<st.size();i+=2) {
  817. String script=st[i];
  818. int line=st[i+1];
  819. Array md;
  820. md.push_back(st[i]);
  821. md.push_back(st[i+1]);
  822. String str = script.get_file()+":"+itos(line);
  823. error_stack->add_item(str);
  824. error_stack->set_item_metadata(error_stack->get_item_count()-1,md);
  825. error_stack->set_item_tooltip(error_stack->get_item_count()-1,TTR("File:")+" "+String(st[i])+"\n"+TTR("Line:")+" "+itos(line));
  826. }
  827. }
  828. void ScriptEditorDebugger:: _error_stack_selected(int p_idx){
  829. Array arr = error_stack->get_item_metadata(p_idx);
  830. if (arr.size()!=2)
  831. return;
  832. Ref<Script> s = ResourceLoader::load(arr[0]);
  833. emit_signal("goto_script_line",s,int(arr[1])-1);
  834. }
  835. void ScriptEditorDebugger::set_hide_on_stop(bool p_hide) {
  836. hide_on_stop=p_hide;
  837. }
  838. void ScriptEditorDebugger::_bind_methods() {
  839. ObjectTypeDB::bind_method(_MD("_stack_dump_frame_selected"),&ScriptEditorDebugger::_stack_dump_frame_selected);
  840. ObjectTypeDB::bind_method(_MD("debug_next"),&ScriptEditorDebugger::debug_next);
  841. ObjectTypeDB::bind_method(_MD("debug_step"),&ScriptEditorDebugger::debug_step);
  842. ObjectTypeDB::bind_method(_MD("debug_break"),&ScriptEditorDebugger::debug_break);
  843. ObjectTypeDB::bind_method(_MD("debug_continue"),&ScriptEditorDebugger::debug_continue);
  844. ObjectTypeDB::bind_method(_MD("_output_clear"),&ScriptEditorDebugger::_output_clear);
  845. ObjectTypeDB::bind_method(_MD("_performance_draw"),&ScriptEditorDebugger::_performance_draw);
  846. ObjectTypeDB::bind_method(_MD("_performance_select"),&ScriptEditorDebugger::_performance_select);
  847. ObjectTypeDB::bind_method(_MD("_scene_tree_request"),&ScriptEditorDebugger::_scene_tree_request);
  848. ObjectTypeDB::bind_method(_MD("_video_mem_request"),&ScriptEditorDebugger::_video_mem_request);
  849. ObjectTypeDB::bind_method(_MD("_live_edit_set"),&ScriptEditorDebugger::_live_edit_set);
  850. ObjectTypeDB::bind_method(_MD("_live_edit_clear"),&ScriptEditorDebugger::_live_edit_clear);
  851. ObjectTypeDB::bind_method(_MD("_error_selected"),&ScriptEditorDebugger::_error_selected);
  852. ObjectTypeDB::bind_method(_MD("_error_stack_selected"),&ScriptEditorDebugger::_error_stack_selected);
  853. ObjectTypeDB::bind_method(_MD("live_debug_create_node"),&ScriptEditorDebugger::live_debug_create_node);
  854. ObjectTypeDB::bind_method(_MD("live_debug_instance_node"),&ScriptEditorDebugger::live_debug_instance_node);
  855. ObjectTypeDB::bind_method(_MD("live_debug_remove_node"),&ScriptEditorDebugger::live_debug_remove_node);
  856. ObjectTypeDB::bind_method(_MD("live_debug_remove_and_keep_node"),&ScriptEditorDebugger::live_debug_remove_and_keep_node);
  857. ObjectTypeDB::bind_method(_MD("live_debug_restore_node"),&ScriptEditorDebugger::live_debug_restore_node);
  858. ObjectTypeDB::bind_method(_MD("live_debug_duplicate_node"),&ScriptEditorDebugger::live_debug_duplicate_node);
  859. ObjectTypeDB::bind_method(_MD("live_debug_reparent_node"),&ScriptEditorDebugger::live_debug_reparent_node);
  860. ADD_SIGNAL(MethodInfo("goto_script_line"));
  861. ADD_SIGNAL(MethodInfo("breaked",PropertyInfo(Variant::BOOL,"reallydid"),PropertyInfo(Variant::BOOL,"can_debug")));
  862. ADD_SIGNAL(MethodInfo("show_debugger",PropertyInfo(Variant::BOOL,"reallydid")));
  863. }
  864. ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor){
  865. ppeer = Ref<PacketPeerStream>( memnew( PacketPeerStream ) );
  866. editor=p_editor;
  867. tabs = memnew( TabContainer );
  868. tabs->set_v_size_flags(SIZE_EXPAND_FILL);
  869. tabs->set_area_as_parent_rect();
  870. add_child(tabs);
  871. VBoxContainer *vbc = memnew( VBoxContainer );
  872. vbc->set_name(TTR("Debugger"));
  873. //tabs->add_child(vbc);
  874. Control *dbg=vbc;
  875. HBoxContainer *hbc = memnew( HBoxContainer );
  876. vbc->add_child(hbc);
  877. reason = memnew( LineEdit );
  878. reason->set_text("");
  879. reason->set_editable(false);
  880. hbc->add_child(reason);
  881. reason->add_color_override("font_color",Color(1,0.4,0.0,0.8));
  882. reason->set_h_size_flags(SIZE_EXPAND_FILL);
  883. //reason->set_clip_text(true);
  884. hbc->add_child( memnew( VSeparator) );
  885. step = memnew( Button );
  886. hbc->add_child(step);
  887. step->set_tooltip(TTR("Step Into"));
  888. step->connect("pressed",this,"debug_step");
  889. next = memnew( Button );
  890. hbc->add_child(next);
  891. next->set_tooltip(TTR("Step Over"));
  892. next->connect("pressed",this,"debug_next");
  893. hbc->add_child( memnew( VSeparator) );
  894. dobreak = memnew( Button );
  895. hbc->add_child(dobreak);
  896. dobreak->set_tooltip(TTR("Break"));
  897. dobreak->connect("pressed",this,"debug_break");
  898. docontinue = memnew( Button );
  899. hbc->add_child(docontinue);
  900. docontinue->set_tooltip(TTR("Continue"));
  901. docontinue->connect("pressed",this,"debug_continue");
  902. hbc->add_child( memnew( VSeparator) );
  903. back = memnew( Button );
  904. hbc->add_child(back);
  905. back->set_tooltip(TTR("Inspect Previous Instance"));
  906. forward = memnew( Button );
  907. hbc->add_child(forward);
  908. forward->set_tooltip(TTR("Inspect Next Instance"));
  909. HSplitContainer *sc = memnew( HSplitContainer );
  910. vbc->add_child(sc);
  911. sc->set_v_size_flags(SIZE_EXPAND_FILL);
  912. stack_dump = memnew( Tree );
  913. stack_dump->set_columns(1);
  914. stack_dump->set_column_titles_visible(true);
  915. stack_dump->set_column_title(0,TTR("Stack Frames"));
  916. stack_dump->set_h_size_flags(SIZE_EXPAND_FILL);
  917. stack_dump->set_hide_root(true);
  918. stack_dump->connect("cell_selected",this,"_stack_dump_frame_selected");
  919. sc->add_child(stack_dump);
  920. inspector = memnew( PropertyEditor );
  921. inspector->set_h_size_flags(SIZE_EXPAND_FILL);
  922. inspector->hide_top_label();
  923. inspector->get_scene_tree()->set_column_title(0,TTR("Variable"));
  924. inspector->set_capitalize_paths(false);
  925. inspector->set_read_only(true);
  926. sc->add_child(inspector);
  927. server = TCP_Server::create_ref();
  928. pending_in_queue=0;
  929. variables = memnew( ScriptEditorDebuggerVariables );
  930. breaked=false;
  931. tabs->add_child(dbg);
  932. //tabs->move_child(vbc,0);
  933. hbc = memnew( HBoxContainer );
  934. vbc->add_child(hbc);
  935. error_split = memnew( HSplitContainer );
  936. VBoxContainer *errvb = memnew( VBoxContainer );
  937. errvb->set_h_size_flags(SIZE_EXPAND_FILL);
  938. error_list = memnew( ItemList );
  939. errvb->add_margin_child(TTR("Errors:"),error_list,true);
  940. error_split->add_child(errvb);
  941. errvb = memnew( VBoxContainer );
  942. errvb->set_h_size_flags(SIZE_EXPAND_FILL);
  943. error_stack = memnew( ItemList );
  944. errvb->add_margin_child(TTR("Stack Trace (if applies):"),error_stack,true);
  945. error_split->add_child(errvb);
  946. error_split->set_name(TTR("Errors"));
  947. tabs->add_child(error_split);
  948. HSplitContainer *hsp = memnew( HSplitContainer );
  949. perf_monitors = memnew(Tree);
  950. perf_monitors->set_columns(2);
  951. perf_monitors->set_column_title(0,TTR("Monitor"));
  952. perf_monitors->set_column_title(1,TTR("Value"));
  953. perf_monitors->set_column_titles_visible(true);
  954. hsp->add_child(perf_monitors);
  955. perf_monitors->set_select_mode(Tree::SELECT_MULTI);
  956. perf_monitors->connect("multi_selected",this,"_performance_select");
  957. perf_draw = memnew( Control );
  958. perf_draw->connect("draw",this,"_performance_draw");
  959. hsp->add_child(perf_draw);
  960. hsp->set_name("Performance");
  961. hsp->set_split_offset(300);
  962. tabs->add_child(hsp);
  963. perf_max.resize(Performance::MONITOR_MAX);
  964. Map<String,TreeItem*> bases;
  965. TreeItem *root=perf_monitors->create_item();
  966. perf_monitors->set_hide_root(true);
  967. for(int i=0;i<Performance::MONITOR_MAX;i++) {
  968. String n = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
  969. String base = n.get_slice("/",0);
  970. String name = n.get_slice("/",1);
  971. if (!bases.has(base)) {
  972. TreeItem *b = perf_monitors->create_item(root);
  973. b->set_text(0,base.capitalize());
  974. b->set_editable(0,false);
  975. b->set_selectable(0,false);
  976. bases[base]=b;
  977. }
  978. TreeItem *it = perf_monitors->create_item(bases[base]);
  979. it->set_editable(0,false);
  980. it->set_selectable(0,true);
  981. it->set_text(0,name.capitalize());
  982. perf_items.push_back(it);
  983. perf_max[i]=0;
  984. }
  985. VBoxContainer *vmem_vb = memnew( VBoxContainer );
  986. HBoxContainer *vmem_hb = memnew( HBoxContainer );
  987. Label *vmlb = memnew(Label(TTR("List of Video Memory Usage by Resource:")+" ") );
  988. vmlb->set_h_size_flags(SIZE_EXPAND_FILL);
  989. vmem_hb->add_child( vmlb );
  990. vmem_hb->add_child( memnew(Label(TTR("Total:")+" ")) );
  991. vmem_total = memnew( LineEdit );
  992. vmem_total->set_editable(false);
  993. vmem_total->set_custom_minimum_size(Size2(100,1));
  994. vmem_hb->add_child(vmem_total);
  995. vmem_refresh = memnew( Button );
  996. vmem_hb->add_child(vmem_refresh);
  997. vmem_vb->add_child(vmem_hb);
  998. vmem_refresh->connect("pressed",this,"_video_mem_request");
  999. MarginContainer *vmmc = memnew( MarginContainer );
  1000. vmem_tree = memnew( Tree );
  1001. vmem_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  1002. vmem_tree->set_h_size_flags(SIZE_EXPAND_FILL);
  1003. vmmc->add_child(vmem_tree);
  1004. vmmc->set_v_size_flags(SIZE_EXPAND_FILL);
  1005. vmem_vb->add_child(vmmc);
  1006. vmem_vb->set_name(TTR("Video Mem"));
  1007. vmem_tree->set_columns(4);
  1008. vmem_tree->set_column_titles_visible(true);
  1009. vmem_tree->set_column_title(0,TTR("Resource Path"));
  1010. vmem_tree->set_column_expand(0,true);
  1011. vmem_tree->set_column_expand(1,false);
  1012. vmem_tree->set_column_title(1,TTR("Type"));
  1013. vmem_tree->set_column_min_width(1,100);
  1014. vmem_tree->set_column_expand(2,false);
  1015. vmem_tree->set_column_title(2,TTR("Format"));
  1016. vmem_tree->set_column_min_width(2,150);
  1017. vmem_tree->set_column_expand(3,false);
  1018. vmem_tree->set_column_title(3,TTR("Usage"));
  1019. vmem_tree->set_column_min_width(3,80);
  1020. vmem_tree->set_hide_root(true);
  1021. tabs->add_child(vmem_vb);
  1022. info = memnew( HSplitContainer );
  1023. info->set_name(TTR("Info"));
  1024. tabs->add_child(info);
  1025. VBoxContainer *info_left = memnew( VBoxContainer );
  1026. info_left->set_h_size_flags(SIZE_EXPAND_FILL);
  1027. info->add_child(info_left);
  1028. clicked_ctrl = memnew( LineEdit );
  1029. info_left->add_margin_child(TTR("Clicked Control:"),clicked_ctrl);
  1030. clicked_ctrl_type = memnew( LineEdit );
  1031. info_left->add_margin_child(TTR("Clicked Control Type:"),clicked_ctrl_type);
  1032. live_edit_root = memnew( LineEdit );
  1033. {
  1034. HBoxContainer *lehb = memnew( HBoxContainer );
  1035. Label *l = memnew( Label(TTR("Live Edit Root:")) );
  1036. lehb->add_child(l);
  1037. l->set_h_size_flags(SIZE_EXPAND_FILL);
  1038. le_set = memnew( Button(TTR("Set From Tree")) );
  1039. lehb->add_child(le_set);
  1040. le_clear = memnew( Button(TTR("Clear")) );
  1041. lehb->add_child(le_clear);
  1042. info_left->add_child(lehb);
  1043. MarginContainer *mc = memnew( MarginContainer );
  1044. mc->add_child(live_edit_root);
  1045. info_left->add_child(mc);
  1046. le_set->set_disabled(true);
  1047. le_clear->set_disabled(true);
  1048. }
  1049. VBoxContainer *info_right = memnew(VBoxContainer);
  1050. info_right->set_h_size_flags(SIZE_EXPAND_FILL);
  1051. info->add_child(info_right);
  1052. HBoxContainer *inforhb = memnew( HBoxContainer );
  1053. info_right->add_child(inforhb);
  1054. Label *l2 = memnew( Label(TTR("Scene Tree:") ) );
  1055. l2->set_h_size_flags(SIZE_EXPAND_FILL);
  1056. inforhb->add_child( l2 );
  1057. Button *refresh = memnew( Button );
  1058. inforhb->add_child(refresh);
  1059. refresh->connect("pressed",this,"_scene_tree_request");
  1060. scene_tree_refresh=refresh;
  1061. MarginContainer *infomc = memnew( MarginContainer );
  1062. info_right->add_child(infomc);
  1063. infomc->set_v_size_flags(SIZE_EXPAND_FILL);
  1064. scene_tree = memnew( Tree );
  1065. infomc->add_child(scene_tree);
  1066. msgdialog = memnew( AcceptDialog );
  1067. add_child(msgdialog);
  1068. log_forced_visible=false;
  1069. p_editor->get_undo_redo()->set_method_notify_callback(_method_changeds,this);
  1070. p_editor->get_undo_redo()->set_property_notify_callback(_property_changeds,this);
  1071. live_debug=false;
  1072. last_path_id=false;
  1073. error_count=0;
  1074. hide_on_stop=true;
  1075. last_error_count=0;
  1076. }
  1077. ScriptEditorDebugger::~ScriptEditorDebugger() {
  1078. // inspector->edit(NULL);
  1079. memdelete(variables);
  1080. ppeer->set_stream_peer(Ref<StreamPeer>());
  1081. server->stop();
  1082. }