1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 15:27:30 +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
@ -45,8 +46,13 @@ namespace osu.Game.Online.Rooms
public static string GetTotalDuration(this BindableList<PlaylistItem> playlist) =>
playlist.Select(p =>
{
var ruleset = p.Beatmap.Ruleset.CreateInstance();
double rate = ModUtils.CalculateRateWithMods(p.RequiredMods.Select(mod => mod.ToMod(ruleset)));
IEnumerable<Mod> modList = [];
if (p.RequiredMods.Length > 0)
{
var ruleset = p.Beatmap.Ruleset.CreateInstance();
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);
}