1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 03:03:21 +08:00

Compare commits

...

13 Commits

Author SHA1 Message Date
Dean Herbert
7fdc274d03
Merge pull request #8029 from smoogipoo/better-room-participants
Implement new multiplayer participants retrieval
2020-02-28 22:40:03 +09:00
Dan Balasescu
c8436d988e
Merge pull request #8041 from peppy/update-framework
Update framework
2020-02-28 22:38:30 +09:00
Dean Herbert
394b88aa65 Add thread mode dropdown 2020-02-28 22:17:45 +09:00
Dean Herbert
4ad2d0cfb6 Remove deprecated debug setting 2020-02-28 22:17:45 +09:00
Dean Herbert
7b9937b851 Update framework 2020-02-28 22:15:39 +09:00
Dean Herbert
276f6da483
Merge branch 'master' into better-room-participants 2020-02-28 16:42:31 +09:00
smoogipoo
b3220476d7 Rename methods 2020-02-27 20:05:12 +09:00
smoogipoo
085968dd7f Rename recent participants 2020-02-27 20:00:53 +09:00
smoogipoo
22862256c1 Increase time between polls 2020-02-27 19:42:19 +09:00
smoogipoo
fe10a64137 Improve participants list transforms 2020-02-27 19:37:07 +09:00
smoogipoo
97c07281d8 Make ParticipantsList use the new participants property 2020-02-27 19:24:13 +09:00
smoogipoo
99442ec9c3 Implement single-room multiplayer room polling 2020-02-27 19:23:50 +09:00
smoogipoo
ffa8a50c6b Make User IEquatable 2020-02-27 19:21:59 +09:00
15 changed files with 296 additions and 132 deletions

View File

@ -52,6 +52,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.221.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2020.225.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2020.228.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,19 @@
// 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 osu.Game.Online.Multiplayer;
namespace osu.Game.Online.API.Requests
{
public class GetRoomRequest : APIRequest<Room>
{
private readonly int roomId;
public GetRoomRequest(int roomId)
{
this.roomId = roomId;
}
protected override string Target => $"rooms/{roomId}";
}
}

View File

@ -59,8 +59,8 @@ namespace osu.Game.Online.Multiplayer
public Bindable<int?> MaxParticipants { get; private set; } = new Bindable<int?>();
[Cached]
[JsonIgnore]
public BindableList<User> Participants { get; private set; } = new BindableList<User>();
[JsonProperty("recent_participants")]
public BindableList<User> RecentParticipants { get; private set; } = new BindableList<User>();
[Cached]
public Bindable<int> ParticipantCount { get; private set; } = new Bindable<int>();
@ -124,10 +124,10 @@ namespace osu.Game.Online.Multiplayer
Playlist.AddRange(other.Playlist);
}
if (!Participants.SequenceEqual(other.Participants))
if (!RecentParticipants.SequenceEqual(other.RecentParticipants))
{
Participants.Clear();
Participants.AddRange(other.Participants);
RecentParticipants.Clear();
RecentParticipants.AddRange(other.RecentParticipants);
}
Position = other.Position;

View File

