mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 17:38:16 +03:00
Re-fix resumemusic/musicfadein once again
So it looks like facb079b35 (PR #316) had
a few issues.
The SDL performance counter doesn't really work that well. Testing
reveals that unfocusing and focusing the game again results in
the resumemusic() script command resuming the track at the wrong time.
Even when not unfocusing the game at all, stopping a track and resuming
it resumes it at the wrong time. (Only disabling the unfocus pause fixes
this.)
Furthermore, there's also the fact that the SDL performance counter
keeps incrementing when the game is paused under GDB. So... yeah.
Instead of dealing with the SDL performance counter, I'm just going to
pause and resume the music directly (so the stopmusic() script command
just pauses the music instead). As a result, we no longer can keep
constantly calling Mix_PauseMusic() or Mix_ResumeMusic() when focused or
unfocused, so I've moved those calls to happen directly when the
relevant SDL events are received (the constant calls were originally in
VCE, and whoever added them (I'm pretty sure it was Leo) was not the
sharpest tool in the shed...).
And we are going to switch over to using our own fade system instead of
the SDL mixer fade system. In fact, we were already using our own fade
system for fadeins after collecting a trinket or a custom level
crewmate, but we were still using the mixer system for the rest. This is
an inconsistency that I am glad to correct, so we're also doing our own
fadeouts now.
There is, however, an issue with the fade system where the length it
goes for is inaccurate, because it's based on a volume-per-frame second
calculation that gets truncated. But that's an issue to fix later - at
least what I'm doing right now makes resumemusic() and musicfadein()
work better than before.
This commit is contained in:
@@ -56,8 +56,6 @@ KeyPoll::KeyPoll(void)
|
||||
|
||||
linealreadyemptykludge = false;
|
||||
|
||||
pauseStart = 0;
|
||||
|
||||
isActive = true;
|
||||
}
|
||||
|
||||
@@ -287,6 +285,8 @@ void KeyPoll::Poll(void)
|
||||
if (!game.disablepause)
|
||||
{
|
||||
isActive = true;
|
||||
music.resume();
|
||||
music.resumeef();
|
||||
}
|
||||
if (!useFullscreenSpaces)
|
||||
{
|
||||
@@ -300,16 +300,13 @@ void KeyPoll::Poll(void)
|
||||
}
|
||||
}
|
||||
SDL_DisableScreenSaver();
|
||||
if (!game.disablepause && Mix_PlayingMusic())
|
||||
{
|
||||
// Correct songStart for how long we were paused
|
||||
music.songStart += SDL_GetPerformanceCounter() - pauseStart;
|
||||
}
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
if (!game.disablepause)
|
||||
{
|
||||
isActive = false;
|
||||
music.pause();
|
||||
music.pauseef();
|
||||
}
|
||||
if (!useFullscreenSpaces)
|
||||
{
|
||||
@@ -321,10 +318,6 @@ void KeyPoll::Poll(void)
|
||||
);
|
||||
}
|
||||
SDL_EnableScreenSaver();
|
||||
if (!game.disablepause)
|
||||
{
|
||||
pauseStart = SDL_GetPerformanceCounter();
|
||||
}
|
||||
break;
|
||||
|
||||
/* Mouse Focus */
|
||||
|
||||
Reference in New Issue
Block a user