Add hitobject lifetime support

This commit is contained in:
smoogipoo
2020-11-10 20:16:52 +09:00
parent 45e9f16f6b
commit 6f3f6dc28b
6 changed files with 86 additions and 16 deletions

View File

@ -16,6 +16,7 @@ using System.Threading;
using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Pooling;
using osu.Framework.Input;
@ -246,6 +247,16 @@ namespace osu.Game.Rulesets.UI
Playfield.Add(drawableObject);
}
protected sealed override HitObjectLifetimeEntry CreateLifetimeEntry(HitObject hitObject)
{
if (!(hitObject is TObject tHitObject))
throw new InvalidOperationException($"Unexpected hitobject type: {hitObject.GetType().ReadableName()}");
return CreateLifetimeEntry(tHitObject);
}
protected virtual HitObjectLifetimeEntry CreateLifetimeEntry(TObject hitObject) => new HitObjectLifetimeEntry(hitObject);
public override void SetRecordTarget(Replay recordingReplay)
{
if (!(KeyBindingInputManager is IHasRecordingHandler recordingInputManager))
@ -564,9 +575,21 @@ namespace osu.Game.Rulesets.UI
m.ApplyToDrawableHitObjects(dho.Yield());
}
dho.Apply(hitObject);
dho.Apply(hitObject, GetLifetimeEntry(hitObject));
});
}
protected abstract HitObjectLifetimeEntry CreateLifetimeEntry(HitObject hitObject);
private readonly Dictionary<HitObject, HitObjectLifetimeEntry> lifetimeEntries = new Dictionary<HitObject, HitObjectLifetimeEntry>();
protected HitObjectLifetimeEntry GetLifetimeEntry(HitObject hitObject)
{
if (lifetimeEntries.TryGetValue(hitObject, out var entry))
return entry;
return lifetimeEntries[hitObject] = CreateLifetimeEntry(hitObject);
}
}
public class BeatmapInvalidForRulesetException : ArgumentException