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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user