Make ScoreProcessors take generic judgements.

This commit is contained in:
smoogipooo 2017-03-16 12:40:35 +09:00
parent a7ba6bbcfe
commit c82ae011fb
25 changed files with 137 additions and 56 deletions

View File

@ -87,8 +87,6 @@ public override IEnumerable<Mod> GetModsFor(ModType type)
new KeyCounterMouse(MouseButton.Right)
};
public override ScoreProcessor CreateScoreProcessor(int hitObjectCount = 0) => null;
public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new CatchDifficultyCalculator(beatmap);
}
}

View File

@ -0,0 +1,21 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Modes.Catch.Judgements;
using osu.Game.Modes.Catch.Objects;
using osu.Game.Modes.UI;
namespace osu.Game.Modes.Catch
{
internal class CatchScoreProcessor : ScoreProcessor<CatchBaseHit, CatchJudgementInfo>
{
public CatchScoreProcessor(HitRenderer<CatchBaseHit, CatchJudgementInfo> hitRenderer)
: base(hitRenderer)
{
}
protected override void UpdateCalculations(CatchJudgementInfo newJudgement)
{
}
}
}

View File

@ -17,11 +17,13 @@ public CatchHitRenderer(WorkingBeatmap beatmap)
{
}
public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor(this);
protected override IBeatmapConverter<CatchBaseHit> CreateBeatmapConverter() => new CatchBeatmapConverter();
protected override IBeatmapProcessor<CatchBaseHit> CreateBeatmapProcessor() => new CatchBeatmapProcessor();
protected override Playfield<CatchBaseHit, CatchJudgementInfo> CreatePlayfield() => new CatchPlayfield();
protected override Playfield<CatchBaseHit, CatchJudgementInfo> CreatePlayfield() => new CatchPlayfield();
protected override DrawableHitObject<CatchBaseHit, CatchJudgementInfo> GetVisualRepresentation(CatchBaseHit h) => null;
}

View File

@ -50,6 +50,7 @@
<Compile Include="Beatmaps\CatchBeatmapConverter.cs" />
<Compile Include="Beatmaps\CatchBeatmapProcessor.cs" />
<Compile Include="CatchDifficultyCalculator.cs" />
<Compile Include="CatchScoreProcessor.cs" />
<Compile Include="Judgements\CatchJudgementInfo.cs" />
<Compile Include="Objects\CatchBaseHit.cs" />
<Compile Include="Objects\Drawable\DrawableFruit.cs" />

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

View File

@ -102,8 +102,6 @@ public override IEnumerable<Mod> GetModsFor(ModType type)
public override IEnumerable<KeyCounter> CreateGameplayKeys() => new KeyCounter[] { /* Todo: Should be keymod specific */ };
public override ScoreProcessor CreateScoreProcessor(int hitObjectCount = 0) => null;
public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new ManiaDifficultyCalculator(beatmap);
}
}

View File

@ -0,0 +1,21 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Modes.Mania.Judgements;
using osu.Game.Modes.Mania.Objects;
using osu.Game.Modes.UI;
namespace osu.Game.Modes.Mania
{
internal class ManiaScoreProcessor : ScoreProcessor<ManiaBaseHit, ManiaJudgementInfo>
{
public ManiaScoreProcessor(HitRenderer<ManiaBaseHit, ManiaJudgementInfo> hitRenderer)
: base(hitRenderer)
{
}
protected override void UpdateCalculations(ManiaJudgementInfo newJudgement)
{
}
}
}

View File

@ -20,11 +20,13 @@ public ManiaHitRenderer(WorkingBeatmap beatmap, int columns = 5)
this.columns = columns;
}
public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(this);
protected override IBeatmapConverter<ManiaBaseHit> CreateBeatmapConverter() => new ManiaBeatmapConverter();
protected override IBeatmapProcessor<ManiaBaseHit> CreateBeatmapProcessor() => new ManiaBeatmapProcessor();
protected override Playfield<ManiaBaseHit, ManiaJudgementInfo> CreatePlayfield() => new ManiaPlayfield(columns);
protected override Playfield<ManiaBaseHit, ManiaJudgementInfo> CreatePlayfield() => new ManiaPlayfield(columns);
protected override DrawableHitObject<ManiaBaseHit, ManiaJudgementInfo> GetVisualRepresentation(ManiaBaseHit h) => null;
}

