Skip to content

Preliminary fixes for off-the-charts allocations #26422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Layout;
using osu.Game.Audio;
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Objects;
Expand Down Expand Up @@ -66,6 +67,8 @@ public partial class DrawableSlider : DrawableOsuHitObject
private Container<DrawableSliderRepeat> repeatContainer;
private PausableSkinnableSound slidingSample;

private readonly LayoutValue drawSizeLayout;

public DrawableSlider()
: this(null)
{
Expand All @@ -82,6 +85,7 @@ public DrawableSlider([CanBeNull] Slider s = null)
AlwaysPresent = true,
Alpha = 0
};
AddLayout(drawSizeLayout = new LayoutValue(Invalidation.DrawSize | Invalidation.MiscGeometry));
}

[BackgroundDependencyLoader]
Expand Down Expand Up @@ -246,21 +250,20 @@ protected override void Update()
Ball.UpdateProgress(completionProgress);
SliderBody?.UpdateProgress(HeadCircle.IsHit ? completionProgress : 0);

foreach (DrawableHitObject hitObject in NestedHitObjects)
{
if (hitObject is ITrackSnaking s)
s.UpdateSnakingPosition(HitObject.Path.PositionAt(SliderBody?.SnakedStart ?? 0), HitObject.Path.PositionAt(SliderBody?.SnakedEnd ?? 0));
}
foreach (DrawableSliderRepeat repeat in repeatContainer)
repeat.UpdateSnakingPosition(HitObject.Path.PositionAt(SliderBody?.SnakedStart ?? 0), HitObject.Path.PositionAt(SliderBody?.SnakedEnd ?? 0));

Size = SliderBody?.Size ?? Vector2.Zero;
OriginPosition = SliderBody?.PathOffset ?? Vector2.Zero;

if (DrawSize != Vector2.Zero)
if (!drawSizeLayout.IsValid)
{
var childAnchorPosition = Vector2.Divide(OriginPosition, DrawSize);
Vector2 pos = Vector2.Divide(OriginPosition, DrawSize);
foreach (var obj in NestedHitObjects)
obj.RelativeAnchorPosition = childAnchorPosition;
Ball.RelativeAnchorPosition = childAnchorPosition;
obj.RelativeAnchorPosition = pos;
Ball.RelativeAnchorPosition = pos;

drawSizeLayout.Validate();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public partial class DrawableSliderRepeat : DrawableOsuHitObject, ITrackSnaking
public partial class DrawableSliderRepeat : DrawableOsuHitObject
{
public new SliderRepeat HitObject => (SliderRepeat)base.HitObject;

Expand Down
15 changes: 0 additions & 15 deletions osu.Game.Rulesets.Osu/Objects/Drawables/ITrackSnaking.cs

This file was deleted.

4 changes: 3 additions & 1 deletion osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,9 @@ protected double CalculateSamplePlaybackBalance(double position)
float balanceAdjustAmount = positionalHitsoundsLevel.Value * 2;
double returnedValue = balanceAdjustAmount * (position - 0.5f);

return returnedValue;
// Rounded to reduce the overhead of audio adjustments (which are currently bindable heavy).
// Balance is very hard to perceive in small increments anyways.
return Math.Round(returnedValue, 2);
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions osu.Game/Screens/Play/HUD/ArgonAccuracyCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ public ArgonAccuracyTextComponent()
},
fractionPart = new ArgonCounterTextComponent(Anchor.TopLeft)
{
RequiredDisplayDigits = { Value = 2 },
WireframeOpacity = { BindTarget = WireframeOpacity },
Scale = new Vector2(0.5f),
},
percentText = new ArgonCounterTextComponent(Anchor.TopLeft)
{
Text = @"%",
RequiredDisplayDigits = { Value = 1 },
WireframeOpacity = { BindTarget = WireframeOpacity }
},
}
Expand Down
25 changes: 25 additions & 0 deletions osu.Game/Screens/Play/HUD/ArgonComboCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ private void load(ScoreProcessor scoreProcessor)
});
}

public override int DisplayedCount
{
get => base.DisplayedCount;
set
{
base.DisplayedCount = value;
updateWireframe();
}
}

private void updateWireframe()
{
text.RequiredDisplayDigits.Value = getDigitsRequiredForDisplayCount();
}

