1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-25 16:24:40 +00:00

voicesgroup resync

This commit is contained in:
MtH 2022-03-10 01:07:39 +01:00
parent 8ff1a3cb85
commit 151c96afc8
2 changed files with 27 additions and 2 deletions

View file

@ -1839,7 +1839,6 @@ class PlayState extends MusicBeatState
{ {
if (_exiting) if (_exiting)
return; return;
vocals.pause(); vocals.pause();
FlxG.sound.music.play(); FlxG.sound.music.play();
Conductor.songPosition = FlxG.sound.music.time + Conductor.offset; Conductor.songPosition = FlxG.sound.music.time + Conductor.offset;
@ -2895,8 +2894,9 @@ class PlayState extends MusicBeatState
override function stepHit() override function stepHit()
{ {
super.stepHit(); super.stepHit();
if (Math.abs(FlxG.sound.music.time - (Conductor.songPosition - Conductor.offset)) > 20 if (Math.abs(FlxG.sound.music.time - (Conductor.songPosition - Conductor.offset)) > 20
|| (SONG.needsVoices && Math.abs(vocals.time - (Conductor.songPosition - Conductor.offset)) > 20)) || Math.abs(vocals.checkSyncError(Conductor.songPosition - Conductor.offset)) > 20)
{ {
resyncVocals(); resyncVocals();
} }

View file

@ -36,6 +36,31 @@ class VoicesGroup extends FlxTypedGroup<FlxSound>
} }
} }
/**
* Finds the largest deviation from the desired time inside this VoicesGroup.
*
* @param targetTime The time to check against.
* If none is provided, it checks the time of all members against the first member of this VoicesGroup.
* @return The largest deviation from the target time found.
*/
public function checkSyncError(?targetTime:Float):Float
{
var error:Float = 0;
forEachAlive(function(snd)
{
if (targetTime == null)
targetTime = snd.time;
else
{
var diff:Float = snd.time - targetTime;
if (Math.abs(diff) > Math.abs(error))
error = diff;
}
});
return error;
}
// prob a better / cleaner way to do all these forEach stuff? // prob a better / cleaner way to do all these forEach stuff?
public function pause() public function pause()
{ {