1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-23 04:33:16 +08:00

Merge remote-tracking branch 'origin/master' into sorcerer-diffcalc-changes

This commit is contained in:
smoogipoo 2019-03-14 19:15:22 +09:00
commit f1c50d5ce1
22 changed files with 313 additions and 120 deletions

View File

@ -22,22 +22,15 @@ namespace osu.Game.Rulesets.Mania.UI
JudgementText.Font = JudgementText.Font.With(size: 25); JudgementText.Font = JudgementText.Font.With(size: 25);
} }
protected override void LoadComplete() protected override double FadeInDuration => 50;
protected override void ApplyHitAnimations()
{ {
base.LoadComplete(); JudgementBody.ScaleTo(0.8f);
JudgementBody.ScaleTo(1, 250, Easing.OutElastic);
this.FadeInFromZero(50, Easing.OutQuint); JudgementBody.Delay(FadeInDuration).ScaleTo(0.75f, 250);
this.Delay(FadeInDuration).FadeOut(200);
if (Result.IsHit)
{
JudgementBody.ScaleTo(0.8f);
JudgementBody.ScaleTo(1, 250, Easing.OutElastic);
JudgementBody.Delay(50).ScaleTo(0.75f, 250);
this.Delay(50).FadeOut(200);
}
Expire();
} }
} }
} }

View File

@ -5,7 +5,6 @@ using osu.Framework.Graphics;
using osuTK; using osuTK;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Scoring;
namespace osu.Game.Rulesets.Osu.Objects.Drawables namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
@ -16,12 +15,10 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
} }
protected override void LoadComplete() protected override void ApplyHitAnimations()
{ {
if (Result.Type != HitResult.Miss) JudgementText?.TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint);
JudgementText?.TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint); base.ApplyHitAnimations();
base.LoadComplete();
} }
} }
} }

View File

@ -39,12 +39,10 @@ namespace osu.Game.Rulesets.Taiko.UI
} }
} }
protected override void LoadComplete() protected override void ApplyHitAnimations()
{ {
if (Result.IsHit) this.MoveToY(-100, 500);
this.MoveToY(-100, 500); base.ApplyHitAnimations();
base.LoadComplete();
} }
} }
} }

View File

@ -0,0 +1,72 @@
// 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.
using System;
using System.Globalization;
using NUnit.Framework;
using osu.Game.Beatmaps.Formats;
namespace osu.Game.Tests.Beatmaps.Formats
{
[TestFixture]
public class ParsingTest
{
[Test]
public void TestNaNHandling() => allThrow<FormatException>("NaN");
[Test]
public void TestBadStringHandling() => allThrow<FormatException>("Random string 123");
[TestCase(Parsing.MAX_PARSE_VALUE)]
[TestCase(-1)]
[TestCase(0)]
[TestCase(1)]
[TestCase(-Parsing.MAX_PARSE_VALUE)]
[TestCase(10, 10)]
[TestCase(-10, 10)]
public void TestValidRanges(double input, double limit = Parsing.MAX_PARSE_VALUE)
{
Assert.AreEqual(Parsing.ParseInt((input).ToString(CultureInfo.InvariantCulture), (int)limit), (int)input);
Assert.AreEqual(Parsing.ParseFloat((input).ToString(CultureInfo.InvariantCulture), (float)limit), (float)input);
Assert.AreEqual(Parsing.ParseDouble((input).ToString(CultureInfo.InvariantCulture), limit), input);
}
[TestCase(double.PositiveInfinity)]
[TestCase(double.NegativeInfinity)]
[TestCase(999999999999)]
[TestCase(Parsing.MAX_PARSE_VALUE * 1.1)]
[TestCase(-Parsing.MAX_PARSE_VALUE * 1.1)]
[TestCase(11, 10)]
[TestCase(-11, 10)]
public void TestOutOfRangeHandling(double input, double limit = Parsing.MAX_PARSE_VALUE)
=> allThrow<OverflowException>(input.ToString(CultureInfo.InvariantCulture), limit);
private void allThrow<T>(string input, double limit = Parsing.MAX_PARSE_VALUE)
where T : Exception
{
Assert.Throws(getIntParseException(input) ?? typeof(T), () => Parsing.ParseInt(input, (int)limit));
Assert.Throws<T>(() => Parsing.ParseFloat(input, (float)limit));
Assert.Throws<T>(() => Parsing.ParseDouble(input, limit));
}
/// <summary>
/// <see cref="int"/> may not be able to parse some inputs.
/// In this case we expect to receive the raw parsing exception.
/// </summary>
/// <param name="input">The input attempting to be parsed.</param>
/// <returns>The type of exception thrown by <see cref="int.Parse(string)"/>. Null if no exception is thrown.</returns>
private Type getIntParseException(string input)
{
try
{
var _ = int.Parse(input);
}
catch (Exception e)
{
return e.GetType();
}
return null;
}
}
}

View File

@ -2,10 +2,10 @@
// 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 System; using System;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using osu.Framework.IO.File; using osu.Framework.IO.File;
using osu.Framework.Logging;
using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Objects.Legacy; using osu.Game.Rulesets.Objects.Legacy;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
@ -25,7 +25,7 @@ namespace osu.Game.Beatmaps.Formats
public static void Register() public static void Register()
{ {
AddDecoder<Beatmap>(@"osu file format v", m => new LegacyBeatmapDecoder(int.Parse(m.Split('v').Last()))); AddDecoder<Beatmap>(@"osu file format v", m => new LegacyBeatmapDecoder(Parsing.ParseInt(m.Split('v').Last())));
} }
/// <summary> /// <summary>
@ -104,25 +104,25 @@ namespace osu.Game.Beatmaps.Formats
metadata.AudioFile = FileSafety.PathStandardise(pair.Value); metadata.AudioFile = FileSafety.PathStandardise(pair.Value);
break; break;
case @"AudioLeadIn": case @"AudioLeadIn":
beatmap.BeatmapInfo.AudioLeadIn = int.Parse(pair.Value); beatmap.BeatmapInfo.AudioLeadIn = Parsing.ParseInt(pair.Value);
break; break;
case @"PreviewTime": case @"PreviewTime":
metadata.PreviewTime = getOffsetTime(int.Parse(pair.Value)); metadata.PreviewTime = getOffsetTime(Parsing.ParseInt(pair.Value));
break; break;
case @"Countdown": case @"Countdown":
beatmap.BeatmapInfo.Countdown = int.Parse(pair.Value) == 1; beatmap.BeatmapInfo.Countdown = Parsing.ParseInt(pair.Value) == 1;
break; break;
case @"SampleSet": case @"SampleSet":
defaultSampleBank = (LegacySampleBank)Enum.Parse(typeof(LegacySampleBank), pair.Value); defaultSampleBank = (LegacySampleBank)Enum.Parse(typeof(LegacySampleBank), pair.Value);
break; break;
case @"SampleVolume": case @"SampleVolume":
defaultSampleVolume = int.Parse(pair.Value); defaultSampleVolume = Parsing.ParseInt(pair.Value);
break; break;
case @"StackLeniency": case @"StackLeniency":
beatmap.BeatmapInfo.StackLeniency = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo); beatmap.BeatmapInfo.StackLeniency = Parsing.ParseFloat(pair.Value);
break; break;
case @"Mode": case @"Mode":
beatmap.BeatmapInfo.RulesetID = int.Parse(pair.Value); beatmap.BeatmapInfo.RulesetID = Parsing.ParseInt(pair.Value);
switch (beatmap.BeatmapInfo.RulesetID) switch (beatmap.BeatmapInfo.RulesetID)
{ {
@ -142,13 +142,13 @@ namespace osu.Game.Beatmaps.Formats
break; break;
case @"LetterboxInBreaks": case @"LetterboxInBreaks":
beatmap.BeatmapInfo.LetterboxInBreaks = int.Parse(pair.Value) == 1; beatmap.BeatmapInfo.LetterboxInBreaks = Parsing.ParseInt(pair.Value) == 1;
break; break;
case @"SpecialStyle": case @"SpecialStyle":
beatmap.BeatmapInfo.SpecialStyle = int.Parse(pair.Value) == 1; beatmap.BeatmapInfo.SpecialStyle = Parsing.ParseInt(pair.Value) == 1;
break; break;
case @"WidescreenStoryboard": case @"WidescreenStoryboard":
beatmap.BeatmapInfo.WidescreenStoryboard = int.Parse(pair.Value) == 1; beatmap.BeatmapInfo.WidescreenStoryboard = Parsing.ParseInt(pair.Value) == 1;
break; break;
} }
} }
@ -163,16 +163,16 @@ namespace osu.Game.Beatmaps.Formats
beatmap.BeatmapInfo.StoredBookmarks = pair.Value; beatmap.BeatmapInfo.StoredBookmarks = pair.Value;
break; break;
case @"DistanceSpacing": case @"DistanceSpacing":
beatmap.BeatmapInfo.DistanceSpacing = double.Parse(pair.Value, NumberFormatInfo.InvariantInfo); beatmap.BeatmapInfo.DistanceSpacing = Math.Max(0, Parsing.ParseDouble(pair.Value));
break; break;
case @"BeatDivisor": case @"BeatDivisor":
beatmap.BeatmapInfo.BeatDivisor = int.Parse(pair.Value); beatmap.BeatmapInfo.BeatDivisor = Parsing.ParseInt(pair.Value);
break; break;
case @"GridSize": case @"GridSize":
beatmap.BeatmapInfo.GridSize = int.Parse(pair.Value); beatmap.BeatmapInfo.GridSize = Parsing.ParseInt(pair.Value);
break; break;
case @"TimelineZoom": case @"TimelineZoom":
beatmap.BeatmapInfo.TimelineZoom = double.Parse(pair.Value, NumberFormatInfo.InvariantInfo); beatmap.BeatmapInfo.TimelineZoom = Math.Max(0, Parsing.ParseDouble(pair.Value));
break; break;
} }
} }
@ -209,10 +209,10 @@ namespace osu.Game.Beatmaps.Formats
beatmap.BeatmapInfo.Metadata.Tags = pair.Value; beatmap.BeatmapInfo.Metadata.Tags = pair.Value;
break; break;
case @"BeatmapID": case @"BeatmapID":
beatmap.BeatmapInfo.OnlineBeatmapID = int.Parse(pair.Value); beatmap.BeatmapInfo.OnlineBeatmapID = Parsing.ParseInt(pair.Value);
break; break;
case @"BeatmapSetID": case @"BeatmapSetID":
beatmap.BeatmapInfo.BeatmapSet = new BeatmapSetInfo { OnlineBeatmapSetID = int.Parse(pair.Value) }; beatmap.BeatmapInfo.BeatmapSet = new BeatmapSetInfo { OnlineBeatmapSetID = Parsing.ParseInt(pair.Value) };
break; break;
} }
} }
@ -225,22 +225,22 @@ namespace osu.Game.Beatmaps.Formats
switch (pair.Key) switch (pair.Key)
{ {
case @"HPDrainRate": case @"HPDrainRate":
difficulty.DrainRate = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo); difficulty.DrainRate = Parsing.ParseFloat(pair.Value);
break; break;
case @"CircleSize": case @"CircleSize":
difficulty.CircleSize = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo); difficulty.CircleSize = Parsing.ParseFloat(pair.Value);
break; break;
case @"OverallDifficulty": case @"OverallDifficulty":
difficulty.OverallDifficulty = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo); difficulty.OverallDifficulty = Parsing.ParseFloat(pair.Value);
break; break;
case @"ApproachRate": case @"ApproachRate":
difficulty.ApproachRate = float.Parse(pair.Value, NumberFormatInfo.InvariantInfo); difficulty.ApproachRate = Parsing.ParseFloat(pair.Value);
break; break;
case @"SliderMultiplier": case @"SliderMultiplier":
difficulty.SliderMultiplier = double.Parse(pair.Value, NumberFormatInfo.InvariantInfo); difficulty.SliderMultiplier = Parsing.ParseDouble(pair.Value);
break; break;
case @"SliderTickRate": case @"SliderTickRate":
difficulty.SliderTickRate = double.Parse(pair.Value, NumberFormatInfo.InvariantInfo); difficulty.SliderTickRate = Parsing.ParseDouble(pair.Value);
break; break;
} }
} }
@ -260,10 +260,12 @@ namespace osu.Game.Beatmaps.Formats
beatmap.BeatmapInfo.Metadata.BackgroundFile = FileSafety.PathStandardise(filename); beatmap.BeatmapInfo.Metadata.BackgroundFile = FileSafety.PathStandardise(filename);
break; break;
case EventType.Break: case EventType.Break:
double start = getOffsetTime(Parsing.ParseDouble(split[1]));
var breakEvent = new BreakPeriod var breakEvent = new BreakPeriod
{ {
StartTime = getOffsetTime(double.Parse(split[1], NumberFormatInfo.InvariantInfo)), StartTime = start,
EndTime = getOffsetTime(double.Parse(split[2], NumberFormatInfo.InvariantInfo)) EndTime = Math.Max(start, getOffsetTime(Parsing.ParseDouble(split[2])))
}; };
if (!breakEvent.HasEffect) if (!breakEvent.HasEffect)
@ -280,25 +282,25 @@ namespace osu.Game.Beatmaps.Formats
{ {
string[] split = line.Split(','); string[] split = line.Split(',');
double time = getOffsetTime(double.Parse(split[0].Trim(), NumberFormatInfo.InvariantInfo)); double time = getOffsetTime(Parsing.ParseDouble(split[0].Trim()));
double beatLength = double.Parse(split[1].Trim(), NumberFormatInfo.InvariantInfo); double beatLength = Parsing.ParseDouble(split[1].Trim());
double speedMultiplier = beatLength < 0 ? 100.0 / -beatLength : 1; double speedMultiplier = beatLength < 0 ? 100.0 / -beatLength : 1;
TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple; TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple;
if (split.Length >= 3) if (split.Length >= 3)
timeSignature = split[2][0] == '0' ? TimeSignatures.SimpleQuadruple : (TimeSignatures)int.Parse(split[2]); timeSignature = split[2][0] == '0' ? TimeSignatures.SimpleQuadruple : (TimeSignatures)Parsing.ParseInt(split[2]);
LegacySampleBank sampleSet = defaultSampleBank; LegacySampleBank sampleSet = defaultSampleBank;
if (split.Length >= 4) if (split.Length >= 4)
sampleSet = (LegacySampleBank)int.Parse(split[3]); sampleSet = (LegacySampleBank)Parsing.ParseInt(split[3]);
int customSampleBank = 0; int customSampleBank = 0;
if (split.Length >= 5) if (split.Length >= 5)
customSampleBank = int.Parse(split[4]); customSampleBank = Parsing.ParseInt(split[4]);
int sampleVolume = defaultSampleVolume; int sampleVolume = defaultSampleVolume;
if (split.Length >= 6) if (split.Length >= 6)
sampleVolume = int.Parse(split[5]); sampleVolume = Parsing.ParseInt(split[5]);
bool timingChange = true; bool timingChange = true;
if (split.Length >= 7) if (split.Length >= 7)
@ -308,7 +310,7 @@ namespace osu.Game.Beatmaps.Formats
bool omitFirstBarSignature = false; bool omitFirstBarSignature = false;
if (split.Length >= 8) if (split.Length >= 8)
{ {
EffectFlags effectFlags = (EffectFlags)int.Parse(split[7]); EffectFlags effectFlags = (EffectFlags)Parsing.ParseInt(split[7]);
kiaiMode = effectFlags.HasFlag(EffectFlags.Kiai); kiaiMode = effectFlags.HasFlag(EffectFlags.Kiai);
omitFirstBarSignature = effectFlags.HasFlag(EffectFlags.OmitFirstBarLine); omitFirstBarSignature = effectFlags.HasFlag(EffectFlags.OmitFirstBarLine);
} }
@ -348,8 +350,13 @@ namespace osu.Game.Beatmaps.Formats
CustomSampleBank = customSampleBank CustomSampleBank = customSampleBank
}); });
} }
catch (FormatException e) catch (FormatException)
{ {
Logger.Log("A timing point could not be parsed correctly and will be ignored", LoggingTarget.Runtime, LogLevel.Important);
}
catch (OverflowException)
{
Logger.Log("A timing point could not be parsed correctly and will be ignored", LoggingTarget.Runtime, LogLevel.Important);
} }
} }

View File

@ -0,0 +1,52 @@
// 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.
using System;
using System.Globalization;
namespace osu.Game.Beatmaps.Formats
{
/// <summary>
/// Helper methods to parse from string to number and perform very basic validation.
/// </summary>
public static class Parsing
{
public const int MAX_COORDINATE_VALUE = 65536;
public const double MAX_PARSE_VALUE = int.MaxValue;
public static float ParseFloat(string input, float parseLimit = (float)MAX_PARSE_VALUE)
{
var output = float.Parse(input, CultureInfo.InvariantCulture);
if (output < -parseLimit) throw new OverflowException("Value is too low");
if (output > parseLimit) throw new OverflowException("Value is too high");
if (float.IsNaN(output)) throw new FormatException("Not a number");
return output;
}
public static double ParseDouble(string input, double parseLimit = MAX_PARSE_VALUE)
{
var output = double.Parse(input, CultureInfo.InvariantCulture);
if (output < -parseLimit) throw new OverflowException("Value is too low");
if (output > parseLimit) throw new OverflowException("Value is too high");
if (double.IsNaN(output)) throw new FormatException("Not a number");
return output;
}
public static int ParseInt(string input, int parseLimit = (int)MAX_PARSE_VALUE)
{
var output = int.Parse(input, CultureInfo.InvariantCulture);
if (output < -parseLimit) throw new OverflowException("Value is too low");
if (output > parseLimit) throw new OverflowException("Value is too high");
return output;
}
}
}

View File

@ -185,10 +185,7 @@ namespace osu.Game.Overlays.Direct
Margin = new MarginPadding { Top = vertical_padding, Right = vertical_padding }, Margin = new MarginPadding { Top = vertical_padding, Right = vertical_padding },
Children = new[] Children = new[]
{ {
new Statistic(FontAwesome.fa_play_circle, SetInfo.OnlineInfo?.PlayCount ?? 0) new Statistic(FontAwesome.fa_play_circle, SetInfo.OnlineInfo?.PlayCount ?? 0),
{
Margin = new MarginPadding { Right = 1 },
},
new Statistic(FontAwesome.fa_heart, SetInfo.OnlineInfo?.FavouriteCount ?? 0), new Statistic(FontAwesome.fa_heart, SetInfo.OnlineInfo?.FavouriteCount ?? 0),
}, },
}, },

View File

@ -160,10 +160,7 @@ namespace osu.Game.Overlays.Direct
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Children = new Drawable[] Children = new Drawable[]
{ {
new Statistic(FontAwesome.fa_play_circle, SetInfo.OnlineInfo?.PlayCount ?? 0) new Statistic(FontAwesome.fa_play_circle, SetInfo.OnlineInfo?.PlayCount ?? 0),
{
Margin = new MarginPadding { Right = 1 },
},
new Statistic(FontAwesome.fa_heart, SetInfo.OnlineInfo?.FavouriteCount ?? 0), new Statistic(FontAwesome.fa_heart, SetInfo.OnlineInfo?.FavouriteCount ?? 0),
new FillFlowContainer new FillFlowContainer
{ {

View File

@ -32,6 +32,12 @@ namespace osu.Game.Rulesets.Judgements
protected Container JudgementBody; protected Container JudgementBody;
protected SpriteText JudgementText; protected SpriteText JudgementText;
/// <summary>
/// Duration of initial fade in.
/// Default fade out will start immediately after this duration.
/// </summary>
protected virtual double FadeInDuration => 100;
/// <summary> /// <summary>
/// Creates a drawable which visualises a <see cref="Judgements.Judgement"/>. /// Creates a drawable which visualises a <see cref="Judgements.Judgement"/>.
/// </summary> /// </summary>
@ -65,11 +71,19 @@ namespace osu.Game.Rulesets.Judgements
}; };
} }
protected virtual void ApplyHitAnimations()
{
JudgementBody.ScaleTo(0.9f);
JudgementBody.ScaleTo(1, 500, Easing.OutElastic);
this.Delay(FadeInDuration).FadeOut(400);
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
this.FadeInFromZero(100, Easing.OutQuint); this.FadeInFromZero(FadeInDuration, Easing.OutQuint);
switch (Result.Type) switch (Result.Type)
{ {
@ -85,10 +99,7 @@ namespace osu.Game.Rulesets.Judgements
this.Delay(600).FadeOut(200); this.Delay(600).FadeOut(200);
break; break;
default: default:
JudgementBody.ScaleTo(0.9f); ApplyHitAnimations();
JudgementBody.ScaleTo(1, 500, Easing.OutElastic);
this.Delay(100).FadeOut(400);
break; break;
} }

View File

@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Mods
public override void ApplyToClock(IAdjustableClock clock) public override void ApplyToClock(IAdjustableClock clock)
{ {
if (clock is IHasPitchAdjust pitchAdjust) if (clock is IHasPitchAdjust pitchAdjust)
pitchAdjust.PitchAdjust = 0.75; pitchAdjust.PitchAdjust *= RateAdjust;
else else
base.ApplyToClock(clock); base.ApplyToClock(clock);
} }

View File

@ -2,12 +2,12 @@
// 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 System; using System;
using osu.Framework.Timing; using System.Linq;
using osu.Game.Graphics; using osu.Game.Graphics;
namespace osu.Game.Rulesets.Mods namespace osu.Game.Rulesets.Mods
{ {
public abstract class ModDoubleTime : Mod, IApplicableToClock public abstract class ModDoubleTime : ModTimeAdjust, IApplicableToClock
{ {
public override string Name => "Double Time"; public override string Name => "Double Time";
public override string Acronym => "DT"; public override string Acronym => "DT";
@ -15,11 +15,9 @@ namespace osu.Game.Rulesets.Mods
public override ModType Type => ModType.DifficultyIncrease; public override ModType Type => ModType.DifficultyIncrease;
public override string Description => "Zoooooooooom..."; public override string Description => "Zoooooooooom...";
public override bool Ranked => true; public override bool Ranked => true;
public override Type[] IncompatibleMods => new[] { typeof(ModHalfTime), typeof(ModTimeRamp) };
public virtual void ApplyToClock(IAdjustableClock clock) public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModHalfTime)).ToArray();
{
clock.Rate = 1.5; protected override double RateAdjust => 1.5;
}
} }
} }

View File

@ -2,12 +2,12 @@
// 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 System; using System;
using osu.Framework.Timing; using System.Linq;
using osu.Game.Graphics; using osu.Game.Graphics;
namespace osu.Game.Rulesets.Mods namespace osu.Game.Rulesets.Mods
{ {
public abstract class ModHalfTime : Mod, IApplicableToClock public abstract class ModHalfTime : ModTimeAdjust, IApplicableToClock
{ {
public override string Name => "Half Time"; public override string Name => "Half Time";
public override string Acronym => "HT"; public override string Acronym => "HT";
@ -15,11 +15,9 @@ namespace osu.Game.Rulesets.Mods
public override ModType Type => ModType.DifficultyReduction; public override ModType Type => ModType.DifficultyReduction;
public override string Description => "Less zoom..."; public override string Description => "Less zoom...";
public override bool Ranked => true; public override bool Ranked => true;
public override Type[] IncompatibleMods => new[] { typeof(ModDoubleTime), typeof(ModTimeRamp) };
public virtual void ApplyToClock(IAdjustableClock clock) public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModDoubleTime)).ToArray();
{
clock.Rate = 0.75; protected override double RateAdjust => 0.75;
}
} }
} }

View File

@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Mods
public override void ApplyToClock(IAdjustableClock clock) public override void ApplyToClock(IAdjustableClock clock)
{ {
if (clock is IHasPitchAdjust pitchAdjust) if (clock is IHasPitchAdjust pitchAdjust)
pitchAdjust.PitchAdjust = 1.5; pitchAdjust.PitchAdjust *= RateAdjust;
else else
base.ApplyToClock(clock); base.ApplyToClock(clock);
} }

View File

@ -0,0 +1,24 @@
// 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.
using System;
using osu.Framework.Audio;
using osu.Framework.Timing;
namespace osu.Game.Rulesets.Mods
{
public abstract class ModTimeAdjust : Mod
{
public override Type[] IncompatibleMods => new[] { typeof(ModTimeRamp) };
protected abstract double RateAdjust { get; }
public virtual void ApplyToClock(IAdjustableClock clock)
{
if (clock is IHasTempoAdjust tempo)
tempo.TempoAdjust *= RateAdjust;
else
clock.Rate *= RateAdjust;
}
}
}

View File

@ -15,7 +15,7 @@ namespace osu.Game.Rulesets.Mods
{ {
public abstract class ModTimeRamp : Mod public abstract class ModTimeRamp : Mod
{ {
public override Type[] IncompatibleMods => new[] { typeof(ModDoubleTime), typeof(ModHalfTime) }; public override Type[] IncompatibleMods => new[] { typeof(ModTimeAdjust) };
protected abstract double FinalRateAdjustment { get; } protected abstract double FinalRateAdjustment { get; }
} }
@ -29,8 +29,6 @@ namespace osu.Game.Rulesets.Mods
private IAdjustableClock clock; private IAdjustableClock clock;
private IHasPitchAdjust pitchAdjust;
/// <summary> /// <summary>
/// The point in the beatmap at which the final ramping rate should be reached. /// The point in the beatmap at which the final ramping rate should be reached.
/// </summary> /// </summary>
@ -39,10 +37,11 @@ namespace osu.Game.Rulesets.Mods
public virtual void ApplyToClock(IAdjustableClock clock) public virtual void ApplyToClock(IAdjustableClock clock)
{ {
this.clock = clock; this.clock = clock;
pitchAdjust = (IHasPitchAdjust)clock;
// for preview purposes lastAdjust = 1;
pitchAdjust.PitchAdjust = 1.0 + FinalRateAdjustment;
// for preview purposes. during gameplay, Update will overwrite this setting.
applyAdjustment(1);
} }
public virtual void ApplyToBeatmap(Beatmap<T> beatmap) public virtual void ApplyToBeatmap(Beatmap<T> beatmap)
@ -55,10 +54,36 @@ namespace osu.Game.Rulesets.Mods
public virtual void Update(Playfield playfield) public virtual void Update(Playfield playfield)
{ {
var absRate = Math.Abs(FinalRateAdjustment); applyAdjustment((clock.CurrentTime - beginRampTime) / finalRateTime);
var adjustment = MathHelper.Clamp(absRate * ((clock.CurrentTime - beginRampTime) / finalRateTime), 0, absRate); }
pitchAdjust.PitchAdjust = 1 + Math.Sign(FinalRateAdjustment) * adjustment; private double lastAdjust = 1;
/// <summary>
/// Adjust the rate along the specified ramp
/// </summary>
/// <param name="amount">The amount of adjustment to apply (from 0..1).</param>
private void applyAdjustment(double amount)
{
double adjust = 1 + (Math.Sign(FinalRateAdjustment) * MathHelper.Clamp(amount, 0, 1) * Math.Abs(FinalRateAdjustment));
switch (clock)
{
case IHasPitchAdjust pitch:
pitch.PitchAdjust /= lastAdjust;
pitch.PitchAdjust *= adjust;
break;
case IHasTempoAdjust tempo:
tempo.TempoAdjust /= lastAdjust;
tempo.TempoAdjust *= adjust;
break;
default:
clock.Rate /= lastAdjust;
clock.Rate *= adjust;
break;
}
lastAdjust = adjust;
} }
} }
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
@ -14,6 +16,9 @@ namespace osu.Game.Rulesets.Mods
public override string Description => "Sloooow doooown..."; public override string Description => "Sloooow doooown...";
public override FontAwesome Icon => FontAwesome.fa_chevron_circle_down; public override FontAwesome Icon => FontAwesome.fa_chevron_circle_down;
public override double ScoreMultiplier => 1.0; public override double ScoreMultiplier => 1.0;
protected override double FinalRateAdjustment => -0.25; protected override double FinalRateAdjustment => -0.25;
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModWindUp<T>)).ToArray();
} }
} }

View File

@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
@ -14,6 +16,9 @@ namespace osu.Game.Rulesets.Mods
public override string Description => "Can you keep up?"; public override string Description => "Can you keep up?";
public override FontAwesome Icon => FontAwesome.fa_chevron_circle_up; public override FontAwesome Icon => FontAwesome.fa_chevron_circle_up;
public override double ScoreMultiplier => 1.0; public override double ScoreMultiplier => 1.0;
protected override double FinalRateAdjustment => 0.5; protected override double FinalRateAdjustment => 0.5;
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModWindDown<T>)).ToArray();
} }
} }

View File

@ -5,7 +5,6 @@ using osuTK;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.IO; using System.IO;
using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Formats;
using osu.Game.Audio; using osu.Game.Audio;
@ -46,9 +45,11 @@ namespace osu.Game.Rulesets.Objects.Legacy
{ {
string[] split = text.Split(','); string[] split = text.Split(',');
Vector2 pos = new Vector2((int)Convert.ToSingle(split[0], CultureInfo.InvariantCulture), (int)Convert.ToSingle(split[1], CultureInfo.InvariantCulture)); Vector2 pos = new Vector2((int)Parsing.ParseFloat(split[0], Parsing.MAX_COORDINATE_VALUE), (int)Parsing.ParseFloat(split[1], Parsing.MAX_COORDINATE_VALUE));
ConvertHitObjectType type = (ConvertHitObjectType)int.Parse(split[3]); double startTime = Parsing.ParseDouble(split[2]) + Offset;
ConvertHitObjectType type = (ConvertHitObjectType)Parsing.ParseInt(split[3]);
int comboOffset = (int)(type & ConvertHitObjectType.ComboOffset) >> 4; int comboOffset = (int)(type & ConvertHitObjectType.ComboOffset) >> 4;
type &= ~ConvertHitObjectType.ComboOffset; type &= ~ConvertHitObjectType.ComboOffset;
@ -56,7 +57,7 @@ namespace osu.Game.Rulesets.Objects.Legacy
bool combo = type.HasFlag(ConvertHitObjectType.NewCombo); bool combo = type.HasFlag(ConvertHitObjectType.NewCombo);
type &= ~ConvertHitObjectType.NewCombo; type &= ~ConvertHitObjectType.NewCombo;
var soundType = (LegacySoundType)int.Parse(split[4]); var soundType = (LegacySoundType)Parsing.ParseInt(split[4]);
var bankInfo = new SampleBankInfo(); var bankInfo = new SampleBankInfo();
HitObject result = null; HitObject result = null;
@ -107,7 +108,7 @@ namespace osu.Game.Rulesets.Objects.Legacy
} }
string[] temp = t.Split(':'); string[] temp = t.Split(':');
points[pointIndex++] = new Vector2((int)Convert.ToDouble(temp[0], CultureInfo.InvariantCulture), (int)Convert.ToDouble(temp[1], CultureInfo.InvariantCulture)) - pos; points[pointIndex++] = new Vector2((int)Parsing.ParseDouble(temp[0], Parsing.MAX_COORDINATE_VALUE), (int)Parsing.ParseDouble(temp[1], Parsing.MAX_COORDINATE_VALUE)) - pos;
} }
// osu-stable special-cased colinear perfect curves to a CurveType.Linear // osu-stable special-cased colinear perfect curves to a CurveType.Linear
@ -116,7 +117,7 @@ namespace osu.Game.Rulesets.Objects.Legacy
if (points.Length == 3 && pathType == PathType.PerfectCurve && isLinear(points)) if (points.Length == 3 && pathType == PathType.PerfectCurve && isLinear(points))
pathType = PathType.Linear; pathType = PathType.Linear;
int repeatCount = Convert.ToInt32(split[6], CultureInfo.InvariantCulture); int repeatCount = Parsing.ParseInt(split[6]);
if (repeatCount > 9000) if (repeatCount > 9000)
throw new ArgumentOutOfRangeException(nameof(repeatCount), @"Repeat count is way too high"); throw new ArgumentOutOfRangeException(nameof(repeatCount), @"Repeat count is way too high");
@ -125,7 +126,7 @@ namespace osu.Game.Rulesets.Objects.Legacy
repeatCount = Math.Max(0, repeatCount - 1); repeatCount = Math.Max(0, repeatCount - 1);
if (split.Length > 7) if (split.Length > 7)
length = Convert.ToDouble(split[7], CultureInfo.InvariantCulture); length = Math.Max(0, Parsing.ParseDouble(split[7]));
if (split.Length > 10) if (split.Length > 10)
readCustomSampleBanks(split[10], bankInfo); readCustomSampleBanks(split[10], bankInfo);
@ -184,7 +185,9 @@ namespace osu.Game.Rulesets.Objects.Legacy
} }
else if (type.HasFlag(ConvertHitObjectType.Spinner)) else if (type.HasFlag(ConvertHitObjectType.Spinner))
{ {
result = CreateSpinner(new Vector2(512, 384) / 2, combo, comboOffset, Convert.ToDouble(split[5], CultureInfo.InvariantCulture) + Offset); double endTime = Math.Max(startTime, Parsing.ParseDouble(split[5]) + Offset);
result = CreateSpinner(new Vector2(512, 384) / 2, combo, comboOffset, endTime);
if (split.Length > 6) if (split.Length > 6)
readCustomSampleBanks(split[6], bankInfo); readCustomSampleBanks(split[6], bankInfo);
@ -193,12 +196,12 @@ namespace osu.Game.Rulesets.Objects.Legacy
{ {
// Note: Hold is generated by BMS converts // Note: Hold is generated by BMS converts
double endTime = Convert.ToDouble(split[2], CultureInfo.InvariantCulture); double endTime = Math.Max(startTime, Parsing.ParseDouble(split[2]));
if (split.Length > 5 && !string.IsNullOrEmpty(split[5])) if (split.Length > 5 && !string.IsNullOrEmpty(split[5]))
{ {
string[] ss = split[5].Split(':'); string[] ss = split[5].Split(':');
endTime = Convert.ToDouble(ss[0], CultureInfo.InvariantCulture); endTime = Math.Max(startTime, Parsing.ParseDouble(ss[0]));
readCustomSampleBanks(string.Join(":", ss.Skip(1)), bankInfo); readCustomSampleBanks(string.Join(":", ss.Skip(1)), bankInfo);
} }
@ -211,7 +214,7 @@ namespace osu.Game.Rulesets.Objects.Legacy
return null; return null;
} }
result.StartTime = Convert.ToDouble(split[2], CultureInfo.InvariantCulture) + Offset; result.StartTime = startTime;
if (result.Samples.Count == 0) if (result.Samples.Count == 0)
result.Samples = convertSoundType(soundType, bankInfo); result.Samples = convertSoundType(soundType, bankInfo);
@ -222,8 +225,14 @@ namespace osu.Game.Rulesets.Objects.Legacy
} }
catch (FormatException) catch (FormatException)
{ {
throw new FormatException("One or more hit objects were malformed."); Logger.Log("A hitobject could not be parsed correctly and will be ignored", LoggingTarget.Runtime, LogLevel.Important);
} }
catch (OverflowException)
{
Logger.Log("A hitobject could not be parsed correctly and will be ignored", LoggingTarget.Runtime, LogLevel.Important);
}
return null;
} }
private void readCustomSampleBanks(string str, SampleBankInfo bankInfo) private void readCustomSampleBanks(string str, SampleBankInfo bankInfo)
@ -233,8 +242,8 @@ namespace osu.Game.Rulesets.Objects.Legacy
string[] split = str.Split(':'); string[] split = str.Split(':');
var bank = (LegacyBeatmapDecoder.LegacySampleBank)int.Parse(split[0]); var bank = (LegacyBeatmapDecoder.LegacySampleBank)Parsing.ParseInt(split[0]);
var addbank = (LegacyBeatmapDecoder.LegacySampleBank)int.Parse(split[1]); var addbank = (LegacyBeatmapDecoder.LegacySampleBank)Parsing.ParseInt(split[1]);
string stringBank = bank.ToString().ToLowerInvariant(); string stringBank = bank.ToString().ToLowerInvariant();
if (stringBank == @"none") if (stringBank == @"none")
@ -247,10 +256,10 @@ namespace osu.Game.Rulesets.Objects.Legacy
bankInfo.Add = string.IsNullOrEmpty(stringAddBank) ? stringBank : stringAddBank; bankInfo.Add = string.IsNullOrEmpty(stringAddBank) ? stringBank : stringAddBank;
if (split.Length > 2) if (split.Length > 2)
bankInfo.CustomSampleBank = int.Parse(split[2]); bankInfo.CustomSampleBank = Parsing.ParseInt(split[2]);
if (split.Length > 3) if (split.Length > 3)
bankInfo.Volume = int.Parse(split[3]); bankInfo.Volume = Math.Max(0, Parsing.ParseInt(split[3]));
bankInfo.Filename = split.Length > 4 ? split[4] : null; bankInfo.Filename = split.Length > 4 ? split[4] : null;
} }

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework; using osu.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -141,11 +142,15 @@ namespace osu.Game.Screens.Play
{ {
if (sourceClock == null) return; if (sourceClock == null) return;
sourceClock.Rate = 1; sourceClock.ResetSpeedAdjustments();
if (sourceClock is IHasTempoAdjust tempo)
tempo.TempoAdjust = UserPlaybackRate.Value;
else
sourceClock.Rate = UserPlaybackRate.Value;
foreach (var mod in beatmap.Mods.Value.OfType<IApplicableToClock>()) foreach (var mod in beatmap.Mods.Value.OfType<IApplicableToClock>())
mod.ApplyToClock(sourceClock); mod.ApplyToClock(sourceClock);
sourceClock.Rate *= UserPlaybackRate.Value;
} }
} }
} }

View File

@ -13,7 +13,7 @@ namespace osu.Game.Tests.Visual
base.Update(); base.Update();
// note that this will override any mod rate application // note that this will override any mod rate application
Beatmap.Value.Track.Rate = Clock.Rate; Beatmap.Value.Track.TempoAdjust = Clock.Rate;
} }
} }
} }

View File

@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.308.0" /> <PackageReference Include="ppy.osu.Framework" Version="2019.313.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" /> <PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" /> <PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />

View File

@ -105,8 +105,8 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.308.0" /> <PackageReference Include="ppy.osu.Framework" Version="2019.313.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2019.308.0" /> <PackageReference Include="ppy.osu.Framework.iOS" Version="2019.313.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" /> <PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" /> <PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />