Skip to content

Commit a30f01c

Browse files
committed
Return arrays instead of lists.
1 parent 15c1684 commit a30f01c

File tree

4 files changed

+24
-36
lines changed

4 files changed

+24
-36
lines changed

RhythmGameUtilities.Tests/UtilitiesTest.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,18 @@ public void TestCalculateBeatBars()
7070

7171
var beatBars = Utilities.CalculateBeatBars(bpmChanges, resolution, timeSignature, true);
7272

73-
Assert.That(beatBars.Count, Is.EqualTo(440));
73+
Assert.That(beatBars.Length, Is.EqualTo(440));
7474
}
7575

7676
[Test]
7777
public void TestFindPositionNearGivenTick()
7878
{
79-
var notes = new List<Note>
79+
var notes = new Note[]
8080
{
81-
new() { Position = 768 },
82-
new() { Position = 960 },
83-
new() { Position = 1152 },
84-
new() { Position = 1536 },
85-
new() { Position = 1728 },
86-
new() { Position = 1920 },
87-
new() { Position = 2304 },
88-
new() { Position = 2496 },
89-
new() { Position = 2688 },
90-
new() { Position = 3072 },
91-
new() { Position = 3264 },
81+
new() { Position = 768 }, new() { Position = 960 }, new() { Position = 1152 },
82+
new() { Position = 1536 }, new() { Position = 1728 }, new() { Position = 1920 },
83+
new() { Position = 2304 }, new() { Position = 2496 }, new() { Position = 2688 },
84+
new() { Position = 3072 }, new() { Position = 3264 },
9285
};
9386

9487
Assert.That(Utilities.FindPositionNearGivenTick(notes, 100), Is.Null);

RhythmGameUtilities/Scripts/Utilities.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,34 +84,35 @@ public static int RoundUpToTheNearestMultiplier(int value, int multiplier)
8484
return UtilitiesInternal.RoundUpToTheNearestMultiplier(value, multiplier);
8585
}
8686

87-
public static List<BeatBar> CalculateBeatBars(Dictionary<int, int> bpmChanges, int resolution = 192, int ts = 4,
87+
public static BeatBar[] CalculateBeatBars(Dictionary<int, int> bpmChanges, int resolution = 192, int ts = 4,
8888
bool includeHalfNotes = true)
8989
{
90-
var beatBars = new List<BeatBar>();
9190

9291
var ptrArray = UtilitiesInternal.CalculateBeatBarsInternal(bpmChanges.Keys.ToArray(),
9392
bpmChanges.Values.ToArray(), bpmChanges.Count, resolution, ts, includeHalfNotes,
9493
out var size);
9594

9695
var beatBarSize = Marshal.SizeOf(typeof(BeatBar));
9796

97+
var beatBars = new BeatBar[size];
98+
9899
for (var i = 0; i < size; i += 1)
99100
{
100101
var beatBarSizePtr = new IntPtr(ptrArray.ToInt64() + beatBarSize * i);
101102
var beatBar = Marshal.PtrToStructure<BeatBar>(beatBarSizePtr);
102103

103-
beatBars.Add(beatBar);
104+
beatBars[i] = beatBar;
104105
}
105106

106107
Marshal.FreeHGlobal(ptrArray);
107108

108109
return beatBars;
109110
}
110111

111-
public static Note? FindPositionNearGivenTick(List<Note> notes, int tick, int delta = 50)
112+
public static Note? FindPositionNearGivenTick(Note[] notes, int tick, int delta = 50)
112113
{
113114
var left = 0;
114-
var right = notes.Count - 1;
115+
var right = notes.Length - 1;
115116

116117
while (left <= right)
117118
{

UnityPackage/Editor/Tests/UtilitiesTest.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,18 @@ public void TestCalculateBeatBars()
7070

7171
var beatBars = Utilities.CalculateBeatBars(bpmChanges, resolution, timeSignature, true);
7272

73-
Assert.That(beatBars.Count, Is.EqualTo(440));
73+
Assert.That(beatBars.Length, Is.EqualTo(440));
7474
}
7575

7676
[Test]
7777
public void TestFindPositionNearGivenTick()
7878
{
79-
var notes = new List<Note>
79+
var notes = new Note[]
8080
{
81-
new() { Position = 768 },
82-
new() { Position = 960 },
83-
new() { Position = 1152 },
84-
new() { Position = 1536 },
85-
new() { Position = 1728 },
86-
new() { Position = 1920 },
87-
new() { Position = 2304 },
88-
new() { Position = 2496 },
89-
new() { Position = 2688 },
90-
new() { Position = 3072 },
91-
new() { Position = 3264 },
81+
new() { Position = 768 }, new() { Position = 960 }, new() { Position = 1152 },
82+
new() { Position = 1536 }, new() { Position = 1728 }, new() { Position = 1920 },
83+
new() { Position = 2304 }, new() { Position = 2496 }, new() { Position = 2688 },
84+
new() { Position = 3072 }, new() { Position = 3264 },
9285
};
9386

9487
Assert.That(Utilities.FindPositionNearGivenTick(notes, 100), Is.Null);

UnityPackage/Scripts/Utilities.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,34 +84,35 @@ public static int RoundUpToTheNearestMultiplier(int value, int multiplier)
8484
return UtilitiesInternal.RoundUpToTheNearestMultiplier(value, multiplier);
8585
}
8686

87-
public static List<BeatBar> CalculateBeatBars(Dictionary<int, int> bpmChanges, int resolution = 192, int ts = 4,
87+
public static BeatBar[] CalculateBeatBars(Dictionary<int, int> bpmChanges, int resolution = 192, int ts = 4,
8888
bool includeHalfNotes = true)
8989
{
90-
var beatBars = new List<BeatBar>();
9190

9291
var ptrArray = UtilitiesInternal.CalculateBeatBarsInternal(bpmChanges.Keys.ToArray(),
9392
bpmChanges.Values.ToArray(), bpmChanges.Count, resolution, ts, includeHalfNotes,
9493
out var size);
9594

9695
var beatBarSize = Marshal.SizeOf(typeof(BeatBar));
9796

97+
var beatBars = new BeatBar[size];
98+
9899
for (var i = 0; i < size; i += 1)
99100
{
100101
var beatBarSizePtr = new IntPtr(ptrArray.ToInt64() + beatBarSize * i);
101102
var beatBar = Marshal.PtrToStructure<BeatBar>(beatBarSizePtr);
102103

103-
beatBars.Add(beatBar);
104+
beatBars[i] = beatBar;
104105
}
105106

106107
Marshal.FreeHGlobal(ptrArray);
107108

108109
return beatBars;
109110
}
110111

111-
public static Note? FindPositionNearGivenTick(List<Note> notes, int tick, int delta = 50)
112+
public static Note? FindPositionNearGivenTick(Note[] notes, int tick, int delta = 50)
112113
{
113114
var left = 0;
114-
var right = notes.Count - 1;
115+
var right = notes.Length - 1;
115116

116117
while (left <= right)
117118
{

0 commit comments

Comments
 (0)