1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Merge pull request #24726 from peppy/skin-lookup-debug

Add debug output for skin configuration lookups
This commit is contained in:
Bartłomiej Dach 2023-09-06 19:28:59 +02:00 committed by GitHub
commit 9b202b5f21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 187 additions and 61 deletions

View File

@ -30,5 +30,7 @@ namespace osu.Game.Rulesets.Mania.Skinning
Lookup = lookup;
ColumnIndex = columnIndex;
}
public override string ToString() => $"[{nameof(ManiaSkinConfigurationLookup)} lookup:{Lookup} col:{ColumnIndex}]";
}
}

View File

@ -219,15 +219,20 @@ namespace osu.Game.Skinning
switch (global)
{
case GlobalSkinColours.ComboColours:
{
LogLookupDebug(this, lookup, LookupDebugType.Hit);
return SkinUtils.As<TValue>(new Bindable<IReadOnlyList<Color4>?>(Configuration.ComboColours));
}
}
break;
case SkinComboColourLookup comboColour:
LogLookupDebug(this, lookup, LookupDebugType.Hit);
return SkinUtils.As<TValue>(new Bindable<Color4>(getComboColour(Configuration, comboColour.ColourIndex)));
}
LogLookupDebug(this, lookup, LookupDebugType.Miss);
return null;
}

View File

@ -72,6 +72,8 @@ namespace osu.Game.Skinning
// If it is decided that we need this due to beatmaps somehow using it, the default (1.0 specified in LegacySkinDecoder.CreateTemplateObject)
// needs to be removed else it will cause incorrect skin behaviours. This is due to the config lookup having no context of which skin
// it should be returning the version for.
Skin.LogLookupDebug(this, lookup, Skin.LookupDebugType.Miss);
return null;
}

View File

@ -30,6 +30,8 @@ namespace osu.Game.Skinning
Lookup = lookup;
ColumnIndex = columnIndex;
}
public override string ToString() => $"[{nameof(LegacyManiaSkinConfigurationLookup)} lookup:{Lookup} col:{ColumnIndex} totalcols:{TotalColumns}]";
}
public enum LegacyManiaSkinConfigurationLookups

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
@ -82,50 +83,61 @@ namespace osu.Game.Skinning
}
}
[SuppressMessage("ReSharper", "RedundantAssignment")] // for `wasHit` assignments used in `finally` debug logic
public override IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup)
{
switch (lookup)
bool wasHit = true;
try
{
case GlobalSkinColours colour:
switch (colour)
{
case GlobalSkinColours.ComboColours:
var comboColours = Configuration.ComboColours;
if (comboColours != null)
return SkinUtils.As<TValue>(new Bindable<IReadOnlyList<Color4>>(comboColours));
switch (lookup)
{
case GlobalSkinColours colour:
switch (colour)
{
case GlobalSkinColours.ComboColours:
var comboColours = Configuration.ComboColours;
if (comboColours != null)
return SkinUtils.As<TValue>(new Bindable<IReadOnlyList<Color4>>(comboColours));
break;
break;
default:
return SkinUtils.As<TValue>(getCustomColour(Configuration, colour.ToString()));
}
default:
return SkinUtils.As<TValue>(getCustomColour(Configuration, colour.ToString()));
}
break;
case SkinComboColourLookup comboColour:
return SkinUtils.As<TValue>(GetComboColour(Configuration, comboColour.ColourIndex, comboColour.Combo));
case SkinCustomColourLookup customColour:
return SkinUtils.As<TValue>(getCustomColour(Configuration, customColour.Lookup.ToString() ?? string.Empty));
case LegacyManiaSkinConfigurationLookup maniaLookup:
if (!AllowManiaSkin)
break;
var result = lookupForMania<TValue>(maniaLookup);
if (result != null)
return result;
case SkinComboColourLookup comboColour:
return SkinUtils.As<TValue>(GetComboColour(Configuration, comboColour.ColourIndex, comboColour.Combo));
break;
case SkinCustomColourLookup customColour:
return SkinUtils.As<TValue>(getCustomColour(Configuration, customColour.Lookup.ToString() ?? string.Empty));
case SkinConfiguration.LegacySetting legacy:
return legacySettingLookup<TValue>(legacy);
case LegacyManiaSkinConfigurationLookup maniaLookup:
if (!AllowManiaSkin)
break;
default:
return genericLookup<TLookup, TValue>(lookup);
var result = lookupForMania<TValue>(maniaLookup);
if (result != null)
return result;
break;
case SkinConfiguration.LegacySetting legacy:
return legacySettingLookup<TValue>(legacy);
default:
return genericLookup<TLookup, TValue>(lookup);
}
wasHit = false;
return null;
}
finally
{
LogLookupDebug(this, lookup, wasHit ? LookupDebugType.Hit : LookupDebugType.Miss);
}
return null;
}
private IBindable<TValue>? lookupForMania<TValue>(LegacyManiaSkinConfigurationLookup maniaLookup)

