Merge branch 'master' into fix-mod-read-setting

This commit is contained in:
Dan Balasescu
2019-12-27 17:45:24 +09:00
committed by GitHub
23 changed files with 456 additions and 293 deletions

View File

@ -11,6 +11,12 @@ namespace osu.Game.Rulesets.Judgements
/// </summary>
public class Judgement
{
/// <summary>
/// The default health increase for a maximum judgement, as a proportion of total health.
/// By default, each maximum judgement restores 5% of total health.
/// </summary>
protected const double DEFAULT_MAX_HEALTH_INCREASE = 0.05;
/// <summary>
/// The maximum <see cref="HitResult"/> that can be achieved.
/// </summary>
@ -55,7 +61,32 @@ namespace osu.Game.Rulesets.Judgements
/// </summary>
/// <param name="result">The <see cref="HitResult"/> to find the numeric health increase for.</param>
/// <returns>The numeric health increase of <paramref name="result"/>.</returns>
protected virtual double HealthIncreaseFor(HitResult result) => 0;
protected virtual double HealthIncreaseFor(HitResult result)
{
switch (result)
{
case HitResult.Miss:
return -DEFAULT_MAX_HEALTH_INCREASE;
case HitResult.Meh:
return -DEFAULT_MAX_HEALTH_INCREASE * 0.05;
case HitResult.Ok:
return -DEFAULT_MAX_HEALTH_INCREASE * 0.01;
case HitResult.Good:
return DEFAULT_MAX_HEALTH_INCREASE * 0.3;
case HitResult.Great:
return DEFAULT_MAX_HEALTH_INCREASE;
case HitResult.Perfect:
return DEFAULT_MAX_HEALTH_INCREASE * 1.05;
default:
return 0;
}
}
/// <summary>
/// Retrieves the numeric health increase of a <see cref="JudgementResult"/>.

View File

@ -71,16 +71,16 @@ namespace osu.Game.Rulesets
public abstract DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null);
/// <summary>
/// Creates a <see cref="ScoreProcessor"/> for a beatmap converted to this ruleset.
/// Creates a <see cref="ScoreProcessor"/> for this <see cref="Ruleset"/>.
/// </summary>
/// <returns>The score processor.</returns>
public virtual ScoreProcessor CreateScoreProcessor(IBeatmap beatmap) => new ScoreProcessor(beatmap);
public virtual ScoreProcessor CreateScoreProcessor() => new ScoreProcessor();
/// <summary>
/// Creates a <see cref="HealthProcessor"/> for a beatmap converted to this ruleset.
/// Creates a <see cref="HealthProcessor"/> for this <see cref="Ruleset"/>.
/// </summary>
/// <returns>The health processor.</returns>
public virtual HealthProcessor CreateHealthProcessor(IBeatmap beatmap) => new HealthProcessor(beatmap);
public virtual HealthProcessor CreateHealthProcessor(double drainStartTime) => new DrainingHealthProcessor(drainStartTime);
/// <summary>
/// Creates a <see cref="IBeatmapConverter"/> to convert a <see cref="IBeatmap"/> to one that is applicable for this <see cref="Ruleset"/>.

View File

@ -0,0 +1,32 @@
// 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.
namespace osu.Game.Rulesets.Scoring
{
/// <summary>
/// A <see cref="HealthProcessor"/> that accumulates health and causes a fail if the final health
/// is less than a value required to pass the beatmap.
/// </summary>
public class AccumulatingHealthProcessor : HealthProcessor
{
protected override bool DefaultFailCondition => JudgedHits == MaxHits && Health.Value < requiredHealth;
private readonly double requiredHealth;
/// <summary>
/// Creates a new <see cref="AccumulatingHealthProcessor"/>.
/// </summary>
/// <param name="requiredHealth">The minimum amount of health required to beatmap.</param>
public AccumulatingHealthProcessor(double requiredHealth)
{
this.requiredHealth = requiredHealth;
}
protected override void Reset(bool storeResults)
{
base.Reset(storeResults);
Health.Value = 0;
}
}
}

View File

