1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 11:42:56 +08:00

Merge branch 'master' into dho-apply

This commit is contained in:
smoogipoo 2020-11-10 01:30:45 +09:00
commit 0bab5605d1
22 changed files with 261 additions and 62 deletions

View File

@ -52,6 +52,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.1030.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2020.1105.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2020.1109.0" />
</ItemGroup>
</Project>

View File

@ -130,7 +130,7 @@ namespace osu.Desktop
switch (host.Window)
{
// Legacy osuTK DesktopGameWindow
case DesktopGameWindow desktopGameWindow:
case OsuTKDesktopWindow desktopGameWindow:
desktopGameWindow.CursorState |= CursorState.Hidden;
desktopGameWindow.SetIconFromStream(iconStream);
desktopGameWindow.Title = Name;

View File

@ -75,7 +75,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
public override bool HandleQuickDeletion()
{
var hoveredControlPoint = ControlPointVisualiser.Pieces.FirstOrDefault(p => p.IsHovered);
var hoveredControlPoint = ControlPointVisualiser?.Pieces.FirstOrDefault(p => p.IsHovered);
if (hoveredControlPoint == null)
return false;

View File

@ -37,6 +37,12 @@ namespace osu.Game.Tests.Editing
}));
}
[Test]
public void TestPatchNoObjectChanges()
{
runTest(new OsuBeatmap());
}
[Test]
public void TestAddHitObject()
{

View File

@ -2,12 +2,14 @@
// See the LICENCE file in the repository root for full licence text.
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.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Database;
using osu.Game.Online.Spectator;
using osu.Game.Overlays.Dashboard;
using osu.Game.Tests.Visual.Gameplay;
@ -22,32 +24,34 @@ namespace osu.Game.Tests.Visual.Online
private CurrentlyPlayingDisplay currentlyPlaying;
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
[Cached(typeof(UserLookupCache))]
private UserLookupCache lookupCache = new TestUserLookupCache();
private Container nestedContainer;
[SetUpSteps]
public void SetUpSteps()
{
AddStep("register request handling", () => dummyAPI.HandleRequest = req =>
{
switch (req)
{
case GetUserRequest cRequest:
cRequest.TriggerSuccess(new User { Username = "peppy", Id = 2 });
break;
}
});
AddStep("add streaming client", () =>
{
Remove(testSpectatorStreamingClient);
nestedContainer?.Remove(testSpectatorStreamingClient);
Remove(lookupCache);
Children = new Drawable[]
{
testSpectatorStreamingClient,
currentlyPlaying = new CurrentlyPlayingDisplay
lookupCache,
nestedContainer = new Container
{
RelativeSizeAxes = Axes.Both,
}
Children = new Drawable[]
{
testSpectatorStreamingClient,
currentlyPlaying = new CurrentlyPlayingDisplay
{
RelativeSizeAxes = Axes.Both,
}
}
},
};
});
@ -62,5 +66,11 @@ namespace osu.Game.Tests.Visual.Online
AddStep("Remove playing user", () => testSpectatorStreamingClient.PlayingUsers.Remove(2));
AddUntilStep("Panel no longer present", () => !currentlyPlaying.ChildrenOfType<UserGridPanel>().Any());
}
internal class TestUserLookupCache : UserLookupCache
{
protected override Task<User> ComputeValueAsync(int lookup, CancellationToken token = default)
=> Task.FromResult(new User { Username = "peppy", Id = 2 });
}
}
}

View File

