mirror of
https://github.com/ppy/osu.git
synced 2025-02-12 15:52:55 +08:00
Avoid accessing WorkingBeatmap.Beatmap
every update call
Notice in passing. Comes with overheads that can be easily avoided. Left a note for a future (slightly more involved) optimisation.
This commit is contained in:
parent
f65be009a3
commit
a23de0b188
@ -203,6 +203,8 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// TODO: This is a touch expensive and can become an issue if being accessed every Update call.
|
||||||
|
// Optimally we would not involve the async flow if things are already loaded.
|
||||||
return loadBeatmapAsync().GetResultSafely();
|
return loadBeatmapAsync().GetResultSafely();
|
||||||
}
|
}
|
||||||
catch (AggregateException ae)
|
catch (AggregateException ae)
|
||||||
|
@ -53,7 +53,7 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
private readonly Bindable<bool> playbackRateValid = new Bindable<bool>(true);
|
private readonly Bindable<bool> playbackRateValid = new Bindable<bool>(true);
|
||||||
|
|
||||||
private readonly WorkingBeatmap beatmap;
|
private readonly IBeatmap beatmap;
|
||||||
|
|
||||||
private Track track;
|
private Track track;
|
||||||
|
|
||||||
@ -63,20 +63,19 @@ namespace osu.Game.Screens.Play
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new master gameplay clock container.
|
/// Create a new master gameplay clock container.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="beatmap">The beatmap to be used for time and metadata references.</param>
|
/// <param name="working">The beatmap to be used for time and metadata references.</param>
|
||||||
/// <param name="gameplayStartTime">The latest time which should be used when introducing gameplay. Will be used when skipping forward.</param>
|
/// <param name="gameplayStartTime">The latest time which should be used when introducing gameplay. Will be used when skipping forward.</param>
|
||||||
public MasterGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStartTime)
|
public MasterGameplayClockContainer(WorkingBeatmap working, double gameplayStartTime)
|
||||||
: base(beatmap.Track, applyOffsets: true, requireDecoupling: true)
|
: base(working.Track, applyOffsets: true, requireDecoupling: true)
|
||||||
{
|
{
|
||||||
this.beatmap = beatmap;
|
beatmap = working.Beatmap;
|
||||||
|
track = working.Track;
|
||||||
track = beatmap.Track;
|
|
||||||
|
|
||||||
GameplayStartTime = gameplayStartTime;
|
GameplayStartTime = gameplayStartTime;
|
||||||
StartTime = findEarliestStartTime(gameplayStartTime, beatmap);
|
StartTime = findEarliestStartTime(gameplayStartTime, working);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double findEarliestStartTime(double gameplayStartTime, WorkingBeatmap beatmap)
|
private static double findEarliestStartTime(double gameplayStartTime, WorkingBeatmap working)
|
||||||
{
|
{
|
||||||
// here we are trying to find the time to start playback from the "zero" point.
|
// here we are trying to find the time to start playback from the "zero" point.
|
||||||
// generally this is either zero, or some point earlier than zero in the case of storyboards, lead-ins etc.
|
// generally this is either zero, or some point earlier than zero in the case of storyboards, lead-ins etc.
|
||||||
@ -86,15 +85,15 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
// if a storyboard is present, it may dictate the appropriate start time by having events in negative time space.
|
// if a storyboard is present, it may dictate the appropriate start time by having events in negative time space.
|
||||||
// this is commonly used to display an intro before the audio track start.
|
// this is commonly used to display an intro before the audio track start.
|
||||||
double? firstStoryboardEvent = beatmap.Storyboard.EarliestEventTime;
|
double? firstStoryboardEvent = working.Storyboard.EarliestEventTime;
|
||||||
if (firstStoryboardEvent != null)
|
if (firstStoryboardEvent != null)
|
||||||
time = Math.Min(time, firstStoryboardEvent.Value);
|
time = Math.Min(time, firstStoryboardEvent.Value);
|
||||||
|
|
||||||
// some beatmaps specify a current lead-in time which should be used instead of the ruleset-provided value when available.
|
// some beatmaps specify a current lead-in time which should be used instead of the ruleset-provided value when available.
|
||||||
// this is not available as an option in the live editor but can still be applied via .osu editing.
|
// this is not available as an option in the live editor but can still be applied via .osu editing.
|
||||||
double firstHitObjectTime = beatmap.Beatmap.HitObjects.First().StartTime;
|
double firstHitObjectTime = working.Beatmap.HitObjects.First().StartTime;
|
||||||
if (beatmap.Beatmap.AudioLeadIn > 0)
|
if (working.Beatmap.AudioLeadIn > 0)
|
||||||
time = Math.Min(time, firstHitObjectTime - beatmap.Beatmap.AudioLeadIn);
|
time = Math.Min(time, firstHitObjectTime - working.Beatmap.AudioLeadIn);
|
||||||
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
@ -136,7 +135,7 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
removeAdjustmentsFromTrack();
|
removeAdjustmentsFromTrack();
|
||||||
|
|
||||||
track = new TrackVirtual(beatmap.Track.Length);
|
track = new TrackVirtual(track.Length);
|
||||||
track.Seek(CurrentTime);
|
track.Seek(CurrentTime);
|
||||||
if (IsRunning)
|
if (IsRunning)
|
||||||
track.Start();
|
track.Start();
|
||||||
@ -228,9 +227,8 @@ namespace osu.Game.Screens.Play
|
|||||||
removeAdjustmentsFromTrack();
|
removeAdjustmentsFromTrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlPointInfo IBeatSyncProvider.ControlPoints => beatmap.Beatmap.ControlPointInfo;
|
ControlPointInfo IBeatSyncProvider.ControlPoints => beatmap.ControlPointInfo;
|
||||||
|
ChannelAmplitudes IHasAmplitudes.CurrentAmplitudes => track.CurrentAmplitudes;
|
||||||
IClock IBeatSyncProvider.Clock => this;
|
IClock IBeatSyncProvider.Clock => this;
|
||||||
|
|
||||||
ChannelAmplitudes IHasAmplitudes.CurrentAmplitudes => beatmap.TrackLoaded ? beatmap.Track.CurrentAmplitudes : ChannelAmplitudes.Empty;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user