mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 10:47:28 +08:00
Sort beat lengths rather than linear search
This commit is contained in:
parent
b40b159acb
commit
18e3f8c233
@ -55,7 +55,7 @@ namespace osu.Game.Beatmaps
|
|||||||
// Note: This is more accurate and may present different results because osu-stable didn't have the ability to calculate slider durations in this context.
|
// Note: This is more accurate and may present different results because osu-stable didn't have the ability to calculate slider durations in this context.
|
||||||
double lastTime = HitObjects.LastOrDefault()?.GetEndTime() ?? ControlPointInfo.TimingPoints.LastOrDefault()?.Time ?? 0;
|
double lastTime = HitObjects.LastOrDefault()?.GetEndTime() ?? ControlPointInfo.TimingPoints.LastOrDefault()?.Time ?? 0;
|
||||||
|
|
||||||
var beatLengthsAndDurations =
|
var mostCommon =
|
||||||
// Construct a set of (beatLength, duration) tuples for each individual timing point.
|
// Construct a set of (beatLength, duration) tuples for each individual timing point.
|
||||||
ControlPointInfo.TimingPoints.Select((t, i) =>
|
ControlPointInfo.TimingPoints.Select((t, i) =>
|
||||||
{
|
{
|
||||||
@ -68,23 +68,10 @@ namespace osu.Game.Beatmaps
|
|||||||
// Aggregate durations into a set of (beatLength, duration) tuples for each beat length
|
// Aggregate durations into a set of (beatLength, duration) tuples for each beat length
|
||||||
.GroupBy(t => Math.Round(t.beatLength * 1000) / 1000)
|
.GroupBy(t => Math.Round(t.beatLength * 1000) / 1000)
|
||||||
.Select(g => (beatLength: g.Key, duration: g.Sum(t => t.duration)))
|
.Select(g => (beatLength: g.Key, duration: g.Sum(t => t.duration)))
|
||||||
// And if there are no timing points, use a default.
|
// Get the most common one, or 0 as a suitable default
|
||||||
.DefaultIfEmpty((TimingControlPoint.DEFAULT_BEAT_LENGTH, 0));
|
.OrderByDescending(i => i.duration).FirstOrDefault();
|
||||||
|
|
||||||
// Find the single beat length with the maximum aggregate duration.
|
return mostCommon.beatLength;
|
||||||
double maxDurationBeatLength = double.NegativeInfinity;
|
|
||||||
double maxDuration = double.NegativeInfinity;
|
|
||||||
|
|
||||||
foreach (var (beatLength, duration) in beatLengthsAndDurations)
|
|
||||||
{
|
|
||||||
if (duration > maxDuration)
|
|
||||||
{
|
|
||||||
maxDuration = duration;
|
|
||||||
maxDurationBeatLength = beatLength;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return maxDurationBeatLength;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IBeatmap IBeatmap.Clone() => Clone();
|
IBeatmap IBeatmap.Clone() => Clone();
|
||||||
|
Loading…
Reference in New Issue
Block a user