2019-01-24 16:43:03 +08:00
|
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
2017-04-17 14:44:46 +08:00
|
|
|
|
using System;
|
2018-01-03 17:44:25 +08:00
|
|
|
|
using System.Linq;
|
2017-05-17 12:07:56 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-09-17 16:40:05 +08:00
|
|
|
|
using System.Threading;
|
2020-06-05 04:28:55 +08:00
|
|
|
|
using osu.Game.Audio;
|
2017-05-17 12:07:56 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2017-05-17 12:07:56 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2017-05-19 15:31:05 +08:00
|
|
|
|
using osu.Game.Rulesets.Mania.Beatmaps.Patterns;
|
2017-05-19 19:57:20 +08:00
|
|
|
|
using osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy;
|
2024-03-28 21:39:15 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2023-10-02 14:53:05 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring.Legacy;
|
2022-04-28 16:46:00 +08:00
|
|
|
|
using osu.Game.Utils;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Mania.Beatmaps
|
2017-03-11 23:34:21 +08:00
|
|
|
|
{
|
2017-05-17 12:07:56 +08:00
|
|
|
|
public class ManiaBeatmapConverter : BeatmapConverter<ManiaHitObject>
|
2017-03-11 23:34:21 +08:00
|
|
|
|
{
|
2017-05-19 19:57:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Maximum number of previous notes to consider for density calculation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const int max_notes_for_density = 7;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-03-28 21:32:27 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The total number of columns.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int TotalColumns => TargetColumns * (Dual ? 2 : 1);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The number of columns per-stage.
|
|
|
|
|
/// </summary>
|
2018-01-03 17:44:25 +08:00
|
|
|
|
public int TargetColumns;
|
2024-03-28 21:32:27 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether to double the number of stages.
|
|
|
|
|
/// </summary>
|
2019-02-28 22:40:03 +08:00
|
|
|
|
public bool Dual;
|
2024-03-28 21:32:27 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the beatmap instantiated with is for the mania ruleset.
|
|
|
|
|
/// </summary>
|
2018-01-03 17:44:25 +08:00
|
|
|
|
public readonly bool IsForCurrentRuleset;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-15 19:52:09 +08:00
|
|
|
|
// Internal for testing purposes
|
2024-03-28 21:39:15 +08:00
|
|
|
|
internal readonly LegacyRandom Random;
|
2018-06-15 19:52:09 +08:00
|
|
|
|
|
2017-05-19 15:31:05 +08:00
|
|
|
|
private Pattern lastPattern = new Pattern();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-24 15:02:16 +08:00
|
|
|
|
public ManiaBeatmapConverter(IBeatmap beatmap, Ruleset ruleset)
|
2024-03-28 21:39:15 +08:00
|
|
|
|
: this(beatmap, LegacyBeatmapConversionDifficultyInfo.FromBeatmap(beatmap), ruleset)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ManiaBeatmapConverter(IBeatmap? beatmap, LegacyBeatmapConversionDifficultyInfo difficulty, Ruleset ruleset)
|
|
|
|
|
: base(beatmap!, ruleset)
|
2017-03-11 23:34:21 +08:00
|
|
|
|
{
|
2024-03-28 21:39:15 +08:00
|
|
|
|
IsForCurrentRuleset = difficulty.SourceRuleset.Equals(ruleset.RulesetInfo);
|
|
|
|
|
Random = new LegacyRandom((int)MathF.Round(difficulty.DrainRate + difficulty.CircleSize) * 20 + (int)(difficulty.OverallDifficulty * 41.2) + (int)MathF.Round(difficulty.ApproachRate));
|
|
|
|
|
TargetColumns = getColumnCount(difficulty);
|
2018-05-07 10:23:29 +08:00
|
|
|
|
|
2023-10-02 14:53:05 +08:00
|
|
|
|
if (IsForCurrentRuleset && TargetColumns > ManiaRuleset.MAX_STAGE_KEYS)
|
2018-01-03 17:44:25 +08:00
|
|
|
|
{
|
2023-10-02 14:53:05 +08:00
|
|
|
|
TargetColumns /= 2;
|
|
|
|
|
Dual = true;
|
2018-01-03 17:44:25 +08:00
|
|
|
|
}
|
2020-10-14 16:53:28 +08:00
|
|
|
|
|
2024-03-28 21:39:15 +08:00
|
|
|
|
static int getColumnCount(LegacyBeatmapConversionDifficultyInfo difficulty)
|
|
|
|
|
{
|
|
|
|
|
double roundedCircleSize = Math.Round(difficulty.CircleSize);
|
2023-12-09 21:09:49 +08:00
|
|
|
|
|
2024-03-28 21:39:15 +08:00
|
|
|
|
if (difficulty.SourceRuleset.ShortName == ManiaRuleset.SHORT_NAME)
|
|
|
|
|
return (int)Math.Max(1, roundedCircleSize);
|
2023-10-02 14:53:05 +08:00
|
|
|
|
|
2024-03-28 21:39:15 +08:00
|
|
|
|
double roundedOverallDifficulty = Math.Round(difficulty.OverallDifficulty);
|
2023-10-02 14:53:05 +08:00
|
|
|
|
|
2024-03-28 21:39:15 +08:00
|
|
|
|
if (difficulty.TotalObjectCount > 0 && difficulty.EndTimeObjectCount >= 0)
|
|
|
|
|
{
|
|
|
|
|
int countSliderOrSpinner = difficulty.EndTimeObjectCount;
|
|
|
|
|
|
|
|
|
|
// In osu!stable, this division appears as if it happens on floats, but due to release-mode
|
|
|
|
|
// optimisations, it actually ends up happening on doubles.
|
|
|
|
|
double percentSpecialObjects = (double)countSliderOrSpinner / difficulty.TotalObjectCount;
|
2023-10-02 14:53:05 +08:00
|
|
|
|
|
2024-03-28 21:39:15 +08:00
|
|
|
|
if (percentSpecialObjects < 0.2)
|
|
|
|
|
return 7;
|
|
|
|
|
if (percentSpecialObjects < 0.3 || roundedCircleSize >= 5)
|
|
|
|
|
return roundedOverallDifficulty > 5 ? 7 : 6;
|
|
|
|
|
if (percentSpecialObjects > 0.6)
|
|
|
|
|
return roundedOverallDifficulty > 4 ? 5 : 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Math.Max(4, Math.Min((int)roundedOverallDifficulty + 1, 7));
|
|
|
|
|
}
|
2023-10-02 14:53:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-28 21:39:15 +08:00
|
|
|
|
public static int GetColumnCount(LegacyBeatmapConversionDifficultyInfo difficulty, IReadOnlyList<Mod>? mods = null)
|
2017-08-22 12:01:51 +08:00
|
|
|
|
{
|
2024-03-28 21:39:15 +08:00
|
|
|
|
var converter = new ManiaBeatmapConverter(null, difficulty, new ManiaRuleset());
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-03-28 21:39:15 +08:00
|
|
|
|
if (mods != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var m in mods.OfType<IApplicableToBeatmapConverter>())
|
|
|
|
|
m.ApplyToBeatmapConverter(converter);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-03-28 21:39:15 +08:00
|
|
|
|
return converter.TotalColumns;
|
2017-03-11 23:34:21 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-03-28 21:39:15 +08:00
|
|
|
|
public override bool CanConvert() => Beatmap.HitObjects.All(h => h is IHasXPosition);
|
|
|
|
|
|
2019-02-28 18:07:43 +08:00
|
|
|
|
protected override Beatmap<ManiaHitObject> CreateBeatmap()
|
|
|
|
|
{
|
2024-03-28 21:47:43 +08:00
|
|
|
|
ManiaBeatmap beatmap = new ManiaBeatmap(new StageDefinition(TargetColumns));
|
2019-02-28 18:07:43 +08:00
|
|
|
|
|
2019-03-01 13:30:58 +08:00
|
|
|
|
if (Dual)
|
2022-10-05 18:14:31 +08:00
|
|
|
|
beatmap.Stages.Add(new StageDefinition(TargetColumns));
|
2019-02-28 18:07:43 +08:00
|
|
|
|
|
|
|
|
|
return beatmap;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-09-17 16:40:05 +08:00
|
|
|
|
protected override IEnumerable<ManiaHitObject> ConvertHitObject(HitObject original, IBeatmap beatmap, CancellationToken cancellationToken)
|
2017-05-17 12:07:56 +08:00
|
|
|
|
{
|
2019-02-28 13:35:00 +08:00
|
|
|
|
if (original is ManiaHitObject maniaOriginal)
|
2017-05-19 14:57:32 +08:00
|
|
|
|
{
|
|
|
|
|
yield return maniaOriginal;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2017-05-19 14:57:32 +08:00
|
|
|
|
yield break;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-14 10:27:14 +08:00
|
|
|
|
var objects = IsForCurrentRuleset ? generateSpecific(original, beatmap) : generateConverted(original, beatmap);
|
2017-05-19 15:31:05 +08:00
|
|
|
|
foreach (ManiaHitObject obj in objects)
|
|
|
|
|
yield return obj;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-06-15 19:00:15 +08:00
|
|
|
|
private readonly LimitedCapacityQueue<double> prevNoteTimes = new LimitedCapacityQueue<double>(max_notes_for_density);
|
2017-05-19 19:57:20 +08:00
|
|
|
|
private double density = int.MaxValue;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2017-05-19 19:57:20 +08:00
|
|
|
|
private void computeDensity(double newNoteTime)
|
|
|
|
|
{
|
2023-06-15 19:00:15 +08:00
|
|
|
|
prevNoteTimes.Enqueue(newNoteTime);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-09 20:11:12 +08:00
|
|
|
|
if (prevNoteTimes.Count >= 2)
|
|
|
|
|
density = (prevNoteTimes[^1] - prevNoteTimes[0]) / prevNoteTimes.Count;
|
2017-05-19 19:57:20 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-19 19:57:20 +08:00
|
|
|
|
private double lastTime;
|
|
|
|
|
private Vector2 lastPosition;
|
2018-06-15 21:08:24 +08:00
|
|
|
|
private PatternType lastStair = PatternType.Stair;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2017-05-19 19:57:20 +08:00
|
|
|
|
private void recordNote(double time, Vector2 position)
|
|
|
|
|
{
|
|
|
|
|
lastTime = time;
|
|
|
|
|
lastPosition = position;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-19 15:39:02 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Method that generates hit objects for osu!mania specific beatmaps.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="original">The original hit object.</param>
|
2018-03-14 10:27:14 +08:00
|
|
|
|
/// <param name="originalBeatmap">The original beatmap. This is used to look-up any values dependent on a fully-loaded beatmap.</param>
|
2017-05-19 15:39:02 +08:00
|
|
|
|
/// <returns>The hit objects generated.</returns>
|
2018-04-19 19:44:38 +08:00
|
|
|
|
private IEnumerable<ManiaHitObject> generateSpecific(HitObject original, IBeatmap originalBeatmap)
|
2017-05-19 15:31:05 +08:00
|
|
|
|
{
|
2024-03-28 21:32:27 +08:00
|
|
|
|
var generator = new SpecificBeatmapPatternGenerator(Random, original, originalBeatmap, TotalColumns, lastPattern);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-15 21:10:57 +08:00
|
|
|
|
foreach (var newPattern in generator.Generate())
|
|
|
|
|
{
|
|
|
|
|
lastPattern = newPattern;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-15 21:10:57 +08:00
|
|
|
|
foreach (var obj in newPattern.HitObjects)
|
|
|
|
|
yield return obj;
|
|
|
|
|
}
|
2017-05-19 15:31:05 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-19 15:39:02 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Method that generates hit objects for non-osu!mania beatmaps.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="original">The original hit object.</param>
|
2018-03-14 10:27:14 +08:00
|
|
|
|
/// <param name="originalBeatmap">The original beatmap. This is used to look-up any values dependent on a fully-loaded beatmap.</param>
|
2017-05-19 15:39:02 +08:00
|
|
|
|
/// <returns>The hit objects generated.</returns>
|
2018-04-19 19:44:38 +08:00
|
|
|
|
private IEnumerable<ManiaHitObject> generateConverted(HitObject original, IBeatmap originalBeatmap)
|
2017-05-19 15:31:05 +08:00
|
|
|
|
{
|
2024-03-28 21:32:27 +08:00
|
|
|
|
Patterns.PatternGenerator? conversion = null;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-11-12 18:16:51 +08:00
|
|
|
|
switch (original)
|
2018-06-15 19:52:09 +08:00
|
|
|
|
{
|
2023-11-29 16:30:21 +08:00
|
|
|
|
case IHasPath:
|
2019-11-12 18:16:51 +08:00
|
|
|
|
{
|
2024-03-28 21:32:27 +08:00
|
|
|
|
var generator = new PathObjectPatternGenerator(Random, original, originalBeatmap, TotalColumns, lastPattern);
|
2019-11-12 18:16:51 +08:00
|
|
|
|
conversion = generator;
|
|
|
|
|
|
|
|
|
|
var positionData = original as IHasPosition;
|
|
|
|
|
|
2020-09-07 15:30:05 +08:00
|
|
|
|
for (int i = 0; i <= generator.SpanCount; i++)
|
2019-11-12 18:16:51 +08:00
|
|
|
|
{
|
2020-09-07 15:30:05 +08:00
|
|
|
|
double time = original.StartTime + generator.SegmentDuration * i;
|
|
|
|
|
|
2019-11-12 18:16:51 +08:00
|
|
|
|
recordNote(time, positionData?.Position ?? Vector2.Zero);
|
|
|
|
|
computeDensity(time);
|
|
|
|
|
}
|
2018-06-15 19:52:36 +08:00
|
|
|
|
|
2019-11-12 18:16:51 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-27 11:38:39 +08:00
|
|
|
|
case IHasDuration endTimeData:
|
2018-06-15 19:52:36 +08:00
|
|
|
|
{
|
2024-03-28 21:32:27 +08:00
|
|
|
|
conversion = new EndTimeObjectPatternGenerator(Random, original, originalBeatmap, TotalColumns, lastPattern);
|
2019-11-12 18:16:51 +08:00
|
|
|
|
|
|
|
|
|
recordNote(endTimeData.EndTime, new Vector2(256, 192));
|
|
|
|
|
computeDensity(endTimeData.EndTime);
|
|
|
|
|
break;
|
2018-06-15 19:52:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-12 18:16:51 +08:00
|
|
|
|
case IHasPosition positionData:
|
|
|
|
|
{
|
|
|
|
|
computeDensity(original.StartTime);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-03-28 21:32:27 +08:00
|
|
|
|
conversion = new HitObjectPatternGenerator(Random, original, originalBeatmap, TotalColumns, lastPattern, lastTime, lastPosition, density, lastStair);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-11-12 18:16:51 +08:00
|
|
|
|
recordNote(original.StartTime, positionData.Position);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-05-19 15:31:05 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-19 19:57:20 +08:00
|
|
|
|
if (conversion == null)
|
2018-06-15 21:10:57 +08:00
|
|
|
|
yield break;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-15 21:10:57 +08:00
|
|
|
|
foreach (var newPattern in conversion.Generate())
|
|
|
|
|
{
|
|
|
|
|
lastPattern = conversion is EndTimeObjectPatternGenerator ? lastPattern : newPattern;
|
|
|
|
|
lastStair = (conversion as HitObjectPatternGenerator)?.StairType ?? lastStair;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-15 21:10:57 +08:00
|
|
|
|
foreach (var obj in newPattern.HitObjects)
|
|
|
|
|
yield return obj;
|
|
|
|
|
}
|
2017-05-19 15:31:05 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-19 15:31:05 +08:00
|
|
|
|
/// <summary>
|
2017-05-19 15:39:02 +08:00
|
|
|
|
/// A pattern generator for osu!mania-specific beatmaps.
|
2017-05-19 15:31:05 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
private class SpecificBeatmapPatternGenerator : Patterns.Legacy.PatternGenerator
|
|
|
|
|
{
|
2024-03-28 21:32:27 +08:00
|
|
|
|
public SpecificBeatmapPatternGenerator(LegacyRandom random, HitObject hitObject, IBeatmap beatmap, int totalColumns, Pattern previousPattern)
|
|
|
|
|
: base(random, hitObject, beatmap, previousPattern, totalColumns)
|
2017-05-19 15:31:05 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-15 21:10:57 +08:00
|
|
|
|
public override IEnumerable<Pattern> Generate()
|
|
|
|
|
{
|
|
|
|
|
yield return generate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Pattern generate()
|
2017-05-19 15:31:05 +08:00
|
|
|
|
{
|
|
|
|
|
var positionData = HitObject as IHasXPosition;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-19 15:31:05 +08:00
|
|
|
|
int column = GetColumn(positionData?.X ?? 0);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-19 15:31:05 +08:00
|
|
|
|
var pattern = new Pattern();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-05-27 11:38:39 +08:00
|
|
|
|
if (HitObject is IHasDuration endTimeData)
|
2017-05-19 15:31:05 +08:00
|
|
|
|
{
|
|
|
|
|
pattern.Add(new HoldNote
|
|
|
|
|
{
|
|
|
|
|
StartTime = HitObject.StartTime,
|
|
|
|
|
Duration = endTimeData.Duration,
|
2020-04-22 12:45:12 +08:00
|
|
|
|
Column = column,
|
2020-04-21 15:33:19 +08:00
|
|
|
|
Samples = HitObject.Samples,
|
2020-06-05 04:28:55 +08:00
|
|
|
|
NodeSamples = (HitObject as IHasRepeats)?.NodeSamples ?? defaultNodeSamples
|
2017-05-19 15:31:05 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2019-11-12 18:16:51 +08:00
|
|
|
|
else if (HitObject is IHasXPosition)
|
2017-05-19 15:31:05 +08:00
|
|
|
|
{
|
|
|
|
|
pattern.Add(new Note
|
|
|
|
|
{
|
|
|
|
|
StartTime = HitObject.StartTime,
|
|
|
|
|
Samples = HitObject.Samples,
|
|
|
|
|
Column = column
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-19 15:31:05 +08:00
|
|
|
|
return pattern;
|
|
|
|
|
}
|
2020-06-05 04:28:55 +08:00
|
|
|
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// osu!mania-specific beatmaps in stable only play samples at the start of the hold note.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
private List<IList<HitSampleInfo>> defaultNodeSamples
|
|
|
|
|
=> new List<IList<HitSampleInfo>>
|
|
|
|
|
{
|
|
|
|
|
HitObject.Samples,
|
|
|
|
|
new List<HitSampleInfo>()
|
|
|
|
|
};
|
2017-05-17 12:07:56 +08:00
|
|
|
|
}
|
2017-03-11 23:34:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|