-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Turn difficulty & performance attributes into structs #30727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 16 commits
e70f257
e88dff0
6e2f8cf
ae25f27
d7ae4a0
4114ff5
109a5ad
c5d5a5b
11cb9e7
b7ae152
aa5dba6
5a989ec
26e9c21
d75eb3a
d12fd89
808d44d
d6e5a47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
| // See the LICENCE file in the repository root for full licence text. | ||
|
|
||
| using System.IO; | ||
| using BenchmarkDotNet.Attributes; | ||
| using osu.Framework.IO.Stores; | ||
| using osu.Game.Beatmaps; | ||
| using osu.Game.Beatmaps.Formats; | ||
| using osu.Game.IO; | ||
| using osu.Game.IO.Archives; | ||
| using osu.Game.Rulesets; | ||
| using osu.Game.Rulesets.Catch; | ||
| using osu.Game.Rulesets.Difficulty; | ||
| using osu.Game.Rulesets.Mania; | ||
| using osu.Game.Rulesets.Osu; | ||
| using osu.Game.Rulesets.Taiko; | ||
| using osu.Game.Scoring; | ||
| using osu.Game.Tests.Resources; | ||
|
|
||
| namespace osu.Game.Benchmarks | ||
| { | ||
| public class BenchmarkDifficultyCalculation : BenchmarkTest | ||
| { | ||
| private FlatWorkingBeatmap beatmap = null!; | ||
|
|
||
| private IDifficultyAttributes osuAttributes = null!; | ||
| private IDifficultyAttributes taikoAttributes = null!; | ||
| private IDifficultyAttributes catchAttributes = null!; | ||
| private IDifficultyAttributes maniaAttributes = null!; | ||
|
|
||
| public override void SetUp() | ||
| { | ||
| using var resources = new DllResourceStore(typeof(TestResources).Assembly); | ||
| using var archive = resources.GetStream("Resources/Archives/241526 Soleily - Renatus.osz"); | ||
| using var zipReader = new ZipArchiveReader(archive); | ||
|
|
||
| using var beatmapStream = new MemoryStream(); | ||
| zipReader.GetStream("Soleily - Renatus (Gamu) [Insane].osu").CopyTo(beatmapStream); | ||
| beatmapStream.Seek(0, SeekOrigin.Begin); | ||
| var reader = new LineBufferedReader(beatmapStream); | ||
| var decoder = Decoder.GetDecoder<Beatmap>(reader); | ||
|
|
||
| beatmap = new FlatWorkingBeatmap(decoder.Decode(reader)); | ||
|
|
||
| // Prepare difficulty attributes for an isolated performance calculation in every mode. | ||
| osuAttributes = DifficultyOsu(); | ||
| taikoAttributes = DifficultyTaiko(); | ||
| catchAttributes = DifficultyCatch(); | ||
| maniaAttributes = DifficultyMania(); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public IDifficultyAttributes DifficultyOsu() => new OsuRuleset().CreateDifficultyCalculator(beatmap).Calculate(); | ||
|
|
||
| [Benchmark] | ||
| public IDifficultyAttributes DifficultyTaiko() => new TaikoRuleset().CreateDifficultyCalculator(beatmap).Calculate(); | ||
|
|
||
| [Benchmark] | ||
| public IDifficultyAttributes DifficultyCatch() => new CatchRuleset().CreateDifficultyCalculator(beatmap).Calculate(); | ||
|
|
||
| [Benchmark] | ||
| public IDifficultyAttributes DifficultyMania() => new ManiaRuleset().CreateDifficultyCalculator(beatmap).Calculate(); | ||
|
|
||
| [Benchmark] | ||
| public void PerformanceOsu() | ||
| { | ||
| Ruleset ruleset = new OsuRuleset(); | ||
| ScoreInfo score = new ScoreInfo(beatmap.BeatmapInfo, ruleset.RulesetInfo); | ||
| ruleset.CreatePerformanceCalculator()!.Calculate(score, osuAttributes); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void PerformanceTaiko() | ||
| { | ||
| Ruleset ruleset = new TaikoRuleset(); | ||
| ScoreInfo score = new ScoreInfo(beatmap.BeatmapInfo, ruleset.RulesetInfo); | ||
| ruleset.CreatePerformanceCalculator()!.Calculate(score, taikoAttributes); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void PerformanceCatch() | ||
| { | ||
| Ruleset ruleset = new CatchRuleset(); | ||
| ScoreInfo score = new ScoreInfo(beatmap.BeatmapInfo, ruleset.RulesetInfo); | ||
| ruleset.CreatePerformanceCalculator()!.Calculate(score, catchAttributes); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void PerformanceMania() | ||
| { | ||
| Ruleset ruleset = new ManiaRuleset(); | ||
| ScoreInfo score = new ScoreInfo(beatmap.BeatmapInfo, ruleset.RulesetInfo); | ||
| ruleset.CreatePerformanceCalculator()!.Calculate(score, maniaAttributes); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,15 @@ | |
|
|
||
| namespace osu.Game.Rulesets.Catch.Difficulty | ||
| { | ||
| public class CatchDifficultyAttributes : DifficultyAttributes | ||
| [JsonObject(MemberSerialization.OptIn)] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's that? why is it here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This attribute was previously defined on the class all attributes inherit from. Even though technically only the osu difficulty attributes need it right now, I decided to stick to how it was before. |
||
| public struct CatchDifficultyAttributes : IDifficultyAttributes | ||
| { | ||
| /// <inheritdoc/> | ||
| public double StarRating { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public int MaxCombo { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The perceived approach rate inclusive of rate-adjusting mods (DT/HT/etc). | ||
| /// </summary> | ||
|
|
@@ -19,22 +26,19 @@ public class CatchDifficultyAttributes : DifficultyAttributes | |
| [JsonProperty("approach_rate")] | ||
| public double ApproachRate { get; set; } | ||
|
|
||
| public override IEnumerable<(int attributeId, object value)> ToDatabaseAttributes() | ||
| public IEnumerable<(int attributeId, object value)> ToDatabaseAttributes() | ||
| { | ||
| foreach (var v in base.ToDatabaseAttributes()) | ||
| yield return v; | ||
|
|
||
| yield return (IDifficultyAttributes.ATTRIB_ID_MAX_COMBO, MaxCombo); | ||
| // Todo: osu!catch should not output star rating in the 'aim' attribute. | ||
| yield return (ATTRIB_ID_AIM, StarRating); | ||
| yield return (ATTRIB_ID_APPROACH_RATE, ApproachRate); | ||
| yield return (IDifficultyAttributes.ATTRIB_ID_AIM, StarRating); | ||
| yield return (IDifficultyAttributes.ATTRIB_ID_APPROACH_RATE, ApproachRate); | ||
| } | ||
|
|
||
| public override void FromDatabaseAttributes(IReadOnlyDictionary<int, double> values, IBeatmapOnlineInfo onlineInfo) | ||
| public void FromDatabaseAttributes(IReadOnlyDictionary<int, double> values, IBeatmapOnlineInfo onlineInfo) | ||
| { | ||
| base.FromDatabaseAttributes(values, onlineInfo); | ||
|
|
||
| StarRating = values[ATTRIB_ID_AIM]; | ||
| ApproachRate = values[ATTRIB_ID_APPROACH_RATE]; | ||
| MaxCombo = (int)values[IDifficultyAttributes.ATTRIB_ID_MAX_COMBO]; | ||
| StarRating = values[IDifficultyAttributes.ATTRIB_ID_AIM]; | ||
| ApproachRate = values[IDifficultyAttributes.ATTRIB_ID_APPROACH_RATE]; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,23 @@ | ||
| // Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
| // See the LICENCE file in the repository root for full licence text. | ||
|
|
||
| using System.Collections.Generic; | ||
| using Newtonsoft.Json; | ||
| using osu.Game.Rulesets.Difficulty; | ||
|
|
||
| namespace osu.Game.Rulesets.Catch.Difficulty | ||
| { | ||
| public class CatchPerformanceAttributes : PerformanceAttributes | ||
| public struct CatchPerformanceAttributes : IPerformanceAttributes | ||
| { | ||
| /// <summary> | ||
| /// Calculated score performance points. | ||
| /// </summary> | ||
| [JsonProperty("pp")] | ||
| public double Total { get; set; } | ||
|
|
||
| public IEnumerable<PerformanceDisplayAttribute> GetAttributesForDisplay() | ||
| { | ||
| yield return new PerformanceDisplayAttribute(nameof(Total), "Achieved PP", Total); | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.