diff --git a/scenes/main_menu.tscn b/scenes/main_menu.tscn index 74f2487..1e394b6 100644 --- a/scenes/main_menu.tscn +++ b/scenes/main_menu.tscn @@ -1719,12 +1719,12 @@ text = "[font_size=20]fog fit_content = true horizontal_alignment = 1 -[node name="xwalfie" type="RichTextLabel" parent="Menus/Extras/Credits/ScrollContainer/VBoxContainer" unique_id=427847284] +[node name="nyarw" type="RichTextLabel" parent="Menus/Extras/Credits/ScrollContainer/VBoxContainer" unique_id=427847284] modulate = Color(0.2627451, 1, 0.9529412, 1) layout_mode = 2 mouse_filter = 1 bbcode_enabled = true -text = "[font_size=20]xwalfie +text = "[font_size=20]nyarw [color=ffffffbb][font_size=16]Contributor" fit_content = true horizontal_alignment = 1 diff --git a/scripts/game/Runner.cs b/scripts/game/Runner.cs index 575cbad..164744d 100644 --- a/scripts/game/Runner.cs +++ b/scripts/game/Runner.cs @@ -27,6 +27,7 @@ public partial class Runner : Node3D private double lastFrame = Time.GetTicksUsec(); private bool firstFrame = true; private bool eventsConnected = false; + private double[] noteTimestamps; [ExportCategory("Settings")] [Export] public bool NotesOnly = false; @@ -206,9 +207,10 @@ public void Play() foreach (var entry in Attempt.Objects) { - ObjectIndicesStart[entry.Key] = 0; + ObjectIndicesStart[entry.Key] = (int)Attempt.FirstNote; ObjectIndicesEnd[entry.Key] = entry.Value.Count; } + noteTimestamps = Attempt.Objects[typeof(Note)].Select(note => (double)note.Millisecond).ToArray(); if (!NotesOnly) { @@ -311,7 +313,7 @@ public void Seek(double ms) foreach (var entry in Attempt.Objects) { - ObjectIndicesStart[entry.Key] = 0; + ObjectIndicesStart[entry.Key] = Util.Misc.BinarySearch(noteTimestamps, ms) + 1; ObjectIndicesEnd[entry.Key] = entry.Value.Count; } diff --git a/scripts/ui/FlatPreview.cs b/scripts/ui/FlatPreview.cs index 2377a27..e4b04e7 100644 --- a/scripts/ui/FlatPreview.cs +++ b/scripts/ui/FlatPreview.cs @@ -13,6 +13,7 @@ public partial class FlatPreview : Panel private Color transparent = new(1, 1, 1, 0); private ColorRect[] tiles = new ColorRect[9]; private int lastPassedNote = 0; + private double[] noteTimestamps; public override void _Ready() { @@ -69,14 +70,7 @@ public override void _Process(double delta) if (Time < oldTime) { - for (int i = 0; i < Map.Notes.Length; i++) - { - if (Time < Map.Notes[i].Millisecond) - { - lastPassedNote = i - 1; - break; - } - } + lastPassedNote = Util.Misc.BinarySearch(noteTimestamps, Time); } for (int i = Math.Clamp(lastPassedNote + 1, 0, Math.Max(0, Map.Notes.Length - 1)); i < Map.Notes.Length; i++) @@ -105,6 +99,7 @@ public void Setup(Map map, bool useSoundManagerStreamPlayer = false) Map = map; UseSoundManagerStreamPlayer = useSoundManagerStreamPlayer; lastPassedNote = -1; + noteTimestamps = Array.ConvertAll(Map.Notes, note => (double)note.Millisecond); } public void Seek(double seek) @@ -113,15 +108,6 @@ public void Seek(double seek) Time = seek; - for (int i = 0; i < Map.Notes.Length; i++) - { - var note = Map.Notes[i]; - - if (note.Millisecond > Time) - { - lastPassedNote = i - 1; - break; - } - } + lastPassedNote = Util.Misc.BinarySearch(noteTimestamps, seek); } } diff --git a/scripts/util/Misc.cs b/scripts/util/Misc.cs index 9c81a0e..7ea4640 100644 --- a/scripts/util/Misc.cs +++ b/scripts/util/Misc.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Security.Cryptography; @@ -160,4 +161,25 @@ public static float ParseFloatInput(string input, float fallback = 0f) return fallback; } + + public static int BinarySearch(double[] values, double time) + { + int left = 0, right = values.Length; + + while (left < right) + { + int middle = (left + right) / 2; + + if (time < values[middle]) + { + right = middle; + } + else + { + left = middle + 1; + } + } + + return left - 1; + } }