Skip to content

Commit a11364d

Browse files
committed
Merge pull request #99010 from Hilderin/embedding-game-process
Embed game process in editor
2 parents 8a743f2 + 9d2a4c0 commit a11364d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1712
-134
lines changed

core/config/engine.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,14 @@ void Engine::set_freeze_time_scale(bool p_frozen) {
415415
freeze_time_scale = p_frozen;
416416
}
417417

418+
void Engine::set_embedded_in_editor(bool p_enabled) {
419+
embedded_in_editor = p_enabled;
420+
}
421+
422+
bool Engine::is_embedded_in_editor() const {
423+
return embedded_in_editor;
424+
}
425+
418426
Engine::Engine() {
419427
singleton = this;
420428
}

core/config/engine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class Engine {
8686
bool editor_hint = false;
8787
bool project_manager_hint = false;
8888
bool extension_reloading = false;
89+
bool embedded_in_editor = false;
8990

9091
bool _print_header = true;
9192

@@ -200,6 +201,8 @@ class Engine {
200201
bool notify_frame_server_synced();
201202

202203
void set_freeze_time_scale(bool p_frozen);
204+
void set_embedded_in_editor(bool p_enabled);
205+
bool is_embedded_in_editor() const;
203206

204207
Engine();
205208
virtual ~Engine();

core/core_bind.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,10 @@ bool Engine::is_editor_hint() const {
19061906
return ::Engine::get_singleton()->is_editor_hint();
19071907
}
19081908

1909+
bool Engine::is_embedded_in_editor() const {
1910+
return ::Engine::get_singleton()->is_embedded_in_editor();
1911+
}
1912+
19091913
String Engine::get_write_movie_path() const {
19101914
return ::Engine::get_singleton()->get_write_movie_path();
19111915
}
@@ -1983,6 +1987,7 @@ void Engine::_bind_methods() {
19831987
ClassDB::bind_method(D_METHOD("get_script_language", "index"), &Engine::get_script_language);
19841988

19851989
ClassDB::bind_method(D_METHOD("is_editor_hint"), &Engine::is_editor_hint);
1990+
ClassDB::bind_method(D_METHOD("is_embedded_in_editor"), &Engine::is_embedded_in_editor);
19861991

19871992
ClassDB::bind_method(D_METHOD("get_write_movie_path"), &Engine::get_write_movie_path);
19881993

core/core_bind.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ class Engine : public Object {
584584
void set_editor_hint(bool p_enabled);
585585
bool is_editor_hint() const;
586586

587+
bool is_embedded_in_editor() const;
588+
587589
// `set_write_movie_path()` is not exposed to the scripting API as changing it at run-time has no effect.
588590
String get_write_movie_path() const;
589591

core/os/os.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ bool OS::has_feature(const String &p_feature) {
408408
return _in_editor;
409409
} else if (p_feature == "editor_runtime") {
410410
return !_in_editor;
411+
} else if (p_feature == "embedded_in_editor") {
412+
return _embedded_in_editor;
411413
}
412414
#else
413415
if (p_feature == "template") {

core/os/os.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class OS {
6262
bool _stderr_enabled = true;
6363
bool _writing_movie = false;
6464
bool _in_editor = false;
65+
bool _embedded_in_editor = false;
6566

6667
CompositeLogger *_logger = nullptr;
6768

doc/classes/DisplayServer.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,9 @@
19251925
<constant name="FEATURE_SCREEN_EXCLUDE_FROM_CAPTURE" value="28" enum="Feature">
19261926
Display server supports [constant WINDOW_FLAG_EXCLUDE_FROM_CAPTURE] window flag.
19271927
</constant>
1928+
<constant name="FEATURE_WINDOW_EMBEDDING" value="29" enum="Feature">
1929+
Display server supports embedding a window from another process. [b]Windows, Linux (X11)[/b]
1930+
</constant>
19281931
<constant name="MOUSE_MODE_VISIBLE" value="0" enum="MouseMode">
19291932
Makes the mouse cursor visible if it is hidden.
19301933
</constant>

doc/classes/Engine.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@
240240
[b]Note:[/b] To detect whether the script is running on an editor [i]build[/i] (such as when pressing [kbd]F5[/kbd]), use [method OS.has_feature] with the [code]"editor"[/code] argument instead. [code]OS.has_feature("editor")[/code] evaluate to [code]true[/code] both when the script is running in the editor and when running the project from the editor, but returns [code]false[/code] when run from an exported project.
241241
</description>
242242
</method>
243+
<method name="is_embedded_in_editor" qualifiers="const">
244+
<return type="bool" />
245+
<description>
246+
Returns [code]true[/code] if the engine is running embedded in the editor. This is useful to prevent attempting to update window mode or window flags that are not supported when running the project embedded in the editor.
247+
</description>
248+
</method>
243249
<method name="is_in_physics_frame" qualifiers="const">
244250
<return type="bool" />
245251
<description>

editor/editor_node.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,9 @@ void EditorNode::_notification(int p_what) {
755755
}
756756

757757
// Set a low FPS cap to decrease CPU/GPU usage while the editor is unfocused.
758-
OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/unfocused_low_processor_mode_sleep_usec")));
758+
if (unfocused_low_processor_usage_mode_enabled) {
759+
OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/unfocused_low_processor_mode_sleep_usec")));
760+
}
759761
} break;
760762

761763
case NOTIFICATION_WM_ABOUT: {
@@ -6732,6 +6734,10 @@ int EditorNode::execute_and_show_output(const String &p_title, const String &p_p
67326734
return eta.exitcode;
67336735
}
67346736

6737+
void EditorNode::set_unfocused_low_processor_usage_mode_enabled(bool p_enabled) {
6738+
unfocused_low_processor_usage_mode_enabled = p_enabled;
6739+
}
6740+
67356741
EditorNode::EditorNode() {
67366742
DEV_ASSERT(!singleton);
67376743
singleton = this;

editor/editor_node.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ class EditorNode : public Node {
476476

477477
bool was_window_windowed_last = false;
478478

479+
bool unfocused_low_processor_usage_mode_enabled = true;
480+
479481
static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS];
480482
static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
481483
static int build_callback_count;
@@ -791,6 +793,8 @@ class EditorNode : public Node {
791793
HashMap<StringName, Variant> get_modified_properties_for_node(Node *p_node, bool p_node_references_only);
792794
HashMap<StringName, Variant> get_modified_properties_reference_to_nodes(Node *p_node, List<Node *> &p_nodes_referenced_by);
793795

796+
void set_unfocused_low_processor_usage_mode_enabled(bool p_enabled);
797+
794798
struct AdditiveNodeEntry {
795799
Node *node = nullptr;
796800
NodePath parent;

0 commit comments

Comments
 (0)