mirror of
https://github.com/ppy/osu.git
synced 2025-03-11 01:07:23 +08:00
Arrays instead of enumerables
This commit is contained in:
parent
8a27b6689e
commit
3b5bf391da
@ -4,7 +4,6 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
@ -415,19 +414,19 @@ namespace osu.Game.Tests.Visual.Ranking
|
||||
RetryOverlay = InternalChildren.OfType<HotkeyRetryOverlay>().SingleOrDefault();
|
||||
}
|
||||
|
||||
protected override Task<IEnumerable<ScoreInfo>> FetchScores()
|
||||
protected override Task<ScoreInfo[]> FetchScores()
|
||||
{
|
||||
var scores = new List<ScoreInfo>();
|
||||
var scores = new ScoreInfo[20];
|
||||
|
||||
for (int i = 0; i < 20; i++)
|
||||
for (int i = 0; i < scores.Length; i++)
|
||||
{
|
||||
var score = TestResources.CreateTestScoreInfo();
|
||||
score.TotalScore += 10 - i;
|
||||
score.HasOnlineReplay = true;
|
||||
scores.Add(score);
|
||||
scores[i] = score;
|
||||
}
|
||||
|
||||
return Task.FromResult<IEnumerable<ScoreInfo>>(scores);
|
||||
return Task.FromResult(scores);
|
||||
}
|
||||
}
|
||||
|
||||
@ -443,19 +442,19 @@ namespace osu.Game.Tests.Visual.Ranking
|
||||
this.fetchWaitTask = fetchWaitTask ?? Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected override Task<IEnumerable<ScoreInfo>> FetchScores()
|
||||
protected override Task<ScoreInfo[]> FetchScores()
|
||||
{
|
||||
return Task.Run<IEnumerable<ScoreInfo>>(async () =>
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
await fetchWaitTask;
|
||||
|
||||
var scores = new List<ScoreInfo>();
|
||||
var scores = new ScoreInfo[20];
|
||||
|
||||
for (int i = 0; i < 20; i++)
|
||||
for (int i = 0; i < scores.Length; i++)
|
||||
{
|
||||
var score = TestResources.CreateTestScoreInfo();
|
||||
score.TotalScore += 10 - i;
|
||||
scores.Add(score);
|
||||
scores[i] = score;
|
||||
}
|
||||
|
||||
Schedule(() => FetchCompleted = true);
|
||||
|
@ -1,7 +1,6 @@
|
||||
// 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.Threading.Tasks;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.Play;
|
||||
@ -22,8 +21,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
Scheduler.AddDelayed(() => StatisticsPanel.ToggleVisibility(), 1000);
|
||||
}
|
||||
|
||||
protected override Task<IEnumerable<ScoreInfo>> FetchScores() => Task.FromResult<IEnumerable<ScoreInfo>>([]);
|
||||
protected override Task<ScoreInfo[]> FetchScores() => Task.FromResult<ScoreInfo[]>([]);
|
||||
|
||||
protected override Task<IEnumerable<ScoreInfo>> FetchNextPage(int direction) => Task.FromResult<IEnumerable<ScoreInfo>>([]);
|
||||
protected override Task<ScoreInfo[]> FetchNextPage(int direction) => Task.FromResult<ScoreInfo[]>([]);
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
|
||||
protected abstract APIRequest<MultiplayerScore> CreateScoreRequest();
|
||||
|
||||
protected override async Task<IEnumerable<ScoreInfo>> FetchScores()
|
||||
protected override async Task<ScoreInfo[]> FetchScores()
|
||||
{
|
||||
// This performs two requests:
|
||||
// 1. A request to show the relevant score (and scores around).
|
||||
@ -141,7 +141,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task<IEnumerable<ScoreInfo>> FetchNextPage(int direction)
|
||||
protected override async Task<ScoreInfo[]> FetchNextPage(int direction)
|
||||
{
|
||||
Debug.Assert(direction == 1 || direction == -1);
|
||||
|
||||
@ -165,7 +165,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
/// </summary>
|
||||
/// <remarks>Does not queue the request.</remarks>
|
||||
/// <param name="pivot">An optional score pivot to retrieve scores around. Can be null to retrieve scores from the highest score.</param>
|
||||
private async Task<IEnumerable<ScoreInfo>> fetchScoresAround(MultiplayerScores? pivot = null)
|
||||
private async Task<ScoreInfo[]> fetchScoresAround(MultiplayerScores? pivot = null)
|
||||
{
|
||||
var requestTaskSource = new TaskCompletionSource<IndexedMultiplayerScores>();
|
||||
var indexReq = pivot != null
|
||||
|
@ -1,7 +1,6 @@
|
||||
// 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 osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
@ -30,7 +29,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
|
||||
protected override APIRequest<MultiplayerScore> CreateScoreRequest() => new ShowPlaylistScoreRequest(RoomId, PlaylistItem.ID, scoreId);
|
||||
|
||||
protected override void OnScoresAdded(IEnumerable<ScoreInfo> scores)
|
||||
protected override void OnScoresAdded(ScoreInfo[] scores)
|
||||
{
|
||||
base.OnScoresAdded(scores);
|
||||
SelectedScore.Value ??= scores.SingleOrDefault(s => s.OnlineID == scoreId);
|
||||
|
@ -1,7 +1,6 @@
|
||||
// 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 osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
@ -24,7 +23,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
|
||||
protected override APIRequest<MultiplayerScore> CreateScoreRequest() => new ShowPlaylistUserScoreRequest(RoomId, PlaylistItem.ID, userId);
|
||||
|
||||
protected override void OnScoresAdded(IEnumerable<ScoreInfo> scores)
|
||||
protected override void OnScoresAdded(ScoreInfo[] scores)
|
||||
{
|
||||
base.OnScoresAdded(scores);
|
||||
|
||||
|
@ -246,7 +246,7 @@ namespace osu.Game.Screens.Ranking
|
||||
|
||||
if (lastFetchCompleted)
|
||||
{
|
||||
Task<IEnumerable<ScoreInfo>> nextPageTask = Task.FromResult<IEnumerable<ScoreInfo>>([]);
|
||||
Task<ScoreInfo[]> nextPageTask = Task.FromResult<ScoreInfo[]>([]);
|
||||
|
||||
if (ScorePanelList.IsScrolledToStart)
|
||||
nextPageTask = FetchNextPage(-1);
|
||||
@ -322,13 +322,13 @@ namespace osu.Game.Screens.Ranking
|
||||
/// <summary>
|
||||
/// Performs a fetch/refresh of scores to be displayed.
|
||||
/// </summary>
|
||||
protected virtual Task<IEnumerable<ScoreInfo>> FetchScores() => Task.FromResult<IEnumerable<ScoreInfo>>([]);
|
||||
protected virtual Task<ScoreInfo[]> FetchScores() => Task.FromResult<ScoreInfo[]>([]);
|
||||
|
||||
/// <summary>
|
||||
/// Performs a fetch of the next page of scores. This is invoked every frame.
|
||||
/// </summary>
|
||||
/// <param name="direction">The fetch direction. -1 to fetch scores greater than the current start of the list, and 1 to fetch scores lower than the current end of the list.</param>
|
||||
protected virtual Task<IEnumerable<ScoreInfo>> FetchNextPage(int direction) => Task.FromResult<IEnumerable<ScoreInfo>>([]);
|
||||
protected virtual Task<ScoreInfo[]> FetchNextPage(int direction) => Task.FromResult<ScoreInfo[]>([]);
|
||||
|
||||
/// <summary>
|
||||
/// Creates the <see cref="Statistics.StatisticsPanel"/> to be used to display extended information about scores.
|
||||
@ -340,7 +340,7 @@ namespace osu.Game.Screens.Ranking
|
||||
: new StatisticsPanel();
|
||||
}
|
||||
|
||||
private void addScores(IEnumerable<ScoreInfo> scores) => Schedule(() =>
|
||||
private void addScores(ScoreInfo[] scores) => Schedule(() =>
|
||||
{
|
||||
foreach (var s in scores)
|
||||
{
|
||||
@ -365,7 +365,7 @@ namespace osu.Game.Screens.Ranking
|
||||
/// Invoked after online scores are fetched and added to the list.
|
||||
/// </summary>
|
||||
/// <param name="scores">The scores that were added.</param>
|
||||
protected virtual void OnScoresAdded(IEnumerable<ScoreInfo> scores)
|
||||
protected virtual void OnScoresAdded(ScoreInfo[] scores)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ namespace osu.Game.Screens.Ranking
|
||||
{
|
||||
}
|
||||
|
||||
protected override async Task<IEnumerable<ScoreInfo>> FetchScores()
|
||||
protected override async Task<ScoreInfo[]> FetchScores()
|
||||
{
|
||||
Debug.Assert(Score != null);
|
||||
|
||||
@ -70,7 +70,7 @@ namespace osu.Game.Screens.Ranking
|
||||
}
|
||||
}
|
||||
|
||||
return toDisplay;
|
||||
return toDisplay.ToArray();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user