editor_run.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*************************************************************************/
  2. /* editor_run.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 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 "editor_run.h"
  30. #include "globals.h"
  31. EditorRun::Status EditorRun::get_status() const {
  32. return status;
  33. }
  34. Error EditorRun::run(const String& p_scene,const String p_custom_args,const List<String>& p_breakpoints,const String& p_edited_scene) {
  35. List<String> args;
  36. String resource_path = Globals::get_singleton()->get_resource_path();
  37. if (resource_path!="") {
  38. args.push_back("-path");
  39. args.push_back(resource_path.replace(" ","%20"));
  40. }
  41. if (true) {
  42. args.push_back("-rdebug");
  43. args.push_back("localhost:"+String::num(GLOBAL_DEF("debug/debug_port", 6007)));
  44. }
  45. if (p_custom_args!="") {
  46. Vector<String> cargs=p_custom_args.split(" ",false);
  47. for(int i=0;i<cargs.size();i++) {
  48. args.push_back(cargs[i].replace("%20"," ").replace("$scene",p_edited_scene.replace(" ","%20")));
  49. }
  50. }
  51. if (p_breakpoints.size()) {
  52. args.push_back("-bp");
  53. String bpoints;
  54. for(const List<String>::Element *E=p_breakpoints.front();E;E=E->next()) {
  55. bpoints+=E->get().replace(" ","%20");
  56. if (E->next())
  57. bpoints+=",";
  58. }
  59. args.push_back(bpoints);
  60. }
  61. args.push_back(p_scene);
  62. String exec = OS::get_singleton()->get_executable_path();
  63. printf("running: %ls", exec.c_str());
  64. for (List<String>::Element* E = args.front(); E ; E = E->next()) {
  65. printf(" %ls", E->get().c_str());
  66. };
  67. printf("\n");
  68. pid=0;
  69. Error err = OS::get_singleton()->execute(exec,args,false,&pid);
  70. ERR_FAIL_COND_V(err,err);
  71. status = STATUS_PLAY;
  72. return OK;
  73. }
  74. void EditorRun::stop() {
  75. if (status!=STATUS_STOP && pid!=0) {
  76. OS::get_singleton()->kill(pid);
  77. }
  78. status=STATUS_STOP;
  79. }
  80. EditorRun::EditorRun() {
  81. status=STATUS_STOP;
  82. }