Merge branch 'master' into spectator-listing

This commit is contained in:
Dean Herbert 2020-11-03 19:56:25 +09:00
commit a3c67aabe2
8 changed files with 52 additions and 20 deletions

View File

@ -22,9 +22,9 @@ namespace osu.Game.Tests.Visual.Menus
{ {
AddStep("ensure playing something", () => Game.MusicController.EnsurePlayingSomething()); AddStep("ensure playing something", () => Game.MusicController.EnsurePlayingSomething());
AddStep("toggle playback", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPlay)); AddStep("toggle playback", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPlay));
AddAssert("music paused", () => !Game.MusicController.IsPlaying && Game.MusicController.IsUserPaused); AddAssert("music paused", () => !Game.MusicController.IsPlaying && Game.MusicController.UserPauseRequested);
AddStep("toggle playback", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPlay)); AddStep("toggle playback", () => globalActionContainer.TriggerPressed(GlobalAction.MusicPlay));
AddAssert("music resumed", () => Game.MusicController.IsPlaying && !Game.MusicController.IsUserPaused); AddAssert("music resumed", () => Game.MusicController.IsPlaying && !Game.MusicController.UserPauseRequested);
} }
[Test] [Test]

View File

@ -56,7 +56,7 @@ namespace osu.Game.Tests.Visual.Navigation
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault); AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);
if (withUserPause) if (withUserPause)
AddStep("pause", () => Game.Dependencies.Get<MusicController>().Stop()); AddStep("pause", () => Game.Dependencies.Get<MusicController>().Stop(true));
AddStep("press enter", () => pressAndRelease(Key.Enter)); AddStep("press enter", () => pressAndRelease(Key.Enter));

View File

