2018-01-05 19:21:19 +08:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-06-16 09:56:33 +08:00
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
2017-06-15 18:25:54 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2017-06-16 08:38:06 +08:00
|
|
|
using osu.Framework.Allocation;
|
2017-08-04 22:07:08 +08:00
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2017-06-15 18:25:54 +08:00
|
|
|
using osu.Framework.Lists;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
using osu.Game.IO.Serialization;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
using osu.Game.Rulesets.Timing;
|
|
|
|
|
2018-01-04 18:22:15 +08:00
|
|
|
namespace osu.Game.Rulesets.UI.Scrolling
|
2017-06-15 18:25:54 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
2017-09-12 18:05:37 +08:00
|
|
|
/// A type of <see cref="RulesetContainer{TPlayfield,TObject}"/> that supports a <see cref="ScrollingPlayfield"/>.
|
2017-09-06 17:05:51 +08:00
|
|
|
/// <see cref="HitObject"/>s inside this <see cref="RulesetContainer{TPlayfield,TObject}"/> will scroll within the playfield.
|
2017-06-15 18:25:54 +08:00
|
|
|
/// </summary>
|
2017-09-06 17:05:51 +08:00
|
|
|
public abstract class ScrollingRulesetContainer<TPlayfield, TObject> : RulesetContainer<TPlayfield, TObject>
|
2017-06-15 18:25:54 +08:00
|
|
|
where TObject : HitObject
|
2017-09-12 17:19:28 +08:00
|
|
|
where TPlayfield : ScrollingPlayfield
|
2017-06-15 18:25:54 +08:00
|
|
|
{
|
2017-08-07 16:25:40 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Provides the default <see cref="MultiplierControlPoint"/>s that adjust the scrolling rate of <see cref="HitObject"/>s
|
2017-09-06 17:05:51 +08:00
|
|
|
/// inside this <see cref="RulesetContainer{TPlayfield,TObject}"/>.
|
2017-08-07 16:25:40 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
2017-06-15 18:25:54 +08:00
|
|
|
protected readonly SortedList<MultiplierControlPoint> DefaultControlPoints = new SortedList<MultiplierControlPoint>(Comparer<MultiplierControlPoint>.Default);
|
|
|
|
|
2017-08-09 12:28:29 +08:00
|
|
|
protected ScrollingRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset)
|
2017-08-09 12:04:11 +08:00
|
|
|
: base(ruleset, beatmap, isForCurrentRuleset)
|
2017-06-15 18:25:54 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-16 08:38:06 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
2017-06-15 18:25:54 +08:00
|
|
|
{
|
|
|
|
// 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
|
2018-01-05 19:17:02 +08:00
|
|
|
// 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);
|
2017-06-15 18:25:54 +08:00
|
|
|
|
|
|
|
DefaultControlPoints.AddRange(timingChanges);
|
2017-08-07 14:22:31 +08:00
|
|
|
|
2017-08-07 16:25:40 +08:00
|
|
|
// If we have no control points, add a default one
|
2017-08-07 14:22:31 +08:00
|
|
|
if (DefaultControlPoints.Count == 0)
|
|
|
|
DefaultControlPoints.Add(new MultiplierControlPoint());
|
2017-08-22 12:00:35 +08:00
|
|
|
|
|
|
|
DefaultControlPoints.ForEach(c => applySpeedAdjustment(c, Playfield));
|
|
|
|
}
|
|
|
|
|
2017-09-12 17:19:28 +08:00
|
|
|
private void applySpeedAdjustment(MultiplierControlPoint controlPoint, ScrollingPlayfield playfield)
|
2017-08-22 12:00:35 +08:00
|
|
|
{
|
2018-01-05 19:56:21 +08:00
|
|
|
playfield.HitObjects.AddControlPoint(controlPoint);
|
2017-08-22 12:00:35 +08:00
|
|
|
playfield.NestedPlayfields.ForEach(p => applySpeedAdjustment(controlPoint, p));
|
2017-06-15 18:25:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2017-08-07 16:25:40 +08:00
|
|
|
/// Generates a <see cref="MultiplierControlPoint"/> with the default timing change/difficulty change from the beatmap at a time.
|
2017-06-15 18:25:54 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="time">The time to create the control point at.</param>
|
2017-08-07 16:25:40 +08:00
|
|
|
/// <returns>The default <see cref="MultiplierControlPoint"/> at <paramref name="time"/>.</returns>
|
2017-06-15 18:25:54 +08:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
2017-06-16 09:56:33 +08:00
|
|
|
}
|