Skip to content

Commit

Permalink
Merge pull request #31941 from bdach/fix-multi-spectator-freestyle
Browse files Browse the repository at this point in the history
Fix multiplayer spectator not working with freestyle
  • Loading branch information
peppy authored Feb 20, 2025
2 parents e15d5a1 + 81b4f0d commit df5fe07
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ public void TestGameplayRateAdjust()

sendFrames(getPlayerIds(4), 300);

AddUntilStep("wait for correct track speed", () => Beatmap.Value.Track.Rate, () => Is.EqualTo(1.5));
AddUntilStep("wait for correct track speed",
() => this.ChildrenOfType<MultiSpectatorPlayer>().All(player => player.ClockAdjustmentsFromMods.AggregateTempo.Value == 1.5));
}

[Test]
Expand Down
20 changes: 18 additions & 2 deletions osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/PlayerArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand Down Expand Up @@ -53,13 +54,14 @@ public partial class PlayerArea : CompositeDrawable
public Score? Score { get; private set; }

[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
private BeatmapManager beatmapManager { get; set; } = null!;

private readonly AudioAdjustments clockAdjustmentsFromMods = new AudioAdjustments();
private readonly BindableDouble volumeAdjustment = new BindableDouble();
private readonly Container gameplayContent;
private readonly LoadingLayer loadingLayer;
private OsuScreenStack? stack;
private Track? loadedTrack;

public PlayerArea(int userId, SpectatorPlayerClock clock)
{
Expand Down Expand Up @@ -89,7 +91,15 @@ public void LoadScore(Score score)

Score = score;

gameplayContent.Child = new PlayerIsolationContainer(beatmap.Value, Score.ScoreInfo.Ruleset, Score.ScoreInfo.Mods)
// Required for freestyle, where each player may be playing a different beatmap.
var workingBeatmap = beatmapManager.GetWorkingBeatmap(Score.ScoreInfo.BeatmapInfo);

// Required to avoid crashes, but we really don't want to be doing this if we can avoid it.
// If we get to fixing this, we will want to investigate every access to `Track` in gameplay.
if (!workingBeatmap.TrackLoaded)
loadedTrack = workingBeatmap.LoadTrack();

gameplayContent.Child = new PlayerIsolationContainer(workingBeatmap, Score.ScoreInfo.Ruleset, Score.ScoreInfo.Mods)
{
RelativeSizeAxes = Axes.Both,
Child = stack = new OsuScreenStack
Expand Down Expand Up @@ -127,6 +137,12 @@ public bool Mute
public override bool PropagatePositionalInputSubTree => false;
public override bool PropagateNonPositionalInputSubTree => false;

protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
loadedTrack?.Dispose();
}

/// <summary>
/// Isolates each player instance from the game-wide ruleset/beatmap/mods (to allow for different players having different settings).
/// </summary>
Expand Down

0 comments on commit df5fe07

Please sign in to comment.