Skip to content

Commit cd6b30d

Browse files
authored
Merge pull request #6 from winnerspiros/fix-catch-time-delta-truncation-11917992746850541583
Fix integer truncation in CatchBeatmapProcessor time delta calculation
2 parents 46ffbb9 + 1894ab5 commit cd6b30d

3 files changed

Lines changed: 61 additions & 3 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2+
// See the LICENCE file in the repository root for full licence text.
3+
4+
using System.Collections.Generic;
5+
using NUnit.Framework;
6+
using osu.Game.Beatmaps;
7+
using osu.Game.Rulesets.Catch.Beatmaps;
8+
using osu.Game.Rulesets.Catch.Objects;
9+
10+
namespace osu.Game.Rulesets.Catch.Tests
11+
{
12+
[TestFixture]
13+
public class CatchBeatmapProcessorTest
14+
{
15+
[Test]
16+
public void TestHardRockOffsetDoublePrecision()
17+
{
18+
// Setup a beatmap with two fruits that will trigger the logic difference.
19+
// We need a time difference that has a fractional part.
20+
// And we need HardRock enabled.
21+
22+
// lastPosition = 100, lastStartTime = 1000.
23+
// offsetPosition = 133.2, startTime = 1100.5.
24+
25+
// positionDiff = 33.2.
26+
// timeDiff (int) = 100.
27+
// timeDiff (double) = 100.5.
28+
29+
// positionDiff < timeDiff / 3
30+
// 33.2 < 33 (False)
31+
// 33.2 < 33.5 (True)
32+
33+
var beatmap = new Beatmap<CatchHitObject>
34+
{
35+
HitObjects = new List<CatchHitObject>
36+
{
37+
new Fruit { StartTime = 1000, X = 100 },
38+
new Fruit { StartTime = 1000 + 100.5, X = 100 + 33.2f }
39+
}
40+
};
41+
42+
var processor = new CatchBeatmapProcessor(beatmap)
43+
{
44+
HardRockOffsets = true
45+
};
46+
47+
processor.ApplyPositionOffsets(beatmap);
48+
49+
var secondObj = beatmap.HitObjects[1];
50+
51+
// If bug is present (int truncation), condition is false, XOffset is 0.
52+
// If fixed (double), condition is true, XOffset is 33.2 (approx).
53+
54+
Assert.That(secondObj.XOffset, Is.Not.EqualTo(0).Within(0.001));
55+
Assert.That(secondObj.XOffset, Is.EqualTo(33.2f).Within(0.001));
56+
}
57+
}
58+
}

osu.Game.Rulesets.Catch.Tests/Resources/Testing/Beatmaps/1431386-expected-conversion.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

osu.Game.Rulesets.Catch/Beatmaps/CatchBeatmapProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ private static void applyHardRockOffset(CatchHitObject hitObject, ref float? las
132132

133133
float positionDiff = offsetPosition - lastPosition.Value;
134134

135-
// Todo: BUG!! Stable calculated time deltas as ints, which affects randomisation. This should be changed to a double.
136-
int timeDiff = (int)(startTime - lastStartTime);
135+
// Stable calculated time deltas as ints, which affects randomisation. This has been changed to a double to fix the issue.
136+
double timeDiff = startTime - lastStartTime;
137137

138138
if (timeDiff > 1000)
139139
{

0 commit comments

Comments
 (0)