2019-09-17 21:33:27 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-07-19 13:07:55 +08:00
|
|
|
using System;
|
2019-04-08 17:32:05 +08:00
|
|
|
using System.Collections.Generic;
|
2019-05-31 13:40:53 +08:00
|
|
|
using System.IO;
|
2018-06-26 17:24:34 +08:00
|
|
|
using System.Linq;
|
2019-05-31 13:40:53 +08:00
|
|
|
using System.Threading.Tasks;
|
2020-04-23 18:24:18 +08:00
|
|
|
using JetBrains.Annotations;
|
2018-05-23 16:37:39 +08:00
|
|
|
using osu.Framework.Allocation;
|
2018-05-23 17:52:09 +08:00
|
|
|
using osu.Framework.Audio;
|
2019-05-31 13:40:53 +08:00
|
|
|
using osu.Framework.Audio.Track;
|
2019-02-21 18:04:31 +08:00
|
|
|
using osu.Framework.Bindables;
|
2019-11-11 12:49:12 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-05-31 17:37:32 +08:00
|
|
|
using osu.Framework.IO.Stores;
|
2018-07-19 13:07:55 +08:00
|
|
|
using osu.Framework.Platform;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Testing;
|
2019-05-31 13:40:53 +08:00
|
|
|
using osu.Framework.Timing;
|
2018-05-23 16:37:39 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2019-07-29 15:55:19 +08:00
|
|
|
using osu.Game.Database;
|
2019-08-01 03:42:23 +08:00
|
|
|
using osu.Game.Online.API;
|
2021-10-25 12:47:12 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-08-04 20:53:00 +08:00
|
|
|
using osu.Game.Overlays;
|
2018-06-26 17:24:34 +08:00
|
|
|
using osu.Game.Rulesets;
|
2019-04-08 17:32:05 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2020-10-05 12:17:13 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2020-04-11 09:23:31 +08:00
|
|
|
using osu.Game.Rulesets.UI;
|
2019-12-13 19:05:38 +08:00
|
|
|
using osu.Game.Screens;
|
2019-11-21 17:50:54 +08:00
|
|
|
using osu.Game.Storyboards;
|
2019-05-31 13:40:53 +08:00
|
|
|
using osu.Game.Tests.Beatmaps;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
2020-09-04 19:34:26 +08:00
|
|
|
[ExcludeFromDynamicCompile]
|
2019-05-15 03:37:25 +08:00
|
|
|
public abstract class OsuTestScene : TestScene
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-12-13 19:05:38 +08:00
|
|
|
protected Bindable<WorkingBeatmap> Beatmap { get; private set; }
|
2019-04-08 17:32:05 +08:00
|
|
|
|
2019-12-13 19:05:38 +08:00
|
|
|
protected Bindable<RulesetInfo> Ruleset;
|
2018-05-23 16:37:39 +08:00
|
|
|
|
2019-12-13 20:45:38 +08:00
|
|
|
protected Bindable<IReadOnlyList<Mod>> SelectedMods;
|
2018-06-26 17:24:34 +08:00
|
|
|
|
2019-12-13 19:05:38 +08:00
|
|
|
protected new OsuScreenDependencies Dependencies { get; private set; }
|
2018-05-23 16:37:39 +08:00
|
|
|
|
2020-04-11 09:23:31 +08:00
|
|
|
private DrawableRulesetDependencies rulesetDependencies;
|
|
|
|
|
2020-01-28 18:44:32 +08:00
|
|
|
private Lazy<Storage> localStorage;
|
2018-07-19 13:07:55 +08:00
|
|
|
protected Storage LocalStorage => localStorage.Value;
|
|
|
|
|
2020-09-15 13:03:36 +08:00
|
|
|
private Lazy<DatabaseContextFactory> contextFactory;
|
2019-09-13 16:15:33 +08:00
|
|
|
|
2021-05-31 17:37:32 +08:00
|
|
|
protected IResourceStore<byte[]> Resources;
|
|
|
|
|
2019-09-13 16:15:33 +08:00
|
|
|
protected IAPIProvider API
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (UseOnlineAPI)
|
2019-09-13 21:15:11 +08:00
|
|
|
throw new InvalidOperationException($"Using the {nameof(OsuTestScene)} dummy API is not supported when {nameof(UseOnlineAPI)} is true");
|
2019-09-13 16:15:33 +08:00
|
|
|
|
|
|
|
return dummyAPI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private DummyAPIAccess dummyAPI;
|
|
|
|
|
2019-07-29 15:55:19 +08:00
|
|
|
protected DatabaseContextFactory ContextFactory => contextFactory.Value;
|
|
|
|
|
2019-08-01 03:42:23 +08:00
|
|
|
/// <summary>
|
2019-09-13 16:15:33 +08:00
|
|
|
/// Whether this test scene requires real-world API access.
|
2019-09-13 20:55:45 +08:00
|
|
|
/// If true, this will bypass the local <see cref="DummyAPIAccess"/> and use the <see cref="OsuGameBase"/> provided one.
|
2019-08-01 03:42:23 +08:00
|
|
|
/// </summary>
|
2019-09-13 16:15:33 +08:00
|
|
|
protected virtual bool UseOnlineAPI => false;
|
2019-08-01 03:42:23 +08:00
|
|
|
|
2020-09-16 18:36:36 +08:00
|
|
|
/// <summary>
|
|
|
|
/// When running headless, there is an opportunity to use the host storage rather than creating a second isolated one.
|
|
|
|
/// This is because the host is recycled per TestScene execution in headless at an nunit level.
|
|
|
|
/// </summary>
|
|
|
|
private Storage isolatedHostStorage;
|
|
|
|
|
2018-07-11 16:07:14 +08:00
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
2018-05-23 16:37:39 +08:00
|
|
|
{
|
2020-09-16 18:36:36 +08:00
|
|
|
if (!UseFreshStoragePerRun)
|
|
|
|
isolatedHostStorage = (parent.Get<GameHost>() as HeadlessGameHost)?.Storage;
|
|
|
|
|
2021-05-31 17:37:32 +08:00
|
|
|
Resources = parent.Get<OsuGameBase>().Resources;
|
|
|
|
|
2020-09-15 13:03:36 +08:00
|
|
|
contextFactory = new Lazy<DatabaseContextFactory>(() =>
|
|
|
|
{
|
|
|
|
var factory = new DatabaseContextFactory(LocalStorage);
|
2020-09-16 18:36:36 +08:00
|
|
|
|
|
|
|
// only reset the database if not using the host storage.
|
|
|
|
// if we reset the host storage, it will delete global key bindings.
|
|
|
|
if (isolatedHostStorage == null)
|
|
|
|
factory.ResetDatabase();
|
|
|
|
|
2020-09-15 13:03:36 +08:00
|
|
|
using (var usage = factory.Get())
|
|
|
|
usage.Migrate();
|
|
|
|
return factory;
|
|
|
|
});
|
|
|
|
|
2021-08-18 15:23:02 +08:00
|
|
|
RecycleLocalStorage(false);
|
2020-09-15 13:03:36 +08:00
|
|
|
|
2020-04-11 09:23:31 +08:00
|
|
|
var baseDependencies = base.CreateChildDependencies(parent);
|
|
|
|
|
2020-04-17 08:38:12 +08:00
|
|
|
var providedRuleset = CreateRuleset();
|
|
|
|
if (providedRuleset != null)
|
|
|
|
baseDependencies = rulesetDependencies = new DrawableRulesetDependencies(providedRuleset, baseDependencies);
|
2020-04-11 09:23:31 +08:00
|
|
|
|
|
|
|
Dependencies = new OsuScreenDependencies(false, baseDependencies);
|
2019-05-31 13:51:12 +08:00
|
|
|
|
2019-12-13 19:05:38 +08:00
|
|
|
Beatmap = Dependencies.Beatmap;
|
|
|
|
Beatmap.SetDefault();
|
|
|
|
|
|
|
|
Ruleset = Dependencies.Ruleset;
|
|
|
|
Ruleset.SetDefault();
|
2018-12-05 19:19:21 +08:00
|
|
|
|
2019-12-13 20:45:38 +08:00
|
|
|
SelectedMods = Dependencies.Mods;
|
|
|
|
SelectedMods.SetDefault();
|
2019-08-01 03:42:23 +08:00
|
|
|
|
2019-09-13 16:15:33 +08:00
|
|
|
if (!UseOnlineAPI)
|
2019-08-01 03:42:23 +08:00
|
|
|
{
|
2019-09-13 16:15:33 +08:00
|
|
|
dummyAPI = new DummyAPIAccess();
|
2019-08-01 03:42:23 +08:00
|
|
|
Dependencies.CacheAs<IAPIProvider>(dummyAPI);
|
2021-06-05 09:30:21 +08:00
|
|
|
base.Content.Add(dummyAPI);
|
2019-08-01 03:42:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Dependencies;
|
2018-05-23 17:52:09 +08:00
|
|
|
}
|
|
|
|
|
2019-11-11 12:49:12 +08:00
|
|
|
protected override Container<Drawable> Content => content ?? base.Content;
|
|
|
|
|
|
|
|
private readonly Container content;
|
|
|
|
|
2019-05-15 03:37:25 +08:00
|
|
|
protected OsuTestScene()
|
2018-07-19 13:07:55 +08:00
|
|
|
{
|
2019-11-11 12:49:12 +08:00
|
|
|
base.Content.Add(content = new DrawSizePreservingFillContainer());
|
2018-07-19 13:07:55 +08:00
|
|
|
}
|
|
|
|
|
2020-09-15 18:01:32 +08:00
|
|
|
protected virtual bool UseFreshStoragePerRun => false;
|
|
|
|
|
2021-08-18 15:23:02 +08:00
|
|
|
public virtual void RecycleLocalStorage(bool isDisposing)
|
2020-01-28 18:44:32 +08:00
|
|
|
{
|
|
|
|
if (localStorage?.IsValueCreated == true)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
localStorage.Value.DeleteDirectory(".");
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
// we don't really care if this fails; it will just leave folders lying around from test runs.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-15 13:25:31 +08:00
|
|
|
localStorage =
|
2021-08-18 14:32:59 +08:00
|
|
|
new Lazy<Storage>(() => isolatedHostStorage ?? new TemporaryNativeStorage($"{GetType().Name}-{Guid.NewGuid()}"));
|
2020-01-28 18:44:32 +08:00
|
|
|
}
|
|
|
|
|
2019-05-31 13:40:53 +08:00
|
|
|
[Resolved]
|
2020-01-02 14:23:41 +08:00
|
|
|
protected AudioManager Audio { get; private set; }
|
2019-05-31 13:40:53 +08:00
|
|
|
|
2020-08-04 20:53:00 +08:00
|
|
|
[Resolved]
|
|
|
|
protected MusicController MusicController { get; private set; }
|
|
|
|
|
2020-04-17 11:17:15 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Creates the ruleset to be used for this test scene.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
2020-06-04 05:44:28 +08:00
|
|
|
/// When testing against ruleset-specific components, this method must be overriden to their corresponding ruleset.
|
2020-04-17 11:17:15 +08:00
|
|
|
/// </remarks>
|
2020-04-23 18:24:18 +08:00
|
|
|
[CanBeNull]
|
2020-04-17 11:17:15 +08:00
|
|
|
protected virtual Ruleset CreateRuleset() => null;
|
|
|
|
|
2019-05-31 13:40:53 +08:00
|
|
|
protected virtual IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestBeatmap(ruleset);
|
|
|
|
|
2021-11-01 15:42:22 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a sample API Beatmap with BeatmapSet populated.
|
|
|
|
/// </summary>
|
2021-11-01 15:43:39 +08:00
|
|
|
/// <param name="ruleset">The ruleset to create the sample model using. osu! ruleset will be used if not specified.</param>
|
|
|
|
protected APIBeatmap CreateAPIBeatmap(RulesetInfo ruleset = null)
|
2021-11-01 15:42:22 +08:00
|
|
|
{
|
2021-11-01 15:43:39 +08:00
|
|
|
var beatmapSet = CreateAPIBeatmapSet(ruleset ?? Ruleset.Value);
|
2021-11-01 15:42:22 +08:00
|
|
|
|
|
|
|
// Avoid circular reference.
|
|
|
|
var beatmap = beatmapSet.Beatmaps.First();
|
|
|
|
beatmapSet.Beatmaps = Array.Empty<APIBeatmap>();
|
|
|
|
|
|
|
|
// Populate the set as that's generally what we expect from the API.
|
|
|
|
beatmap.BeatmapSet = beatmapSet;
|
|
|
|
|
|
|
|
return beatmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a sample API BeatmapSet with beatmaps populated.
|
|
|
|
/// </summary>
|
2021-11-01 15:43:39 +08:00
|
|
|
/// <param name="ruleset">The ruleset to create the sample model using. osu! ruleset will be used if not specified.</param>
|
|
|
|
protected APIBeatmapSet CreateAPIBeatmapSet(RulesetInfo ruleset = null)
|
2021-10-25 12:47:12 +08:00
|
|
|
{
|
2021-11-01 15:43:39 +08:00
|
|
|
var beatmap = CreateBeatmap(ruleset ?? Ruleset.Value).BeatmapInfo;
|
2021-10-25 12:47:12 +08:00
|
|
|
|
|
|
|
return new APIBeatmapSet
|
|
|
|
{
|
2021-11-12 16:50:31 +08:00
|
|
|
OnlineID = ((IBeatmapSetInfo)beatmap.BeatmapSet).OnlineID,
|
2021-11-01 14:42:12 +08:00
|
|
|
Status = BeatmapSetOnlineStatus.Ranked,
|
|
|
|
Covers = new BeatmapSetOnlineCovers
|
|
|
|
{
|
|
|
|
Cover = "https://assets.ppy.sh/beatmaps/163112/covers/cover.jpg",
|
|
|
|
Card = "https://assets.ppy.sh/beatmaps/163112/covers/card.jpg",
|
|
|
|
List = "https://assets.ppy.sh/beatmaps/163112/covers/list.jpg"
|
|
|
|
},
|
2021-10-25 12:47:12 +08:00
|
|
|
Title = beatmap.BeatmapSet.Metadata.Title,
|
|
|
|
TitleUnicode = beatmap.BeatmapSet.Metadata.TitleUnicode,
|
|
|
|
Artist = beatmap.BeatmapSet.Metadata.Artist,
|
|
|
|
ArtistUnicode = beatmap.BeatmapSet.Metadata.ArtistUnicode,
|
|
|
|
Author = beatmap.BeatmapSet.Metadata.Author,
|
|
|
|
Source = beatmap.BeatmapSet.Metadata.Source,
|
|
|
|
Tags = beatmap.BeatmapSet.Metadata.Tags,
|
|
|
|
Beatmaps = new[]
|
|
|
|
{
|
|
|
|
new APIBeatmap
|
|
|
|
{
|
2021-11-12 16:45:05 +08:00
|
|
|
OnlineID = ((IBeatmapInfo)beatmap).OnlineID,
|
2021-11-12 16:50:31 +08:00
|
|
|
OnlineBeatmapSetID = ((IBeatmapSetInfo)beatmap.BeatmapSet).OnlineID,
|
2021-10-25 12:47:12 +08:00
|
|
|
Status = beatmap.Status,
|
|
|
|
Checksum = beatmap.MD5Hash,
|
2021-11-04 17:46:26 +08:00
|
|
|
AuthorID = beatmap.Metadata.Author.OnlineID,
|
2021-10-25 12:47:12 +08:00
|
|
|
RulesetID = beatmap.RulesetID,
|
2021-11-11 16:18:51 +08:00
|
|
|
StarRating = beatmap.StarRating,
|
2021-11-11 16:19:53 +08:00
|
|
|
DifficultyName = beatmap.DifficultyName,
|
2021-10-25 12:47:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-31 13:51:12 +08:00
|
|
|
protected WorkingBeatmap CreateWorkingBeatmap(RulesetInfo ruleset) =>
|
2021-07-05 23:52:39 +08:00
|
|
|
CreateWorkingBeatmap(CreateBeatmap(ruleset));
|
2019-05-31 13:40:53 +08:00
|
|
|
|
2019-11-21 17:50:54 +08:00
|
|
|
protected virtual WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null) =>
|
2020-01-02 14:23:41 +08:00
|
|
|
new ClockBackedTestWorkingBeatmap(beatmap, storyboard, Clock, Audio);
|
2019-05-31 13:40:53 +08:00
|
|
|
|
2018-05-28 16:55:41 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2019-05-31 13:40:53 +08:00
|
|
|
private void load(RulesetStore rulesets)
|
2018-05-28 16:55:41 +08:00
|
|
|
{
|
2020-06-10 23:23:31 +08:00
|
|
|
Ruleset.Value = CreateRuleset()?.RulesetInfo ?? rulesets.AvailableRulesets.First();
|
2018-05-28 16:55:41 +08:00
|
|
|
}
|
|
|
|
|
2018-05-24 11:53:32 +08:00
|
|
|
protected override void Dispose(bool isDisposing)
|
2018-05-23 17:52:09 +08:00
|
|
|
{
|
2018-05-24 11:53:32 +08:00
|
|
|
base.Dispose(isDisposing);
|
2018-05-23 17:52:09 +08:00
|
|
|
|
2020-04-11 09:23:31 +08:00
|
|
|
rulesetDependencies?.Dispose();
|
|
|
|
|
2020-08-04 20:53:00 +08:00
|
|
|
if (MusicController?.TrackLoaded == true)
|
2020-11-02 13:56:50 +08:00
|
|
|
MusicController.Stop();
|
2018-07-19 13:07:55 +08:00
|
|
|
|
2020-09-15 13:03:36 +08:00
|
|
|
if (contextFactory?.IsValueCreated == true)
|
2019-07-29 15:55:19 +08:00
|
|
|
contextFactory.Value.ResetDatabase();
|
|
|
|
|
2021-08-18 15:23:02 +08:00
|
|
|
RecycleLocalStorage(true);
|
2018-05-23 16:37:39 +08:00
|
|
|
}
|
|
|
|
|
2019-05-15 03:37:25 +08:00
|
|
|
protected override ITestSceneTestRunner CreateRunner() => new OsuTestSceneTestRunner();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-05-31 13:40:53 +08:00
|
|
|
public class ClockBackedTestWorkingBeatmap : TestWorkingBeatmap
|
|
|
|
{
|
|
|
|
private readonly Track track;
|
|
|
|
|
|
|
|
private readonly TrackVirtualStore store;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Create an instance which creates a <see cref="TestBeatmap"/> for the provided ruleset when requested.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="ruleset">The target ruleset.</param>
|
|
|
|
/// <param name="referenceClock">A clock which should be used instead of a stopwatch for virtual time progression.</param>
|
|
|
|
/// <param name="audio">Audio manager. Required if a reference clock isn't provided.</param>
|
|
|
|
public ClockBackedTestWorkingBeatmap(RulesetInfo ruleset, IFrameBasedClock referenceClock, AudioManager audio)
|
2019-11-21 17:50:54 +08:00
|
|
|
: this(new TestBeatmap(ruleset), null, referenceClock, audio)
|
2019-05-31 13:40:53 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Create an instance which provides the <see cref="IBeatmap"/> when requested.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="beatmap">The beatmap</param>
|
2019-11-21 17:50:54 +08:00
|
|
|
/// <param name="storyboard">The storyboard.</param>
|
2019-05-31 13:40:53 +08:00
|
|
|
/// <param name="referenceClock">An optional clock which should be used instead of a stopwatch for virtual time progression.</param>
|
|
|
|
/// <param name="audio">Audio manager. Required if a reference clock isn't provided.</param>
|
2020-10-05 12:17:13 +08:00
|
|
|
public ClockBackedTestWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard, IFrameBasedClock referenceClock, AudioManager audio)
|
2020-04-14 20:05:42 +08:00
|
|
|
: base(beatmap, storyboard, audio)
|
2019-05-31 13:40:53 +08:00
|
|
|
{
|
2020-10-05 13:04:04 +08:00
|
|
|
double trackLength = 60000;
|
2020-10-05 12:29:36 +08:00
|
|
|
|
2020-10-05 13:04:04 +08:00
|
|
|
if (beatmap.HitObjects.Count > 0)
|
|
|
|
// add buffer after last hitobject to allow for final replay frames etc.
|
2020-10-29 16:52:58 +08:00
|
|
|
trackLength = Math.Max(trackLength, beatmap.HitObjects.Max(h => h.GetEndTime()) + 2000);
|
2020-10-05 12:17:13 +08:00
|
|
|
|
2019-05-31 13:40:53 +08:00
|
|
|
if (referenceClock != null)
|
|
|
|
{
|
|
|
|
store = new TrackVirtualStore(referenceClock);
|
|
|
|
audio.AddItem(store);
|
2020-10-05 12:29:36 +08:00
|
|
|
track = store.GetVirtual(trackLength);
|
2019-05-31 13:40:53 +08:00
|
|
|
}
|
|
|
|
else
|
2020-10-05 12:29:36 +08:00
|
|
|
track = audio?.Tracks.GetVirtual(trackLength);
|
2019-05-31 13:40:53 +08:00
|
|
|
}
|
|
|
|
|
2020-02-10 16:01:41 +08:00
|
|
|
~ClockBackedTestWorkingBeatmap()
|
2019-05-31 13:40:53 +08:00
|
|
|
{
|
2020-02-10 16:01:41 +08:00
|
|
|
// Remove the track store from the audio manager
|
2019-05-31 13:40:53 +08:00
|
|
|
store?.Dispose();
|
|
|
|
}
|
|
|
|
|
2020-08-07 21:31:41 +08:00
|
|
|
protected override Track GetBeatmapTrack() => track;
|
2019-05-31 13:40:53 +08:00
|
|
|
|
|
|
|
public class TrackVirtualStore : AudioCollectionManager<Track>, ITrackStore
|
|
|
|
{
|
|
|
|
private readonly IFrameBasedClock referenceClock;
|
|
|
|
|
|
|
|
public TrackVirtualStore(IFrameBasedClock referenceClock)
|
|
|
|
{
|
|
|
|
this.referenceClock = referenceClock;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Track Get(string name) => throw new NotImplementedException();
|
|
|
|
|
|
|
|
public Task<Track> GetAsync(string name) => throw new NotImplementedException();
|
|
|
|
|
|
|
|
public Stream GetStream(string name) => throw new NotImplementedException();
|
|
|
|
|
|
|
|
public IEnumerable<string> GetAvailableResources() => throw new NotImplementedException();
|
|
|
|
|
2019-11-12 18:33:24 +08:00
|
|
|
public Track GetVirtual(double length = double.PositiveInfinity)
|
2019-05-31 13:40:53 +08:00
|
|
|
{
|
|
|
|
var track = new TrackVirtualManual(referenceClock) { Length = length };
|
|
|
|
AddItem(track);
|
|
|
|
return track;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A virtual track which tracks a reference clock.
|
|
|
|
/// </summary>
|
|
|
|
public class TrackVirtualManual : Track
|
|
|
|
{
|
2020-03-03 11:59:41 +08:00
|
|
|
private readonly IFrameBasedClock referenceClock;
|
2019-05-31 13:40:53 +08:00
|
|
|
|
2020-03-06 00:28:59 +08:00
|
|
|
private bool running;
|
|
|
|
|
2019-05-31 13:40:53 +08:00
|
|
|
public TrackVirtualManual(IFrameBasedClock referenceClock)
|
|
|
|
{
|
|
|
|
this.referenceClock = referenceClock;
|
|
|
|
Length = double.PositiveInfinity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool Seek(double seek)
|
|
|
|
{
|
2020-03-06 21:44:11 +08:00
|
|
|
accumulated = Math.Clamp(seek, 0, Length);
|
2020-03-06 00:28:59 +08:00
|
|
|
lastReferenceTime = null;
|
2020-03-03 11:59:41 +08:00
|
|
|
|
2020-03-06 00:28:59 +08:00
|
|
|
return accumulated == seek;
|
2019-05-31 13:40:53 +08:00
|
|
|
}
|
|
|
|
|
2020-03-06 00:28:59 +08:00
|
|
|
public override void Start()
|
|
|
|
{
|
|
|
|
running = true;
|
|
|
|
}
|
2019-05-31 13:40:53 +08:00
|
|
|
|
|
|
|
public override void Reset()
|
|
|
|
{
|
2020-03-06 00:28:59 +08:00
|
|
|
Seek(0);
|
2019-05-31 13:40:53 +08:00
|
|
|
base.Reset();
|
|
|
|
}
|
|
|
|
|
2020-03-06 00:28:59 +08:00
|
|
|
public override void Stop()
|
|
|
|
{
|
|
|
|
if (running)
|
|
|
|
{
|
|
|
|
running = false;
|
|
|
|
lastReferenceTime = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool IsRunning => running;
|
2019-05-31 13:40:53 +08:00
|
|
|
|
2020-03-06 00:28:59 +08:00
|
|
|
private double? lastReferenceTime;
|
2019-05-31 13:40:53 +08:00
|
|
|
|
2020-03-06 00:28:59 +08:00
|
|
|
private double accumulated;
|
|
|
|
|
|
|
|
public override double CurrentTime => Math.Min(accumulated, Length);
|
2019-05-31 13:40:53 +08:00
|
|
|
|
|
|
|
protected override void UpdateState()
|
|
|
|
{
|
|
|
|
base.UpdateState();
|
|
|
|
|
2020-03-06 00:28:59 +08:00
|
|
|
if (running)
|
|
|
|
{
|
|
|
|
double refTime = referenceClock.CurrentTime;
|
|
|
|
|
2020-07-28 11:08:15 +08:00
|
|
|
double? lastRefTime = lastReferenceTime;
|
|
|
|
|
|
|
|
if (lastRefTime != null)
|
|
|
|
accumulated += (refTime - lastRefTime.Value) * Rate;
|
2020-03-06 00:28:59 +08:00
|
|
|
|
|
|
|
lastReferenceTime = refTime;
|
|
|
|
}
|
|
|
|
|
2019-05-31 13:40:53 +08:00
|
|
|
if (CurrentTime >= Length)
|
|
|
|
{
|
|
|
|
Stop();
|
2021-06-16 16:44:21 +08:00
|
|
|
// `RaiseCompleted` is not called here to prevent transitioning to the next song.
|
2019-05-31 13:40:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 03:37:25 +08:00
|
|
|
public class OsuTestSceneTestRunner : OsuGameBase, ITestSceneTestRunner
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-05-14 17:39:56 +08:00
|
|
|
private TestSceneTestRunner.TestRunner runner;
|
2018-04-18 14:12:48 +08:00
|
|
|
|
2018-04-22 03:10:06 +08:00
|
|
|
protected override void LoadAsyncComplete()
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2018-04-22 03:10:06 +08:00
|
|
|
// this has to be run here rather than LoadComplete because
|
2019-05-15 17:32:29 +08:00
|
|
|
// TestScene.cs is checking the IsLoaded state (on another thread) and expects
|
2018-04-22 03:10:06 +08:00
|
|
|
// the runner to be loaded at that point.
|
2019-05-14 17:39:56 +08:00
|
|
|
Add(runner = new TestSceneTestRunner.TestRunner());
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
2018-04-18 14:12:48 +08:00
|
|
|
|
2021-09-06 23:45:53 +08:00
|
|
|
protected override void InitialiseFonts()
|
|
|
|
{
|
|
|
|
// skip fonts load as it's not required for testing purposes.
|
|
|
|
}
|
|
|
|
|
2019-05-14 17:39:56 +08:00
|
|
|
public void RunTestBlocking(TestScene test) => runner.RunTestBlocking(test);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|