Skip to content

Commit

Permalink
Refactor polling components (namespace/namings)
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Feb 12, 2025
1 parent 43928c9 commit 24cc772
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
3 changes: 1 addition & 2 deletions osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
using osu.Game.Rulesets.Taiko;
using osu.Game.Scoring;
using osu.Game.Screens.OnlinePlay;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Lounge;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
using osu.Game.Screens.OnlinePlay.Match;
Expand Down Expand Up @@ -806,7 +805,7 @@ public void TestRoomSettingsReQueriedWhenJoiningRoom()
AddUntilStep("wait for room", () => this.ChildrenOfType<DrawableRoom>().Any());
AddStep("select room", () => InputManager.Key(Key.Down));

AddStep("disable polling", () => this.ChildrenOfType<ListingPollingComponent>().Single().TimeBetweenPolls.Value = 0);
AddStep("disable polling", () => this.ChildrenOfType<LoungePollingComponent>().Single().TimeBetweenPolls.Value = 0);
AddStep("change server-side settings", () =>
{
multiplayerClient.ServerSideRooms[0].Name = "New name";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Lounge.Components;

namespace osu.Game.Screens.OnlinePlay.Components
namespace osu.Game.Screens.OnlinePlay.Lounge
{
/// <summary>
/// A <see cref="PollingComponent"/> that polls for the lounge listing.
/// </summary>
public partial class ListingPollingComponent : PollingComponent
public partial class LoungePollingComponent : PollingComponent
{
[Resolved]
private IAPIProvider api { get; set; } = null!;
Expand Down
17 changes: 8 additions & 9 deletions osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
using osu.Game.Rulesets;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
using osu.Game.Screens.OnlinePlay.Match;
using osu.Game.Users;
Expand Down Expand Up @@ -77,7 +76,7 @@ public abstract partial class LoungeSubScreen : OnlinePlaySubScreen, IOnlinePlay
private readonly IBindable<bool> operationInProgress = new Bindable<bool>();
private readonly IBindable<bool> isIdle = new BindableBool();
private RoomsContainer roomsContainer = null!;
private ListingPollingComponent listingPollingComponent = null!;
private LoungePollingComponent pollingComponent = null!;
private PopoverContainer popoverContainer = null!;
private LoadingLayer loadingLayer = null!;
private SearchTextBox searchTextBox = null!;
Expand All @@ -94,7 +93,7 @@ private void load()

InternalChildren = new Drawable[]
{
listingPollingComponent = new ListingPollingComponent
pollingComponent = new LoungePollingComponent
{
RoomsReceived = onListingReceived,
Filter = { BindTarget = filter }
Expand Down Expand Up @@ -189,7 +188,7 @@ protected override void LoadComplete()
{
roomsContainer.Rooms.Clear();
hasListingResults.Value = false;
listingPollingComponent.PollImmediately();
pollingComponent.PollImmediately();
});

updateFilter();
Expand Down Expand Up @@ -270,7 +269,7 @@ public override void OnResuming(ScreenTransitionEvent e)
onReturning();

// Poll for any newly-created rooms (including potentially the user's own).
listingPollingComponent.PollImmediately();
pollingComponent.PollImmediately();
}

public override bool OnExiting(ScreenExitEvent e)
Expand Down Expand Up @@ -388,7 +387,7 @@ public void Open(Room? room = null) => Schedule(() =>

protected virtual void OpenNewRoom(Room room) => this.Push(CreateRoomSubScreen(room));

public void RefreshRooms() => listingPollingComponent.PollImmediately();
public void RefreshRooms() => pollingComponent.PollImmediately();

private void updateLoadingLayer()
{
Expand All @@ -401,11 +400,11 @@ private void updateLoadingLayer()
private void updatePollingRate(bool isCurrentScreen)
{
if (!isCurrentScreen)
listingPollingComponent.TimeBetweenPolls.Value = 0;
pollingComponent.TimeBetweenPolls.Value = 0;
else
listingPollingComponent.TimeBetweenPolls.Value = isIdle.Value ? 120000 : 15000;
pollingComponent.TimeBetweenPolls.Value = isIdle.Value ? 120000 : 15000;

Logger.Log($"Polling adjusted (listing: {listingPollingComponent.TimeBetweenPolls.Value})");
Logger.Log($"Polling adjusted (listing: {pollingComponent.TimeBetweenPolls.Value})");
}

protected abstract OsuButton CreateNewRoomButton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public partial class PlaylistsRoomSubScreen : RoomSubScreen
private IdleTracker? idleTracker { get; set; }

private MatchLeaderboard leaderboard = null!;
private SelectionPollingComponent selectionPollingComponent = null!;
private PlaylistsRoomUpdater roomUpdater = null!;
private FillFlowContainer progressSection = null!;
private DrawableRoomPlaylist drawablePlaylist = null!;

Expand All @@ -64,7 +64,7 @@ private void load()
if (idleTracker != null)
isIdle.BindTo(idleTracker.IsIdle);

AddInternal(selectionPollingComponent = new SelectionPollingComponent(Room));
AddInternal(roomUpdater = new PlaylistsRoomUpdater(Room));
}

protected override void LoadComplete()
Expand Down Expand Up @@ -328,8 +328,8 @@ protected override void OpenStyleSelection()

private void updatePollingRate()
{
selectionPollingComponent.TimeBetweenPolls.Value = isIdle.Value ? 30000 : 5000;
Logger.Log($"Polling adjusted (selection: {selectionPollingComponent.TimeBetweenPolls.Value})");
roomUpdater.TimeBetweenPolls.Value = isIdle.Value ? 30000 : 5000;
Logger.Log($"Polling adjusted (selection: {roomUpdater.TimeBetweenPolls.Value})");
}

private void closePlaylist()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
using osu.Game.Online.API;
using osu.Game.Online.Rooms;

namespace osu.Game.Screens.OnlinePlay.Components
namespace osu.Game.Screens.OnlinePlay.Playlists
{
/// <summary>
/// A <see cref="PollingComponent"/> that polls for and updates a room.
/// </summary>
public partial class SelectionPollingComponent : PollingComponent
public partial class PlaylistsRoomUpdater : PollingComponent
{
[Resolved]
private IAPIProvider api { get; set; } = null!;

private readonly Room room;

public SelectionPollingComponent(Room room)
public PlaylistsRoomUpdater(Room room)
{
this.room = room;
}
Expand Down

0 comments on commit 24cc772

Please sign in to comment.