switch to less stuttery timing method
This commit is contained in:
+10
-17
@@ -61,7 +61,7 @@ uv1_scale = Vector3(-1, 1, 1)
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_w20vk"]
|
||||
viewport_path = NodePath("Mask")
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_bs53h"]
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_osg3y"]
|
||||
resource_local_to_scene = true
|
||||
shader = ExtResource("3_rjbyl")
|
||||
shader_parameter/mask = SubResource("ViewportTexture_w20vk")
|
||||
@@ -140,7 +140,7 @@ anchor_mode = 0
|
||||
editor_draw_screen = false
|
||||
|
||||
[node name="Background" parent="2D Viewport/Viewport Control" instance=ExtResource("2_8g6gv")]
|
||||
material = SubResource("ShaderMaterial_bs53h")
|
||||
material = SubResource("ShaderMaterial_osg3y")
|
||||
layout_mode = 1
|
||||
offset_top = -1920.0
|
||||
offset_right = 1920.0
|
||||
@@ -187,8 +187,8 @@ layout_mode = 1
|
||||
anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -1820.0
|
||||
offset_bottom = -1820.0
|
||||
offset_top = -1920.0
|
||||
offset_bottom = -1920.0
|
||||
grow_vertical = 0
|
||||
|
||||
[node name="ViewportView Left" type="SubViewportContainer" parent="2D Viewport/Viewport Control"]
|
||||
@@ -232,21 +232,14 @@ position = Vector2(0, -1920)
|
||||
offset = Vector2(1921, 1920)
|
||||
anchor_mode = 0
|
||||
|
||||
[node name="ViewportView" type="SubViewportContainer" parent="."]
|
||||
modulate = Color(1, 1, 1, 0.329412)
|
||||
anchors_preset = 7
|
||||
anchor_left = 0.5
|
||||
anchor_top = 1.0
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -960.0
|
||||
offset_top = -1920.0
|
||||
offset_right = 960.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
|
||||
[node name="AudioStreamPlayer BGM" type="AudioStreamPlayer" parent="."]
|
||||
script = ExtResource("4_c2dke")
|
||||
|
||||
[node name="AudioStreamPlayer SFX" type="AudioStreamPlayer" parent="."]
|
||||
script = ExtResource("5_owrd5")
|
||||
|
||||
[node name="Dev Area" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 1920.0
|
||||
offset_bottom = 1920.0
|
||||
|
||||
@@ -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