1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 12:42:54 +08:00

General refactoring

This commit is contained in:
Dan Balasescu 2022-08-15 21:26:54 +09:00
parent d686e841c5
commit 502e31dd37
6 changed files with 57 additions and 79 deletions

View File

@ -15,7 +15,6 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data
{ {
/// <summary> /// <summary>
/// List of <see cref="DifficultyHitObject"/>s that are encoded within this <see cref="MonoEncoding"/>. /// List of <see cref="DifficultyHitObject"/>s that are encoded within this <see cref="MonoEncoding"/>.
/// This is not declared as <see cref="TaikoDifficultyHitObject"/> to avoid circular dependencies.
/// </summary> /// </summary>
public List<TaikoDifficultyHitObject> EncodedData { get; private set; } = new List<TaikoDifficultyHitObject>(); public List<TaikoDifficultyHitObject> EncodedData { get; private set; } = new List<TaikoDifficultyHitObject>();

View File

@ -9,8 +9,7 @@ using osu.Game.Rulesets.Taiko.Objects;
namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
{ {
/// <summary> /// <summary>
/// Utility class to perform various encodings. This is separated out from the encoding classes to prevent circular /// Utility class to perform various encodings.
/// dependencies.
/// </summary> /// </summary>
public class TaikoColourDifficultyPreprocessor public class TaikoColourDifficultyPreprocessor
{ {
@ -26,7 +25,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
// Assign indexing and encoding data to all relevant objects. Only the first note of each encoding type is // Assign indexing and encoding data to all relevant objects. Only the first note of each encoding type is
// assigned with the relevant encodings. // assigned with the relevant encodings.
encodings.ForEach(coupledEncoding => foreach (var coupledEncoding in encodings)
{ {
coupledEncoding.Payload[0].Payload[0].EncodedData[0].Colour.CoupledColourEncoding = coupledEncoding; coupledEncoding.Payload[0].Payload[0].EncodedData[0].Colour.CoupledColourEncoding = coupledEncoding;
@ -48,7 +47,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
monoEncoding.EncodedData[0].Colour.MonoEncoding = monoEncoding; monoEncoding.EncodedData[0].Colour.MonoEncoding = monoEncoding;
} }
} }
}); }
return colours; return colours;
} }
@ -58,35 +57,29 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
/// </summary> /// </summary>
public static List<MonoEncoding> EncodeMono(List<DifficultyHitObject> data) public static List<MonoEncoding> EncodeMono(List<DifficultyHitObject> data)
{ {
List<MonoEncoding> encoded = new List<MonoEncoding>(); List<MonoEncoding> encodings = new List<MonoEncoding>();
MonoEncoding? currentEncoding = null;
MonoEncoding? lastEncoded = null;
for (int i = 0; i < data.Count; i++) for (int i = 0; i < data.Count; i++)
{ {
TaikoDifficultyHitObject taikoObject = (TaikoDifficultyHitObject)data[i]; TaikoDifficultyHitObject taikoObject = (TaikoDifficultyHitObject)data[i];
// This ignores all non-note objects, which may or may not be the desired behaviour // This ignores all non-note objects, which may or may not be the desired behaviour
TaikoDifficultyHitObject? previousObject = taikoObject.PreviousNote(0); TaikoDifficultyHitObject? previousObject = taikoObject.PreviousNote(0);
// If the colour changed or if this is the first object in the run, create a new mono encoding // If this is the first object in the list or the colour changed, create a new mono encoding
if if (currentEncoding == null || (taikoObject.BaseObject as Hit)?.Type != (previousObject?.BaseObject as Hit)?.Type)
(
previousObject == null || // First object in the list
(taikoObject.BaseObject as Hit)?.Type != (previousObject.BaseObject as Hit)?.Type
)
{ {
lastEncoded = new MonoEncoding(); currentEncoding = new MonoEncoding();
lastEncoded.EncodedData.Add(taikoObject); encodings.Add(currentEncoding);
encoded.Add(lastEncoded);
continue; continue;
} }
// If we're here, we're in the same encoding as the previous object, thus lastEncoded is not null.
// Add the current object to the encoded payload. // Add the current object to the encoded payload.
lastEncoded!.EncodedData.Add(taikoObject); currentEncoding.EncodedData.Add(taikoObject);
} }
return encoded; return encodings;
} }
/// <summary> /// <summary>
@ -94,27 +87,24 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
/// </summary> /// </summary>
public static List<ColourEncoding> EncodeColour(List<MonoEncoding> data) public static List<ColourEncoding> EncodeColour(List<MonoEncoding> data)
{ {
List<ColourEncoding> encoded = new List<ColourEncoding>(); List<ColourEncoding> encodings = new List<ColourEncoding>();
ColourEncoding? lastEncoded = null; ColourEncoding? currentEncoding = null;
for (int i = 0; i < data.Count; i++) for (int i = 0; i < data.Count; i++)
{ {
// Starts a new ColourEncoding if the previous MonoEncoding has a different mono length, or if this is // Start a new ColourEncoding if the previous MonoEncoding has a different mono length, or if this is the first MonoEncoding in the list.
// the first MonoEncoding in the list. if (currentEncoding == null || data[i].RunLength != data[i - 1].RunLength)
if (lastEncoded == null || data[i].RunLength != data[i - 1].RunLength)
{ {
lastEncoded = new ColourEncoding(); currentEncoding = new ColourEncoding();
lastEncoded.Payload.Add(data[i]); encodings.Add(currentEncoding);
encoded.Add(lastEncoded);
continue; continue;
} }
// If we're here, we're in the same encoding as the previous object. Add the current MonoEncoding to the // Add the current MonoEncoding to the encoded payload.
// encoded payload. currentEncoding.Payload.Add(data[i]);
lastEncoded.Payload.Add(data[i]);
} }
return encoded; return encodings;
} }
/// <summary> /// <summary>
@ -122,16 +112,15 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
/// </summary> /// </summary>
public static List<CoupledColourEncoding> EncodeCoupledColour(List<ColourEncoding> data) public static List<CoupledColourEncoding> EncodeCoupledColour(List<ColourEncoding> data)
{ {
List<CoupledColourEncoding> encoded = new List<CoupledColourEncoding>(); List<CoupledColourEncoding> encodings = new List<CoupledColourEncoding>();
CoupledColourEncoding? lastEncoded = null; CoupledColourEncoding? currentEncoding = null;
for (int i = 0; i < data.Count; i++) for (int i = 0; i < data.Count; i++)
{ {
// Starts a new CoupledColourEncoding. ColourEncodings that should be grouped together will be handled // Start a new CoupledColourEncoding. ColourEncodings that should be grouped together will be handled later within this loop.
// later within this loop. currentEncoding = new CoupledColourEncoding
lastEncoded = new CoupledColourEncoding
{ {
Previous = lastEncoded Previous = currentEncoding
}; };
// Determine if future ColourEncodings should be grouped. // Determine if future ColourEncodings should be grouped.
@ -140,7 +129,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
if (!isCoupled) if (!isCoupled)
{ {
// If not, add the current ColourEncoding to the encoded payload and continue. // If not, add the current ColourEncoding to the encoded payload and continue.
lastEncoded.Payload.Add(data[i]); currentEncoding.Payload.Add(data[i]);
} }
else else
{ {
@ -148,27 +137,27 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
// subsequent ColourEncodings should be grouped by increasing i and doing the appropriate isCoupled check. // subsequent ColourEncodings should be grouped by increasing i and doing the appropriate isCoupled check.
while (isCoupled) while (isCoupled)
{ {
lastEncoded.Payload.Add(data[i]); currentEncoding.Payload.Add(data[i]);
i++; i++;
isCoupled = i < data.Count - 2 && data[i].IsRepetitionOf(data[i + 2]); isCoupled = i < data.Count - 2 && data[i].IsRepetitionOf(data[i + 2]);
} }
// Skip over viewed data and add the rest to the payload // Skip over viewed data and add the rest to the payload
lastEncoded.Payload.Add(data[i]); currentEncoding.Payload.Add(data[i]);
lastEncoded.Payload.Add(data[i + 1]); currentEncoding.Payload.Add(data[i + 1]);
i++; i++;
} }
encoded.Add(lastEncoded); encodings.Add(currentEncoding);
} }
// Final pass to find repetition intervals // Final pass to find repetition intervals
for (int i = 0; i < encoded.Count; i++) for (int i = 0; i < encodings.Count; i++)
{ {
encoded[i].FindRepetitionInterval(); encodings[i].FindRepetitionInterval();
} }
return encoded; return encodings;
} }
/// <summary> /// <summary>

