| | | 1 | | //======================================================================= |
| | | 2 | | // WaitForNextSimulate.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 | | namespace Gravitas.Support; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// A coroutine yield instruction that waits until the next Gravitas simulation frame. |
| | | 12 | | /// </summary> |
| | | 13 | | public readonly struct WaitForNextSimulate : ILockedYieldInstruction |
| | | 14 | | { |
| | | 15 | | private readonly GravitasWorldContext _context; |
| | | 16 | | private readonly int _checkedInFrameCount; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Creates an instruction that waits until the context advances to another simulation frame. |
| | | 20 | | /// </summary> |
| | | 21 | | public WaitForNextSimulate(GravitasWorldContext context) |
| | | 22 | | { |
| | 13 | 23 | | SwiftThrowHelper.ThrowIfNull(context, nameof(context)); |
| | | 24 | | |
| | 13 | 25 | | _context = context; |
| | 13 | 26 | | _checkedInFrameCount = context.FrameCount; |
| | 13 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <inheritdoc /> |
| | 10 | 30 | | public GravitasWorldContext Context => _context; |
| | | 31 | | |
| | | 32 | | /// <inheritdoc /> |
| | | 33 | | public bool KeepWaiting => |
| | 9 | 34 | | _context.FrameCount == _checkedInFrameCount; |
| | | 35 | | |
| | | 36 | | /// <inheritdoc /> |
| | 1 | 37 | | public object? Current => null; |
| | | 38 | | |
| | | 39 | | /// <inheritdoc /> |
| | 2 | 40 | | public bool MoveNext() => KeepWaiting; |
| | | 41 | | |
| | | 42 | | /// <inheritdoc /> |
| | 1 | 43 | | public void Reset() { } |
| | | 44 | | |
| | | 45 | | /// <inheritdoc /> |
| | 11 | 46 | | public void Dispose() { } |
| | | 47 | | } |