Define the concept of patterns + additional comments.

This commit is contained in:
smoogipooo
2017-05-18 15:05:45 +09:00
parent 618c162535
commit 1fa1897d71
8 changed files with 255 additions and 201 deletions

View File

@ -1,32 +1,33 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK; using System;
using System.Collections.Generic;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy;
using osu.Game.Rulesets.Mania.MathUtils;
using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using System; using OpenTK;
using System.Collections.Generic;
using osu.Game.Rulesets.Mania.MathUtils;
namespace osu.Game.Rulesets.Mania.Beatmaps namespace osu.Game.Rulesets.Mania.Beatmaps
{ {
/// <summary> /// <summary>
/// Special converter used for converting from osu!stable beatmaps. /// Special converter used for converting from osu!stable beatmaps.
/// </summary> /// </summary>
internal class LegacyConverter internal class LegacyBeatmapConverter
{ {
private readonly FastRandom random; private readonly FastRandom random;
private ObjectList lastRow = new ObjectList(); private Patterns.Pattern lastPattern = new Patterns.Pattern();
private readonly int availableColumns; private readonly int availableColumns;
private readonly float localXDivisor; private readonly float localXDivisor;
private readonly Beatmap beatmap; private readonly Beatmap beatmap;
public LegacyConverter(Beatmap beatmap) public LegacyBeatmapConverter(Beatmap beatmap)
{ {
this.beatmap = beatmap; this.beatmap = beatmap;
@ -93,10 +94,10 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
var distanceData = original as IHasDistance; var distanceData = original as IHasDistance;
var positionData = original as IHasPosition; var positionData = original as IHasPosition;
ObjectConversion conversion = null; Patterns.PatternGenerator conversion = null;
if (distanceData != null) if (distanceData != null)
conversion = new DistanceObjectConversion(original, lastRow, random, beatmap); conversion = new DistanceObjectPatternGenerator(random, original, beatmap, lastPattern);
else if (endTimeData != null) else if (endTimeData != null)
{ {
// Spinner // Spinner
@ -109,12 +110,12 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
if (conversion == null) if (conversion == null)
yield break; yield break;
ObjectList newRow = conversion.Generate(); Patterns.Pattern newPattern = conversion.Generate();
foreach (ManiaHitObject obj in newRow.HitObjects) foreach (ManiaHitObject obj in newPattern.HitObjects)
yield return obj; yield return obj;
lastRow = newRow; lastPattern = newPattern;
} }
private int getColumn(float position) => MathHelper.Clamp((int)Math.Floor(position / localXDivisor), 0, availableColumns - 1); private int getColumn(float position) => MathHelper.Clamp((int)Math.Floor(position / localXDivisor), 0, availableColumns - 1);

View File

@ -19,7 +19,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
protected override Beatmap<ManiaHitObject> ConvertBeatmap(Beatmap original) protected override Beatmap<ManiaHitObject> ConvertBeatmap(Beatmap original)
{ {
// Todo: This should be cased when we get better conversion methods // Todo: This should be cased when we get better conversion methods
var converter = new LegacyConverter(original); var converter = new LegacyBeatmapConverter(original);
return new Beatmap<ManiaHitObject> return new Beatmap<ManiaHitObject>
{ {

View File

@ -1,50 +1,49 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using System; using System;
using osu.Game.Rulesets.Mania.MathUtils;
using System.Linq; using System.Linq;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Mania.MathUtils;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Rulesets.Mania.Beatmaps namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy
{ {
internal class DistanceObjectConversion : ObjectConversion /// <summary>
/// A pattern generator for IHasDistance hit objects.
/// </summary>
internal class DistanceObjectPatternGenerator : PatternGenerator
{ {
/// <summary> /// <summary>
/// Base osu! slider scoring distance. /// Base osu! slider scoring distance.
/// </summary> /// </summary>
private const float osu_base_scoring_distance = 100; private const float osu_base_scoring_distance = 100;
private readonly HitObject originalObject;
private readonly double endTime; private readonly double endTime;
private readonly int repeatCount; private readonly int repeatCount;
private LegacyConvertType convertType; private PatternType convertType;
public DistanceObjectConversion(HitObject originalObject, ObjectList previousObjects, FastRandom random, Beatmap beatmap) public DistanceObjectPatternGenerator(FastRandom random, HitObject hitObject, Beatmap beatmap, Pattern previousPattern)
: base(previousObjects, random, beatmap) : base(random, hitObject, beatmap, previousPattern)
{ {
this.originalObject = originalObject;
ControlPoint overridePoint; ControlPoint overridePoint;
ControlPoint controlPoint = Beatmap.TimingInfo.TimingPointAt(originalObject.StartTime, out overridePoint); ControlPoint controlPoint = Beatmap.TimingInfo.TimingPointAt(hitObject.StartTime, out overridePoint);
convertType = LegacyConvertType.None; convertType = PatternType.None;
if ((overridePoint ?? controlPoint)?.KiaiMode == false) if ((overridePoint ?? controlPoint)?.KiaiMode == false)
convertType = LegacyConvertType.LowProbability; convertType = PatternType.LowProbability;
var distanceData = originalObject as IHasDistance; var distanceData = hitObject as IHasDistance;
var repeatsData = originalObject as IHasRepeats; var repeatsData = hitObject as IHasRepeats;
repeatCount = repeatsData?.RepeatCount ?? 1; repeatCount = repeatsData?.RepeatCount ?? 1;
double speedAdjustment = beatmap.TimingInfo.SpeedMultiplierAt(originalObject.StartTime); double speedAdjustment = beatmap.TimingInfo.SpeedMultiplierAt(hitObject.StartTime);
double speedAdjustedBeatLength = beatmap.TimingInfo.BeatLengthAt(originalObject.StartTime) * speedAdjustment; double speedAdjustedBeatLength = beatmap.TimingInfo.BeatLengthAt(hitObject.StartTime) * speedAdjustment;
// The true distance, accounting for any repeats. This ends up being the drum roll distance later // The true distance, accounting for any repeats. This ends up being the drum roll distance later
double distance = distanceData.Distance * repeatCount; double distance = distanceData.Distance * repeatCount;
@ -54,73 +53,73 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
// The duration of the osu! hit object // The duration of the osu! hit object
double osuDuration = distance / osuVelocity; double osuDuration = distance / osuVelocity;
endTime = originalObject.StartTime + osuDuration; endTime = hitObject.StartTime + osuDuration;
} }
public override ObjectList Generate() public override Pattern Generate()
{ {
double segmentDuration = endTime / repeatCount; double segmentDuration = endTime / repeatCount;
if (repeatCount > 1) if (repeatCount > 1)
{ {
if (segmentDuration <= 90) if (segmentDuration <= 90)
return generateRandomHoldNotes(originalObject.StartTime, endTime, 1); return generateRandomHoldNotes(HitObject.StartTime, endTime, 1);
if (segmentDuration <= 120) if (segmentDuration <= 120)
{ {
convertType |= LegacyConvertType.ForceNotStack; convertType |= PatternType.ForceNotStack;
return generateRandomNotes(originalObject.StartTime, segmentDuration, repeatCount); return generateRandomNotes(HitObject.StartTime, segmentDuration, repeatCount);
} }
if (segmentDuration <= 160) if (segmentDuration <= 160)
return generateStair(originalObject.StartTime, segmentDuration, repeatCount); return generateStair(HitObject.StartTime, segmentDuration);
if (segmentDuration <= 200 && ConversionDifficulty > 3) if (segmentDuration <= 200 && ConversionDifficulty > 3)
return generateRandomMultipleNotes(originalObject.StartTime, segmentDuration, repeatCount); return generateRandomMultipleNotes(HitObject.StartTime, segmentDuration, repeatCount);
double duration = endTime - originalObject.StartTime; double duration = endTime - HitObject.StartTime;
if (duration >= 4000) if (duration >= 4000)
return generateNRandomNotes(originalObject.StartTime, endTime, 0.23, 0, 0); return generateNRandomNotes(HitObject.StartTime, endTime, 0.23, 0, 0);
if (segmentDuration > 400 && duration < 4000 && repeatCount < AvailableColumns - 1 - RandomStart) if (segmentDuration > 400 && duration < 4000 && repeatCount < AvailableColumns - 1 - RandomStart)
return generateTiledHoldNotes(originalObject.StartTime, segmentDuration, repeatCount); return generateTiledHoldNotes(HitObject.StartTime, segmentDuration, repeatCount);
return generateHoldAndNormalNotes(originalObject.StartTime, segmentDuration); return generateHoldAndNormalNotes(HitObject.StartTime, segmentDuration);
} }
if (segmentDuration <= 110) if (segmentDuration <= 110)
{ {
if (PreviousObjects.ColumnsFilled < AvailableColumns) if (PreviousPattern.ColumnsFilled < AvailableColumns)
convertType |= LegacyConvertType.ForceNotStack; convertType |= PatternType.ForceNotStack;
else else
convertType &= ~LegacyConvertType.ForceNotStack; convertType &= ~PatternType.ForceNotStack;
return generateRandomNotes(originalObject.StartTime, segmentDuration, segmentDuration < 80 ? 0 : 1); return generateRandomNotes(HitObject.StartTime, segmentDuration, segmentDuration < 80 ? 0 : 1);
} }
if (ConversionDifficulty > 6.5) if (ConversionDifficulty > 6.5)
{ {
if ((convertType & LegacyConvertType.LowProbability) > 0) if ((convertType & PatternType.LowProbability) > 0)
return generateNRandomNotes(originalObject.StartTime, endTime, 0.78, 0.3, 0); return generateNRandomNotes(HitObject.StartTime, endTime, 0.78, 0.3, 0);
return generateNRandomNotes(originalObject.StartTime, endTime, 0.85, 0.36, 0.03); return generateNRandomNotes(HitObject.StartTime, endTime, 0.85, 0.36, 0.03);
} }
if (ConversionDifficulty > 4) if (ConversionDifficulty > 4)
{ {
if ((convertType & LegacyConvertType.LowProbability) > 0) if ((convertType & PatternType.LowProbability) > 0)
return generateNRandomNotes(originalObject.StartTime, endTime, 0.43, 0.08, 0); return generateNRandomNotes(HitObject.StartTime, endTime, 0.43, 0.08, 0);
return generateNRandomNotes(originalObject.StartTime, endTime, 0.56, 0.18, 0); return generateNRandomNotes(HitObject.StartTime, endTime, 0.56, 0.18, 0);
} }
if (ConversionDifficulty > 2.5) if (ConversionDifficulty > 2.5)
{ {
if ((convertType & LegacyConvertType.LowProbability) > 0) if ((convertType & PatternType.LowProbability) > 0)
return generateNRandomNotes(originalObject.StartTime, endTime, 0.3, 0, 0); return generateNRandomNotes(HitObject.StartTime, endTime, 0.3, 0, 0);
return generateNRandomNotes(originalObject.StartTime, endTime, 0.37, 0.08, 0); return generateNRandomNotes(HitObject.StartTime, endTime, 0.37, 0.08, 0);
} }
if ((convertType & LegacyConvertType.LowProbability) > 0) if ((convertType & PatternType.LowProbability) > 0)
return generateNRandomNotes(originalObject.StartTime, endTime, 0.17, 0, 0); return generateNRandomNotes(HitObject.StartTime, endTime, 0.17, 0, 0);
return generateNRandomNotes(originalObject.StartTime, endTime, 0.27, 0, 0); return generateNRandomNotes(HitObject.StartTime, endTime, 0.27, 0, 0);
} }
/// <summary> /// <summary>
@ -129,34 +128,34 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
/// <param name="startTime">Start time of each hold note.</param> /// <param name="startTime">Start time of each hold note.</param>
/// <param name="endTime">End time of the hold notes.</param> /// <param name="endTime">End time of the hold notes.</param>
/// <param name="noteCount">Number of hold notes.</param> /// <param name="noteCount">Number of hold notes.</param>
/// <returns>The <see cref="ObjectList"/> containing the hit objects.</returns> /// <returns>The <see cref="Pattern"/> containing the hit objects.</returns>
private ObjectList generateRandomHoldNotes(double startTime, double endTime, int noteCount) private Pattern generateRandomHoldNotes(double startTime, double endTime, int noteCount)
{ {
// - - - - // - - - -
// ■ - ■ ■ // ■ - ■ ■
// □ - □ □ // □ - □ □
// ■ - ■ ■ // ■ - ■ ■
var newObjects = new ObjectList(); var pattern = new Pattern();
int usableColumns = AvailableColumns - RandomStart - PreviousObjects.ColumnsFilled; int usableColumns = AvailableColumns - RandomStart - PreviousPattern.ColumnsFilled;
int nextColumn = Random.Next(RandomStart, AvailableColumns); int nextColumn = Random.Next(RandomStart, AvailableColumns);
for (int i = 0; i < Math.Min(usableColumns, noteCount); i++) for (int i = 0; i < Math.Min(usableColumns, noteCount); i++)
{ {
while (newObjects.IsFilled(nextColumn) || PreviousObjects.IsFilled(nextColumn)) //find available column while (pattern.IsFilled(nextColumn) || PreviousPattern.IsFilled(nextColumn)) //find available column
nextColumn = Random.Next(RandomStart, AvailableColumns); nextColumn = Random.Next(RandomStart, AvailableColumns);
Add(newObjects, originalObject, nextColumn, startTime, endTime, noteCount); AddToPattern(pattern, HitObject, nextColumn, startTime, endTime, noteCount);
} }
// This is can't be combined with the above loop due to RNG // This is can't be combined with the above loop due to RNG
for (int i = 0; i < noteCount - usableColumns; i++) for (int i = 0; i < noteCount - usableColumns; i++)
{ {
while (newObjects.IsFilled(nextColumn)) while (pattern.IsFilled(nextColumn))
nextColumn = Random.Next(RandomStart, AvailableColumns); nextColumn = Random.Next(RandomStart, AvailableColumns);
Add(newObjects, originalObject, nextColumn, startTime, endTime, noteCount); AddToPattern(pattern, HitObject, nextColumn, startTime, endTime, noteCount);
} }
return newObjects; return pattern;
} }
/// <summary> /// <summary>
@ -165,8 +164,8 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
/// <param name="startTime">The start time.</param> /// <param name="startTime">The start time.</param>
/// <param name="separationTime">The separation of notes between rows.</param> /// <param name="separationTime">The separation of notes between rows.</param>
/// <param name="repeatCount">The number of rows.</param> /// <param name="repeatCount">The number of rows.</param>
/// <returns>The <see cref="ObjectList"/> containing the hit objects.</returns> /// <returns>The <see cref="Pattern"/> containing the hit objects.</returns>
private ObjectList generateRandomNotes(double startTime, double separationTime, int repeatCount) private Pattern generateRandomNotes(double startTime, double separationTime, int repeatCount)
{ {
// - - - - // - - - -
// x - - - // x - - -
@ -174,19 +173,19 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
// - - - x // - - - x
// x - - - // x - - -
var newObjects = new ObjectList(); var pattern = new Pattern();
int nextColumn = GetColumn((originalObject as IHasXPosition)?.X ?? 0, true); int nextColumn = GetColumn((HitObject as IHasXPosition)?.X ?? 0, true);
if ((convertType & LegacyConvertType.ForceNotStack) > 0 && PreviousObjects.ColumnsFilled < AvailableColumns) if ((convertType & PatternType.ForceNotStack) > 0 && PreviousPattern.ColumnsFilled < AvailableColumns)
{ {
while (PreviousObjects.IsFilled(nextColumn)) while (PreviousPattern.IsFilled(nextColumn))
nextColumn = Random.Next(RandomStart, AvailableColumns); nextColumn = Random.Next(RandomStart, AvailableColumns);
} }
int lastColumn = nextColumn; int lastColumn = nextColumn;
for (int i = 0; i <= repeatCount; i++) for (int i = 0; i <= repeatCount; i++)
{ {
Add(newObjects, originalObject, nextColumn, startTime, startTime); AddToPattern(pattern, HitObject, nextColumn, startTime, startTime);
while (nextColumn == lastColumn) while (nextColumn == lastColumn)
nextColumn = Random.Next(RandomStart, AvailableColumns); nextColumn = Random.Next(RandomStart, AvailableColumns);
@ -194,7 +193,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
startTime += separationTime; startTime += separationTime;
} }
return newObjects; return pattern;
} }
/// <summary> /// <summary>
@ -202,9 +201,8 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
/// </summary> /// </summary>
/// <param name="startTime">The start time.</param> /// <param name="startTime">The start time.</param>
/// <param name="separationTime">The separation of notes between rows.</param> /// <param name="separationTime">The separation of notes between rows.</param>
/// <param name="repeatCount">The number of rows/notes.</param> /// <returns>The <see cref="Pattern"/> containing the hit objects.</returns>
/// <returns>The <see cref="ObjectList"/> containing the hit objects.</returns> private Pattern generateStair(double startTime, double separationTime)
private ObjectList generateStair(double startTime, double separationTime, int repeatCount)
{ {
// - - - - // - - - -
// x - - - // x - - -
@ -215,14 +213,14 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
// - x - - // - x - -
// x - - - // x - - -
var newObjects = new ObjectList(); var pattern = new Pattern();
int column = GetColumn((originalObject as IHasXPosition)?.X ?? 0, true); int column = GetColumn((HitObject as IHasXPosition)?.X ?? 0, true);
bool increasing = Random.NextDouble() > 0.5; bool increasing = Random.NextDouble() > 0.5;
for (int i = 0; i <= repeatCount; i++) for (int i = 0; i <= repeatCount; i++)
{ {
Add(newObjects, originalObject, column, startTime, startTime); AddToPattern(pattern, HitObject, column, startTime, startTime);
startTime += separationTime; startTime += separationTime;
// Check if we're at the borders of the stage, and invert the pattern if so // Check if we're at the borders of the stage, and invert the pattern if so
@ -248,7 +246,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
} }
} }
return newObjects; return pattern;
} }
/// <summary> /// <summary>
@ -257,8 +255,8 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
/// <param name="startTime">The start time.</param> /// <param name="startTime">The start time.</param>
/// <param name="separationTime">The separation of notes between rows.</param> /// <param name="separationTime">The separation of notes between rows.</param>
/// <param name="repeatCount">The number of rows.</param> /// <param name="repeatCount">The number of rows.</param>
/// <returns>The <see cref="ObjectList"/> containing the hit objects.</returns> /// <returns>The <see cref="Pattern"/> containing the hit objects.</returns>
private ObjectList generateRandomMultipleNotes(double startTime, double separationTime, int repeatCount) private Pattern generateRandomMultipleNotes(double startTime, double separationTime, int repeatCount)
{ {
// - - - - // - - - -
// x - - // x - -
@ -266,15 +264,15 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
// - - - x // - - - x
// x - x - // x - x -
var newObjects = new ObjectList(); var pattern = new Pattern();
bool legacy = AvailableColumns >= 4 && AvailableColumns <= 8; bool legacy = AvailableColumns >= 4 && AvailableColumns <= 8;
int interval = Random.Next(1, AvailableColumns - (legacy ? 1 : 0)); int interval = Random.Next(1, AvailableColumns - (legacy ? 1 : 0));
int nextColumn = GetColumn((originalObject as IHasXPosition)?.X ?? 0, true); int nextColumn = GetColumn((HitObject as IHasXPosition)?.X ?? 0, true);
for (int i = 0; i <= repeatCount; i++) for (int i = 0; i <= repeatCount; i++)
{ {
Add(newObjects, originalObject, nextColumn, startTime, startTime, 2); AddToPattern(pattern, HitObject, nextColumn, startTime, startTime, 2);
nextColumn += interval; nextColumn += interval;
if (nextColumn >= AvailableColumns - RandomStart) if (nextColumn >= AvailableColumns - RandomStart)
@ -283,13 +281,13 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
// If we're in 2K, let's not add many consecutive doubles // If we're in 2K, let's not add many consecutive doubles
if (AvailableColumns > 2) if (AvailableColumns > 2)
Add(newObjects, originalObject, nextColumn, startTime, startTime, 2); AddToPattern(pattern, HitObject, nextColumn, startTime, startTime, 2);
nextColumn = Random.Next(RandomStart, AvailableColumns); nextColumn = Random.Next(RandomStart, AvailableColumns);
startTime += separationTime; startTime += separationTime;
} }
return newObjects; return pattern;
} }
/// <summary> /// <summary>
@ -300,8 +298,8 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
/// <param name="p2">The probability required for 2 hold notes to be generated.</param> /// <param name="p2">The probability required for 2 hold notes to be generated.</param>
/// <param name="p3">The probability required for 3 hold notes to be generated.</param> /// <param name="p3">The probability required for 3 hold notes to be generated.</param>
/// <param name="p4">The probability required for 4 hold notes to be generated.</param> /// <param name="p4">The probability required for 4 hold notes to be generated.</param>
/// <returns>The <see cref="ObjectList"/> containing the hit objects.</returns> /// <returns>The <see cref="Pattern"/> containing the hit objects.</returns>
private ObjectList generateNRandomNotes(double startTime, double endTime, double p2, double p3, double p4) private Pattern generateNRandomNotes(double startTime, double endTime, double p2, double p3, double p4)
{ {
// - - - - // - - - -
// ■ - ■ ■ // ■ - ■ ■
@ -334,8 +332,8 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
Func<SampleInfo, bool> isDoubleSample = sample => sample.Name == SampleInfo.HIT_CLAP && sample.Name == SampleInfo.HIT_FINISH; Func<SampleInfo, bool> isDoubleSample = sample => sample.Name == SampleInfo.HIT_CLAP && sample.Name == SampleInfo.HIT_FINISH;
bool canGenerateTwoNotes = (convertType & LegacyConvertType.LowProbability) == 0; bool canGenerateTwoNotes = (convertType & PatternType.LowProbability) == 0;
canGenerateTwoNotes &= originalObject.Samples.Any(isDoubleSample) || sampleInfoListAt(originalObject.StartTime).Any(isDoubleSample); canGenerateTwoNotes &= HitObject.Samples.Any(isDoubleSample) || sampleInfoListAt(HitObject.StartTime).Any(isDoubleSample);
if (canGenerateTwoNotes) if (canGenerateTwoNotes)
p2 = 1; p2 = 1;
@ -349,8 +347,8 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
/// <param name="startTime">The first hold note start time.</param> /// <param name="startTime">The first hold note start time.</param>
/// <param name="separationTime">The separation time between hold notes.</param> /// <param name="separationTime">The separation time between hold notes.</param>
/// <param name="noteCount">The amount of hold notes.</param> /// <param name="noteCount">The amount of hold notes.</param>
/// <returns>The <see cref="ObjectList"/> containing the hit objects.</returns> /// <returns>The <see cref="Pattern"/> containing the hit objects.</returns>
private ObjectList generateTiledHoldNotes(double startTime, double separationTime, int noteCount) private Pattern generateTiledHoldNotes(double startTime, double separationTime, int noteCount)
{ {
// - - - - // - - - -
// ■ ■ ■ ■ // ■ ■ ■ ■
@ -361,27 +359,27 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
// □ ■ - - // □ ■ - -
// ■ - - - // ■ - - -
var newObjects = new ObjectList(); var pattern = new Pattern();
int columnRepeat = Math.Min(noteCount, AvailableColumns); int columnRepeat = Math.Min(noteCount, AvailableColumns);
int nextColumn = GetColumn((originalObject as IHasXPosition)?.X ?? 0, true); int nextColumn = GetColumn((HitObject as IHasXPosition)?.X ?? 0, true);
if ((convertType & LegacyConvertType.ForceNotStack) > 0 && PreviousObjects.ColumnsFilled < AvailableColumns) if ((convertType & PatternType.ForceNotStack) > 0 && PreviousPattern.ColumnsFilled < AvailableColumns)
{ {
while (PreviousObjects.IsFilled(nextColumn)) while (PreviousPattern.IsFilled(nextColumn))
nextColumn = Random.Next(RandomStart, AvailableColumns); nextColumn = Random.Next(RandomStart, AvailableColumns);
} }
for (int i = 0; i < columnRepeat; i++) for (int i = 0; i < columnRepeat; i++)
{ {
while (newObjects.IsFilled(nextColumn)) while (pattern.IsFilled(nextColumn))
nextColumn = Random.Next(RandomStart, AvailableColumns); nextColumn = Random.Next(RandomStart, AvailableColumns);
Add(newObjects, originalObject, nextColumn, startTime, endTime, noteCount); AddToPattern(pattern, HitObject, nextColumn, startTime, endTime, noteCount);
startTime += separationTime; startTime += separationTime;
} }
return newObjects; return pattern;
} }
/// <summary> /// <summary>
@ -389,8 +387,8 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
/// </summary> /// </summary>
/// <param name="startTime">The start time of notes.</param> /// <param name="startTime">The start time of notes.</param>
/// <param name="separationTime">The separation time between notes.</param> /// <param name="separationTime">The separation time between notes.</param>
/// <returns>The <see cref="ObjectList"/> containing the hit objects.</returns> /// <returns>The <see cref="Pattern"/> containing the hit objects.</returns>
private ObjectList generateHoldAndNormalNotes(double startTime, double separationTime) private Pattern generateHoldAndNormalNotes(double startTime, double separationTime)
{ {
// - - - - // - - - -
// ■ x x - // ■ x x -
@ -398,17 +396,17 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
// ■ x - x // ■ x - x
// ■ - x x // ■ - x x
var newObjects = new ObjectList(); var pattern = new Pattern();
int holdColumn = GetColumn((originalObject as IHasXPosition)?.X ?? 0, true); int holdColumn = GetColumn((HitObject as IHasXPosition)?.X ?? 0, true);
if ((convertType & LegacyConvertType.ForceNotStack) > 0 && PreviousObjects.ColumnsFilled < AvailableColumns) if ((convertType & PatternType.ForceNotStack) > 0 && PreviousPattern.ColumnsFilled < AvailableColumns)
{ {
while (PreviousObjects.IsFilled(holdColumn)) while (PreviousPattern.IsFilled(holdColumn))
holdColumn = Random.Next(RandomStart, AvailableColumns); holdColumn = Random.Next(RandomStart, AvailableColumns);
} }
// Create the hold note // Create the hold note
Add(newObjects, originalObject, holdColumn, startTime, separationTime * repeatCount); AddToPattern(pattern, HitObject, holdColumn, startTime, separationTime * repeatCount);
int noteCount = 1; int noteCount = 1;
if (ConversionDifficulty > 6.5) if (ConversionDifficulty > 6.5)
@ -422,26 +420,26 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
bool ignoreHead = !sampleInfoListAt(startTime).Any(s => s.Name == SampleInfo.HIT_WHISTLE || s.Name == SampleInfo.HIT_FINISH || s.Name == SampleInfo.HIT_CLAP); bool ignoreHead = !sampleInfoListAt(startTime).Any(s => s.Name == SampleInfo.HIT_WHISTLE || s.Name == SampleInfo.HIT_FINISH || s.Name == SampleInfo.HIT_CLAP);
int nextColumn = Random.Next(RandomStart, AvailableColumns); int nextColumn = Random.Next(RandomStart, AvailableColumns);
var tempObjects = new ObjectList(); var rowPattern = new Pattern();
for (int i = 0; i <= repeatCount; i++) for (int i = 0; i <= repeatCount; i++)
{ {
if (!(ignoreHead && startTime == originalObject.StartTime)) if (!(ignoreHead && startTime == HitObject.StartTime))
{ {
for (int j = 0; j < noteCount; j++) for (int j = 0; j < noteCount; j++)
{ {
while (tempObjects.IsFilled(nextColumn) || nextColumn == holdColumn) while (rowPattern.IsFilled(nextColumn) || nextColumn == holdColumn)
nextColumn = Random.Next(RandomStart, AvailableColumns); nextColumn = Random.Next(RandomStart, AvailableColumns);
Add(tempObjects, originalObject, nextColumn, startTime, startTime, noteCount + 1); AddToPattern(rowPattern, HitObject, nextColumn, startTime, startTime, noteCount + 1);
} }
} }
newObjects.Add(tempObjects); pattern.Add(rowPattern);
tempObjects.Clear(); rowPattern.Clear();
startTime += separationTime; startTime += separationTime;
} }
return newObjects; return pattern;
} }
/// <summary> /// <summary>
@ -451,14 +449,14 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
/// <returns></returns> /// <returns></returns>
private SampleInfoList sampleInfoListAt(double time) private SampleInfoList sampleInfoListAt(double time)
{ {
var curveData = originalObject as IHasCurve; var curveData = HitObject as IHasCurve;
if (curveData == null) if (curveData == null)
return originalObject.Samples; return HitObject.Samples;
double segmentTime = (curveData.EndTime - originalObject.StartTime) / repeatCount; double segmentTime = (curveData.EndTime - HitObject.StartTime) / repeatCount;
int index = (int)(segmentTime == 0 ? 0 : (time - originalObject.StartTime) / segmentTime); int index = (int)(segmentTime == 0 ? 0 : (time - HitObject.StartTime) / segmentTime);
return curveData.RepeatSamples[index]; return curveData.RepeatSamples[index];
} }
} }

View File

@ -1,42 +1,39 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mania.MathUtils;
using System; using System;
using System.Linq; using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.MathUtils;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using OpenTK;
namespace osu.Game.Rulesets.Mania.Beatmaps namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy
{ {
internal abstract class ObjectConversion /// <summary>
/// A pattern generator for legacy hit objects.
/// </summary>
internal abstract class PatternGenerator : Patterns.PatternGenerator
{ {
protected readonly int AvailableColumns; /// <summary>
/// The column index at which to start generating random notes.
/// </summary>
protected readonly int RandomStart; protected readonly int RandomStart;
protected ObjectList PreviousObjects; /// <summary>
/// The random number generator to use.
/// </summary>
protected readonly FastRandom Random; protected readonly FastRandom Random;
protected readonly Beatmap Beatmap;
protected ObjectConversion(ObjectList previousObjects, FastRandom random, Beatmap beatmap) protected PatternGenerator(FastRandom random, HitObject hitObject, Beatmap beatmap, Pattern previousPattern)
: base(hitObject, beatmap, previousPattern)
{ {
PreviousObjects = previousObjects;
Random = random; Random = random;
Beatmap = beatmap;
AvailableColumns = (int)Math.Round(beatmap.BeatmapInfo.Difficulty.CircleSize);
RandomStart = AvailableColumns == 8 ? 1 : 0; RandomStart = AvailableColumns == 8 ? 1 : 0;
} }
/// <summary>
/// Generates a new object list filled with converted hit objects.
/// </summary>
/// <returns>The <see cref="ObjectList"/> containing the hit objects.</returns>
public abstract ObjectList Generate();
/// <summary> /// <summary>
/// Converts an x-position into a column. /// Converts an x-position into a column.
/// </summary> /// </summary>
@ -78,44 +75,6 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
return val >= 1 - p2 ? 2 : 1; return val >= 1 - p2 ? 2 : 1;
} }
/// <summary>
/// Constructs and adds a note to an object list.
/// </summary>
/// <param name="objectList">The list to add to.</param>
/// <param name="originalObject">The original hit object (used for samples).</param>
/// <param name="column">The column to add the note to.</param>
/// <param name="startTime">The start time of the note.</param>
/// <param name="endTime">The end time of the note (set to <paramref name="startTime"/> for a non-hold note).</param>
/// <param name="siblings">The number of children alongside this note (these will not be generated, but are used for volume calculations).</param>
protected void Add(ObjectList objectList, HitObject originalObject, int column, double startTime, double endTime, int siblings = 1)
{
ManiaHitObject newObject;
if (startTime == endTime)
{
newObject = new Note
{
StartTime = startTime,
Samples = originalObject.Samples,
Column = column
};
}
else
{
newObject = new HoldNote
{
StartTime = startTime,
Samples = originalObject.Samples,
Column = column,
Duration = endTime - startTime
};
}
// Todo: Consider siblings and write sample volumes (probably at ManiaHitObject level)
objectList.Add(newObject);
}
private double? conversionDifficulty; private double? conversionDifficulty;
/// <summary> /// <summary>
/// A difficulty factor used for various conversion methods from osu!stable. /// A difficulty factor used for various conversion methods from osu!stable.

View File

@ -3,10 +3,13 @@
using System; using System;
namespace osu.Game.Rulesets.Mania.Beatmaps namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy
{ {
/// <summary>
/// The type of pattern to generate. Used for legacy patterns.
/// </summary>
[Flags] [Flags]
internal enum LegacyConvertType internal enum PatternType
{ {
None = 0, None = 0,
/// <summary> /// <summary>

View File

@ -1,56 +1,59 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Rulesets.Mania.Objects;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Rulesets.Mania.Objects;
namespace osu.Game.Rulesets.Mania.Beatmaps namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns
{ {
internal class ObjectList /// <summary>
/// Creates a pattern containing hit objects.
/// </summary>
internal class Pattern
{ {
private readonly List<ManiaHitObject> hitObjects = new List<ManiaHitObject>(); private readonly List<ManiaHitObject> hitObjects = new List<ManiaHitObject>();
/// <summary> /// <summary>
/// All the hit objects contained in this list. /// All the hit objects contained in this pattern.
/// </summary> /// </summary>
public IEnumerable<ManiaHitObject> HitObjects => hitObjects; public IEnumerable<ManiaHitObject> HitObjects => hitObjects;
/// <summary> /// <summary>
/// Whether a column of this list has been taken. /// Whether this pattern already contains a hit object in a code.
/// </summary> /// </summary>
/// <param name="column">The column index.</param> /// <param name="column">The column index.</param>
/// <returns>Whether the column already contains a hit object.</returns> /// <returns>Whether this pattern already contains a hit object in <paramref name="column"/></returns>
public bool IsFilled(int column) => hitObjects.Exists(h => h.Column == column); public bool IsFilled(int column) => hitObjects.Exists(h => h.Column == column);
/// <summary> /// <summary>
/// Amount of columns taken up by hit objects in this list. /// Amount of columns taken up by hit objects in this pattern.
/// </summary> /// </summary>
public int ColumnsFilled => HitObjects.GroupBy(h => h.Column).Count(); public int ColumnsFilled => HitObjects.GroupBy(h => h.Column).Count();
/// <summary> /// <summary>
/// Adds a hit object to this list. /// Adds a hit object to this pattern.
/// </summary> /// </summary>
/// <param name="hitObject">The hit object to add.</param> /// <param name="hitObject">The hit object to add.</param>
public void Add(ManiaHitObject hitObject) => hitObjects.Add(hitObject); public void Add(ManiaHitObject hitObject) => hitObjects.Add(hitObject);
/// <summary> /// <summary>
/// Copies hit object from another list to this one. /// Copies hit object from another pattern to this one.
/// </summary> /// </summary>
/// <param name="other">The other list.</param> /// <param name="other">The other pattern.</param>
public void Add(ObjectList other) public void Add(Pattern other)
{ {
other.HitObjects.ForEach(Add); other.HitObjects.ForEach(Add);
} }
/// <summary> /// <summary>
/// Clears this list. /// Clears this pattern, removing all hit objects.
/// </summary> /// </summary>
public void Clear() => hitObjects.Clear(); public void Clear() => hitObjects.Clear();
/// <summary> /// <summary>
/// Removes a hit object from this list. /// Removes a hit object from this pattern.
/// </summary> /// </summary>
/// <param name="hitObject">The hit object to remove.</param> /// <param name="hitObject">The hit object to remove.</param>
public bool Remove(ManiaHitObject hitObject) => hitObjects.Remove(hitObject); public bool Remove(ManiaHitObject hitObject) => hitObjects.Remove(hitObject);

View File

@ -0,0 +1,89 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Objects;
namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns
{
/// <summary>
/// Generator to create a pattern <see cref="Pattern"/> from a hit object.
/// </summary>
internal abstract class PatternGenerator
{
/// <summary>
/// The number of columns available to create the pattern.
/// </summary>
protected readonly int AvailableColumns;
/// <summary>
/// The last pattern.
/// </summary>
protected readonly Pattern PreviousPattern;
/// <summary>
/// The hit object to create the pattern for.
/// </summary>
protected readonly HitObject HitObject;
/// <summary>
/// The beatmap which <see cref="HitObject"/> is a part of.
/// </summary>
protected readonly Beatmap Beatmap;
protected PatternGenerator(HitObject hitObject, Beatmap beatmap, Pattern previousPattern)
{
PreviousPattern = previousPattern;
HitObject = hitObject;
Beatmap = beatmap;
AvailableColumns = (int)Math.Round(beatmap.BeatmapInfo.Difficulty.CircleSize);
}
/// <summary>
/// Generates the pattern for <see cref="HitObject"/>, filled with hit objects.
/// </summary>
/// <returns>The <see cref="Pattern"/> containing the hit objects.</returns>
public abstract Pattern Generate();
/// <summary>
/// Constructs and adds a note to a pattern.
/// </summary>
/// <param name="pattern">The pattern to add to.</param>
/// <param name="originalObject">The original hit object (used for samples).</param>
/// <param name="column">The column to add the note to.</param>
/// <param name="startTime">The start time of the note.</param>
/// <param name="endTime">The end time of the note (set to <paramref name="startTime"/> for a non-hold note).</param>
/// <param name="siblings">The number of children alongside this note (these will not be generated, but are used for volume calculations).</param>
protected void AddToPattern(Pattern pattern, HitObject originalObject, int column, double startTime, double endTime, int siblings = 1)
{
ManiaHitObject newObject;
if (startTime == endTime)
{
newObject = new Note
{
StartTime = startTime,
Samples = originalObject.Samples,
Column = column
};
}
else
{
newObject = new HoldNote
{
StartTime = startTime,
Samples = originalObject.Samples,
Column = column,
Duration = endTime - startTime
};
}
// Todo: Consider siblings and write sample volumes (probably at ManiaHitObject level)
pattern.Add(newObject);
}
}
}

View File

@ -47,12 +47,13 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Beatmaps\DistanceObjectConversion.cs" /> <Compile Include="Beatmaps\Patterns\Legacy\DistanceObjectPatternGenerator.cs" />
<Compile Include="Beatmaps\ObjectConversion.cs" /> <Compile Include="Beatmaps\Patterns\Legacy\PatternGenerator.cs" />
<Compile Include="Beatmaps\LegacyConverter.cs" /> <Compile Include="Beatmaps\Patterns\PatternGenerator.cs" />
<Compile Include="Beatmaps\LegacyConvertType.cs" /> <Compile Include="Beatmaps\LegacyBeatmapConverter.cs" />
<Compile Include="Beatmaps\Patterns\Legacy\PatternType.cs" />
<Compile Include="Beatmaps\ManiaBeatmapConverter.cs" /> <Compile Include="Beatmaps\ManiaBeatmapConverter.cs" />
<Compile Include="Beatmaps\ObjectList.cs" /> <Compile Include="Beatmaps\Patterns\Pattern.cs" />
<Compile Include="MathUtils\FastRandom.cs" /> <Compile Include="MathUtils\FastRandom.cs" />
<Compile Include="Judgements\HitWindows.cs" /> <Compile Include="Judgements\HitWindows.cs" />
<Compile Include="Judgements\ManiaJudgement.cs" /> <Compile Include="Judgements\ManiaJudgement.cs" />