You've already forked godot
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:
@@ -33,6 +33,7 @@
|
||||
#include "editor/debugger/debug_adapter/debug_adapter_protocol.h"
|
||||
#include "editor/debugger/editor_debugger_node.h"
|
||||
#include "editor/debugger/script_editor_debugger.h"
|
||||
#include "editor/export/editor_export.h"
|
||||
#include "editor/export/editor_export_platform.h"
|
||||
#include "editor/run/editor_run_bar.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);
|
||||
}
|
||||
} else {
|
||||
int device = args.get("device", -1);
|
||||
int idx = -1;
|
||||
if (platform_string == "android") {
|
||||
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) {
|
||||
// Not limited to Android, iOS, Web.
|
||||
const int platform_idx = EditorExport::get_singleton()->get_export_platform_index_by_name(platform_string);
|
||||
if (platform_idx == -1) {
|
||||
return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN_PLATFORM);
|
||||
}
|
||||
|
||||
EditorRunBar *run_bar = EditorRunBar::get_singleton();
|
||||
Error err = platform_string == "android" ? run_bar->start_native_device(device * 10000 + idx) : run_bar->start_native_device(idx);
|
||||
// If it is not passed, would mean first device of this platform.
|
||||
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 == ERR_INVALID_PARAMETER && platform_string == "android") {
|
||||
if (err == ERR_INVALID_PARAMETER) {
|
||||
return prepare_error_response(p_params, DAP::ErrorType::MISSING_DEVICE);
|
||||
} else {
|
||||
return prepare_error_response(p_params, DAP::ErrorType::UNKNOWN);
|
||||
|
||||
@@ -142,10 +142,20 @@ void EditorExport::remove_export_platform(const Ref<EditorExportPlatform> &p_pla
|
||||
should_reload_presets = true;
|
||||
}
|
||||
|
||||
int EditorExport::get_export_platform_count() {
|
||||
int EditorExport::get_export_platform_count() const {
|
||||
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) {
|
||||
ERR_FAIL_INDEX_V(p_idx, export_platforms.size(), Ref<EditorExportPlatform>());
|
||||
|
||||
|
||||
@@ -65,8 +65,14 @@ protected:
|
||||
public:
|
||||
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);
|
||||
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);
|
||||
void remove_export_platform(const Ref<EditorExportPlatform> &p_platform);
|
||||
|
||||
|
||||
@@ -454,7 +454,7 @@ String EditorRunBar::get_playing_scene() const {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
bool is_playing() 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;
|
||||
void stop_child_process(OS::ProcessID p_pid);
|
||||
|
||||
@@ -55,20 +55,14 @@ void EditorRunNative::_notification(int p_what) {
|
||||
if (eep.is_null()) {
|
||||
continue;
|
||||
}
|
||||
int platform_idx = -1;
|
||||
for (int j = 0; j < EditorExport::get_singleton()->get_export_platform_count(); j++) {
|
||||
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);
|
||||
const int platform_idx = EditorExport::get_singleton()->get_export_platform_index_by_name(eep->get_name());
|
||||
const int device_count = MIN(eep->get_options_count(), 9000);
|
||||
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->set_item_disabled(-1, true);
|
||||
for (int j = 0; j < dc; j++) {
|
||||
popup->add_icon_item(eep->get_option_icon(j), eep->get_option_label(j), 10000 * platform_idx + j);
|
||||
for (int j = 0; j < device_count; 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_indent(-1, 2);
|
||||
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) {
|
||||
if (p_id < 0) {
|
||||
return OK;
|
||||
}
|
||||
ERR_FAIL_COND_V(p_id < 0, FAILED);
|
||||
|
||||
int platform = p_id / 10000;
|
||||
int idx = p_id % 10000;
|
||||
const int platform = EditorExport::decode_platform_from_id(p_id);
|
||||
const int idx = EditorExport::decode_device_from_id(p_id);
|
||||
resume_id = p_id;
|
||||
|
||||
if (!EditorNode::get_singleton()->ensure_main_scene(true)) {
|
||||
|
||||
Reference in New Issue
Block a user