2019-01-24 08:43:03 +00:00
// 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.
2018-04-13 09:19:50 +00:00
2018-11-20 07:51:59 +00:00
using osuTK ;
2020-01-09 04:43:44 +00:00
using osu.Framework.Utils ;
2017-03-12 13:13:43 +00:00
using osu.Game.Beatmaps ;
2017-04-18 07:05:58 +00:00
using osu.Game.Rulesets.Osu.Objects ;
2017-03-12 13:13:43 +00:00
using System ;
2021-01-31 16:59:35 +00:00
using System.Collections.Generic ;
2019-09-02 09:58:13 +00:00
using System.Diagnostics ;
2018-02-28 07:34:47 +00:00
using System.Linq ;
2017-03-28 12:26:20 +00:00
using osu.Framework.Graphics ;
2018-11-28 08:20:37 +00:00
using osu.Game.Replays ;
2021-01-31 16:59:35 +00:00
using osu.Game.Rulesets.Mods ;
2019-11-25 10:01:24 +00:00
using osu.Game.Rulesets.Objects ;
2019-03-07 09:30:31 +00:00
using osu.Game.Rulesets.Osu.Beatmaps ;
2019-09-06 06:24:00 +00:00
using osu.Game.Rulesets.Osu.Scoring ;
2017-12-30 20:23:18 +00:00
using osu.Game.Rulesets.Scoring ;
2018-04-13 09:19:50 +00:00
2017-04-28 15:19:15 +00:00
namespace osu.Game.Rulesets.Osu.Replays
2017-03-05 08:46:00 +00:00
{
2017-04-28 18:08:48 +00:00
public class OsuAutoGenerator : OsuAutoGeneratorBase
2017-03-05 08:46:00 +00:00
{
2019-03-07 09:30:31 +00:00
public new OsuBeatmap Beatmap = > ( OsuBeatmap ) base . Beatmap ;
2017-04-28 18:08:48 +00:00
#region Parameters
2018-04-13 09:19:50 +00:00
2017-04-28 15:19:15 +00:00
/// <summary>
/// If delayed movements should be used, causing the cursor to stay on each hitobject for as long as possible.
/// Mainly for Autopilot.
/// </summary>
2017-04-28 18:08:48 +00:00
public bool DelayedMovements ; // ModManager.CheckActive(Mods.Relax2);
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
#endregion
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
#region Constants
2018-04-13 09:19:50 +00:00
2019-09-02 09:58:13 +00:00
private readonly HitWindows defaultHitWindows ;
2017-04-28 15:19:15 +00:00
/// <summary>
/// What easing to use when moving between hitobjects
/// </summary>
2017-07-22 18:50:25 +00:00
private Easing preferredEasing = > DelayedMovements ? Easing . InOutCubic : Easing . Out ;
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
#endregion
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
#region Construction / Initialisation
2018-04-13 09:19:50 +00:00
2021-01-31 16:59:35 +00:00
public OsuAutoGenerator ( IBeatmap beatmap , IReadOnlyList < Mod > mods )
: base ( beatmap , mods )
2017-04-28 16:21:33 +00:00
{
2019-09-02 09:58:13 +00:00
defaultHitWindows = new OsuHitWindows ( ) ;
2021-10-02 03:34:29 +00:00
defaultHitWindows . SetDifficulty ( Beatmap . Difficulty . OverallDifficulty ) ;
2017-03-05 08:46:00 +00:00
}
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
#endregion
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
#region Generator
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
/// <summary>
/// Which button (left or right) to use for the current hitobject.
/// Even means LMB will be used to click, odd means RMB will be used.
/// This keeps track of the button previously used for alt/singletap logic.
/// </summary>
private int buttonIndex ;
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
public override Replay Generate ( )
2017-03-05 08:46:00 +00:00
{
2020-09-28 05:15:26 +00:00
if ( Beatmap . HitObjects . Count = = 0 )
return Replay ;
2017-04-21 15:24:09 +00:00
buttonIndex = 0 ;
2018-04-13 09:19:50 +00:00
2018-02-28 07:34:47 +00:00
AddFrameToReplay ( new OsuReplayFrame ( Beatmap . HitObjects [ 0 ] . StartTime - 1500 , new Vector2 ( 256 , 500 ) ) ) ;
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
for ( int i = 0 ; i < Beatmap . HitObjects . Count ; i + + )
2017-03-05 08:46:00 +00:00
{
2017-04-28 18:08:48 +00:00
OsuHitObject h = Beatmap . HitObjects [ i ] ;
2018-04-13 09:19:50 +00:00
2017-03-09 06:52:40 +00:00
if ( DelayedMovements & & i > 0 )
2017-03-05 08:46:00 +00:00
{
2017-04-28 18:08:48 +00:00
OsuHitObject prev = Beatmap . HitObjects [ i - 1 ] ;
2017-04-21 15:24:09 +00:00
addDelayedMovements ( h , prev ) ;
}
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
addHitObjectReplay ( h ) ;
}
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
return Replay ;
2017-04-21 15:24:09 +00:00
}
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
private void addDelayedMovements ( OsuHitObject h , OsuHitObject prev )
{
2019-11-25 10:01:24 +00:00
double endTime = prev . GetEndTime ( ) ;
2018-04-13 09:19:50 +00:00
2022-07-02 05:33:05 +00:00
HitWindows ? hitWindows = null ;
2019-09-02 09:58:13 +00:00
switch ( h )
{
case HitCircle hitCircle :
hitWindows = hitCircle . HitWindows ;
break ;
case Slider slider :
hitWindows = slider . TailCircle . HitWindows ;
break ;
2022-06-24 12:25:23 +00:00
case Spinner :
2019-09-02 09:58:13 +00:00
hitWindows = defaultHitWindows ;
break ;
}
Debug . Assert ( hitWindows ! = null ) ;
2017-04-21 15:24:09 +00:00
// Make the cursor stay at a hitObject as long as possible (mainly for autopilot).
2019-09-06 06:24:00 +00:00
if ( h . StartTime - hitWindows . WindowFor ( HitResult . Miss ) > endTime + hitWindows . WindowFor ( HitResult . Meh ) + 50 )
2017-04-21 15:24:09 +00:00
{
2019-09-02 09:58:13 +00:00
if ( ! ( prev is Spinner ) & & h . StartTime - endTime < 1000 )
2019-09-06 06:24:00 +00:00
AddFrameToReplay ( new OsuReplayFrame ( endTime + hitWindows . WindowFor ( HitResult . Meh ) , new Vector2 ( prev . StackedEndPosition . X , prev . StackedEndPosition . Y ) ) ) ;
2019-09-02 09:58:13 +00:00
if ( ! ( h is Spinner ) )
2019-09-06 06:24:00 +00:00
AddFrameToReplay ( new OsuReplayFrame ( h . StartTime - hitWindows . WindowFor ( HitResult . Miss ) , new Vector2 ( h . StackedPosition . X , h . StackedPosition . Y ) ) ) ;
2017-04-21 15:24:09 +00:00
}
2019-09-06 06:24:00 +00:00
else if ( h . StartTime - hitWindows . WindowFor ( HitResult . Meh ) > endTime + hitWindows . WindowFor ( HitResult . Meh ) + 50 )
2017-04-21 15:24:09 +00:00
{
2019-09-02 09:58:13 +00:00
if ( ! ( prev is Spinner ) & & h . StartTime - endTime < 1000 )
2019-09-06 06:24:00 +00:00
AddFrameToReplay ( new OsuReplayFrame ( endTime + hitWindows . WindowFor ( HitResult . Meh ) , new Vector2 ( prev . StackedEndPosition . X , prev . StackedEndPosition . Y ) ) ) ;
2019-09-02 09:58:13 +00:00
if ( ! ( h is Spinner ) )
2019-09-06 06:24:00 +00:00
AddFrameToReplay ( new OsuReplayFrame ( h . StartTime - hitWindows . WindowFor ( HitResult . Meh ) , new Vector2 ( h . StackedPosition . X , h . StackedPosition . Y ) ) ) ;
2018-03-24 09:48:43 +00:00
}
2020-09-29 08:16:55 +00:00
else if ( h . StartTime - hitWindows . WindowFor ( HitResult . Ok ) > endTime + hitWindows . WindowFor ( HitResult . Ok ) + 50 )
2018-03-24 09:48:43 +00:00
{
2019-09-02 09:58:13 +00:00
if ( ! ( prev is Spinner ) & & h . StartTime - endTime < 1000 )
2020-09-29 08:16:55 +00:00
AddFrameToReplay ( new OsuReplayFrame ( endTime + hitWindows . WindowFor ( HitResult . Ok ) , new Vector2 ( prev . StackedEndPosition . X , prev . StackedEndPosition . Y ) ) ) ;
2019-09-02 09:58:13 +00:00
if ( ! ( h is Spinner ) )
2020-09-29 08:16:55 +00:00
AddFrameToReplay ( new OsuReplayFrame ( h . StartTime - hitWindows . WindowFor ( HitResult . Ok ) , new Vector2 ( h . StackedPosition . X , h . StackedPosition . Y ) ) ) ;
2017-04-21 15:24:09 +00:00
}
}
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
private void addHitObjectReplay ( OsuHitObject h )
{
// Default values for circles/sliders
2017-05-17 23:54:17 +00:00
Vector2 startPosition = h . StackedPosition ;
2017-07-22 18:50:25 +00:00
Easing easing = preferredEasing ;
2017-04-21 15:24:09 +00:00
float spinnerDirection = - 1 ;
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// The startPosition for the slider should not be its .Position, but the point on the circle whose tangent crosses the current cursor position
// We also modify spinnerDirection so it spins in the direction it enters the spin circle, to make a smooth transition.
// TODO: Shouldn't the spinner always spin in the same direction?
2020-08-31 14:50:31 +00:00
if ( h is Spinner spinner )
2017-04-21 15:24:09 +00:00
{
2020-08-31 15:20:45 +00:00
// spinners with 0 spins required will auto-complete - don't bother
if ( spinner . SpinsRequired = = 0 )
2020-08-31 14:21:00 +00:00
return ;
2019-12-14 12:54:22 +00:00
calcSpinnerStartPosAndDirection ( ( ( OsuReplayFrame ) Frames [ ^ 1 ] ) . Position , out startPosition , out spinnerDirection ) ;
2018-04-13 09:19:50 +00:00
2019-12-14 12:54:22 +00:00
Vector2 spinCentreOffset = SPINNER_CENTRE - ( ( OsuReplayFrame ) Frames [ ^ 1 ] ) . Position ;
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
if ( spinCentreOffset . Length > SPIN_RADIUS )
2017-04-21 15:24:09 +00:00
{
// If moving in from the outside, don't ease out (default eases out). This means auto will "start" spinning immediately after moving into position.
2017-07-22 18:50:25 +00:00
easing = Easing . In ;
2017-04-21 15:24:09 +00:00
}
}
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// Do some nice easing for cursor movements
if ( Frames . Count > 0 )
{
2017-12-31 16:15:14 +00:00
moveToHitObject ( h , startPosition , easing ) ;
2017-04-21 15:24:09 +00:00
}
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// Add frames to click the hitobject
addHitObjectClickFrames ( h , startPosition , spinnerDirection ) ;
}
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
#endregion
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
#region Helper subroutines
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
private static void calcSpinnerStartPosAndDirection ( Vector2 prevPos , out Vector2 startPosition , out float spinnerDirection )
{
2017-04-28 18:08:48 +00:00
Vector2 spinCentreOffset = SPINNER_CENTRE - prevPos ;
2017-04-21 15:24:09 +00:00
float distFromCentre = spinCentreOffset . Length ;
2019-11-24 23:45:42 +00:00
float distToTangentPoint = MathF . Sqrt ( distFromCentre * distFromCentre - SPIN_RADIUS * SPIN_RADIUS ) ;
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
if ( distFromCentre > SPIN_RADIUS )
2017-04-21 15:24:09 +00:00
{
// Previous cursor position was outside spin circle, set startPosition to the tangent point.
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// Angle between centre offset and tangent point offset.
2019-11-24 23:45:42 +00:00
float angle = MathF . Asin ( SPIN_RADIUS / distFromCentre ) ;
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
if ( angle > 0 )
{
spinnerDirection = - 1 ;
}
else
{
spinnerDirection = 1 ;
2017-03-05 08:46:00 +00:00
}
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// Rotate by angle so it's parallel to tangent line
2019-11-24 23:45:42 +00:00
spinCentreOffset . X = spinCentreOffset . X * MathF . Cos ( angle ) - spinCentreOffset . Y * MathF . Sin ( angle ) ;
spinCentreOffset . Y = spinCentreOffset . X * MathF . Sin ( angle ) + spinCentreOffset . Y * MathF . Cos ( angle ) ;
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// Set length to distToTangentPoint
spinCentreOffset . Normalize ( ) ;
spinCentreOffset * = distToTangentPoint ;
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// Move along the tangent line, now startPosition is at the tangent point.
startPosition = prevPos + spinCentreOffset ;
}
else if ( spinCentreOffset . Length > 0 )
{
// Previous cursor position was inside spin circle, set startPosition to the nearest point on spin circle.
2017-04-28 18:08:48 +00:00
startPosition = SPINNER_CENTRE - spinCentreOffset * ( SPIN_RADIUS / spinCentreOffset . Length ) ;
2017-04-21 15:24:09 +00:00
spinnerDirection = 1 ;
}
else
{
// Degenerate case where cursor position is exactly at the centre of the spin circle.
2017-04-28 18:08:48 +00:00
startPosition = SPINNER_CENTRE + new Vector2 ( 0 , - SPIN_RADIUS ) ;
2017-04-21 15:24:09 +00:00
spinnerDirection = 1 ;
}
}
2018-04-13 09:19:50 +00:00
2017-12-31 16:15:14 +00:00
private void moveToHitObject ( OsuHitObject h , Vector2 targetPos , Easing easing )
2017-04-21 15:24:09 +00:00
{
2019-12-14 12:54:22 +00:00
OsuReplayFrame lastFrame = ( OsuReplayFrame ) Frames [ ^ 1 ] ;
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// Wait until Auto could "see and react" to the next note.
2021-01-31 16:56:03 +00:00
double waitTime = h . StartTime - Math . Max ( 0.0 , h . TimePreempt - getReactionTime ( h . StartTime - h . TimePreempt ) ) ;
2021-07-05 08:24:23 +00:00
bool hasWaited = false ;
2019-04-01 02:39:02 +00:00
2017-04-21 15:24:09 +00:00
if ( waitTime > lastFrame . Time )
{
2018-02-28 07:34:47 +00:00
lastFrame = new OsuReplayFrame ( waitTime , lastFrame . Position ) { Actions = lastFrame . Actions } ;
2021-07-05 08:24:23 +00:00
hasWaited = true ;
2017-04-28 18:30:34 +00:00
AddFrameToReplay ( lastFrame ) ;
2017-04-21 15:24:09 +00:00
}
2018-04-13 09:19:50 +00:00
2021-01-31 16:56:03 +00:00
double timeDifference = ApplyModsToTimeDelta ( lastFrame . Time , h . StartTime ) ;
2022-07-02 05:33:05 +00:00
OsuReplayFrame ? lastLastFrame = Frames . Count > = 2 ? ( OsuReplayFrame ) Frames [ ^ 2 ] : null ;
2021-07-05 08:11:59 +00:00
2021-07-05 08:52:10 +00:00
if ( timeDifference > 0 )
2021-07-05 08:22:48 +00:00
{
2021-07-05 08:52:10 +00:00
// If the last frame is a key-up frame and there has been no wait period, adjust the last frame's position such that it begins eased movement instantaneously.
2021-07-05 09:49:09 +00:00
if ( lastLastFrame ! = null & & lastFrame is OsuKeyUpReplayFrame & & ! hasWaited )
2021-07-05 08:52:10 +00:00
{
// [lastLastFrame] ... [lastFrame] ... [current frame]
// We want to find the cursor position at lastFrame, so interpolate between lastLastFrame and the new target position.
lastFrame . Position = Interpolation . ValueAt ( lastFrame . Time , lastFrame . Position , targetPos , lastLastFrame . Time , h . StartTime , easing ) ;
}
2021-07-05 08:11:59 +00:00
2021-07-05 08:52:10 +00:00
Vector2 lastPosition = lastFrame . Position ;
2018-04-13 09:19:50 +00:00
2021-07-05 09:51:23 +00:00
// Perform the rest of the eased movement until the target position is reached.
2021-07-05 08:52:10 +00:00
for ( double time = lastFrame . Time + GetFrameDelay ( lastFrame . Time ) ; time < h . StartTime ; time + = GetFrameDelay ( time ) )
{
Vector2 currentPosition = Interpolation . ValueAt ( time , lastPosition , targetPos , lastFrame . Time , h . StartTime , easing ) ;
AddFrameToReplay ( new OsuReplayFrame ( ( int ) time , new Vector2 ( currentPosition . X , currentPosition . Y ) ) { Actions = lastFrame . Actions } ) ;
}
2017-04-21 15:24:09 +00:00
}
2021-07-05 08:22:48 +00:00
2021-07-05 09:38:02 +00:00
// Start alternating once the time separation is too small (faster than ~225BPM).
if ( timeDifference > 0 & & timeDifference < 266 )
2021-07-05 08:22:48 +00:00
buttonIndex + + ;
else
buttonIndex = 0 ;
2017-04-28 15:19:15 +00:00
}
2018-04-13 09:19:50 +00:00
2021-01-31 16:56:03 +00:00
/// <summary>
/// Calculates the "reaction time" in ms between "seeing" a new hit object and moving to "react" to it.
/// </summary>
/// <remarks>
/// Already superhuman, but still somewhat realistic.
/// </remarks>
private double getReactionTime ( double timeInstant ) = > ApplyModsToRate ( timeInstant , 100 ) ;
2017-04-28 15:19:15 +00:00
// Add frames to click the hitobject
private void addHitObjectClickFrames ( OsuHitObject h , Vector2 startPosition , float spinnerDirection )
2017-04-21 15:24:09 +00:00
{
// Time to insert the first frame which clicks the object
// Here we mainly need to determine which button to use
2018-02-28 07:34:47 +00:00
var action = buttonIndex % 2 = = 0 ? OsuAction . LeftButton : OsuAction . RightButton ;
2018-04-13 09:19:50 +00:00
2018-02-28 07:34:47 +00:00
var startFrame = new OsuReplayFrame ( h . StartTime , new Vector2 ( startPosition . X , startPosition . Y ) , action ) ;
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// TODO: Why do we delay 1 ms if the object is a spinner? There already is KEY_UP_DELAY from hEndTime.
2019-11-25 10:01:24 +00:00
double hEndTime = h . GetEndTime ( ) + KEY_UP_DELAY ;
2017-04-21 15:24:09 +00:00
int endDelay = h is Spinner ? 1 : 0 ;
2021-07-05 08:24:23 +00:00
var endFrame = new OsuKeyUpReplayFrame ( hEndTime + endDelay , new Vector2 ( h . StackedEndPosition . X , h . StackedEndPosition . Y ) ) ;
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// Decrement because we want the previous frame, not the next one
2017-04-28 18:30:34 +00:00
int index = FindInsertionIndex ( startFrame ) - 1 ;
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// If the previous frame has a button pressed, force alternation.
// If there are frames ahead, modify those to use the new button press.
// Do we have a previous frame? No need to check for < replay.Count since we decremented!
if ( index > = 0 )
{
2018-02-28 07:34:47 +00:00
var previousFrame = ( OsuReplayFrame ) Frames [ index ] ;
var previousActions = previousFrame . Actions ;
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// If a button is already held, then we simply alternate
2018-02-28 07:34:47 +00:00
if ( previousActions . Any ( ) )
2017-03-05 08:46:00 +00:00
{
2017-04-21 15:24:09 +00:00
// Force alternation if we have the same button. Otherwise we can just keep the naturally to us assigned button.
2018-02-28 07:34:47 +00:00
if ( previousActions . Contains ( action ) )
2017-03-05 08:46:00 +00:00
{
2018-02-28 07:34:47 +00:00
action = action = = OsuAction . LeftButton ? OsuAction . RightButton : OsuAction . LeftButton ;
startFrame . Actions . Clear ( ) ;
startFrame . Actions . Add ( action ) ;
2017-03-05 08:46:00 +00:00
}
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// We always follow the most recent slider / spinner, so remove any other frames that occur while it exists.
2017-04-28 18:30:34 +00:00
int endIndex = FindInsertionIndex ( endFrame ) ;
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
if ( index < Frames . Count - 1 )
Frames . RemoveRange ( index + 1 , Math . Max ( 0 , endIndex - ( index + 1 ) ) ) ;
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// After alternating we need to keep holding the other button in the future rather than the previous one.
for ( int j = index + 1 ; j < Frames . Count ; + + j )
{
2018-02-28 07:34:47 +00:00
var frame = ( OsuReplayFrame ) Frames [ j ] ;
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// Don't affect frames which stop pressing a button!
2018-02-28 07:34:47 +00:00
if ( j < Frames . Count - 1 | | frame . Actions . SequenceEqual ( previousActions ) )
{
frame . Actions . Clear ( ) ;
frame . Actions . Add ( action ) ;
}
2017-04-21 15:24:09 +00:00
}
}
}
2018-04-13 09:19:50 +00:00
2017-04-28 18:30:34 +00:00
AddFrameToReplay ( startFrame ) ;
2018-04-13 09:19:50 +00:00
2023-11-20 02:50:28 +00:00
// 0.05 rad/ms, or ~477 RPM, as per stable.
// the redundant conversion from RPM to rad/ms is here for ease of testing custom SPM specs.
2023-11-17 14:48:48 +00:00
const float spin_rpm = 0.05f / ( 2 * MathF . PI ) * 60000 ;
2024-03-06 02:42:20 +00:00
float radsPerMillisecond = float . DegreesToRadians ( spin_rpm * 360 ) / 60000 ;
2023-11-17 07:44:11 +00:00
2018-07-17 05:35:09 +00:00
switch ( h )
2017-04-21 15:24:09 +00:00
{
2018-07-17 05:35:09 +00:00
// We add intermediate frames for spinning / following a slider here.
case Spinner spinner :
Vector2 difference = startPosition - SPINNER_CENTRE ;
2018-04-13 09:19:50 +00:00
2018-07-17 05:35:09 +00:00
float radius = difference . Length ;
2019-11-24 23:45:42 +00:00
float angle = radius = = 0 ? 0 : MathF . Atan2 ( difference . Y , difference . X ) ;
2018-04-13 09:19:50 +00:00
2018-07-17 05:35:09 +00:00
double t ;
2021-01-31 16:56:03 +00:00
double previousFrame = h . StartTime ;
2018-04-13 09:19:50 +00:00
2021-01-31 16:56:03 +00:00
for ( double nextFrame = h . StartTime + GetFrameDelay ( h . StartTime ) ; nextFrame < spinner . EndTime ; nextFrame + = GetFrameDelay ( nextFrame ) )
2018-07-17 05:35:09 +00:00
{
2021-01-31 16:56:03 +00:00
t = ApplyModsToTimeDelta ( previousFrame , nextFrame ) * spinnerDirection ;
2023-11-17 07:44:11 +00:00
angle + = ( float ) t * radsPerMillisecond ;
2018-04-13 09:19:50 +00:00
2021-01-31 16:56:03 +00:00
Vector2 pos = SPINNER_CENTRE + CirclePosition ( angle , SPIN_RADIUS ) ;
AddFrameToReplay ( new OsuReplayFrame ( ( int ) nextFrame , new Vector2 ( pos . X , pos . Y ) , action ) ) ;
previousFrame = nextFrame ;
2018-07-17 05:35:09 +00:00
}
2018-04-13 09:19:50 +00:00
2021-01-31 16:56:03 +00:00
t = ApplyModsToTimeDelta ( previousFrame , spinner . EndTime ) * spinnerDirection ;
2023-11-17 07:44:11 +00:00
angle + = ( float ) t * radsPerMillisecond ;
2021-01-31 16:56:03 +00:00
Vector2 endPosition = SPINNER_CENTRE + CirclePosition ( angle , SPIN_RADIUS ) ;
2018-04-13 09:19:50 +00:00
2018-07-17 05:35:09 +00:00
AddFrameToReplay ( new OsuReplayFrame ( spinner . EndTime , new Vector2 ( endPosition . X , endPosition . Y ) , action ) ) ;
2018-04-13 09:19:50 +00:00
2018-07-17 05:35:09 +00:00
endFrame . Position = endPosition ;
break ;
2019-04-01 02:39:02 +00:00
2018-07-17 05:35:09 +00:00
case Slider slider :
2021-01-31 16:56:03 +00:00
for ( double j = GetFrameDelay ( slider . StartTime ) ; j < slider . Duration ; j + = GetFrameDelay ( slider . StartTime + j ) )
2018-07-17 05:35:09 +00:00
{
Vector2 pos = slider . StackedPositionAt ( j / slider . Duration ) ;
AddFrameToReplay ( new OsuReplayFrame ( h . StartTime + j , new Vector2 ( pos . X , pos . Y ) , action ) ) ;
}
2018-04-13 09:19:50 +00:00
2018-07-17 05:35:09 +00:00
AddFrameToReplay ( new OsuReplayFrame ( slider . EndTime , new Vector2 ( slider . StackedEndPosition . X , slider . StackedEndPosition . Y ) , action ) ) ;
break ;
2017-03-05 08:46:00 +00:00
}
2018-04-13 09:19:50 +00:00
2017-04-21 15:24:09 +00:00
// We only want to let go of our button if we are at the end of the current replay. Otherwise something is still going on after us so we need to keep the button pressed!
2019-12-14 12:54:22 +00:00
if ( Frames [ ^ 1 ] . Time < = endFrame . Time )
2017-04-28 18:30:34 +00:00
AddFrameToReplay ( endFrame ) ;
2017-03-05 08:46:00 +00:00
}
2018-04-13 09:19:50 +00:00
2017-04-28 18:08:48 +00:00
#endregion
2021-07-05 08:24:23 +00:00
private class OsuKeyUpReplayFrame : OsuReplayFrame
{
public OsuKeyUpReplayFrame ( double time , Vector2 position )
: base ( time , position )
{
}
}
2017-03-05 08:46:00 +00:00
}
}