Set default history retention to 0 for Skill and override in StrainSkill

Some skills might not even require history retention, so why waste the allocations?
This commit is contained in:
Samuel Cattini-Schultz
2021-04-06 11:53:31 +10:00
parent 4f614a703e
commit 5cd43b3a7f
2 changed files with 18 additions and 5 deletions

View File

@ -22,8 +22,9 @@ namespace osu.Game.Rulesets.Difficulty.Skills
/// Soft capacity of the <see cref="Previous"/> queue.
/// <see cref="Previous"/> will automatically resize if it exceeds capacity, but will do so at a very slight performance impact.
/// The actual capacity will be set to this value + 1 to allow for storage of the current object before the next can be processed.
/// Setting to zero (default) will cause <see cref="Previous"/> to be uninstanciated.
/// </summary>
protected virtual int PreviousCollectionSoftCapacity => 1;
protected virtual int PreviousCollectionSoftCapacity => 0;
/// <summary>
/// Mods for use in skill calculations.
@ -35,7 +36,9 @@ namespace osu.Game.Rulesets.Difficulty.Skills
protected Skill(Mod[] mods)
{
this.mods = mods;
Previous = new ReverseQueue<DifficultyHitObject>(PreviousCollectionSoftCapacity + 1);
if (PreviousCollectionSoftCapacity > 0)
Previous = new ReverseQueue<DifficultyHitObject>(PreviousCollectionSoftCapacity + 1);
}
internal void ProcessInternal(DifficultyHitObject current)
@ -51,8 +54,6 @@ namespace osu.Game.Rulesets.Difficulty.Skills
/// <param name="current">The <see cref="DifficultyHitObject"/> to be processed.</param>
protected virtual void RemoveExtraneousHistory(DifficultyHitObject current)
{
while (Previous.Count > 1)
Previous.Dequeue();
}
/// <summary>
@ -61,7 +62,6 @@ namespace osu.Game.Rulesets.Difficulty.Skills
/// <param name="current">The <see cref="DifficultyHitObject"/> that was just processed.</param>
protected virtual void AddToHistory(DifficultyHitObject current)
{
Previous.Enqueue(current);
}
/// <summary>

View File

@ -20,6 +20,8 @@ namespace osu.Game.Rulesets.Difficulty.Skills
/// </summary>
protected abstract double SkillMultiplier { get; }
protected override int PreviousCollectionSoftCapacity => 1;
/// <summary>
/// Determines how quickly strain decays for the given skill.
/// For example a value of 0.15 indicates that strain decays to 15% of its original value in one second.
@ -52,6 +54,17 @@ namespace osu.Game.Rulesets.Difficulty.Skills
{
}
protected override void RemoveExtraneousHistory(DifficultyHitObject current)
{
while (Previous.Count > 1)
Previous.Dequeue();
}
protected override void AddToHistory(DifficultyHitObject current)
{
Previous.Enqueue(current);
}
/// <summary>
/// Process a <see cref="DifficultyHitObject"/> and update current strain values accordingly.
/// </summary>