diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-05-07 00:43:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-07 00:43:45 +0200 |
commit | 3a5310ccb990633bbba1d17dbeb503d46faa8615 (patch) | |
tree | 6243000b7b33ba889823f55a4f7940c2b720daa7 /editor | |
parent | 94f6fb6d240ae989c27810841d1d91ab5c1f2600 (diff) | |
parent | ce4aa07276f4772f86c9b2a38b49378ef991b981 (diff) |
Merge pull request #35992 from Calinou/main-run-args-command-placeholder
Implement the `%command%` placeholder in the Main Run Args setting
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_node.cpp | 2 | ||||
-rw-r--r-- | editor/editor_run.cpp | 45 |
2 files changed, 40 insertions, 7 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index ed670b1296..07e95e7b83 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5877,8 +5877,6 @@ EditorNode::EditorNode() { register_exporters(); - GLOBAL_DEF("editor/run/main_run_args", ""); - ClassDB::set_class_enabled("RootMotionView", true); //defs here, use EDITOR_GET in logic diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp index e46f4eb65a..5e6d2ab69c 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -183,15 +183,50 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L args.push_back(p_scene); } + String exec = OS::get_singleton()->get_executable_path(); + if (p_custom_args != "") { - Vector<String> cargs = p_custom_args.split(" ", false); - for (int i = 0; i < cargs.size(); i++) { - args.push_back(cargs[i].replace(" ", "%20")); + // Allow the user to specify a command to run, similar to Steam's launch options. + // In this case, Godot will no longer be run directly; it's up to the underlying command + // to run it. For instance, this can be used on Linux to force a running project + // to use Optimus using `prime-run` or similar. + // Example: `prime-run %command% --time-scale 0.5` + const int placeholder_pos = p_custom_args.find("%command%"); + + Vector<String> custom_args; + + if (placeholder_pos != -1) { + // Prepend executable-specific custom arguments. + // If nothing is placed before `%command%`, behave as if no placeholder was specified. + Vector<String> exec_args = p_custom_args.substr(0, placeholder_pos).split(" ", false); + if (exec_args.size() >= 1) { + exec = exec_args[0]; + exec_args.remove(0); + + // Append the Godot executable name before we append executable arguments + // (since the order is reversed when using `push_front()`). + args.push_front(OS::get_singleton()->get_executable_path()); + } + + for (int i = exec_args.size() - 1; i >= 0; i--) { + // Iterate backwards as we're pushing items in the reverse order. + args.push_front(exec_args[i].replace(" ", "%20")); + } + + // Append Godot-specific custom arguments. + custom_args = p_custom_args.substr(placeholder_pos + String("%command%").size()).split(" ", false); + for (int i = 0; i < custom_args.size(); i++) { + args.push_back(custom_args[i].replace(" ", "%20")); + } + } else { + // Append Godot-specific custom arguments. + custom_args = p_custom_args.split(" ", false); + for (int i = 0; i < custom_args.size(); i++) { + args.push_back(custom_args[i].replace(" ", "%20")); + } } } - String exec = OS::get_singleton()->get_executable_path(); - printf("Running: %s", exec.utf8().get_data()); for (List<String>::Element *E = args.front(); E; E = E->next()) { printf(" %s", E->get().utf8().get_data()); |