2020-04-11 01:22:23 +00:00
|
|
|
// 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;
|
2020-09-24 05:29:44 +00:00
|
|
|
using osu.Framework.Graphics.OpenGL.Textures;
|
2020-04-11 01:22:23 +00:00
|
|
|
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>
|
2020-04-11 02:13:04 +00:00
|
|
|
public TextureStore TextureStore { get; }
|
2020-04-11 01:22:23 +00:00
|
|
|
|
|
|
|
/// <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>
|
2020-04-11 02:13:04 +00:00
|
|
|
public ISampleStore SampleStore { get; }
|
2020-04-11 01:22:23 +00:00
|
|
|
|
|
|
|
/// <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")));
|
2020-09-24 05:29:44 +00:00
|
|
|
CacheAs(TextureStore = new FallbackTextureStore(TextureStore, parent.Get<TextureStore>()));
|
2020-04-11 01:22:23 +00:00
|
|
|
|
|
|
|
SampleStore = parent.Get<AudioManager>().GetSampleStore(new NamespacedResourceStore<byte[]>(resources, @"Samples"));
|
|
|
|
SampleStore.PlaybackConcurrency = OsuGameBase.SAMPLE_CONCURRENCY;
|
2020-09-24 05:29:44 +00:00
|
|
|
CacheAs(SampleStore = new FallbackSampleStore(SampleStore, parent.Get<ISampleStore>()));
|
2020-04-11 01:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2020-09-24 05:29:44 +00:00
|
|
|
TextureStore?.Dispose();
|
2020-04-11 01:22:23 +00:00
|
|
|
RulesetConfigManager = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-09-24 05:29:44 +00:00
|
|
|
/// A sample store which adds a fallback source and prevents disposal of the fallback source.
|
2020-04-11 01:22:23 +00:00
|
|
|
/// </summary>
|
|
|
|
public class FallbackSampleStore : ISampleStore
|
|
|
|
{
|
|
|
|
private readonly ISampleStore primary;
|
2020-09-24 05:29:44 +00:00
|
|
|
private readonly ISampleStore fallback;
|
2020-04-11 01:22:23 +00:00
|
|
|
|
2020-09-24 05:29:44 +00:00
|
|
|
public FallbackSampleStore(ISampleStore primary, ISampleStore fallback)
|
2020-04-11 01:22:23 +00:00
|
|
|
{
|
|
|
|
this.primary = primary;
|
2020-09-24 05:29:44 +00:00
|
|
|
this.fallback = fallback;
|
2020-04-11 01:22:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 05:29:44 +00:00
|
|
|
public SampleChannel Get(string name) => primary.Get(name) ?? fallback.Get(name);
|
2020-04-11 01:22:23 +00:00
|
|
|
|
2020-09-24 05:29:44 +00:00
|
|
|
public Task<SampleChannel> GetAsync(string name) => primary.GetAsync(name) ?? fallback.GetAsync(name);
|
2020-04-11 01:22:23 +00:00
|
|
|
|
2020-09-24 05:29:44 +00:00
|
|
|
public Stream GetStream(string name) => primary.GetStream(name) ?? fallback.GetStream(name);
|
2020-04-11 01:22:23 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2020-08-06 12:53:20 +00:00
|
|
|
public void RemoveAllAdjustments(AdjustableProperty type) => throw new NotSupportedException();
|
|
|
|
|
2020-04-11 01:22:23 +00:00
|
|
|
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()
|
|
|
|
{
|
2020-09-24 05:29:44 +00:00
|
|
|
primary?.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A texture store which adds a fallback source and prevents disposal of the fallback source.
|
|
|
|
/// </summary>
|
|
|
|
public class FallbackTextureStore : TextureStore
|
|
|
|
{
|
|
|
|
private readonly TextureStore primary;
|
|
|
|
private readonly TextureStore fallback;
|
|
|
|
|
|
|
|
public FallbackTextureStore(TextureStore primary, TextureStore fallback)
|
|
|
|
{
|
|
|
|
this.primary = primary;
|
|
|
|
this.fallback = fallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Texture Get(string name, WrapMode wrapModeS, WrapMode wrapModeT)
|
|
|
|
=> primary.Get(name, wrapModeS, wrapModeT) ?? fallback.Get(name, wrapModeS, wrapModeT);
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
{
|
|
|
|
base.Dispose(disposing);
|
|
|
|
primary?.Dispose();
|
2020-04-11 01:22:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|