Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keep_screen_on editor setting #95048

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

KoBeWi
Copy link
Member

@KoBeWi KoBeWi commented Aug 2, 2024

Closes #95020

I did not test if the setting is working correctly.

@KoBeWi KoBeWi added this to the 4.4 milestone Aug 2, 2024
@KoBeWi KoBeWi requested review from a team as code owners August 2, 2024 01:49
Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least on macOS, this won't fully solve the issue, Project Manager will still prevent Mac from sleeping since it's initializing the audio driver, which is constantly outputting "empty" sound.

Adding something like this on top of it (this change by itself seems fine and is necessary to allow sleeping) will do it:

diff --git a/main/main.cpp b/main/main.cpp
index e42469b51b..fcace48686 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -2355,6 +2355,10 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
 		// If all else failed it would be the dummy driver (no sound).
 		audio_driver_idx = 0;
 	}
+	if (project_manager) {
+		audio_driver = NULL_AUDIO_DRIVER;
+		audio_driver_idx = AudioDriverManager::get_driver_count() - 1;
+	}
 
 	if (Engine::get_singleton()->get_write_movie_path() != String()) {
 		// Always use dummy driver for audio driver (which is last), also in no threaded mode.

I do not think project manager is using audio at all, so it should not have any negative effects. Won't help with the editor, we probably gonna need some sort of "low priority" audio driver mode, where it's starting on demand and shutting down after few seconds of silence.

@kus04e4ek
Copy link
Contributor

kus04e4ek commented Aug 2, 2024

diff --git a/main/main.cpp b/main/main.cpp
index e42469b51b..fcace48686 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -2355,6 +2355,10 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
 		// If all else failed it would be the dummy driver (no sound).
 		audio_driver_idx = 0;
 	}
+	if (project_manager) {
+		audio_driver = NULL_AUDIO_DRIVER;
+		audio_driver_idx = AudioDriverManager::get_driver_count() - 1;
+	}
 
 	if (Engine::get_singleton()->get_write_movie_path() != String()) {
 		// Always use dummy driver for audio driver (which is last), also in no threaded mode.

Something like this feels a little bit better from the style perspective (keeps special cases together where audio_driver is dummy and audio_driver is not used after this, so it's not needed to be set):

diff --git a/main/main.cpp b/main/main.cpp
index e42469b51b0..acc271c594e 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -2360,6 +2360,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
 		// Always use dummy driver for audio driver (which is last), also in no threaded mode.
 		audio_driver_idx = AudioDriverManager::get_driver_count() - 1;
 		AudioDriverDummy::get_dummy_singleton()->set_use_threads(false);
+	} else if (project_manager) {
+		// Always use dummy driver for audio driver (which is last).
+		audio_driver_idx = AudioDriverManager::get_driver_count() - 1;
 	}
 
 	{

Specifiying audio driver in command line arguments can be useful for testing (even in Project Manager just to check that everything initializes properly), but it's not possible when going with the current style. I would refactor it like this, but it's probably worth it's own PR:

diff

diff --git a/main/main.cpp b/main/main.cpp
index e42469b51b0..fd37fea7a6c 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -2336,30 +2336,35 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
 	GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.ios", PROPERTY_HINT_ENUM_SUGGESTION, "default,iOS,headless"), "default");
 	GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.macos", PROPERTY_HINT_ENUM_SUGGESTION, "default,macos,headless"), "default");
 
-	GLOBAL_DEF_RST_NOVAL("audio/driver/driver", AudioDriverManager::get_driver(0)->get_name());
-	if (audio_driver.is_empty()) { // Specified in project.godot.
-		audio_driver = GLOBAL_GET("audio/driver/driver");
-	}
-
 	// Make sure that dummy is the last one, which it is assumed to be by design.
 	DEV_ASSERT(NULL_AUDIO_DRIVER == AudioDriverManager::get_driver(AudioDriverManager::get_driver_count() - 1)->get_name());
-	for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
-		if (audio_driver == AudioDriverManager::get_driver(i)->get_name()) {
-			audio_driver_idx = i;
-			break;
-		}
-	}
 
-	if (audio_driver_idx < 0) {
-		// If the requested driver wasn't found, pick the first entry.
-		// If all else failed it would be the dummy driver (no sound).
-		audio_driver_idx = 0;
-	}
-
-	if (Engine::get_singleton()->get_write_movie_path() != String()) {
+	GLOBAL_DEF_RST_NOVAL("audio/driver/driver", AudioDriverManager::get_driver(0)->get_name());
+	if (!Engine::get_singleton()->get_write_movie_path().is_empty()) {
 		// Always use dummy driver for audio driver (which is last), also in no threaded mode.
 		audio_driver_idx = AudioDriverManager::get_driver_count() - 1;
 		AudioDriverDummy::get_dummy_singleton()->set_use_threads(false);
+	} else if (project_manager && audio_driver.is_empty()) {
+		// Project Manager uses the dummy driver for the audio driver (which is last)
+		// unless the audio driver is specified in command line arguments.
+		audio_driver_idx = AudioDriverManager::get_driver_count() - 1;
+	} else {
+		if (audio_driver.is_empty()) { // Specified in project.godot.
+			audio_driver = GLOBAL_GET("audio/driver/driver");
+		}
+
+		for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
+			if (audio_driver == AudioDriverManager::get_driver(i)->get_name()) {
+				audio_driver_idx = i;
+				break;
+			}
+		}
+
+		if (audio_driver_idx < 0) {
+			// If the requested driver wasn't found, pick the first entry.
+			// If all else failed it would be the dummy driver (no sound).
+			audio_driver_idx = 0;
+		}
 	}
 
 	{

We probably gonna need some sort of "low priority" audio driver mode, where it's starting on demand and shutting down after few seconds of silence.

See #63458 for 3.x.

@KoBeWi
Copy link
Member Author

KoBeWi commented Aug 2, 2024

The audio driver issue is quite old and not really related to the one linked here. I think #38208 addresses it.

@akien-mga akien-mga merged commit 012ccbc into godotengine:master Aug 27, 2024
18 checks passed
@akien-mga
Copy link
Member

Thanks!

@KoBeWi KoBeWi deleted the keep_the_party_going branch August 27, 2024 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Project manager prevents screensaver/powersaving from starting
4 participants