@ -0,0 +1,157 @@
// 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 System;
using System.Collections.Generic;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
namespace osu.Game.Rulesets.Scoring
{
/// <summary>
/// A <see cref="HealthProcessor"/> which continuously drains health.<br />
/// At HP=0, the minimum health reached for a perfect play is 95%.<br />
/// At HP=5, the minimum health reached for a perfect play is 70%.<br />
/// At HP=10, the minimum health reached for a perfect play is 30%.
/// </summary>
public class DrainingHealthProcessor : HealthProcessor
{
/// <summary>
/// A reasonable allowable error for the minimum health offset from <see cref="targetMinimumHealth"/>. A 1% error is unnoticeable.
/// </summary>
private const double minimum_health_error = 0.01;
/// <summary>
/// The minimum health target at an HP drain rate of 0.
/// </summary>
private const double min_health_target = 0.95;
/// <summary>
/// The minimum health target at an HP drain rate of 5.
/// </summary>
private const double mid_health_target = 0.70;
/// <summary>
/// The minimum health target at an HP drain rate of 10.
/// </summary>
private const double max_health_target = 0.30;
private IBeatmap beatmap;
private double gameplayEndTime;
private readonly double drainStartTime;
private readonly List<(double time, double health)> healthIncreases = new List<(double, double)>();
private double targetMinimumHealth;
private double drainRate = 1;
/// <summary>
/// Creates a new <see cref="DrainingHealthProcessor"/>.
/// </summary>
/// <param name="drainStartTime">The time after which draining should begin.</param>
public DrainingHealthProcessor(double drainStartTime)
{
this.drainStartTime = drainStartTime;
}
protected override void Update()
{
base.Update();
if (!IsBreakTime.Value)
{
// When jumping in and out of gameplay time within a single frame, health should only be drained for the period within the gameplay time
double lastGameplayTime = Math.Clamp(Time.Current - Time.Elapsed, drainStartTime, gameplayEndTime);
double currentGameplayTime = Math.Clamp(Time.Current, drainStartTime, gameplayEndTime);
Health.Value -= drainRate * (currentGameplayTime - lastGameplayTime);
}
}
public override void ApplyBeatmap(IBeatmap beatmap)
{
this.beatmap = beatmap;
if (beatmap.HitObjects.Count > 0)
gameplayEndTime = beatmap.HitObjects[^1].GetEndTime();
targetMinimumHealth = BeatmapDifficulty.DifficultyRange(beatmap.BeatmapInfo.BaseDifficulty.DrainRate, min_health_target, mid_health_target, max_health_target);
base.ApplyBeatmap(beatmap);
}
protected override void ApplyResultInternal(JudgementResult result)
{
base.ApplyResultInternal(result);
healthIncreases.Add((result.HitObject.GetEndTime() + result.TimeOffset, GetHealthIncreaseFor(result)));
}
protected override void Reset(bool storeResults)
{
base.Reset(storeResults);
drainRate = 1;
if (storeResults)
drainRate = computeDrainRate();
healthIncreases.Clear();
}
private double computeDrainRate()
{
if (healthIncreases.Count == 0)
return 0;
int adjustment = 1;
double result = 1;
// Although we expect the following loop to converge within 30 iterations (health within 1/2^31 accuracy of the target),
// we'll still keep a safety measure to avoid infinite loops by detecting overflows.
while (adjustment > 0)
{
double currentHealth = 1;
double lowestHealth = 1;
int currentBreak = -1;
for (int i = 0; i < healthIncreases.Count; i++)
{
double currentTime = healthIncreases[i].time;
double lastTime = i > 0 ? healthIncreases[i - 1].time : drainStartTime;
// Subtract any break time from the duration since the last object
if (beatmap.Breaks.Count > 0)
{
// Advance the last break occuring before the current time
while (currentBreak + 1 < beatmap.Breaks.Count && beatmap.Breaks[currentBreak + 1].EndTime < currentTime)
currentBreak++;
if (currentBreak >= 0)
lastTime = Math.Max(lastTime, beatmap.Breaks[currentBreak].EndTime);
}
// Apply health adjustments
currentHealth -= (healthIncreases[i].time - lastTime) * result;
lowestHealth = Math.Min(lowestHealth, currentHealth);
currentHealth = Math.Min(1, currentHealth + healthIncreases[i].health);
// Common scenario for when the drain rate is definitely too harsh
if (lowestHealth < 0)
break;
}
// Stop if the resulting health is within a reasonable offset from the target
if (Math.Abs(lowestHealth - targetMinimumHealth) <= minimum_health_error)
break;
// This effectively works like a binary search - each iteration the search space moves closer to the target, but may exceed it.
adjustment *= 2;
result += 1.0 / adjustment * Math.Sign(lowestHealth - targetMinimumHealth);
}
return result;
}
}
}

View File

