1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 04:32:57 +08:00

Require ScoreProcessor to receive ruleset

This commit is contained in:
Dan Balasescu 2022-03-14 15:51:10 +09:00
parent 9cc7f70872
commit 3fff7f4b7e
30 changed files with 88 additions and 44 deletions

View File

@ -1,11 +0,0 @@
// 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.
using osu.Game.Rulesets.Scoring;
namespace osu.Game.Rulesets.Pippidon.Scoring
{
public class PippidonScoreProcessor : ScoreProcessor
{
}
}

View File

@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.Catch.Tests
[SetUp]
public void SetUp() => Schedule(() =>
{
scoreProcessor = new ScoreProcessor();
scoreProcessor = new ScoreProcessor(new CatchRuleset());
SetContents(_ => new CatchComboDisplay
{

View File

@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Catch
{
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => new DrawableCatchRuleset(this, beatmap, mods);
public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor();
public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor(this);
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new CatchBeatmapConverter(beatmap, this);

View File

@ -7,6 +7,11 @@ namespace osu.Game.Rulesets.Catch.Scoring
{
public class CatchScoreProcessor : ScoreProcessor
{
public CatchScoreProcessor(Ruleset ruleset)
: base(ruleset)
{
}
protected override double ClassicScoreMultiplier => 28;
}
}

View File

@ -47,7 +47,7 @@ namespace osu.Game.Rulesets.Mania
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => new DrawableManiaRuleset(this, beatmap, mods);
public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor();
public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(this);
public override HealthProcessor CreateHealthProcessor(double drainStartTime) => new ManiaHealthProcessor(drainStartTime, 0.5);

View File

@ -7,6 +7,11 @@ namespace osu.Game.Rulesets.Mania.Scoring
{
internal class ManiaScoreProcessor : ScoreProcessor
{
public ManiaScoreProcessor(Ruleset ruleset)
: base(ruleset)
{
}
protected override double DefaultAccuracyPortion => 0.99;
protected override double DefaultComboPortion => 0.01;

View File

@ -43,7 +43,7 @@ namespace osu.Game.Rulesets.Osu
{
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => new DrawableOsuRuleset(this, beatmap, mods);
public override ScoreProcessor CreateScoreProcessor() => new OsuScoreProcessor();
public override ScoreProcessor CreateScoreProcessor() => new OsuScoreProcessor(this);
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new OsuBeatmapConverter(beatmap, this);

View File

@ -11,6 +11,11 @@ namespace osu.Game.Rulesets.Osu.Scoring
{
public class OsuScoreProcessor : ScoreProcessor
{
public OsuScoreProcessor(Ruleset ruleset)
: base(ruleset)
{
}
protected override double ClassicScoreMultiplier => 36;
protected override HitEvent CreateHitEvent(JudgementResult result)

View File

@ -46,7 +46,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
[SetUp]
public void SetUp()
{
scoreProcessor = new TaikoScoreProcessor();
scoreProcessor = new TaikoScoreProcessor(new TaikoRuleset());
}
[Test]

View File

@ -7,6 +7,11 @@ namespace osu.Game.Rulesets.Taiko.Scoring
{
internal class TaikoScoreProcessor : ScoreProcessor
{
public TaikoScoreProcessor(Ruleset ruleset)
: base(ruleset)
{
}
protected override double DefaultAccuracyPortion => 0.75;
protected override double DefaultComboPortion => 0.25;

View File

@ -36,7 +36,7 @@ namespace osu.Game.Rulesets.Taiko
{
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => new DrawableTaikoRuleset(this, beatmap, mods);
public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor();
public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(this);
public override HealthProcessor CreateHealthProcessor(double drainStartTime) => new TaikoHealthProcessor();

View File

@ -25,7 +25,7 @@ namespace osu.Game.Tests.Gameplay
{
var beatmap = new Beatmap<HitObject> { HitObjects = { new HitObject() } };
var scoreProcessor = new ScoreProcessor();
var scoreProcessor = new ScoreProcessor(new OsuRuleset());
scoreProcessor.ApplyBeatmap(beatmap);
// Apply a miss judgement
@ -39,7 +39,7 @@ namespace osu.Game.Tests.Gameplay
{
var beatmap = new Beatmap<HitObject> { HitObjects = { new HitObject() } };
var scoreProcessor = new ScoreProcessor();
var scoreProcessor = new ScoreProcessor(new OsuRuleset());
scoreProcessor.ApplyBeatmap(beatmap);
// Apply a judgement
@ -53,7 +53,7 @@ namespace osu.Game.Tests.Gameplay
{
var beatmap = new Beatmap<HitObject> { HitObjects = { new HitCircle() } };
var scoreProcessor = new ScoreProcessor();
var scoreProcessor = new ScoreProcessor(new OsuRuleset());
scoreProcessor.ApplyBeatmap(beatmap);
scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], new TestJudgement(HitResult.Great)) { Type = HitResult.Great });

View File

@ -10,6 +10,7 @@ using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Scoring;
@ -27,7 +28,7 @@ namespace osu.Game.Tests.Rulesets.Scoring
[SetUp]
public void SetUp()
{
scoreProcessor = new ScoreProcessor();
scoreProcessor = new ScoreProcessor(new OsuRuleset());
beatmap = new TestBeatmap(new RulesetInfo())
{
HitObjects = new List<HitObject>

View File

@ -32,7 +32,7 @@ namespace osu.Game.Tests.Visual.Gameplay
private SkinManager skinManager { get; set; }
[Cached]
private ScoreProcessor scoreProcessor = new ScoreProcessor();
private ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset());
[Cached(typeof(HealthProcessor))]
private HealthProcessor healthProcessor = new DrainingHealthProcessor(0);

View File

@ -10,6 +10,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Configuration;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
@ -24,7 +25,7 @@ namespace osu.Game.Tests.Visual.Gameplay
private HUDOverlay hudOverlay;
[Cached]
private ScoreProcessor scoreProcessor = new ScoreProcessor();
private ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset());
[Cached(typeof(HealthProcessor))]
private HealthProcessor healthProcessor = new DrainingHealthProcessor(0);

View File

@ -273,6 +273,11 @@ namespace osu.Game.Tests.Visual.Gameplay
private class TestScoreProcessor : ScoreProcessor
{
public TestScoreProcessor()
: base(new OsuRuleset())
{
}
public void Reset() => base.Reset(false);
}
}

View File

@ -45,7 +45,7 @@ namespace osu.Game.Tests.Visual.Gameplay
gameplayState = new GameplayState(beatmap, ruleset);
gameplayState.LastJudgementResult.BindTo(lastJudgementResult);
scoreProcessor = new ScoreProcessor();
scoreProcessor = new ScoreProcessor(ruleset);
Child = dependencyContainer = new DependencyProvidingContainer
{

View File

@ -17,7 +17,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public class TestSceneSkinEditorMultipleSkins : SkinnableTestScene
{
[Cached]
private readonly ScoreProcessor scoreProcessor = new ScoreProcessor();
private readonly ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset());
[Cached(typeof(HealthProcessor))]
private HealthProcessor healthProcessor = new DrainingHealthProcessor(0);

View File

@ -5,6 +5,7 @@ using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play.HUD;
using osu.Game.Skinning;
@ -14,7 +15,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public class TestSceneSkinnableAccuracyCounter : SkinnableHUDComponentTestScene
{
[Cached]
private ScoreProcessor scoreProcessor = new ScoreProcessor();
private ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset());
protected override Drawable CreateDefaultImplementation() => new DefaultAccuracyCounter();
protected override Drawable CreateLegacyImplementation() => new LegacyAccuracyCounter();

View File

@ -5,6 +5,7 @@ using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play.HUD;
@ -13,7 +14,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public class TestSceneSkinnableComboCounter : SkinnableHUDComponentTestScene
{
[Cached]
private ScoreProcessor scoreProcessor = new ScoreProcessor();
private ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset());
protected override Drawable CreateDefaultImplementation() => new DefaultComboCounter();
protected override Drawable CreateLegacyImplementation() => new LegacyComboCounter();

View File

@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual.Gameplay
private HUDOverlay hudOverlay;
[Cached]
private ScoreProcessor scoreProcessor = new ScoreProcessor();
private ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset());
[Cached(typeof(HealthProcessor))]
private HealthProcessor healthProcessor = new DrainingHealthProcessor(0);

View File

@ -4,6 +4,7 @@
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play.HUD;
using osu.Game.Skinning;
@ -13,7 +14,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public class TestSceneSkinnableScoreCounter : SkinnableHUDComponentTestScene
{
[Cached]
private ScoreProcessor scoreProcessor = new ScoreProcessor();
private ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset());
protected override Drawable CreateDefaultImplementation() => new DefaultScoreCounter();
protected override Drawable CreateLegacyImplementation() => new LegacyScoreCounter();

View File

@ -6,6 +6,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Scoring;
@ -102,6 +103,11 @@ namespace osu.Game.Tests.Visual.Gameplay
private class TestScoreProcessor : ScoreProcessor
{
public TestScoreProcessor()
: base(new OsuRuleset())
{
}
public void Reset() => base.Reset(false);
}
}

View File

@ -43,7 +43,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
var playable = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
var scoreProcessor = new OsuScoreProcessor();
var scoreProcessor = new OsuScoreProcessor(Ruleset.Value.CreateInstance());
scoreProcessor.ApplyBeatmap(playable);
LoadComponentAsync(leaderboard = new MultiSpectatorLeaderboard(Ruleset.Value, scoreProcessor, clocks.Keys.Select(id => new MultiplayerRoomUser(id)).ToArray())

View File

@ -64,7 +64,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
Children = new Drawable[]
{
scoreProcessor = new OsuScoreProcessor(),
scoreProcessor = new OsuScoreProcessor(Ruleset.Value.CreateInstance()),
};
scoreProcessor.ApplyBeatmap(playableBeatmap);

View File

@ -75,7 +75,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
Children = new Drawable[]
{
scoreProcessor = new OsuScoreProcessor(),
scoreProcessor = new OsuScoreProcessor(Ruleset.Value.CreateInstance()),
};
scoreProcessor.ApplyBeatmap(playableBeatmap);

View File

@ -201,7 +201,7 @@ namespace osu.Game.Rulesets
/// Creates a <see cref="ScoreProcessor"/> for this <see cref="Ruleset"/>.
/// </summary>
/// <returns>The score processor.</returns>
public virtual ScoreProcessor CreateScoreProcessor() => new ScoreProcessor();
public virtual ScoreProcessor CreateScoreProcessor() => new ScoreProcessor(this);
/// <summary>
/// Creates a <see cref="HealthProcessor"/> for this <see cref="Ruleset"/>.

View File

@ -84,6 +84,7 @@ namespace osu.Game.Rulesets.Scoring
/// </summary>
protected virtual double ClassicScoreMultiplier => 36;
private readonly Ruleset ruleset;
private readonly double accuracyPortion;
private readonly double comboPortion;
@ -116,8 +117,10 @@ namespace osu.Game.Rulesets.Scoring
private double scoreMultiplier = 1;
public ScoreProcessor()
public ScoreProcessor(Ruleset ruleset)
{
this.ruleset = ruleset;
accuracyPortion = DefaultAccuracyPortion;
comboPortion = DefaultComboPortion;
@ -255,7 +258,7 @@ namespace osu.Game.Rulesets.Scoring
/// <returns>The total score in the given <see cref="ScoringMode"/>.</returns>
public double ComputeFinalScore(ScoringMode mode, ScoreInfo scoreInfo)
{
extractFromStatistics(scoreInfo.Ruleset.CreateInstance(),
extractFromStatistics(ruleset,
scoreInfo.Statistics,
out double extractedBaseScore,
out double extractedMaxBaseScore,
@ -282,7 +285,7 @@ namespace osu.Game.Rulesets.Scoring
if (!beatmapApplied)
throw new InvalidOperationException($"Cannot compute partial score without calling {nameof(ApplyBeatmap)}.");
extractFromStatistics(scoreInfo.Ruleset.CreateInstance(),
extractFromStatistics(ruleset,
scoreInfo.Statistics,
out double extractedBaseScore,
out _,
@ -317,7 +320,7 @@ namespace osu.Game.Rulesets.Scoring
if (scoreInfo.IsLegacyScore && scoreInfo.Ruleset.OnlineID == 3)
{
extractFromStatistics(
scoreInfo.Ruleset.CreateInstance(),
ruleset,
scoreInfo.Statistics,
out double computedBaseScore,
out double computedMaxBaseScore,

View File

@ -26,6 +26,7 @@ using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Skinning;
using osuTK;
@ -56,6 +57,7 @@ namespace osu.Game.Screens.Play.HUD
private JudgementResult lastJudgement;
private PerformanceCalculator performanceCalculator;
private ScoreInfo scoreInfo;
public PerformancePointsCounter()
{
@ -72,9 +74,10 @@ namespace osu.Game.Screens.Play.HUD
if (gameplayState != null)
{
performanceCalculator = gameplayState.Ruleset.CreatePerformanceCalculator();
clonedMods = gameplayState.Mods.Select(m => m.DeepClone()).ToArray();
scoreInfo = new ScoreInfo(gameplayState.Score.ScoreInfo.BeatmapInfo, gameplayState.Score.ScoreInfo.Ruleset);
var gameplayWorkingBeatmap = new GameplayWorkingBeatmap(gameplayState.Beatmap);
difficultyCache.GetTimedDifficultyAttributesAsync(gameplayWorkingBeatmap, gameplayState.Ruleset, clonedMods, loadCancellationSource.Token)
.ContinueWith(task => Schedule(() =>
@ -123,16 +126,13 @@ namespace osu.Game.Screens.Play.HUD
var attrib = getAttributeAtTime(judgement);
if (gameplayState == null || attrib == null)
if (gameplayState == null || attrib == null || scoreProcessor == null)
{
IsValid = false;
return;
}
// awkward but we need to make sure the true mods are not passed to PerformanceCalculator as it makes a mess of track applications.
var scoreInfo = gameplayState.Score.ScoreInfo.DeepClone();
scoreInfo.Mods = clonedMods;
scoreProcessor.PopulateScore(scoreInfo);
Current.Value = (int)Math.Round(performanceCalculator?.Calculate(scoreInfo, attrib).Total ?? 0, MidpointRounding.AwayFromZero);
IsValid = true;
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Allocation;
@ -11,11 +12,16 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osuTK;
using osuTK.Graphics;
@ -30,7 +36,7 @@ namespace osu.Game.Skinning.Editor
private const float component_display_scale = 0.8f;
[Cached]
private ScoreProcessor scoreProcessor = new ScoreProcessor
private ScoreProcessor scoreProcessor = new ScoreProcessor(new DummyRuleset())
{
Combo = { Value = RNG.Next(1, 1000) },
TotalScore = { Value = RNG.Next(1000, 10000000) }
@ -171,5 +177,15 @@ namespace osu.Game.Skinning.Editor
return true;
}
}
private class DummyRuleset : Ruleset
{
public override IEnumerable<Mod> GetModsFor(ModType type) => throw new NotImplementedException();
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => throw new NotImplementedException();
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new NotImplementedException();
public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => throw new NotImplementedException();
public override string Description { get; }
public override string ShortName { get; }
}
}
}