View File

@ -51,6 +51,7 @@
<Compile Include="Beatmaps\ManiaBeatmapProcessor.cs" />
<Compile Include="Judgements\ManiaJudgementInfo.cs" />
<Compile Include="ManiaDifficultyCalculator.cs" />
<Compile Include="ManiaScoreProcessor.cs" />
<Compile Include="Objects\Drawable\DrawableNote.cs" />
<Compile Include="Objects\HoldNote.cs" />
<Compile Include="Objects\ManiaBaseHit.cs" />

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

View File

@ -95,8 +95,6 @@ public override IEnumerable<Mod> GetModsFor(ModType type)
public override FontAwesome Icon => FontAwesome.fa_osu_osu_o;
public override ScoreProcessor CreateScoreProcessor(int hitObjectCount = 0) => new OsuScoreProcessor(hitObjectCount);
public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new OsuDifficultyCalculator(beatmap);
protected override PlayMode PlayMode => PlayMode.Osu;

View File

@ -1,22 +1,23 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Modes.Judgements;
using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Osu.Judgements;
using osu.Game.Modes.Osu.Objects;
using osu.Game.Modes.UI;
namespace osu.Game.Modes.Osu
{
internal class OsuScoreProcessor : ScoreProcessor
internal class OsuScoreProcessor : ScoreProcessor<OsuHitObject, OsuJudgementInfo>
{
public OsuScoreProcessor(int hitObjectCount = 0)
: base(hitObjectCount)
public OsuScoreProcessor(HitRenderer<OsuHitObject, OsuJudgementInfo> hitRenderer)
: base(hitRenderer)
{
Health.Value = 1;
Accuracy.Value = 1;
}
protected override void UpdateCalculations(JudgementInfo judgement)
protected override void UpdateCalculations(OsuJudgementInfo judgement)
{
if (judgement != null)
{
@ -38,7 +39,7 @@ protected override void UpdateCalculations(JudgementInfo judgement)
foreach (var judgementInfo in Judgements)
{
var j = (OsuJudgementInfo)judgementInfo;
var j = judgementInfo;
score += j.ScoreValue;
maxScore += j.MaxScoreValue;
}

View File

@ -19,11 +19,13 @@ public OsuHitRenderer(WorkingBeatmap beatmap)
{
}
public override ScoreProcessor CreateScoreProcessor() => new OsuScoreProcessor(this);
protected override IBeatmapConverter<OsuHitObject> CreateBeatmapConverter() => new OsuBeatmapConverter();
protected override IBeatmapProcessor<OsuHitObject> CreateBeatmapProcessor() => new OsuBeatmapProcessor();
protected override Playfield<OsuHitObject, OsuJudgementInfo> CreatePlayfield() => new OsuPlayfield();
protected override Playfield<OsuHitObject, OsuJudgementInfo> CreatePlayfield() => new OsuPlayfield();
protected override KeyConversionInputManager CreateKeyConversionInputManager() => new OsuKeyConversionInputManager();

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

View File

@ -88,8 +88,6 @@ public override IEnumerable<Mod> GetModsFor(ModType type)
new KeyCounterKeyboard(Key.K)
};
public override ScoreProcessor CreateScoreProcessor(int hitObjectCount = 0) => null;
public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new TaikoDifficultyCalculator(beatmap);
}
}

View File

@ -0,0 +1,21 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Modes.Taiko.Judgements;
using osu.Game.Modes.Taiko.Objects;
using osu.Game.Modes.UI;
namespace osu.Game.Modes.Taiko
{
internal class TaikoScoreProcessor : ScoreProcessor<TaikoBaseHit, TaikoJudgementInfo>
{
public TaikoScoreProcessor(HitRenderer<TaikoBaseHit, TaikoJudgementInfo> hitRenderer)
: base(hitRenderer)
{
}
protected override void UpdateCalculations(TaikoJudgementInfo newJudgement)
{
}
}
}

View File

@ -17,11 +17,13 @@ public TaikoHitRenderer(WorkingBeatmap beatmap)
{
}
public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(this);
protected override IBeatmapConverter<TaikoBaseHit> CreateBeatmapConverter() => new TaikoBeatmapConverter();
protected override IBeatmapProcessor<TaikoBaseHit> CreateBeatmapProcessor() => new TaikoBeatmapProcessor();
protected override Playfield<TaikoBaseHit, TaikoJudgementInfo> CreatePlayfield() => new TaikoPlayfield();
protected override Playfield<TaikoBaseHit, TaikoJudgementInfo> CreatePlayfield() => new TaikoPlayfield();
protected override DrawableHitObject<TaikoBaseHit, TaikoJudgementInfo> GetVisualRepresentation(TaikoBaseHit h) => null;
}