private int getDigitsRequiredForDisplayCount()
{
// one for the single presumed starting digit, one for the "x" at the end.
int digitsRequired = 2;
long c = DisplayedCount;
while ((c /= 10) > 0)
digitsRequired++;
return digitsRequired;
}

protected override LocalisableString FormatCount(int count) => $@"{count}x";

protected override IHasText CreateText() => text = new ArgonCounterTextComponent(Anchor.TopLeft, MatchesStrings.MatchScoreStatsCombo.ToUpper())
Expand Down
41 changes: 26 additions & 15 deletions osu.Game/Screens/Play/HUD/ArgonCounterTextComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
Expand Down Expand Up @@ -33,14 +33,7 @@ public partial class ArgonCounterTextComponent : CompositeDrawable, IHasText
public LocalisableString Text
{
get => textPart.Text;
set
{
int remainingCount = RequiredDisplayDigits.Value - value.ToString().Count(char.IsDigit);
string remainingText = remainingCount > 0 ? new string('#', remainingCount) : string.Empty;

wireframesPart.Text = remainingText + value;
textPart.Text = value;
}
set => textPart.Text = value;
}

public ArgonCounterTextComponent(Anchor anchor, LocalisableString? label = null)
Expand Down Expand Up @@ -81,6 +74,8 @@ public ArgonCounterTextComponent(Anchor anchor, LocalisableString? label = null)
}
}
};

RequiredDisplayDigits.BindValueChanged(digits => wireframesPart.Text = new string('#', digits.NewValue));
}

private string textLookup(char c)
Expand Down Expand Up @@ -137,33 +132,49 @@ public ArgonCounterSpriteText(Func<char, string> getLookup)
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
const string font_name = @"argon-counter";

Spacing = new Vector2(-2f, 0f);
Font = new FontUsage(@"argon-counter", 1);
glyphStore = new GlyphStore(textures, getLookup);
Font = new FontUsage(font_name, 1);
glyphStore = new GlyphStore(font_name, textures, getLookup);
}

protected override TextBuilder CreateTextBuilder(ITexturedGlyphLookupStore store) => base.CreateTextBuilder(glyphStore);

private class GlyphStore : ITexturedGlyphLookupStore
{
private readonly string fontName;
private readonly TextureStore textures;
private readonly Func<char, string> getLookup;

public GlyphStore(TextureStore textures, Func<char, string> getLookup)
private readonly Dictionary<char, ITexturedCharacterGlyph?> cache = new Dictionary<char, ITexturedCharacterGlyph?>();

public GlyphStore(string fontName, TextureStore textures, Func<char, string> getLookup)
{
this.fontName = fontName;
this.textures = textures;
this.getLookup = getLookup;
}

public ITexturedCharacterGlyph? Get(string? fontName, char character)
{
// We only service one font.
if (fontName != this.fontName)
return null;

if (cache.TryGetValue(character, out var cached))
return cached;

string lookup = getLookup(character);
var texture = textures.Get($"Gameplay/Fonts/{fontName}-{lookup}");

if (texture == null)
return null;
TexturedCharacterGlyph? glyph = null;

if (texture != null)
glyph = new TexturedCharacterGlyph(new CharacterGlyph(character, 0, 0, texture.Width, texture.Height, null), texture, 0.125f);

return new TexturedCharacterGlyph(new CharacterGlyph(character, 0, 0, texture.Width, texture.Height, null), texture, 0.125f);
cache[character] = glyph;
return glyph;
}

public Task<ITexturedCharacterGlyph?> GetAsync(string fontName, char character) => Task.Run(() => Get(fontName, character));
Expand Down
16 changes: 12 additions & 4 deletions osu.Game/Screens/Play/HUD/ArgonHealthDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Caching;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
Expand Down Expand Up @@ -68,11 +69,11 @@ public double GlowBarValue
get => glowBarValue;
set
{
if (glowBarValue == value)
if (Precision.AlmostEquals(glowBarValue, value, 0.0001))
return;

glowBarValue = value;
Scheduler.AddOnce(updatePathVertices);
pathVerticesCache.Invalidate();
}
}

