1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-24 14:10:40 +08:00
Files
osu-lazer/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs
T
StanR fadb1c3f2c Calculate clock time when creating difficulty hit objects (#36962)
This change removes `clockRate` precalculation from
`DifficultyCalculator`.

The idea is that clock rate should be calculated in-place (ideally for
every object) since we store and access it using DHOs. This also
prevents anyone from accidentally passing clock rate to skills

Unfortunately osu uses clock rate to calculate OD for the whole map in
`CreateDifficultyAttributes` so we can't make it completely DHO-based,
but I think one single in-place call to `ModUtils.CalculateRateWithMods`
in `CreateDifficultyAttributes` is fine

---------

Co-authored-by: James Wilson <tsunyoku@gmail.com>
2026-03-16 21:17:49 +00:00

94 lines
3.3 KiB
C#

// 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.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Beatmaps;
using osu.Game.Rulesets.Catch.Difficulty.Preprocessing;
using osu.Game.Rulesets.Catch.Difficulty.Skills;
using osu.Game.Rulesets.Catch.Mods;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Difficulty.Skills;
using osu.Game.Rulesets.Mods;
using osu.Game.Utils;
namespace osu.Game.Rulesets.Catch.Difficulty
{
public class CatchDifficultyCalculator : DifficultyCalculator
{
private const double difficulty_multiplier = 4.59;
public override int Version => 20251020;
public CatchDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap)
: base(ruleset, beatmap)
{
}
protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills)
{
if (beatmap.HitObjects.Count == 0)
return new CatchDifficultyAttributes { Mods = mods };
CatchDifficultyAttributes attributes = new CatchDifficultyAttributes
{
StarRating = Math.Sqrt(skills.OfType<Movement>().Single().DifficultyValue()) * difficulty_multiplier,
Mods = mods,
MaxCombo = beatmap.GetMaxCombo(),
};
return attributes;
}
protected override IEnumerable<DifficultyHitObject> CreateDifficultyHitObjects(IBeatmap beatmap, Mod[] mods)
{
CatchHitObject? lastObject = null;
List<DifficultyHitObject> objects = new List<DifficultyHitObject>();
double clockRate = ModUtils.CalculateRateWithMods(mods);
float halfCatcherWidth = Catcher.CalculateCatchWidth(beatmap.Difficulty) * 0.5f;
// For circle sizes above 5.5, reduce the catcher width further to simulate imperfect gameplay.
halfCatcherWidth *= 1 - (Math.Max(0, beatmap.Difficulty.CircleSize - 5.5f) * 0.0625f);
// In 2B beatmaps, it is possible that a normal Fruit is placed in the middle of a JuiceStream.
foreach (var hitObject in CatchBeatmap.GetPalpableObjects(beatmap.HitObjects))
{
// We want to only consider fruits that contribute to the combo.
if (hitObject is Banana || hitObject is TinyDroplet)
continue;
if (lastObject != null)
objects.Add(new CatchDifficultyHitObject(hitObject, lastObject, clockRate, halfCatcherWidth, objects, objects.Count));
lastObject = hitObject;
}
return objects;
}
protected override Skill[] CreateSkills(IBeatmap beatmap, Mod[] mods)
{
return new Skill[]
{
new Movement(mods),
};
}
protected override Mod[] DifficultyAdjustmentMods => new Mod[]
{
new CatchModDoubleTime(),
new CatchModHalfTime(),
new CatchModHardRock(),
new CatchModEasy(),
};
}
}