View File

@ -46,7 +46,10 @@ namespace osu.Game.Skinning
public IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup)
where TLookup : notnull
where TValue : notnull
=> null;
{
Skin.LogLookupDebug(this, lookup, Skin.LookupDebugType.Miss);
return null;
}
public void Dispose()
{

View File

@ -6,10 +6,13 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using Newtonsoft.Json;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
@ -54,6 +57,8 @@ namespace osu.Game.Skinning
private readonly RealmBackedResourceStore<SkinInfo>? realmBackedStorage;
public string Name { get; }
/// <summary>
/// Construct a new skin.
/// </summary>
@ -63,6 +68,8 @@ namespace osu.Game.Skinning
/// <param name="configurationFilename">An optional filename to read the skin configuration from. If not provided, the configuration will be retrieved from the storage using "skin.ini".</param>
protected Skin(SkinInfo skin, IStorageResourceProvider? resources, IResourceStore<byte[]>? storage = null, string configurationFilename = @"skin.ini")
{
Name = skin.Name;
if (resources != null)
{
SkinInfo = skin.ToLive(resources.RealmAccess);
@ -239,5 +246,50 @@ namespace osu.Game.Skinning
}
#endregion
public override string ToString() => $"{GetType().ReadableName()} {{ Name: {Name} }}";
private static readonly ThreadLocal<int> nested_level = new ThreadLocal<int>(() => 0);
[Conditional("SKIN_LOOKUP_DEBUG")]
internal static void LogLookupDebug(object callingClass, object lookup, LookupDebugType type, [CallerMemberName] string callerMethod = "")
{
string icon = string.Empty;
int level = nested_level.Value;
switch (type)
{
case LookupDebugType.Hit:
icon = "🟢 hit";
break;
case LookupDebugType.Miss:
icon = "🔴 miss";
break;
case LookupDebugType.Enter:
nested_level.Value++;
break;
case LookupDebugType.Exit:
nested_level.Value--;
if (nested_level.Value == 0)
Logger.Log(string.Empty);
return;
}
string lookupString = lookup.ToString() ?? string.Empty;
string callingClassString = callingClass.ToString() ?? string.Empty;
Logger.Log($"{string.Join(null, Enumerable.Repeat("|-", level))}{callingClassString}.{callerMethod}(lookup: {lookupString}) {icon}");
}
internal enum LookupDebugType
{
Hit,
Miss,
Enter,
Exit
}
}
}

View File

@ -261,13 +261,22 @@ namespace osu.Game.Skinning
private T lookupWithFallback<T>(Func<ISkin, T> lookupFunction)
where T : class
{
foreach (var source in AllSources)
try
{
if (lookupFunction(source) is T skinSourced)
return skinSourced;
}
Skin.LogLookupDebug(this, lookupFunction, Skin.LookupDebugType.Enter);
return null;
foreach (var source in AllSources)
{
if (lookupFunction(source) is T skinSourced)
return skinSourced;
}
return null;
}
finally
{
Skin.LogLookupDebug(this, lookupFunction, Skin.LookupDebugType.Exit);
}
}
#region IResourceStorageProvider

View File

@ -7,6 +7,7 @@ using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
@ -161,17 +162,26 @@ namespace osu.Game.Skinning
where TLookup : notnull
where TValue : notnull
{
foreach (var (_, lookupWrapper) in skinSources)
try
{
IBindable<TValue>? bindable;
if ((bindable = lookupWrapper.GetConfig<TLookup, TValue>(lookup)) != null)
return bindable;
Skin.LogLookupDebug(this, lookup, Skin.LookupDebugType.Enter);
foreach (var (_, lookupWrapper) in skinSources)
{
IBindable<TValue>? bindable;
if ((bindable = lookupWrapper.GetConfig<TLookup, TValue>(lookup)) != null)
return bindable;
}
if (!AllowFallingBackToParent)
return null;
return ParentSource?.GetConfig<TLookup, TValue>(lookup);
}
finally
{
Skin.LogLookupDebug(this, lookup, Skin.LookupDebugType.Exit);
}
if (!AllowFallingBackToParent)
return null;
return ParentSource?.GetConfig<TLookup, TValue>(lookup);
}
/// <summary>
@ -271,25 +281,36 @@ namespace osu.Game.Skinning
where TLookup : notnull
where TValue : notnull
{
switch (lookup)
try
{
case GlobalSkinColours:
case SkinComboColourLookup:
case SkinCustomColourLookup:
if (provider.AllowColourLookup)
return skin.GetConfig<TLookup, TValue>(lookup);
Skin.LogLookupDebug(this, lookup, Skin.LookupDebugType.Enter);
break;
switch (lookup)
{
case GlobalSkinColours:
case SkinComboColourLookup:
case SkinCustomColourLookup:
if (provider.AllowColourLookup)
return skin.GetConfig<TLookup, TValue>(lookup);
default:
if (provider.AllowConfigurationLookup)
return skin.GetConfig<TLookup, TValue>(lookup);
break;
break;
default:
if (provider.AllowConfigurationLookup)
return skin.GetConfig<TLookup, TValue>(lookup);
break;
}
return null;
}
finally
{
Skin.LogLookupDebug(this, lookup, Skin.LookupDebugType.Exit);
}
return null;
}
public override string ToString() => $"{GetType().ReadableName()} {{ Skin: {skin} }}";
}
}
}

View File

@ -34,6 +34,19 @@ namespace osu.Game.Skinning
public virtual ISample? GetSample(ISampleInfo sampleInfo) => Skin.GetSample(sampleInfo);
public virtual IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup) where TLookup : notnull where TValue : notnull => Skin.GetConfig<TLookup, TValue>(lookup);
public virtual IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup) where TLookup : notnull where TValue : notnull
{
try
{
Skinning.Skin.LogLookupDebug(this, lookup, Skinning.Skin.LookupDebugType.Enter);
return Skin.GetConfig<TLookup, TValue>(lookup);
}
finally
{
Skinning.Skin.LogLookupDebug(this, lookup, Skinning.Skin.LookupDebugType.Exit);
}
}
public override string ToString() => $"{nameof(SkinTransformer)} {{ Skin: {Skin} }}";
}
}

View File

@ -190,15 +190,20 @@ namespace osu.Game.Skinning
switch (global)
{
case GlobalSkinColours.ComboColours:
{
LogLookupDebug(this, lookup, LookupDebugType.Hit);
return SkinUtils.As<TValue>(new Bindable<IReadOnlyList<Color4>?>(Configuration.ComboColours));
}
}
break;
case SkinComboColourLookup comboColour:
LogLookupDebug(this, lookup, LookupDebugType.Hit);
return SkinUtils.As<TValue>(new Bindable<Color4>(getComboColour(Configuration, comboColour.ColourIndex)));
}
LogLookupDebug(this, lookup, LookupDebugType.Miss);
return null;
}