mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 21:52:54 +08:00
Move replay recorder to final location
This commit is contained in:
parent
d5bc4915e6
commit
2735a2250c
@ -1,13 +1,10 @@
|
||||
// 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Input.StateChanges;
|
||||
@ -41,7 +38,7 @@ namespace osu.Game.Tests.Gameplay
|
||||
{
|
||||
new TestRulesetInputManager(new TestSceneModSettings.TestRulesetInfo(), 0, SimultaneousBindingMode.Unique)
|
||||
{
|
||||
RecordTarget = replay,
|
||||
Recorder = new TestReplayRecorder(replay),
|
||||
Child = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
@ -171,19 +168,6 @@ namespace osu.Game.Tests.Gameplay
|
||||
|
||||
public class TestRulesetInputManager : RulesetInputManager<TestAction>
|
||||
{
|
||||
private ReplayRecorder<TestAction> recorder;
|
||||
|
||||
public Replay RecordTarget
|
||||
{
|
||||
set
|
||||
{
|
||||
if (recorder != null)
|
||||
throw new InvalidOperationException("Cannot attach more than one recorder");
|
||||
|
||||
KeyBindingContainer.Add(recorder = new TestReplayRecorder(value));
|
||||
}
|
||||
}
|
||||
|
||||
public TestRulesetInputManager(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
|
||||
: base(ruleset, variant, unique)
|
||||
{
|
||||
@ -230,66 +214,4 @@ namespace osu.Game.Tests.Gameplay
|
||||
protected override ReplayFrame HandleFrame(InputState state, List<TestAction> pressedActions, ReplayFrame previousFrame) =>
|
||||
new TestReplayFrame(Time.Current, ToLocalSpace(state.Mouse.Position), pressedActions.ToArray());
|
||||
}
|
||||
|
||||
internal abstract class ReplayRecorder<T> : Component, IKeyBindingHandler<T>
|
||||
where T : struct
|
||||
{
|
||||
private readonly Replay target;
|
||||
|
||||
private readonly List<T> pressedActions = new List<T>();
|
||||
|
||||
private InputManager inputManager;
|
||||
|
||||
public int RecordFrameRate = 60;
|
||||
|
||||
protected ReplayRecorder(Replay target)
|
||||
{
|
||||
this.target = target;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
Depth = float.MinValue;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
inputManager = GetContainingInputManager();
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
recordFrame(false);
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
public bool OnPressed(T action)
|
||||
{
|
||||
pressedActions.Add(action);
|
||||
recordFrame(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnReleased(T action)
|
||||
{
|
||||
pressedActions.Remove(action);
|
||||
recordFrame(true);
|
||||
}
|
||||
|
||||
private void recordFrame(bool important)
|
||||
{
|
||||
var last = target.Frames.LastOrDefault();
|
||||
|
||||
if (!important && last != null && Time.Current - last.Time < (1000d / RecordFrameRate))
|
||||
return;
|
||||
|
||||
var frame = HandleFrame(inputManager.CurrentState, pressedActions, last);
|
||||
|
||||
if (frame != null)
|
||||
target.Frames.Add(frame);
|
||||
}
|
||||
|
||||
protected abstract ReplayFrame HandleFrame(InputState state, List<T> testActions, ReplayFrame previousFrame);
|
||||
}
|
||||
}
|
||||
|
@ -302,6 +302,8 @@ namespace osu.Game.Rulesets.UI
|
||||
|
||||
protected virtual ReplayInputHandler CreateReplayInputHandler(Replay replay) => null;
|
||||
|
||||
protected virtual ReplayRecorder CreateReplayRecorder(Replay replay) => null;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Playfield.
|
||||
/// </summary>
|
||||
|
81
osu.Game/Rulesets/UI/ReplayRecorder.cs
Normal file
81
osu.Game/Rulesets/UI/ReplayRecorder.cs
Normal file
@ -0,0 +1,81 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Input.States;
|
||||
using osu.Game.Replays;
|
||||
using osu.Game.Rulesets.Replays;
|
||||
|
||||
namespace osu.Game.Rulesets.UI
|
||||
{
|
||||
public abstract class ReplayRecorder<T> : ReplayRecorder, IKeyBindingHandler<T>
|
||||
where T : struct
|
||||
{
|
||||
private readonly Replay target;
|
||||
|
||||
private readonly List<T> pressedActions = new List<T>();
|
||||
|
||||
private InputManager inputManager;
|
||||
|
||||
public int RecordFrameRate = 60;
|
||||
|
||||
protected ReplayRecorder(Replay target)
|
||||
{
|
||||
this.target = target;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
Depth = float.MinValue;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
inputManager = GetContainingInputManager();
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
recordFrame(false);
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
public bool OnPressed(T action)
|
||||
{
|
||||
pressedActions.Add(action);
|
||||
recordFrame(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnReleased(T action)
|
||||
{
|
||||
pressedActions.Remove(action);
|
||||
recordFrame(true);
|
||||
}
|
||||
|
||||
private void recordFrame(bool important)
|
||||
{
|
||||
var last = target.Frames.LastOrDefault();
|
||||
|
||||
if (!important && last != null && Time.Current - last.Time < (1000d / RecordFrameRate))
|
||||
return;
|
||||
|
||||
var frame = HandleFrame(inputManager.CurrentState, pressedActions, last);
|
||||
|
||||
if (frame != null)
|
||||
target.Frames.Add(frame);
|
||||
}
|
||||
|
||||
protected abstract ReplayFrame HandleFrame(InputState state, List<T> testActions, ReplayFrame previousFrame);
|
||||
}
|
||||
|
||||
public abstract class ReplayRecorder : Component
|
||||
{
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
// 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 System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -26,6 +27,21 @@ namespace osu.Game.Rulesets.UI
|
||||
public abstract class RulesetInputManager<T> : PassThroughInputManager, ICanAttachKeyCounter, IHasReplayHandler
|
||||
where T : struct
|
||||
{
|
||||
private ReplayRecorder recorder;
|
||||
|
||||
public ReplayRecorder Recorder
|
||||
{
|
||||
set
|
||||
{
|
||||
if (recorder != null)
|
||||
throw new InvalidOperationException("Cannot attach more than one recorder");
|
||||
|
||||
recorder = value;
|
||||
|
||||
KeyBindingContainer.Add(recorder);
|
||||
}
|
||||
}
|
||||
|
||||
protected override InputState CreateInitialState()
|
||||
{
|
||||
var state = base.CreateInitialState();
|
||||
|
Loading…
Reference in New Issue
Block a user