mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 17:23:22 +08:00
Implement stateless colour evaluator and required encoding changes
This commit is contained in:
parent
7917a60e3c
commit
e4086b058b
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using osu.Game.Rulesets.Difficulty.Preprocessing;
|
||||||
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing;
|
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing;
|
||||||
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour;
|
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour;
|
||||||
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data;
|
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data;
|
||||||
@ -18,19 +19,26 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Evaluators
|
|||||||
/// <param name="width">The radius of the sigmoid, outside of which values are near the minimum/maximum.</param>
|
/// <param name="width">The radius of the sigmoid, outside of which values are near the minimum/maximum.</param>
|
||||||
/// <param name="middle">The middle of the sigmoid output.</param>
|
/// <param name="middle">The middle of the sigmoid output.</param>
|
||||||
/// <param name="height">The height of the sigmoid output. This will be equal to max value - min value.</param>
|
/// <param name="height">The height of the sigmoid output. This will be equal to max value - min value.</param>
|
||||||
public static double Sigmoid(double val, double center, double width, double middle, double height)
|
private static double sigmoid(double val, double center, double width, double middle, double height)
|
||||||
{
|
{
|
||||||
double sigmoid = Math.Tanh(Math.E * -(val - center) / width);
|
double sigmoid = Math.Tanh(Math.E * -(val - center) / width);
|
||||||
return sigmoid * (height / 2) + middle;
|
return sigmoid * (height / 2) + middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Evaluate the difficulty of the first note of a <see cref="MonoEncoding"/> or a <see cref="ColourEncoding"/>.
|
/// Evaluate the difficulty of the first note of a <see cref="MonoEncoding"/>.
|
||||||
/// <param name="i">The index of either encoding within it's respective parent.</param>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static double EvaluateDifficultyOf(int i)
|
public static double EvaluateDifficultyOf(MonoEncoding encoding)
|
||||||
{
|
{
|
||||||
return Sigmoid(i, 2, 2, 0.5, 1);
|
return sigmoid(encoding.Index, 2, 2, 0.5, 1) * EvaluateDifficultyOf(encoding.Parent!) * 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Evaluate the difficulty of the first note of a <see cref="ColourEncoding"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static double EvaluateDifficultyOf(ColourEncoding encoding)
|
||||||
|
{
|
||||||
|
return sigmoid(encoding.Index, 2, 2, 0.5, 1) * EvaluateDifficultyOf(encoding.Parent!);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -38,31 +46,22 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Evaluators
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static double EvaluateDifficultyOf(CoupledColourEncoding encoding)
|
public static double EvaluateDifficultyOf(CoupledColourEncoding encoding)
|
||||||
{
|
{
|
||||||
return 1 - Sigmoid(encoding.RepetitionInterval, 2, 2, 0.5, 1);
|
return 2 * (1 - sigmoid(encoding.RepetitionInterval, 2, 2, 0.5, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public static double EvaluateDifficultyOf(DifficultyHitObject hitObject)
|
||||||
/// Pre-evaluate and *assign* difficulty values of all hit objects encoded in a <see cref="CoupledColourEncoding"/>.
|
|
||||||
/// Difficulty values are assigned to <see cref="TaikoDifficultyHitObjectColour.EvaluatedDifficulty"/> of each
|
|
||||||
/// <see cref="TaikoDifficultyHitObject"/> encoded within.
|
|
||||||
/// </summary>
|
|
||||||
public static void PreEvaluateDifficulties(CoupledColourEncoding encoding)
|
|
||||||
{
|
{
|
||||||
double coupledEncodingDifficulty = 2 * EvaluateDifficultyOf(encoding);
|
TaikoDifficultyHitObjectColour colour = ((TaikoDifficultyHitObject)hitObject).Colour;
|
||||||
encoding.Payload[0].Payload[0].EncodedData[0].Colour!.EvaluatedDifficulty += coupledEncodingDifficulty;
|
double difficulty = 0.0d;
|
||||||
|
|
||||||
for (int i = 0; i < encoding.Payload.Count; i++)
|
if (colour.MonoEncoding != null) // Difficulty for MonoEncoding
|
||||||
{
|
difficulty += EvaluateDifficultyOf(colour.MonoEncoding);
|
||||||
ColourEncoding colourEncoding = encoding.Payload[i];
|
if (colour.ColourEncoding != null) // Difficulty for ColourEncoding
|
||||||
double colourEncodingDifficulty = EvaluateDifficultyOf(i) * coupledEncodingDifficulty;
|
difficulty += EvaluateDifficultyOf(colour.ColourEncoding);
|
||||||
colourEncoding.Payload[0].EncodedData[0].Colour!.EvaluatedDifficulty += colourEncodingDifficulty;
|
if (colour.CoupledColourEncoding != null) // Difficulty for CoupledColourEncoding
|
||||||
|
difficulty += EvaluateDifficultyOf(colour.CoupledColourEncoding);
|
||||||
|
|
||||||
for (int j = 0; j < colourEncoding.Payload.Count; j++)
|
return difficulty;
|
||||||
{
|
|
||||||
MonoEncoding monoEncoding = colourEncoding.Payload[j];
|
|
||||||
monoEncoding.EncodedData[0].Colour!.EvaluatedDifficulty += EvaluateDifficultyOf(j) * colourEncodingDifficulty * 0.5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,13 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public List<MonoEncoding> Payload { get; private set; } = new List<MonoEncoding>();
|
public List<MonoEncoding> Payload { get; private set; } = new List<MonoEncoding>();
|
||||||
|
|
||||||
|
public CoupledColourEncoding? Parent;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Index of this encoding within it's parent encoding
|
||||||
|
/// </summary>
|
||||||
|
public int Index;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determine if this <see cref="ColourEncoding"/> is a repetition of another <see cref="ColourEncoding"/>. This
|
/// Determine if this <see cref="ColourEncoding"/> is a repetition of another <see cref="ColourEncoding"/>. This
|
||||||
/// is a strict comparison and is true if and only if the colour sequence is exactly the same.
|
/// is a strict comparison and is true if and only if the colour sequence is exactly the same.
|
||||||
|
@ -19,6 +19,13 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public List<TaikoDifficultyHitObject> EncodedData { get; private set; } = new List<TaikoDifficultyHitObject>();
|
public List<TaikoDifficultyHitObject> EncodedData { get; private set; } = new List<TaikoDifficultyHitObject>();
|
||||||
|
|
||||||
|
public ColourEncoding? Parent;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Index of this encoding within it's parent encoding
|
||||||
|
/// </summary>
|
||||||
|
public int Index;
|
||||||
|
|
||||||
public int RunLength => EncodedData.Count;
|
public int RunLength => EncodedData.Count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Game.Rulesets.Difficulty.Preprocessing;
|
using osu.Game.Rulesets.Difficulty.Preprocessing;
|
||||||
using osu.Game.Rulesets.Taiko.Difficulty.Evaluators;
|
|
||||||
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data;
|
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data;
|
||||||
using osu.Game.Rulesets.Taiko.Objects;
|
using osu.Game.Rulesets.Taiko.Objects;
|
||||||
|
|
||||||
@ -25,22 +24,36 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
|
|||||||
List<TaikoDifficultyHitObjectColour> colours = new List<TaikoDifficultyHitObjectColour>();
|
List<TaikoDifficultyHitObjectColour> colours = new List<TaikoDifficultyHitObjectColour>();
|
||||||
List<CoupledColourEncoding> encodings = Encode(hitObjects);
|
List<CoupledColourEncoding> encodings = Encode(hitObjects);
|
||||||
|
|
||||||
// Assign colour to objects
|
// Assign indexing and encoding data to all relevant objects. Only the first note of each encoding type is
|
||||||
|
// assigned with the relevant encodings.
|
||||||
encodings.ForEach(coupledEncoding =>
|
encodings.ForEach(coupledEncoding =>
|
||||||
{
|
{
|
||||||
coupledEncoding.Payload.ForEach(encoding =>
|
coupledEncoding.Payload[0].Payload[0].EncodedData[0].Colour.CoupledColourEncoding = coupledEncoding;
|
||||||
{
|
|
||||||
encoding.Payload.ForEach(mono =>
|
|
||||||
{
|
|
||||||
mono.EncodedData.ForEach(hitObject =>
|
|
||||||
{
|
|
||||||
hitObject.Colour = new TaikoDifficultyHitObjectColour(coupledEncoding);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Pre-evaluate and assign difficulty values
|
// TODO: Review this -
|
||||||
ColourEvaluator.PreEvaluateDifficulties(coupledEncoding);
|
// The outermost loop is kept a ForEach loop since it doesn't need index information, and we want to
|
||||||
|
// keep i and j for ColourEncoding's and MonoEncoding's index respectively, to keep it in line with
|
||||||
|
// documentation.
|
||||||
|
// If we want uniformity for the outermost loop, it can be switched to a for loop with h or something
|
||||||
|
// else as an index
|
||||||
|
//
|
||||||
|
// While parent and index should be part of the encoding process, they are assigned here instead due to
|
||||||
|
// this being a simple one location to assign them.
|
||||||
|
for (int i = 0; i < coupledEncoding.Payload.Count; ++i)
|
||||||
|
{
|
||||||
|
ColourEncoding colourEncoding = coupledEncoding.Payload[i];
|
||||||
|
colourEncoding.Parent = coupledEncoding;
|
||||||
|
colourEncoding.Index = i;
|
||||||
|
colourEncoding.Payload[0].EncodedData[0].Colour.ColourEncoding = colourEncoding;
|
||||||
|
|
||||||
|
for (int j = 0; j < colourEncoding.Payload.Count; ++j)
|
||||||
|
{
|
||||||
|
MonoEncoding monoEncoding = colourEncoding.Payload[j];
|
||||||
|
monoEncoding.Parent = colourEncoding;
|
||||||
|
monoEncoding.Index = j;
|
||||||
|
monoEncoding.EncodedData[0].Colour.MonoEncoding = monoEncoding;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return colours;
|
return colours;
|
||||||
@ -67,7 +80,6 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
|
|||||||
previousObject == null || // First object in the list
|
previousObject == null || // First object in the list
|
||||||
(taikoObject.BaseObject as Hit)?.Type != (previousObject.BaseObject as Hit)?.Type
|
(taikoObject.BaseObject as Hit)?.Type != (previousObject.BaseObject as Hit)?.Type
|
||||||
)
|
)
|
||||||
|
|
||||||
{
|
{
|
||||||
lastEncoded = new MonoEncoding();
|
lastEncoded = new MonoEncoding();
|
||||||
lastEncoded.EncodedData.Add(taikoObject);
|
lastEncoded.EncodedData.Add(taikoObject);
|
||||||
@ -111,18 +123,6 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
|
|||||||
return encoded;
|
return encoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Encodes a list of <see cref="TaikoDifficultyHitObject"/>s into a list of <see cref="CoupledColourEncoding"/>s.
|
|
||||||
/// </summary>
|
|
||||||
public static List<CoupledColourEncoding> Encode(List<DifficultyHitObject> data)
|
|
||||||
{
|
|
||||||
List<MonoEncoding> firstPass = EncodeMono(data);
|
|
||||||
List<ColourEncoding> secondPass = EncodeColour(firstPass);
|
|
||||||
List<CoupledColourEncoding> thirdPass = EncodeCoupledColour(secondPass);
|
|
||||||
|
|
||||||
return thirdPass;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Encodes a list of <see cref="ColourEncoding"/>s into a list of <see cref="CoupledColourEncoding"/>s.
|
/// Encodes a list of <see cref="ColourEncoding"/>s into a list of <see cref="CoupledColourEncoding"/>s.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -176,5 +176,17 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
|
|||||||
|
|
||||||
return encoded;
|
return encoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encodes a list of <see cref="TaikoDifficultyHitObject"/>s into a list of <see cref="CoupledColourEncoding"/>s.
|
||||||
|
/// </summary>
|
||||||
|
public static List<CoupledColourEncoding> Encode(List<DifficultyHitObject> data)
|
||||||
|
{
|
||||||
|
List<MonoEncoding> firstPass = EncodeMono(data);
|
||||||
|
List<ColourEncoding> secondPass = EncodeColour(firstPass);
|
||||||
|
List<CoupledColourEncoding> thirdPass = EncodeCoupledColour(secondPass);
|
||||||
|
|
||||||
|
return thirdPass;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,18 +6,26 @@ using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data;
|
|||||||
namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
|
namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stores colour compression information for a <see cref="TaikoDifficultyHitObject"/>. This is only present for the
|
/// Stores colour compression information for a <see cref="TaikoDifficultyHitObject"/>.
|
||||||
/// first <see cref="TaikoDifficultyHitObject"/> in a <see cref="CoupledColourEncoding"/> chunk.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TaikoDifficultyHitObjectColour
|
public class TaikoDifficultyHitObjectColour
|
||||||
{
|
{
|
||||||
public CoupledColourEncoding Encoding { get; }
|
/// <summary>
|
||||||
|
/// <see cref="MonoEncoding"/> encoding that encodes this note, only present if this is the first note within a
|
||||||
|
/// <see cref="MonoEncoding"/>
|
||||||
|
/// </summary>
|
||||||
|
public MonoEncoding? MonoEncoding;
|
||||||
|
|
||||||
public double EvaluatedDifficulty = 0;
|
/// <summary>
|
||||||
|
/// <see cref="ColourEncoding"/> encoding that encodes this note, only present if this is the first note within
|
||||||
|
/// a <see cref="ColourEncoding"/>
|
||||||
|
/// </summary>
|
||||||
|
public ColourEncoding? ColourEncoding;
|
||||||
|
|
||||||
public TaikoDifficultyHitObjectColour(CoupledColourEncoding encoding)
|
/// <summary>
|
||||||
{
|
/// <see cref="CoupledColourEncoding"/> encoding that encodes this note, only present if this is the first note
|
||||||
Encoding = encoding;
|
/// within a <see cref="CoupledColourEncoding"/>
|
||||||
}
|
/// </summary>
|
||||||
|
public CoupledColourEncoding? CoupledColourEncoding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing
|
|||||||
/// 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
|
/// This need to be writeable by TaikoDifficultyHitObjectColour so that it can assign potentially reused instances
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TaikoDifficultyHitObjectColour? Colour;
|
public TaikoDifficultyHitObjectColour Colour;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new difficulty hit object.
|
/// Creates a new difficulty hit object.
|
||||||
@ -53,6 +53,9 @@ 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;
|
var currentHit = hitObject as Hit;
|
||||||
noteDifficultyHitObjects = noteObjects;
|
noteDifficultyHitObjects = noteObjects;
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
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;
|
||||||
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing;
|
using osu.Game.Rulesets.Taiko.Difficulty.Evaluators;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
|
namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
|
||||||
{
|
{
|
||||||
@ -29,8 +29,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
|
|||||||
|
|
||||||
protected override double StrainValueOf(DifficultyHitObject current)
|
protected override double StrainValueOf(DifficultyHitObject current)
|
||||||
{
|
{
|
||||||
double difficulty = ((TaikoDifficultyHitObject)current).Colour?.EvaluatedDifficulty ?? 0;
|
return ColourEvaluator.EvaluateDifficultyOf(current);
|
||||||
return difficulty;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user