mirror of
https://github.com/osukey/osukey.git
synced 2025-06-25 05:07:59 +09:00
Merge pull request #492 from smoogipooo/scoreprocessor_computation
Scoreprocessor computation
This commit is contained in:
commit
049af04a92
@ -39,7 +39,7 @@ namespace osu.Game.Database
|
|||||||
using (SerializationReader sr = new SerializationReader(s))
|
using (SerializationReader sr = new SerializationReader(s))
|
||||||
{
|
{
|
||||||
var ruleset = Ruleset.GetRuleset((PlayMode)sr.ReadByte());
|
var ruleset = Ruleset.GetRuleset((PlayMode)sr.ReadByte());
|
||||||
score = ruleset.CreateScoreProcessor().GetScore();
|
score = ruleset.CreateScoreProcessor().CreateScore();
|
||||||
|
|
||||||
/* score.Pass = true;*/
|
/* score.Pass = true;*/
|
||||||
var version = sr.ReadInt32();
|
var version = sr.ReadInt32();
|
||||||
|
@ -7,13 +7,14 @@ using System.Collections.Generic;
|
|||||||
using osu.Game.Modes.Judgements;
|
using osu.Game.Modes.Judgements;
|
||||||
using osu.Game.Modes.UI;
|
using osu.Game.Modes.UI;
|
||||||
using osu.Game.Modes.Objects;
|
using osu.Game.Modes.Objects;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
|
||||||
namespace osu.Game.Modes
|
namespace osu.Game.Modes
|
||||||
{
|
{
|
||||||
public abstract class ScoreProcessor
|
public abstract class ScoreProcessor
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked when the score is in a failing state.
|
/// Invoked when the ScoreProcessor is in a failed state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action Failed;
|
public event Action Failed;
|
||||||
|
|
||||||
@ -42,7 +43,28 @@ namespace osu.Game.Modes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly BindableInt HighestCombo = new BindableInt();
|
public readonly BindableInt HighestCombo = new BindableInt();
|
||||||
|
|
||||||
public virtual Score GetScore() => new Score
|
/// <summary>
|
||||||
|
/// Whether the score is in a failed state.
|
||||||
|
/// </summary>
|
||||||
|
public virtual bool HasFailed => false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether this ScoreProcessor has already triggered the failed state.
|
||||||
|
/// </summary>
|
||||||
|
private bool alreadyFailed;
|
||||||
|
|
||||||
|
protected ScoreProcessor()
|
||||||
|
{
|
||||||
|
Combo.ValueChanged += delegate { HighestCombo.Value = Math.Max(HighestCombo.Value, Combo.Value); };
|
||||||
|
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a Score applicable to the game mode in which this ScoreProcessor resides.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The Score.</returns>
|
||||||
|
public virtual Score CreateScore() => new Score
|
||||||
{
|
{
|
||||||
TotalScore = TotalScore,
|
TotalScore = TotalScore,
|
||||||
Combo = Combo,
|
Combo = Combo,
|
||||||
@ -52,16 +74,31 @@ namespace osu.Game.Modes
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the score is in a failing state.
|
/// Resets this ScoreProcessor to a default state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Whether the score is in a failing state.</returns>
|
protected virtual void Reset()
|
||||||
public abstract bool CheckFailed();
|
{
|
||||||
|
TotalScore.Value = 0;
|
||||||
|
Accuracy.Value = 0;
|
||||||
|
Health.Value = 0;
|
||||||
|
Combo.Value = 0;
|
||||||
|
HighestCombo.Value = 0;
|
||||||
|
|
||||||
|
alreadyFailed = false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Notifies subscribers that the score is in a failed state.
|
/// Checks if the score is in a failed state and notifies subscribers.
|
||||||
|
/// <para>
|
||||||
|
/// This can only ever notify subscribers once.
|
||||||
|
/// </para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected void TriggerFailed()
|
protected void UpdateFailed()
|
||||||
{
|
{
|
||||||
|
if (alreadyFailed || !HasFailed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
alreadyFailed = true;
|
||||||
Failed?.Invoke();
|
Failed?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,29 +112,28 @@ namespace osu.Game.Modes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly List<TJudgement> Judgements = new List<TJudgement>();
|
protected readonly List<TJudgement> Judgements = new List<TJudgement>();
|
||||||
|
|
||||||
/// <summary>
|
public override bool HasFailed => Health.Value == Health.MinValue;
|
||||||
/// Whether the score is in a failable state.
|
|
||||||
/// </summary>
|
|
||||||
protected virtual bool IsFailable => Health.Value == Health.MinValue;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether this ScoreProcessor has already failed.
|
|
||||||
/// </summary>
|
|
||||||
private bool hasFailed;
|
|
||||||
|
|
||||||
protected ScoreProcessor()
|
protected ScoreProcessor()
|
||||||
{
|
{
|
||||||
Combo.ValueChanged += delegate { HighestCombo.Value = Math.Max(HighestCombo.Value, Combo.Value); };
|
}
|
||||||
|
|
||||||
|
protected ScoreProcessor(HitRenderer<TObject, TJudgement> hitRenderer)
|
||||||
|
{
|
||||||
|
Judgements.Capacity = hitRenderer.Beatmap.HitObjects.Count;
|
||||||
|
|
||||||
|
hitRenderer.OnJudgement += addJudgement;
|
||||||
|
|
||||||
|
ComputeTargets(hitRenderer.Beatmap);
|
||||||
|
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ScoreProcessor(HitRenderer<TObject, TJudgement> hitRenderer)
|
/// <summary>
|
||||||
: this()
|
/// Computes target scoring values for this ScoreProcessor. This is equivalent to performing an auto-play of the score to find the values.
|
||||||
{
|
/// </summary>
|
||||||
Judgements.Capacity = hitRenderer.Beatmap.HitObjects.Count;
|
/// <param name="beatmap">The Beatmap containing the objects that will be judged by this ScoreProcessor.</param>
|
||||||
hitRenderer.OnJudgement += addJudgement;
|
protected virtual void ComputeTargets(Beatmap<TObject> beatmap) { }
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a judgement to this ScoreProcessor.
|
/// Adds a judgement to this ScoreProcessor.
|
||||||
@ -111,33 +147,12 @@ namespace osu.Game.Modes
|
|||||||
|
|
||||||
judgement.ComboAtHit = (ulong)Combo.Value;
|
judgement.ComboAtHit = (ulong)Combo.Value;
|
||||||
|
|
||||||
CheckFailed();
|
UpdateFailed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CheckFailed()
|
protected override void Reset()
|
||||||
{
|
|
||||||
if (!hasFailed && IsFailable)
|
|
||||||
{
|
|
||||||
hasFailed = true;
|
|
||||||
TriggerFailed();
|
|
||||||
}
|
|
||||||
|
|
||||||
return hasFailed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Resets this ScoreProcessor to a stale state.
|
|
||||||
/// </summary>
|
|
||||||
protected virtual void Reset()
|
|
||||||
{
|
{
|
||||||
Judgements.Clear();
|
Judgements.Clear();
|
||||||
|
|
||||||
hasFailed = false;
|
|
||||||
TotalScore.Value = 0;
|
|
||||||
Accuracy.Value = 0;
|
|
||||||
Health.Value = 0;
|
|
||||||
Combo.Value = 0;
|
|
||||||
HighestCombo.Value = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -146,4 +161,4 @@ namespace osu.Game.Modes
|
|||||||
/// <param name="newJudgement">A new JudgementInfo that triggered this calculation. May be null.</param>
|
/// <param name="newJudgement">A new JudgementInfo that triggered this calculation. May be null.</param>
|
||||||
protected abstract void UpdateCalculations(TJudgement newJudgement);
|
protected abstract void UpdateCalculations(TJudgement newJudgement);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,6 +25,9 @@ namespace osu.Game.Modes.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class HitRenderer : Container
|
public abstract class HitRenderer : Container
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Invoked when all the judgeable HitObjects have been judged.
|
||||||
|
/// </summary>
|
||||||
public event Action OnAllJudged;
|
public event Action OnAllJudged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -190,9 +193,10 @@ namespace osu.Game.Modes.UI
|
|||||||
/// <param name="judgedObject">The object that Judgement has been updated for.</param>
|
/// <param name="judgedObject">The object that Judgement has been updated for.</param>
|
||||||
private void onJudgement(DrawableHitObject<TObject, TJudgement> judgedObject)
|
private void onJudgement(DrawableHitObject<TObject, TJudgement> judgedObject)
|
||||||
{
|
{
|
||||||
OnJudgement?.Invoke(judgedObject.Judgement);
|
|
||||||
Playfield.OnJudgement(judgedObject);
|
Playfield.OnJudgement(judgedObject);
|
||||||
|
|
||||||
|
OnJudgement?.Invoke(judgedObject.Judgement);
|
||||||
|
|
||||||
CheckAllJudged();
|
CheckAllJudged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,14 +239,9 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
private void onCompletion()
|
private void onCompletion()
|
||||||
{
|
{
|
||||||
// Force a final check to see if the player has failed
|
// Only show the completion screen if the player hasn't failed
|
||||||
// Some game modes (e.g. taiko) fail at the end of the map
|
if (scoreProcessor.HasFailed)
|
||||||
if (scoreProcessor.CheckFailed())
|
|
||||||
{
|
|
||||||
// If failed, onFail will be invoked which will push a new screen.
|
|
||||||
// Let's not push the completion screen in this case
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
Delay(1000);
|
Delay(1000);
|
||||||
Schedule(delegate
|
Schedule(delegate
|
||||||
@ -254,7 +249,7 @@ namespace osu.Game.Screens.Play
|
|||||||
ValidForResume = false;
|
ValidForResume = false;
|
||||||
Push(new Results
|
Push(new Results
|
||||||
{
|
{
|
||||||
Score = scoreProcessor.GetScore()
|
Score = scoreProcessor.CreateScore()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user