1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-16 18:32:56 +08:00

Merge branch 'master' into catch-coordinate

This commit is contained in:
Dan Balasescu 2020-07-02 22:32:21 +09:00 committed by GitHub
commit 9801563ad3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 135 additions and 97 deletions

View File

@ -2,7 +2,6 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/.idea/.idea.osu.Desktop/.idea/.idea.osu.Desktop.iml" filepath="$PROJECT_DIR$/.idea/.idea.osu.Desktop/.idea/.idea.osu.Desktop.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/.idea.osu.Desktop/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.osu.Desktop/riderModule.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/.idea.osu.Desktop/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.osu.Desktop/riderModule.iml" />
</modules> </modules>
</component> </component>

View File

@ -52,6 +52,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.622.1" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2020.622.1" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2020.623.0" /> <PackageReference Include="ppy.osu.Framework.Android" Version="2020.701.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -127,6 +127,9 @@ namespace osu.Game.Tests.NonVisual
var osu = loadOsu(host); var osu = loadOsu(host);
var storage = osu.Dependencies.Get<Storage>(); var storage = osu.Dependencies.Get<Storage>();
// Store the current storage's path. We'll need to refer to this for assertions in the original directory after the migration completes.
string originalDirectory = storage.GetFullPath(".");
// ensure we perform a save // ensure we perform a save
host.Dependencies.Get<FrameworkConfigManager>().Save(); host.Dependencies.Get<FrameworkConfigManager>().Save();
@ -145,25 +148,25 @@ namespace osu.Game.Tests.NonVisual
Assert.That(storage.GetFullPath("."), Is.EqualTo(customPath)); Assert.That(storage.GetFullPath("."), Is.EqualTo(customPath));
// ensure cache was not moved // ensure cache was not moved
Assert.That(host.Storage.ExistsDirectory("cache")); Assert.That(Directory.Exists(Path.Combine(originalDirectory, "cache")));
// ensure nested cache was moved // ensure nested cache was moved
Assert.That(!host.Storage.ExistsDirectory(Path.Combine("test-nested", "cache"))); Assert.That(!Directory.Exists(Path.Combine(originalDirectory, "test-nested", "cache")));
Assert.That(storage.ExistsDirectory(Path.Combine("test-nested", "cache"))); Assert.That(storage.ExistsDirectory(Path.Combine("test-nested", "cache")));
foreach (var file in OsuStorage.IGNORE_FILES) foreach (var file in OsuStorage.IGNORE_FILES)
{ {
Assert.That(host.Storage.Exists(file), Is.True); Assert.That(File.Exists(Path.Combine(originalDirectory, file)));
Assert.That(storage.Exists(file), Is.False); Assert.That(storage.Exists(file), Is.False);
} }
foreach (var dir in OsuStorage.IGNORE_DIRECTORIES) foreach (var dir in OsuStorage.IGNORE_DIRECTORIES)
{ {
Assert.That(host.Storage.ExistsDirectory(dir), Is.True); Assert.That(Directory.Exists(Path.Combine(originalDirectory, dir)));
Assert.That(storage.ExistsDirectory(dir), Is.False); Assert.That(storage.ExistsDirectory(dir), Is.False);
} }
Assert.That(new StreamReader(host.Storage.GetStream("storage.ini")).ReadToEnd().Contains($"FullPath = {customPath}")); Assert.That(new StreamReader(Path.Combine(originalDirectory, "storage.ini")).ReadToEnd().Contains($"FullPath = {customPath}"));
} }
finally finally
{ {

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Audio.Track;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
@ -14,15 +15,11 @@ namespace osu.Game.Tests.Visual.Menus
public TestSceneIntroWelcome() public TestSceneIntroWelcome()
{ {
AddAssert("check if menu music loops", () => AddUntilStep("wait for load", () => getTrack() != null);
{
var menu = IntroStack?.CurrentScreen as MainMenu;
if (menu == null) AddAssert("check if menu music loops", () => getTrack().Looping);
return false;
return menu.Track.Looping;
});
} }
private Track getTrack() => (IntroStack?.CurrentScreen as MainMenu)?.Track;
} }
} }

View File

