mirror of
https://github.com/osukey/osukey.git
synced 2025-06-14 15:58:06 +09:00
Pause imports during active gameplay
This commit is contained in:
parent
07eadba6d3
commit
62ffb4fe78
@ -62,6 +62,7 @@ namespace osu.Game.Beatmaps
|
|||||||
BeatmapTrackStore = audioManager.GetTrackStore(userResources);
|
BeatmapTrackStore = audioManager.GetTrackStore(userResources);
|
||||||
|
|
||||||
beatmapImporter = CreateBeatmapImporter(storage, realm);
|
beatmapImporter = CreateBeatmapImporter(storage, realm);
|
||||||
|
beatmapImporter.PauseImports.BindTo(PauseImports);
|
||||||
beatmapImporter.ProcessBeatmap = args => ProcessBeatmap?.Invoke(args);
|
beatmapImporter.ProcessBeatmap = args => ProcessBeatmap?.Invoke(args);
|
||||||
beatmapImporter.PostNotification = obj => PostNotification?.Invoke(obj);
|
beatmapImporter.PostNotification = obj => PostNotification?.Invoke(obj);
|
||||||
|
|
||||||
@ -458,7 +459,8 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
public Task Import(ImportTask[] tasks, ImportParameters parameters = default) => beatmapImporter.Import(tasks, parameters);
|
public Task Import(ImportTask[] tasks, ImportParameters parameters = default) => beatmapImporter.Import(tasks, parameters);
|
||||||
|
|
||||||
public Task<IEnumerable<Live<BeatmapSetInfo>>> Import(ProgressNotification notification, ImportTask[] tasks, ImportParameters parameters = default) => beatmapImporter.Import(notification, tasks, parameters);
|
public Task<IEnumerable<Live<BeatmapSetInfo>>> Import(ProgressNotification notification, ImportTask[] tasks, ImportParameters parameters = default) =>
|
||||||
|
beatmapImporter.Import(notification, tasks, parameters);
|
||||||
|
|
||||||
public Task<Live<BeatmapSetInfo>?> Import(ImportTask task, ImportParameters parameters = default, CancellationToken cancellationToken = default) =>
|
public Task<Live<BeatmapSetInfo>?> Import(ImportTask task, ImportParameters parameters = default, CancellationToken cancellationToken = default) =>
|
||||||
beatmapImporter.Import(task, parameters, cancellationToken);
|
beatmapImporter.Import(task, parameters, cancellationToken);
|
||||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
@ -18,6 +19,11 @@ namespace osu.Game.Database
|
|||||||
public class ModelManager<TModel> : IModelManager<TModel>, IModelFileManager<TModel, RealmNamedFileUsage>
|
public class ModelManager<TModel> : IModelManager<TModel>, IModelFileManager<TModel, RealmNamedFileUsage>
|
||||||
where TModel : RealmObject, IHasRealmFiles, IHasGuidPrimaryKey, ISoftDelete
|
where TModel : RealmObject, IHasRealmFiles, IHasGuidPrimaryKey, ISoftDelete
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Temporarily pause imports to avoid performance overheads affecting gameplay scenarios.
|
||||||
|
/// </summary>
|
||||||
|
public readonly BindableBool PauseImports = new BindableBool();
|
||||||
|
|
||||||
protected RealmAccess Realm { get; }
|
protected RealmAccess Realm { get; }
|
||||||
|
|
||||||
private readonly RealmFileStore realmFileStore;
|
private readonly RealmFileStore realmFileStore;
|
||||||
|
@ -8,6 +8,7 @@ using System.Linq;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
@ -56,6 +57,11 @@ namespace osu.Game.Database
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly ThreadedTaskScheduler import_scheduler_batch = new ThreadedTaskScheduler(import_queue_request_concurrency, nameof(RealmArchiveModelImporter<TModel>));
|
private static readonly ThreadedTaskScheduler import_scheduler_batch = new ThreadedTaskScheduler(import_queue_request_concurrency, nameof(RealmArchiveModelImporter<TModel>));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Temporarily pause imports to avoid performance overheads affecting gameplay scenarios.
|
||||||
|
/// </summary>
|
||||||
|
public readonly BindableBool PauseImports = new BindableBool();
|
||||||
|
|
||||||
public abstract IEnumerable<string> HandledExtensions { get; }
|
public abstract IEnumerable<string> HandledExtensions { get; }
|
||||||
|
|
||||||
protected readonly RealmFileStore Files;
|
protected readonly RealmFileStore Files;
|
||||||
@ -253,7 +259,7 @@ namespace osu.Game.Database
|
|||||||
/// <param name="cancellationToken">An optional cancellation token.</param>
|
/// <param name="cancellationToken">An optional cancellation token.</param>
|
||||||
public virtual Live<TModel>? ImportModel(TModel item, ArchiveReader? archive = null, ImportParameters parameters = default, CancellationToken cancellationToken = default) => Realm.Run(realm =>
|
public virtual Live<TModel>? ImportModel(TModel item, ArchiveReader? archive = null, ImportParameters parameters = default, CancellationToken cancellationToken = default) => Realm.Run(realm =>
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
pauseIfNecessary(cancellationToken);
|
||||||
|
|
||||||
TModel? existing;
|
TModel? existing;
|
||||||
|
|
||||||
@ -551,6 +557,22 @@ namespace osu.Game.Database
|
|||||||
/// <returns>Whether to perform deletion.</returns>
|
/// <returns>Whether to perform deletion.</returns>
|
||||||
protected virtual bool ShouldDeleteArchive(string path) => false;
|
protected virtual bool ShouldDeleteArchive(string path) => false;
|
||||||
|
|
||||||
|
private void pauseIfNecessary(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (!PauseImports.Value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Logger.Log(@"Import is being paused.");
|
||||||
|
|
||||||
|
while (PauseImports.Value)
|
||||||
|
{
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
Thread.Sleep(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.Log(@"Import is being resumed.");
|
||||||
|
}
|
||||||
|
|
||||||
private IEnumerable<string> getIDs(IEnumerable<INamedFile> files)
|
private IEnumerable<string> getIDs(IEnumerable<INamedFile> files)
|
||||||
{
|
{
|
||||||
foreach (var f in files.OrderBy(f => f.Filename))
|
foreach (var f in files.OrderBy(f => f.Filename))
|
||||||
|
@ -307,6 +307,10 @@ namespace osu.Game
|
|||||||
// Transfer any runtime changes back to configuration file.
|
// Transfer any runtime changes back to configuration file.
|
||||||
SkinManager.CurrentSkinInfo.ValueChanged += skin => configSkin.Value = skin.NewValue.ID.ToString();
|
SkinManager.CurrentSkinInfo.ValueChanged += skin => configSkin.Value = skin.NewValue.ID.ToString();
|
||||||
|
|
||||||
|
BeatmapManager.PauseImports.BindTo(LocalUserPlaying);
|
||||||
|
SkinManager.PauseImports.BindTo(LocalUserPlaying);
|
||||||
|
ScoreManager.PauseImports.BindTo(LocalUserPlaying);
|
||||||
|
|
||||||
IsActive.BindValueChanged(active => updateActiveState(active.NewValue), true);
|
IsActive.BindValueChanged(active => updateActiveState(active.NewValue), true);
|
||||||
|
|
||||||
Audio.AddAdjustment(AdjustableProperty.Volume, inactiveVolumeFade);
|
Audio.AddAdjustment(AdjustableProperty.Volume, inactiveVolumeFade);
|
||||||
|
@ -38,6 +38,8 @@ namespace osu.Game.Scoring
|
|||||||
{
|
{
|
||||||
PostNotification = obj => PostNotification?.Invoke(obj)
|
PostNotification = obj => PostNotification?.Invoke(obj)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
scoreImporter.PauseImports.BindTo(PauseImports);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Score GetScore(ScoreInfo score) => scoreImporter.GetScore(score);
|
public Score GetScore(ScoreInfo score) => scoreImporter.GetScore(score);
|
||||||
|
@ -79,6 +79,8 @@ namespace osu.Game.Skinning
|
|||||||
PostNotification = obj => PostNotification?.Invoke(obj),
|
PostNotification = obj => PostNotification?.Invoke(obj),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
skinImporter.PauseImports.BindTo(PauseImports);
|
||||||
|
|
||||||
var defaultSkins = new[]
|
var defaultSkins = new[]
|
||||||
{
|
{
|
||||||
DefaultClassicSkin = new DefaultLegacySkin(this),
|
DefaultClassicSkin = new DefaultLegacySkin(this),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user