Skip to content

Commit

Permalink
Fix OpenRCT2#2287: Sound not disabled when starting without focus
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Daniel-Lightbourn committed Apr 23, 2024
1 parent 1b4defb commit feaafa4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ Appreciation for contributors who have provided substantial work, but are no lon
* Jan Kelemen (jan-kelemen)
* Cory Ye (CoryfY)
* Karsten Van Fossan (karstenvanf)
* Daniel Lightbourn (Daniel-Lightbourn)

## Toolchain
* (Balletie) - macOS
Expand Down
8 changes: 8 additions & 0 deletions src/openrct2/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,14 @@ namespace OpenRCT2

_uiContext->ProcessMessages();

// Start the title music now that focus events have been processed.
if (static bool firstTime = true; firstTime)
{
firstTime = false;

OpenRCT2::Audio::PlayTitleMusic();
}

if (_ticksAccumulator < kGameUpdateTimeMS)
{
const auto sleepTimeSec = (kGameUpdateTimeMS - _ticksAccumulator);
Expand Down
11 changes: 10 additions & 1 deletion src/openrct2/title/TitleScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,16 @@ void TitleScreen::Load()
ContextOpenWindow(WindowClass::MainWindow);
CreateWindows();
TitleInitialise();
OpenRCT2::Audio::PlayTitleMusic();

// Defer the title music until window messages can be processed.
if (static bool firstTime = true; firstTime)
{
firstTime = false;
}
else
{
OpenRCT2::Audio::PlayTitleMusic();
}

if (gOpenRCT2ShowChangelog)
{
Expand Down

0 comments on commit feaafa4

Please sign in to comment.