| | | 1 | | //======================================================================= |
| | | 2 | | // GravitasLifecycleHooks.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026–present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using Gravitas.Support; |
| | | 9 | | using SwiftCollections; |
| | | 10 | | using System; |
| | | 11 | | |
| | | 12 | | namespace Gravitas; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Owns ordered lifecycle hook storage for one Gravitas runtime owner. |
| | | 16 | | /// </summary> |
| | | 17 | | internal sealed class GravitasLifecycleHooks |
| | | 18 | | { |
| | 5083 | 19 | | private readonly LifecycleHookHandler _hookHandler = new(); |
| | | 20 | | |
| | 5083 | 21 | | private readonly SwiftList<OrderedLifecycleHook> _simulateHooks = new(); |
| | | 22 | | |
| | 5083 | 23 | | private readonly SwiftList<OrderedLifecycleHook> _lateSimulateHooks = new(); |
| | | 24 | | |
| | 5083 | 25 | | private readonly SwiftList<OrderedLifecycleHook> _visualizeHooks = new(); |
| | | 26 | | |
| | 5083 | 27 | | private readonly SwiftList<OrderedLifecycleHook> _lateVisualizeHooks = new(); |
| | | 28 | | |
| | 5083 | 29 | | private readonly SwiftList<OrderedLifecycleHook> _resetHooks = new(); |
| | | 30 | | |
| | 5083 | 31 | | private readonly SwiftList<OrderedLifecycleHook> _frameRateChangedHooks = new(); |
| | | 32 | | |
| | | 33 | | internal IDisposable RegisterOnSimulate(string owner, int order, Action callback) => |
| | 9 | 34 | | _hookHandler.RegisterHook(_simulateHooks, owner, order, callback); |
| | | 35 | | |
| | | 36 | | internal IDisposable RegisterOnLateSimulate(string owner, int order, Action callback) => |
| | 3 | 37 | | _hookHandler.RegisterHook(_lateSimulateHooks, owner, order, callback); |
| | | 38 | | |
| | | 39 | | internal IDisposable RegisterOnVisualize(string owner, int order, Action callback) => |
| | 1 | 40 | | _hookHandler.RegisterHook(_visualizeHooks, owner, order, callback); |
| | | 41 | | |
| | | 42 | | internal IDisposable RegisterOnLateVisualize(string owner, int order, Action callback) => |
| | 1 | 43 | | _hookHandler.RegisterHook(_lateVisualizeHooks, owner, order, callback); |
| | | 44 | | |
| | | 45 | | internal IDisposable RegisterOnReset(string owner, int order, Action callback) => |
| | 2 | 46 | | _hookHandler.RegisterHook(_resetHooks, owner, order, callback); |
| | | 47 | | |
| | | 48 | | internal IDisposable RegisterOnFrameRateChanged(string owner, int order, Action callback) => |
| | 2 | 49 | | _hookHandler.RegisterHook(_frameRateChangedHooks, owner, order, callback); |
| | | 50 | | |
| | | 51 | | internal void InvokeSimulate() |
| | | 52 | | { |
| | 2320 | 53 | | if (_simulateHooks.Count != 0) |
| | 4 | 54 | | _hookHandler.InvokeHooks(_simulateHooks); |
| | 2318 | 55 | | } |
| | | 56 | | |
| | | 57 | | internal void InvokeLateSimulate() |
| | | 58 | | { |
| | 2825 | 59 | | if (_lateSimulateHooks.Count != 0) |
| | 3 | 60 | | _hookHandler.InvokeHooks(_lateSimulateHooks); |
| | 2824 | 61 | | } |
| | | 62 | | |
| | | 63 | | internal void InvokeVisualize() |
| | | 64 | | { |
| | 29 | 65 | | if (_visualizeHooks.Count != 0) |
| | 1 | 66 | | _hookHandler.InvokeHooks(_visualizeHooks); |
| | 29 | 67 | | } |
| | | 68 | | |
| | | 69 | | internal void InvokeLateVisualize() |
| | | 70 | | { |
| | 15 | 71 | | if (_lateVisualizeHooks.Count != 0) |
| | 1 | 72 | | _hookHandler.InvokeHooks(_lateVisualizeHooks); |
| | 15 | 73 | | } |
| | | 74 | | |
| | | 75 | | internal void InvokeReset() |
| | | 76 | | { |
| | 31 | 77 | | if (_resetHooks.Count != 0) |
| | 1 | 78 | | _hookHandler.InvokeHooks(_resetHooks); |
| | 31 | 79 | | } |
| | | 80 | | |
| | | 81 | | internal void InvokeFrameRateChanged() |
| | | 82 | | { |
| | 1863 | 83 | | if (_frameRateChangedHooks.Count != 0) |
| | 2 | 84 | | _hookHandler.InvokeHooks(_frameRateChangedHooks); |
| | 1863 | 85 | | } |
| | | 86 | | } |