1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 03:25:11 +08:00

Initial removal of TimingSection.

This commit is contained in:
smoogipooo 2017-05-12 22:23:32 +09:00
parent 0597a95db0
commit a25f11e809
6 changed files with 40 additions and 99 deletions

View File

@ -7,15 +7,16 @@ using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using OpenTK;
using osu.Game.Beatmaps.Timing;
namespace osu.Game.Rulesets.Mania.Timing
{
/// <summary>
/// A container in which the Y-relative coordinate space is spanned by a length of time.
/// <para>
/// This container contains <see cref="TimingSection"/>s which scroll inside this container.
/// Drawables added to this container are moved inside the relevant <see cref="TimingSection"/>,
/// and as such, will scroll along with the <see cref="TimingSection"/>s.
/// This container contains <see cref="ControlPoint"/>s which scroll inside this container.
/// Drawables added to this container are moved inside the relevant <see cref="ControlPoint"/>,
/// and as such, will scroll along with the <see cref="ControlPoint"/>s.
/// </para>
/// </summary>
public class TimeRelativeContainer : Container<Drawable>
@ -31,9 +32,9 @@ namespace osu.Game.Rulesets.Mania.Timing
private readonly List<DrawableTimingSection> drawableTimingSections;
public TimeRelativeContainer(IEnumerable<TimingSection> timingSections)
public TimeRelativeContainer(IEnumerable<ControlPoint> timingChanges)
{
drawableTimingSections = timingSections.Select(t => new DrawableTimingSection(t)).ToList();
drawableTimingSections = timingChanges.Select(t => new DrawableTimingSection(t)).ToList();
Children = drawableTimingSections;
}
@ -68,13 +69,7 @@ namespace osu.Game.Rulesets.Mania.Timing
/// </summary>
private class DrawableTimingSection : Container
{
protected override Container<Drawable> Content => content;
/// <summary>
/// The container which will scroll relative to the current time.
/// </summary>
private readonly Container content;
private readonly TimingSection section;
private readonly ControlPoint timingChange;
/// <summary>
/// Creates a drawable timing section. The height of this container will be proportional
@ -84,26 +79,17 @@ namespace osu.Game.Rulesets.Mania.Timing
/// which means that the content container will scroll at twice the normal rate.
/// </para>
/// </summary>
/// <param name="section">The section to create the drawable timing section for.</param>
public DrawableTimingSection(TimingSection section)
/// <param name="timingChange">The timing change to create the drawable timing section for.</param>
public DrawableTimingSection(ControlPoint timingChange)
{
this.section = section;
this.timingChange = timingChange;
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
RelativeSizeAxes = Axes.Both;
AddInternal(content = new Container
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativePositionAxes = Axes.Both,
RelativeSizeAxes = Axes.Both,
Y = -(float)section.StartTime,
Height = (float)section.Duration,
RelativeCoordinateSpace = new Vector2(1, (float)section.Duration)
});
Y = -(float)timingChange.Time;
}
protected override void Update()
@ -111,11 +97,11 @@ namespace osu.Game.Rulesets.Mania.Timing
var parent = (TimeRelativeContainer)Parent;
// Adjust our height to account for the speed changes
Height = (float)(parent.TimeSpan * 1000 / section.BeatLength);
Height = (float)(parent.TimeSpan * 1000 / timingChange.BeatLength / timingChange.SpeedMultiplier);
RelativeCoordinateSpace = new Vector2(1, (float)parent.TimeSpan);
// Scroll the content
content.Y = (float)(Time.Current - section.StartTime);
Y = (float)(Time.Current - timingChange.Time);
}
public override void Add(Drawable drawable)
@ -124,7 +110,7 @@ namespace osu.Game.Rulesets.Mania.Timing
// we need to offset it back by our position so that it becomes correctly relatively-positioned to us
// This can be removed if hit objects were stored such that either their StartTime or their "beat offset" was relative to the timing section
// they belonged to, but this requires a radical change to the beatmap format which we're not ready to do just yet
drawable.Y += (float)section.StartTime;
drawable.Y += (float)timingChange.Time;
base.Add(drawable);
}
@ -134,7 +120,7 @@ namespace osu.Game.Rulesets.Mania.Timing
/// can be placed within the timing section's bounds (in this case, from the start of the timing section up to infinity).
/// </summary>
/// <param name="drawable">The drawable to check.</param>
public bool CanContain(Drawable drawable) => content.Y >= drawable.Y;
public bool CanContain(Drawable drawable) => Y >= drawable.Y;
}
}
}

View File

@ -1,30 +0,0 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps.Timing;
namespace osu.Game.Rulesets.Mania.Timing
{
/// <summary>
/// A point in the map where the beat length or speed multiplier has changed .
/// </summary>
public class TimingSection
{
/// <summary>
/// The time at which the change occurred.
/// </summary>
public double StartTime;
/// <summary>
/// The duration of this timing section - lasts until the next timing section.
/// </summary>
public double Duration;
/// <summary>
/// The beat length, includes any speed multiplier.
/// </summary>
public double BeatLength;
/// <summary>
/// The time signature of this timing section.
/// </summary>
public TimeSignatures TimeSignature;
}
}

View File

