mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 17:52:56 +08:00
Fix skin file path lookup performance
Move path mapping to the resource store, so caching can happen against the component's name rather than the skin path. Fixes regression of beatmap load time when a custom skin is selected.
This commit is contained in:
parent
d3092a3003
commit
30b1447318
@ -1,9 +1,6 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Graphics;
|
||||
@ -22,16 +19,14 @@ namespace osu.Game.Skinning
|
||||
public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager)
|
||||
: base(skin)
|
||||
{
|
||||
storage = new SkinResourceStore(skin, storage);
|
||||
samples = audioManager.GetSampleManager(storage);
|
||||
textures = new TextureStore(new RawTextureLoaderStore(storage));
|
||||
}
|
||||
|
||||
private string getPathForFile(string filename) =>
|
||||
SkinInfo.Files.FirstOrDefault(f => string.Equals(Path.GetFileNameWithoutExtension(f.Filename), filename, StringComparison.InvariantCultureIgnoreCase))?.FileInfo.StoragePath;
|
||||
|
||||
public override Drawable GetDrawableComponent(string componentName)
|
||||
{
|
||||
var texture = textures.Get(getPathForFile(componentName.Split('/').Last()));
|
||||
var texture = textures.Get(componentName);
|
||||
if (texture == null) return null;
|
||||
|
||||
return new Sprite
|
||||
@ -42,6 +37,6 @@ namespace osu.Game.Skinning
|
||||
};
|
||||
}
|
||||
|
||||
public override SampleChannel GetSample(string sampleName) => samples.Get(getPathForFile(sampleName.Split('/').Last()));
|
||||
public override SampleChannel GetSample(string sampleName) => samples.Get(sampleName);
|
||||
}
|
||||
}
|
||||
|
29
osu.Game/Skinning/SkinResourceStore.cs
Normal file
29
osu.Game/Skinning/SkinResourceStore.cs
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using osu.Framework.IO.Stores;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
public class SkinResourceStore : IResourceStore<byte[]>
|
||||
{
|
||||
private readonly SkinInfo skin;
|
||||
private readonly IResourceStore<byte[]> underlyingStore;
|
||||
|
||||
private string getPathForFile(string filename) =>
|
||||
skin.Files.FirstOrDefault(f => string.Equals(Path.GetFileNameWithoutExtension(f.Filename), filename.Split('/').Last(), StringComparison.InvariantCultureIgnoreCase))?.FileInfo.StoragePath;
|
||||
|
||||
public SkinResourceStore(SkinInfo skin, IResourceStore<byte[]> underlyingStore)
|
||||
{
|
||||
this.skin = skin;
|
||||
this.underlyingStore = underlyingStore;
|
||||
}
|
||||
|
||||
public Stream GetStream(string name) => underlyingStore.GetStream(getPathForFile(name));
|
||||
|
||||
byte[] IResourceStore<byte[]>.Get(string name) => underlyingStore.Get(getPathForFile(name));
|
||||
}
|
||||
}
|
@ -870,6 +870,7 @@
|
||||
<Compile Include="Skinning\SkinnableDrawable.cs" />
|
||||
<Compile Include="Skinning\SkinnableSound.cs" />
|
||||
<Compile Include="Skinning\SkinReloadableDrawable.cs" />
|
||||
<Compile Include="Skinning\SkinResourceStore.cs" />
|
||||
<Compile Include="Skinning\SkinStore.cs" />
|
||||
<Compile Include="Storyboards\CommandLoop.cs" />
|
||||
<Compile Include="Storyboards\CommandTimeline.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user