mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 10:42:55 +08:00
Move speed adjustment code from ManiaHitRenderer to SpeedAdjustedHitRenderer.
This commit is contained in:
parent
6fd37ebc32
commit
fda220acbc
@ -31,7 +31,7 @@ using osu.Game.Rulesets.UI;
|
|||||||
|
|
||||||
namespace osu.Game.Rulesets.Mania.UI
|
namespace osu.Game.Rulesets.Mania.UI
|
||||||
{
|
{
|
||||||
public class ManiaHitRenderer : HitRenderer<ManiaHitObject, ManiaJudgement>
|
public class ManiaHitRenderer : SpeedAdjustedHitRenderer<ManiaHitObject, ManiaJudgement>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Preferred column count. This will only have an effect during the initialization of the play field.
|
/// Preferred column count. This will only have an effect during the initialization of the play field.
|
||||||
@ -50,8 +50,6 @@ namespace osu.Game.Rulesets.Mania.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly List<SpeedAdjustmentContainer> barlineTimingChanges = new List<SpeedAdjustmentContainer>();
|
private readonly List<SpeedAdjustmentContainer> barlineTimingChanges = new List<SpeedAdjustmentContainer>();
|
||||||
|
|
||||||
private readonly SortedList<MultiplierControlPoint> defaultControlPoints = new SortedList<MultiplierControlPoint>(Comparer<MultiplierControlPoint>.Default);
|
|
||||||
|
|
||||||
public ManiaHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset)
|
public ManiaHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset)
|
||||||
: base(beatmap, isForCurrentRuleset)
|
: base(beatmap, isForCurrentRuleset)
|
||||||
{
|
{
|
||||||
@ -116,7 +114,7 @@ namespace osu.Game.Rulesets.Mania.UI
|
|||||||
|
|
||||||
private void generateDefaultSpeedAdjustments()
|
private void generateDefaultSpeedAdjustments()
|
||||||
{
|
{
|
||||||
defaultControlPoints.ForEach(c =>
|
DefaultControlPoints.ForEach(c =>
|
||||||
{
|
{
|
||||||
foreach (List<SpeedAdjustmentContainer> t in hitObjectTimingChanges)
|
foreach (List<SpeedAdjustmentContainer> t in hitObjectTimingChanges)
|
||||||
t.Add(new ManiaSpeedAdjustmentContainer(c, ScrollingAlgorithm.Basic));
|
t.Add(new ManiaSpeedAdjustmentContainer(c, ScrollingAlgorithm.Basic));
|
||||||
@ -124,93 +122,20 @@ namespace osu.Game.Rulesets.Mania.UI
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generates a control point at a point in time with the relevant timing change/difficulty change from the beatmap.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="time">The time to create the control point at.</param>
|
|
||||||
/// <returns>The <see cref="MultiplierControlPoint"/> at <paramref name="time"/>.</returns>
|
|
||||||
public MultiplierControlPoint CreateControlPointAt(double time)
|
|
||||||
{
|
|
||||||
if (defaultControlPoints.Count == 0)
|
|
||||||
return new MultiplierControlPoint(time);
|
|
||||||
|
|
||||||
int index = defaultControlPoints.BinarySearch(new MultiplierControlPoint(time));
|
|
||||||
if (index < 0)
|
|
||||||
return new MultiplierControlPoint(time);
|
|
||||||
|
|
||||||
return new MultiplierControlPoint(time, defaultControlPoints[index].DeepClone());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void ApplyBeatmap()
|
protected override void ApplyBeatmap()
|
||||||
{
|
{
|
||||||
base.ApplyBeatmap();
|
base.ApplyBeatmap();
|
||||||
|
|
||||||
PreferredColumns = (int)Math.Round(Beatmap.BeatmapInfo.Difficulty.CircleSize);
|
PreferredColumns = (int)Math.Round(Beatmap.BeatmapInfo.Difficulty.CircleSize);
|
||||||
|
|
||||||
// Calculate default multiplier control points
|
|
||||||
var lastTimingPoint = new TimingControlPoint();
|
|
||||||
var lastDifficultyPoint = new DifficultyControlPoint();
|
|
||||||
|
|
||||||
// Merge timing + difficulty points
|
|
||||||
var allPoints = new SortedList<ControlPoint>(Comparer<ControlPoint>.Default);
|
|
||||||
allPoints.AddRange(Beatmap.ControlPointInfo.TimingPoints);
|
|
||||||
allPoints.AddRange(Beatmap.ControlPointInfo.DifficultyPoints);
|
|
||||||
|
|
||||||
// Generate the timing points, making non-timing changes use the previous timing change
|
|
||||||
var timingChanges = allPoints.Select(c =>
|
|
||||||
{
|
|
||||||
var timingPoint = c as TimingControlPoint;
|
|
||||||
var difficultyPoint = c as DifficultyControlPoint;
|
|
||||||
|
|
||||||
if (timingPoint != null)
|
|
||||||
lastTimingPoint = timingPoint;
|
|
||||||
|
|
||||||
if (difficultyPoint != null)
|
|
||||||
lastDifficultyPoint = difficultyPoint;
|
|
||||||
|
|
||||||
return new MultiplierControlPoint(c.Time)
|
|
||||||
{
|
|
||||||
TimingPoint = lastTimingPoint,
|
|
||||||
DifficultyPoint = lastDifficultyPoint
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
double lastObjectTime = (Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? Objects.LastOrDefault()?.StartTime ?? double.MaxValue;
|
|
||||||
|
|
||||||
// Perform some post processing of the timing changes
|
|
||||||
timingChanges = timingChanges
|
|
||||||
// Collapse sections after the last hit object
|
|
||||||
.Where(s => s.StartTime <= lastObjectTime)
|
|
||||||
// Collapse sections with the same start time
|
|
||||||
.GroupBy(s => s.StartTime).Select(g => g.Last()).OrderBy(s => s.StartTime)
|
|
||||||
// Collapse sections with the same beat length
|
|
||||||
.GroupBy(s => s.TimingPoint.BeatLength * s.DifficultyPoint.SpeedMultiplier).Select(g => g.First())
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
defaultControlPoints.AddRange(timingChanges);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Playfield<ManiaHitObject, ManiaJudgement> CreatePlayfield()
|
protected override Playfield<ManiaHitObject, ManiaJudgement> CreatePlayfield() => new ManiaPlayfield(PreferredColumns)
|
||||||
{
|
{
|
||||||
var playfield = new ManiaPlayfield(PreferredColumns)
|
Anchor = Anchor.Centre,
|
||||||
{
|
Origin = Anchor.Centre,
|
||||||
Anchor = Anchor.Centre,
|
// Invert by default for now (should be moved to config/skin later)
|
||||||
Origin = Anchor.Centre,
|
Scale = new Vector2(1, -1)
|
||||||
// Invert by default for now (should be moved to config/skin later)
|
};
|
||||||
Scale = new Vector2(1, -1)
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < PreferredColumns; i++)
|
|
||||||
{
|
|
||||||
foreach (var change in hitObjectTimingChanges[i])
|
|
||||||
playfield.Columns.ElementAt(i).Add(change);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var change in barlineTimingChanges)
|
|
||||||
playfield.Add(change);
|
|
||||||
|
|
||||||
return playfield;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(this);
|
public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(this);
|
||||||
|
|
||||||
@ -236,5 +161,21 @@ namespace osu.Game.Rulesets.Mania.UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override Vector2 GetPlayfieldAspectAdjust() => new Vector2(1, 0.8f);
|
protected override Vector2 GetPlayfieldAspectAdjust() => new Vector2(1, 0.8f);
|
||||||
|
|
||||||
|
protected override void ApplySpeedAdjustments()
|
||||||
|
{
|
||||||
|
var maniaPlayfield = Playfield as ManiaPlayfield;
|
||||||
|
if (maniaPlayfield == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int i = 0; i < PreferredColumns; i++)
|
||||||
|
{
|
||||||
|
foreach (var change in hitObjectTimingChanges[i])
|
||||||
|
maniaPlayfield.Columns.ElementAt(i).Add(change);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var change in barlineTimingChanges)
|
||||||
|
maniaPlayfield.Add(change);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -250,13 +250,16 @@ namespace osu.Game.Rulesets.UI
|
|||||||
{
|
{
|
||||||
KeyConversionInputManager.Add(Playfield = CreatePlayfield());
|
KeyConversionInputManager.Add(Playfield = CreatePlayfield());
|
||||||
|
|
||||||
loadObjects();
|
LoadObjects();
|
||||||
|
|
||||||
if (InputManager?.ReplayInputHandler != null)
|
if (InputManager?.ReplayInputHandler != null)
|
||||||
InputManager.ReplayInputHandler.ToScreenSpace = Playfield.ScaledContent.ToScreenSpace;
|
InputManager.ReplayInputHandler.ToScreenSpace = Playfield.ScaledContent.ToScreenSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadObjects()
|
/// <summary>
|
||||||
|
/// Creates and adds drawable representations of hit objects to the play field.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void LoadObjects()
|
||||||
{
|
{
|
||||||
drawableObjects.Capacity = Beatmap.HitObjects.Count;
|
drawableObjects.Capacity = Beatmap.HitObjects.Count;
|
||||||
|
|
||||||
|
99
osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs
Normal file
99
osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Lists;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
|
using osu.Game.IO.Serialization;
|
||||||
|
using osu.Game.Rulesets.Judgements;
|
||||||
|
using osu.Game.Rulesets.Objects;
|
||||||
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
|
using osu.Game.Rulesets.Timing;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.UI
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A type of <see cref="HitRenderer{TObject, TJudgement}"/> that supports speed adjustments in some capacity.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class SpeedAdjustedHitRenderer<TObject, TJudgement> : HitRenderer<TObject, TJudgement>
|
||||||
|
where TObject : HitObject
|
||||||
|
where TJudgement : Judgement
|
||||||
|
{
|
||||||
|
protected readonly SortedList<MultiplierControlPoint> DefaultControlPoints = new SortedList<MultiplierControlPoint>(Comparer<MultiplierControlPoint>.Default);
|
||||||
|
|
||||||
|
public SpeedAdjustedHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset)
|
||||||
|
: base(beatmap, isForCurrentRuleset)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ApplyBeatmap()
|
||||||
|
{
|
||||||
|
// Calculate default multiplier control points
|
||||||
|
var lastTimingPoint = new TimingControlPoint();
|
||||||
|
var lastDifficultyPoint = new DifficultyControlPoint();
|
||||||
|
|
||||||
|
// Merge timing + difficulty points
|
||||||
|
var allPoints = new SortedList<ControlPoint>(Comparer<ControlPoint>.Default);
|
||||||
|
allPoints.AddRange(Beatmap.ControlPointInfo.TimingPoints);
|
||||||
|
allPoints.AddRange(Beatmap.ControlPointInfo.DifficultyPoints);
|
||||||
|
|
||||||
|
// Generate the timing points, making non-timing changes use the previous timing change
|
||||||
|
var timingChanges = allPoints.Select(c =>
|
||||||
|
{
|
||||||
|
var timingPoint = c as TimingControlPoint;
|
||||||
|
var difficultyPoint = c as DifficultyControlPoint;
|
||||||
|
|
||||||
|
if (timingPoint != null)
|
||||||
|
lastTimingPoint = timingPoint;
|
||||||
|
|
||||||
|
if (difficultyPoint != null)
|
||||||
|
lastDifficultyPoint = difficultyPoint;
|
||||||
|
|
||||||
|
return new MultiplierControlPoint(c.Time)
|
||||||
|
{
|
||||||
|
TimingPoint = lastTimingPoint,
|
||||||
|
DifficultyPoint = lastDifficultyPoint
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
double lastObjectTime = (Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? Objects.LastOrDefault()?.StartTime ?? double.MaxValue;
|
||||||
|
|
||||||
|
// Perform some post processing of the timing changes
|
||||||
|
timingChanges = timingChanges
|
||||||
|
// Collapse sections after the last hit object
|
||||||
|
.Where(s => s.StartTime <= lastObjectTime)
|
||||||
|
// Collapse sections with the same start time
|
||||||
|
.GroupBy(s => s.StartTime).Select(g => g.Last()).OrderBy(s => s.StartTime)
|
||||||
|
// Collapse sections with the same beat length
|
||||||
|
.GroupBy(s => s.TimingPoint.BeatLength * s.DifficultyPoint.SpeedMultiplier).Select(g => g.First());
|
||||||
|
|
||||||
|
DefaultControlPoints.AddRange(timingChanges);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates a control point with the default timing change/difficulty change from the beatmap at a time.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="time">The time to create the control point at.</param>
|
||||||
|
/// <returns>The <see cref="MultiplierControlPoint"/> at <paramref name="time"/>.</returns>
|
||||||
|
public MultiplierControlPoint CreateControlPointAt(double time)
|
||||||
|
{
|
||||||
|
if (DefaultControlPoints.Count == 0)
|
||||||
|
return new MultiplierControlPoint(time);
|
||||||
|
|
||||||
|
int index = DefaultControlPoints.BinarySearch(new MultiplierControlPoint(time));
|
||||||
|
if (index < 0)
|
||||||
|
return new MultiplierControlPoint(time);
|
||||||
|
|
||||||
|
return new MultiplierControlPoint(time, DefaultControlPoints[index].DeepClone());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadObjects()
|
||||||
|
{
|
||||||
|
// We need to add speed adjustments before hit objects are loaded
|
||||||
|
ApplySpeedAdjustments();
|
||||||
|
|
||||||
|
base.LoadObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void ApplySpeedAdjustments();
|
||||||
|
}
|
||||||
|
}
|
@ -314,6 +314,7 @@
|
|||||||
<Compile Include="Screens\Select\SongSelect.cs" />
|
<Compile Include="Screens\Select\SongSelect.cs" />
|
||||||
<Compile Include="Rulesets\UI\HitRenderer.cs" />
|
<Compile Include="Rulesets\UI\HitRenderer.cs" />
|
||||||
<Compile Include="Rulesets\UI\Playfield.cs" />
|
<Compile Include="Rulesets\UI\Playfield.cs" />
|
||||||
|
<Compile Include="Rulesets\UI\SpeedAdjustedHitRenderer.cs" />
|
||||||
<Compile Include="Screens\Select\EditSongSelect.cs" />
|
<Compile Include="Screens\Select\EditSongSelect.cs" />
|
||||||
<Compile Include="Screens\Play\HUD\ComboCounter.cs" />
|
<Compile Include="Screens\Play\HUD\ComboCounter.cs" />
|
||||||
<Compile Include="Screens\Play\HUD\ComboResultCounter.cs" />
|
<Compile Include="Screens\Play\HUD\ComboResultCounter.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user