1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +08:00

Rewrite the way speed adjustments are applied.

This commit is contained in:
smoogipooo 2017-06-09 19:57:03 +09:00
parent 921350128d
commit 1f56848442
11 changed files with 138 additions and 109 deletions

View File

@ -0,0 +1,14 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.Timing;
namespace osu.Game.Rulesets.Mania.Mods
{
internal interface IGenerateSpeedAdjustments
{
void ApplyToHitRenderer(ManiaHitRenderer hitRenderer, ref List<SpeedAdjustmentContainer>[] hitObjectTimingChanges, ref List<SpeedAdjustmentContainer> barlineTimingChanges);
}
}

View File

@ -5,12 +5,6 @@ using System.Collections.Generic;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.Objects.Types;
using System.Linq;
using osu.Framework.Lists;
using osu.Game.Beatmaps.ControlPoints;
using osu.Framework.MathUtils;
using osu.Game.Graphics;
using osu.Game.Rulesets.Mania.Timing;
using osu.Game.Rulesets.Objects;
@ -18,7 +12,7 @@ using osu.Game.Rulesets.Timing;
namespace osu.Game.Rulesets.Mania.Mods
{
public class ManiaModGravity : Mod, IApplicableMod<ManiaHitObject>
public class ManiaModGravity : Mod, IGenerateSpeedAdjustments
{
public override string Name => "Gravity";
@ -26,45 +20,26 @@ namespace osu.Game.Rulesets.Mania.Mods
public override FontAwesome Icon => FontAwesome.fa_sort_desc;
public void ApplyToHitRenderer(HitRenderer<ManiaHitObject> hitRenderer)
public void ApplyToHitRenderer(ManiaHitRenderer hitRenderer, ref List<SpeedAdjustmentContainer>[] hitObjectTimingChanges, ref List<SpeedAdjustmentContainer> barlineTimingChanges)
{
var maniaHitRenderer = (ManiaHitRenderer)hitRenderer;
maniaHitRenderer.HitObjectTimingChanges = new List<SpeedAdjustmentContainer>[maniaHitRenderer.PreferredColumns];
maniaHitRenderer.BarlineTimingChanges = new List<SpeedAdjustmentContainer>();
for (int i = 0; i < maniaHitRenderer.PreferredColumns; i++)
maniaHitRenderer.HitObjectTimingChanges[i] = new List<SpeedAdjustmentContainer>();
foreach (HitObject obj in maniaHitRenderer.Objects)
foreach (HitObject obj in hitRenderer.Objects)
{
var maniaObject = obj as ManiaHitObject;
if (maniaObject == null)
continue;
maniaHitRenderer.HitObjectTimingChanges[maniaObject.Column].Add(new ManiaSpeedAdjustmentContainer(new MultiplierControlPoint(obj.StartTime)
{
TimingPoint = { BeatLength = 1000 }
}, ScrollingAlgorithm.Gravity));
MultiplierControlPoint controlPoint = hitRenderer.CreateControlPointAt(obj.StartTime);
controlPoint.TimingPoint.BeatLength = 1000;
hitObjectTimingChanges[maniaObject.Column].Add(new ManiaSpeedAdjustmentContainer(controlPoint, ScrollingAlgorithm.Gravity));
}
double lastObjectTime = (maniaHitRenderer.Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? maniaHitRenderer.Objects.LastOrDefault()?.StartTime ?? double.MaxValue;
SortedList<TimingControlPoint> timingPoints = maniaHitRenderer.Beatmap.ControlPointInfo.TimingPoints;
for (int i = 0; i < timingPoints.Count; i++)
foreach (BarLine barLine in hitRenderer.BarLines)
{
TimingControlPoint point = timingPoints[i];
var controlPoint = hitRenderer.CreateControlPointAt(barLine.StartTime);
controlPoint.TimingPoint.BeatLength = 1000;
// Stop on the beat before the next timing point, or if there is no next timing point stop slightly past the last object
double endTime = i < timingPoints.Count - 1 ? timingPoints[i + 1].Time - point.BeatLength : lastObjectTime + point.BeatLength * (int)point.TimeSignature;
for (double t = timingPoints[i].Time; Precision.DefinitelyBigger(endTime, t); t += point.BeatLength)
{
maniaHitRenderer.BarlineTimingChanges.Add(new ManiaSpeedAdjustmentContainer(new MultiplierControlPoint(t)
{
TimingPoint = { BeatLength = 1000 }
}, ScrollingAlgorithm.Gravity));
}
barlineTimingChanges.Add(new ManiaSpeedAdjustmentContainer(controlPoint, ScrollingAlgorithm.Gravity));
}
}
}

View File

@ -3,7 +3,6 @@
using osu.Framework.Graphics;
using osu.Game.Rulesets.Timing;
using osu.Game.Rulesets.Timing.Drawables;
namespace osu.Game.Rulesets.Mania.Timing
{

View File

@ -3,7 +3,6 @@
using osu.Framework.Graphics;
using osu.Game.Rulesets.Timing;
using osu.Game.Rulesets.Timing.Drawables;
namespace osu.Game.Rulesets.Mania.Timing
{

View File

@ -3,7 +3,6 @@
using osu.Framework.Graphics;
using osu.Game.Rulesets.Timing;
using osu.Game.Rulesets.Timing.Drawables;
namespace osu.Game.Rulesets.Mania.Timing
{

View File

@ -6,17 +6,17 @@ using System.Collections.Generic;
using System.Linq;
using OpenTK;
using OpenTK.Input;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Lists;
using osu.Framework.MathUtils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.IO.Serialization;
using osu.Game.Rulesets.Beatmaps;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Judgements;
using osu.Game.Rulesets.Mania.Mods;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.Mania.Scoring;
@ -36,42 +36,103 @@ namespace osu.Game.Rulesets.Mania.UI
/// </summary>
public int PreferredColumns;
public readonly List<BarLine> BarLines = new List<BarLine>();
/// <summary>
/// Per-column timing changes.
/// </summary>
public List<SpeedAdjustmentContainer>[] HitObjectTimingChanges;
private readonly List<SpeedAdjustmentContainer>[] hitObjectTimingChanges;
/// <summary>
/// Bar line timing changes.
/// </summary>
public List<SpeedAdjustmentContainer> BarlineTimingChanges;
private readonly List<SpeedAdjustmentContainer> barlineTimingChanges = new List<SpeedAdjustmentContainer>();
/// <summary>
/// Number of columns in the playfield of this hit renderer. Null if the play field hasn't been generated yet.
/// </summary>
public int? Columns { get; private set; }
private readonly SortedList<MultiplierControlPoint> defaultControlPoints = new SortedList<MultiplierControlPoint>(Comparer<MultiplierControlPoint>.Default);
public ManiaHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset)
: base(beatmap, isForCurrentRuleset)
{
Columns = PreferredColumns;
// Generate the speed adjustment container lists
hitObjectTimingChanges = new List<SpeedAdjustmentContainer>[PreferredColumns];
for (int i = 0; i < PreferredColumns; i++)
hitObjectTimingChanges[i] = new List<SpeedAdjustmentContainer>();
generateDefaultTimingChanges();
// Generate the bar line list
double lastObjectTime = (Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? Objects.LastOrDefault()?.StartTime ?? double.MaxValue;
SortedList<TimingControlPoint> timingPoints = Beatmap.ControlPointInfo.TimingPoints;
for (int i = 0; i < timingPoints.Count; i++)
{
TimingControlPoint point = timingPoints[i];
// Stop on the beat before the next timing point, or if there is no next timing point stop slightly past the last object
double endTime = i < timingPoints.Count - 1 ? timingPoints[i + 1].Time - point.BeatLength : lastObjectTime + point.BeatLength * (int)point.TimeSignature;
int index = 0;
for (double t = timingPoints[i].Time; Precision.DefinitelyBigger(endTime, t); t += point.BeatLength, index++)
{
BarLines.Add(new BarLine
{
StartTime = t,
ControlPoint = point,
BeatIndex = index
});
}
}
// Generate speed adjustments from mods first
bool useDefaultSpeedAdjustments = true;
if (Mods != null)
{
foreach (var speedAdjustmentMod in Mods.OfType<IGenerateSpeedAdjustments>())
{
useDefaultSpeedAdjustments = false;
speedAdjustmentMod.ApplyToHitRenderer(this, ref hitObjectTimingChanges, ref barlineTimingChanges);
}
}
// Generate the default speed adjustments
if (useDefaultSpeedAdjustments)
generateDefaultSpeedAdjustments();
}
private void generateDefaultTimingChanges()
private void generateDefaultSpeedAdjustments()
{
if (HitObjectTimingChanges != null || BarlineTimingChanges != null)
return;
defaultControlPoints.ForEach(c =>
{
foreach (List<SpeedAdjustmentContainer> t in hitObjectTimingChanges)
t.Add(new ManiaSpeedAdjustmentContainer(c, ScrollingAlgorithm.Basic));
barlineTimingChanges.Add(new ManiaSpeedAdjustmentContainer(c, ScrollingAlgorithm.Basic));
});
}
HitObjectTimingChanges = new List<SpeedAdjustmentContainer>[PreferredColumns];
BarlineTimingChanges = new List<SpeedAdjustmentContainer>();
/// <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);
for (int i = 0; i < PreferredColumns; i++)
HitObjectTimingChanges[i] = new List<SpeedAdjustmentContainer>();
int index = defaultControlPoints.BinarySearch(new MultiplierControlPoint(time));
if (index < 0)
return new MultiplierControlPoint(time);
double lastSpeedMultiplier = 1;
double lastBeatLength = 500;
return new MultiplierControlPoint(time, defaultControlPoints[index].DeepClone());
}
protected override void ApplyBeatmap()
{
base.ApplyBeatmap();
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);
@ -85,15 +146,15 @@ namespace osu.Game.Rulesets.Mania.UI
var difficultyPoint = c as DifficultyControlPoint;
if (timingPoint != null)
lastBeatLength = timingPoint.BeatLength;
lastTimingPoint = timingPoint;
if (difficultyPoint != null)
lastSpeedMultiplier = difficultyPoint.SpeedMultiplier;
lastDifficultyPoint = difficultyPoint;
return new MultiplierControlPoint(c.Time)
{
TimingPoint = { BeatLength = lastBeatLength },
DifficultyPoint = { SpeedMultiplier = lastSpeedMultiplier }
TimingPoint = lastTimingPoint,
DifficultyPoint = lastDifficultyPoint
};
});
@ -109,19 +170,7 @@ namespace osu.Game.Rulesets.Mania.UI
.GroupBy(s => s.TimingPoint.BeatLength * s.DifficultyPoint.SpeedMultiplier).Select(g => g.First())
.ToList();
timingChanges.ForEach(t =>
{
for (int i = 0; i < PreferredColumns; i++)
HitObjectTimingChanges[i].Add(new ManiaSpeedAdjustmentContainer(t, ScrollingAlgorithm.Basic));
BarlineTimingChanges.Add(new ManiaSpeedAdjustmentContainer(t, ScrollingAlgorithm.Basic));
});
}
protected override void ApplyBeatmap()
{
base.ApplyBeatmap();
PreferredColumns = (int)Math.Round(Beatmap.BeatmapInfo.Difficulty.CircleSize);
defaultControlPoints.AddRange(timingChanges);
}
protected override Playfield<ManiaHitObject, ManiaJudgement> CreatePlayfield()
@ -136,44 +185,16 @@ namespace osu.Game.Rulesets.Mania.UI
for (int i = 0; i < PreferredColumns; i++)
{
foreach (var change in HitObjectTimingChanges[i])
foreach (var change in hitObjectTimingChanges[i])
playfield.Columns.ElementAt(i).Add(change);
}
foreach (var change in BarlineTimingChanges)
foreach (var change in barlineTimingChanges)
playfield.Add(change);
return playfield;
}
[BackgroundDependencyLoader]
private void load()
{
var maniaPlayfield = (ManiaPlayfield)Playfield;
double lastObjectTime = (Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? Objects.LastOrDefault()?.StartTime ?? double.MaxValue;
SortedList<TimingControlPoint> timingPoints = Beatmap.ControlPointInfo.TimingPoints;
for (int i = 0; i < timingPoints.Count; i++)
{
TimingControlPoint point = timingPoints[i];
// Stop on the beat before the next timing point, or if there is no next timing point stop slightly past the last object
double endTime = i < timingPoints.Count - 1 ? timingPoints[i + 1].Time - point.BeatLength : lastObjectTime + point.BeatLength * (int)point.TimeSignature;
int index = 0;
for (double t = timingPoints[i].Time; Precision.DefinitelyBigger(endTime, t); t += point.BeatLength, index++)
{
maniaPlayfield.Add(new DrawableBarLine(new BarLine
{
StartTime = t,
ControlPoint = point,
BeatIndex = index
}));
}
}
}
public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(this);
protected override BeatmapConverter<ManiaHitObject> CreateBeatmapConverter() => new ManiaBeatmapConverter();

View File

@ -62,6 +62,7 @@
<Compile Include="Judgements\ManiaHitResult.cs" />
<Compile Include="Judgements\ManiaJudgement.cs" />
<Compile Include="ManiaDifficultyCalculator.cs" />
<Compile Include="Mods\IGenerateSpeedAdjustments.cs" />
<Compile Include="Objects\Drawables\DrawableBarLine.cs" />
<Compile Include="Objects\Drawables\DrawableHoldNote.cs" />
<Compile Include="Objects\Drawables\DrawableHoldNoteTick.cs" />

View File

@ -5,14 +5,14 @@ using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Caching;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using OpenTK;
using osu.Framework.Configuration;
namespace osu.Game.Rulesets.Timing.Drawables
namespace osu.Game.Rulesets.Timing
{
/// <summary>
/// A collection of hit objects which scrolls within a <see cref="SpeedAdjustmentContainer"/>.

View File

@ -1,11 +1,13 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.IO.Serialization;
namespace osu.Game.Rulesets.Timing
{
public class MultiplierControlPoint
public class MultiplierControlPoint : IJsonSerializable, IComparable<MultiplierControlPoint>
{
/// <summary>
/// The time in milliseconds at which this control point starts.
@ -20,9 +22,22 @@ namespace osu.Game.Rulesets.Timing
public TimingControlPoint TimingPoint = new TimingControlPoint();
public DifficultyControlPoint DifficultyPoint = new DifficultyControlPoint();
public MultiplierControlPoint()
{
}
public MultiplierControlPoint(double startTime)
{
StartTime = startTime;
}
public MultiplierControlPoint(double startTime, MultiplierControlPoint other)
: this(startTime)
{
TimingPoint = other.TimingPoint;
DifficultyPoint = other.DifficultyPoint;
}
public int CompareTo(MultiplierControlPoint other) => StartTime.CompareTo(other?.StartTime);
}
}

View File

@ -7,7 +7,6 @@ using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Timing.Drawables;
using OpenTK;
namespace osu.Game.Rulesets.Timing

View File

@ -120,6 +120,11 @@ namespace osu.Game.Rulesets.UI
/// </summary>
public Beatmap<TObject> Beatmap;
/// <summary>
/// The mods which are to be applied.
/// </summary>
protected IEnumerable<Mod> Mods;
/// <summary>
/// Creates a hit renderer for a beatmap.
/// </summary>
@ -129,6 +134,8 @@ namespace osu.Game.Rulesets.UI
{
Debug.Assert(beatmap != null, "HitRenderer initialized with a null beatmap.");
Mods = beatmap.Mods.Value;
RelativeSizeAxes = Axes.Both;
BeatmapConverter<TObject> converter = CreateBeatmapConverter();