@ -17,6 +17,7 @@ using System.Collections.Generic;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Judgements;
using osu.Game.Beatmaps.Timing;
namespace osu.Game.Rulesets.Mania.UI
{
@ -40,7 +41,7 @@ namespace osu.Game.Rulesets.Mania.UI
public readonly TimeRelativeContainer TimingSectionContainer;
public Column(IEnumerable<TimingSection> timingSections)
public Column(IEnumerable<ControlPoint> timingChanges)
{
RelativeSizeAxes = Axes.Y;
Width = column_width;
@ -87,7 +88,7 @@ namespace osu.Game.Rulesets.Mania.UI
}
}
},
TimingSectionContainer = new TimeRelativeContainer(timingSections)
TimingSectionContainer = new TimeRelativeContainer(timingChanges)
{
Name = "Hit objects",
RelativeSizeAxes = Axes.Both,

View File

@ -33,53 +33,37 @@ namespace osu.Game.Rulesets.Mania.UI
protected override Playfield<ManiaHitObject, ManiaJudgement> CreatePlayfield()
{
var timingSections = new List<TimingSection>();
ControlPoint firstTimingChange = Beatmap.TimingInfo.ControlPoints.FirstOrDefault(t => t.TimingChange);
// Construct all the relevant timing sections
ControlPoint lastTimingChange = Beatmap.TimingInfo.ControlPoints.FirstOrDefault(t => t.TimingChange);
if (lastTimingChange == null)
if (firstTimingChange == null)
throw new Exception("The Beatmap contains no timing points!");
foreach (ControlPoint point in Beatmap.TimingInfo.ControlPoints)
// Generate the timing points, making non-timing changes use the previous timing change
var timingChanges = Beatmap.TimingInfo.ControlPoints.Select(c =>
{
if (point.TimingChange)
lastTimingChange = point;
ControlPoint t = c.Clone();
timingSections.Add(new TimingSection
{
StartTime = point.Time,
BeatLength = lastTimingChange.BeatLength / point.SpeedMultiplier,
TimeSignature = point.TimeSignature
});
}
if (c.TimingChange)
firstTimingChange = c;
else
t.BeatLength = firstTimingChange.BeatLength;
return t;
});
double lastObjectTime = (Objects.Last() as IHasEndTime)?.EndTime ?? Objects.Last().StartTime;
// Perform some post processing of the timing sections
timingSections = timingSections
// Perform some post processing of the timing changes
timingChanges = timingChanges
// Collapse sections after the last hit object
.Where(s => s.StartTime <= lastObjectTime)
.Where(s => s.Time <= lastObjectTime)
// Collapse sections with the same start time
.GroupBy(s => s.StartTime).Select(g => g.Last()).OrderBy(s => s.StartTime)
.GroupBy(s => s.Time).Select(g => g.Last()).OrderBy(s => s.Time)
// Collapse sections with the same beat length
.GroupBy(s => s.BeatLength).Select(g => g.First())
.GroupBy(s => s.BeatLength * s.SpeedMultiplier).Select(g => g.First())
.ToList();
// Determine duration of timing sections
for (int i = 0; i < timingSections.Count; i++)
{
if (i < timingSections.Count - 1)
timingSections[i].Duration = timingSections[i + 1].StartTime - timingSections[i].StartTime;
else
{
// Extra length added for the last timing section to extend past the last hitobject
double extraLength = timingSections[i].BeatLength * (int)timingSections[i].TimeSignature;
timingSections[i].Duration = lastObjectTime + extraLength - timingSections[i].StartTime;
}
}
return new ManiaPlayfield(Columns ?? (int)Math.Round(Beatmap.BeatmapInfo.Difficulty.CircleSize), timingSections)
return new ManiaPlayfield(Columns ?? (int)Math.Round(Beatmap.BeatmapInfo.Difficulty.CircleSize), timingChanges)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre

View File

@ -20,6 +20,7 @@ using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Mania.Timing;
using osu.Framework.Input;
using osu.Game.Beatmaps.Timing;
namespace osu.Game.Rulesets.Mania.UI
{
@ -62,7 +63,7 @@ namespace osu.Game.Rulesets.Mania.UI
private readonly int columnCount;
public ManiaPlayfield(int columnCount, IEnumerable<TimingSection> timingSections)
public ManiaPlayfield(int columnCount, IEnumerable<ControlPoint> timingChanges)
{
this.columnCount = columnCount;
@ -94,7 +95,7 @@ namespace osu.Game.Rulesets.Mania.UI
Padding = new MarginPadding { Left = 1, Right = 1 },
Spacing = new Vector2(1, 0)
},
barlineContainer = new TimeRelativeContainer(timingSections)
barlineContainer = new TimeRelativeContainer(timingChanges)
{
Name = "Bar lines",
Anchor = Anchor.BottomCentre,
@ -107,7 +108,7 @@ namespace osu.Game.Rulesets.Mania.UI
};
for (int i = 0; i < columnCount; i++)
Columns.Add(new Column(timingSections));
Columns.Add(new Column(timingChanges));
TimeSpan = time_span_default;
}

View File

@ -58,7 +58,6 @@
<Compile Include="Objects\Drawables\Pieces\NotePiece.cs" />
<Compile Include="Objects\Types\IHasColumn.cs" />
<Compile Include="Scoring\ManiaScoreProcessor.cs" />
<Compile Include="Timing\TimingSection.cs" />
<Compile Include="Objects\HoldNote.cs" />
<Compile Include="Objects\ManiaHitObject.cs" />
<Compile Include="Objects\Note.cs" />