@ -13,6 +13,7 @@ using Newtonsoft.Json;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Logging;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Replays.Legacy; using osu.Game.Replays.Legacy;
@ -122,19 +123,26 @@ namespace osu.Game.Online.Spectator
isConnected = false; isConnected = false;
playingUsers.Clear(); playingUsers.Clear();
if (ex != null) await tryUntilConnected(); if (ex != null)
{
Logger.Log($"Spectator client lost connection: {ex}", LoggingTarget.Network);
await tryUntilConnected();
}
}; };
await tryUntilConnected(); await tryUntilConnected();
async Task tryUntilConnected() async Task tryUntilConnected()
{ {
Logger.Log("Spectator client connecting...", LoggingTarget.Network);
while (api.State.Value == APIState.Online) while (api.State.Value == APIState.Online)
{ {
try try
{ {
// reconnect on any failure // reconnect on any failure
await connection.StartAsync(); await connection.StartAsync();
Logger.Log("Spectator client connected!", LoggingTarget.Network);
// success // success
isConnected = true; isConnected = true;
@ -151,8 +159,9 @@ namespace osu.Game.Online.Spectator
break; break;
} }
catch catch (Exception e)
{ {
Logger.Log($"Spectator client connection error: {e}", LoggingTarget.Network);
await Task.Delay(5000); await Task.Delay(5000);
} }
} }

View File

@ -45,7 +45,10 @@ namespace osu.Game.Overlays
private readonly BindableList<BeatmapSetInfo> beatmapSets = new BindableList<BeatmapSetInfo>(); private readonly BindableList<BeatmapSetInfo> beatmapSets = new BindableList<BeatmapSetInfo>();
public bool IsUserPaused { get; private set; } /// <summary>
/// Whether the user has requested the track to be paused. Use <see cref="IsPlaying"/> to determine whether the track is still playing.
/// </summary>
public bool UserPauseRequested { get; private set; }
/// <summary> /// <summary>
/// Fired when the global <see cref="WorkingBeatmap"/> has changed. /// Fired when the global <see cref="WorkingBeatmap"/> has changed.
@ -148,7 +151,7 @@ namespace osu.Game.Overlays
/// </summary> /// </summary>
public void EnsurePlayingSomething() public void EnsurePlayingSomething()
{ {
if (IsUserPaused) return; if (UserPauseRequested) return;
if (CurrentTrack.IsDummyDevice || beatmap.Value.BeatmapSetInfo.DeletePending) if (CurrentTrack.IsDummyDevice || beatmap.Value.BeatmapSetInfo.DeletePending)
{ {
@ -166,10 +169,17 @@ namespace osu.Game.Overlays
/// <summary> /// <summary>
/// Start playing the current track (if not already playing). /// Start playing the current track (if not already playing).
/// </summary> /// </summary>
/// <param name="restart">Whether to restart the track from the beginning.</param>
/// <param name="requestedByUser">
/// Whether the request to play was issued by the user rather than internally.
/// Specifying <c>true</c> will ensure that other methods like <see cref="EnsurePlayingSomething"/>
/// will resume music playback going forward.
/// </param>
/// <returns>Whether the operation was successful.</returns> /// <returns>Whether the operation was successful.</returns>
public bool Play(bool restart = false) public bool Play(bool restart = false, bool requestedByUser = false)
{ {
IsUserPaused = false; if (requestedByUser)
UserPauseRequested = false;
if (restart) if (restart)
CurrentTrack.Restart(); CurrentTrack.Restart();
@ -182,9 +192,14 @@ namespace osu.Game.Overlays
/// <summary> /// <summary>
/// Stop playing the current track and pause at the current position. /// Stop playing the current track and pause at the current position.
/// </summary> /// </summary>
public void Stop() /// <param name="requestedByUser">
/// Whether the request to stop was issued by the user rather than internally.
/// Specifying <c>true</c> will ensure that other methods like <see cref="EnsurePlayingSomething"/>
/// will not resume music playback until the next explicit call to <see cref="Play"/>.
/// </param>
public void Stop(bool requestedByUser = false)
{ {
IsUserPaused = true; UserPauseRequested |= requestedByUser;
if (CurrentTrack.IsRunning) if (CurrentTrack.IsRunning)
CurrentTrack.Stop(); CurrentTrack.Stop();
} }
@ -196,9 +211,9 @@ namespace osu.Game.Overlays
public bool TogglePause() public bool TogglePause()
{ {
if (CurrentTrack.IsRunning) if (CurrentTrack.IsRunning)
Stop(); Stop(true);
else else
Play(); Play(requestedByUser: true);
return true; return true;
} }

View File

@ -419,11 +419,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
}; };
// bring in updates from selection changes // bring in updates from selection changes
EditorBeatmap.HitObjectUpdated += _ => UpdateTernaryStates(); EditorBeatmap.HitObjectUpdated += _ => Scheduler.AddOnce(UpdateTernaryStates);
EditorBeatmap.SelectedHitObjects.CollectionChanged += (sender, args) => EditorBeatmap.SelectedHitObjects.CollectionChanged += (sender, args) =>
{ {
Scheduler.AddOnce(updateVisibility); Scheduler.AddOnce(updateVisibility);
UpdateTernaryStates(); Scheduler.AddOnce(UpdateTernaryStates);
}; };
} }

View File

@ -266,8 +266,15 @@ namespace osu.Game.Screens.Edit
{ {
public override string TargetMember => nameof(currentTime); public override string TargetMember => nameof(currentTime);
protected override void Apply(EditorClock clock, double time) => protected override void Apply(EditorClock clock, double time) => clock.currentTime = valueAt(time);
clock.currentTime = Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
private double valueAt(double time)
{
if (time < StartTime) return StartValue;
if (time >= EndTime) return EndValue;
return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
}
protected override void ReadIntoStartValue(EditorClock clock) => StartValue = clock.currentTime; protected override void ReadIntoStartValue(EditorClock clock) => StartValue = clock.currentTime;
} }

View File

@ -579,7 +579,8 @@ namespace osu.Game.Screens.Select
updateComponentFromBeatmap(Beatmap.Value); updateComponentFromBeatmap(Beatmap.Value);
// restart playback on returning to song select, regardless. // restart playback on returning to song select, regardless.
music.Play(); // not sure this should be a permanent thing (we may want to leave a user pause paused even on returning)
music.Play(requestedByUser: true);
} }
this.FadeIn(250); this.FadeIn(250);
@ -681,7 +682,7 @@ namespace osu.Game.Screens.Select
track.RestartPoint = Beatmap.Value.Metadata.PreviewTime; track.RestartPoint = Beatmap.Value.Metadata.PreviewTime;
if (!track.IsRunning && (music.IsUserPaused != true || isNewTrack)) if (!track.IsRunning && (music.UserPauseRequested != true || isNewTrack))
music.Play(true); music.Play(true);
lastTrack.SetTarget(track); lastTrack.SetTarget(track);

View File

@ -189,7 +189,7 @@ namespace osu.Game.Tests.Visual
rulesetDependencies?.Dispose(); rulesetDependencies?.Dispose();
if (MusicController?.TrackLoaded == true) if (MusicController?.TrackLoaded == true)
MusicController.CurrentTrack.Stop(); MusicController.Stop();
if (contextFactory?.IsValueCreated == true) if (contextFactory?.IsValueCreated == true)
contextFactory.Value.ResetDatabase(); contextFactory.Value.ResetDatabase();