2017-03-11 15:34:21 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-05-17 04:07:56 +00:00
|
|
|
|
using osu.Game.Rulesets.Beatmaps;
|
2017-04-18 07:05:58 +00:00
|
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
2017-04-17 06:44:46 +00:00
|
|
|
|
using System;
|
2017-05-17 04:07:56 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Game.Beatmaps;
|
2017-04-18 07:05:58 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2017-05-17 04:07:56 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2017-05-19 07:31:05 +00:00
|
|
|
|
using osu.Game.Rulesets.Mania.Beatmaps.Patterns;
|
|
|
|
|
using osu.Game.Rulesets.Mania.MathUtils;
|
|
|
|
|
using osu.Game.Database;
|
2017-05-19 11:57:20 +00:00
|
|
|
|
using osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy;
|
|
|
|
|
using OpenTK;
|
2017-05-29 07:18:01 +00:00
|
|
|
|
using osu.Game.Audio;
|
2017-03-11 15:34:21 +00:00
|
|
|
|
|
2017-04-18 07:05:58 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Mania.Beatmaps
|
2017-03-11 15:34:21 +00:00
|
|
|
|
{
|
2017-05-17 04:07:56 +00:00
|
|
|
|
public class ManiaBeatmapConverter : BeatmapConverter<ManiaHitObject>
|
2017-03-11 15:34:21 +00:00
|
|
|
|
{
|
2017-05-19 11:57:20 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Maximum number of previous notes to consider for density calculation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const int max_notes_for_density = 7;
|
|
|
|
|
|
2017-05-19 08:38:06 +00:00
|
|
|
|
protected override IEnumerable<Type> ValidConversionTypes { get; } = new[] { typeof(IHasXPosition) };
|
2017-04-17 06:44:46 +00:00
|
|
|
|
|
2017-05-19 07:31:05 +00:00
|
|
|
|
private Pattern lastPattern = new Pattern();
|
|
|
|
|
private FastRandom random;
|
2017-05-19 07:49:05 +00:00
|
|
|
|
private Beatmap beatmap;
|
2017-05-19 07:31:05 +00:00
|
|
|
|
private bool isForCurrentRuleset;
|
|
|
|
|
|
2017-05-19 06:57:32 +00:00
|
|
|
|
protected override Beatmap<ManiaHitObject> ConvertBeatmap(Beatmap original, bool isForCurrentRuleset)
|
2017-03-11 15:34:21 +00:00
|
|
|
|
{
|
2017-05-19 07:31:05 +00:00
|
|
|
|
this.isForCurrentRuleset = isForCurrentRuleset;
|
2017-05-19 06:57:32 +00:00
|
|
|
|
|
2017-05-19 07:49:05 +00:00
|
|
|
|
beatmap = original;
|
|
|
|
|
|
2017-05-19 07:31:05 +00:00
|
|
|
|
BeatmapDifficulty difficulty = original.BeatmapInfo.Difficulty;
|
2017-05-11 03:32:30 +00:00
|
|
|
|
|
2017-05-19 07:31:05 +00:00
|
|
|
|
int seed = (int)Math.Round(difficulty.DrainRate + difficulty.CircleSize) * 20 + (int)(difficulty.OverallDifficulty * 41.2) + (int)Math.Round(difficulty.ApproachRate);
|
|
|
|
|
random = new FastRandom(seed);
|
|
|
|
|
|
|
|
|
|
return base.ConvertBeatmap(original, isForCurrentRuleset);
|
2017-03-11 15:34:21 +00:00
|
|
|
|
}
|
2017-05-17 04:07:56 +00:00
|
|
|
|
|
|
|
|
|
protected override IEnumerable<ManiaHitObject> ConvertHitObject(HitObject original, Beatmap beatmap)
|
|
|
|
|
{
|
2017-05-19 06:57:32 +00:00
|
|
|
|
var maniaOriginal = original as ManiaHitObject;
|
|
|
|
|
if (maniaOriginal != null)
|
|
|
|
|
{
|
|
|
|
|
yield return maniaOriginal;
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 07:49:05 +00:00
|
|
|
|
var objects = isForCurrentRuleset ? generateSpecific(original) : generateConverted(original);
|
2017-05-19 07:31:05 +00:00
|
|
|
|
|
|
|
|
|
if (objects == null)
|
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
|
|
foreach (ManiaHitObject obj in objects)
|
|
|
|
|
yield return obj;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-22 04:43:53 +00:00
|
|
|
|
private readonly List<double> prevNoteTimes = new List<double>(max_notes_for_density);
|
2017-05-19 11:57:20 +00:00
|
|
|
|
private double density = int.MaxValue;
|
|
|
|
|
private void computeDensity(double newNoteTime)
|
|
|
|
|
{
|
|
|
|
|
if (prevNoteTimes.Count == max_notes_for_density)
|
|
|
|
|
prevNoteTimes.RemoveAt(0);
|
|
|
|
|
prevNoteTimes.Add(newNoteTime);
|
|
|
|
|
|
|
|
|
|
density = (prevNoteTimes[prevNoteTimes.Count - 1] - prevNoteTimes[0]) / prevNoteTimes.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double lastTime;
|
|
|
|
|
private Vector2 lastPosition;
|
|
|
|
|
private PatternType lastStair;
|
|
|
|
|
private void recordNote(double time, Vector2 position)
|
|
|
|
|
{
|
|
|
|
|
lastTime = time;
|
|
|
|
|
lastPosition = position;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 07:39:02 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Method that generates hit objects for osu!mania specific beatmaps.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="original">The original hit object.</param>
|
|
|
|
|
/// <returns>The hit objects generated.</returns>
|
2017-05-19 07:49:05 +00:00
|
|
|
|
private IEnumerable<ManiaHitObject> generateSpecific(HitObject original)
|
2017-05-19 07:31:05 +00:00
|
|
|
|
{
|
|
|
|
|
var generator = new SpecificBeatmapPatternGenerator(random, original, beatmap, lastPattern);
|
|
|
|
|
|
|
|
|
|
Pattern newPattern = generator.Generate();
|
|
|
|
|
lastPattern = newPattern;
|
|
|
|
|
|
|
|
|
|
return newPattern.HitObjects;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 07:39:02 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Method that generates hit objects for non-osu!mania beatmaps.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="original">The original hit object.</param>
|
|
|
|
|
/// <returns>The hit objects generated.</returns>
|
2017-05-19 07:49:05 +00:00
|
|
|
|
private IEnumerable<ManiaHitObject> generateConverted(HitObject original)
|
2017-05-19 07:31:05 +00:00
|
|
|
|
{
|
|
|
|
|
var endTimeData = original as IHasEndTime;
|
|
|
|
|
var distanceData = original as IHasDistance;
|
|
|
|
|
var positionData = original as IHasPosition;
|
|
|
|
|
|
|
|
|
|
// Following lines currently commented out to appease resharper
|
|
|
|
|
|
2017-05-19 11:57:20 +00:00
|
|
|
|
Patterns.PatternGenerator conversion = null;
|
2017-05-19 07:31:05 +00:00
|
|
|
|
|
|
|
|
|
if (distanceData != null)
|
2017-05-19 08:48:23 +00:00
|
|
|
|
conversion = new DistanceObjectPatternGenerator(random, original, beatmap, lastPattern);
|
2017-05-19 07:31:05 +00:00
|
|
|
|
else if (endTimeData != null)
|
2017-05-19 08:51:59 +00:00
|
|
|
|
conversion = new EndTimeObjectPatternGenerator(random, original, beatmap);
|
2017-05-19 07:31:05 +00:00
|
|
|
|
else if (positionData != null)
|
|
|
|
|
{
|
2017-05-19 11:57:20 +00:00
|
|
|
|
computeDensity(original.StartTime);
|
|
|
|
|
|
|
|
|
|
conversion = new HitObjectPatternGenerator(random, original, beatmap, lastPattern, lastTime, lastPosition, density, lastStair);
|
|
|
|
|
|
|
|
|
|
recordNote(original.StartTime, positionData.Position);
|
2017-05-19 07:31:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 11:57:20 +00:00
|
|
|
|
if (conversion == null)
|
|
|
|
|
return null;
|
2017-05-19 07:31:05 +00:00
|
|
|
|
|
2017-05-19 11:57:20 +00:00
|
|
|
|
Pattern newPattern = conversion.Generate();
|
|
|
|
|
lastPattern = newPattern;
|
|
|
|
|
|
2017-05-19 12:17:14 +00:00
|
|
|
|
var stairPatternGenerator = (HitObjectPatternGenerator)conversion;
|
|
|
|
|
lastStair = stairPatternGenerator.StairType;
|
2017-05-19 07:31:05 +00:00
|
|
|
|
|
2017-05-19 11:57:20 +00:00
|
|
|
|
return newPattern.HitObjects;
|
2017-05-19 07:31:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-05-19 07:39:02 +00:00
|
|
|
|
/// A pattern generator for osu!mania-specific beatmaps.
|
2017-05-19 07:31:05 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
private class SpecificBeatmapPatternGenerator : Patterns.Legacy.PatternGenerator
|
|
|
|
|
{
|
|
|
|
|
public SpecificBeatmapPatternGenerator(FastRandom random, HitObject hitObject, Beatmap beatmap, Pattern previousPattern)
|
|
|
|
|
: base(random, hitObject, beatmap, previousPattern)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Pattern Generate()
|
|
|
|
|
{
|
|
|
|
|
var endTimeData = HitObject as IHasEndTime;
|
|
|
|
|
var positionData = HitObject as IHasXPosition;
|
|
|
|
|
|
|
|
|
|
int column = GetColumn(positionData?.X ?? 0);
|
2017-05-19 06:57:32 +00:00
|
|
|
|
|
2017-05-19 07:31:05 +00:00
|
|
|
|
var pattern = new Pattern();
|
2017-05-19 06:57:32 +00:00
|
|
|
|
|
2017-05-19 07:31:05 +00:00
|
|
|
|
if (endTimeData != null)
|
|
|
|
|
{
|
|
|
|
|
pattern.Add(new HoldNote
|
|
|
|
|
{
|
|
|
|
|
StartTime = HitObject.StartTime,
|
|
|
|
|
Duration = endTimeData.Duration,
|
|
|
|
|
Column = column,
|
2017-05-29 07:18:01 +00:00
|
|
|
|
Head = { Samples = sampleInfoListAt(HitObject.StartTime) },
|
|
|
|
|
Tail = { Samples = sampleInfoListAt(endTimeData.EndTime) },
|
2017-05-19 07:31:05 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (positionData != null)
|
|
|
|
|
{
|
|
|
|
|
pattern.Add(new Note
|
|
|
|
|
{
|
|
|
|
|
StartTime = HitObject.StartTime,
|
|
|
|
|
Samples = HitObject.Samples,
|
|
|
|
|
Column = column
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pattern;
|
|
|
|
|
}
|
2017-05-29 07:18:01 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves the sample info list at a point in time.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="time">The time to retrieve the sample info list from.</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private SampleInfoList sampleInfoListAt(double time)
|
|
|
|
|
{
|
|
|
|
|
var curveData = HitObject as IHasCurve;
|
|
|
|
|
|
|
|
|
|
if (curveData == null)
|
|
|
|
|
return HitObject.Samples;
|
|
|
|
|
|
|
|
|
|
double segmentTime = (curveData.EndTime - HitObject.StartTime) / curveData.RepeatCount;
|
|
|
|
|
|
|
|
|
|
int index = (int)(segmentTime == 0 ? 0 : (time - HitObject.StartTime) / segmentTime);
|
|
|
|
|
return curveData.RepeatSamples[index];
|
|
|
|
|
}
|
2017-05-17 04:07:56 +00:00
|
|
|
|
}
|
2017-03-11 15:34:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|