@ -202,7 +202,9 @@ namespace osu.Game.Beatmaps
/// <param name="cancellationToken">A token that may be used to cancel this update.</param>
private void updateBindable([NotNull] BindableStarDifficulty bindable, [CanBeNull] RulesetInfo rulesetInfo, [CanBeNull] IEnumerable<Mod> mods, CancellationToken cancellationToken = default)
{
GetAsync(new DifficultyCacheLookup(bindable.Beatmap, rulesetInfo, mods), cancellationToken)
// GetDifficultyAsync will fall back to existing data from BeatmapInfo if not locally available
// (contrary to GetAsync)
GetDifficultyAsync(bindable.Beatmap, rulesetInfo, mods, cancellationToken)
.ContinueWith(t =>
{
// We're on a threadpool thread, but we should exit back to the update thread so consumers can safely handle value-changed events.

View File

@ -235,11 +235,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleHitObjects(TextWriter writer)
{
writer.WriteLine("[HitObjects]");
if (beatmap.HitObjects.Count == 0)
return;
writer.WriteLine("[HitObjects]");
foreach (var h in beatmap.HitObjects)
handleHitObject(writer, h);
}

View File

@ -0,0 +1,117 @@
// 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 System.Threading;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Users;
namespace osu.Game.Database
{
public class UserLookupCache : MemoryCachingComponent<int, User>
{
private readonly HashSet<int> nextTaskIDs = new HashSet<int>();
[Resolved]
private IAPIProvider api { get; set; }
private readonly object taskAssignmentLock = new object();
private Task<List<User>> pendingRequest;
/// <summary>
/// Whether <see cref="pendingRequest"/> has already grabbed its IDs.
/// </summary>
private bool pendingRequestConsumedIDs;
public Task<User> GetUserAsync(int userId, CancellationToken token = default) => GetAsync(userId, token);
protected override async Task<User> ComputeValueAsync(int lookup, CancellationToken token = default)
{
var users = await getQueryTaskForUser(lookup);
return users.FirstOrDefault(u => u.Id == lookup);
}
/// <summary>
/// Return the task responsible for fetching the provided user.
/// This may be part of a larger batch lookup to reduce web requests.
/// </summary>
/// <param name="userId">The user to lookup.</param>
/// <returns>The task responsible for the lookup.</returns>
private Task<List<User>> getQueryTaskForUser(int userId)
{
lock (taskAssignmentLock)
{
nextTaskIDs.Add(userId);
// if there's a pending request which hasn't been started yet (and is not yet full), we can wait on it.
if (pendingRequest != null && !pendingRequestConsumedIDs && nextTaskIDs.Count < 50)
return pendingRequest;
return queueNextTask(nextLookup);
}
List<User> nextLookup()
{
int[] lookupItems;
lock (taskAssignmentLock)
{
pendingRequestConsumedIDs = true;
lookupItems = nextTaskIDs.ToArray();
nextTaskIDs.Clear();
if (lookupItems.Length == 0)
{
queueNextTask(null);
return new List<User>();
}
}
var request = new GetUsersRequest(lookupItems);
// rather than queueing, we maintain our own single-threaded request stream.
api.Perform(request);
return request.Result?.Users;
}
}
/// <summary>
/// Queues new work at the end of the current work tasks.
/// Ensures the provided work is eventually run.
/// </summary>
/// <param name="work">The work to run. Can be null to signify the end of available work.</param>
/// <returns>The task tracking this work.</returns>
private Task<List<User>> queueNextTask(Func<List<User>> work)
{
lock (taskAssignmentLock)
{
if (work == null)
{
pendingRequest = null;
pendingRequestConsumedIDs = false;
}
else if (pendingRequest == null)
{
// special case for the first request ever.
pendingRequest = Task.Run(work);
pendingRequestConsumedIDs = false;
}
else
{
// append the new request on to the last to be executed.
pendingRequest = pendingRequest.ContinueWith(_ => work());
pendingRequestConsumedIDs = false;
}
return pendingRequest;
}
}
}
}

View File

@ -0,0 +1,10 @@
// 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.
namespace osu.Game.Online.API.Requests
{
public class GetTopUsersRequest : APIRequest<GetTopUsersResponse>
{
protected override string Target => @"rankings/osu/performance";
}
}

View File

@ -0,0 +1,15 @@
// 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 Newtonsoft.Json;
using osu.Game.Users;
namespace osu.Game.Online.API.Requests
{
public class GetTopUsersResponse : ResponseWithCursor
{
[JsonProperty("ranking")]
public List<UserStatistics> Users;
}
}

View File

@ -6,7 +6,7 @@ using osu.Game.Rulesets;
namespace osu.Game.Online.API.Requests
{
public class GetUserRankingsRequest : GetRankingsRequest<GetUsersResponse>
public class GetUserRankingsRequest : GetRankingsRequest<GetTopUsersResponse>
{
public readonly UserRankingsType Type;

View File

@ -1,10 +1,24 @@
// 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.
using System;
namespace osu.Game.Online.API.Requests
{
public class GetUsersRequest : APIRequest<GetUsersResponse>
{
protected override string Target => @"rankings/osu/performance";
private readonly int[] userIds;
private const int max_ids_per_request = 50;
public GetUsersRequest(int[] userIds)
{
if (userIds.Length > max_ids_per_request)
throw new ArgumentException($"{nameof(GetUsersRequest)} calls only support up to {max_ids_per_request} IDs at once");
this.userIds = userIds;
}
protected override string Target => "users/?ids[]=" + string.Join("&ids[]=", userIds);
}
}

View File

@ -9,7 +9,7 @@ namespace osu.Game.Online.API.Requests
{
public class GetUsersResponse : ResponseWithCursor
{
[JsonProperty("ranking")]
public List<UserStatistics> Users;
[JsonProperty("users")]
public List<User> Users;
}
}

View File

@ -61,6 +61,8 @@ namespace osu.Game
protected BeatmapDifficultyCache DifficultyCache;
protected UserLookupCache UserCache;
protected SkinManager SkinManager;
protected RulesetStore RulesetStore;
@ -229,6 +231,9 @@ namespace osu.Game
dependencies.Cache(DifficultyCache = new BeatmapDifficultyCache());
AddInternal(DifficultyCache);
dependencies.Cache(UserCache = new UserLookupCache());
AddInternal(UserCache);
var scorePerformanceManager = new ScorePerformanceCache();
dependencies.Cache(scorePerformanceManager);
AddInternal(scorePerformanceManager);

View File

@ -8,8 +8,8 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Game.Database;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Spectator;
using osu.Game.Screens.Multi.Match.Components;
using osu.Game.Screens.Play;
@ -37,6 +37,7 @@ namespace osu.Game.Overlays.Dashboard
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(10),
Spacing = new Vector2(10),
};
}
@ -44,41 +45,52 @@ namespace osu.Game.Overlays.Dashboard
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private UserLookupCache users { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
playingUsers.BindTo(spectatorStreaming.PlayingUsers);
playingUsers.BindCollectionChanged((sender, e) => Schedule(() =>
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (var u in e.NewItems.OfType<int>())
{
var request = new GetUserRequest(u);
request.Success += user => Schedule(() =>
{
if (playingUsers.Contains(user.Id))
userFlow.Add(createUserPanel(user));
});
api.Queue(request);
}
break;
case NotifyCollectionChangedAction.Remove:
foreach (var u in e.OldItems.OfType<int>())
userFlow.FirstOrDefault(card => card.User.Id == u)?.Expire();
break;
case NotifyCollectionChangedAction.Reset:
userFlow.Clear();
break;
}
}), true);
playingUsers.BindCollectionChanged(onUsersChanged, true);
}
private void onUsersChanged(object sender, NotifyCollectionChangedEventArgs e) => Schedule(() =>
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (var id in e.NewItems.OfType<int>().ToArray())
{
users.GetUserAsync(id).ContinueWith(u =>
{
if (u.Result == null) return;
Schedule(() =>
{
// user may no longer be playing.
if (!playingUsers.Contains(u.Result.Id))
return;
userFlow.Add(createUserPanel(u.Result));
});
});
}
break;
case NotifyCollectionChangedAction.Remove:
foreach (var u in e.OldItems.OfType<int>())
userFlow.FirstOrDefault(card => card.User.Id == u)?.Expire();
break;
case NotifyCollectionChangedAction.Reset:
userFlow.Clear();
break;
}
});
private PlayingUserPanel createUserPanel(User user) =>
new PlayingUserPanel(user).With(panel =>
{

View File

@ -131,8 +131,7 @@ namespace osu.Game.Overlays
break;
case DashboardOverlayTabs.CurrentlyPlaying:
//todo: enable once caching logic is better
//loadDisplay(new CurrentlyPlayingDisplay());
loadDisplay(new CurrentlyPlayingDisplay());
break;
default:

View File

@ -20,6 +20,7 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
{
base.LoadBeatmap(beatmap);
controlPointGroups.UnbindAll();
controlPointGroups.BindTo(beatmap.Beatmap.ControlPointInfo.Groups);
controlPointGroups.BindCollectionChanged((sender, args) =>
{

View File

@ -27,6 +27,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
base.LoadBeatmap(beatmap);
controlPointGroups.UnbindAll();
controlPointGroups.BindTo(beatmap.Beatmap.ControlPointInfo.Groups);
controlPointGroups.BindCollectionChanged((sender, args) =>
{

View File

@ -499,6 +499,9 @@ namespace osu.Game.Screens.Edit
// confirming exit without save means we should delete the new beatmap completely.
beatmapManager.Delete(playableBeatmap.BeatmapInfo.BeatmapSet);
// eagerly clear contents before restoring default beatmap to prevent value change callbacks from firing.
ClearInternal();
// in theory this shouldn't be required but due to EF core not sharing instance states 100%
// MusicController is unaware of the changed DeletePending state.
Beatmap.SetDefault();

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using DiffPlex;
@ -35,6 +36,9 @@ namespace osu.Game.Screens.Edit
int oldHitObjectsIndex = Array.IndexOf(result.PiecesOld, "[HitObjects]");
int newHitObjectsIndex = Array.IndexOf(result.PiecesNew, "[HitObjects]");
Debug.Assert(oldHitObjectsIndex >= 0);
Debug.Assert(newHitObjectsIndex >= 0);
var toRemove = new List<int>();
var toAdd = new List<int>();

View File

@ -26,7 +26,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Framework" Version="2020.1105.0" />
<PackageReference Include="ppy.osu.Framework" Version="2020.1109.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.1030.0" />
<PackageReference Include="Sentry" Version="2.1.6" />
<PackageReference Include="SharpCompress" Version="0.26.0" />

View File

@ -70,7 +70,7 @@
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup Label="Package References">
<PackageReference Include="ppy.osu.Framework.iOS" Version="2020.1105.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2020.1109.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.1030.0" />
</ItemGroup>
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) -->
@ -88,7 +88,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Framework" Version="2020.1105.0" />
<PackageReference Include="ppy.osu.Framework" Version="2020.1109.0" />
<PackageReference Include="SharpCompress" Version="0.26.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />