1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Merge pull request #20606 from sw1tchbl4d3r/barline_generator_improvements

Barline generator improvements
This commit is contained in:
Dean Herbert 2022-10-11 01:31:30 +09:00 committed by GitHub
commit 5a43cb6bb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 97 additions and 5 deletions

View File

@ -0,0 +1,87 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Taiko.Objects;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Taiko.Tests
{
public class TestSceneBarLineGeneration : OsuTestScene
{
[Test]
public void TestCloseBarLineGeneration()
{
const double start_time = 1000;
var beatmap = new Beatmap<TaikoHitObject>
{
HitObjects =
{
new Hit
{
Type = HitType.Centre,
StartTime = start_time
}
},
BeatmapInfo =
{
Difficulty = new BeatmapDifficulty { SliderTickRate = 4 },
Ruleset = new TaikoRuleset().RulesetInfo
},
};
beatmap.ControlPointInfo.Add(start_time, new TimingControlPoint());
beatmap.ControlPointInfo.Add(start_time + 1, new TimingControlPoint());
var barlines = new BarLineGenerator<BarLine>(beatmap).BarLines;
AddAssert("first barline generated", () => barlines.Any(b => b.StartTime == start_time));
AddAssert("second barline generated", () => barlines.Any(b => b.StartTime == start_time + 1));
}
[Test]
public void TestOmitBarLineEffectPoint()
{
const double start_time = 1000;
const double beat_length = 500;
const int time_signature_numerator = 4;
var beatmap = new Beatmap<TaikoHitObject>
{
HitObjects =
{
new Hit
{
Type = HitType.Centre,
StartTime = start_time
}
},
BeatmapInfo =
{
Difficulty = new BeatmapDifficulty { SliderTickRate = 4 },
Ruleset = new TaikoRuleset().RulesetInfo
},
};
beatmap.ControlPointInfo.Add(start_time, new TimingControlPoint
{
BeatLength = beat_length,
TimeSignature = new TimeSignature(time_signature_numerator)
});
beatmap.ControlPointInfo.Add(start_time, new EffectControlPoint { OmitFirstBarLine = true });
var barlines = new BarLineGenerator<BarLine>(beatmap).BarLines;
AddAssert("first barline ommited", () => barlines.All(b => b.StartTime != start_time));
AddAssert("second barline generated", () => barlines.Any(b => b.StartTime == start_time + (beat_length * time_signature_numerator)));
}
}
}

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
@ -40,14 +38,21 @@ namespace osu.Game.Rulesets.Objects
for (int i = 0; i < timingPoints.Count; i++)
{
TimingControlPoint currentTimingPoint = timingPoints[i];
EffectControlPoint currentEffectPoint = beatmap.ControlPointInfo.EffectPointAt(currentTimingPoint.Time);
int currentBeat = 0;
// Stop on the beat before the next timing point, or if there is no next timing point stop slightly past the last object
double endTime = i < timingPoints.Count - 1 ? timingPoints[i + 1].Time - currentTimingPoint.BeatLength : lastHitTime + currentTimingPoint.BeatLength * currentTimingPoint.TimeSignature.Numerator;
// Stop on the next timing point, or if there is no next timing point stop slightly past the last object
double endTime = i < timingPoints.Count - 1 ? timingPoints[i + 1].Time : lastHitTime + currentTimingPoint.BeatLength * currentTimingPoint.TimeSignature.Numerator;
double startTime = currentTimingPoint.Time;
double barLength = currentTimingPoint.BeatLength * currentTimingPoint.TimeSignature.Numerator;
for (double t = currentTimingPoint.Time; Precision.DefinitelyBigger(endTime, t); t += barLength, currentBeat++)
if (currentEffectPoint.OmitFirstBarLine)
{
startTime += barLength;
}
for (double t = startTime; Precision.AlmostBigger(endTime, t); t += barLength, currentBeat++)
{
double roundedTime = Math.Round(t, MidpointRounding.AwayFromZero);