Use IGameplayClock to ensure our clock source is correct

This commit is contained in:
Dean Herbert 2023-06-20 20:47:56 +09:00
parent 0e86102681
commit 04dad6c6e8
2 changed files with 8 additions and 3 deletions

View File

@ -101,7 +101,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
base.SetUpSteps();
AddStep("Add trigger source", () => Player.HUDOverlay.Add(sampleTriggerSource = new TestGameplaySampleTriggerSource(Player.DrawableRuleset.Playfield.HitObjectContainer)));
AddStep("Add trigger source", () => Player.GameplayClockContainer.Add(sampleTriggerSource = new TestGameplaySampleTriggerSource(Player.DrawableRuleset.Playfield.HitObjectContainer)));
}
[Test]

View File

@ -5,10 +5,12 @@
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Game.Audio;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.UI
@ -29,6 +31,9 @@ namespace osu.Game.Rulesets.UI
private readonly Container<SkinnableSound> hitSounds;
[Resolved]
private IGameplayClock gameplayClock { get; set; }
public GameplaySampleTriggerSource(HitObjectContainer hitObjectContainer)
{
this.hitObjectContainer = hitObjectContainer;
@ -104,11 +109,11 @@ namespace osu.Game.Rulesets.UI
// Else we want the earliest valid nested.
// In cases of nested objects, they will always have earlier sample data than their parent object.
return getAllNested(mostValidObject.HitObject).OrderBy(h => h.StartTime).FirstOrDefault(h => h.StartTime > Time.Current) ?? mostValidObject.HitObject;
return getAllNested(mostValidObject.HitObject).OrderBy(h => h.StartTime).FirstOrDefault(h => h.StartTime > gameplayClock.CurrentTime) ?? mostValidObject.HitObject;
}
private bool isAlreadyHit(HitObjectLifetimeEntry h) => h.Result?.HasResult == true;
private bool isCloseEnoughToCurrentTime(HitObjectLifetimeEntry h) => Time.Current >= h.HitObject.StartTime - h.HitObject.HitWindows.WindowFor(HitResult.Miss) * 2;
private bool isCloseEnoughToCurrentTime(HitObjectLifetimeEntry h) => gameplayClock.CurrentTime >= h.HitObject.StartTime - h.HitObject.HitWindows.WindowFor(HitResult.Miss) * 2;
private IEnumerable<HitObject> getAllNested(HitObject hitObject)
{