@ -22,11 +22,6 @@ namespace osu.Game.Overlays.Settings.Sections.Debug
Bindable = frameworkConfig.GetBindable<bool>(FrameworkSetting.ShowLogOverlay)
},
new SettingsCheckbox
{
LabelText = "Performance logging",
Bindable = config.GetBindable<bool>(DebugSetting.PerformanceLogging)
},
new SettingsCheckbox
{
LabelText = "Bypass front-to-back render pass",
Bindable = config.GetBindable<bool>(DebugSetting.BypassFrontToBackPass)

View File

@ -4,6 +4,7 @@
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Game.Configuration;
namespace osu.Game.Overlays.Settings.Sections.Graphics
@ -24,6 +25,11 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
LabelText = "Frame limiter",
Bindable = config.GetBindable<FrameSync>(FrameworkSetting.FrameSync)
},
new SettingsEnumDropdown<ExecutionMode>
{
LabelText = "Threading mode",
Bindable = config.GetBindable<ExecutionMode>(FrameworkSetting.ExecutionMode)
},
new SettingsCheckbox
{
LabelText = "Show FPS",

View File

@ -16,7 +16,7 @@ namespace osu.Game.Screens.Multi.Components
}
public OverlinedParticipants(Direction direction)
: base("Participants")
: base("Recent participants")
{
OsuScrollContainer scroll;
ParticipantsList list;

View File

@ -1,15 +1,13 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Threading;
using osu.Game.Graphics;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Users;
using osu.Game.Users.Drawables;
using osuTK;
@ -26,7 +24,9 @@ namespace osu.Game.Screens.Multi.Components
set
{
base.RelativeSizeAxes = value;
fill.RelativeSizeAxes = value;
if (tiles != null)
tiles.RelativeSizeAxes = value;
}
}
@ -36,83 +36,75 @@ namespace osu.Game.Screens.Multi.Components
set
{
base.AutoSizeAxes = value;
fill.AutoSizeAxes = value;
if (tiles != null)
tiles.AutoSizeAxes = value;
}
}
private FillDirection direction = FillDirection.Full;
public FillDirection Direction
{
get => fill.Direction;
set => fill.Direction = value;
}
get => direction;
set
{
direction = value;
private readonly FillFlowContainer fill;
public ParticipantsList()
{
InternalChild = fill = new FillFlowContainer { Spacing = new Vector2(10) };
if (tiles != null)
tiles.Direction = value;
}
}
[BackgroundDependencyLoader]
private void load()
{
RoomID.BindValueChanged(_ => updateParticipants(), true);
RecentParticipants.CollectionChanged += (_, __) => updateParticipants();
updateParticipants();
}
[Resolved]
private IAPIProvider api { get; set; }
private GetRoomScoresRequest request;
private ScheduledDelegate scheduledUpdate;
private FillFlowContainer<UserTile> tiles;
private void updateParticipants()
{
var roomId = RoomID.Value ?? 0;
request?.Cancel();
// nice little progressive fade
int time = 500;
foreach (var c in fill.Children)
scheduledUpdate?.Cancel();
scheduledUpdate = Schedule(() =>
{
c.Delay(500 - time).FadeOut(time, Easing.Out);
time = Math.Max(20, time - 20);
c.Expire();
}
tiles?.FadeOut(250, Easing.Out).Expire();
if (roomId == 0) return;
tiles = new FillFlowContainer<UserTile>
{
Alpha = 0,
Direction = Direction,
AutoSizeAxes = AutoSizeAxes,
RelativeSizeAxes = RelativeSizeAxes,
Spacing = new Vector2(10)
};
request = new GetRoomScoresRequest(roomId);
request.Success += scores => Schedule(() =>
{
if (roomId != RoomID.Value)
return;
for (int i = 0; i < RecentParticipants.Count; i++)
tiles.Add(new UserTile { User = RecentParticipants[i] });
fill.Clear();
foreach (var s in scores)
fill.Add(new UserTile(s.User));
AddInternal(tiles);
fill.FadeInFromZero(1000, Easing.OutQuint);
tiles.Delay(250).FadeIn(250, Easing.OutQuint);
});
api.Queue(request);
}
protected override void Dispose(bool isDisposing)
{
request?.Cancel();
base.Dispose(isDisposing);
}
private class UserTile : CompositeDrawable, IHasTooltip
{
private readonly User user;
public string TooltipText => user.Username;
public UserTile(User user)
public User User
{
get => avatar.User;
set => avatar.User = value;
}
public string TooltipText => User?.Username ?? string.Empty;
private readonly UpdateableAvatar avatar;
public UserTile()
{
this.user = user;
Size = new Vector2(TILE_SIZE);
CornerRadius = 5f;
Masking = true;
@ -124,11 +116,7 @@ namespace osu.Game.Screens.Multi.Components
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"27252d"),
},
new UpdateableAvatar
{
RelativeSizeAxes = Axes.Both,
User = user,
},
avatar = new UpdateableAvatar { RelativeSizeAxes = Axes.Both },
};
}
}