Expand All @@ -83,11 +84,11 @@ public double HealthBarValue
get => healthBarValue;
set
{
if (healthBarValue == value)
if (Precision.AlmostEquals(healthBarValue, value, 0.0001))
return;

healthBarValue = value;
Scheduler.AddOnce(updatePathVertices);
pathVerticesCache.Invalidate();
}
}

Expand All @@ -100,6 +101,8 @@ public double HealthBarValue

private readonly LayoutValue drawSizeLayout = new LayoutValue(Invalidation.DrawSize);

private readonly Cached pathVerticesCache = new Cached();

public ArgonHealthDisplay()
{
AddLayout(drawSizeLayout);
Expand Down Expand Up @@ -208,6 +211,9 @@ protected override void Update()
drawSizeLayout.Validate();
}

if (!pathVerticesCache.IsValid)
updatePathVertices();

mainBar.Alpha = (float)Interpolation.DampContinuously(mainBar.Alpha, Current.Value > 0 ? 1 : 0, 40, Time.Elapsed);
glowBar.Alpha = (float)Interpolation.DampContinuously(glowBar.Alpha, GlowBarValue > 0 ? 1 : 0, 40, Time.Elapsed);
}
Expand Down Expand Up @@ -346,6 +352,8 @@ private void updatePathVertices()

mainBar.Vertices = healthBarVertices.Select(v => v - healthBarVertices[0]).ToList();
mainBar.Position = healthBarVertices[0];

pathVerticesCache.Validate();
}

protected override void Dispose(bool isDisposing)
Expand Down
36 changes: 34 additions & 2 deletions osu.Game/Screens/Play/HUD/ArgonScoreCounter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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 osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
Expand All @@ -15,6 +16,8 @@ namespace osu.Game.Screens.Play.HUD
{
public partial class ArgonScoreCounter : GameplayScoreCounter, ISerialisableDrawable
{
private ArgonScoreTextComponent scoreText = null!;

protected override double RollingDuration => 500;
protected override Easing RollingEasing => Easing.OutQuint;

Expand All @@ -33,13 +36,42 @@ public partial class ArgonScoreCounter : GameplayScoreCounter, ISerialisableDraw

protected override LocalisableString FormatCount(long count) => count.ToLocalisableString();

protected override IHasText CreateText() => new ArgonScoreTextComponent(Anchor.TopRight, BeatmapsetsStrings.ShowScoreboardHeadersScore.ToUpper())
protected override IHasText CreateText() => scoreText = new ArgonScoreTextComponent(Anchor.TopRight, BeatmapsetsStrings.ShowScoreboardHeadersScore.ToUpper())
{
RequiredDisplayDigits = { BindTarget = RequiredDisplayDigits },
WireframeOpacity = { BindTarget = WireframeOpacity },
ShowLabel = { BindTarget = ShowLabel },
};

public ArgonScoreCounter()
{
RequiredDisplayDigits.BindValueChanged(_ => updateWireframe());
}

public override long DisplayedCount
{
get => base.DisplayedCount;
set
{
base.DisplayedCount = value;
updateWireframe();
}
}

private void updateWireframe()
{
scoreText.RequiredDisplayDigits.Value =
Math.Max(RequiredDisplayDigits.Value, getDigitsRequiredForDisplayCount());
}

private int getDigitsRequiredForDisplayCount()
{
int digitsRequired = 1;
long c = DisplayedCount;
while ((c /= 10) > 0)
digitsRequired++;
return digitsRequired;
}

private partial class ArgonScoreTextComponent : ArgonCounterTextComponent
{
public ArgonScoreTextComponent(Anchor anchor, LocalisableString? label = null)
Expand Down
5 changes: 0 additions & 5 deletions osu.Game/Screens/Play/HUD/ComboCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ public abstract partial class ComboCounter : RollingCounter<int>, ISerialisableD
{
public bool UsesFixedAnchor { get; set; }

protected ComboCounter()
{
Current.Value = DisplayedCount = 0;
}

protected override double GetProportionalDuration(int currentValue, int newValue)
{
return Math.Abs(currentValue - newValue) * RollingDuration * 100.0f;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Play/HUD/HealthDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract partial class HealthDisplay : CompositeDrawable
public Bindable<double> Current { get; } = new BindableDouble
{
MinValue = 0,
MaxValue = 1
MaxValue = 1,
};

private BindableNumber<double> health = null!;
Expand Down
Loading