editor_run.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*************************************************************************/
  2. /* editor_run.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "editor_run.h"
  31. #include "editor_settings.h"
  32. #include "project_settings.h"
  33. EditorRun::Status EditorRun::get_status() const {
  34. return status;
  35. }
  36. Error EditorRun::run(const String &p_scene, const String p_custom_args, const List<String> &p_breakpoints) {
  37. List<String> args;
  38. String resource_path = ProjectSettings::get_singleton()->get_resource_path();
  39. String remote_host = EditorSettings::get_singleton()->get("network/debug/remote_host");
  40. int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
  41. if (resource_path != "") {
  42. args.push_back("--path");
  43. args.push_back(resource_path.replace(" ", "%20"));
  44. }
  45. if (true) {
  46. args.push_back("--remote-debug");
  47. args.push_back(remote_host + ":" + String::num(remote_port));
  48. }
  49. args.push_back("--allow_focus_steal_pid");
  50. args.push_back(itos(OS::get_singleton()->get_process_id()));
  51. if (debug_collisions) {
  52. args.push_back("--debug-collisions");
  53. }
  54. if (debug_navigation) {
  55. args.push_back("--debug-navigation");
  56. }
  57. int screen = EditorSettings::get_singleton()->get("run/window_placement/screen");
  58. if (screen == 0) {
  59. screen = OS::get_singleton()->get_current_screen();
  60. } else {
  61. screen--;
  62. }
  63. if (OS::get_singleton()->is_disable_crash_handler()) {
  64. args.push_back("--disable-crash-handler");
  65. }
  66. Rect2 screen_rect;
  67. screen_rect.position = OS::get_singleton()->get_screen_position(screen);
  68. screen_rect.size = OS::get_singleton()->get_screen_size(screen);
  69. Size2 desired_size;
  70. desired_size.x = ProjectSettings::get_singleton()->get("display/window/size/width");
  71. desired_size.y = ProjectSettings::get_singleton()->get("display/window/size/height");
  72. Size2 test_size;
  73. test_size.x = ProjectSettings::get_singleton()->get("display/window/size/test_width");
  74. test_size.y = ProjectSettings::get_singleton()->get("display/window/size/test_height");
  75. if (test_size.x > 0 && test_size.y > 0) {
  76. desired_size = test_size;
  77. }
  78. int window_placement = EditorSettings::get_singleton()->get("run/window_placement/rect");
  79. switch (window_placement) {
  80. case 0: { // top left
  81. args.push_back("--position");
  82. args.push_back(itos(screen_rect.position.x) + "," + itos(screen_rect.position.y));
  83. } break;
  84. case 1: { // centered
  85. Vector2 pos = screen_rect.position + ((screen_rect.size - desired_size) / 2).floor();
  86. args.push_back("--position");
  87. args.push_back(itos(pos.x) + "," + itos(pos.y));
  88. } break;
  89. case 2: { // custom pos
  90. Vector2 pos = EditorSettings::get_singleton()->get("run/window_placement/rect_custom_position");
  91. pos += screen_rect.position;
  92. args.push_back("--position");
  93. args.push_back(itos(pos.x) + "," + itos(pos.y));
  94. } break;
  95. case 3: { // force maximized
  96. Vector2 pos = screen_rect.position;
  97. args.push_back("--position");
  98. args.push_back(itos(pos.x) + "," + itos(pos.y));
  99. args.push_back("--maximized");
  100. } break;
  101. case 4: { // force fullscreen
  102. Vector2 pos = screen_rect.position;
  103. args.push_back("--position");
  104. args.push_back(itos(pos.x) + "," + itos(pos.y));
  105. args.push_back("--fullscreen");
  106. } break;
  107. }
  108. if (p_breakpoints.size()) {
  109. args.push_back("--breakpoints");
  110. String bpoints;
  111. for (const List<String>::Element *E = p_breakpoints.front(); E; E = E->next()) {
  112. bpoints += E->get().replace(" ", "%20");
  113. if (E->next())
  114. bpoints += ",";
  115. }
  116. args.push_back(bpoints);
  117. }
  118. if (p_scene != "") {
  119. args.push_back(p_scene);
  120. }
  121. if (p_custom_args != "") {
  122. Vector<String> cargs = p_custom_args.split(" ", false);
  123. for (int i = 0; i < cargs.size(); i++) {
  124. args.push_back(cargs[i].replace(" ", "%20"));
  125. }
  126. }
  127. String exec = OS::get_singleton()->get_executable_path();
  128. printf("Running: %ls", exec.c_str());
  129. for (List<String>::Element *E = args.front(); E; E = E->next()) {
  130. printf(" %ls", E->get().c_str());
  131. };
  132. printf("\n");
  133. pid = 0;
  134. Error err = OS::get_singleton()->execute(exec, args, false, &pid);
  135. ERR_FAIL_COND_V(err, err);
  136. status = STATUS_PLAY;
  137. return OK;
  138. }
  139. void EditorRun::stop() {
  140. if (status != STATUS_STOP && pid != 0) {
  141. OS::get_singleton()->kill(pid);
  142. }
  143. status = STATUS_STOP;
  144. }
  145. void EditorRun::set_debug_collisions(bool p_debug) {
  146. debug_collisions = p_debug;
  147. }
  148. bool EditorRun::get_debug_collisions() const {
  149. return debug_collisions;
  150. }
  151. void EditorRun::set_debug_navigation(bool p_debug) {
  152. debug_navigation = p_debug;
  153. }
  154. bool EditorRun::get_debug_navigation() const {
  155. return debug_navigation;
  156. }
  157. EditorRun::EditorRun() {
  158. status = STATUS_STOP;
  159. debug_collisions = false;
  160. debug_navigation = false;
  161. }