editor_run.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*************************************************************************/
  2. /* editor_run.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 "editor_run.h"
  31. #include "editor_settings.h"
  32. #include "globals.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, const String &p_edited_scene) {
  37. List<String> args;
  38. String resource_path = Globals::get_singleton()->get_resource_path();
  39. String remote_host = EditorSettings::get_singleton()->get("network/debug_host");
  40. int remote_port = (int)EditorSettings::get_singleton()->get("network/debug_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("-rdebug");
  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("-debugcol");
  53. }
  54. if (debug_navigation) {
  55. args.push_back("-debugnav");
  56. }
  57. if (OS::get_singleton()->is_disable_crash_handler()) {
  58. args.push_back("--disable-crash-handler");
  59. }
  60. int screen = EditorSettings::get_singleton()->get("game_window_placement/screen");
  61. if (screen == 0) {
  62. screen = OS::get_singleton()->get_current_screen();
  63. } else {
  64. screen--;
  65. }
  66. Rect2 screen_rect;
  67. screen_rect.pos = 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 = Globals::get_singleton()->get("display/width");
  71. desired_size.y = Globals::get_singleton()->get("display/height");
  72. Size2 test_size;
  73. test_size.x = Globals::get_singleton()->get("display/test_width");
  74. test_size.y = Globals::get_singleton()->get("display/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("game_window_placement/rect");
  79. switch (window_placement) {
  80. case 0: { // top left
  81. args.push_back("-p");
  82. args.push_back(itos(screen_rect.pos.x) + "x" + itos(screen_rect.pos.y));
  83. } break;
  84. case 1: { // centered
  85. Vector2 pos = screen_rect.pos + ((screen_rect.size - desired_size) / 2).floor();
  86. args.push_back("-p");
  87. args.push_back(itos(pos.x) + "x" + itos(pos.y));
  88. } break;
  89. case 2: { // custom pos
  90. Vector2 pos = EditorSettings::get_singleton()->get("game_window_placement/rect_custom_position");
  91. pos += screen_rect.pos;
  92. args.push_back("-p");
  93. args.push_back(itos(pos.x) + "x" + itos(pos.y));
  94. } break;
  95. case 3: { // force maximized
  96. Vector2 pos = screen_rect.pos;
  97. args.push_back("-p");
  98. args.push_back(itos(pos.x) + "x" + itos(pos.y));
  99. args.push_back("-mx");
  100. } break;
  101. case 4: { // force fullscreen
  102. Vector2 pos = screen_rect.pos;
  103. args.push_back("-p");
  104. args.push_back(itos(pos.x) + "x" + itos(pos.y));
  105. args.push_back("-f");
  106. } break;
  107. }
  108. if (p_breakpoints.size()) {
  109. args.push_back("-bp");
  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_custom_args != "") {
  119. Vector<String> cargs = p_custom_args.split(" ", false);
  120. for (int i = 0; i < cargs.size(); i++) {
  121. args.push_back(cargs[i].replace("$scene", p_scene).replace(" ", "%20"));
  122. }
  123. }
  124. String exec = OS::get_singleton()->get_executable_path();
  125. printf("running: %ls", exec.c_str());
  126. for (List<String>::Element *E = args.front(); E; E = E->next()) {
  127. printf(" %ls", E->get().c_str());
  128. };
  129. printf("\n");
  130. pid = 0;
  131. Error err = OS::get_singleton()->execute(exec, args, false, &pid);
  132. ERR_FAIL_COND_V(err, err);
  133. status = STATUS_PLAY;
  134. return OK;
  135. }
  136. void EditorRun::stop() {
  137. if (status != STATUS_STOP && pid != 0) {
  138. OS::get_singleton()->kill(pid);
  139. }
  140. status = STATUS_STOP;
  141. }
  142. void EditorRun::set_debug_collisions(bool p_debug) {
  143. debug_collisions = p_debug;
  144. }
  145. bool EditorRun::get_debug_collisions() const {
  146. return debug_collisions;
  147. }
  148. void EditorRun::set_debug_navigation(bool p_debug) {
  149. debug_navigation = p_debug;
  150. }
  151. bool EditorRun::get_debug_navigation() const {
  152. return debug_navigation;
  153. }
  154. EditorRun::EditorRun() {
  155. status = STATUS_STOP;
  156. debug_collisions = false;
  157. debug_navigation = false;
  158. }