| | | 1 | | using SwiftCollections; |
| | | 2 | | using System; |
| | | 3 | | using Trailblazer.Support; |
| | | 4 | | |
| | | 5 | | namespace Trailblazer; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Owns ordered lifecycle hook storage for one Trailblazer runtime owner. |
| | | 9 | | /// </summary> |
| | | 10 | | internal sealed class TrailblazerLifecycleHooks |
| | | 11 | | { |
| | 961 | 12 | | private readonly LifecycleHookHandler _hookHandler = new(); |
| | | 13 | | |
| | 961 | 14 | | private readonly SwiftList<OrderedLifecycleHook> _simulateHooks = new(); |
| | | 15 | | |
| | 961 | 16 | | private readonly SwiftList<OrderedLifecycleHook> _lateSimulateHooks = new(); |
| | | 17 | | |
| | 961 | 18 | | private readonly SwiftList<OrderedLifecycleHook> _visualizeHooks = new(); |
| | | 19 | | |
| | 961 | 20 | | private readonly SwiftList<OrderedLifecycleHook> _resetHooks = new(); |
| | | 21 | | |
| | 961 | 22 | | private readonly SwiftList<OrderedLifecycleHook> _frameRateChangedHooks = new(); |
| | | 23 | | |
| | 2 | 24 | | internal int SimulateHookCount => _simulateHooks.Count; |
| | | 25 | | |
| | 2 | 26 | | internal int ResetHookCount => _resetHooks.Count; |
| | | 27 | | |
| | | 28 | | internal IDisposable RegisterOnSimulate(string owner, int order, Action callback) => |
| | 7 | 29 | | _hookHandler.RegisterHook(_simulateHooks, owner, order, callback); |
| | | 30 | | |
| | | 31 | | internal IDisposable RegisterOnLateSimulate(string owner, int order, Action callback) => |
| | 1 | 32 | | _hookHandler.RegisterHook(_lateSimulateHooks, owner, order, callback); |
| | | 33 | | |
| | | 34 | | internal IDisposable RegisterOnVisualize(string owner, int order, Action callback) => |
| | 1 | 35 | | _hookHandler.RegisterHook(_visualizeHooks, owner, order, callback); |
| | | 36 | | |
| | | 37 | | internal IDisposable RegisterOnReset(string owner, int order, Action callback) => |
| | 2 | 38 | | _hookHandler.RegisterHook(_resetHooks, owner, order, callback); |
| | | 39 | | |
| | | 40 | | internal IDisposable RegisterOnFrameRateChanged(string owner, int order, Action callback) => |
| | 1 | 41 | | _hookHandler.RegisterHook(_frameRateChangedHooks, owner, order, callback); |
| | | 42 | | |
| | | 43 | | internal void InvokeSimulate() |
| | | 44 | | { |
| | 2299 | 45 | | if (_simulateHooks.Count != 0) |
| | 2 | 46 | | _hookHandler.InvokeHooks(_simulateHooks); |
| | 2299 | 47 | | } |
| | | 48 | | |
| | | 49 | | internal void InvokeLateSimulate() |
| | | 50 | | { |
| | 2 | 51 | | if (_lateSimulateHooks.Count != 0) |
| | 1 | 52 | | _hookHandler.InvokeHooks(_lateSimulateHooks); |
| | 2 | 53 | | } |
| | | 54 | | |
| | | 55 | | internal void InvokeVisualize() |
| | | 56 | | { |
| | 5 | 57 | | if (_visualizeHooks.Count != 0) |
| | 2 | 58 | | _hookHandler.InvokeHooks(_visualizeHooks); |
| | 5 | 59 | | } |
| | | 60 | | |
| | | 61 | | internal void InvokeReset() |
| | | 62 | | { |
| | 25 | 63 | | if (_resetHooks.Count != 0) |
| | 1 | 64 | | _hookHandler.InvokeHooks(_resetHooks); |
| | 25 | 65 | | } |
| | | 66 | | |
| | | 67 | | internal void InvokeFrameRateChanged() |
| | | 68 | | { |
| | 9 | 69 | | if (_frameRateChangedHooks.Count != 0) |
| | 1 | 70 | | _hookHandler.InvokeHooks(_frameRateChangedHooks); |
| | 9 | 71 | | } |
| | | 72 | | } |