View File

@ -28,7 +28,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
private Bindable<FilterCriteria> filter { get; set; }
[Resolved]
private Bindable<Room> currentRoom { get; set; }
private Bindable<Room> selectedRoom { get; set; }
[Resolved]
private IRoomManager roomManager { get; set; }
@ -122,7 +122,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
else
roomFlow.Children.ForEach(r => r.State = r.Room == room ? SelectionState.Selected : SelectionState.NotSelected);
currentRoom.Value = room;
selectedRoom.Value = room;
}
protected override void Dispose(bool isDisposing)

View File

@ -26,7 +26,7 @@ namespace osu.Game.Screens.Multi.Lounge
private readonly LoadingLayer loadingLayer;
[Resolved]
private Bindable<Room> currentRoom { get; set; }
private Bindable<Room> selectedRoom { get; set; }
public LoungeSubScreen()
{
@ -101,8 +101,8 @@ namespace osu.Game.Screens.Multi.Lounge
{
base.OnResuming(last);
if (currentRoom.Value?.RoomID.Value == null)
currentRoom.Value = new Room();
if (selectedRoom.Value?.RoomID.Value == null)
selectedRoom.Value = new Room();
onReturning();
}
@ -143,7 +143,7 @@ namespace osu.Game.Screens.Multi.Lounge
if (!this.IsCurrentScreen())
return;
currentRoom.Value = room;
selectedRoom.Value = room;
this.Push(new MatchSubScreen(room));
}

View File

@ -48,7 +48,7 @@ namespace osu.Game.Screens.Multi
private readonly IBindable<bool> isIdle = new BindableBool();
[Cached]
private readonly Bindable<Room> currentRoom = new Bindable<Room>();
private readonly Bindable<Room> selectedRoom = new Bindable<Room>();
[Cached]
private readonly Bindable<FilterCriteria> currentFilter = new Bindable<FilterCriteria>(new FilterCriteria());
@ -163,14 +163,39 @@ namespace osu.Game.Screens.Multi
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new CachedModelDependencyContainer<Room>(base.CreateChildDependencies(parent));
dependencies.Model.BindTo(currentRoom);
dependencies.Model.BindTo(selectedRoom);
return dependencies;
}
private void updatePollingRate(bool idle)
{
roomManager.TimeBetweenPolls = !this.IsCurrentScreen() || !(screenStack.CurrentScreen is LoungeSubScreen) ? 0 : (idle ? 120000 : 15000);
Logger.Log($"Polling adjusted to {roomManager.TimeBetweenPolls}");
if (!this.IsCurrentScreen())
{
roomManager.TimeBetweenListingPolls = 0;
roomManager.TimeBetweenSelectionPolls = 0;
}
else
{
switch (screenStack.CurrentScreen)
{
case LoungeSubScreen _:
roomManager.TimeBetweenListingPolls = idle ? 120000 : 15000;
roomManager.TimeBetweenSelectionPolls = idle ? 120000 : 15000;
break;
case MatchSubScreen _:
roomManager.TimeBetweenListingPolls = 0;
roomManager.TimeBetweenSelectionPolls = idle ? 30000 : 5000;
break;
default:
roomManager.TimeBetweenListingPolls = 0;
roomManager.TimeBetweenSelectionPolls = 0;
break;
}
}
Logger.Log($"Polling adjusted (listing: {roomManager.TimeBetweenListingPolls}, selection: {roomManager.TimeBetweenSelectionPolls})");
}
/// <summary>
@ -222,6 +247,8 @@ namespace osu.Game.Screens.Multi
base.OnResuming(last);
beginHandlingTrack();
updatePollingRate(isIdle.Value);
}
public override void OnSuspending(IScreen next)
@ -231,7 +258,7 @@ namespace osu.Game.Screens.Multi
endHandlingTrack();
roomManager.TimeBetweenPolls = 0;
updatePollingRate(isIdle.Value);
}
public override bool OnExiting(IScreen next)