View File

@ -54,6 +54,7 @@
<Compile Include="Objects\Drawable\DrawableTaikoHit.cs" />
<Compile Include="Objects\TaikoBaseHit.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TaikoScoreProcessor.cs" />
<Compile Include="UI\TaikoHitRenderer.cs" />
<Compile Include="UI\TaikoPlayfield.cs" />
<Compile Include="TaikoRuleset.cs" />

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

View File

@ -39,9 +39,8 @@ public Score ReadReplayFile(string replayFilename)
using (SerializationReader sr = new SerializationReader(s))
{
var ruleset = Ruleset.GetRuleset((PlayMode)sr.ReadByte());
var processor = ruleset.CreateScoreProcessor();
score = processor.GetScore();
score = new Score();
/* score.Pass = true;*/
var version = sr.ReadInt32();

View File

@ -29,8 +29,6 @@ public abstract class Ruleset
public abstract IEnumerable<Mod> GetModsFor(ModType type);
public abstract ScoreProcessor CreateScoreProcessor(int hitObjectCount = 0);
public abstract HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap);
public abstract DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap);

View File

@ -5,6 +5,8 @@
using System;
using System.Collections.Generic;
using osu.Game.Modes.Judgements;
using osu.Game.Modes.UI;
using osu.Game.Modes.Objects;
namespace osu.Game.Modes
{
@ -28,36 +30,50 @@ public abstract class ScoreProcessor
public readonly BindableInt Combo = new BindableInt();
/// <summary>
/// Are we allowed to fail?
/// Keeps track of the highest combo ever achieved in this play.
/// This is handled automatically by ScoreProcessor.
/// </summary>
protected bool CanFail => true;
protected bool HasFailed { get; private set; }
public readonly BindableInt HighestCombo = new BindableInt();
/// <summary>
/// Called when we reach a failing health of zero.
/// </summary>
public event Action Failed;
/// <summary>
/// Keeps track of the highest combo ever achieved in this play.
/// This is handled automatically by ScoreProcessor.
/// </summary>
public readonly BindableInt HighestCombo = new BindableInt();
protected void TriggerFailed()
{
Failed?.Invoke();
}
}
public readonly List<JudgementInfo> Judgements;
public abstract class ScoreProcessor<TObject, TJudgement> : ScoreProcessor
where TObject : HitObject
where TJudgement : JudgementInfo
{
/// <summary>
/// All judgements held by this ScoreProcessor.
/// </summary>
protected List<TJudgement> Judgements;
/// <summary>
/// Initializes a new instance of the <see cref="ScoreProcessor"/> class.
/// Are we allowed to fail?
/// </summary>
/// <param name="hitObjectCount">Number of HitObjects. It is used for specifying Judgements collection Capacity</param>
protected ScoreProcessor(int hitObjectCount = 0)
protected bool CanFail => true;
/// <summary>
/// Whether this ScoreProcessor has already triggered the failed event.
/// </summary>
protected bool HasFailed { get; private set; }
protected ScoreProcessor(HitRenderer<TObject, TJudgement> hitRenderer)
{
Combo.ValueChanged += delegate { HighestCombo.Value = Math.Max(HighestCombo.Value, Combo.Value); };
Judgements = new List<JudgementInfo>(hitObjectCount);
Judgements = new List<TJudgement>(hitRenderer.Beatmap.HitObjects.Count);
hitRenderer.OnJudgement += addJudgement;
}
public void AddJudgement(JudgementInfo judgement)
private void addJudgement(TJudgement judgement)
{
Judgements.Add(judgement);
@ -67,7 +83,7 @@ public void AddJudgement(JudgementInfo judgement)
if (Health.Value == Health.MinValue && !HasFailed)
{
HasFailed = true;
Failed?.Invoke();
TriggerFailed();
}
}
@ -75,6 +91,6 @@ public void AddJudgement(JudgementInfo judgement)
/// Update any values that potentially need post-processing on a judgement change.
/// </summary>
/// <param name="newJudgement">A new JudgementInfo that triggered this calculation. May be null.</param>
protected abstract void UpdateCalculations(JudgementInfo newJudgement);
protected abstract void UpdateCalculations(TJudgement newJudgement);
}
}

