From 982b3078a440916c07fb74d17b3d9389daff0045 Mon Sep 17 00:00:00 2001 From: nyarw Date: Sun, 23 Aug 2026 14:55:35 +0200 Subject: [PATCH 1/3] binary search --- scripts/game/Runner.cs | 4 ++-- scripts/util/Misc.cs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/scripts/game/Runner.cs b/scripts/game/Runner.cs index 575cbad..58d0a68 100644 --- a/scripts/game/Runner.cs +++ b/scripts/game/Runner.cs @@ -206,7 +206,7 @@ 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; } @@ -311,7 +311,7 @@ public void Seek(double ms) foreach (var entry in Attempt.Objects) { - ObjectIndicesStart[entry.Key] = 0; + ObjectIndicesStart[entry.Key] = Util.Misc.BinarySearch(entry.Value, ms) + 1; ObjectIndicesEnd[entry.Key] = entry.Value.Count; } diff --git a/scripts/util/Misc.cs b/scripts/util/Misc.cs index 9c81a0e..b8e21e7 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(IReadOnlyList notes, double time) where T : ITimelineObject + { + int left = 0, right = notes.Count; + + while (left < right) + { + int middle = (left + right) / 2; + + if (time < notes[middle].Millisecond) + { + right = middle; + } + else + { + left = middle + 1; + } + } + + return left - 1; + } } From 7f7fb3ddec1f35d1331d2da77161ea4bbc9a5706 Mon Sep 17 00:00:00 2001 From: xwalfie Date: Mon, 24 Aug 2026 21:37:49 +0200 Subject: [PATCH 2/3] make binarysearch double[] --- scripts/game/Runner.cs | 4 +++- scripts/ui/FlatPreview.cs | 22 ++++------------------ scripts/util/Misc.cs | 6 +++--- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/scripts/game/Runner.cs b/scripts/game/Runner.cs index 58d0a68..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; @@ -209,6 +210,7 @@ public void Play() 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] = Util.Misc.BinarySearch(entry.Value, ms) + 1; + 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 b8e21e7..7ea4640 100644 --- a/scripts/util/Misc.cs +++ b/scripts/util/Misc.cs @@ -162,15 +162,15 @@ public static float ParseFloatInput(string input, float fallback = 0f) return fallback; } - public static int BinarySearch(IReadOnlyList notes, double time) where T : ITimelineObject + public static int BinarySearch(double[] values, double time) { - int left = 0, right = notes.Count; + int left = 0, right = values.Length; while (left < right) { int middle = (left + right) / 2; - if (time < notes[middle].Millisecond) + if (time < values[middle]) { right = middle; } From 949d1d575abf01cd7b84fccda2cc77a57f3f860e Mon Sep 17 00:00:00 2001 From: nyarw Date: Tue, 25 Aug 2026 15:46:19 +0200 Subject: [PATCH 3/3] rename xwalfie to nyarw in contributor list --- scenes/main_menu.tscn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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