View File

@ -31,7 +31,7 @@ namespace osu.Game.Screens.Multi
protected BindableList<PlaylistItem> Playlist { get; private set; }
[Resolved(typeof(Room))]
protected BindableList<User> Participants { get; private set; }
protected BindableList<User> RecentParticipants { get; private set; }
[Resolved(typeof(Room))]
protected Bindable<int> ParticipantCount { get; private set; }

View File

@ -2,10 +2,13 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
using osu.Game.Beatmaps;
using osu.Game.Online;
@ -17,20 +20,24 @@ using osu.Game.Screens.Multi.Lounge.Components;
namespace osu.Game.Screens.Multi
{
public class RoomManager : PollingComponent, IRoomManager
public class RoomManager : CompositeDrawable, IRoomManager
{
public event Action RoomsUpdated;
private readonly BindableList<Room> rooms = new BindableList<Room>();
public IBindableList<Room> Rooms => rooms;
private Room joinedRoom;
public double TimeBetweenListingPolls
{
get => listingPollingComponent.TimeBetweenPolls;
set => listingPollingComponent.TimeBetweenPolls = value;
}
[Resolved]
private Bindable<FilterCriteria> currentFilter { get; set; }
[Resolved]
private IAPIProvider api { get; set; }
public double TimeBetweenSelectionPolls
{
get => selectionPollingComponent.TimeBetweenPolls;
set => selectionPollingComponent.TimeBetweenPolls = value;
}
[Resolved]
private RulesetStore rulesets { get; set; }
@ -38,14 +45,26 @@ namespace osu.Game.Screens.Multi
[Resolved]
private BeatmapManager beatmaps { get; set; }
[BackgroundDependencyLoader]
private void load()
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private Bindable<Room> selectedRoom { get; set; }
private readonly ListingPollingComponent listingPollingComponent;
private readonly SelectionPollingComponent selectionPollingComponent;
private Room joinedRoom;
public RoomManager()
{
currentFilter.BindValueChanged(_ =>
RelativeSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
if (IsLoaded)
PollImmediately();
});
listingPollingComponent = new ListingPollingComponent { RoomsReceived = onListingReceived },
selectionPollingComponent = new SelectionPollingComponent { RoomReceived = onSelectedRoomReceived }
};
}
protected override void Dispose(bool isDisposing)
@ -116,45 +135,52 @@ namespace osu.Game.Screens.Multi
joinedRoom = null;
}
private GetRoomsRequest pollReq;
protected override Task Poll()
/// <summary>
/// Invoked when the listing of all <see cref="Room"/>s is received from the server.
/// </summary>
/// <param name="listing">The listing.</param>
private void onListingReceived(List<Room> listing)
{
if (!api.IsLoggedIn)
return base.Poll();
var tcs = new TaskCompletionSource<bool>();
pollReq?.Cancel();
pollReq = new GetRoomsRequest(currentFilter.Value.PrimaryFilter);
pollReq.Success += result =>
// Remove past matches
foreach (var r in rooms.ToList())
{
// Remove past matches
foreach (var r in rooms.ToList())
if (listing.All(e => e.RoomID.Value != r.RoomID.Value))
rooms.Remove(r);
}
for (int i = 0; i < listing.Count; i++)
{
if (selectedRoom.Value?.RoomID?.Value == listing[i].RoomID.Value)
{
if (result.All(e => e.RoomID.Value != r.RoomID.Value))
rooms.Remove(r);
// The listing request contains less data than the selection request, so data from the selection request is always preferred while the room is selected.
continue;
}
for (int i = 0; i < result.Count; i++)
var r = listing[i];
r.Position.Value = i;
update(r, r);
addRoom(r);
}
RoomsUpdated?.Invoke();
}
/// <summary>
/// Invoked when a <see cref="Room"/> is received from the server.
/// </summary>
/// <param name="toUpdate">The received <see cref="Room"/>.</param>
private void onSelectedRoomReceived(Room toUpdate)
{
foreach (var room in rooms)
{
if (room.RoomID.Value == toUpdate.RoomID.Value)
{
var r = result[i];
r.Position.Value = i;
update(r, r);
addRoom(r);
toUpdate.Position.Value = room.Position.Value;
update(room, toUpdate);
break;
}
RoomsUpdated?.Invoke();
tcs.SetResult(true);
};
pollReq.Failure += _ => tcs.SetResult(false);
api.Queue(pollReq);
return tcs.Task;
}
}
/// <summary>
@ -182,5 +208,100 @@ namespace osu.Game.Screens.Multi
else
existing.CopyFrom(room);
}
private class SelectionPollingComponent : PollingComponent
{
public Action<Room> RoomReceived;
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private Bindable<Room> selectedRoom { get; set; }
[BackgroundDependencyLoader]
private void load()
{
selectedRoom.BindValueChanged(_ =>
{
if (IsLoaded)
PollImmediately();
});
}
private GetRoomRequest pollReq;
protected override Task Poll()
{
if (!api.IsLoggedIn)
return base.Poll();
if (selectedRoom.Value?.RoomID.Value == null)
return base.Poll();
var tcs = new TaskCompletionSource<bool>();
pollReq?.Cancel();
pollReq = new GetRoomRequest(selectedRoom.Value.RoomID.Value.Value);
pollReq.Success += result =>
{
RoomReceived?.Invoke(result);
tcs.SetResult(true);
};
pollReq.Failure += _ => tcs.SetResult(false);
api.Queue(pollReq);
return tcs.Task;
}
}
private class ListingPollingComponent : PollingComponent
{
public Action<List<Room>> RoomsReceived;
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private Bindable<FilterCriteria> currentFilter { get; set; }
[BackgroundDependencyLoader]
private void load()
{
currentFilter.BindValueChanged(_ =>
{
if (IsLoaded)
PollImmediately();
});
}
private GetRoomsRequest pollReq;
protected override Task Poll()
{
if (!api.IsLoggedIn)
return base.Poll();
var tcs = new TaskCompletionSource<bool>();
pollReq?.Cancel();
pollReq = new GetRoomsRequest(currentFilter.Value.PrimaryFilter);
pollReq.Success += result =>
{
RoomsReceived?.Invoke(result);
tcs.SetResult(true);
};
pollReq.Failure += _ => tcs.SetResult(false);
api.Queue(pollReq);
return tcs.Task;
}
}
}
}

