This commit is contained in:
Hyper_ 2025-04-04 16:26:52 -03:00 committed by GitHub
commit e0e7402c1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 5 deletions

View file

@ -764,9 +764,9 @@ class PauseSubState extends MusicBeatSubState
*/
static function quitToChartEditor(state:PauseSubState):Void
{
state.close();
if (FlxG.sound.music != null) FlxG.sound.music.pause(); // Don't reset song position!
PlayState.instance.close(); // This only works because PlayState is a substate!
state.close();
}
}

View file

@ -7,6 +7,7 @@ import flixel.FlxObject;
import flixel.FlxSubState;
import flixel.math.FlxMath;
import flixel.math.FlxPoint;
import flixel.sound.FlxSound;
import flixel.text.FlxText;
import flixel.tweens.FlxTween;
import flixel.ui.FlxBar;
@ -433,6 +434,11 @@ class PlayState extends MusicBeatSubState
*/
var cameraTweensPausedBySubState:List<FlxTween> = new List<FlxTween>();
/**
* Track any sounds we've paused for a Pause substate, so we can unpause them when we return.
*/
var soundsPausedBySubState:List<FlxSound> = new List<FlxSound>();
/**
* False until `create()` has completed.
*/
@ -811,7 +817,6 @@ class PlayState extends MusicBeatSubState
super.update(elapsed);
var list = FlxG.sound.list;
updateHealthBar();
updateScoreText();
@ -1224,9 +1229,25 @@ class PlayState extends MusicBeatSubState
musicPausedBySubState = true;
}
// Pause vocals.
// Not tracking that we've done this via a bool because vocal re-syncing involves pausing the vocals anyway.
if (vocals != null) vocals.pause();
// Pause any sounds that are playing and keep track of them.
// Vocals are also paused here but are not included as they are handled separately.
if (Std.isOfType(subState, PauseSubState))
{
FlxG.sound.list.forEachAlive(function(sound:FlxSound) {
// The need to check for time is obligatory because of scheduled sounds
if (sound == FlxG.sound.music || (!sound.playing && sound.time >= 0)) return;
sound.pause();
soundsPausedBySubState.add(sound);
});
vocals?.forEach(function(voice:FunkinSound) {
soundsPausedBySubState.remove(voice);
});
}
else
{
vocals?.pause();
}
}
// Pause camera tweening, and keep track of which tweens we pause.
@ -1282,6 +1303,8 @@ class PlayState extends MusicBeatSubState
musicPausedBySubState = false;
}
forEachPausedSound(needsReset ? (s) -> s.destroy() : (s) -> s.resume());
// Resume camera tweens if we paused any.
for (camTween in cameraTweensPausedBySubState)
{
@ -3228,6 +3251,8 @@ class PlayState extends MusicBeatSubState
}
}
forEachPausedSound((s) -> s.destroy());
// Remove reference to stage and remove sprites from it to save memory.
if (currentStage != null)
{
@ -3535,6 +3560,15 @@ class PlayState extends MusicBeatSubState
scrollSpeedTweens = [];
}
function forEachPausedSound(f:FlxSound->Void):Void
{
for (sound in soundsPausedBySubState)
{
f(sound);
}
soundsPausedBySubState.clear();
}
#if FEATURE_DEBUG_FUNCTIONS
/**
* Jumps forward or backward a number of sections in the song.