1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-02 16:48:55 +00:00

Refactor debugging on a device with DAP - now possible with all device types

Co-authored-by: Thaddeus Crews <repiteo@outlook.com>
This commit is contained in:
Ivan Shakhov
2025-08-26 15:22:55 +02:00
parent 6fd949a6dc
commit 49ac9f63fd
6 changed files with 39 additions and 42 deletions

View File

@@ -33,6 +33,7 @@
#include "editor/debugger/debug_adapter/debug_adapter_protocol.h" #include "editor/debugger/debug_adapter/debug_adapter_protocol.h"
#include "editor/debugger/editor_debugger_node.h" #include "editor/debugger/editor_debugger_node.h"
#include "editor/debugger/script_editor_debugger.h" #include "editor/debugger/script_editor_debugger.h"
#include "editor/export/editor_export.h"
#include "editor/export/editor_export_platform.h" #include "editor/export/editor_export_platform.h"
#include "editor/run/editor_run_bar.h" #include "editor/run/editor_run_bar.h"
#include "editor/script/script_editor_plugin.h" #include "editor/script/script_editor_plugin.h"
@@ -217,32 +218,20 @@ Dictionary DebugAdapterParser::_launch_process(const Dictionary &p_params) const
EditorRunBar::get_singleton()->play_custom_scene(scene, play_args); EditorRunBar::get_singleton()->play_custom_scene(scene, play_args);
} }
} else { } else {
int device = args.get("device", -1); // Not limited to Android, iOS, Web.
int idx = -1; const int platform_idx = EditorExport::get_singleton()->get_export_platform_index_by_name(platform_string);
if (platform_string == "android") { if (platform_idx == -1) {
for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
if (EditorExport::get_singleton()->get_export_platform(i)->get_name() == "Android") {
idx = i;
break;
}
}
} else if (platform_string == "web") {
for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
if (EditorExport::get_singleton()->get_export_platform(i)->get_name() == "Web") {
idx = i;
break;
}
}
}
if (idx == -1) {
return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN_PLATFORM); return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN_PLATFORM);
} }
EditorRunBar *run_bar = EditorRunBar::get_singleton(); // If it is not passed, would mean first device of this platform.
Error err = platform_string == "android" ? run_bar->start_native_device(device * 10000 + idx) : run_bar->start_native_device(idx); const int device_idx = args.get("device", 0);
const EditorRunBar *run_bar = EditorRunBar::get_singleton();
const int encoded_id = EditorExport::encode_platform_device_id(platform_idx, device_idx);
const Error err = run_bar->start_native_device(encoded_id);
if (err) { if (err) {
if (err == ERR_INVALID_PARAMETER && platform_string == "android") { if (err == ERR_INVALID_PARAMETER) {
return prepare_error_response(p_params, DAP::ErrorType::MISSING_DEVICE); return prepare_error_response(p_params, DAP::ErrorType::MISSING_DEVICE);
} else { } else {
return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN); return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN);

View File

@@ -142,10 +142,20 @@ void EditorExport::remove_export_platform(const Ref<EditorExportPlatform> &p_pla
should_reload_presets = true; should_reload_presets = true;
} }
int EditorExport::get_export_platform_count() { int EditorExport::get_export_platform_count() const {
return export_platforms.size(); return export_platforms.size();
} }
int EditorExport::get_export_platform_index_by_name(const String &p_name) {
for (int j = 0; j < get_export_platform_count(); j++) {
Ref<EditorExportPlatform> plat = get_export_platform(j);
if (!plat.is_null() && plat->get_name().nocasecmp_to(p_name) == 0) {
return j;
}
}
return -1;
}
Ref<EditorExportPlatform> EditorExport::get_export_platform(int p_idx) { Ref<EditorExportPlatform> EditorExport::get_export_platform(int p_idx) {
ERR_FAIL_INDEX_V(p_idx, export_platforms.size(), Ref<EditorExportPlatform>()); ERR_FAIL_INDEX_V(p_idx, export_platforms.size(), Ref<EditorExportPlatform>());

View File

@@ -65,8 +65,14 @@ protected:
public: public:
static EditorExport *get_singleton() { return singleton; } static EditorExport *get_singleton() { return singleton; }
// Encodes a platform/device pair into a single menu/device id and decodes it back.
static int encode_platform_device_id(int p_platform_idx, int p_device_idx) { return p_platform_idx * 10000 + p_device_idx; }
static int decode_platform_from_id(int p_id) { return p_id / 10000; }
static int decode_device_from_id(int p_id) { return p_id % 10000; }
void add_export_platform(const Ref<EditorExportPlatform> &p_platform); void add_export_platform(const Ref<EditorExportPlatform> &p_platform);
int get_export_platform_count(); int get_export_platform_count() const;
int get_export_platform_index_by_name(const String &p_name);
Ref<EditorExportPlatform> get_export_platform(int p_idx); Ref<EditorExportPlatform> get_export_platform(int p_idx);
void remove_export_platform(const Ref<EditorExportPlatform> &p_platform); void remove_export_platform(const Ref<EditorExportPlatform> &p_platform);

View File

@@ -454,7 +454,7 @@ String EditorRunBar::get_playing_scene() const {
return run_filename; return run_filename;
} }
Error EditorRunBar::start_native_device(int p_device_id) { Error EditorRunBar::start_native_device(int p_device_id) const {
return run_native->start_run_native(p_device_id); return run_native->start_run_native(p_device_id);
} }

View File

@@ -121,7 +121,7 @@ public:
bool is_playing() const; bool is_playing() const;
String get_playing_scene() const; String get_playing_scene() const;
Error start_native_device(int p_device_id); Error start_native_device(int p_device_id) const;
OS::ProcessID has_child_process(OS::ProcessID p_pid) const; OS::ProcessID has_child_process(OS::ProcessID p_pid) const;
void stop_child_process(OS::ProcessID p_pid); void stop_child_process(OS::ProcessID p_pid);

View File

@@ -55,20 +55,14 @@ void EditorRunNative::_notification(int p_what) {
if (eep.is_null()) { if (eep.is_null()) {
continue; continue;
} }
int platform_idx = -1; const int platform_idx = EditorExport::get_singleton()->get_export_platform_index_by_name(eep->get_name());
for (int j = 0; j < EditorExport::get_singleton()->get_export_platform_count(); j++) { const int device_count = MIN(eep->get_options_count(), 9000);
if (eep->get_name() == EditorExport::get_singleton()->get_export_platform(j)->get_name()) {
platform_idx = j;
break;
}
}
int dc = MIN(eep->get_options_count(), 9000);
String error; String error;
if (dc > 0 && preset->is_runnable()) { if (device_count > 0 && preset->is_runnable()) {
popup->add_icon_item(eep->get_run_icon(), eep->get_name(), -1); popup->add_icon_item(eep->get_run_icon(), eep->get_name(), -1);
popup->set_item_disabled(-1, true); popup->set_item_disabled(-1, true);
for (int j = 0; j < dc; j++) { for (int j = 0; j < device_count; j++) {
popup->add_icon_item(eep->get_option_icon(j), eep->get_option_label(j), 10000 * platform_idx + j); popup->add_icon_item(eep->get_option_icon(j), eep->get_option_label(j), EditorExport::encode_platform_device_id(platform_idx, j));
popup->set_item_tooltip(-1, eep->get_option_tooltip(j)); popup->set_item_tooltip(-1, eep->get_option_tooltip(j));
popup->set_item_indent(-1, 2); popup->set_item_indent(-1, 2);
if (device_shortcut_id <= 4 && eep->is_option_runnable(j)) { if (device_shortcut_id <= 4 && eep->is_option_runnable(j)) {
@@ -99,12 +93,10 @@ void EditorRunNative::_confirm_run_native() {
} }
Error EditorRunNative::start_run_native(int p_id) { Error EditorRunNative::start_run_native(int p_id) {
if (p_id < 0) { ERR_FAIL_COND_V(p_id < 0, FAILED);
return OK;
}
int platform = p_id / 10000; const int platform = EditorExport::decode_platform_from_id(p_id);
int idx = p_id % 10000; const int idx = EditorExport::decode_device_from_id(p_id);
resume_id = p_id; resume_id = p_id;
if (!EditorNode::get_singleton()->ensure_main_scene(true)) { if (!EditorNode::get_singleton()->ensure_main_scene(true)) {