| | | 1 | | using System; |
| | | 2 | | using Lattice.ECS.Core; |
| | | 3 | | using Lattice.Math; |
| | | 4 | | |
| | | 5 | | namespace Lattice.ECS.Session |
| | | 6 | | { |
| | | 7 | | /// <summary> |
| | | 8 | | /// SessionRuntime 的 Tick 管线执行器。 |
| | | 9 | | /// 负责统一驱动输入、系统模拟、结构提交、清理与历史写入阶段。 |
| | | 10 | | /// </summary> |
| | | 11 | | internal sealed class SessionTickProcessor |
| | | 12 | | { |
| | | 13 | | public void Execute( |
| | | 14 | | Frame frame, |
| | | 15 | | FP deltaTime, |
| | | 16 | | Action<SessionTickStage> enterStage, |
| | | 17 | | Action<Frame> applyInputs, |
| | | 18 | | Action<Frame, FP> updateSystems, |
| | | 19 | | Action<Frame> cleanupFrame, |
| | | 20 | | Action<Frame> captureHistory, |
| | | 21 | | Action<Frame, FP>? onFrameUpdate, |
| | | 22 | | bool raiseFrameUpdateEvent, |
| | | 23 | | bool captureHistoryStage) |
| | | 24 | | { |
| | 625 | 25 | | enterStage(SessionTickStage.InputApply); |
| | 625 | 26 | | applyInputs(frame); |
| | | 27 | | |
| | 625 | 28 | | bool structuralScopeStarted = false; |
| | | 29 | | try |
| | | 30 | | { |
| | 625 | 31 | | enterStage(SessionTickStage.Simulation); |
| | 625 | 32 | | frame.BeginDeferredStructuralChanges(); |
| | 625 | 33 | | structuralScopeStarted = true; |
| | 625 | 34 | | updateSystems(frame, deltaTime); |
| | | 35 | | |
| | 625 | 36 | | enterStage(SessionTickStage.StructuralCommit); |
| | 625 | 37 | | frame.CommitStructuralChanges(); |
| | 625 | 38 | | structuralScopeStarted = false; |
| | | 39 | | |
| | 625 | 40 | | enterStage(SessionTickStage.Cleanup); |
| | 625 | 41 | | cleanupFrame(frame); |
| | | 42 | | |
| | 625 | 43 | | if (raiseFrameUpdateEvent) |
| | | 44 | | { |
| | 517 | 45 | | onFrameUpdate?.Invoke(frame, deltaTime); |
| | | 46 | | } |
| | | 47 | | |
| | 625 | 48 | | if (captureHistoryStage) |
| | | 49 | | { |
| | 586 | 50 | | enterStage(SessionTickStage.HistoryCapture); |
| | 586 | 51 | | captureHistory(frame); |
| | | 52 | | } |
| | 625 | 53 | | } |
| | | 54 | | finally |
| | | 55 | | { |
| | 625 | 56 | | if (structuralScopeStarted) |
| | | 57 | | { |
| | 0 | 58 | | frame.AbortStructuralChanges(); |
| | | 59 | | } |
| | | 60 | | |
| | 625 | 61 | | enterStage(SessionTickStage.Idle); |
| | 625 | 62 | | } |
| | 625 | 63 | | } |
| | | 64 | | } |
| | | 65 | | } |