mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 19:42:55 +08:00
Send frames to streaming client from replay recorder
This commit is contained in:
parent
93db75bd41
commit
175fd512b0
@ -7,7 +7,10 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Rulesets.Replays;
|
||||||
|
using osu.Game.Rulesets.Replays.Types;
|
||||||
|
|
||||||
namespace osu.Game.Online.Spectator
|
namespace osu.Game.Online.Spectator
|
||||||
{
|
{
|
||||||
@ -22,6 +25,9 @@ namespace osu.Game.Online.Spectator
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private APIAccess api { get; set; }
|
private APIAccess api { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IBindable<WorkingBeatmap> beatmap { get; set; }
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
@ -111,5 +117,12 @@ namespace osu.Game.Online.Spectator
|
|||||||
public Task EndPlaying(int beatmapId) => connection.SendAsync(nameof(ISpectatorServer.EndPlaySession), beatmapId);
|
public Task EndPlaying(int beatmapId) => connection.SendAsync(nameof(ISpectatorServer.EndPlaySession), beatmapId);
|
||||||
|
|
||||||
private Task WatchUser(string userId) => connection.SendAsync(nameof(ISpectatorServer.StartWatchingUser), userId);
|
private Task WatchUser(string userId) => connection.SendAsync(nameof(ISpectatorServer.StartWatchingUser), userId);
|
||||||
|
|
||||||
|
public void HandleFrame(ReplayFrame frame)
|
||||||
|
{
|
||||||
|
if (frame is IConvertibleReplayFrame convertible)
|
||||||
|
// TODO: don't send a bundle for each individual frame
|
||||||
|
SendFrames(new FrameDataBundle(new[] { convertible.ToLegacy(beatmap.Value.Beatmap) }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -250,8 +250,11 @@ namespace osu.Game
|
|||||||
|
|
||||||
FileStore.Cleanup();
|
FileStore.Cleanup();
|
||||||
|
|
||||||
|
// add api components to hierarchy.
|
||||||
if (API is APIAccess apiAccess)
|
if (API is APIAccess apiAccess)
|
||||||
AddInternal(apiAccess);
|
AddInternal(apiAccess);
|
||||||
|
AddInternal(spectatorStreaming);
|
||||||
|
|
||||||
AddInternal(RulesetConfigCache);
|
AddInternal(RulesetConfigCache);
|
||||||
|
|
||||||
MenuCursorContainer = new MenuCursorContainer { RelativeSizeAxes = Axes.Both };
|
MenuCursorContainer = new MenuCursorContainer { RelativeSizeAxes = Axes.Both };
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Online.Spectator;
|
||||||
using osu.Game.Replays;
|
using osu.Game.Replays;
|
||||||
using osu.Game.Rulesets.Replays;
|
using osu.Game.Rulesets.Replays;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -60,6 +62,9 @@ namespace osu.Game.Rulesets.UI
|
|||||||
recordFrame(true);
|
recordFrame(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Resolved(canBeNull: true)]
|
||||||
|
private SpectatorStreamingClient spectatorStreaming { get; set; }
|
||||||
|
|
||||||
private void recordFrame(bool important)
|
private void recordFrame(bool important)
|
||||||
{
|
{
|
||||||
var last = target.Frames.LastOrDefault();
|
var last = target.Frames.LastOrDefault();
|
||||||
@ -72,7 +77,11 @@ namespace osu.Game.Rulesets.UI
|
|||||||
var frame = HandleFrame(position, pressedActions, last);
|
var frame = HandleFrame(position, pressedActions, last);
|
||||||
|
|
||||||
if (frame != null)
|
if (frame != null)
|
||||||
|
{
|
||||||
target.Frames.Add(frame);
|
target.Frames.Add(frame);
|
||||||
|
|
||||||
|
spectatorStreaming?.HandleFrame(frame);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract ReplayFrame HandleFrame(Vector2 mousePosition, List<T> actions, ReplayFrame previousFrame);
|
protected abstract ReplayFrame HandleFrame(Vector2 mousePosition, List<T> actions, ReplayFrame previousFrame);
|
||||||
|
Loading…
Reference in New Issue
Block a user