1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 14:27:25 +08:00

Instancing a Ruleset only when it's necessary to

This commit is contained in:
Xesquim 2024-06-06 13:26:52 -03:00
parent dd3f4bcdab
commit 6e3bea938e

View File

@ -6,6 +6,7 @@ using System.Linq;
using Humanizer;
using Humanizer.Localisation;
using osu.Framework.Bindables;
using osu.Game.Rulesets.Mods;
using osu.Game.Utils;
namespace osu.Game.Online.Rooms
@ -44,9 +45,14 @@ namespace osu.Game.Online.Rooms
/// </summary>
public static string GetTotalDuration(this BindableList<PlaylistItem> playlist) =>
playlist.Select(p =>
{
IEnumerable<Mod> modList = [];
if (p.RequiredMods.Length > 0)
{
var ruleset = p.Beatmap.Ruleset.CreateInstance();
double rate = ModUtils.CalculateRateWithMods(p.RequiredMods.Select(mod => mod.ToMod(ruleset)));
modList = p.RequiredMods.Select(mod => mod.ToMod(ruleset));
}
double rate = ModUtils.CalculateRateWithMods(modList);
return p.Beatmap.Length / rate;
}).Sum().Milliseconds().Humanize(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Hour, precision: 2);
}