1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:03:13 +08:00

Add stable sorting of storyboard elements

This commit is contained in:
Dean Herbert 2019-03-26 16:16:28 +09:00
parent a63bcff5cc
commit 92184adef5
5 changed files with 18 additions and 11 deletions

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Graphics;
@ -38,6 +39,10 @@ namespace osu.Game.Beatmaps.Formats
{
this.storyboard = storyboard;
base.ParseStreamInto(stream, storyboard);
// OrderBy is used to guarantee that the parsing order of hitobjects with equal start times is maintained (stably-sorted)
foreach (StoryboardLayer layer in storyboard.Layers)
layer.Elements = layer.Elements.OrderBy(h => h.StartTime).ToList();
}
protected override void ParseLine(Storyboard storyboard, Section section, string line)

View File

@ -25,7 +25,7 @@ namespace osu.Game.Storyboards.Drawables
public DrawableStoryboardSample(StoryboardSample sample)
{
this.sample = sample;
LifetimeStart = sample.Time;
LifetimeStart = sample.StartTime;
}
[BackgroundDependencyLoader]
@ -43,27 +43,27 @@ namespace osu.Game.Storyboards.Drawables
base.Update();
// TODO: this logic will need to be consolidated with other game samples like hit sounds.
if (Time.Current < sample.Time)
if (Time.Current < sample.StartTime)
{
// We've rewound before the start time of the sample
channel?.Stop();
// In the case that the user fast-forwards to a point far beyond the start time of the sample,
// we want to be able to fall into the if-conditional below (therefore we must not have a life time end)
LifetimeStart = sample.Time;
LifetimeStart = sample.StartTime;
LifetimeEnd = double.MaxValue;
}
else if (Time.Current - Time.Elapsed < sample.Time)
else if (Time.Current - Time.Elapsed < sample.StartTime)
{
// We've passed the start time of the sample. We only play the sample if we're within an allowable range
// from the sample's start, to reduce layering if we've been fast-forwarded far into the future
if (Time.Current - sample.Time < allowable_late_start)
if (Time.Current - sample.StartTime < allowable_late_start)
channel?.Play();
// In the case that the user rewinds to a point far behind the start time of the sample,
// we want to be able to fall into the if-conditional above (therefore we must not have a life time start)
LifetimeStart = double.MinValue;
LifetimeEnd = sample.Time;
LifetimeEnd = sample.StartTime;
}
}
}

View File

@ -10,6 +10,8 @@ namespace osu.Game.Storyboards
string Path { get; }
bool IsDrawable { get; }
double StartTime { get; }
Drawable CreateDrawable();
}
}

View File

@ -13,8 +13,7 @@ namespace osu.Game.Storyboards
public bool EnabledWhenPassing = true;
public bool EnabledWhenFailing = true;
private readonly List<IStoryboardElement> elements = new List<IStoryboardElement>();
public IEnumerable<IStoryboardElement> Elements => elements;
public List<IStoryboardElement> Elements = new List<IStoryboardElement>();
public StoryboardLayer(string name, int depth)
{
@ -24,7 +23,7 @@ namespace osu.Game.Storyboards
public void Add(IStoryboardElement element)
{
elements.Add(element);
Elements.Add(element);
}
public DrawableStoryboardLayer CreateDrawable()

View File

@ -11,13 +11,14 @@ namespace osu.Game.Storyboards
public string Path { get; set; }
public bool IsDrawable => true;
public double Time;
public double StartTime { get; }
public float Volume;
public StoryboardSample(string path, double time, float volume)
{
Path = path;
Time = time;
StartTime = time;
Volume = volume;
}