2019-01-24 16:43:03 +08: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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-13 14:12:10 +08:00
|
|
|
|
using System;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-06-13 14:12:10 +08:00
|
|
|
|
using osu.Framework.Lists;
|
2019-01-23 19:52:00 +08:00
|
|
|
|
using osu.Framework.Screens;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
2019-01-24 13:42:09 +08:00
|
|
|
|
public abstract class TestCasePlayer : TestCasePlayerBase
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly Ruleset ruleset;
|
|
|
|
|
|
|
|
|
|
protected Player Player;
|
|
|
|
|
|
|
|
|
|
protected TestCasePlayer(Ruleset ruleset)
|
|
|
|
|
{
|
|
|
|
|
this.ruleset = ruleset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected TestCasePlayer()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(RulesetStore rulesets)
|
|
|
|
|
{
|
|
|
|
|
Add(new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Framework.Graphics.Axes.Both,
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
Depth = int.MaxValue
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (ruleset != null)
|
|
|
|
|
{
|
|
|
|
|
Player p = null;
|
|
|
|
|
AddStep(ruleset.RulesetInfo.Name, () => p = loadPlayerFor(ruleset));
|
2019-01-23 13:43:23 +08:00
|
|
|
|
AddCheckSteps(() => p);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var r in rulesets.AvailableRulesets)
|
|
|
|
|
{
|
|
|
|
|
Player p = null;
|
|
|
|
|
AddStep(r.Name, () => p = loadPlayerFor(r));
|
2019-01-23 13:43:23 +08:00
|
|
|
|
AddCheckSteps(() => p);
|
2018-06-13 14:26:05 +08:00
|
|
|
|
|
2018-09-11 12:10:34 +08:00
|
|
|
|
AddUntilStep(() =>
|
2018-06-13 14:12:10 +08:00
|
|
|
|
{
|
|
|
|
|
p = null;
|
|
|
|
|
|
|
|
|
|
GC.Collect();
|
|
|
|
|
GC.WaitForPendingFinalizers();
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
workingWeakReferences.ForEachAlive(_ => count++);
|
2018-06-13 14:26:05 +08:00
|
|
|
|
return count == 1;
|
2018-09-11 12:10:34 +08:00
|
|
|
|
}, "no leaked beatmaps");
|
2018-06-13 14:12:10 +08:00
|
|
|
|
|
2018-09-11 12:10:34 +08:00
|
|
|
|
AddUntilStep(() =>
|
2018-06-13 14:26:05 +08:00
|
|
|
|
{
|
|
|
|
|
GC.Collect();
|
|
|
|
|
GC.WaitForPendingFinalizers();
|
|
|
|
|
int count = 0;
|
2018-06-13 14:12:10 +08:00
|
|
|
|
|
2018-06-13 14:26:05 +08:00
|
|
|
|
playerWeakReferences.ForEachAlive(_ => count++);
|
2018-06-13 14:12:10 +08:00
|
|
|
|
return count == 1;
|
2018-09-11 12:10:34 +08:00
|
|
|
|
}, "no leaked players");
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 13:43:23 +08:00
|
|
|
|
protected virtual void AddCheckSteps(Func<Player> player)
|
|
|
|
|
{
|
|
|
|
|
AddUntilStep(() => player().IsLoaded, "player loaded");
|
|
|
|
|
}
|
2018-05-26 13:46:05 +08:00
|
|
|
|
|
2018-04-19 19:44:38 +08:00
|
|
|
|
protected virtual IBeatmap CreateBeatmap(Ruleset ruleset) => new TestBeatmap(ruleset.RulesetInfo);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-13 14:12:10 +08:00
|
|
|
|
private readonly WeakList<WorkingBeatmap> workingWeakReferences = new WeakList<WorkingBeatmap>();
|
2018-06-13 14:26:05 +08:00
|
|
|
|
private readonly WeakList<Player> playerWeakReferences = new WeakList<Player>();
|
2018-06-13 14:12:10 +08:00
|
|
|
|
|
2018-06-26 17:59:13 +08:00
|
|
|
|
private Player loadPlayerFor(RulesetInfo ri)
|
|
|
|
|
{
|
|
|
|
|
Ruleset.Value = ri;
|
|
|
|
|
return loadPlayerFor(ri.CreateInstance());
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private Player loadPlayerFor(Ruleset r)
|
|
|
|
|
{
|
|
|
|
|
var beatmap = CreateBeatmap(r);
|
2019-02-19 11:16:44 +08:00
|
|
|
|
var working = new TestWorkingBeatmap(beatmap, Clock);
|
2018-06-13 14:12:10 +08:00
|
|
|
|
|
|
|
|
|
workingWeakReferences.Add(working);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-13 14:12:10 +08:00
|
|
|
|
Beatmap.Value = working;
|
2018-05-23 16:37:39 +08:00
|
|
|
|
Beatmap.Value.Mods.Value = new[] { r.GetAllMods().First(m => m is ModNoFail) };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-13 14:12:10 +08:00
|
|
|
|
Player?.Exit();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-06 19:21:47 +08:00
|
|
|
|
var player = CreatePlayer(r);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-13 14:26:05 +08:00
|
|
|
|
playerWeakReferences.Add(player);
|
|
|
|
|
|
2018-06-13 14:12:10 +08:00
|
|
|
|
LoadComponentAsync(player, p =>
|
|
|
|
|
{
|
|
|
|
|
Player = p;
|
|
|
|
|
LoadScreen(p);
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
return player;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-06 19:21:47 +08:00
|
|
|
|
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
AllowPause = false,
|
|
|
|
|
AllowLeadIn = false,
|
|
|
|
|
AllowResults = false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|