@ -4,12 +4,11 @@
using System;
using osu.Framework.Bindables;
using osu.Framework.MathUtils;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Judgements;
namespace osu.Game.Rulesets.Scoring
{
public class HealthProcessor : JudgementProcessor
public abstract class HealthProcessor : JudgementProcessor
{
/// <summary>
/// Invoked when the <see cref="ScoreProcessor"/> is in a failed state.
@ -27,16 +26,16 @@ namespace osu.Game.Rulesets.Scoring
/// </summary>
public readonly BindableDouble Health = new BindableDouble(1) { MinValue = 0, MaxValue = 1 };
/// <summary>
/// Whether gameplay is currently in a break.
/// </summary>
public readonly IBindable<bool> IsBreakTime = new Bindable<bool>();
/// <summary>
/// Whether this ScoreProcessor has already triggered the failed state.
/// </summary>
public bool HasFailed { get; private set; }
public HealthProcessor(IBeatmap beatmap)
: base(beatmap)
{
}
protected override void ApplyResultInternal(JudgementResult result)
{
result.HealthAtJudgement = Health.Value;
@ -45,7 +44,7 @@ namespace osu.Game.Rulesets.Scoring
if (HasFailed)
return;
Health.Value += HealthAdjustmentFactorFor(result) * result.Judgement.HealthIncreaseFor(result);
Health.Value += GetHealthIncreaseFor(result);
if (!DefaultFailCondition && FailConditions?.Invoke(this, result) != true)
return;
@ -62,11 +61,11 @@ namespace osu.Game.Rulesets.Scoring
}
/// <summary>
/// An adjustment factor which is multiplied into the health increase provided by a <see cref="JudgementResult"/>.
/// Retrieves the health increase for a <see cref="JudgementResult"/>.
/// </summary>
/// <param name="result">The <see cref="JudgementResult"/> for which the adjustment should apply.</param>
/// <returns>The adjustment factor.</returns>
protected virtual double HealthAdjustmentFactorFor(JudgementResult result) => 1;
/// <param name="result">The <see cref="JudgementResult"/>.</param>
/// <returns>The health increase.</returns>
protected virtual double GetHealthIncreaseFor(JudgementResult result) => result.Judgement.HealthIncreaseFor(result);
/// <summary>
/// The default conditions for failing.

View File

@ -3,13 +3,14 @@
using System;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
namespace osu.Game.Rulesets.Scoring
{
public abstract class JudgementProcessor
public abstract class JudgementProcessor : Component
{
/// <summary>
/// Invoked when all <see cref="HitObject"/>s have been judged by this <see cref="JudgementProcessor"/>.
@ -36,23 +37,17 @@ namespace osu.Game.Rulesets.Scoring
/// </summary>
public bool HasCompleted => JudgedHits == MaxHits;
protected JudgementProcessor(IBeatmap beatmap)
/// <summary>
/// Applies a <see cref="IBeatmap"/> to this <see cref="ScoreProcessor"/>.
/// </summary>
/// <param name="beatmap">The <see cref="IBeatmap"/> to read properties from.</param>
public virtual void ApplyBeatmap(IBeatmap beatmap)
{
ApplyBeatmap(beatmap);
Reset(false);
SimulateAutoplay(beatmap);
Reset(true);
}
/// <summary>
/// Applies any properties of the <see cref="IBeatmap"/> which affect scoring to this <see cref="ScoreProcessor"/>.
/// </summary>
/// <param name="beatmap">The <see cref="IBeatmap"/> to read properties from.</param>
protected virtual void ApplyBeatmap(IBeatmap beatmap)
{
}
/// <summary>
/// Applies the score change of a <see cref="JudgementResult"/> to this <see cref="ScoreProcessor"/>.
/// </summary>
@ -138,7 +133,6 @@ namespace osu.Game.Rulesets.Scoring
throw new InvalidOperationException($"{GetType().ReadableName()} must provide a {nameof(JudgementResult)} through {nameof(CreateResult)}.");
result.Type = judgement.MaxResult;
ApplyResult(result);
}
}

View File

@ -7,7 +7,6 @@ using System.Diagnostics;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
@ -64,15 +63,9 @@ namespace osu.Game.Rulesets.Scoring
private double scoreMultiplier = 1;
public ScoreProcessor(IBeatmap beatmap)
: base(beatmap)
public ScoreProcessor()
{
Debug.Assert(base_portion + combo_portion == 1.0);
}
protected override void ApplyBeatmap(IBeatmap beatmap)
{
base.ApplyBeatmap(beatmap);
Combo.ValueChanged += combo => HighestCombo.Value = Math.Max(HighestCombo.Value, combo.NewValue);
Accuracy.ValueChanged += accuracy =>
@ -82,12 +75,6 @@ namespace osu.Game.Rulesets.Scoring
Rank.Value = mod.AdjustRank(Rank.Value, accuracy.NewValue);
};
if (maxBaseScore == 0 || maxHighestCombo == 0)
{
Mode.Value = ScoringMode.Classic;
Mode.Disabled = true;
}
Mode.ValueChanged += _ => updateScore();
Mods.ValueChanged += mods =>
{
@ -225,6 +212,12 @@ namespace osu.Game.Rulesets.Scoring
{
maxHighestCombo = HighestCombo.Value;
maxBaseScore = baseScore;
if (maxBaseScore == 0 || maxHighestCombo == 0)
{
Mode.Value = ScoringMode.Classic;
Mode.Disabled = true;
}
}
baseScore = 0;

View File

@ -72,10 +72,9 @@ namespace osu.Game.Rulesets.UI
/// </summary>
public override Playfield Playfield => playfield.Value;
/// <summary>
/// Place to put drawables above hit objects but below UI.
/// </summary>
public Container Overlays { get; private set; }
private Container overlays;
public override Container Overlays => overlays;
public override GameplayClock FrameStableClock => frameStabilityContainer.GameplayClock;
@ -185,12 +184,15 @@ namespace osu.Game.Rulesets.UI
frameStabilityContainer = new FrameStabilityContainer(GameplayStartTime)
{
FrameStablePlayback = FrameStablePlayback,
Child = KeyBindingInputManager
.WithChild(CreatePlayfieldAdjustmentContainer()
.WithChild(Playfield)
)
Children = new Drawable[]
{
KeyBindingInputManager
.WithChild(CreatePlayfieldAdjustmentContainer()
.WithChild(Playfield)
),
overlays = new Container { RelativeSizeAxes = Axes.Both }
}
},
Overlays = new Container { RelativeSizeAxes = Axes.Both }
};
if ((ResumeOverlay = CreateResumeOverlay()) != null)
@ -385,6 +387,11 @@ namespace osu.Game.Rulesets.UI
/// </summary>
public abstract Playfield Playfield { get; }
/// <summary>
/// Place to put drawables above hit objects but below UI.
/// </summary>
public abstract Container Overlays { get; }
/// <summary>
/// The frame-stable clock which is being used for playfield display.
/// </summary>

View File

@ -131,10 +131,12 @@ namespace osu.Game.Screens.Play
DrawableRuleset = ruleset.CreateDrawableRulesetWith(playableBeatmap, Mods.Value);
ScoreProcessor = ruleset.CreateScoreProcessor(playableBeatmap);
ScoreProcessor = ruleset.CreateScoreProcessor();
ScoreProcessor.ApplyBeatmap(playableBeatmap);
ScoreProcessor.Mods.BindTo(Mods);
HealthProcessor = ruleset.CreateHealthProcessor(playableBeatmap);
HealthProcessor = ruleset.CreateHealthProcessor(playableBeatmap.HitObjects[0].StartTime);
HealthProcessor.ApplyBeatmap(playableBeatmap);
if (!ScoreProcessor.Mode.Disabled)
config.BindWith(OsuSetting.ScoreDisplayMode, ScoreProcessor.Mode);
@ -206,12 +208,6 @@ namespace osu.Game.Screens.Play
{
target.AddRange(new[]
{
BreakOverlay = new BreakOverlay(working.Beatmap.BeatmapInfo.LetterboxInBreaks, DrawableRuleset.GameplayStartTime, ScoreProcessor)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Breaks = working.Beatmap.Breaks
},
// display the cursor above some HUD elements.
DrawableRuleset.Cursor?.CreateProxy() ?? new Container(),
DrawableRuleset.ResumeOverlay?.CreateProxy() ?? new Container(),
@ -266,6 +262,18 @@ namespace osu.Game.Screens.Play
},
failAnimation = new FailAnimation(DrawableRuleset) { OnComplete = onFailComplete, }
});
DrawableRuleset.Overlays.Add(BreakOverlay = new BreakOverlay(working.Beatmap.BeatmapInfo.LetterboxInBreaks, DrawableRuleset.GameplayStartTime, ScoreProcessor)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Breaks = working.Beatmap.Breaks
});
DrawableRuleset.Overlays.Add(ScoreProcessor);
DrawableRuleset.Overlays.Add(HealthProcessor);
HealthProcessor.IsBreakTime.BindTo(BreakOverlay.IsBreakTime);
}
private void updatePauseOnFocusLostState() =>