mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:12:54 +08:00
Merge branch 'beatmap-length-calcualtions' into pause-screen-progress
This commit is contained in:
commit
cf9fda0cf2
@ -42,7 +42,8 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(90, 90)
|
||||
Size = new Vector2(90, 90),
|
||||
Scale = new Vector2(3),
|
||||
}
|
||||
};
|
||||
});
|
||||
@ -64,17 +65,24 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
InputManager.MoveMouseTo(tickMarkerHead.ScreenSpaceDrawQuad.Centre);
|
||||
InputManager.PressButton(MouseButton.Left);
|
||||
});
|
||||
AddStep("move to 8 and release", () =>
|
||||
AddStep("move to 1", () => InputManager.MoveMouseTo(getPositionForDivisor(1)));
|
||||
AddStep("move to 16 and release", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(tickSliderBar.ScreenSpaceDrawQuad.Centre);
|
||||
InputManager.MoveMouseTo(getPositionForDivisor(16));
|
||||
InputManager.ReleaseButton(MouseButton.Left);
|
||||
});
|
||||
AddAssert("divisor is 8", () => bindableBeatDivisor.Value == 8);
|
||||
AddAssert("divisor is 16", () => bindableBeatDivisor.Value == 16);
|
||||
AddStep("hold marker", () => InputManager.PressButton(MouseButton.Left));
|
||||
AddStep("move to 16", () => InputManager.MoveMouseTo(getPositionForDivisor(16)));
|
||||
AddStep("move to ~10 and release", () =>
|
||||
AddStep("move to ~6 and release", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(getPositionForDivisor(6));
|
||||
InputManager.ReleaseButton(MouseButton.Left);
|
||||
});
|
||||
AddAssert("divisor clamped to 8", () => bindableBeatDivisor.Value == 8);
|
||||
AddStep("move to ~10 and click", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(getPositionForDivisor(10));
|
||||
InputManager.PressButton(MouseButton.Left);
|
||||
InputManager.ReleaseButton(MouseButton.Left);
|
||||
});
|
||||
AddAssert("divisor clamped to 8", () => bindableBeatDivisor.Value == 8);
|
||||
@ -82,12 +90,11 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
|
||||
private Vector2 getPositionForDivisor(int divisor)
|
||||
{
|
||||
float relativePosition = (float)Math.Clamp(divisor, 0, 16) / 16;
|
||||
var sliderDrawQuad = tickSliderBar.ScreenSpaceDrawQuad;
|
||||
return new Vector2(
|
||||
sliderDrawQuad.TopLeft.X + sliderDrawQuad.Width * relativePosition,
|
||||
sliderDrawQuad.Centre.Y
|
||||
);
|
||||
float localX = (1 - 1 / (float)divisor) * tickSliderBar.UsableWidth + tickSliderBar.RangePadding;
|
||||
return tickSliderBar.ToScreenSpace(new Vector2(
|
||||
localX,
|
||||
tickSliderBar.DrawHeight / 2
|
||||
));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -7,6 +7,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
@ -137,8 +138,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
if (!objects.Any())
|
||||
return;
|
||||
|
||||
double firstHit = objects.First().StartTime;
|
||||
double lastHit = objects.Max(o => o.GetEndTime());
|
||||
(double firstHit, double lastHit) = BeatmapExtensions.CalculatePlayableBounds(objects);
|
||||
|
||||
if (lastHit == 0)
|
||||
lastHit = objects.Last().StartTime;
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Logging;
|
||||
@ -11,7 +10,6 @@ using osu.Framework.Platform;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
{
|
||||
@ -74,7 +72,7 @@ namespace osu.Game.Beatmaps
|
||||
var calculator = ruleset.CreateDifficultyCalculator(working);
|
||||
|
||||
beatmap.StarRating = calculator.Calculate().StarRating;
|
||||
beatmap.Length = calculateLength(working.Beatmap);
|
||||
beatmap.Length = working.Beatmap.CalculatePlayableLength();
|
||||
beatmap.BPM = 60000 / working.Beatmap.GetMostCommonBeatLength();
|
||||
}
|
||||
|
||||
@ -82,20 +80,6 @@ namespace osu.Game.Beatmaps
|
||||
workingBeatmapCache.Invalidate(beatmapSet);
|
||||
});
|
||||
|
||||
private double calculateLength(IBeatmap b)
|
||||
{
|
||||
if (!b.HitObjects.Any())
|
||||
return 0;
|
||||
|
||||
var lastObject = b.HitObjects.Last();
|
||||
|
||||
//TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list).
|
||||
double endTime = lastObject.GetEndTime();
|
||||
double startTime = b.HitObjects.First().StartTime;
|
||||
|
||||
return endTime - startTime;
|
||||
}
|
||||
|
||||
#region Implementation of IDisposable
|
||||
|
||||
public void Dispose()
|
||||
|
@ -104,6 +104,19 @@ namespace osu.Game.Beatmaps
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the total milliseconds between the first and last hittable objects.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is cached to <see cref="BeatmapInfo.Length"/>, so using that is preferrable when available.
|
||||
/// </remarks>
|
||||
public static double CalculatePlayableLength(this IBeatmap beatmap) => CalculatePlayableLength(beatmap.HitObjects);
|
||||
|
||||
/// <summary>
|
||||
/// Find the timestamps in milliseconds of the start and end of the playable region.
|
||||
/// </summary>
|
||||
public static (double start, double end) CalculatePlayableBounds(this IBeatmap beatmap) => CalculatePlayableBounds(beatmap.HitObjects);
|
||||
|
||||
/// <summary>
|
||||
/// Find the absolute end time of the latest <see cref="HitObject"/> in a beatmap. Will throw if beatmap contains no objects.
|
||||
/// </summary>
|
||||
@ -114,5 +127,36 @@ namespace osu.Game.Beatmaps
|
||||
/// It's not super efficient so calls should be kept to a minimum.
|
||||
/// </remarks>
|
||||
public static double GetLastObjectTime(this IBeatmap beatmap) => beatmap.HitObjects.Max(h => h.GetEndTime());
|
||||
|
||||
#region Helper methods
|
||||
|
||||
/// <summary>
|
||||
/// Find the total milliseconds between the first and last hittable objects.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is cached to <see cref="BeatmapInfo.Length"/>, so using that is preferrable when available.
|
||||
/// </remarks>
|
||||
public static double CalculatePlayableLength(IEnumerable<HitObject> objects)
|
||||
{
|
||||
(double start, double end) = CalculatePlayableBounds(objects);
|
||||
|
||||
return end - start;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find the timestamps in milliseconds of the start and end of the playable region.
|
||||
/// </summary>
|
||||
public static (double start, double end) CalculatePlayableBounds(IEnumerable<HitObject> objects)
|
||||
{
|
||||
if (!objects.Any())
|
||||
return (0, 0);
|
||||
|
||||
double lastObjectTime = objects.Max(o => o.GetEndTime());
|
||||
double firstObjectTime = objects.First().StartTime;
|
||||
|
||||
return (firstObjectTime, lastObjectTime);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -154,12 +154,15 @@ namespace osu.Game.Screens.Edit
|
||||
/// </summary>
|
||||
/// <param name="index">The 0-based beat index.</param>
|
||||
/// <param name="beatDivisor">The beat divisor.</param>
|
||||
/// <param name="validDivisors">The list of valid divisors which can be chosen from. Assumes ordered from low to high. Defaults to <see cref="PREDEFINED_DIVISORS"/> if omitted.</param>
|
||||
/// <returns>The applicable divisor.</returns>
|
||||
public static int GetDivisorForBeatIndex(int index, int beatDivisor)
|
||||
public static int GetDivisorForBeatIndex(int index, int beatDivisor, int[] validDivisors = null)
|
||||
{
|
||||
validDivisors ??= PREDEFINED_DIVISORS;
|
||||
|
||||
int beat = index % beatDivisor;
|
||||
|
||||
foreach (int divisor in PREDEFINED_DIVISORS)
|
||||
foreach (int divisor in validDivisors)
|
||||
{
|
||||
if ((beat * divisor) % beatDivisor == 0)
|
||||
return divisor;
|
||||
|
@ -383,7 +383,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
{
|
||||
CurrentNumber.BindTo(this.beatDivisor = beatDivisor);
|
||||
|
||||
Padding = new MarginPadding { Horizontal = 5 };
|
||||
RangePadding = 5;
|
||||
Padding = new MarginPadding { Horizontal = RangePadding };
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -398,15 +399,20 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
ClearInternal();
|
||||
CurrentNumber.ValueChanged -= moveMarker;
|
||||
|
||||
foreach (int divisor in beatDivisor.ValidDivisors.Value.Presets)
|
||||
int largestDivisor = beatDivisor.ValidDivisors.Value.Presets.Last();
|
||||
|
||||
for (int tickIndex = 0; tickIndex <= largestDivisor; tickIndex++)
|
||||
{
|
||||
AddInternal(new Tick(divisor)
|
||||
int divisor = BindableBeatDivisor.GetDivisorForBeatIndex(tickIndex, largestDivisor, (int[])beatDivisor.ValidDivisors.Value.Presets);
|
||||
bool isSolidTick = divisor * (largestDivisor - tickIndex) == largestDivisor;
|
||||
|
||||
AddInternal(new Tick(divisor, isSolidTick)
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.Centre,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Colour = BindableBeatDivisor.GetColourFor(divisor, colours),
|
||||
X = getMappedPosition(divisor),
|
||||
X = tickIndex / (float)largestDivisor,
|
||||
});
|
||||
}
|
||||
|
||||
@ -418,6 +424,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
private void moveMarker(ValueChangedEvent<int> divisor)
|
||||
{
|
||||
marker.MoveToX(getMappedPosition(divisor.NewValue), 100, Easing.OutQuint);
|
||||
|
||||
foreach (Tick tick in InternalChildren.OfType<Tick>().Where(t => !t.AlwaysDisplayed))
|
||||
{
|
||||
tick.FadeTo(divisor.NewValue % tick.Divisor == 0 ? 0.2f : 0f, 100, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateValue(float value)
|
||||
@ -483,13 +494,22 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
OnUserChange(Current.Value);
|
||||
}
|
||||
|
||||
private float getMappedPosition(float divisor) => MathF.Pow((divisor - 1) / (beatDivisor.ValidDivisors.Value.Presets.Last() - 1), 0.90f);
|
||||
private float getMappedPosition(float divisor) => 1 - 1 / divisor;
|
||||
|
||||
private partial class Tick : Circle
|
||||
{
|
||||
public Tick(int divisor)
|
||||
public readonly bool AlwaysDisplayed;
|
||||
|
||||
public readonly int Divisor;
|
||||
|
||||
public Tick(int divisor, bool alwaysDisplayed)
|
||||
{
|
||||
AlwaysDisplayed = alwaysDisplayed;
|
||||
Divisor = divisor;
|
||||
|
||||
Size = new Vector2(6f, 12) * BindableBeatDivisor.GetSize(divisor);
|
||||
Alpha = alwaysDisplayed ? 1 : 0;
|
||||
|
||||
InternalChild = new Box { RelativeSizeAxes = Axes.Both };
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
@ -26,8 +27,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
if (!objects.Any())
|
||||
return;
|
||||
|
||||
double firstHit = objects.First().StartTime;
|
||||
double lastHit = objects.Max(o => o.GetEndTime());
|
||||
(double firstHit, double lastHit) = BeatmapExtensions.CalculatePlayableBounds(objects);
|
||||
|
||||
if (lastHit == 0)
|
||||
lastHit = objects.Last().StartTime;
|
||||
|
@ -6,6 +6,7 @@
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
@ -26,8 +27,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
if (!objects.Any())
|
||||
return;
|
||||
|
||||
double firstHit = objects.First().StartTime;
|
||||
double lastHit = objects.Max(o => o.GetEndTime());
|
||||
(double firstHit, double lastHit) = BeatmapExtensions.CalculatePlayableBounds(objects);
|
||||
|
||||
if (lastHit == 0)
|
||||
lastHit = objects.Last().StartTime;
|
||||
|
@ -2,12 +2,12 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Skinning;
|
||||
@ -52,9 +52,9 @@ namespace osu.Game.Screens.Play.HUD
|
||||
set
|
||||
{
|
||||
objects = value;
|
||||
FirstHitTime = objects.FirstOrDefault()?.StartTime ?? 0;
|
||||
//TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list).
|
||||
LastHitTime = objects.LastOrDefault()?.GetEndTime() ?? 0;
|
||||
|
||||
(FirstHitTime, LastHitTime) = BeatmapExtensions.CalculatePlayableBounds(objects);
|
||||
|
||||
UpdateObjects(objects);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user