1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 15:42:54 +08:00
osu-lazer/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimeMultiplayer.cs
2020-12-20 23:36:56 +09:00

68 lines
2.3 KiB
C#

// 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.Framework.Allocation;
using osu.Framework.Logging;
using osu.Framework.Screens;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.RealtimeMultiplayer;
using osu.Game.Screens.Multi.Components;
using osu.Game.Screens.Multi.Lounge;
namespace osu.Game.Screens.Multi.RealtimeMultiplayer
{
public class RealtimeMultiplayer : Multiplayer
{
[Resolved]
private StatefulMultiplayerClient client { get; set; }
public override void OnResuming(IScreen last)
{
base.OnResuming(last);
if (client.Room != null)
client.ChangeState(MultiplayerUserState.Idle);
}
protected override void UpdatePollingRate(bool isIdle)
{
var timeshiftManager = (RealtimeRoomManager)RoomManager;
if (!this.IsCurrentScreen())
{
timeshiftManager.TimeBetweenListingPolls.Value = 0;
timeshiftManager.TimeBetweenSelectionPolls.Value = 0;
}
else
{
switch (CurrentSubScreen)
{
case LoungeSubScreen _:
timeshiftManager.TimeBetweenListingPolls.Value = isIdle ? 120000 : 15000;
timeshiftManager.TimeBetweenSelectionPolls.Value = isIdle ? 120000 : 15000;
break;
// Don't poll inside the match or anywhere else.
default:
timeshiftManager.TimeBetweenListingPolls.Value = 0;
timeshiftManager.TimeBetweenSelectionPolls.Value = 0;
break;
}
}
Logger.Log($"Polling adjusted (listing: {timeshiftManager.TimeBetweenListingPolls.Value}, selection: {timeshiftManager.TimeBetweenSelectionPolls.Value})");
}
protected override Room CreateNewRoom()
{
var room = base.CreateNewRoom();
room.Category.Value = RoomCategory.Realtime;
return room;
}
protected override RoomManager CreateRoomManager() => new RealtimeRoomManager();
protected override LoungeSubScreen CreateLounge() => new RealtimeLoungeSubScreen();
}
}