2019-06-16 01:21:00 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-01-22 17:46:59 +08:00
|
|
|
|
using System;
|
2018-01-12 17:35:28 +08:00
|
|
|
|
using System.Linq;
|
2020-01-09 12:43:44 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2018-01-12 17:35:28 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2019-03-07 17:30:31 +08:00
|
|
|
|
using osu.Game.Rulesets.Catch.Beatmaps;
|
2018-01-12 17:35:28 +08:00
|
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
2018-01-22 17:46:59 +08:00
|
|
|
|
using osu.Game.Rulesets.Catch.UI;
|
2018-01-12 17:35:28 +08:00
|
|
|
|
using osu.Game.Rulesets.Replays;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-01-12 17:35:28 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Catch.Replays
|
|
|
|
|
{
|
2021-05-06 23:31:12 +08:00
|
|
|
|
internal class CatchAutoGenerator : AutoGenerator<CatchReplayFrame>
|
2018-01-12 17:35:28 +08:00
|
|
|
|
{
|
2019-03-07 17:30:31 +08:00
|
|
|
|
public new CatchBeatmap Beatmap => (CatchBeatmap)base.Beatmap;
|
|
|
|
|
|
2024-08-29 23:48:53 +08:00
|
|
|
|
private readonly float halfCatcherWidth;
|
|
|
|
|
|
2019-03-07 17:30:31 +08:00
|
|
|
|
public CatchAutoGenerator(IBeatmap beatmap)
|
2018-01-12 17:35:28 +08:00
|
|
|
|
: base(beatmap)
|
|
|
|
|
{
|
2024-08-29 23:48:53 +08:00
|
|
|
|
halfCatcherWidth = Catcher.CalculateCatchWidth(beatmap.Difficulty) * 0.5f;
|
2018-01-12 17:35:28 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-05-06 20:53:34 +08:00
|
|
|
|
protected override void GenerateFrames()
|
2018-01-12 17:35:28 +08:00
|
|
|
|
{
|
2020-09-28 13:15:26 +08:00
|
|
|
|
if (Beatmap.HitObjects.Count == 0)
|
2021-05-06 20:53:34 +08:00
|
|
|
|
return;
|
2020-09-28 13:15:26 +08:00
|
|
|
|
|
2020-07-01 23:21:45 +08:00
|
|
|
|
float lastPosition = CatchPlayfield.CENTER_X;
|
2018-01-22 17:46:59 +08:00
|
|
|
|
double lastTime = 0;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-11-24 18:57:37 +08:00
|
|
|
|
void moveToNext(PalpableCatchHitObject h)
|
2018-01-22 17:46:59 +08:00
|
|
|
|
{
|
2020-12-09 16:58:53 +08:00
|
|
|
|
float positionChange = Math.Abs(lastPosition - h.EffectiveX);
|
2018-01-22 17:46:59 +08:00
|
|
|
|
double timeAvailable = h.StartTime - lastTime;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-01-29 09:53:26 +08:00
|
|
|
|
if (timeAvailable < 0)
|
2021-01-29 10:03:23 +08:00
|
|
|
|
{
|
2021-01-29 09:53:26 +08:00
|
|
|
|
return;
|
2021-01-29 10:03:23 +08:00
|
|
|
|
}
|
2021-01-29 09:53:26 +08:00
|
|
|
|
|
2019-06-16 04:41:10 +08:00
|
|
|
|
// So we can either make it there without a dash or not.
|
2019-06-16 04:57:52 +08:00
|
|
|
|
// If positionChange is 0, we don't need to move, so speedRequired should also be 0 (could be NaN if timeAvailable is 0 too)
|
|
|
|
|
// The case where positionChange > 0 and timeAvailable == 0 results in PositiveInfinity which provides expected beheaviour.
|
2019-06-16 01:14:24 +08:00
|
|
|
|
double speedRequired = positionChange == 0 ? 0 : positionChange / timeAvailable;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-10-26 19:09:48 +08:00
|
|
|
|
bool dashRequired = speedRequired > Catcher.BASE_WALK_SPEED;
|
|
|
|
|
bool impossibleJump = speedRequired > Catcher.BASE_DASH_SPEED;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-08-29 23:48:53 +08:00
|
|
|
|
if (lastPosition - halfCatcherWidth < h.EffectiveX && lastPosition + halfCatcherWidth > h.EffectiveX)
|
2018-01-22 17:46:59 +08:00
|
|
|
|
{
|
2020-05-05 09:31:11 +08:00
|
|
|
|
// we are already in the correct range.
|
2018-01-22 17:46:59 +08:00
|
|
|
|
lastTime = h.StartTime;
|
2019-09-12 17:33:46 +08:00
|
|
|
|
addFrame(h.StartTime, lastPosition);
|
2018-01-22 17:46:59 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-16 01:21:00 +08:00
|
|
|
|
if (impossibleJump)
|
2018-01-22 17:46:59 +08:00
|
|
|
|
{
|
2020-12-09 16:58:53 +08:00
|
|
|
|
addFrame(h.StartTime, h.EffectiveX);
|
2018-01-22 17:46:59 +08:00
|
|
|
|
}
|
|
|
|
|
else if (h.HyperDash)
|
|
|
|
|
{
|
2019-09-12 17:33:46 +08:00
|
|
|
|
addFrame(h.StartTime - timeAvailable, lastPosition);
|
2020-12-09 16:58:53 +08:00
|
|
|
|
addFrame(h.StartTime, h.EffectiveX);
|
2018-01-22 17:46:59 +08:00
|
|
|
|
}
|
|
|
|
|
else if (dashRequired)
|
|
|
|
|
{
|
2020-05-05 09:31:11 +08:00
|
|
|
|
// we do a movement in two parts - the dash part then the normal part...
|
2021-10-26 19:09:48 +08:00
|
|
|
|
double timeAtNormalSpeed = positionChange / Catcher.BASE_WALK_SPEED;
|
2018-01-22 17:46:59 +08:00
|
|
|
|
double timeWeNeedToSave = timeAtNormalSpeed - timeAvailable;
|
|
|
|
|
double timeAtDashSpeed = timeWeNeedToSave / 2;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-12-09 16:58:53 +08:00
|
|
|
|
float midPosition = (float)Interpolation.Lerp(lastPosition, h.EffectiveX, (float)timeAtDashSpeed / timeAvailable);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-05-05 09:31:11 +08:00
|
|
|
|
// dash movement
|
2019-09-12 17:33:46 +08:00
|
|
|
|
addFrame(h.StartTime - timeAvailable + 1, lastPosition, true);
|
|
|
|
|
addFrame(h.StartTime - timeAvailable + timeAtDashSpeed, midPosition);
|
2020-12-09 16:58:53 +08:00
|
|
|
|
addFrame(h.StartTime, h.EffectiveX);
|
2018-01-22 17:46:59 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-10-26 19:09:48 +08:00
|
|
|
|
double timeBefore = positionChange / Catcher.BASE_WALK_SPEED;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-09-12 17:33:46 +08:00
|
|
|
|
addFrame(h.StartTime - timeBefore, lastPosition);
|
2020-12-09 16:58:53 +08:00
|
|
|
|
addFrame(h.StartTime, h.EffectiveX);
|
2018-01-22 17:46:59 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-01-22 17:46:59 +08:00
|
|
|
|
lastTime = h.StartTime;
|
2020-12-09 16:58:53 +08:00
|
|
|
|
lastPosition = h.EffectiveX;
|
2018-01-22 17:46:59 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-01-12 17:35:28 +08:00
|
|
|
|
foreach (var obj in Beatmap.HitObjects)
|
|
|
|
|
{
|
2020-11-24 18:57:37 +08:00
|
|
|
|
if (obj is PalpableCatchHitObject palpableObject)
|
2018-01-12 17:35:28 +08:00
|
|
|
|
{
|
2020-11-24 18:57:37 +08:00
|
|
|
|
moveToNext(palpableObject);
|
2018-01-12 17:35:28 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-01-12 17:35:28 +08:00
|
|
|
|
foreach (var nestedObj in obj.NestedHitObjects.Cast<CatchHitObject>())
|
|
|
|
|
{
|
2020-11-24 18:57:37 +08:00
|
|
|
|
if (nestedObj is PalpableCatchHitObject palpableNestedObject)
|
2018-01-12 17:35:28 +08:00
|
|
|
|
{
|
2020-11-24 18:57:37 +08:00
|
|
|
|
moveToNext(palpableNestedObject);
|
2018-01-12 17:35:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-12 17:33:46 +08:00
|
|
|
|
|
|
|
|
|
private void addFrame(double time, float? position = null, bool dashing = false)
|
|
|
|
|
{
|
2021-05-06 20:53:34 +08:00
|
|
|
|
Frames.Add(new CatchReplayFrame(time, position, dashing, LastFrame));
|
2019-09-12 17:33:46 +08:00
|
|
|
|
}
|
2018-01-12 17:35:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|