mirror of
https://github.com/ppy/osu.git
synced 2024-12-05 09:42:54 +08:00
Compare commits
17 Commits
3d65f3ccab
...
00d2bd79bb
Author | SHA1 | Date | |
---|---|---|---|
|
00d2bd79bb | ||
|
aa0ee5cf3a | ||
|
a7586c52d0 | ||
|
e555131b39 | ||
|
ad4df82593 | ||
|
a4d58648e2 | ||
|
4c128c7925 | ||
|
174df35125 | ||
|
510b8d96b1 | ||
|
7a96fef38d | ||
|
ede8d81d26 | ||
|
f69b5bc28a | ||
|
f42b07a4ee | ||
|
f898cfb086 | ||
|
809e4c57e1 | ||
|
c839203a0d | ||
|
e6a931a5c8 |
@ -37,5 +37,7 @@ namespace osu.Game.Rulesets.Osu.Difficulty.Skills
|
||||
|
||||
return currentStrain;
|
||||
}
|
||||
|
||||
public override bool IsRelevant => withSliders;
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
for (double i = 0; i < 5000; i += RNG.NextDouble() * 10 + i / 1000)
|
||||
objects.Add(new HitObject { StartTime = i });
|
||||
|
||||
graph.Objects = objects;
|
||||
graph.SetFromObjects(objects);
|
||||
}
|
||||
|
||||
private partial class TestSongProgressGraph : DefaultSongProgressGraph
|
||||
|
@ -91,8 +91,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
AddToggleStep("toggle graph", b =>
|
||||
{
|
||||
applyToDefaultProgress(s => s.ShowGraph.Value = b);
|
||||
applyToArgonProgress(s => s.ShowGraph.Value = b);
|
||||
applyToDefaultProgress(s => s.GraphType.Value = b ? DifficultyGraphType.ObjectDensity : DifficultyGraphType.None);
|
||||
applyToArgonProgress(s => s.GraphType.Value = b ? DifficultyGraphType.ObjectDensity : DifficultyGraphType.None);
|
||||
});
|
||||
|
||||
AddStep("set white background", () => background.FadeColour(Color4.White, 200, Easing.OutQuint));
|
||||
|
@ -163,6 +163,14 @@ namespace osu.Game.Beatmaps
|
||||
updateScheduler);
|
||||
}
|
||||
|
||||
public Task<List<double[]>> GetSectionDifficultiesAsync(IWorkingBeatmap beatmap, Ruleset ruleset, Mod[] mods, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return Task.Factory.StartNew(() => ruleset.CreateDifficultyCalculator(beatmap).CalculateSectionDifficulties(mods, cancellationToken).ToList(),
|
||||
cancellationToken,
|
||||
TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously,
|
||||
updateScheduler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates all tracked <see cref="BindableStarDifficulty"/> using the current ruleset and mods.
|
||||
/// </summary>
|
||||
|
@ -10,14 +10,14 @@ namespace osu.Game.Localisation.HUD
|
||||
private const string prefix = @"osu.Game.Resources.Localisation.HUD.SongProgress";
|
||||
|
||||
/// <summary>
|
||||
/// "Show difficulty graph"
|
||||
/// "Difficulty graph type"
|
||||
/// </summary>
|
||||
public static LocalisableString ShowGraph => new TranslatableString(getKey(@"show_graph"), "Show difficulty graph");
|
||||
public static LocalisableString GraphType => new TranslatableString(getKey(@"graph_type"), "Difficulty graph type");
|
||||
|
||||
/// <summary>
|
||||
/// "Whether a graph displaying difficulty throughout the beatmap should be shown"
|
||||
/// "Type of a graph displaying difficulty throughout the beatmap"
|
||||
/// </summary>
|
||||
public static LocalisableString ShowGraphDescription => new TranslatableString(getKey(@"show_graph_description"), "Whether a graph displaying difficulty throughout the beatmap should be shown");
|
||||
public static LocalisableString GraphTypeDescription => new TranslatableString(getKey(@"graph_type_description"), "Type of a graph displaying difficulty throughout the beatmap");
|
||||
|
||||
/// <summary>
|
||||
/// "Show time"
|
||||
|
@ -133,6 +133,55 @@ namespace osu.Game.Rulesets.Difficulty
|
||||
return attribs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the difficulty of section of the beatmap with no mods applied.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Per-skill array where each value represents difficulty of this section in certain skill.</returns>
|
||||
public IEnumerable<double[]> CalculateSectionDifficulties(CancellationToken cancellationToken = default)
|
||||
=> CalculateSectionDifficulties(Array.Empty<Mod>(), cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the difficulty of section of the beatmap using a specific mod combination.
|
||||
/// </summary>
|
||||
/// <param name="mods">The mods that should be applied to the beatmap.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Per-skill array where each value represents difficulty of this section in certain skill.</returns>
|
||||
public IEnumerable<double[]> CalculateSectionDifficulties([NotNull] IEnumerable<Mod> mods, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
preProcess(mods, cancellationToken);
|
||||
|
||||
var skills = CreateSkills(Beatmap, playableMods, clockRate);
|
||||
StrainSkill[] relevantSkills = skills.OfType<StrainSkill>().Where(s => s.IsRelevant).ToArray();
|
||||
var hitObjects = getDifficultyHitObjects();
|
||||
|
||||
if (!hitObjects.Any())
|
||||
return Enumerable.Empty<double[]>();
|
||||
|
||||
// Add sections before first object to preserve correct bounds
|
||||
foreach (var skill in relevantSkills)
|
||||
skill.AddEmptySections(hitObjects.First().StartTime, Beatmap.HitObjects.First().StartTime / clockRate);
|
||||
|
||||
foreach (var hitObject in hitObjects)
|
||||
{
|
||||
foreach (var skill in relevantSkills)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
skill.Process(hitObject);
|
||||
}
|
||||
}
|
||||
|
||||
// Add sections up to the end time of last object to preserve correct bounds
|
||||
foreach (var skill in relevantSkills)
|
||||
skill.AddEmptySections(Beatmap.HitObjects.Last().GetEndTime() / clockRate);
|
||||
|
||||
var strainsForSkills = relevantSkills
|
||||
.Select(skill => skill.GetCurrentStrainPeaks().ToArray());
|
||||
|
||||
return strainsForSkills;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the difficulty of the beatmap using all mod combinations applicable to the beatmap.
|
||||
/// </summary>
|
||||
|
@ -37,5 +37,10 @@ namespace osu.Game.Rulesets.Difficulty.Skills
|
||||
/// Returns the calculated difficulty value representing all <see cref="DifficultyHitObject"/>s that have been processed up to this point.
|
||||
/// </summary>
|
||||
public abstract double DifficultyValue();
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this Skill is relevant to star rating calculation.
|
||||
/// </summary>
|
||||
public virtual bool IsRelevant => true;
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,22 @@ namespace osu.Game.Rulesets.Difficulty.Skills
|
||||
return ObjectStrains.Sum(s => 1.1 / (1 + Math.Exp(-10 * (s / consistentTopStrain - 0.88))));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds empty strain sections
|
||||
/// </summary>
|
||||
public void AddEmptySections(double time, double? currentSectionOverride = null)
|
||||
{
|
||||
if (currentSectionOverride.HasValue)
|
||||
currentSectionEnd = Math.Ceiling(currentSectionOverride.Value / SectionLength) * SectionLength;
|
||||
|
||||
while (time > currentSectionEnd)
|
||||
{
|
||||
saveCurrentPeak();
|
||||
currentSectionPeak = 0; // This is wrong, but there's no way get decay from this class
|
||||
currentSectionEnd += SectionLength;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the current peak strain level to the list of strain peaks, which will be used to calculate an overall difficulty.
|
||||
/// </summary>
|
||||
|
@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -80,19 +81,34 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
bool matchingFilter = true;
|
||||
|
||||
matchingFilter &= criteria.Ruleset == null || r.Room.PlaylistItemStats?.RulesetIDs.Any(id => id == criteria.Ruleset.OnlineID) != false;
|
||||
|
||||
if (!string.IsNullOrEmpty(criteria.SearchString))
|
||||
{
|
||||
// Room name isn't translatable, so ToString() is used here for simplicity.
|
||||
matchingFilter &= r.FilterTerms.Any(term => term.ToString().Contains(criteria.SearchString, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
|
||||
matchingFilter &= matchPermissions(r, criteria.Permissions);
|
||||
|
||||
// Room name isn't translatable, so ToString() is used here for simplicity.
|
||||
string[] filterTerms = r.FilterTerms.Select(t => t.ToString()).ToArray();
|
||||
string[] searchTerms = criteria.SearchString.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
matchingFilter &= searchTerms.All(searchTerm => filterTerms.Any(filterTerm => checkTerm(filterTerm, searchTerm)));
|
||||
|
||||
r.MatchingFilter = matchingFilter;
|
||||
}
|
||||
});
|
||||
|
||||
// Lifted from SearchContainer.
|
||||
static bool checkTerm(string haystack, string needle)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
for (int i = 0; i < needle.Length; i++)
|
||||
{
|
||||
int found = CultureInfo.InvariantCulture.CompareInfo.IndexOf(haystack, needle[i], index, CompareOptions.OrdinalIgnoreCase);
|
||||
if (found < 0)
|
||||
return false;
|
||||
|
||||
index = found + 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool matchPermissions(DrawableLoungeRoom room, RoomPermissionsFilter accessType)
|
||||
{
|
||||
switch (accessType)
|
||||
|
@ -24,8 +24,8 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
private const float bar_height = 10;
|
||||
|
||||
[SettingSource(typeof(SongProgressStrings), nameof(SongProgressStrings.ShowGraph), nameof(SongProgressStrings.ShowGraphDescription))]
|
||||
public Bindable<bool> ShowGraph { get; } = new BindableBool(true);
|
||||
[SettingSource(typeof(SongProgressStrings), nameof(SongProgressStrings.GraphType), nameof(SongProgressStrings.GraphTypeDescription))]
|
||||
public Bindable<DifficultyGraphType> GraphType { get; } = new Bindable<DifficultyGraphType>(DifficultyGraphType.ObjectDensity);
|
||||
|
||||
[SettingSource(typeof(SongProgressStrings), nameof(SongProgressStrings.ShowTime), nameof(SongProgressStrings.ShowTimeDescription))]
|
||||
public Bindable<bool> ShowTime { get; } = new BindableBool(true);
|
||||
@ -98,8 +98,11 @@ namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
GraphTypeInternal.ValueChanged += _ => updateGraphVisibility();
|
||||
GraphTypeInternal.Value = GraphType.Value;
|
||||
GraphTypeInternal.BindTo(GraphType);
|
||||
|
||||
Interactive.BindValueChanged(_ => bar.Interactive = Interactive.Value, true);
|
||||
ShowGraph.BindValueChanged(_ => updateGraphVisibility(), true);
|
||||
ShowTime.BindValueChanged(_ => info.FadeTo(ShowTime.Value ? 1 : 0, 200, Easing.In), true);
|
||||
AccentColour.BindValueChanged(_ => Colour = AccentColour.Value, true);
|
||||
|
||||
@ -109,17 +112,19 @@ namespace osu.Game.Screens.Play.HUD
|
||||
Width = previousWidth;
|
||||
}
|
||||
|
||||
protected override void UpdateObjects(IEnumerable<HitObject> objects)
|
||||
protected override void UpdateTimeBounds()
|
||||
{
|
||||
graph.Objects = objects;
|
||||
|
||||
info.StartTime = bar.StartTime = FirstHitTime;
|
||||
info.EndTime = bar.EndTime = LastHitTime;
|
||||
}
|
||||
|
||||
protected override void UpdateFromObjects(IEnumerable<HitObject> objects) => graph.SetFromObjects(objects);
|
||||
|
||||
protected override void UpdateFromStrains(double[] sectionStrains) => graph.SetFromStrains(sectionStrains);
|
||||
|
||||
private void updateGraphVisibility()
|
||||
{
|
||||
graph.FadeTo(ShowGraph.Value ? 1 : 0, 200, Easing.In);
|
||||
graph.FadeTo(GraphTypeInternal.Value != DifficultyGraphType.None ? 1 : 0, 200, Easing.In);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
|
@ -10,49 +10,48 @@ using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public partial class ArgonSongProgressGraph : SegmentedGraph<int>
|
||||
public partial class ArgonSongProgressGraph : SegmentedGraph<float>
|
||||
{
|
||||
private const int tier_count = 5;
|
||||
|
||||
private const int display_granularity = 200;
|
||||
|
||||
private IEnumerable<HitObject>? objects;
|
||||
|
||||
public IEnumerable<HitObject> Objects
|
||||
public void SetFromObjects(IEnumerable<HitObject> objects)
|
||||
{
|
||||
set
|
||||
float[] values = new float[display_granularity];
|
||||
|
||||
if (!objects.Any())
|
||||
return;
|
||||
|
||||
(double firstHit, double lastHit) = BeatmapExtensions.CalculatePlayableBounds(objects);
|
||||
|
||||
if (lastHit == 0)
|
||||
lastHit = objects.Last().StartTime;
|
||||
|
||||
double interval = (lastHit - firstHit + 1) / display_granularity;
|
||||
|
||||
foreach (var h in objects)
|
||||
{
|
||||
objects = value;
|
||||
double endTime = h.GetEndTime();
|
||||
|
||||
int[] values = new int[display_granularity];
|
||||
Debug.Assert(endTime >= h.StartTime);
|
||||
|
||||
if (!objects.Any())
|
||||
return;
|
||||
|
||||
(double firstHit, double lastHit) = BeatmapExtensions.CalculatePlayableBounds(objects);
|
||||
|
||||
if (lastHit == 0)
|
||||
lastHit = objects.Last().StartTime;
|
||||
|
||||
double interval = (lastHit - firstHit + 1) / display_granularity;
|
||||
|
||||
foreach (var h in objects)
|
||||
{
|
||||
double endTime = h.GetEndTime();
|
||||
|
||||
Debug.Assert(endTime >= h.StartTime);
|
||||
|
||||
int startRange = (int)((h.StartTime - firstHit) / interval);
|
||||
int endRange = (int)((endTime - firstHit) / interval);
|
||||
for (int i = startRange; i <= endRange; i++)
|
||||
values[i]++;
|
||||
}
|
||||
|
||||
Values = values;
|
||||
int startRange = (int)((h.StartTime - firstHit) / interval);
|
||||
int endRange = (int)((endTime - firstHit) / interval);
|
||||
for (int i = startRange; i <= endRange; i++)
|
||||
values[i]++;
|
||||
}
|
||||
|
||||
Values = values;
|
||||
}
|
||||
|
||||
public void SetFromStrains(double[] strains)
|
||||
{
|
||||
Values = FormatUtils.ResampleStrains(strains, display_granularity).Select(value => (float)value).ToArray();
|
||||
}
|
||||
|
||||
public ArgonSongProgressGraph()
|
||||
|
@ -31,8 +31,8 @@ namespace osu.Game.Screens.Play.HUD
|
||||
private readonly SongProgressInfo info;
|
||||
private readonly Container content;
|
||||
|
||||
[SettingSource(typeof(SongProgressStrings), nameof(SongProgressStrings.ShowGraph), nameof(SongProgressStrings.ShowGraphDescription))]
|
||||
public Bindable<bool> ShowGraph { get; } = new BindableBool(true);
|
||||
[SettingSource(typeof(SongProgressStrings), nameof(SongProgressStrings.GraphType), nameof(SongProgressStrings.GraphTypeDescription))]
|
||||
public Bindable<DifficultyGraphType> GraphType { get; } = new Bindable<DifficultyGraphType>(DifficultyGraphType.ObjectDensity);
|
||||
|
||||
[SettingSource(typeof(SongProgressStrings), nameof(SongProgressStrings.ShowTime), nameof(SongProgressStrings.ShowTimeDescription))]
|
||||
public Bindable<bool> ShowTime { get; } = new BindableBool(true);
|
||||
@ -95,24 +95,31 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
GraphTypeInternal.ValueChanged += _ => updateGraphVisibility();
|
||||
GraphTypeInternal.Value = GraphType.Value;
|
||||
GraphTypeInternal.BindTo(GraphType);
|
||||
|
||||
Interactive.BindValueChanged(_ => updateBarVisibility(), true);
|
||||
ShowGraph.BindValueChanged(_ => updateGraphVisibility(), true);
|
||||
ShowTime.BindValueChanged(_ => updateTimeVisibility(), true);
|
||||
AccentColour.BindValueChanged(_ => Colour = AccentColour.Value, true);
|
||||
|
||||
updateGraphVisibility();
|
||||
|
||||
base.LoadComplete();
|
||||
}
|
||||
|
||||
protected override void UpdateObjects(IEnumerable<HitObject> objects)
|
||||
protected override void UpdateTimeBounds()
|
||||
{
|
||||
graph.Objects = objects;
|
||||
|
||||
info.StartTime = FirstHitTime;
|
||||
info.EndTime = LastHitTime;
|
||||
bar.StartTime = FirstHitTime;
|
||||
bar.EndTime = LastHitTime;
|
||||
}
|
||||
|
||||
protected override void UpdateFromObjects(IEnumerable<HitObject> objects) => graph.SetFromObjects(objects);
|
||||
|
||||
protected override void UpdateFromStrains(double[] sectionStrains) => graph.SetFromStrains(sectionStrains);
|
||||
|
||||
protected override void UpdateProgress(double progress, bool isIntro)
|
||||
{
|
||||
graph.Progress = isIntro ? 0 : (int)(graph.ColumnCount * progress);
|
||||
@ -140,8 +147,8 @@ namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
float barHeight = bottom_bar_height + handle_size.Y;
|
||||
|
||||
bar.ResizeHeightTo(ShowGraph.Value ? barHeight + graph_height : barHeight, transition_duration, Easing.In);
|
||||
graph.FadeTo(ShowGraph.Value ? 1 : 0, transition_duration, Easing.In);
|
||||
bar.ResizeHeightTo(GraphTypeInternal.Value != DifficultyGraphType.None ? barHeight + graph_height : barHeight, transition_duration, Easing.In);
|
||||
graph.FadeTo(GraphTypeInternal.Value != DifficultyGraphType.None ? 1 : 0, transition_duration, Easing.In);
|
||||
|
||||
updateInfoMargin();
|
||||
}
|
||||
@ -155,7 +162,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
private void updateInfoMargin()
|
||||
{
|
||||
float finalMargin = bottom_bar_height + (Interactive.Value ? handle_size.Y : 0) + (ShowGraph.Value ? graph_height : 0);
|
||||
float finalMargin = bottom_bar_height + (Interactive.Value ? handle_size.Y : 0) + (GraphTypeInternal.Value != DifficultyGraphType.None ? graph_height : 0);
|
||||
info.TransformTo(nameof(info.Margin), new MarginPadding { Bottom = finalMargin }, transition_duration, Easing.In);
|
||||
}
|
||||
}
|
||||
|
@ -8,44 +8,44 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public partial class DefaultSongProgressGraph : SquareGraph
|
||||
{
|
||||
private IEnumerable<HitObject> objects;
|
||||
private const int granularity = 200;
|
||||
|
||||
public IEnumerable<HitObject> Objects
|
||||
public void SetFromObjects(IEnumerable<HitObject> objects)
|
||||
{
|
||||
set
|
||||
Values = new float[granularity];
|
||||
|
||||
if (!objects.Any())
|
||||
return;
|
||||
|
||||
(double firstHit, double lastHit) = BeatmapExtensions.CalculatePlayableBounds(objects);
|
||||
|
||||
if (lastHit == 0)
|
||||
lastHit = objects.Last().StartTime;
|
||||
|
||||
double interval = (lastHit - firstHit + 1) / granularity;
|
||||
|
||||
foreach (var h in objects)
|
||||
{
|
||||
objects = value;
|
||||
double endTime = h.GetEndTime();
|
||||
|
||||
const int granularity = 200;
|
||||
Values = new int[granularity];
|
||||
Debug.Assert(endTime >= h.StartTime);
|
||||
|
||||
if (!objects.Any())
|
||||
return;
|
||||
|
||||
(double firstHit, double lastHit) = BeatmapExtensions.CalculatePlayableBounds(objects);
|
||||
|
||||
if (lastHit == 0)
|
||||
lastHit = objects.Last().StartTime;
|
||||
|
||||
double interval = (lastHit - firstHit + 1) / granularity;
|
||||
|
||||
foreach (var h in objects)
|
||||
{
|
||||
double endTime = h.GetEndTime();
|
||||
|
||||
Debug.Assert(endTime >= h.StartTime);
|
||||
|
||||
int startRange = (int)((h.StartTime - firstHit) / interval);
|
||||
int endRange = (int)((endTime - firstHit) / interval);
|
||||
for (int i = startRange; i <= endRange; i++)
|
||||
Values[i]++;
|
||||
}
|
||||
int startRange = (int)((h.StartTime - firstHit) / interval);
|
||||
int endRange = (int)((endTime - firstHit) / interval);
|
||||
for (int i = startRange; i <= endRange; i++)
|
||||
Values[i]++;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFromStrains(double[] strains)
|
||||
{
|
||||
Values = FormatUtils.ResampleStrains(strains, granularity).Select(value => (float)value).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,18 +3,30 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Skinning;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
public enum DifficultyGraphType
|
||||
{
|
||||
None,
|
||||
ObjectDensity,
|
||||
Difficulty
|
||||
}
|
||||
|
||||
public abstract partial class SongProgress : OverlayContainer, ISerialisableDrawable
|
||||
{
|
||||
// Some implementations of this element allow seeking during gameplay playback.
|
||||
@ -32,6 +44,11 @@ namespace osu.Game.Screens.Play.HUD
|
||||
/// </remarks>
|
||||
public readonly Bindable<bool> Interactive = new Bindable<bool>();
|
||||
|
||||
/// <summary>
|
||||
/// Type of the difficulty info used in graph.
|
||||
/// </summary>
|
||||
protected readonly Bindable<DifficultyGraphType> GraphTypeInternal = new Bindable<DifficultyGraphType>(DifficultyGraphType.None);
|
||||
|
||||
public bool UsesFixedAnchor { get; set; }
|
||||
|
||||
[Resolved]
|
||||
@ -46,20 +63,6 @@ namespace osu.Game.Screens.Play.HUD
|
||||
/// </summary>
|
||||
protected IClock FrameStableClock => frameStableClock ?? GameplayClock;
|
||||
|
||||
private IEnumerable<HitObject>? objects;
|
||||
|
||||
public IEnumerable<HitObject> Objects
|
||||
{
|
||||
set
|
||||
{
|
||||
objects = value;
|
||||
|
||||
(FirstHitTime, LastHitTime) = BeatmapExtensions.CalculatePlayableBounds(objects);
|
||||
|
||||
UpdateObjects(objects);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
@ -67,10 +70,6 @@ namespace osu.Game.Screens.Play.HUD
|
||||
Show();
|
||||
}
|
||||
|
||||
protected double FirstHitTime { get; private set; }
|
||||
|
||||
protected double LastHitTime { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Called every update frame with current progress information.
|
||||
/// </summary>
|
||||
@ -78,8 +77,6 @@ namespace osu.Game.Screens.Play.HUD
|
||||
/// <param name="isIntro">If <c>true</c>, progress is (0..1) through the intro.</param>
|
||||
protected abstract void UpdateProgress(double progress, bool isIntro);
|
||||
|
||||
protected virtual void UpdateObjects(IEnumerable<HitObject> objects) { }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(DrawableRuleset? drawableRuleset, Player? player)
|
||||
{
|
||||
@ -90,6 +87,27 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
Objects = drawableRuleset.Objects;
|
||||
}
|
||||
|
||||
GraphTypeInternal.BindValueChanged(_ => updateBasedOnGraphType(), true);
|
||||
}
|
||||
|
||||
private void updateBasedOnGraphType()
|
||||
{
|
||||
switch (GraphTypeInternal.Value)
|
||||
{
|
||||
case DifficultyGraphType.None:
|
||||
UpdateFromObjects(Enumerable.Empty<HitObject>());
|
||||
break;
|
||||
|
||||
case DifficultyGraphType.ObjectDensity:
|
||||
if (objects != null) UpdateFromObjects(objects);
|
||||
break;
|
||||
|
||||
case DifficultyGraphType.Difficulty:
|
||||
if (sectionStrains != null) UpdateFromStrains(getTotalStrains(sectionStrains));
|
||||
else calculateStrains();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void PopIn() => this.FadeIn(500, Easing.OutQuint);
|
||||
@ -127,5 +145,79 @@ namespace osu.Game.Screens.Play.HUD
|
||||
UpdateProgress(objectOffsetCurrent / objectDuration, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void UpdateTimeBounds() { }
|
||||
|
||||
#region object density
|
||||
|
||||
protected double FirstHitTime { get; private set; }
|
||||
|
||||
protected double LastHitTime { get; private set; }
|
||||
|
||||
private IEnumerable<HitObject>? objects;
|
||||
|
||||
public IEnumerable<HitObject> Objects
|
||||
{
|
||||
set
|
||||
{
|
||||
objects = value;
|
||||
|
||||
(FirstHitTime, LastHitTime) = BeatmapExtensions.CalculatePlayableBounds(objects);
|
||||
|
||||
UpdateTimeBounds();
|
||||
updateBasedOnGraphType();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void UpdateFromObjects(IEnumerable<HitObject> objects) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region diffcalc
|
||||
|
||||
private bool strainsCalculationWasStarted;
|
||||
|
||||
private List<double[]>? sectionStrains;
|
||||
|
||||
[Resolved]
|
||||
private BeatmapDifficultyCache difficultyCache { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private IBindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
|
||||
|
||||
private void calculateStrains()
|
||||
{
|
||||
// No need for another recalc if strains are being recalculated right now;
|
||||
if (strainsCalculationWasStarted) return;
|
||||
|
||||
strainsCalculationWasStarted = true;
|
||||
difficultyCache.GetSectionDifficultiesAsync(beatmap.Value, ruleset.Value.CreateInstance(), mods.Value.ToArray())
|
||||
.ContinueWith(task => Schedule(() =>
|
||||
{
|
||||
sectionStrains = task.GetResultSafely();
|
||||
updateBasedOnGraphType();
|
||||
}), TaskContinuationOptions.OnlyOnRanToCompletion);
|
||||
}
|
||||
|
||||
private double[] getTotalStrains(List<double[]> allStrains)
|
||||
{
|
||||
var result = allStrains
|
||||
.SelectMany(arr => arr.Select((value, index) => (value, index)))
|
||||
.GroupBy(x => x.index)
|
||||
.Select(g => Math.Sqrt(g.Sum(x => x.value * x.value)));
|
||||
|
||||
// Skip one to account for delay in strains
|
||||
return result.Skip(1).ToArray();
|
||||
}
|
||||
|
||||
protected virtual void UpdateFromStrains(double[] sectionStrains) { }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +43,9 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
private float[] calculatedValues = Array.Empty<float>(); // values but adjusted to fit the amount of columns
|
||||
|
||||
private int[] values;
|
||||
private float[] values;
|
||||
|
||||
public int[] Values
|
||||
public float[] Values
|
||||
{
|
||||
get => values;
|
||||
set
|
||||
@ -168,13 +168,13 @@ namespace osu.Game.Screens.Play
|
||||
return;
|
||||
}
|
||||
|
||||
int max = values.Max();
|
||||
float max = values.Max();
|
||||
|
||||
float step = values.Length / (float)ColumnCount;
|
||||
|
||||
for (float i = 0; i < values.Length; i += step)
|
||||
{
|
||||
newValues.Add((float)values[(int)i] / max);
|
||||
newValues.Add(values[(int)i] / max);
|
||||
}
|
||||
|
||||
calculatedValues = newValues.ToArray();
|
||||
|
@ -55,6 +55,8 @@ namespace osu.Game.Screens.Ranking
|
||||
[Resolved]
|
||||
private Player? player { get; set; }
|
||||
|
||||
private bool skipExitTransition;
|
||||
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; } = null!;
|
||||
|
||||
@ -203,6 +205,7 @@ namespace osu.Game.Screens.Ranking
|
||||
{
|
||||
if (!this.IsCurrentScreen()) return;
|
||||
|
||||
skipExitTransition = true;
|
||||
player?.Restart(true);
|
||||
},
|
||||
});
|
||||
@ -313,7 +316,8 @@ namespace osu.Game.Screens.Ranking
|
||||
// HitObject references from HitEvent.
|
||||
Score?.HitEvents.Clear();
|
||||
|
||||
this.FadeOut(100);
|
||||
if (!skipExitTransition)
|
||||
this.FadeOut(100);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Humanizer;
|
||||
using osu.Framework.Extensions.LocalisationExtensions;
|
||||
using osu.Framework.Localisation;
|
||||
@ -59,5 +60,160 @@ namespace osu.Game.Utils
|
||||
/// <param name="baseBpm">The base BPM to round.</param>
|
||||
/// <param name="rate">Rate adjustment, if applicable.</param>
|
||||
public static int RoundBPM(double baseBpm, double rate = 1) => (int)Math.Round(Math.Round(baseBpm) * rate);
|
||||
|
||||
/// <summary>
|
||||
/// Resampling strain values to certain bin size.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The main feature of this resampling is that peak strains will be always preserved.
|
||||
/// This means that the highest strain can't be decreased by averaging or interpolation.
|
||||
/// </remarks>
|
||||
public static double[] ResampleStrains(double[] values, int targetSize)
|
||||
{
|
||||
// Set to at least one value, what will be 0 in this case
|
||||
if (values.Length == 0)
|
||||
values = new double[1];
|
||||
|
||||
if (targetSize > values.Length)
|
||||
return resamplingUpscale(values, targetSize);
|
||||
else if (targetSize < values.Length)
|
||||
return resamplingDownscale(values, targetSize);
|
||||
|
||||
return (double[])values.Clone();
|
||||
}
|
||||
|
||||
private static double[] resamplingUpscale(double[] values, int targetSize)
|
||||
{
|
||||
// Create array filled with -inf
|
||||
double[] result = Enumerable.Repeat(double.NegativeInfinity, targetSize).ToArray();
|
||||
|
||||
// First and last peaks are constant
|
||||
result[0] = values[0];
|
||||
result[^1] = values[^1];
|
||||
|
||||
// On the first pass we place peaks
|
||||
|
||||
int sourceIndex = 1;
|
||||
int targetIndex = 1;
|
||||
|
||||
// Adjust sizes accounting for the fact that first and last elements already set-up
|
||||
int sourceSize = Math.Max(1, values.Length - 1);
|
||||
targetSize -= 1;
|
||||
|
||||
for (; targetIndex < targetSize - 1; targetIndex++)
|
||||
{
|
||||
double sourceProgress = (double)sourceIndex / sourceSize;
|
||||
|
||||
double targetProgressNext = (targetIndex + 1.0) / targetSize;
|
||||
|
||||
// If we reached the point where source is between current and next - then peak is either current or next
|
||||
if (sourceProgress <= targetProgressNext)
|
||||
{
|
||||
double targetProgressCurrent = (double)targetIndex / targetSize;
|
||||
|
||||
double distanceToCurrent = sourceProgress - targetProgressCurrent;
|
||||
double distanceToNext = targetProgressNext - sourceProgress;
|
||||
|
||||
// If it's next what is closer - abbadon current and move to next immediatly
|
||||
if (distanceToNext < distanceToCurrent)
|
||||
{
|
||||
result[targetIndex] = double.NegativeInfinity;
|
||||
targetIndex++;
|
||||
}
|
||||
|
||||
result[targetIndex] = values[sourceIndex];
|
||||
sourceIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
// On second pass we interpolate between peaks
|
||||
|
||||
sourceIndex = 0;
|
||||
targetIndex = 1;
|
||||
|
||||
for (; targetIndex < targetSize; targetIndex++)
|
||||
{
|
||||
// If we're on peak - skip iteration
|
||||
if (result[targetIndex] != double.NegativeInfinity)
|
||||
{
|
||||
sourceIndex++;
|
||||
continue;
|
||||
}
|
||||
|
||||
double targetProgress = (double)targetIndex / targetSize;
|
||||
|
||||
double previousPeakProgress = (double)sourceIndex / sourceSize;
|
||||
double nextPeakProgress = (sourceIndex + 1.0) / sourceSize;
|
||||
|
||||
double distanceToPreviousPeak = targetProgress - previousPeakProgress;
|
||||
double distanceToNextPeak = nextPeakProgress - targetProgress;
|
||||
|
||||
double lerpCoef = distanceToPreviousPeak / (distanceToPreviousPeak + distanceToNextPeak);
|
||||
double nextValue = sourceIndex + 1 < values.Length ? values[sourceIndex + 1] : values[sourceIndex];
|
||||
result[targetIndex] = double.Lerp(values[sourceIndex], nextValue, lerpCoef);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static double[] resamplingDownscale(double[] values, int targetSize)
|
||||
{
|
||||
double[] result = new double[targetSize];
|
||||
|
||||
int sourceIndex = 0;
|
||||
int targetIndex = 0;
|
||||
|
||||
double currentSampleMax = double.NegativeInfinity;
|
||||
|
||||
for (; sourceIndex < values.Length; sourceIndex++)
|
||||
{
|
||||
double currentValue = values[sourceIndex];
|
||||
|
||||
double sourceProgress = (sourceIndex + 0.5) / values.Length;
|
||||
double targetProgressBorder = (targetIndex + 1.0) / targetSize;
|
||||
|
||||
double distanceToBorder = targetProgressBorder - sourceProgress;
|
||||
|
||||
// Handle transition to next sample
|
||||
if (distanceToBorder < 0)
|
||||
{
|
||||
double targetProgressCurrent = (targetIndex + 0.5) / targetSize;
|
||||
double targetProgressNext = (targetIndex + 1.5) / targetSize;
|
||||
|
||||
// Try fit weighted current into still current sample
|
||||
// It would always be closer to Next than to Current
|
||||
double weight = (targetProgressNext - sourceProgress) / (sourceProgress - targetProgressCurrent);
|
||||
double weightedValue = currentValue * weight;
|
||||
|
||||
if (currentSampleMax < weightedValue) currentSampleMax = weightedValue;
|
||||
|
||||
// Flush current max
|
||||
result[targetIndex] = currentSampleMax;
|
||||
targetIndex++;
|
||||
currentSampleMax = double.NegativeInfinity;
|
||||
|
||||
// Try to fit weighted previous into future sample
|
||||
if (sourceIndex > 0)
|
||||
{
|
||||
double prevValue = values[sourceIndex - 1];
|
||||
double sourceProgressPrev = (sourceIndex - 0.5) / values.Length;
|
||||
|
||||
// It would always be closer to Current than to Current
|
||||
weight = (sourceProgressPrev - targetProgressCurrent) / (targetProgressNext - sourceProgressPrev);
|
||||
weightedValue = prevValue * weight;
|
||||
|
||||
currentSampleMax = weightedValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Replace with maximum of the sample
|
||||
if (currentSampleMax < currentValue) currentSampleMax = currentValue;
|
||||
}
|
||||
|
||||
// Flush last value
|
||||
result[targetIndex] = currentSampleMax;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user