1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-09 11:22:58 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Difficulty/Evaluators/ReadingEvaluator.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

150 lines
5.9 KiB
C#
Raw Normal View History

2022-06-21 15:54:27 +08: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.
using System;
2022-07-20 02:17:16 +08:00
using System.Collections.Generic;
2022-08-09 20:43:12 +08:00
using osu.Framework.Extensions.ObjectExtensions;
2022-06-21 15:54:27 +08:00
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Osu.Difficulty.Preprocessing;
2022-08-11 03:04:38 +08:00
using osu.Game.Rulesets.Osu.Mods;
2022-06-21 20:15:31 +08:00
using osu.Game.Rulesets.Osu.Objects;
2022-06-21 15:54:27 +08:00
namespace osu.Game.Rulesets.Osu.Difficulty.Evaluators
{
2022-10-19 02:13:25 +08:00
public static class ReadingEvaluator
2022-06-21 15:54:27 +08:00
{
2022-10-19 02:13:25 +08:00
private const double reading_window_size = 3000;
2022-08-11 02:09:42 +08:00
2022-06-21 15:54:27 +08:00
public static double EvaluateDifficultyOf(DifficultyHitObject current, bool hidden)
{
2022-08-09 20:43:12 +08:00
if (current.BaseObject is Spinner || current.Index == 0)
2022-06-21 20:15:31 +08:00
return 0;
2022-06-21 15:54:27 +08:00
var currObj = (OsuDifficultyHitObject)current;
2022-06-22 06:21:57 +08:00
double currVelocity = currObj.LazyJumpDistance / currObj.StrainTime;
2022-06-21 15:54:27 +08:00
2022-08-11 03:04:38 +08:00
// Maybe I should just pass in clockrate...
var clockRateEstimate = current.BaseObject.StartTime / currObj.StartTime;
double pastObjectDifficultyInfluence = 1.0;
2022-10-19 19:56:21 +08:00
foreach (var loopObj in retrievePastVisibleObjects(currObj))
2022-07-20 02:17:16 +08:00
{
2022-08-11 02:09:42 +08:00
double loopDifficulty = currObj.OpacityAt(loopObj.BaseObject.StartTime, false);
2022-08-09 20:43:12 +08:00
2022-08-11 02:09:42 +08:00
// Small distances means objects may be cheesed, so it doesn't matter whether they are arranged confusingly.
2023-07-30 19:51:36 +08:00
loopDifficulty *= logistic((loopObj.MinimumJumpDistance - 90) / 15);
2022-08-09 20:43:12 +08:00
double timeBetweenCurrAndLoopObj = (currObj.BaseObject.StartTime - loopObj.BaseObject.StartTime) / clockRateEstimate;
loopDifficulty *= getTimeNerfFactor(timeBetweenCurrAndLoopObj);
2022-08-11 03:04:38 +08:00
pastObjectDifficultyInfluence += loopDifficulty;
2022-06-21 15:54:27 +08:00
}
2023-08-10 07:30:11 +08:00
double noteDensityDifficulty = Math.Pow(4 * Math.Log(Math.Max(1, pastObjectDifficultyInfluence - 3)), 2.3);
2022-10-05 08:32:05 +08:00
2022-06-22 06:21:57 +08:00
double hiddenDifficulty = 0;
2022-06-21 15:54:27 +08:00
2022-08-11 03:04:38 +08:00
if (hidden)
{
2022-10-19 19:56:21 +08:00
double timeSpentInvisible = getDurationSpentInvisible(currObj) / clockRateEstimate;
2023-07-30 19:51:36 +08:00
double timeDifficultyFactor = 1000 / pastObjectDifficultyInfluence;
2022-08-11 03:04:38 +08:00
2023-08-10 07:30:11 +08:00
double visibleObjectFactor = Math.Clamp(retrieveCurrentVisibleObjects(currObj).Count - 2, 0, 15);
2023-07-30 19:51:36 +08:00
hiddenDifficulty += Math.Pow(visibleObjectFactor * timeSpentInvisible / timeDifficultyFactor, 1) +
2023-08-10 07:30:11 +08:00
(8 + visibleObjectFactor) * currVelocity;
2022-08-11 03:04:38 +08:00
}
2022-10-18 05:05:04 +08:00
double difficulty = hiddenDifficulty + noteDensityDifficulty;
2022-10-19 02:09:49 +08:00
difficulty *= getConstantAngleNerfFactor(currObj);
2022-08-28 01:33:07 +08:00
2022-06-21 15:54:27 +08:00
return difficulty;
}
2022-07-20 02:17:16 +08:00
// Returns a list of objects that are visible on screen at
// the point in time at which the current object becomes visible.
2022-10-19 19:56:21 +08:00
private static IEnumerable<OsuDifficultyHitObject> retrievePastVisibleObjects(OsuDifficultyHitObject current)
2022-07-20 02:17:16 +08:00
{
for (int i = 0; i < current.Index; i++)
{
2022-10-19 19:56:21 +08:00
OsuDifficultyHitObject hitObject = (OsuDifficultyHitObject)current.Previous(i);
2022-07-20 02:17:16 +08:00
2022-10-19 19:56:21 +08:00
if (hitObject.IsNull() ||
current.StartTime - hitObject.StartTime > reading_window_size ||
2022-10-19 20:00:00 +08:00
hitObject.StartTime < current.StartTime - current.Preempt)
2022-07-20 02:17:16 +08:00
break;
2022-10-19 19:56:21 +08:00
yield return hitObject;
2022-07-20 02:17:16 +08:00
}
}
2023-07-30 19:51:36 +08:00
private static List<OsuDifficultyHitObject> retrieveCurrentVisibleObjects(OsuDifficultyHitObject current)
{
List<OsuDifficultyHitObject> objects = new List<OsuDifficultyHitObject>();
for (int i = 0; i < current.Count; i++)
{
OsuDifficultyHitObject hitObject = (OsuDifficultyHitObject)current.Next(i);
if (hitObject.IsNull() ||
(hitObject.StartTime - current.StartTime) > reading_window_size ||
current.StartTime < hitObject.StartTime - hitObject.Preempt)
break;
objects.Add(hitObject);
}
return objects;
}
2022-08-11 03:04:38 +08:00
private static double getDurationSpentInvisible(OsuDifficultyHitObject current)
{
var baseObject = (OsuHitObject)current.BaseObject;
double fadeOutStartTime = baseObject.StartTime - baseObject.TimePreempt + baseObject.TimeFadeIn;
double fadeOutDuration = baseObject.TimePreempt * OsuModHidden.FADE_OUT_DURATION_MULTIPLIER;
return (fadeOutStartTime + fadeOutDuration) - (baseObject.StartTime - baseObject.TimePreempt);
}
2022-10-08 03:26:56 +08:00
private static double getConstantAngleNerfFactor(OsuDifficultyHitObject current)
{
const double time_limit = 2000;
2022-10-19 02:09:49 +08:00
const double time_limit_low = 200;
2022-10-08 03:26:56 +08:00
double constantAngleCount = 0;
int index = 0;
double currentTimeGap = 0;
while (currentTimeGap < time_limit)
{
var loopObj = (OsuDifficultyHitObject)current.Previous(index);
if (loopObj.IsNull())
break;
double longIntervalFactor = Math.Clamp(1 - (loopObj.StrainTime - time_limit_low) / (time_limit - time_limit_low), 0, 1);
if (loopObj.Angle.IsNotNull() && current.Angle.IsNotNull())
{
double angleDifference = Math.Abs(current.Angle.Value - loopObj.Angle.Value);
2022-10-18 05:15:31 +08:00
constantAngleCount += Math.Cos(4 * Math.Min(Math.PI / 8, angleDifference)) * longIntervalFactor;
2022-10-08 03:26:56 +08:00
}
currentTimeGap = current.StartTime - loopObj.StartTime;
index++;
}
2022-10-19 19:56:21 +08:00
return Math.Pow(Math.Min(1, 2 / constantAngleCount), 2);
2022-10-08 03:26:56 +08:00
}
private static double getTimeNerfFactor(double deltaTime)
{
2022-10-19 19:56:21 +08:00
return Math.Clamp(2 - deltaTime / (reading_window_size / 2), 0, 1);
}
2022-06-21 15:54:27 +08:00
private static double logistic(double x) => 1 / (1 + Math.Pow(Math.E, -x));
}
}