View File

@ -9,7 +9,7 @@ using osu.Framework.Bindables;
namespace osu.Game.Users
{
public class User
public class User : IEquatable<User>
{
[JsonProperty(@"id")]
public long Id = 1;
@ -244,5 +244,13 @@ namespace osu.Game.Users
[Description("Touch Screen")]
Touch,
}
public bool Equals(User other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Id == other.Id;
}
}
}

View File

@ -23,7 +23,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.221.0" />
<PackageReference Include="ppy.osu.Framework" Version="2020.225.0" />
<PackageReference Include="ppy.osu.Framework" Version="2020.228.0" />
<PackageReference Include="Sentry" Version="2.0.3" />
<PackageReference Include="SharpCompress" Version="0.24.0" />
<PackageReference Include="NUnit" Version="3.12.0" />

View File

@ -71,7 +71,7 @@
</ItemGroup>
<ItemGroup Label="Package References">
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.221.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2020.225.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2020.228.0" />
</ItemGroup>
<!-- Xamarin.iOS does not automatically handle transitive dependencies from NuGet packages. -->
<ItemGroup Label="Transitive Dependencies">
@ -79,7 +79,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.225.0" />
<PackageReference Include="ppy.osu.Framework" Version="2020.228.0" />
<PackageReference Include="SharpCompress" Version="0.24.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />