1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 16:27:26 +08:00

Merge branch 'master' into song-select-loading-reoptimisation

This commit is contained in:
Dan Balasescu 2017-03-18 01:25:22 +09:00 committed by GitHub
commit cd30958086
11 changed files with 117 additions and 92 deletions

View File

@ -8,11 +8,6 @@ namespace osu.Game.Modes.Osu.Beatmaps
{ {
internal class OsuBeatmapProcessor : IBeatmapProcessor<OsuHitObject> internal class OsuBeatmapProcessor : IBeatmapProcessor<OsuHitObject>
{ {
public void SetDefaults(OsuHitObject hitObject, Beatmap<OsuHitObject> beatmap)
{
hitObject.SetDefaultsFromBeatmap(beatmap);
}
public void PostProcess(Beatmap<OsuHitObject> beatmap) public void PostProcess(Beatmap<OsuHitObject> beatmap)
{ {
if (beatmap.ComboColors.Count == 0) if (beatmap.ComboColors.Count == 0)

View File

@ -3,10 +3,11 @@
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using OpenTK; using OpenTK;
using osu.Game.Beatmaps;
using osu.Game.Modes.Osu.Objects.Drawables; using osu.Game.Modes.Osu.Objects.Drawables;
using osu.Game.Modes.Objects.Types; using osu.Game.Modes.Objects.Types;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Game.Beatmaps.Timing;
using osu.Game.Database;
namespace osu.Game.Modes.Osu.Objects namespace osu.Game.Modes.Osu.Objects
{ {
@ -67,9 +68,11 @@ namespace osu.Game.Modes.Osu.Objects
return OsuScoreResult.Miss; return OsuScoreResult.Miss;
} }
public virtual void SetDefaultsFromBeatmap(Beatmap<OsuHitObject> beatmap) public override void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty)
{ {
Scale = (1.0f - 0.7f * (beatmap.BeatmapInfo.Difficulty.CircleSize - 5) / 5) / 2; base.ApplyDefaults(timing, difficulty);
Scale = (1.0f - 0.7f * (difficulty.CircleSize - 5) / 5) / 2;
} }
} }
} }

View File

@ -2,13 +2,13 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK; using OpenTK;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Samples; using osu.Game.Beatmaps.Samples;
using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Timing;
using osu.Game.Modes.Objects.Types; using osu.Game.Modes.Objects.Types;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using osu.Game.Database;
namespace osu.Game.Modes.Osu.Objects namespace osu.Game.Modes.Osu.Objects
{ {
@ -47,19 +47,17 @@ namespace osu.Game.Modes.Osu.Objects
public double Velocity; public double Velocity;
public double TickDistance; public double TickDistance;
public override void SetDefaultsFromBeatmap(Beatmap<OsuHitObject> beatmap) public override void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty)
{ {
base.SetDefaultsFromBeatmap(beatmap); base.ApplyDefaults(timing, difficulty);
var baseDifficulty = beatmap.BeatmapInfo.Difficulty;
ControlPoint overridePoint; ControlPoint overridePoint;
ControlPoint timingPoint = beatmap.TimingInfo.TimingPointAt(StartTime, out overridePoint); ControlPoint timingPoint = timing.TimingPointAt(StartTime, out overridePoint);
var velocityAdjustment = overridePoint?.VelocityAdjustment ?? 1; var velocityAdjustment = overridePoint?.VelocityAdjustment ?? 1;
var baseVelocity = 100 * baseDifficulty.SliderMultiplier / velocityAdjustment; var baseVelocity = 100 * difficulty.SliderMultiplier / velocityAdjustment;
Velocity = baseVelocity / timingPoint.BeatLength; Velocity = baseVelocity / timingPoint.BeatLength;
TickDistance = baseVelocity / baseDifficulty.SliderTickRate; TickDistance = baseVelocity / difficulty.SliderTickRate;
} }
public IEnumerable<SliderTick> Ticks public IEnumerable<SliderTick> Ticks

View File

@ -197,7 +197,7 @@ namespace osu.Game.Beatmaps.Formats
if (split.Length > 2) if (split.Length > 2)
{ {
//int kiaiFlags = split.Length > 7 ? Convert.ToInt32(split[7], NumberFormatInfo.InvariantInfo) : 0; int effectFlags = split.Length > 7 ? Convert.ToInt32(split[7], NumberFormatInfo.InvariantInfo) : 0;
double beatLength = double.Parse(split[1].Trim(), NumberFormatInfo.InvariantInfo); double beatLength = double.Parse(split[1].Trim(), NumberFormatInfo.InvariantInfo);
cp = new ControlPoint cp = new ControlPoint
{ {
@ -205,6 +205,8 @@ namespace osu.Game.Beatmaps.Formats
BeatLength = beatLength > 0 ? beatLength : 0, BeatLength = beatLength > 0 ? beatLength : 0,
VelocityAdjustment = beatLength < 0 ? -beatLength / 100.0 : 1, VelocityAdjustment = beatLength < 0 ? -beatLength / 100.0 : 1,
TimingChange = split.Length <= 6 || split[6][0] == '1', TimingChange = split.Length <= 6 || split[6][0] == '1',
KiaiMode = (effectFlags & 1) > 0,
OmitFirstBarLine = (effectFlags & 8) > 0
}; };
} }

View File

@ -8,17 +8,10 @@ namespace osu.Game.Beatmaps
/// <summary> /// <summary>
/// Processes a post-converted Beatmap. /// Processes a post-converted Beatmap.
/// </summary> /// </summary>
/// <typeparam name="T">The type of HitObject contained in the Beatmap.</typeparam> /// <typeparam name="TObject">The type of HitObject contained in the Beatmap.</typeparam>
public interface IBeatmapProcessor<T> public interface IBeatmapProcessor<TObject>
where T : HitObject where TObject : HitObject
{ {
/// <summary>
/// Sets default values for a HitObject.
/// </summary>
/// <param name="hitObject">The HitObject to set default values for.</param>
/// <param name="beatmap">The Beatmap to extract the default values from.</param>
void SetDefaults(T hitObject, Beatmap<T> beatmap);
/// <summary> /// <summary>
/// Post-processes a Beatmap to add mode-specific components that aren't added during conversion. /// Post-processes a Beatmap to add mode-specific components that aren't added during conversion.
/// <para> /// <para>
@ -26,6 +19,6 @@ namespace osu.Game.Beatmaps
/// </para> /// </para>
/// </summary> /// </summary>
/// <param name="beatmap">The Beatmap to process.</param> /// <param name="beatmap">The Beatmap to process.</param>
void PostProcess(Beatmap<T> beatmap); void PostProcess(Beatmap<TObject> beatmap);
} }
} }

View File

@ -16,6 +16,7 @@ namespace osu.Game.Beatmaps.Timing
public double VelocityAdjustment; public double VelocityAdjustment;
public bool TimingChange; public bool TimingChange;
public bool KiaiMode; public bool KiaiMode;
public bool OmitFirstBarLine;
} }

View File

@ -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();

View File

@ -2,6 +2,8 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps.Samples; using osu.Game.Beatmaps.Samples;
using osu.Game.Beatmaps.Timing;
using osu.Game.Database;
namespace osu.Game.Modes.Objects namespace osu.Game.Modes.Objects
{ {
@ -22,5 +24,12 @@ namespace osu.Game.Modes.Objects
/// The sample to be played when this HitObject is hit. /// The sample to be played when this HitObject is hit.
/// </summary> /// </summary>
public HitSampleInfo Sample { get; set; } public HitSampleInfo Sample { get; set; }
/// <summary>
/// Applies default values to this HitObject.
/// </summary>
/// <param name="difficulty">The difficulty settings to use.</param>
/// <param name="timing">The timing settings to use.</param>
public virtual void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty) { }
} }
} }

View File

@ -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);
} }
} }

View File

@ -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>
@ -86,16 +89,26 @@ namespace osu.Game.Modes.UI
{ {
Debug.Assert(beatmap != null, "HitRenderer initialized with a null beatmap."); Debug.Assert(beatmap != null, "HitRenderer initialized with a null beatmap.");
// Convert + process the beatmap
Beatmap = CreateBeatmapConverter().Convert(beatmap.Beatmap);
Beatmap.HitObjects.ForEach(h => CreateBeatmapProcessor().SetDefaults(h, Beatmap));
CreateBeatmapProcessor().PostProcess(Beatmap);
applyMods(beatmap.Mods.Value);
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
IBeatmapConverter<TObject> converter = CreateBeatmapConverter();
IBeatmapProcessor<TObject> processor = CreateBeatmapProcessor();
// Convert the beatmap
Beatmap = converter.Convert(beatmap.Beatmap);
// Apply defaults
foreach (var h in Beatmap.HitObjects)
h.ApplyDefaults(Beatmap.TimingInfo, Beatmap.BeatmapInfo.Difficulty);
// Post-process the beatmap
processor.PostProcess(Beatmap);
// Add mods, should always be the last thing applied to give full control to mods
applyMods(beatmap.Mods.Value);
} }
/// <summary> /// <summary>
/// Applies the active mods to this HitRenderer. /// Applies the active mods to this HitRenderer.
/// </summary> /// </summary>
@ -190,9 +203,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();
} }

View File

@ -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()
}); });
}); });
} }