mirror of
https://github.com/ppy/osu
synced 2024-12-15 11:25:29 +00:00
Merge pull request #8703 from smoogipoo/fix-editorbeatmap-updates
Fix EditorBeatmap potentially not updating hitobjects
This commit is contained in:
commit
3a36c0008f
@ -1,6 +1,7 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
using NUnit.Framework;
|
||||
@ -162,5 +163,69 @@ namespace osu.Game.Tests.Beatmaps
|
||||
Assert.That(editorBeatmap.HitObjects.Count(h => h == hitCircle), Is.EqualTo(1));
|
||||
Assert.That(editorBeatmap.HitObjects.IndexOf(hitCircle), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that multiple hitobjects are updated simultaneously.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestMultipleHitObjectUpdate()
|
||||
{
|
||||
var updatedObjects = new List<HitObject>();
|
||||
var allHitObjects = new List<HitObject>();
|
||||
EditorBeatmap editorBeatmap = null;
|
||||
|
||||
AddStep("add beatmap", () =>
|
||||
{
|
||||
updatedObjects.Clear();
|
||||
|
||||
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap());
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var h = new HitCircle();
|
||||
editorBeatmap.Add(h);
|
||||
allHitObjects.Add(h);
|
||||
}
|
||||
});
|
||||
|
||||
AddStep("change all start times", () =>
|
||||
{
|
||||
editorBeatmap.HitObjectUpdated += h => updatedObjects.Add(h);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
allHitObjects[i].StartTime += 10;
|
||||
});
|
||||
|
||||
// Distinct ensures that all hitobjects have been updated once, debounce is tested below.
|
||||
AddAssert("all hitobjects updated", () => updatedObjects.Distinct().Count() == 10);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that hitobject updates are debounced when they happen too soon.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestDebouncedUpdate()
|
||||
{
|
||||
var updatedObjects = new List<HitObject>();
|
||||
EditorBeatmap editorBeatmap = null;
|
||||
|
||||
AddStep("add beatmap", () =>
|
||||
{
|
||||
updatedObjects.Clear();
|
||||
|
||||
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap());
|
||||
editorBeatmap.Add(new HitCircle());
|
||||
});
|
||||
|
||||
AddStep("change start time twice", () =>
|
||||
{
|
||||
editorBeatmap.HitObjectUpdated += h => updatedObjects.Add(h);
|
||||
|
||||
editorBeatmap.HitObjects[0].StartTime = 10;
|
||||
editorBeatmap.HitObjects[0].StartTime = 20;
|
||||
});
|
||||
|
||||
AddAssert("only updated once", () => updatedObjects.Count == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ namespace osu.Game.Screens.Edit
|
||||
trackStartTime(obj);
|
||||
}
|
||||
|
||||
private readonly HashSet<HitObject> pendingUpdates = new HashSet<HitObject>();
|
||||
private ScheduledDelegate scheduledUpdate;
|
||||
|
||||
/// <summary>
|
||||
@ -74,15 +75,27 @@ namespace osu.Game.Screens.Edit
|
||||
private void updateHitObject([CanBeNull] HitObject hitObject, bool silent)
|
||||
{
|
||||
scheduledUpdate?.Cancel();
|
||||
scheduledUpdate = Scheduler.AddDelayed(() =>
|
||||
|
||||
if (hitObject != null)
|
||||
pendingUpdates.Add(hitObject);
|
||||
|
||||
scheduledUpdate = Schedule(() =>
|
||||
{
|
||||
beatmapProcessor?.PreProcess();
|
||||
hitObject?.ApplyDefaults(ControlPointInfo, BeatmapInfo.BaseDifficulty);
|
||||
|
||||
foreach (var obj in pendingUpdates)
|
||||
obj.ApplyDefaults(ControlPointInfo, BeatmapInfo.BaseDifficulty);
|
||||
|
||||
beatmapProcessor?.PostProcess();
|
||||
|
||||
if (!silent)
|
||||
HitObjectUpdated?.Invoke(hitObject);
|
||||
}, 0);
|
||||
{
|
||||
foreach (var obj in pendingUpdates)
|
||||
HitObjectUpdated?.Invoke(obj);
|
||||
}
|
||||
|
||||
pendingUpdates.Clear();
|
||||
});
|
||||
}
|
||||
|
||||
public BeatmapInfo BeatmapInfo
|
||||
|
Loading…
Reference in New Issue
Block a user