mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 20:53:04 +08:00
Merge branch 'multiplayer-spectator-leaderboard' into multiplayer-spectator-screen
This commit is contained in:
commit
950e4e05ef
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ContentModelUserStore">
|
<component name="UserContentModel">
|
||||||
<attachedFolders />
|
<attachedFolders />
|
||||||
<explicitIncludes />
|
<explicitIncludes />
|
||||||
<explicitExcludes />
|
<explicitExcludes />
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/.idea.osu.Desktop/.idea/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.osu.Desktop/.idea/riderModule.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -93,7 +93,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
InputManager.Click(MouseButton.Left);
|
InputManager.Click(MouseButton.Left);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddWaitStep("wait", 10);
|
AddUntilStep("wait for join", () => Client.Room != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -114,6 +114,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
InputManager.Click(MouseButton.Left);
|
InputManager.Click(MouseButton.Left);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for room join", () => Client.Room != null);
|
||||||
|
|
||||||
AddStep("join other user (ready)", () =>
|
AddStep("join other user (ready)", () =>
|
||||||
{
|
{
|
||||||
Client.AddUser(new User { Id = 55 });
|
Client.AddUser(new User { Id = 55 });
|
||||||
|
@ -0,0 +1,229 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Framework.Timing;
|
||||||
|
using osu.Framework.Utils;
|
||||||
|
using osu.Game.Database;
|
||||||
|
using osu.Game.Online;
|
||||||
|
using osu.Game.Online.Spectator;
|
||||||
|
using osu.Game.Replays.Legacy;
|
||||||
|
using osu.Game.Rulesets.Osu.Scoring;
|
||||||
|
using osu.Game.Scoring;
|
||||||
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate;
|
||||||
|
using osu.Game.Screens.Play.HUD;
|
||||||
|
using osu.Game.Users;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Multiplayer
|
||||||
|
{
|
||||||
|
public class TestSceneMultiplayerSpectatorLeaderboard : MultiplayerTestScene
|
||||||
|
{
|
||||||
|
[Cached(typeof(SpectatorStreamingClient))]
|
||||||
|
private TestSpectatorStreamingClient streamingClient = new TestSpectatorStreamingClient();
|
||||||
|
|
||||||
|
[Cached(typeof(UserLookupCache))]
|
||||||
|
private UserLookupCache lookupCache = new TestUserLookupCache();
|
||||||
|
|
||||||
|
protected override Container<Drawable> Content => content;
|
||||||
|
private readonly Container content;
|
||||||
|
|
||||||
|
private readonly Dictionary<int, ManualClock> clocks = new Dictionary<int, ManualClock>
|
||||||
|
{
|
||||||
|
{ 55, new ManualClock() },
|
||||||
|
{ 56, new ManualClock() }
|
||||||
|
};
|
||||||
|
|
||||||
|
public TestSceneMultiplayerSpectatorLeaderboard()
|
||||||
|
{
|
||||||
|
base.Content.AddRange(new Drawable[]
|
||||||
|
{
|
||||||
|
streamingClient,
|
||||||
|
lookupCache,
|
||||||
|
content = new Container { RelativeSizeAxes = Axes.Both }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[SetUpSteps]
|
||||||
|
public new void SetUpSteps()
|
||||||
|
{
|
||||||
|
MultiplayerSpectatorLeaderboard leaderboard = null;
|
||||||
|
|
||||||
|
AddStep("reset", () =>
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
|
||||||
|
foreach (var (userId, clock) in clocks)
|
||||||
|
{
|
||||||
|
streamingClient.EndPlay(userId, 0);
|
||||||
|
clock.CurrentTime = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("create leaderboard", () =>
|
||||||
|
{
|
||||||
|
foreach (var (userId, _) in clocks)
|
||||||
|
streamingClient.StartPlay(userId, 0);
|
||||||
|
|
||||||
|
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
|
||||||
|
|
||||||
|
var playable = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
|
||||||
|
var scoreProcessor = new OsuScoreProcessor();
|
||||||
|
scoreProcessor.ApplyBeatmap(playable);
|
||||||
|
|
||||||
|
LoadComponentAsync(leaderboard = new MultiplayerSpectatorLeaderboard(scoreProcessor, clocks.Keys.ToArray()) { Expanded = { Value = true } }, Add);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for load", () => leaderboard.IsLoaded);
|
||||||
|
|
||||||
|
AddStep("add clock sources", () =>
|
||||||
|
{
|
||||||
|
foreach (var (userId, clock) in clocks)
|
||||||
|
leaderboard.AddClock(userId, clock);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestLeaderboardTracksCurrentTime()
|
||||||
|
{
|
||||||
|
AddStep("send frames", () =>
|
||||||
|
{
|
||||||
|
// For user 55, send frames in sets of 1.
|
||||||
|
// For user 56, send frames in sets of 10.
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
streamingClient.SendFrames(55, i, 1);
|
||||||
|
|
||||||
|
if (i % 10 == 0)
|
||||||
|
streamingClient.SendFrames(56, i, 10);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assertCombo(55, 1);
|
||||||
|
assertCombo(56, 10);
|
||||||
|
|
||||||
|
// Advance to a point where only user 55's frame changes.
|
||||||
|
setTime(500);
|
||||||
|
assertCombo(55, 5);
|
||||||
|
assertCombo(56, 10);
|
||||||
|
|
||||||
|
// Advance to a point where both user's frame changes.
|
||||||
|
setTime(1100);
|
||||||
|
assertCombo(55, 11);
|
||||||
|
assertCombo(56, 20);
|
||||||
|
|
||||||
|
// Advance user 56 only to a point where its frame changes.
|
||||||
|
setTime(56, 2100);
|
||||||
|
assertCombo(55, 11);
|
||||||
|
assertCombo(56, 30);
|
||||||
|
|
||||||
|
// Advance both users beyond their last frame
|
||||||
|
setTime(101 * 100);
|
||||||
|
assertCombo(55, 100);
|
||||||
|
assertCombo(56, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestNoFrames()
|
||||||
|
{
|
||||||
|
assertCombo(55, 0);
|
||||||
|
assertCombo(56, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTime(double time) => AddStep($"set time {time}", () =>
|
||||||
|
{
|
||||||
|
foreach (var (_, clock) in clocks)
|
||||||
|
clock.CurrentTime = time;
|
||||||
|
});
|
||||||
|
|
||||||
|
private void setTime(int userId, double time)
|
||||||
|
=> AddStep($"set user {userId} time {time}", () => clocks[userId].CurrentTime = time);
|
||||||
|
|
||||||
|
private void assertCombo(int userId, int expectedCombo)
|
||||||
|
=> AddUntilStep($"player {userId} has {expectedCombo} combo", () => this.ChildrenOfType<GameplayLeaderboardScore>().Single(s => s.User?.Id == userId).Combo.Value == expectedCombo);
|
||||||
|
|
||||||
|
private class TestSpectatorStreamingClient : SpectatorStreamingClient
|
||||||
|
{
|
||||||
|
private readonly Dictionary<int, int> userBeatmapDictionary = new Dictionary<int, int>();
|
||||||
|
private readonly Dictionary<int, bool> userSentStateDictionary = new Dictionary<int, bool>();
|
||||||
|
|
||||||
|
public TestSpectatorStreamingClient()
|
||||||
|
: base(new DevelopmentEndpointConfiguration())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartPlay(int userId, int beatmapId)
|
||||||
|
{
|
||||||
|
userBeatmapDictionary[userId] = beatmapId;
|
||||||
|
userSentStateDictionary[userId] = false;
|
||||||
|
sendState(userId, beatmapId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void EndPlay(int userId, int beatmapId)
|
||||||
|
{
|
||||||
|
((ISpectatorClient)this).UserFinishedPlaying(userId, new SpectatorState
|
||||||
|
{
|
||||||
|
BeatmapID = beatmapId,
|
||||||
|
RulesetID = 0,
|
||||||
|
});
|
||||||
|
userSentStateDictionary[userId] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendFrames(int userId, int index, int count)
|
||||||
|
{
|
||||||
|
var frames = new List<LegacyReplayFrame>();
|
||||||
|
|
||||||
|
for (int i = index; i < index + count; i++)
|
||||||
|
{
|
||||||
|
var buttonState = i == index + count - 1 ? ReplayButtonState.None : ReplayButtonState.Left1;
|
||||||
|
frames.Add(new LegacyReplayFrame(i * 100, RNG.Next(0, 512), RNG.Next(0, 512), buttonState));
|
||||||
|
}
|
||||||
|
|
||||||
|
var bundle = new FrameDataBundle(new ScoreInfo { Combo = index + count }, frames);
|
||||||
|
((ISpectatorClient)this).UserSentFrames(userId, bundle);
|
||||||
|
if (!userSentStateDictionary[userId])
|
||||||
|
sendState(userId, userBeatmapDictionary[userId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WatchUser(int userId)
|
||||||
|
{
|
||||||
|
if (userSentStateDictionary[userId])
|
||||||
|
{
|
||||||
|
// usually the server would do this.
|
||||||
|
sendState(userId, userBeatmapDictionary[userId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
base.WatchUser(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendState(int userId, int beatmapId)
|
||||||
|
{
|
||||||
|
((ISpectatorClient)this).UserBeganPlaying(userId, new SpectatorState
|
||||||
|
{
|
||||||
|
BeatmapID = beatmapId,
|
||||||
|
RulesetID = 0,
|
||||||
|
});
|
||||||
|
userSentStateDictionary[userId] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestUserLookupCache : UserLookupCache
|
||||||
|
{
|
||||||
|
protected override Task<User> ComputeValueAsync(int lookup, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
return Task.FromResult(new User
|
||||||
|
{
|
||||||
|
Id = lookup,
|
||||||
|
Username = $"User {lookup}"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -27,8 +27,6 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
public IBeatmap Beatmap { get; }
|
public IBeatmap Beatmap { get; }
|
||||||
|
|
||||||
private CancellationToken cancellationToken;
|
|
||||||
|
|
||||||
protected BeatmapConverter(IBeatmap beatmap, Ruleset ruleset)
|
protected BeatmapConverter(IBeatmap beatmap, Ruleset ruleset)
|
||||||
{
|
{
|
||||||
Beatmap = beatmap;
|
Beatmap = beatmap;
|
||||||
@ -41,8 +39,6 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
public IBeatmap Convert(CancellationToken cancellationToken = default)
|
public IBeatmap Convert(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
this.cancellationToken = cancellationToken;
|
|
||||||
|
|
||||||
// We always operate on a clone of the original beatmap, to not modify it game-wide
|
// We always operate on a clone of the original beatmap, to not modify it game-wide
|
||||||
return ConvertBeatmap(Beatmap.Clone(), cancellationToken);
|
return ConvertBeatmap(Beatmap.Clone(), cancellationToken);
|
||||||
}
|
}
|
||||||
@ -55,19 +51,6 @@ namespace osu.Game.Beatmaps
|
|||||||
/// <returns>The converted Beatmap.</returns>
|
/// <returns>The converted Beatmap.</returns>
|
||||||
protected virtual Beatmap<T> ConvertBeatmap(IBeatmap original, CancellationToken cancellationToken)
|
protected virtual Beatmap<T> ConvertBeatmap(IBeatmap original, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
#pragma warning disable 618
|
|
||||||
return ConvertBeatmap(original);
|
|
||||||
#pragma warning restore 618
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Performs the conversion of a Beatmap using this Beatmap Converter.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="original">The un-converted Beatmap.</param>
|
|
||||||
/// <returns>The converted Beatmap.</returns>
|
|
||||||
[Obsolete("Use the cancellation-supporting override")] // Can be removed 20210318
|
|
||||||
protected virtual Beatmap<T> ConvertBeatmap(IBeatmap original)
|
|
||||||
{
|
|
||||||
var beatmap = CreateBeatmap();
|
var beatmap = CreateBeatmap();
|
||||||
|
|
||||||
beatmap.BeatmapInfo = original.BeatmapInfo;
|
beatmap.BeatmapInfo = original.BeatmapInfo;
|
||||||
@ -121,21 +104,6 @@ namespace osu.Game.Beatmaps
|
|||||||
/// <param name="beatmap">The un-converted Beatmap.</param>
|
/// <param name="beatmap">The un-converted Beatmap.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>The converted hit object.</returns>
|
/// <returns>The converted hit object.</returns>
|
||||||
protected virtual IEnumerable<T> ConvertHitObject(HitObject original, IBeatmap beatmap, CancellationToken cancellationToken)
|
protected virtual IEnumerable<T> ConvertHitObject(HitObject original, IBeatmap beatmap, CancellationToken cancellationToken) => Enumerable.Empty<T>();
|
||||||
{
|
|
||||||
#pragma warning disable 618
|
|
||||||
return ConvertHitObject(original, beatmap);
|
|
||||||
#pragma warning restore 618
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Performs the conversion of a hit object.
|
|
||||||
/// This method is generally executed sequentially for all objects in a beatmap.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="original">The hit object to convert.</param>
|
|
||||||
/// <param name="beatmap">The un-converted Beatmap.</param>
|
|
||||||
/// <returns>The converted hit object.</returns>
|
|
||||||
[Obsolete("Use the cancellation-supporting override")] // Can be removed 20210318
|
|
||||||
protected virtual IEnumerable<T> ConvertHitObject(HitObject original, IBeatmap beatmap) => Enumerable.Empty<T>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,11 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osuTK;
|
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps
|
namespace osu.Game.Beatmaps
|
||||||
{
|
{
|
||||||
public class BeatmapStatistic
|
public class BeatmapStatistic
|
||||||
{
|
{
|
||||||
[Obsolete("Use CreateIcon instead")] // can be removed 20210203
|
|
||||||
public IconUsage Icon = FontAwesome.Regular.QuestionCircle;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A function to create the icon for display purposes. Use default icons available via <see cref="BeatmapStatisticIcon"/> whenever possible for conformity.
|
/// A function to create the icon for display purposes. Use default icons available via <see cref="BeatmapStatisticIcon"/> whenever possible for conformity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -20,12 +15,5 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
public string Content;
|
public string Content;
|
||||||
public string Name;
|
public string Name;
|
||||||
|
|
||||||
public BeatmapStatistic()
|
|
||||||
{
|
|
||||||
#pragma warning disable 618
|
|
||||||
CreateIcon = () => new SpriteIcon { Icon = Icon, Scale = new Vector2(0.7f) };
|
|
||||||
#pragma warning restore 618
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Globalization;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using osu.Framework.IO.Network;
|
using osu.Framework.IO.Network;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
@ -11,11 +12,13 @@ namespace osu.Game.Online.Solo
|
|||||||
public class CreateSoloScoreRequest : APIRequest<APIScoreToken>
|
public class CreateSoloScoreRequest : APIRequest<APIScoreToken>
|
||||||
{
|
{
|
||||||
private readonly int beatmapId;
|
private readonly int beatmapId;
|
||||||
|
private readonly int rulesetId;
|
||||||
private readonly string versionHash;
|
private readonly string versionHash;
|
||||||
|
|
||||||
public CreateSoloScoreRequest(int beatmapId, string versionHash)
|
public CreateSoloScoreRequest(int beatmapId, int rulesetId, string versionHash)
|
||||||
{
|
{
|
||||||
this.beatmapId = beatmapId;
|
this.beatmapId = beatmapId;
|
||||||
|
this.rulesetId = rulesetId;
|
||||||
this.versionHash = versionHash;
|
this.versionHash = versionHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,9 +27,10 @@ namespace osu.Game.Online.Solo
|
|||||||
var req = base.CreateWebRequest();
|
var req = base.CreateWebRequest();
|
||||||
req.Method = HttpMethod.Post;
|
req.Method = HttpMethod.Post;
|
||||||
req.AddParameter("version_hash", versionHash);
|
req.AddParameter("version_hash", versionHash);
|
||||||
|
req.AddParameter("ruleset_id", rulesetId.ToString(CultureInfo.InvariantCulture));
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Target => $@"solo/{beatmapId}/scores";
|
protected override string Target => $@"beatmaps/{beatmapId}/solo/scores";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,6 @@ namespace osu.Game.Online.Solo
|
|||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Target => $@"solo/{beatmapId}/scores/{scoreId}";
|
protected override string Target => $@"beatmaps/{beatmapId}/solo/scores/{scoreId}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,13 +57,6 @@ namespace osu.Game.Overlays.Settings
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("Use Current instead")] // Can be removed 20210406
|
|
||||||
public Bindable<T> Bindable
|
|
||||||
{
|
|
||||||
get => Current;
|
|
||||||
set => Current = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual Bindable<T> Current
|
public virtual Bindable<T> Current
|
||||||
{
|
{
|
||||||
get => controlWithCurrent.Current;
|
get => controlWithCurrent.Current;
|
||||||
|
@ -28,18 +28,6 @@ namespace osu.Game.Rulesets.Judgements
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected const double DEFAULT_MAX_HEALTH_INCREASE = 0.05;
|
protected const double DEFAULT_MAX_HEALTH_INCREASE = 0.05;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether this <see cref="Judgement"/> should affect the current combo.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("Has no effect. Use HitResult members instead (e.g. use small-tick or bonus to not affect combo).")] // Can be removed 20210328
|
|
||||||
public virtual bool AffectsCombo => true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether this <see cref="Judgement"/> should be counted as base (combo) or bonus score.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("Has no effect. Use HitResult members instead (e.g. use small-tick or bonus to not affect combo).")] // Can be removed 20210328
|
|
||||||
public virtual bool IsBonus => !AffectsCombo;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum <see cref="HitResult"/> that can be achieved.
|
/// The maximum <see cref="HitResult"/> that can be achieved.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -11,7 +11,6 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Framework.Extensions.TypeExtensions;
|
using osu.Framework.Extensions.TypeExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Framework.Logging;
|
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Rulesets.Judgements;
|
using osu.Game.Rulesets.Judgements;
|
||||||
@ -736,24 +735,6 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
if (!Result.HasResult)
|
if (!Result.HasResult)
|
||||||
throw new InvalidOperationException($"{GetType().ReadableName()} applied a {nameof(JudgementResult)} but did not update {nameof(JudgementResult.Type)}.");
|
throw new InvalidOperationException($"{GetType().ReadableName()} applied a {nameof(JudgementResult)} but did not update {nameof(JudgementResult.Type)}.");
|
||||||
|
|
||||||
// Some (especially older) rulesets use scorable judgements instead of the newer ignorehit/ignoremiss judgements.
|
|
||||||
// Can be removed 20210328
|
|
||||||
if (Result.Judgement.MaxResult == HitResult.IgnoreHit)
|
|
||||||
{
|
|
||||||
HitResult originalType = Result.Type;
|
|
||||||
|
|
||||||
if (Result.Type == HitResult.Miss)
|
|
||||||
Result.Type = HitResult.IgnoreMiss;
|
|
||||||
else if (Result.Type >= HitResult.Meh && Result.Type <= HitResult.Perfect)
|
|
||||||
Result.Type = HitResult.IgnoreHit;
|
|
||||||
|
|
||||||
if (Result.Type != originalType)
|
|
||||||
{
|
|
||||||
Logger.Log($"{GetType().ReadableName()} applied an invalid hit result ({originalType}) when {nameof(HitResult.IgnoreMiss)} or {nameof(HitResult.IgnoreHit)} is expected.\n"
|
|
||||||
+ $"This has been automatically adjusted to {Result.Type}, and support will be removed from 2021-03-28 onwards.", level: LogLevel.Important);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Result.Type.IsValidHitResult(Result.Judgement.MinResult, Result.Judgement.MaxResult))
|
if (!Result.Type.IsValidHitResult(Result.Judgement.MinResult, Result.Judgement.MaxResult))
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
|
@ -139,15 +139,6 @@ namespace osu.Game.Rulesets.Objects
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void CreateNestedHitObjects(CancellationToken cancellationToken)
|
protected virtual void CreateNestedHitObjects(CancellationToken cancellationToken)
|
||||||
{
|
|
||||||
// ReSharper disable once MethodSupportsCancellation (https://youtrack.jetbrains.com/issue/RIDER-44520)
|
|
||||||
#pragma warning disable 618
|
|
||||||
CreateNestedHitObjects();
|
|
||||||
#pragma warning restore 618
|
|
||||||
}
|
|
||||||
|
|
||||||
[Obsolete("Use the cancellation-supporting override")] // Can be removed 20210318
|
|
||||||
protected virtual void CreateNestedHitObjects()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,12 +346,6 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
|
|
||||||
score.HitEvents = hitEvents;
|
score.HitEvents = hitEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a <see cref="HitWindows"/> for this processor.
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("Method is now unused.")] // Can be removed 20210328
|
|
||||||
public virtual HitWindows CreateHitWindows() => new HitWindows();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ScoringMode
|
public enum ScoringMode
|
||||||
|
@ -0,0 +1,85 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Timing;
|
||||||
|
using osu.Game.Online.Spectator;
|
||||||
|
using osu.Game.Rulesets.Scoring;
|
||||||
|
using osu.Game.Screens.Play.HUD;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||||
|
{
|
||||||
|
public class MultiplayerSpectatorLeaderboard : MultiplayerGameplayLeaderboard
|
||||||
|
{
|
||||||
|
private readonly Dictionary<int, TrackedUserData> trackedData = new Dictionary<int, TrackedUserData>();
|
||||||
|
|
||||||
|
public MultiplayerSpectatorLeaderboard(ScoreProcessor scoreProcessor, int[] userIds)
|
||||||
|
: base(scoreProcessor, userIds)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddClock(int userId, IClock source) => trackedData[userId] = new TrackedUserData(source);
|
||||||
|
|
||||||
|
public void RemoveClock(int userId, IClock source) => trackedData.Remove(userId);
|
||||||
|
|
||||||
|
protected override void OnIncomingFrames(int userId, FrameDataBundle bundle)
|
||||||
|
{
|
||||||
|
if (!trackedData.TryGetValue(userId, out var data))
|
||||||
|
return;
|
||||||
|
|
||||||
|
data.Frames.Add(new TimedFrameHeader(bundle.Frames.First().Time, bundle.Header));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
foreach (var (userId, data) in trackedData)
|
||||||
|
{
|
||||||
|
var targetTime = data.Clock.CurrentTime;
|
||||||
|
|
||||||
|
if (data.Frames.Count == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int frameIndex = data.Frames.BinarySearch(new TimedFrameHeader(targetTime));
|
||||||
|
if (frameIndex < 0)
|
||||||
|
frameIndex = ~frameIndex;
|
||||||
|
frameIndex = Math.Clamp(frameIndex - 1, 0, data.Frames.Count - 1);
|
||||||
|
|
||||||
|
SetCurrentFrame(userId, data.Frames[frameIndex].Header);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TrackedUserData
|
||||||
|
{
|
||||||
|
public readonly IClock Clock;
|
||||||
|
public readonly List<TimedFrameHeader> Frames = new List<TimedFrameHeader>();
|
||||||
|
|
||||||
|
public TrackedUserData(IClock clock)
|
||||||
|
{
|
||||||
|
Clock = clock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TimedFrameHeader : IComparable<TimedFrameHeader>
|
||||||
|
{
|
||||||
|
public readonly double Time;
|
||||||
|
public readonly FrameHeader Header;
|
||||||
|
|
||||||
|
public TimedFrameHeader(double time)
|
||||||
|
{
|
||||||
|
Time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimedFrameHeader(double time, FrameHeader header)
|
||||||
|
{
|
||||||
|
Time = time;
|
||||||
|
Header = header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CompareTo(TimedFrameHeader other) => Time.CompareTo(other.Time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -20,7 +20,6 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
public class MultiplayerGameplayLeaderboard : GameplayLeaderboard
|
public class MultiplayerGameplayLeaderboard : GameplayLeaderboard
|
||||||
{
|
{
|
||||||
private readonly ScoreProcessor scoreProcessor;
|
private readonly ScoreProcessor scoreProcessor;
|
||||||
|
|
||||||
private readonly Dictionary<int, TrackedUserData> userScores = new Dictionary<int, TrackedUserData>();
|
private readonly Dictionary<int, TrackedUserData> userScores = new Dictionary<int, TrackedUserData>();
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
@ -116,13 +115,32 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
trackedData.UpdateScore(scoreProcessor, mode.NewValue);
|
trackedData.UpdateScore(scoreProcessor, mode.NewValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleIncomingFrames(int userId, FrameDataBundle bundle)
|
private void handleIncomingFrames(int userId, FrameDataBundle bundle) => Schedule(() =>
|
||||||
{
|
{
|
||||||
if (userScores.TryGetValue(userId, out var trackedData))
|
if (userScores.ContainsKey(userId))
|
||||||
{
|
OnIncomingFrames(userId, bundle);
|
||||||
trackedData.LastHeader = bundle.Header;
|
});
|
||||||
trackedData.UpdateScore(scoreProcessor, scoringMode.Value);
|
|
||||||
}
|
/// <summary>
|
||||||
|
/// Invoked when new frames have arrived for a user.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// By default, this immediately sets the current frame to be displayed for the user.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="userId">The user which the frames arrived for.</param>
|
||||||
|
/// <param name="bundle">The bundle of frames.</param>
|
||||||
|
protected virtual void OnIncomingFrames(int userId, FrameDataBundle bundle) => SetCurrentFrame(userId, bundle.Header);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the current frame to be displayed for a user.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">The user to set the frame of.</param>
|
||||||
|
/// <param name="header">The frame to set.</param>
|
||||||
|
protected void SetCurrentFrame(int userId, FrameHeader header)
|
||||||
|
{
|
||||||
|
var trackedScore = userScores[userId];
|
||||||
|
trackedScore.LastHeader = header;
|
||||||
|
trackedScore.UpdateScore(scoreProcessor, scoringMode.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
@ -17,7 +17,10 @@ namespace osu.Game.Screens.Play
|
|||||||
if (!(Beatmap.Value.BeatmapInfo.OnlineBeatmapID is int beatmapId))
|
if (!(Beatmap.Value.BeatmapInfo.OnlineBeatmapID is int beatmapId))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new CreateSoloScoreRequest(beatmapId, Game.VersionHash);
|
if (!(Ruleset.Value.ID is int rulesetId))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new CreateSoloScoreRequest(beatmapId, rulesetId, Game.VersionHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool HandleTokenRetrievalFailure(Exception exception) => false;
|
protected override bool HandleTokenRetrievalFailure(Exception exception) => false;
|
||||||
|
Loading…
Reference in New Issue
Block a user