Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scenes/main_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions scripts/game/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand Down
22 changes: 4 additions & 18 deletions scripts/ui/FlatPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
}
22 changes: 22 additions & 0 deletions scripts/util/Misc.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Security.Cryptography;
Expand Down Expand Up @@ -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;
}
}
Loading