View File

@ -25,14 +25,6 @@ namespace osu.Game.Modes.UI
/// </summary>
public abstract class HitRenderer : Container
{
/// <summary>
/// The event that's fired when a hit object is judged.
/// </summary>
public event Action<JudgementInfo> OnJudgement;
/// <summary>
/// The event that's fired when all hit objects have been judged.
/// </summary>
public event Action OnAllJudged;
/// <summary>
@ -57,17 +49,16 @@ protected HitRenderer()
}
/// <summary>
/// Triggers a judgement for further processing.
/// Checks whether all HitObjects have been judged, and invokes OnAllJudged.
/// </summary>
/// <param name="j">The judgement to trigger.</param>
protected void TriggerOnJudgement(JudgementInfo j)
protected void CheckAllJudged()
{
OnJudgement?.Invoke(j);
if (AllObjectsJudged)
OnAllJudged?.Invoke();
}
public abstract ScoreProcessor CreateScoreProcessor();
/// <summary>
/// Creates a key conversion input manager.
/// </summary>
@ -141,6 +132,8 @@ public abstract class HitRenderer<TObject, TJudgement> : HitRenderer<TObject>
where TObject : HitObject
where TJudgement : JudgementInfo
{
public event Action<TJudgement> OnJudgement;
protected override Container<Drawable> Content => content;
protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result.HasValue);
@ -197,8 +190,10 @@ private void loadObjects()
/// <param name="judgedObject">The object that Judgement has been updated for.</param>
private void onJudgement(DrawableHitObject<TObject, TJudgement> judgedObject)
{
TriggerOnJudgement(judgedObject.Judgement);
OnJudgement?.Invoke(judgedObject.Judgement);
Playfield.OnJudgement(judgedObject);
CheckAllJudged();
}
/// <summary>

View File

@ -108,10 +108,13 @@ private void load(AudioManager audio, BeatmapDatabase beatmaps, OsuConfigManager
});
ruleset = Ruleset.GetRuleset(Beatmap.PlayMode);
hitRenderer = ruleset.CreateHitRendererWith(Beatmap);
scoreProcessor = hitRenderer.CreateScoreProcessor();
hudOverlay = new StandardHudOverlay();
hudOverlay.KeyCounter.Add(ruleset.CreateGameplayKeys());
hudOverlay.BindProcessor(scoreProcessor = ruleset.CreateScoreProcessor(beatmap.HitObjects.Count));
hudOverlay.BindProcessor(scoreProcessor);
pauseOverlay = new PauseOverlay
{
@ -125,7 +128,6 @@ private void load(AudioManager audio, BeatmapDatabase beatmaps, OsuConfigManager
OnQuit = Exit
};
hitRenderer = ruleset.CreateHitRendererWith(Beatmap);
if (ReplayInputHandler != null)
hitRenderer.InputManager.ReplayInputHandler = ReplayInputHandler;
@ -133,7 +135,6 @@ private void load(AudioManager audio, BeatmapDatabase beatmaps, OsuConfigManager
hudOverlay.BindHitRenderer(hitRenderer);
//bind HitRenderer to ScoreProcessor and ourselves (for a pass situation)
hitRenderer.OnJudgement += scoreProcessor.AddJudgement;
hitRenderer.OnAllJudged += onPass;
//bind ScoreProcessor to ourselves (for a fail situation)

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE