-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0944f00
commit ee54da9
Showing
3 changed files
with
80 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Osu.Patcher.Hook/Patches/LivePerformance/PerformanceCalculator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using Osu.Performance; | ||
using Osu.Stubs; | ||
|
||
namespace Osu.Patcher.Hook.Patches.LivePerformance; | ||
|
||
/// <summary> | ||
/// Handles initializing and disposing the performance calculator based on current score and settings. | ||
/// </summary> | ||
internal static class PerformanceCalculator | ||
{ | ||
public static OsuPerformance? Calculator { get; private set; } | ||
|
||
public static bool IsInitialized => Calculator != null; | ||
|
||
/// <summary> | ||
/// Disposes the existing performance calculator, and initializes a new one according to the current score info. | ||
/// This must be called after <c>Ruleset::ResetScore()</c> | ||
/// </summary> | ||
public static void ResetCalculator() | ||
{ | ||
try | ||
{ | ||
ResetCalculatorSync(); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine($"Failed to reset performance calculator: {e}"); | ||
} | ||
} | ||
|
||
private static void ResetCalculatorSync() | ||
{ | ||
Debug.WriteLine("Resetting performance calculator"); | ||
|
||
// TODO: don't dispose it if the beatmap is the same, reuse parsed beatmap in native side | ||
Calculator?.Dispose(); | ||
Calculator = null; | ||
|
||
var currentScore = Player.CurrentScore.Get(); | ||
if (currentScore == null) return; | ||
|
||
var modsObfuscated = Score.EnabledMods.Get(currentScore); | ||
var mods = Score.EnabledModsGetValue.Invoke(modsObfuscated); | ||
|
||
// Clear relax mod for now (live pp calculations for relax are fucking garbage) | ||
mods &= ~(1 << 7); | ||
|
||
var beatmap = Score.Beatmap.Get(currentScore); | ||
if (beatmap == null) return; | ||
|
||
var beatmapPath = Beatmap.GetBeatmapPath(beatmap); | ||
if (beatmapPath == null) return; | ||
|
||
Calculator = new OsuPerformance(beatmapPath, (uint)mods); | ||
Calculator.OnNewCalculation += Console.WriteLine; | ||
|
||
Debug.WriteLine("Initialized performance calculator!"); | ||
} | ||
} |