switch to less stuttery timing method
This commit is contained in:
@@ -4,6 +4,19 @@ using System;
|
||||
|
||||
public partial class BGM : AudioStreamPlayer
|
||||
{
|
||||
// latency compensation
|
||||
private ulong timeStartUsec;
|
||||
private float timeDelay;
|
||||
|
||||
public float CurTime
|
||||
{
|
||||
get
|
||||
{
|
||||
float time = (Time.GetTicksUsec() - timeStartUsec) / 1000000f;
|
||||
return time - timeDelay;
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadFromUser(string path)
|
||||
{
|
||||
if (!path.StartsWith("user://"))
|
||||
@@ -43,4 +56,11 @@ public partial class BGM : AudioStreamPlayer
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
timeStartUsec = Time.GetTicksUsec();
|
||||
timeDelay = (float) (AudioServer.GetTimeToNextMix() + AudioServer.GetOutputLatency());
|
||||
base.Play();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace WacK.Scenes
|
||||
double time = bgmController.GetPlaybackPosition() + AudioServer.GetTimeSinceLastMix() - AudioServer.GetOutputLatency();
|
||||
|
||||
var nPos = noteDisplay.Position;
|
||||
nPos.Y = ((float)time * scrollPxPerSec) + 1920;
|
||||
nPos.Y = (bgmController.CurTime * scrollPxPerSec) + 1910;
|
||||
noteDisplay.Position = nPos;
|
||||
scrollDisplay.Position = nPos;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user