// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; namespace osu.Framework.Graphics.Performance { /// /// An object for a to consume, which provides a and . /// /// /// Management of the object which the refers to is left up to the consumer. /// public class LifetimeEntry { private double lifetimeStart = double.MinValue; /// /// The time at which this becomes alive in a . /// public double LifetimeStart { get => lifetimeStart; // A method is used as C# doesn't allow the combination of a non-virtual getter and a virtual setter. set => SetLifetimeStart(value); } private double lifetimeEnd = double.MaxValue; /// /// The time at which this becomes dead in a . /// public double LifetimeEnd { get => lifetimeEnd; set => SetLifetimeEnd(value); } /// /// Invoked before or changes. /// It is used because cannot be used to ensure comparator stability. /// internal event Action RequestLifetimeUpdate; /// /// Invoked after or changes. /// public event Action LifetimeChanged; /// /// Update of this . /// protected virtual void SetLifetimeStart(double start) { if (start != lifetimeStart) SetLifetime(start, lifetimeEnd); } /// /// Update of this . /// protected virtual void SetLifetimeEnd(double end) { if (end != lifetimeEnd) SetLifetime(lifetimeStart, end); } /// /// Updates the stored lifetimes of this . /// /// The new value. /// The new value. protected void SetLifetime(double start, double end) { RequestLifetimeUpdate?.Invoke(this); lifetimeStart = start; lifetimeEnd = Math.Max(start, end); // Negative intervals are undesired. LifetimeChanged?.Invoke(this); } /// /// The current state of this . /// internal LifetimeEntryState State { get; set; } /// /// Uniquely identifies this in a . /// internal ulong ChildId { get; set; } } }