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

Fix #2287: Sound not disabled when starting without focus #21777

Conversation

Daniel-Lightbourn
Copy link

For #2287
Defer calling PlayTitleMusic() the first time when OpenRCT2 starts until after SDL events have been polled. This allows the code to process focus events to mute the audio before the title music starts playing.

This slightly changes the current behavior in that the music no longer starts right when the window is created but about when the game starts rendering (about 1 second later on my machine).

Copy link
Member

@ZehMatt ZehMatt left a comment

Choose a reason for hiding this comment

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

This unfortunately a bad approach to go about this issue, this would also only work if people have the Uncap FPS disabled, this is also not the proper place to have logic like this.

@Daniel-Lightbourn
Copy link
Author

I had not noticed there were two Run*Frame functions; I can hoist the check up to cover them, but you seem to not like how I did this.

I can do something more complicated like having a Context::PostFirstFrame function that unpauses the SDL audio device and change AudioMixer::Init to not unpause it. I'd change the do while loop in Context::RunGameLoop to something like:

RunFrame();
PostFirstFrame();
while(!_finished) {
    RunFrame();
}

@Daniel-Lightbourn
Copy link
Author

@ZehMatt?

@ZehMatt
Copy link
Member

ZehMatt commented Apr 23, 2024

I don't like that idea, the music should start playing post-load of a save file, we can probably just add a check for which screen flags are set after a save is loaded and call PlayTitleMusic(), we have quite a lot of code scattered regarding load/save so its best to delay this until we cleaned that up. Perhaps there is a suitable spot for such new code but adding more complexity at the moment is unfortunately out of the question, sorry.

Defer calling `PlayTitleMusic()` the first time when OpenRCT2 starts until
after SDL events have been polled. This allows the code to process focus
events to mute the audio before the title music starts playing.
@Daniel-Lightbourn
Copy link
Author

@ZehMatt What about moving the PlayTitleMusic() inside of TitleScreen::Tick()? I experimented with having it get called after loading a park in a sequence, but unfortunately, that still happens ever so slightly too early; if the main thread were to stall, a couple audio samples could go through before OpenRCT2 realizes it's not in focus.

If you find this acceptably, I'll squash and fix up the commit message.

@AaronVanGeffen
Copy link
Member

Sorry, it shouldn't go in the tick logic either. I appreciate that you're trying to solve an issue, but as @ZehMatt said, it would be better to refactor the loading code instead of hacking in a fix.

Considering the approach, and the emerged merge conflict, I think it's best to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants