Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/run/editor_run_native.cpp
9902 views
1
/**************************************************************************/
2
/* editor_run_native.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
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
31
#include "editor_run_native.h"
32
33
#include "editor/editor_node.h"
34
#include "editor/export/editor_export.h"
35
#include "editor/export/editor_export_platform.h"
36
#include "editor/settings/editor_settings.h"
37
#include "editor/themes/editor_scale.h"
38
39
void EditorRunNative::_notification(int p_what) {
40
switch (p_what) {
41
case NOTIFICATION_THEME_CHANGED: {
42
remote_debug->set_button_icon(get_editor_theme_icon(SNAME("PlayRemote")));
43
} break;
44
45
case NOTIFICATION_PROCESS: {
46
bool changed = EditorExport::get_singleton()->poll_export_platforms() || first;
47
48
if (changed) {
49
PopupMenu *popup = remote_debug->get_popup();
50
popup->clear();
51
int device_shortcut_id = 1;
52
for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
53
Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i);
54
Ref<EditorExportPlatform> eep = preset->get_platform();
55
if (eep.is_null()) {
56
continue;
57
}
58
int platform_idx = -1;
59
for (int j = 0; j < EditorExport::get_singleton()->get_export_platform_count(); j++) {
60
if (eep->get_name() == EditorExport::get_singleton()->get_export_platform(j)->get_name()) {
61
platform_idx = j;
62
break;
63
}
64
}
65
int dc = MIN(eep->get_options_count(), 9000);
66
String error;
67
if (dc > 0 && preset->is_runnable()) {
68
popup->add_icon_item(eep->get_run_icon(), eep->get_name(), -1);
69
popup->set_item_disabled(-1, true);
70
for (int j = 0; j < dc; j++) {
71
popup->add_icon_item(eep->get_option_icon(j), eep->get_option_label(j), 10000 * platform_idx + j);
72
popup->set_item_tooltip(-1, eep->get_option_tooltip(j));
73
popup->set_item_indent(-1, 2);
74
if (device_shortcut_id <= 4) {
75
// Assign shortcuts for the first 4 devices added in the list.
76
popup->set_item_shortcut(-1, ED_GET_SHORTCUT(vformat("remote_deploy/deploy_to_device_%d", device_shortcut_id)), true);
77
device_shortcut_id += 1;
78
}
79
}
80
}
81
}
82
if (popup->get_item_count() == 0) {
83
remote_debug->set_disabled(true);
84
remote_debug->set_tooltip_text(TTRC("No Remote Deploy export presets configured."));
85
} else {
86
remote_debug->set_disabled(false);
87
remote_debug->set_tooltip_text(TTRC("Remote Deploy"));
88
}
89
90
first = false;
91
}
92
} break;
93
}
94
}
95
96
void EditorRunNative::_confirm_run_native() {
97
run_confirmed = true;
98
resume_run_native();
99
}
100
101
Error EditorRunNative::start_run_native(int p_id) {
102
if (p_id < 0) {
103
return OK;
104
}
105
106
int platform = p_id / 10000;
107
int idx = p_id % 10000;
108
resume_id = p_id;
109
110
if (!EditorNode::get_singleton()->ensure_main_scene(true)) {
111
return OK;
112
}
113
114
Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(platform);
115
ERR_FAIL_COND_V(eep.is_null(), ERR_UNAVAILABLE);
116
117
Ref<EditorExportPreset> preset;
118
119
for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
120
Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
121
if (ep->is_runnable() && ep->get_platform() == eep) {
122
preset = ep;
123
break;
124
}
125
}
126
127
if (preset.is_null()) {
128
EditorNode::get_singleton()->show_warning(TTR("No runnable export preset found for this platform.\nPlease add a runnable preset in the Export menu or define an existing preset as runnable."));
129
return ERR_UNAVAILABLE;
130
}
131
132
String architecture = eep->get_device_architecture(idx);
133
if (!run_confirmed && !architecture.is_empty()) {
134
String preset_arch = "architectures/" + architecture;
135
bool is_arch_enabled = preset->get(preset_arch);
136
137
if (!is_arch_enabled) {
138
run_native_confirm->set_text(vformat(TTR("Warning: The CPU architecture \"%s\" is not active in your export preset.\n\nRun \"Remote Deploy\" anyway?"), architecture));
139
run_native_confirm->popup_centered();
140
return OK;
141
}
142
}
143
run_confirmed = false;
144
145
preset->update_value_overrides();
146
147
emit_signal(SNAME("native_run"), preset);
148
149
BitField<EditorExportPlatform::DebugFlags> flags = 0;
150
151
bool deploy_debug_remote = is_deploy_debug_remote_enabled();
152
bool deploy_dumb = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_file_server", false);
153
bool debug_collisions = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_collisions", false);
154
bool debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_navigation", false);
155
156
if (deploy_debug_remote) {
157
flags.set_flag(EditorExportPlatform::DEBUG_FLAG_REMOTE_DEBUG);
158
}
159
if (deploy_dumb) {
160
flags.set_flag(EditorExportPlatform::DEBUG_FLAG_DUMB_CLIENT);
161
}
162
if (debug_collisions) {
163
flags.set_flag(EditorExportPlatform::DEBUG_FLAG_VIEW_COLLISIONS);
164
}
165
if (debug_navigation) {
166
flags.set_flag(EditorExportPlatform::DEBUG_FLAG_VIEW_NAVIGATION);
167
}
168
169
eep->clear_messages();
170
Error err = eep->run(preset, idx, flags);
171
result_dialog_log->clear();
172
if (eep->fill_log_messages(result_dialog_log, err)) {
173
if (eep->get_worst_message_type() >= EditorExportPlatform::EXPORT_MESSAGE_ERROR) {
174
result_dialog->popup_centered_ratio(0.5);
175
}
176
}
177
return err;
178
}
179
180
void EditorRunNative::resume_run_native() {
181
start_run_native(resume_id);
182
}
183
184
void EditorRunNative::_bind_methods() {
185
ADD_SIGNAL(MethodInfo("native_run", PropertyInfo(Variant::OBJECT, "preset", PROPERTY_HINT_RESOURCE_TYPE, "EditorExportPreset")));
186
}
187
188
bool EditorRunNative::is_deploy_debug_remote_enabled() const {
189
return EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_deploy_remote_debug", true);
190
}
191
192
EditorRunNative::EditorRunNative() {
193
ED_SHORTCUT("remote_deploy/deploy_to_device_1", TTRC("Deploy to First Device in List"), KeyModifierMask::SHIFT | Key::F5);
194
ED_SHORTCUT_OVERRIDE("remote_deploy/deploy_to_device_1", "macos", KeyModifierMask::META | KeyModifierMask::SHIFT | Key::B);
195
ED_SHORTCUT("remote_deploy/deploy_to_device_2", TTRC("Deploy to Second Device in List"));
196
ED_SHORTCUT("remote_deploy/deploy_to_device_3", TTRC("Deploy to Third Device in List"));
197
ED_SHORTCUT("remote_deploy/deploy_to_device_4", TTRC("Deploy to Fourth Device in List"));
198
199
remote_debug = memnew(MenuButton);
200
remote_debug->set_flat(false);
201
remote_debug->set_theme_type_variation("RunBarButton");
202
remote_debug->get_popup()->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
203
remote_debug->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &EditorRunNative::start_run_native));
204
remote_debug->set_tooltip_text(TTRC("Remote Deploy"));
205
remote_debug->set_disabled(true);
206
207
add_child(remote_debug);
208
209
result_dialog = memnew(AcceptDialog);
210
result_dialog->set_title(TTR("Project Run"));
211
result_dialog_log = memnew(RichTextLabel);
212
result_dialog_log->set_custom_minimum_size(Size2(300, 80) * EDSCALE);
213
result_dialog->add_child(result_dialog_log);
214
215
add_child(result_dialog);
216
result_dialog->hide();
217
218
run_native_confirm = memnew(ConfirmationDialog);
219
add_child(run_native_confirm);
220
run_native_confirm->connect(SceneStringName(confirmed), callable_mp(this, &EditorRunNative::_confirm_run_native));
221
222
set_process(true);
223
}
224
225