@ -24,12 +24,12 @@ namespace osu.Game.IO
"storage.ini" "storage.ini"
}; };
public OsuStorage(GameHost host) public OsuStorage(GameHost host, Storage defaultStorage)
: base(host.Storage, string.Empty) : base(defaultStorage, string.Empty)
{ {
this.host = host; this.host = host;
storageConfig = new StorageConfigManager(host.Storage); storageConfig = new StorageConfigManager(defaultStorage);
var customStoragePath = storageConfig.Get<string>(StorageConfig.FullPath); var customStoragePath = storageConfig.Get<string>(StorageConfig.FullPath);

View File

@ -312,11 +312,13 @@ namespace osu.Game
base.SetHost(host); base.SetHost(host);
// may be non-null for certain tests // may be non-null for certain tests
Storage ??= new OsuStorage(host); Storage ??= host.Storage;
LocalConfig ??= new OsuConfigManager(Storage); LocalConfig ??= new OsuConfigManager(Storage);
} }
protected override Storage CreateStorage(GameHost host, Storage defaultStorage) => new OsuStorage(host, defaultStorage);
private readonly List<ICanAcceptFiles> fileImporters = new List<ICanAcceptFiles>(); private readonly List<ICanAcceptFiles> fileImporters = new List<ICanAcceptFiles>();
public async Task Import(params string[] paths) public async Task Import(params string[] paths)

View File

@ -18,9 +18,6 @@ using osu.Game.Input.Handlers;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osuTK.Input; using osuTK.Input;
using static osu.Game.Input.Handlers.ReplayInputHandler; using static osu.Game.Input.Handlers.ReplayInputHandler;
using JoystickState = osu.Framework.Input.States.JoystickState;
using KeyboardState = osu.Framework.Input.States.KeyboardState;
using MouseState = osu.Framework.Input.States.MouseState;
namespace osu.Game.Rulesets.UI namespace osu.Game.Rulesets.UI
{ {
@ -42,11 +39,7 @@ namespace osu.Game.Rulesets.UI
} }
} }
protected override InputState CreateInitialState() protected override InputState CreateInitialState() => new RulesetInputManagerInputState<T>(base.CreateInitialState());
{
var state = base.CreateInitialState();
return new RulesetInputManagerInputState<T>(state.Mouse, state.Keyboard, state.Joystick);
}
protected readonly KeyBindingContainer<T> KeyBindingContainer; protected readonly KeyBindingContainer<T> KeyBindingContainer;
@ -203,8 +196,8 @@ namespace osu.Game.Rulesets.UI
{ {
public ReplayState<T> LastReplayState; public ReplayState<T> LastReplayState;
public RulesetInputManagerInputState(MouseState mouse = null, KeyboardState keyboard = null, JoystickState joystick = null) public RulesetInputManagerInputState(InputState state = null)
: base(mouse, keyboard, joystick) : base(state)
{ {
} }
} }

View File

@ -3,21 +3,26 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using JetBrains.Annotations;
using osu.Game.Rulesets.Timing; using osu.Game.Rulesets.Timing;
namespace osu.Game.Rulesets.UI.Scrolling.Algorithms namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
{ {
public class SequentialScrollAlgorithm : IScrollAlgorithm public class SequentialScrollAlgorithm : IScrollAlgorithm
{ {
private readonly Dictionary<double, double> positionCache; private static readonly IComparer<PositionMapping> by_position_comparer = Comparer<PositionMapping>.Create((c1, c2) => c1.Position.CompareTo(c2.Position));
private readonly IReadOnlyList<MultiplierControlPoint> controlPoints; private readonly IReadOnlyList<MultiplierControlPoint> controlPoints;
/// <summary>
/// Stores a mapping of time -> position for each control point.
/// </summary>
private readonly List<PositionMapping> positionMappings = new List<PositionMapping>();
public SequentialScrollAlgorithm(IReadOnlyList<MultiplierControlPoint> controlPoints) public SequentialScrollAlgorithm(IReadOnlyList<MultiplierControlPoint> controlPoints)
{ {
this.controlPoints = controlPoints; this.controlPoints = controlPoints;
positionCache = new Dictionary<double, double>();
} }
public double GetDisplayStartTime(double originTime, float offset, double timeRange, float scrollLength) public double GetDisplayStartTime(double originTime, float offset, double timeRange, float scrollLength)
@ -27,55 +32,31 @@ namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
public float GetLength(double startTime, double endTime, double timeRange, float scrollLength) public float GetLength(double startTime, double endTime, double timeRange, float scrollLength)
{ {
var objectLength = relativePositionAtCached(endTime, timeRange) - relativePositionAtCached(startTime, timeRange); var objectLength = relativePositionAt(endTime, timeRange) - relativePositionAt(startTime, timeRange);
return (float)(objectLength * scrollLength); return (float)(objectLength * scrollLength);
} }
public float PositionAt(double time, double currentTime, double timeRange, float scrollLength) public float PositionAt(double time, double currentTime, double timeRange, float scrollLength)
{ {
// Caching is not used here as currentTime is unlikely to have been previously cached double timelineLength = relativePositionAt(time, timeRange) - relativePositionAt(currentTime, timeRange);
double timelinePosition = relativePositionAt(currentTime, timeRange); return (float)(timelineLength * scrollLength);
return (float)((relativePositionAtCached(time, timeRange) - timelinePosition) * scrollLength);
} }
public double TimeAt(float position, double currentTime, double timeRange, float scrollLength) public double TimeAt(float position, double currentTime, double timeRange, float scrollLength)
{ {
// Convert the position to a length relative to time = 0 if (controlPoints.Count == 0)
double length = position / scrollLength + relativePositionAt(currentTime, timeRange); return position * timeRange;
// We need to consider all timing points until the specified time and not just the currently-active one, // Find the position at the current time, and the given length.
// since each timing point individually affects the positions of _all_ hitobjects after its start time double relativePosition = relativePositionAt(currentTime, timeRange) + position / scrollLength;
for (int i = 0; i < controlPoints.Count; i++)
{
var current = controlPoints[i];
var next = i < controlPoints.Count - 1 ? controlPoints[i + 1] : null;
// Duration of the current control point var positionMapping = findControlPointMapping(timeRange, new PositionMapping(0, null, relativePosition), by_position_comparer);
var currentDuration = (next?.StartTime ?? double.PositiveInfinity) - current.StartTime;
// Figure out the length of control point // Begin at the control point's time and add the remaining time to reach the given position.
var currentLength = currentDuration / timeRange * current.Multiplier; return positionMapping.Time + (relativePosition - positionMapping.Position) * timeRange / positionMapping.ControlPoint.Multiplier;
if (currentLength > length)
{
// The point is within this control point
return current.StartTime + length * timeRange / current.Multiplier;
}
length -= currentLength;
}
return 0; // Should never occur
} }
private double relativePositionAtCached(double time, double timeRange) public void Reset() => positionMappings.Clear();
{
if (!positionCache.TryGetValue(time, out double existing))
positionCache[time] = existing = relativePositionAt(time, timeRange);
return existing;
}
public void Reset() => positionCache.Clear();
/// <summary> /// <summary>
/// Finds the position which corresponds to a point in time. /// Finds the position which corresponds to a point in time.
@ -84,37 +65,100 @@ namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
/// <param name="time">The time to find the position at.</param> /// <param name="time">The time to find the position at.</param>
/// <param name="timeRange">The amount of time visualised by the scrolling area.</param> /// <param name="timeRange">The amount of time visualised by the scrolling area.</param>
/// <returns>A positive value indicating the position at <paramref name="time"/>.</returns> /// <returns>A positive value indicating the position at <paramref name="time"/>.</returns>
private double relativePositionAt(double time, double timeRange) private double relativePositionAt(in double time, in double timeRange)
{ {
if (controlPoints.Count == 0) if (controlPoints.Count == 0)
return time / timeRange; return time / timeRange;
double length = 0; var mapping = findControlPointMapping(timeRange, new PositionMapping(time));
// We need to consider all timing points until the specified time and not just the currently-active one, // Begin at the control point's position and add the remaining distance to reach the given time.
// since each timing point individually affects the positions of _all_ hitobjects after its start time return mapping.Position + (time - mapping.Time) / timeRange * mapping.ControlPoint.Multiplier;
for (int i = 0; i < controlPoints.Count; i++) }
/// <summary>
/// Finds a <see cref="MultiplierControlPoint"/>'s <see cref="PositionMapping"/> that is relevant to a given <see cref="PositionMapping"/>.
/// </summary>
/// <remarks>
/// This is used to find the last <see cref="MultiplierControlPoint"/> occuring prior to a time value, or prior to a position value (if <see cref="by_position_comparer"/> is used).
/// </remarks>
/// <param name="timeRange">The time range.</param>
/// <param name="search">The <see cref="PositionMapping"/> to find the closest <see cref="PositionMapping"/> to.</param>
/// <param name="comparer">The comparison. If null, the default comparer is used (by time).</param>
/// <returns>The <see cref="MultiplierControlPoint"/>'s <see cref="PositionMapping"/> that is relevant for <paramref name="search"/>.</returns>
private PositionMapping findControlPointMapping(in double timeRange, in PositionMapping search, IComparer<PositionMapping> comparer = null)
{
generatePositionMappings(timeRange);
var mappingIndex = positionMappings.BinarySearch(search, comparer ?? Comparer<PositionMapping>.Default);
if (mappingIndex < 0)
{ {
var current = controlPoints[i]; // If the search value isn't found, the _next_ control point is returned, but we actually want the _previous_ control point.
var next = i < controlPoints.Count - 1 ? controlPoints[i + 1] : null; // In doing so, we must make sure to not underflow the position mapping list (i.e. always use the 0th control point for time < first_control_point_time).
mappingIndex = Math.Max(0, ~mappingIndex - 1);
// We don't need to consider any control points beyond the current time, since it will not yet Debug.Assert(mappingIndex < positionMappings.Count);
// affect any hitobjects
if (i > 0 && current.StartTime > time)
continue;
// Duration of the current control point
var currentDuration = (next?.StartTime ?? double.PositiveInfinity) - current.StartTime;
// We want to consider the minimal amount of time that this control point has affected,
// which may be either its duration, or the amount of time that has passed within it
var durationInCurrent = Math.Min(currentDuration, time - current.StartTime);
// Figure out how much of the time range the duration represents, and adjust it by the speed multiplier
length += durationInCurrent / timeRange * current.Multiplier;
} }
return length; var mapping = positionMappings[mappingIndex];
Debug.Assert(mapping.ControlPoint != null);
return mapping;
}
/// <summary>
/// Generates the mapping of <see cref="MultiplierControlPoint"/> (and their respective start times) to their relative position from 0.
/// </summary>
/// <param name="timeRange">The time range.</param>
private void generatePositionMappings(in double timeRange)
{
if (positionMappings.Count > 0)
return;
if (controlPoints.Count == 0)
return;
positionMappings.Add(new PositionMapping(controlPoints[0].StartTime, controlPoints[0]));
for (int i = 0; i < controlPoints.Count - 1; i++)
{
var current = controlPoints[i];
var next = controlPoints[i + 1];
// Figure out how much of the time range the duration represents, and adjust it by the speed multiplier
float length = (float)((next.StartTime - current.StartTime) / timeRange * current.Multiplier);
positionMappings.Add(new PositionMapping(next.StartTime, next, positionMappings[^1].Position + length));
}
}
private readonly struct PositionMapping : IComparable<PositionMapping>
{
/// <summary>
/// The time corresponding to this position.
/// </summary>
public readonly double Time;
/// <summary>
/// The <see cref="MultiplierControlPoint"/> at <see cref="Time"/>.
/// </summary>
[CanBeNull]
public readonly MultiplierControlPoint ControlPoint;
/// <summary>
/// The relative position from 0 of <see cref="ControlPoint"/>.
/// </summary>
public readonly double Position;
public PositionMapping(double time, MultiplierControlPoint controlPoint = null, double position = default)
{
Time = time;
ControlPoint = controlPoint;
Position = position;
}
public int CompareTo(PositionMapping other) => Time.CompareTo(other.Time);
} }
} }
} }

View File

@ -79,6 +79,11 @@ namespace osu.Game.Screens.Ranking
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]
{ {
statisticsPanel = new StatisticsPanel
{
RelativeSizeAxes = Axes.Both,
Score = { BindTarget = SelectedScore }
},
scorePanelList = new ScorePanelList scorePanelList = new ScorePanelList
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -89,11 +94,6 @@ namespace osu.Game.Screens.Ranking
{ {
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
}, },
statisticsPanel = new StatisticsPanel
{
RelativeSizeAxes = Axes.Both,
Score = { BindTarget = SelectedScore }
},
} }
} }
}, },

View File

@ -24,7 +24,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Framework" Version="2020.623.0" /> <PackageReference Include="ppy.osu.Framework" Version="2020.701.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.622.1" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2020.622.1" />
<PackageReference Include="Sentry" Version="2.1.4" /> <PackageReference Include="Sentry" Version="2.1.4" />
<PackageReference Include="SharpCompress" Version="0.25.1" /> <PackageReference Include="SharpCompress" Version="0.25.1" />

View File

@ -70,7 +70,7 @@
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Package References"> <ItemGroup Label="Package References">
<PackageReference Include="ppy.osu.Framework.iOS" Version="2020.623.0" /> <PackageReference Include="ppy.osu.Framework.iOS" Version="2020.701.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.622.1" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2020.622.1" />
</ItemGroup> </ItemGroup>
<!-- Xamarin.iOS does not automatically handle transitive dependencies from NuGet packages. --> <!-- Xamarin.iOS does not automatically handle transitive dependencies from NuGet packages. -->
@ -80,7 +80,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Framework" Version="2020.623.0" /> <PackageReference Include="ppy.osu.Framework" Version="2020.701.0" />
<PackageReference Include="SharpCompress" Version="0.25.1" /> <PackageReference Include="SharpCompress" Version="0.25.1" />
<PackageReference Include="NUnit" Version="3.12.0" /> <PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />