Skip to content

Commit

Permalink
Merge branch 'ppy:master' into pattern-2
Browse files Browse the repository at this point in the history
  • Loading branch information
vunyunt authored Nov 29, 2024
2 parents a11de07 b71bccc commit fd0dd9f
Show file tree
Hide file tree
Showing 95 changed files with 1,529 additions and 723 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 114,10 @@ jobs:
dotnet-version: "8.0.x"

- name: Install .NET workloads
run: dotnet workload install android
# since windows image 20241113.3.0, not specifying a version here
# installs the .NET 7 version of android workload for very unknown reasons.
# revisit once we upgrade to .NET 9, it's probably fixed there.
run: dotnet workload install android --version (dotnet --version)

- name: Compile
run: dotnet build -c Debug osu.Android.slnf
Expand Down
2 changes: 1 addition & 1 deletion osu.Android.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 10,7 @@
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Framework.Android" Version="2024.1118.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2024.1128.0" />
</ItemGroup>
<PropertyGroup>
<!-- Fody does not handle Android build well, and warns when unchanged.
Expand Down
33 changes: 14 additions & 19 deletions osu.Desktop/DiscordRichPresence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 15,7 @@
using osu.Game;
using osu.Game.Configuration;
using osu.Game.Extensions;
using osu.Game.Online;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer;
Expand Down Expand Up @@ -47,6 48,9 @@ internal partial class DiscordRichPresence : Component
[Resolved]
private MultiplayerClient multiplayerClient { get; set; } = null!;

[Resolved]
private LocalUserStatisticsProvider statisticsProvider { get; set; } = null!;

[Resolved]
private OsuConfigManager config { get; set; } = null!;

Expand Down Expand Up @@ -117,7 121,9 @@ protected override void LoadComplete()
status.BindValueChanged(_ => schedulePresenceUpdate());
activity.BindValueChanged(_ => schedulePresenceUpdate());
privacyMode.BindValueChanged(_ => schedulePresenceUpdate());

multiplayerClient.RoomUpdated = onRoomUpdated;
statisticsProvider.StatisticsUpdated = onStatisticsUpdated;
}

private void onReady(object _, ReadyMessage __)
Expand All @@ -133,6 139,8 @@ private void onReady(object _, ReadyMessage __)

private void onRoomUpdated() => schedulePresenceUpdate();

private void onStatisticsUpdated(UserStatisticsUpdate _) => schedulePresenceUpdate();

private ScheduledDelegate? presenceUpdateDelegate;

private void schedulePresenceUpdate()
Expand Down Expand Up @@ -167,7 175,7 @@ private void updatePresence(bool hideIdentifiableInformation)
presence.State = clampLength(activity.Value.GetStatus(hideIdentifiableInformation));
presence.Details = clampLength(activity.Value.GetDetails(hideIdentifiableInformation) ?? string.Empty);

if (getBeatmapID(activity.Value) is int beatmapId && beatmapId > 0)
if (activity.Value.GetBeatmapID(hideIdentifiableInformation) is int beatmapId && beatmapId > 0)
{
presence.Buttons = new[]
{
Expand Down Expand Up @@ -229,10 237,8 @@ private void updatePresence(bool hideIdentifiableInformation)
presence.Assets.LargeImageText = string.Empty;
else
{
if (user.Value.RulesetsStatistics != null && user.Value.RulesetsStatistics.TryGetValue(ruleset.Value.ShortName, out UserStatistics? statistics))
presence.Assets.LargeImageText = $"{user.Value.Username}" (statistics.GlobalRank > 0 ? $" (rank #{statistics.GlobalRank:N0})" : string.Empty);
else
presence.Assets.LargeImageText = $"{user.Value.Username}" (user.Value.Statistics?.GlobalRank > 0 ? $" (rank #{user.Value.Statistics.GlobalRank:N0})" : string.Empty);
var statistics = statisticsProvider.GetStatisticsFor(ruleset.Value);
presence.Assets.LargeImageText = $"{user.Value.Username}" (statistics?.GlobalRank > 0 ? $" (rank #{statistics.GlobalRank:N0})" : string.Empty);
}

// small image
Expand Down Expand Up @@ -327,25 333,14 @@ private static bool tryParseRoomSecret(string secretJson, out long roomId, out s
return true;
}

private static int? getBeatmapID(UserActivity activity)
{
switch (activity)
{
case UserActivity.InGame game:
return game.BeatmapID;

case UserActivity.EditingBeatmap edit:
return edit.BeatmapID;
}

return null;
}

protected override void Dispose(bool isDisposing)
{
if (multiplayerClient.IsNotNull())
multiplayerClient.RoomUpdated -= onRoomUpdated;

if (statisticsProvider.IsNotNull())
statisticsProvider.StatisticsUpdated -= onStatisticsUpdated;

client.Dispose();
base.Dispose(isDisposing);
}
Expand Down
38 changes: 32 additions & 6 deletions osu.Game.Benchmarks/BenchmarkUnstableRate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 4,54 @@
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using osu.Framework.Utils;
using osu.Game.Rulesets.Objects;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Scoring;

namespace osu.Game.Benchmarks
{
public class BenchmarkUnstableRate : BenchmarkTest
{
private List<HitEvent> events = null!;
private readonly List<List<HitEvent>> incrementalEventLists = new List<List<HitEvent>>();

public override void SetUp()
{
base.SetUp();
events = new List<HitEvent>();

for (int i = 0; i < 1000; i )
events.Add(new HitEvent(RNG.NextDouble(-200.0, 200.0), RNG.NextDouble(1.0, 2.0), HitResult.Great, new HitObject(), null, null));
var events = new List<HitEvent>();

for (int i = 0; i < 2048; i )
{
// Ensure the object has hit windows populated.
var hitObject = new HitCircle();
hitObject.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
events.Add(new HitEvent(RNG.NextDouble(-200.0, 200.0), RNG.NextDouble(1.0, 2.0), HitResult.Great, hitObject, null, null));

incrementalEventLists.Add(new List<HitEvent>(events));
}
}

[Benchmark]
public void CalculateUnstableRate()
{
_ = events.CalculateUnstableRate();
for (int i = 0; i < 2048; i )
{
var events = incrementalEventLists[i];
_ = events.CalculateUnstableRate();
}
}

[Benchmark]
public void CalculateUnstableRateUsingIncrementalCalculation()
{
HitEventExtensions.UnstableRateCalculationResult? last = null;

for (int i = 0; i < 2048; i )
{
var events = incrementalEventLists[i];
last = events.CalculateUnstableRate(last);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,7 @@ protected override void InitialiseDefaults()
{
base.InitialiseDefaults();

SetDefault(ManiaRulesetSetting.ScrollSpeed, 8, 1, 40);
SetDefault(ManiaRulesetSetting.ScrollSpeed, 8.0, 1.0, 40.0, 0.1);
SetDefault(ManiaRulesetSetting.ScrollDirection, ManiaScrollingDirection.Down);
SetDefault(ManiaRulesetSetting.TimingBasedNoteColouring, false);

Expand All @@ -31,15 31,15 @@ protected override void InitialiseDefaults()

if (Get<double?>(ManiaRulesetSetting.ScrollTime) is double scrollTime)
{
SetValue(ManiaRulesetSetting.ScrollSpeed, (int)Math.Round(DrawableManiaRuleset.MAX_TIME_RANGE / scrollTime));
SetValue(ManiaRulesetSetting.ScrollSpeed, Math.Round(DrawableManiaRuleset.MAX_TIME_RANGE / scrollTime));
SetValue<double?>(ManiaRulesetSetting.ScrollTime, null);
}
#pragma warning restore CS0618
}

public override TrackedSettings CreateTrackedSettings() => new TrackedSettings
{
new TrackedSetting<int>(ManiaRulesetSetting.ScrollSpeed,
new TrackedSetting<double>(ManiaRulesetSetting.ScrollSpeed,
speed => new SettingDescription(
rawValue: speed,
name: RulesetSettingsStrings.ScrollSpeed,
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Mania/Edit/DrawableManiaEditorRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 44,7 @@ protected override void LoadComplete()

protected override void Update()
{
TargetTimeRange = TimelineTimeRange == null || ShowSpeedChanges.Value ? ComputeScrollTime(Config.Get<int>(ManiaRulesetSetting.ScrollSpeed)) : TimelineTimeRange.Value;
TargetTimeRange = TimelineTimeRange == null || ShowSpeedChanges.Value ? ComputeScrollTime(Config.Get<double>(ManiaRulesetSetting.ScrollSpeed)) : TimelineTimeRange.Value;
base.Update();
}
}
Expand Down
8 changes: 4 additions & 4 deletions osu.Game.Rulesets.Mania/ManiaSettingsSubsection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 33,11 @@ private void load()
LabelText = RulesetSettingsStrings.ScrollingDirection,
Current = config.GetBindable<ManiaScrollingDirection>(ManiaRulesetSetting.ScrollDirection)
},
new SettingsSlider<int, ManiaScrollSlider>
new SettingsSlider<double, ManiaScrollSlider>
{
LabelText = RulesetSettingsStrings.ScrollSpeed,
Current = config.GetBindable<int>(ManiaRulesetSetting.ScrollSpeed),
KeyboardStep = 5
Current = config.GetBindable<double>(ManiaRulesetSetting.ScrollSpeed),
KeyboardStep = 1
},
new SettingsCheckbox
{
Expand All @@ -48,7 48,7 @@ private void load()
};
}

private partial class ManiaScrollSlider : RoundedSliderBar<int>
private partial class ManiaScrollSlider : RoundedSliderBar<double>
{
public override LocalisableString TooltipText => RulesetSettingsStrings.ScrollSpeedTooltip((int)DrawableManiaRuleset.ComputeScrollTime(Current.Value), Current.Value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 164,10 @@ public override Drawable GetDrawableComponent(ISkinComponentLookup lookup)

private Drawable getResult(HitResult result)
{
if (!hit_result_mapping.ContainsKey(result))
if (!hit_result_mapping.TryGetValue(result, out var value))
return null;

string filename = this.GetManiaSkinConfig<string>(hit_result_mapping[result])?.Value
string filename = this.GetManiaSkinConfig<string>(value)?.Value
?? default_hit_result_skin_filenames[result];

var animation = this.GetAnimation(filename, true, true, frameLength: 1000 / 20d);
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 56,7 @@ public partial class DrawableManiaRuleset : DrawableScrollingRuleset<ManiaHitObj
protected new ManiaRulesetConfigManager Config => (ManiaRulesetConfigManager)base.Config;

private readonly Bindable<ManiaScrollingDirection> configDirection = new Bindable<ManiaScrollingDirection>();
private readonly BindableInt configScrollSpeed = new BindableInt();
private readonly BindableDouble configScrollSpeed = new BindableDouble();

private double currentTimeRange;
protected double TargetTimeRange;
Expand Down Expand Up @@ -160,7 160,7 @@ private void updateTimeRange()
/// </summary>
/// <param name="scrollSpeed">The scroll speed.</param>
/// <returns>The scroll time.</returns>
public static double ComputeScrollTime(int scrollSpeed) => MAX_TIME_RANGE / scrollSpeed;
public static double ComputeScrollTime(double scrollSpeed) => MAX_TIME_RANGE / scrollSpeed;

public override PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer() => new ManiaPlayfieldAdjustmentContainer();

Expand Down
4 changes: 4 additions & 0 deletions osu.Game.Rulesets.Osu/Edit/OsuGridToolboxGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 38,7 @@ public partial class OsuGridToolboxGroup : EditorToolboxGroup, IKeyBindingHandle
{
MinValue = 0f,
MaxValue = OsuPlayfield.BASE_SIZE.X,
Precision = 0.01f,
};

/// <summary>
Expand All @@ -47,6 48,7 @@ public partial class OsuGridToolboxGroup : EditorToolboxGroup, IKeyBindingHandle
{
MinValue = 0f,
MaxValue = OsuPlayfield.BASE_SIZE.Y,
Precision = 0.01f,
};

/// <summary>
Expand All @@ -56,6 58,7 @@ public partial class OsuGridToolboxGroup : EditorToolboxGroup, IKeyBindingHandle
{
MinValue = 4f,
MaxValue = 128f,
Precision = 0.01f,
};

/// <summary>
Expand All @@ -65,6 68,7 @@ public partial class OsuGridToolboxGroup : EditorToolboxGroup, IKeyBindingHandle
{
MinValue = -180f,
MaxValue = 180f,
Precision = 0.01f,
};

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 63,17 @@ private void load(ISkinSource source)
Origin = Anchor.Centre,
Texture = source.GetTexture("spinner-top"),
},
fixedMiddle = new Sprite
spinningMiddle = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Texture = source.GetTexture("spinner-middle"),
Texture = source.GetTexture("spinner-middle2"),
},
spinningMiddle = new Sprite
fixedMiddle = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Texture = source.GetTexture("spinner-middle2"),
Texture = source.GetTexture("spinner-middle"),
},
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 1000,7 @@ public void TestLegacyDefaultsPreserved(bool applyOffsets)
Assert.That(decoded.BeatmapInfo.WidescreenStoryboard, Is.False);
Assert.That(decoded.BeatmapInfo.EpilepsyWarning, Is.False);
Assert.That(decoded.BeatmapInfo.SamplesMatchPlaybackRate, Is.False);
Assert.That(decoded.BeatmapInfo.Countdown, Is.EqualTo(CountdownType.Normal));
Assert.That(decoded.BeatmapInfo.Countdown, Is.EqualTo(CountdownType.None));
Assert.That(decoded.BeatmapInfo.CountdownOffset, Is.EqualTo(0));
Assert.That(decoded.BeatmapInfo.Metadata.PreviewTime, Is.EqualTo(-1));
Assert.That(decoded.BeatmapInfo.Ruleset.OnlineID, Is.EqualTo(0));
Expand Down
5 changes: 5 additions & 0 deletions osu.Game.Tests/ImportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
Expand Down Expand Up @@ -64,6 65,10 @@ private void load()
// Beatmap must be imported before the collection manager is loaded.
if (withBeatmap)
BeatmapManager.Import(TestResources.GetTestBeatmapForImport()).WaitSafely();

// the logic for setting the initial ruleset exists in OsuGame rather than OsuGameBase.
// the ruleset bindable is not meant to be nullable, so assign any ruleset in here.
Ruleset.Value = RulesetStore.AvailableRulesets.First();
}
}
}
Expand Down
45 changes: 43 additions & 2 deletions osu.Game.Tests/NonVisual/Ranking/UnstableRateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 20,53 @@ public class UnstableRateTest
public void TestDistributedHits()
{
var events = Enumerable.Range(-5, 11)
.Select(t => new HitEvent(t - 5, 1.0, HitResult.Great, new HitObject(), null, null));
.Select(t => new HitEvent(t - 5, 1.0, HitResult.Great, new HitObject(), null, null))
.ToList();

var unstableRate = new UnstableRate(events);

Assert.IsNotNull(unstableRate.Value);
Assert.IsTrue(Precision.AlmostEquals(unstableRate.Value.Value, 10 * Math.Sqrt(10)));
Assert.AreEqual(unstableRate.Value.Value, 10 * Math.Sqrt(10), Precision.DOUBLE_EPSILON);
}

[Test]
public void TestDistributedHitsIncrementalRewind()
{
var events = Enumerable.Range(-5, 11)
.Select(t => new HitEvent(t - 5, 1.0, HitResult.Great, new HitObject(), null, null))
.ToList();

HitEventExtensions.UnstableRateCalculationResult result = null;

for (int i = 0; i < events.Count; i )
{
result = events.GetRange(0, i 1)
.CalculateUnstableRate(result);
}

result = events.GetRange(0, 2).CalculateUnstableRate(result);

Assert.IsNotNull(result!.Result);
Assert.AreEqual(5, result.Result, Precision.DOUBLE_EPSILON);
}

[Test]
public void TestDistributedHitsIncremental()
{
var events = Enumerable.Range(-5, 11)
.Select(t => new HitEvent(t - 5, 1.0, HitResult.Great, new HitObject(), null, null))
.ToList();

HitEventExtensions.UnstableRateCalculationResult result = null;

for (int i = 0; i < events.Count; i )
{
result = events.GetRange(0, i 1)
.CalculateUnstableRate(result);
}

Assert.IsNotNull(result!.Result);
Assert.AreEqual(10 * Math.Sqrt(10), result.Result, Precision.DOUBLE_EPSILON);
}

[Test]
Expand Down
Loading

0 comments on commit fd0dd9f

Please sign in to comment.