mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Move ruleset dependencies caching to its own container
This commit is contained in:
@ -11,20 +11,15 @@ using osu.Game.Rulesets.Objects;
|
|||||||
using osu.Game.Rulesets.Objects.Drawables;
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Audio;
|
|
||||||
using osu.Framework.Audio.Sample;
|
|
||||||
using osu.Framework.Audio.Track;
|
using osu.Framework.Audio.Track;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.IO.Stores;
|
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics.Cursor;
|
using osu.Game.Graphics.Cursor;
|
||||||
using osu.Game.Input.Handlers;
|
using osu.Game.Input.Handlers;
|
||||||
@ -113,6 +108,8 @@ namespace osu.Game.Rulesets.UI
|
|||||||
|
|
||||||
private OnScreenDisplay onScreenDisplay;
|
private OnScreenDisplay onScreenDisplay;
|
||||||
|
|
||||||
|
private DrawableRulesetDependencies dependencies;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a ruleset visualisation for the provided ruleset and beatmap.
|
/// Creates a ruleset visualisation for the provided ruleset and beatmap.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -147,30 +144,15 @@ namespace osu.Game.Rulesets.UI
|
|||||||
|
|
||||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||||
{
|
{
|
||||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
dependencies = new DrawableRulesetDependencies(Ruleset, base.CreateChildDependencies(parent));
|
||||||
|
|
||||||
var resources = Ruleset.CreateResourceStore();
|
textureStore = dependencies.TextureStore;
|
||||||
|
localSampleStore = dependencies.SampleStore;
|
||||||
if (resources != null)
|
Config = dependencies.RulesetConfigManager;
|
||||||
{
|
|
||||||
textureStore = new TextureStore(new TextureLoaderStore(new NamespacedResourceStore<byte[]>(resources, "Textures")));
|
|
||||||
textureStore.AddStore(dependencies.Get<TextureStore>());
|
|
||||||
dependencies.Cache(textureStore);
|
|
||||||
|
|
||||||
localSampleStore = dependencies.Get<AudioManager>().GetSampleStore(new NamespacedResourceStore<byte[]>(resources, "Samples"));
|
|
||||||
localSampleStore.PlaybackConcurrency = OsuGameBase.SAMPLE_CONCURRENCY;
|
|
||||||
dependencies.CacheAs<ISampleStore>(new FallbackSampleStore(localSampleStore, dependencies.Get<ISampleStore>()));
|
|
||||||
}
|
|
||||||
|
|
||||||
onScreenDisplay = dependencies.Get<OnScreenDisplay>();
|
onScreenDisplay = dependencies.Get<OnScreenDisplay>();
|
||||||
|
|
||||||
Config = dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset);
|
|
||||||
|
|
||||||
if (Config != null)
|
if (Config != null)
|
||||||
{
|
|
||||||
dependencies.Cache(Config);
|
|
||||||
onScreenDisplay?.BeginTracking(this, Config);
|
onScreenDisplay?.BeginTracking(this, Config);
|
||||||
}
|
|
||||||
|
|
||||||
return dependencies;
|
return dependencies;
|
||||||
}
|
}
|
||||||
@ -362,13 +344,14 @@ namespace osu.Game.Rulesets.UI
|
|||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
localSampleStore?.Dispose();
|
|
||||||
|
|
||||||
if (Config != null)
|
if (Config != null)
|
||||||
{
|
{
|
||||||
onScreenDisplay?.StopTracking(this, Config);
|
onScreenDisplay?.StopTracking(this, Config);
|
||||||
Config = null;
|
Config = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dispose the components created by this dependency container.
|
||||||
|
dependencies.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,62 +502,4 @@ namespace osu.Game.Rulesets.UI
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A sample store which adds a fallback source.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// This is a temporary implementation to workaround ISampleStore limitations.
|
|
||||||
/// </remarks>
|
|
||||||
public class FallbackSampleStore : ISampleStore
|
|
||||||
{
|
|
||||||
private readonly ISampleStore primary;
|
|
||||||
private readonly ISampleStore secondary;
|
|
||||||
|
|
||||||
public FallbackSampleStore(ISampleStore primary, ISampleStore secondary)
|
|
||||||
{
|
|
||||||
this.primary = primary;
|
|
||||||
this.secondary = secondary;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SampleChannel Get(string name) => primary.Get(name) ?? secondary.Get(name);
|
|
||||||
|
|
||||||
public Task<SampleChannel> GetAsync(string name) => primary.GetAsync(name) ?? secondary.GetAsync(name);
|
|
||||||
|
|
||||||
public Stream GetStream(string name) => primary.GetStream(name) ?? secondary.GetStream(name);
|
|
||||||
|
|
||||||
public IEnumerable<string> GetAvailableResources() => throw new NotSupportedException();
|
|
||||||
|
|
||||||
public void AddAdjustment(AdjustableProperty type, BindableNumber<double> adjustBindable) => throw new NotSupportedException();
|
|
||||||
|
|
||||||
public void RemoveAdjustment(AdjustableProperty type, BindableNumber<double> adjustBindable) => throw new NotSupportedException();
|
|
||||||
|
|
||||||
public BindableNumber<double> Volume => throw new NotSupportedException();
|
|
||||||
|
|
||||||
public BindableNumber<double> Balance => throw new NotSupportedException();
|
|
||||||
|
|
||||||
public BindableNumber<double> Frequency => throw new NotSupportedException();
|
|
||||||
|
|
||||||
public BindableNumber<double> Tempo => throw new NotSupportedException();
|
|
||||||
|
|
||||||
public IBindable<double> GetAggregate(AdjustableProperty type) => throw new NotSupportedException();
|
|
||||||
|
|
||||||
public IBindable<double> AggregateVolume => throw new NotSupportedException();
|
|
||||||
|
|
||||||
public IBindable<double> AggregateBalance => throw new NotSupportedException();
|
|
||||||
|
|
||||||
public IBindable<double> AggregateFrequency => throw new NotSupportedException();
|
|
||||||
|
|
||||||
public IBindable<double> AggregateTempo => throw new NotSupportedException();
|
|
||||||
|
|
||||||
public int PlaybackConcurrency
|
|
||||||
{
|
|
||||||
get => throw new NotSupportedException();
|
|
||||||
set => throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
148
osu.Game/Rulesets/UI/DrawableRulesetDependencies.cs
Normal file
148
osu.Game/Rulesets/UI/DrawableRulesetDependencies.cs
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
// 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 System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
|
using osu.Framework.Audio.Sample;
|
||||||
|
using osu.Framework.Audio.Track;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Framework.IO.Stores;
|
||||||
|
using osu.Game.Rulesets.Configuration;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.UI
|
||||||
|
{
|
||||||
|
public class DrawableRulesetDependencies : DependencyContainer, IDisposable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The texture store to be used for the ruleset.
|
||||||
|
/// </summary>
|
||||||
|
public TextureStore TextureStore { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The sample store to be used for the ruleset.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This is the local sample store pointing to the ruleset sample resources,
|
||||||
|
/// the cached sample store (<see cref="FallbackSampleStore"/>) retrieves from
|
||||||
|
/// this store and falls back to the parent store if this store doesn't have the requested sample.
|
||||||
|
/// </remarks>
|
||||||
|
public ISampleStore SampleStore { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ruleset config manager.
|
||||||
|
/// </summary>
|
||||||
|
public IRulesetConfigManager RulesetConfigManager { get; private set; }
|
||||||
|
|
||||||
|
public DrawableRulesetDependencies(Ruleset ruleset, IReadOnlyDependencyContainer parent)
|
||||||
|
: base(parent)
|
||||||
|
{
|
||||||
|
var resources = ruleset.CreateResourceStore();
|
||||||
|
|
||||||
|
if (resources != null)
|
||||||
|
{
|
||||||
|
TextureStore = new TextureStore(new TextureLoaderStore(new NamespacedResourceStore<byte[]>(resources, @"Textures")));
|
||||||
|
TextureStore.AddStore(parent.Get<TextureStore>());
|
||||||
|
Cache(TextureStore);
|
||||||
|
|
||||||
|
SampleStore = parent.Get<AudioManager>().GetSampleStore(new NamespacedResourceStore<byte[]>(resources, @"Samples"));
|
||||||
|
SampleStore.PlaybackConcurrency = OsuGameBase.SAMPLE_CONCURRENCY;
|
||||||
|
CacheAs<ISampleStore>(new FallbackSampleStore(SampleStore, parent.Get<ISampleStore>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
RulesetConfigManager = parent.Get<RulesetConfigCache>().GetConfigFor(ruleset);
|
||||||
|
if (RulesetConfigManager != null)
|
||||||
|
Cache(RulesetConfigManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Disposal
|
||||||
|
|
||||||
|
~DrawableRulesetDependencies()
|
||||||
|
{
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool isDisposed;
|
||||||
|
|
||||||
|
protected void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (isDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
isDisposed = true;
|
||||||
|
|
||||||
|
SampleStore?.Dispose();
|
||||||
|
RulesetConfigManager = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A sample store which adds a fallback source.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This is a temporary implementation to workaround ISampleStore limitations.
|
||||||
|
/// </remarks>
|
||||||
|
public class FallbackSampleStore : ISampleStore
|
||||||
|
{
|
||||||
|
private readonly ISampleStore primary;
|
||||||
|
private readonly ISampleStore secondary;
|
||||||
|
|
||||||
|
public FallbackSampleStore(ISampleStore primary, ISampleStore secondary)
|
||||||
|
{
|
||||||
|
this.primary = primary;
|
||||||
|
this.secondary = secondary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SampleChannel Get(string name) => primary.Get(name) ?? secondary.Get(name);
|
||||||
|
|
||||||
|
public Task<SampleChannel> GetAsync(string name) => primary.GetAsync(name) ?? secondary.GetAsync(name);
|
||||||
|
|
||||||
|
public Stream GetStream(string name) => primary.GetStream(name) ?? secondary.GetStream(name);
|
||||||
|
|
||||||
|
public IEnumerable<string> GetAvailableResources() => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public void AddAdjustment(AdjustableProperty type, BindableNumber<double> adjustBindable) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public void RemoveAdjustment(AdjustableProperty type, BindableNumber<double> adjustBindable) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public BindableNumber<double> Volume => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public BindableNumber<double> Balance => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public BindableNumber<double> Frequency => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public BindableNumber<double> Tempo => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public IBindable<double> GetAggregate(AdjustableProperty type) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public IBindable<double> AggregateVolume => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public IBindable<double> AggregateBalance => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public IBindable<double> AggregateFrequency => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public IBindable<double> AggregateTempo => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public int PlaybackConcurrency
|
||||||
|
{
|
||||||
|
get => throw new NotSupportedException();
|
||||||
|
set => throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user