From a47870b376e59e8d495b5a29067c4a6ef5611526 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 20 Apr 2017 11:16:08 +0900 Subject: [PATCH] Apply Ruleset to Scores. Reduce complexity of score creation. --- .../Scoring/OsuScoreProcessor.cs | 6 ++--- osu.Game/Database/ScoreDatabase.cs | 2 +- osu.Game/Rulesets/Scoring/Score.cs | 2 ++ osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 12 +--------- osu.Game/Screens/Play/Player.cs | 23 +++++++++++++------ 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs index 470086bf78..7c6bf8344b 100644 --- a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs +++ b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs @@ -37,16 +37,14 @@ namespace osu.Game.Rulesets.Osu.Scoring private readonly Dictionary scoreResultCounts = new Dictionary(); private readonly Dictionary comboResultCounts = new Dictionary(); - public override Score GetPopulatedScore() + public override void PopulateScore(Score score) { - var score = base.GetPopulatedScore(); + base.PopulateScore(score); score.Statistics[@"300"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Hit300); score.Statistics[@"100"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Hit100); score.Statistics[@"50"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Hit50); score.Statistics[@"x"] = scoreResultCounts.GetOrDefault(OsuScoreResult.Miss); - - return score; } protected override void OnNewJudgement(OsuJudgement judgement) diff --git a/osu.Game/Database/ScoreDatabase.cs b/osu.Game/Database/ScoreDatabase.cs index 2ffe12d50e..affbaf4e2b 100644 --- a/osu.Game/Database/ScoreDatabase.cs +++ b/osu.Game/Database/ScoreDatabase.cs @@ -45,7 +45,7 @@ namespace osu.Game.Database using (SerializationReader sr = new SerializationReader(s)) { var ruleset = rulesets.GetRuleset(sr.ReadByte()).CreateInstance(); - score = ruleset.CreateScoreProcessor().CreateEmptyScore(); + score = new Score(); /* score.Pass = true;*/ var version = sr.ReadInt32(); diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index fbbd766a18..5d94fde03b 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -32,6 +32,8 @@ namespace osu.Game.Rulesets.Scoring [JsonProperty(@"mods")] protected string[] ModStrings { get; set; } //todo: parse to Mod objects + public RulesetInfo Ruleset { get; set; } + public Mod[] Mods { get; set; } [JsonProperty(@"user")] diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 1fe21c8724..f31a1a11aa 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -61,12 +61,6 @@ namespace osu.Game.Rulesets.Scoring Reset(); } - /// - /// Creates a Score applicable to the ruleset in which this ScoreProcessor resides. - /// - /// The Score. - public virtual Score CreateEmptyScore() => new Score(); - private ScoreRank rankFrom(double acc) { if (acc == 1) @@ -114,10 +108,8 @@ namespace osu.Game.Rulesets.Scoring /// /// Retrieve a score populated with data for the current play this processor is responsible for. /// - public virtual Score GetPopulatedScore() + public virtual void PopulateScore(Score score) { - var score = CreateEmptyScore(); - score.TotalScore = TotalScore; score.Combo = Combo; score.MaxCombo = HighestCombo; @@ -125,8 +117,6 @@ namespace osu.Game.Rulesets.Scoring score.Rank = rankFrom(Accuracy); score.Date = DateTime.Now; score.Health = Health; - - return score; } } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 8c3f3da58a..fc7cbe170a 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -51,7 +51,7 @@ namespace osu.Game.Screens.Play private IAdjustableClock sourceClock; private IFrameBasedClock interpolatedSourceClock; - private Ruleset ruleset; + private RulesetInfo ruleset; private ScoreProcessor scoreProcessor; protected HitRenderer HitRenderer; @@ -68,6 +68,8 @@ namespace osu.Game.Screens.Play dimLevel = config.GetBindable(OsuConfig.DimLevel); mouseWheelDisabled = config.GetBindable(OsuConfig.MouseDisableWheel); + Ruleset rulesetInstance; + try { if (Beatmap == null) @@ -82,15 +84,17 @@ namespace osu.Game.Screens.Play try { // Try using the preferred user ruleset - ruleset = osu == null ? Beatmap.BeatmapInfo.Ruleset.CreateInstance() : osu.Ruleset.Value.CreateInstance(); - HitRenderer = ruleset.CreateHitRendererWith(Beatmap); + ruleset = osu == null ? Beatmap.BeatmapInfo.Ruleset : osu.Ruleset.Value; } catch (BeatmapInvalidForModeException) { // Default to the beatmap ruleset - ruleset = Beatmap.BeatmapInfo.Ruleset.CreateInstance(); - HitRenderer = ruleset.CreateHitRendererWith(Beatmap); + ruleset = Beatmap.BeatmapInfo.Ruleset; } + + rulesetInstance = ruleset.CreateInstance(); + + HitRenderer = rulesetInstance.CreateHitRendererWith(Beatmap); } catch (Exception e) { @@ -125,7 +129,7 @@ namespace osu.Game.Screens.Play Origin = Anchor.Centre }; - hudOverlay.KeyCounter.Add(ruleset.CreateGameplayKeys()); + hudOverlay.KeyCounter.Add(rulesetInstance.CreateGameplayKeys()); hudOverlay.BindProcessor(scoreProcessor); hudOverlay.BindHitRenderer(HitRenderer); @@ -266,7 +270,12 @@ namespace osu.Game.Screens.Play Delay(1000); onCompletionEvent = Schedule(delegate { - var score = scoreProcessor.GetPopulatedScore(); + var score = new Score + { + Beatmap = Beatmap.BeatmapInfo, + Ruleset = ruleset + }; + scoreProcessor.PopulateScore(score); score.User = HitRenderer.Replay?.User ?? (Game as OsuGame)?.API?.LocalUser?.Value; Push(new Results(score)); });