View File

@ -11,20 +11,17 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
public class TaikoDifficultyHitObjectColour public class TaikoDifficultyHitObjectColour
{ {
/// <summary> /// <summary>
/// <see cref="MonoEncoding"/> encoding that encodes this note, only present if this is the first note within a /// The <see cref="MonoEncoding"/> that encodes this note, only present if this is the first note within a <see cref="MonoEncoding"/>
/// <see cref="MonoEncoding"/>
/// </summary> /// </summary>
public MonoEncoding? MonoEncoding; public MonoEncoding? MonoEncoding;
/// <summary> /// <summary>
/// <see cref="ColourEncoding"/> encoding that encodes this note, only present if this is the first note within /// The <see cref="ColourEncoding"/> that encodes this note, only present if this is the first note within a <see cref="ColourEncoding"/>
/// a <see cref="ColourEncoding"/>
/// </summary> /// </summary>
public ColourEncoding? ColourEncoding; public ColourEncoding? ColourEncoding;
/// <summary> /// <summary>
/// <see cref="CoupledColourEncoding"/> encoding that encodes this note, only present if this is the first note /// The <see cref="CoupledColourEncoding"/> that encodes this note, only present if this is the first note within a <see cref="CoupledColourEncoding"/>
/// within a <see cref="CoupledColourEncoding"/>
/// </summary> /// </summary>
public CoupledColourEncoding? CoupledColourEncoding; public CoupledColourEncoding? CoupledColourEncoding;
} }

