mirror of
https://github.com/ppy/osu.git
synced 2024-11-15 09:47:24 +08:00
e1897f9998
This avoids accidental usage which could result in data being lost or ignored (as only the last `user` in a single frame would arrive). This was added specifically to debounce sample playback, but given that it's only debouncing on a single frame (hardly noticeable) I'm not going to add back support for that yet. It should be handled by sample playback concurrency or something more local to the usage.
114 lines
4.0 KiB
C#
114 lines
4.0 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 JetBrains.Annotations;
|
|
using osu.Framework.Allocation;
|
|
using osu.Game.Online.Multiplayer;
|
|
using osu.Game.Online.Rooms;
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|
{
|
|
public abstract class MultiplayerRoomComposite : OnlinePlayComposite
|
|
{
|
|
[CanBeNull]
|
|
protected MultiplayerRoom Room => Client.Room;
|
|
|
|
[Resolved]
|
|
protected MultiplayerClient Client { get; private set; }
|
|
|
|
protected override void LoadComplete()
|
|
{
|
|
base.LoadComplete();
|
|
|
|
Client.RoomUpdated += invokeOnRoomUpdated;
|
|
Client.UserLeft += invokeUserLeft;
|
|
Client.UserKicked += invokeUserKicked;
|
|
Client.UserJoined += invokeUserJoined;
|
|
Client.ItemAdded += invokeItemAdded;
|
|
Client.ItemRemoved += invokeItemRemoved;
|
|
Client.ItemChanged += invokeItemChanged;
|
|
|
|
OnRoomUpdated();
|
|
}
|
|
|
|
private void invokeOnRoomUpdated() => Scheduler.AddOnce(OnRoomUpdated);
|
|
private void invokeUserJoined(MultiplayerRoomUser user) => Scheduler.Add(() => UserJoined(user));
|
|
private void invokeUserKicked(MultiplayerRoomUser user) => Scheduler.Add(() => UserKicked(user));
|
|
private void invokeUserLeft(MultiplayerRoomUser user) => Scheduler.Add(() => UserLeft(user));
|
|
private void invokeItemAdded(MultiplayerPlaylistItem item) => Schedule(() => PlaylistItemAdded(item));
|
|
private void invokeItemRemoved(long item) => Schedule(() => PlaylistItemRemoved(item));
|
|
private void invokeItemChanged(MultiplayerPlaylistItem item) => Schedule(() => PlaylistItemChanged(item));
|
|
|
|
/// <summary>
|
|
/// Invoked when a user has joined the room.
|
|
/// </summary>
|
|
/// <param name="user">The user.</param>
|
|
protected virtual void UserJoined(MultiplayerRoomUser user)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invoked when a user has been kicked from the room (including the local user).
|
|
/// </summary>
|
|
/// <param name="user">The user.</param>
|
|
protected virtual void UserKicked(MultiplayerRoomUser user)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invoked when a user has left the room.
|
|
/// </summary>
|
|
/// <param name="user">The user.</param>
|
|
protected virtual void UserLeft(MultiplayerRoomUser user)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invoked when a playlist item is added to the room.
|
|
/// </summary>
|
|
/// <param name="item">The added playlist item.</param>
|
|
protected virtual void PlaylistItemAdded(MultiplayerPlaylistItem item)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invoked when a playlist item is removed from the room.
|
|
/// </summary>
|
|
/// <param name="item">The ID of the removed playlist item.</param>
|
|
protected virtual void PlaylistItemRemoved(long item)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invoked when a playlist item is changed in the room.
|
|
/// </summary>
|
|
/// <param name="item">The new playlist item, with an existing item's ID.</param>
|
|
protected virtual void PlaylistItemChanged(MultiplayerPlaylistItem item)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invoked when any change occurs to the multiplayer room.
|
|
/// </summary>
|
|
protected virtual void OnRoomUpdated()
|
|
{
|
|
}
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
{
|
|
if (Client != null)
|
|
{
|
|
Client.RoomUpdated -= invokeOnRoomUpdated;
|
|
Client.UserLeft -= invokeUserLeft;
|
|
Client.UserKicked -= invokeUserKicked;
|
|
Client.UserJoined -= invokeUserJoined;
|
|
Client.ItemAdded -= invokeItemAdded;
|
|
Client.ItemRemoved -= invokeItemRemoved;
|
|
Client.ItemChanged -= invokeItemChanged;
|
|
}
|
|
|
|
base.Dispose(isDisposing);
|
|
}
|
|
}
|
|
}
|