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 10 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
28 changes: 18 additions & 10 deletions osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public partial class DrawableSlider : DrawableOsuHitObject

private ShakeContainer shakeContainer;

private Vector2? childAnchorPosition;

protected override IEnumerable<Drawable> DimmablePieces => new Drawable[]
{
HeadCircle,
Expand Down Expand Up @@ -119,7 +121,11 @@ private void load()
}
});

PositionBindable.BindValueChanged(_ => Position = HitObject.StackedPosition);
PositionBindable.BindValueChanged(_ =>
{
Position = HitObject.StackedPosition;
childAnchorPosition = null;
});
StackHeightBindable.BindValueChanged(_ => Position = HitObject.StackedPosition);
ScaleBindable.BindValueChanged(scale => Ball.Scale = new Vector2(scale.NewValue));

Expand Down Expand Up @@ -246,21 +252,23 @@ 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)
{
var childAnchorPosition = Vector2.Divide(OriginPosition, DrawSize);
foreach (var obj in NestedHitObjects)
obj.RelativeAnchorPosition = childAnchorPosition;
Ball.RelativeAnchorPosition = childAnchorPosition;
Vector2 pos = Vector2.Divide(OriginPosition, DrawSize);

if (pos != childAnchorPosition)
{
childAnchorPosition = pos;
foreach (var obj in NestedHitObjects)
obj.RelativeAnchorPosition = pos;
Ball.RelativeAnchorPosition = pos;
}
}
}

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
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,8 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
Expand Down Expand Up @@ -33,14 +34,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 +75,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 +133,48 @@ 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.
Debug.Assert(fontName == this.fontName);

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
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
35 changes: 27 additions & 8 deletions osu.Game/Skinning/LegacySpriteText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
Expand Down Expand Up @@ -44,10 +45,11 @@ public LegacySpriteText(LegacyFont font)
[BackgroundDependencyLoader]
private void load(ISkinSource skin)
{
base.Font = new FontUsage(skin.GetFontPrefix(font), 1, fixedWidth: FixedWidth);
string fontPrefix = skin.GetFontPrefix(font);
base.Font = new FontUsage(fontPrefix, 1, fixedWidth: FixedWidth);
Spacing = new Vector2(-skin.GetFontOverlap(font), 0);

glyphStore = new LegacyGlyphStore(skin, MaxSizePerGlyph);
glyphStore = new LegacyGlyphStore(fontPrefix, skin, MaxSizePerGlyph);
}

protected override TextBuilder CreateTextBuilder(ITexturedGlyphLookupStore store) => base.CreateTextBuilder(glyphStore);
Expand All @@ -57,25 +59,42 @@ private class LegacyGlyphStore : ITexturedGlyphLookupStore
private readonly ISkin skin;
private readonly Vector2? maxSize;

public LegacyGlyphStore(ISkin skin, Vector2? maxSize)
private readonly string fontName;

private readonly Dictionary<char, ITexturedCharacterGlyph?> cache = new Dictionary<char, ITexturedCharacterGlyph?>();

public LegacyGlyphStore(string fontName, ISkin skin, Vector2? maxSize)
{
this.fontName = fontName;
this.skin = skin;
this.maxSize = maxSize;
}

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 = getLookupName(character);

var texture = skin.GetTexture($"{fontName}-{lookup}");

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

if (texture != null)
{
if (maxSize != null)
texture = texture.WithMaximumSize(maxSize.Value);

if (maxSize != null)
texture = texture.WithMaximumSize(maxSize.Value);
glyph = new TexturedCharacterGlyph(new CharacterGlyph(character, 0, 0, texture.Width, texture.Height, null), texture, 1f / texture.ScaleAdjust);
}

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

private static string getLookupName(char character)
Expand Down
28 changes: 26 additions & 2 deletions osu.Game/Skinning/SkinnableSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,33 @@ private void updateSamples()
/// <summary>
/// Whether any samples are currently playing.
/// </summary>
public bool IsPlaying => samplesContainer.Any(s => s.Playing);
public bool IsPlaying
{
get
{
foreach (PoolableSkinnableSample s in samplesContainer)
{
if (s.Playing)
return true;
}

return false;
}
}

public bool IsPlayed => samplesContainer.Any(s => s.Played);
public bool IsPlayed
{
get
{
foreach (PoolableSkinnableSample s in samplesContainer)
{
if (s.Played)
return true;
}

return false;
}
}

public IBindable<double> AggregateVolume => samplesContainer.AggregateVolume;

Expand Down