View File

@ -45,9 +45,8 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing
/// <summary> /// <summary>
/// Colour data for this hit object. This is used by colour evaluator to calculate colour difficulty, but can be used /// Colour data for this hit object. This is used by colour evaluator to calculate colour difficulty, but can be used
/// by other skills in the future. /// by other skills in the future.
/// This need to be writeable by TaikoDifficultyHitObjectColour so that it can assign potentially reused instances
/// </summary> /// </summary>
public TaikoDifficultyHitObjectColour Colour; public readonly TaikoDifficultyHitObjectColour Colour;
/// <summary> /// <summary>
/// Creates a new difficulty hit object. /// Creates a new difficulty hit object.
@ -59,7 +58,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing
/// <param name="objects">The list of all <see cref="DifficultyHitObject"/>s in the current beatmap.</param> /// <param name="objects">The list of all <see cref="DifficultyHitObject"/>s in the current beatmap.</param>
/// <param name="centreHitObjects">The list of centre (don) <see cref="DifficultyHitObject"/>s in the current beatmap.</param> /// <param name="centreHitObjects">The list of centre (don) <see cref="DifficultyHitObject"/>s in the current beatmap.</param>
/// <param name="rimHitObjects">The list of rim (kat) <see cref="DifficultyHitObject"/>s in the current beatmap.</param> /// <param name="rimHitObjects">The list of rim (kat) <see cref="DifficultyHitObject"/>s in the current beatmap.</param>
/// <param name="noteObjects">The list of <see cref="DifficultyHitObject"/>s that is a hit (i.e. not a slider or spinner) in the current beatmap.</param> /// <param name="noteObjects">The list of <see cref="DifficultyHitObject"/>s that is a hit (i.e. not a drumroll or swell) in the current beatmap.</param>
/// <param name="index">The position of this <see cref="DifficultyHitObject"/> in the <paramref name="objects"/> list.</param> /// <param name="index">The position of this <see cref="DifficultyHitObject"/> in the <paramref name="objects"/> list.</param>
public TaikoDifficultyHitObject(HitObject hitObject, HitObject lastObject, HitObject lastLastObject, double clockRate, public TaikoDifficultyHitObject(HitObject hitObject, HitObject lastObject, HitObject lastLastObject, double clockRate,
List<DifficultyHitObject> objects, List<DifficultyHitObject> objects,
@ -68,33 +67,31 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing
List<TaikoDifficultyHitObject> noteObjects, int index) List<TaikoDifficultyHitObject> noteObjects, int index)
: base(hitObject, lastObject, clockRate, objects, index) : base(hitObject, lastObject, clockRate, objects, index)
{ {
// Create the Colour object, its properties should be filled in by TaikoDifficultyPreprocessor
Colour = new TaikoDifficultyHitObjectColour();
var currentHit = hitObject as Hit;
noteDifficultyHitObjects = noteObjects; noteDifficultyHitObjects = noteObjects;
// Create the Colour object, its properties should be filled in by TaikoDifficultyPreprocessor
Colour = new TaikoDifficultyHitObjectColour();
Rhythm = getClosestRhythm(lastObject, lastLastObject, clockRate); Rhythm = getClosestRhythm(lastObject, lastLastObject, clockRate);
HitType? hitType = currentHit?.Type;
if (hitType == HitType.Centre) switch ((hitObject as Hit)?.Type)
{ {
case HitType.Centre:
MonoIndex = centreHitObjects.Count; MonoIndex = centreHitObjects.Count;
centreHitObjects.Add(this); centreHitObjects.Add(this);
monoDifficultyHitObjects = centreHitObjects; monoDifficultyHitObjects = centreHitObjects;
} break;
else if (hitType == HitType.Rim)
{ case HitType.Rim:
MonoIndex = rimHitObjects.Count; MonoIndex = rimHitObjects.Count;
rimHitObjects.Add(this); rimHitObjects.Add(this);
monoDifficultyHitObjects = rimHitObjects; monoDifficultyHitObjects = rimHitObjects;
} break;
// Need to be done after HitType is set.
if (hitType == null) return;
default:
NoteIndex = noteObjects.Count; NoteIndex = noteObjects.Count;
noteObjects.Add(this); noteObjects.Add(this);
break;
}
} }
/// <summary> /// <summary>

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using osu.Game.Rulesets.Difficulty.Preprocessing; using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Difficulty.Skills; using osu.Game.Rulesets.Difficulty.Skills;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;