|
@@ -42,14 +42,14 @@ Add these two and it's possible to guess almost exactly when sound or music will
|
|
|
|
|
|
|
|
|
|
func _ready():
|
|
func _ready():
|
|
- time_begin = OS.get_ticks_usec()
|
|
|
|
|
|
+ time_begin = Time.get_ticks_usec()
|
|
time_delay = AudioServer.get_time_to_next_mix() + AudioServer.get_output_latency()
|
|
time_delay = AudioServer.get_time_to_next_mix() + AudioServer.get_output_latency()
|
|
$Player.play()
|
|
$Player.play()
|
|
|
|
|
|
|
|
|
|
func _process(delta):
|
|
func _process(delta):
|
|
# Obtain from ticks.
|
|
# Obtain from ticks.
|
|
- var time = (OS.get_ticks_usec() - time_begin) / 1000000.0
|
|
|
|
|
|
+ var time = (Time.get_ticks_usec() - time_begin) / 1000000.0
|
|
# Compensate for latency.
|
|
# Compensate for latency.
|
|
time -= time_delay
|
|
time -= time_delay
|
|
# May be below 0 (did not begin yet).
|
|
# May be below 0 (did not begin yet).
|
|
@@ -63,14 +63,14 @@ Add these two and it's possible to guess almost exactly when sound or music will
|
|
|
|
|
|
public override void _Ready()
|
|
public override void _Ready()
|
|
{
|
|
{
|
|
- _timeBegin = OS.GetTicksUsec();
|
|
|
|
|
|
+ _timeBegin = Time.GetTicksUsec();
|
|
_timeDelay = AudioServer.GetTimeToNextMix() + AudioServer.GetOutputLatency();
|
|
_timeDelay = AudioServer.GetTimeToNextMix() + AudioServer.GetOutputLatency();
|
|
GetNode<AudioStreamPlayer>("Player").Play();
|
|
GetNode<AudioStreamPlayer>("Player").Play();
|
|
}
|
|
}
|
|
|
|
|
|
public override void _Process(float _delta)
|
|
public override void _Process(float _delta)
|
|
{
|
|
{
|
|
- double time = (OS.GetTicksUsec() - _timeBegin) / 1000000.0d;
|
|
|
|
|
|
+ double time = (Time.GetTicksUsec() - _timeBegin) / 1000000.0d;
|
|
time = Math.Max(0.0d, time - _timeDelay);
|
|
time = Math.Max(0.0d, time - _timeDelay);
|
|
GD.Print(string.Format("Time is: {0}", time));
|
|
GD.Print(string.Format("Time is: {0}", time));
|
|
}
|
|
}
|